mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-22 07:41:20 -04:00
Mods:
Updated dataservice tests and fixed subsequent bugs added bug fixes for RetroDb and fixed postability issue (removed map.at use) Added: Data access module used as token service gxs service backend (RsGenExchange) RsPhotoV2 which is a modification to deal with different interface provided by RsGenExchange also added subsequent p3photoserviceV2 NxsTestHub to help with testing nxsnetservice (RsGxsNetService is not yet working) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5274 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f05d2f9b09
commit
081b59ee1a
27 changed files with 1529 additions and 395 deletions
|
@ -69,7 +69,11 @@ void init_item(RsGxsGrpMetaData* metaGrp)
|
|||
metaGrp->mPublishTs = rand()%3452;
|
||||
metaGrp->mGroupFlags = rand()%43;
|
||||
|
||||
|
||||
metaGrp->mGroupStatus = rand()%313;
|
||||
metaGrp->mSubscribeFlags = rand()%2251;
|
||||
metaGrp->mMsgCount = rand()%2421;
|
||||
metaGrp->mLastPost = rand()%2211;
|
||||
metaGrp->mPop = rand()%5262;
|
||||
}
|
||||
|
||||
void init_item(RsGxsMsgMetaData* metaMsg)
|
||||
|
|
5
libretroshare/src/tests/gxs/nxstesthub.cc
Normal file
5
libretroshare/src/tests/gxs/nxstesthub.cc
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "nxstesthub.h"
|
||||
|
||||
NxsTestHub::NxsTestHub()
|
||||
{
|
||||
}
|
45
libretroshare/src/tests/gxs/nxstesthub.h
Normal file
45
libretroshare/src/tests/gxs/nxstesthub.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef NXSTESTHUB_H
|
||||
#define NXSTESTHUB_H
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
#include "gxs/rsgxsnetservice.h"
|
||||
|
||||
/*!
|
||||
* This scenario module allows you to model
|
||||
* simply back and forth conversation between nxs and a virtual peer
|
||||
* (this module being the virtual peer)
|
||||
*/
|
||||
class NxsScenario
|
||||
{
|
||||
|
||||
static int SCENARIO_OUTGOING;
|
||||
static int SCENARIO_INCOMING;
|
||||
|
||||
public:
|
||||
|
||||
virtual int scenarioType() = 0;
|
||||
|
||||
virtual void receive(RsNxsItem* ) = 0;
|
||||
virtual RsNxsItem* send() = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class NxsTestHub : public RsThread
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
NxsTestHub(NxsScenario* , std::pair<RsGxsNetService*, RsGxsNetService*> servicePair);
|
||||
|
||||
/*!
|
||||
* To be called only after this thread has
|
||||
* been shutdown
|
||||
*/
|
||||
bool testsPassed();
|
||||
|
||||
void run();
|
||||
};
|
||||
|
||||
#endif // NXSTESTHUB_H
|
73
libretroshare/src/tests/gxs/rs_test.pro
Normal file
73
libretroshare/src/tests/gxs/rs_test.pro
Normal file
|
@ -0,0 +1,73 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-05-06T09:19:26
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core network
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = rs_test
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
win32 {
|
||||
# Switch on extra warnings
|
||||
QMAKE_CFLAGS += -Wextra
|
||||
QMAKE_CXXFLAGS += -Wextra
|
||||
|
||||
# Switch off optimization for release version
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE += -O0
|
||||
QMAKE_CFLAGS_RELEASE -= -O2
|
||||
QMAKE_CFLAGS_RELEASE += -O0
|
||||
|
||||
# Switch on optimization for debug version
|
||||
#QMAKE_CXXFLAGS_DEBUG += -O2
|
||||
#QMAKE_CFLAGS_DEBUG += -O2
|
||||
DEFINES *= WINDOWS_SYS
|
||||
PRE_TARGETDEPS += C:\Development\Rs\v0.5-new_cache_system\libretroshare\libretroshare-build-desktop\lib\libretroshare.a
|
||||
LIBS += C:\Development\Rs\v0.5-new_cache_system\libretroshare\libretroshare-build-desktop\lib\libretroshare.a
|
||||
LIBS += -L"../lib"
|
||||
LIBS += -lssl -lcrypto -lgpgme -lpthreadGC2d -lminiupnpc -lz
|
||||
# added after bitdht
|
||||
# LIBS += -lws2_32
|
||||
LIBS += -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lgdi32
|
||||
LIBS += -lole32 -lwinmm
|
||||
|
||||
# export symbols for the plugins
|
||||
#LIBS += -Wl,--export-all-symbols,--out-implib,lib/libretroshare-gui.a
|
||||
|
||||
GPG_ERROR_DIR = ../../../../libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../gpgme-1.1.8
|
||||
GPG_ERROR_DIR = ../../../../lib/libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../lib/gpgme-1.1.8
|
||||
INCLUDEPATH += . $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src ../../Libraries/sqlite/sqlite-autoconf-3070900
|
||||
LIBS += C:\Development\Libraries\sqlite\sqlite-autoconf-3070900\.libs\libsqlite3.a
|
||||
}
|
||||
|
||||
win32 {
|
||||
# must be added after bitdht
|
||||
LIBS += -lws2_32
|
||||
}
|
||||
|
||||
SOURCES += \
|
||||
support.cc \
|
||||
#rsnxsitems_test.cc
|
||||
rsdataservice_test.cc \
|
||||
data_support.cc
|
||||
#rsnxsservice_test.cc \
|
||||
#nxstesthub.cc
|
||||
#rsgxsdata_test.cc
|
||||
|
||||
HEADERS += support.h \
|
||||
#rsnxsitems_test.h
|
||||
rsdataservice_test.h \
|
||||
data_support.h
|
||||
#rsnxsservice_test.h \
|
||||
#nxstesthub.h
|
||||
|
||||
INCLUDEPATH += C:\Development\Rs\v0.5-new_cache_system\libretroshare\src
|
|
@ -18,8 +18,7 @@ int main()
|
|||
std::cerr << "RsDataService Tests" << std::endl;
|
||||
|
||||
test_groupStoreAndRetrieve(); REPORT("test_groupStoreAndRetrieve");
|
||||
|
||||
//test_messageStoresAndRetrieve(); REPORT("test_messageStoresAndRetrieve");
|
||||
test_messageStoresAndRetrieve(); REPORT("test_messageStoresAndRetrieve");
|
||||
|
||||
FINALREPORT("RsDataService Tests");
|
||||
|
||||
|
@ -29,7 +28,10 @@ int main()
|
|||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* All memory is disposed off, good for looking
|
||||
* for memory leaks
|
||||
*/
|
||||
void test_groupStoreAndRetrieve(){
|
||||
|
||||
setUp();
|
||||
|
@ -46,7 +48,11 @@ void test_groupStoreAndRetrieve(){
|
|||
p.second = grpMeta;
|
||||
init_item(*grp);
|
||||
init_item(grpMeta);
|
||||
grpMeta->mGroupId = grp->grpId;
|
||||
grps.insert(p);
|
||||
|
||||
grpMeta = NULL;
|
||||
grp = NULL;
|
||||
}
|
||||
|
||||
dStore->storeGroup(grps);
|
||||
|
@ -56,6 +62,230 @@ void test_groupStoreAndRetrieve(){
|
|||
dStore->retrieveNxsGrps(gR, false);
|
||||
dStore->retrieveGxsGrpMetaData(grpMetaR);
|
||||
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*>::iterator mit = grps.begin();
|
||||
|
||||
bool grpMatch = true, grpMetaMatch = true;
|
||||
|
||||
for(; mit != grps.end(); mit++)
|
||||
{
|
||||
const std::string grpId = mit->first->grpId;
|
||||
|
||||
// check if it exists
|
||||
if(gR.find(grpId) == gR.end()) {
|
||||
grpMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsNxsGrp *l = mit->first,
|
||||
*r = gR[grpId];
|
||||
|
||||
// assign transaction number
|
||||
// to right to as tn is not stored
|
||||
// in db
|
||||
r->transactionNumber = l->transactionNumber;
|
||||
|
||||
// then do a comparison
|
||||
if(!( *l == *r)) {
|
||||
grpMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// now do a comparison of grp meta types
|
||||
|
||||
if(grpMetaR.find(grpId) == grpMetaR.end())
|
||||
{
|
||||
grpMetaMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsGxsGrpMetaData *l_Meta = mit->second,
|
||||
*r_Meta = grpMetaR[grpId];
|
||||
|
||||
if(!(*l_Meta == *r_Meta))
|
||||
{
|
||||
grpMetaMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
/* release resources */
|
||||
delete l_Meta;
|
||||
delete r_Meta;
|
||||
delete l;
|
||||
delete r;
|
||||
|
||||
remove(grpId.c_str());
|
||||
}
|
||||
|
||||
grpMetaR.clear();
|
||||
|
||||
CHECK(grpMatch);
|
||||
tearDown();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Test for both selective and
|
||||
* bulk msg retrieval
|
||||
*/
|
||||
void test_messageStoresAndRetrieve()
|
||||
{
|
||||
setUp();
|
||||
|
||||
// first create a grpId
|
||||
std::string grpId0, grpId1;
|
||||
|
||||
randString(SHORT_STR, grpId0);
|
||||
randString(SHORT_STR, grpId1);
|
||||
std::vector<std::string> grpV; // stores grpIds of all msgs stored and retrieved
|
||||
grpV.push_back(grpId0);
|
||||
grpV.push_back(grpId1);
|
||||
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
|
||||
RsNxsMsg* msg = NULL;
|
||||
RsGxsMsgMetaData* msgMeta = NULL;
|
||||
int nMsgs = rand()%120;
|
||||
GxsMsgReq req;
|
||||
|
||||
std::map<std::string, RsNxsMsg*> VergrpId0, VergrpId1;
|
||||
std::map<std::string, RsGxsMsgMetaData*> VerMetagrpId0, VerMetagrpId1;
|
||||
|
||||
for(int i=0; i<nMsgs; i++)
|
||||
{
|
||||
msg = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
msgMeta = new RsGxsMsgMetaData();
|
||||
init_item(*msg);
|
||||
init_item(msgMeta);
|
||||
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
|
||||
int chosen = 0;
|
||||
if(rand()%50 > 24){
|
||||
chosen = 1;
|
||||
|
||||
}
|
||||
|
||||
const std::string& grpId = grpV[chosen];
|
||||
|
||||
if(chosen)
|
||||
req[grpId].insert(msg->msgId);
|
||||
|
||||
msgMeta->mMsgId = msg->msgId;
|
||||
msgMeta->mGroupId = msg->grpId = grpId;
|
||||
|
||||
// store msgs in map to use for verification
|
||||
std::pair<std::string, RsNxsMsg*> vP(msg->msgId, msg);
|
||||
std::pair<std::string, RsGxsMsgMetaData*> vPmeta(msg->msgId, msgMeta);
|
||||
|
||||
if(!chosen)
|
||||
{
|
||||
VergrpId0.insert(vP);
|
||||
VerMetagrpId0.insert(vPmeta);
|
||||
}
|
||||
else
|
||||
{
|
||||
VergrpId1.insert(vP);
|
||||
VerMetagrpId0.insert(vPmeta);
|
||||
}
|
||||
msg = NULL;
|
||||
msgMeta = NULL;
|
||||
|
||||
msgs.insert(p);
|
||||
}
|
||||
|
||||
req[grpV[0]] = std::set<std::string>(); // assign empty list for other
|
||||
|
||||
dStore->storeMessage(msgs);
|
||||
|
||||
// now retrieve msgs for comparison
|
||||
// first selective retrieval
|
||||
|
||||
GxsMsgResult msgResult;
|
||||
GxsMsgMetaResult msgMetaResult;
|
||||
dStore->retrieveNxsMsgs(req, msgResult, false);
|
||||
dStore->retrieveGxsMsgMetaData(grpV, msgMetaResult);
|
||||
|
||||
// now look at result for grpId 1
|
||||
std::vector<RsNxsMsg*>& result0 = msgResult[grpId0];
|
||||
std::vector<RsNxsMsg*>& result1 = msgResult[grpId1];
|
||||
std::vector<RsGxsMsgMetaData*>& resultMeta0 = msgMetaResult[grpId0];
|
||||
std::vector<RsGxsMsgMetaData*>& resultMeta1 = msgMetaResult[grpId1];
|
||||
|
||||
|
||||
|
||||
bool msgGrpId0_Match = true, msgGrpId1_Match = true;
|
||||
bool msgMetaGrpId0_Match = true, msgMetaGrpId1_Match = true;
|
||||
|
||||
// MSG test, selective retrieval
|
||||
for(std::vector<RsNxsMsg*>::size_type i = 0; i < result0.size(); i++)
|
||||
{
|
||||
RsNxsMsg* l = result0[i] ;
|
||||
|
||||
if(VergrpId0.find(l->msgId) == VergrpId0.end())
|
||||
{
|
||||
msgGrpId0_Match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsNxsMsg* r = VergrpId0[l->msgId];
|
||||
r->transactionNumber = l->transactionNumber;
|
||||
|
||||
if(!(*l == *r))
|
||||
{
|
||||
msgGrpId0_Match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(msgGrpId0_Match);
|
||||
|
||||
// META test
|
||||
for(std::vector<RsGxsMsgMetaData*>::size_type i = 0; i < resultMeta0.size(); i++)
|
||||
{
|
||||
RsGxsMsgMetaData* l = resultMeta0[i] ;
|
||||
|
||||
if(VerMetagrpId0.find(l->mMsgId) == VerMetagrpId0.end())
|
||||
{
|
||||
msgMetaGrpId0_Match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsGxsMsgMetaData* r = VerMetagrpId0[l->mMsgId];
|
||||
|
||||
if(!(*l == *r))
|
||||
{
|
||||
msgMetaGrpId0_Match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(msgMetaGrpId0_Match);
|
||||
|
||||
// MSG test, bulk retrieval
|
||||
for(std::vector<RsNxsMsg*>::size_type i = 0; i < result1.size(); i++)
|
||||
{
|
||||
RsNxsMsg* l = result1[i] ;
|
||||
|
||||
if(VergrpId1.find(l->msgId) == VergrpId1.end())
|
||||
{
|
||||
msgGrpId1_Match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsNxsMsg* r = VergrpId1[l->msgId];
|
||||
|
||||
r->transactionNumber = l->transactionNumber;
|
||||
|
||||
if(!(*l == *r))
|
||||
{
|
||||
msgGrpId1_Match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(msgGrpId1_Match);
|
||||
|
||||
//dStore->retrieveGxsMsgMetaData();
|
||||
std::string msgFile = grpId0 + "-msgs";
|
||||
remove(msgFile.c_str());
|
||||
msgFile = grpId1 + "-msgs";
|
||||
remove(msgFile.c_str());
|
||||
tearDown();
|
||||
}
|
||||
|
||||
|
@ -80,5 +310,42 @@ void tearDown(){
|
|||
perror("Error: ");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator ==(const RsGxsGrpMetaData& l, const RsGxsGrpMetaData& r)
|
||||
{
|
||||
if(!(l.adminSign == r.adminSign)) return false;
|
||||
if(!(l.idSign == r.idSign)) return false;
|
||||
if(!(l.keys == r.keys)) return false;
|
||||
if(l.mGroupFlags != r.mGroupFlags) return false;
|
||||
if(l.mPublishTs != r.mPublishTs) return false;
|
||||
if(l.mAuthorId != r.mAuthorId) return false;
|
||||
if(l.mGroupName != r.mGroupName) return false;
|
||||
if(l.mGroupId != r.mGroupId) return false;
|
||||
if(l.mGroupStatus != r.mGroupStatus) return false;
|
||||
if(l.mPop != r.mPop) return false;
|
||||
if(l.mMsgCount != r.mMsgCount) return false;
|
||||
if(l.mSubscribeFlags != r.mSubscribeFlags) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsMsgMetaData& l, const RsGxsMsgMetaData& r)
|
||||
{
|
||||
|
||||
if(!(l.idSign == r.idSign)) return false;
|
||||
if(!(l.pubSign == r.pubSign)) return false;
|
||||
if(l.mGroupId != r.mGroupId) return false;
|
||||
if(l.mAuthorId != r.mAuthorId) return false;
|
||||
if(l.mParentId != r.mParentId) return false;
|
||||
if(l.mOrigMsgId != r.mOrigMsgId) return false;
|
||||
if(l.mThreadId != r.mThreadId) return false;
|
||||
if(l.mMsgId != r.mMsgId) return false;
|
||||
if(l.mMsgName != r.mMsgName) return false;
|
||||
if(l.mPublishTs != r.mPublishTs) return false;
|
||||
if(l.mMsgFlags != r.mMsgFlags) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@ void test_storeAndDeleteMessage();
|
|||
void test_searchMsg();
|
||||
void test_searchGrp();
|
||||
|
||||
bool operator ==(const RsGxsGrpMetaData& l, const RsGxsGrpMetaData& r);
|
||||
bool operator ==(const RsGxsMsgMetaData& l, const RsGxsMsgMetaData& r);
|
||||
|
||||
void test_multiThreaded();
|
||||
|
||||
class DataReadWrite : RsThread
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue