- Added clean up of test data

- re-enabled gxs test code

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7374 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2014-05-18 16:44:19 +00:00
parent bfe872118b
commit 5eef86d9fd
11 changed files with 100 additions and 11 deletions

View File

@ -29,3 +29,11 @@ RsSerialType* init_item(RsNxsSyncGrpItem& rsgl);
RsSerialType* init_item(RsNxsSyncMsgItem& rsgml); RsSerialType* init_item(RsNxsSyncMsgItem& rsgml);
RsSerialType* init_item(RsNxsTransac& rstx); RsSerialType* init_item(RsNxsTransac& rstx);
template<typename T>
void copy_all_but(T& ex, const std::list<T>& s, std::list<T>& d)
{
typename std::list<T>::const_iterator cit = s.begin();
for(; cit != s.end(); cit++)
if(*cit != ex)
d.push_back(*cit);
}

View File

@ -31,10 +31,8 @@ NxsGrpSync::NxsGrpSync()
for(; it != mPeerIds.end(); it++) for(; it != mPeerIds.end(); it++)
{ {
// data stores // data stores
RsGeneralDataService* ds = new RsDataService("./", "grp_store_" + RsGeneralDataService* ds = createDataStore(*it, mServType);
it->toStdString(), mServType, NULL, "key");
mDataServices.insert(std::make_pair(*it, ds)); mDataServices.insert(std::make_pair(*it, ds));
// net managers // net managers
std::list<RsPeerId> otherPeers; std::list<RsPeerId> otherPeers;
copy_all_but<RsPeerId>(*it, mPeerIds, otherPeers); copy_all_but<RsPeerId>(*it, mPeerIds, otherPeers);

View File

@ -51,6 +51,40 @@ bool NxsGrpTestScenario::checkDeepTestPassed()
return false; return false;
} }
void NxsGrpTestScenario::cleanTestScenario()
{
DataPeerMap::iterator mit = mDataPeerMap.begin();
RsPeerId::std_vector peerIds;
// remove grps and msg data
for(; mit != mDataPeerMap.end(); mit++)
{
mit->second->resetDataStore();
peerIds.push_back(mit->first);
} }
// now delete tables
RsPeerId::std_vector::const_iterator cit = peerIds.begin();
for(; cit != peerIds.end(); cit++)
{
std::string tableFile = "grp_store_" + cit->toStdString();
remove(tableFile.c_str());
}
}
RsGeneralDataService* NxsGrpTestScenario::createDataStore(
const RsPeerId& peerId, uint16_t servType)
{
RsGeneralDataService* ds = new RsDataService("./", "grp_store_" +
peerId.toStdString(), servType, NULL, "key");
mDataPeerMap.insert(std::make_pair(peerId, ds));
return ds;
}
}
/* namespace rs_nxs_test */ /* namespace rs_nxs_test */

View File

@ -22,11 +22,17 @@ public:
virtual bool checkTestPassed(); virtual bool checkTestPassed();
virtual bool checkDeepTestPassed(); virtual bool checkDeepTestPassed();
void cleanTestScenario();
protected: protected:
RsDataService* createDataStore(const RsPeerId& peerId);
virtual const ExpectedMap& getExpectedMap() = 0; virtual const ExpectedMap& getExpectedMap() = 0;
RsGeneralDataService* createDataStore(const RsPeerId& peerId, uint16_t servType);
private:
typedef std::map<RsPeerId, RsGeneralDataService*> DataPeerMap;
DataPeerMap mDataPeerMap;
}; };
} /* namespace rs_nxs_test */ } /* namespace rs_nxs_test */

View File

@ -32,8 +32,7 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync()
for(; it != mPeerIds.end(); it++) for(; it != mPeerIds.end(); it++)
{ {
// data stores // data stores
RsGeneralDataService* ds = new RsDataService("./", "data_store_" + RsGeneralDataService* ds = createDataStore(*it, mServType);
it->toStdString(), mServType, NULL, "key");
mDataServices.insert(std::make_pair(*it, ds)); mDataServices.insert(std::make_pair(*it, ds));
// net managers // net managers

View File

@ -67,6 +67,41 @@ bool NxsMsgTestScenario::checkDeepTestPassed() {
return false; return false;
} }
void NxsMsgTestScenario::cleanTestScenario()
{
DataPeerMap::iterator mit = mDataPeerMap.begin();
RsPeerId::std_vector peerIds;
// remove grps and msg data
for(; mit != mDataPeerMap.end(); mit++)
{
mit->second->resetDataStore();
peerIds.push_back(mit->first);
} }
// now delete tables
RsPeerId::std_vector::const_iterator cit = peerIds.begin();
for(; cit != peerIds.end(); cit++)
{
std::string tableFile = "grp_store_" + cit->toStdString();
remove(tableFile.c_str());
}
}
RsGeneralDataService* NxsMsgTestScenario::createDataStore(
const RsPeerId& peerId, uint16_t servType) {
RsGeneralDataService* ds = new RsDataService("./", "msg_store_" +
peerId.toStdString(), servType, NULL, "key");
mDataPeerMap.insert(std::make_pair(peerId, ds));
return ds;
}
}
/* namespace rs_nxs_test */ /* namespace rs_nxs_test */

View File

@ -22,11 +22,17 @@ public:
bool checkTestPassed(); bool checkTestPassed();
bool checkDeepTestPassed(); bool checkDeepTestPassed();
void cleanTestScenario();
protected: protected:
RsDataService* createDataStore(const RsPeerId& peerId); RsGeneralDataService* createDataStore(const RsPeerId& peerId, uint16_t servType);
virtual const ExpectedMap& getExpectedMap() = 0; virtual const ExpectedMap& getExpectedMap() = 0;
private:
typedef std::map<RsPeerId, RsGeneralDataService*> DataPeerMap;
DataPeerMap mDataPeerMap;
}; };
} /* namespace rs_nxs_test */ } /* namespace rs_nxs_test */

View File

@ -138,6 +138,7 @@ void rs_nxs_test::NxsTestHub::EndTest()
mit->second->join(); mit->second->join();
} }
mTestScenario->cleanTestScenario();
} }
void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid, void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid,

View File

@ -38,6 +38,8 @@ namespace rs_nxs_test
virtual uint16_t getServiceType() = 0; virtual uint16_t getServiceType() = 0;
virtual RsServiceInfo getServiceInfo() = 0; virtual RsServiceInfo getServiceInfo() = 0;
virtual void cleanTestScenario() = 0;
}; };
} }

View File

@ -24,6 +24,7 @@ TEST(libretroshare_gxs, gxs_grp_sync)
tHub.EndTest(); tHub.EndTest();
ASSERT_TRUE(tHub.testsPassed()); ASSERT_TRUE(tHub.testsPassed());
} }
TEST(libretroshare_gxs, gxs_msg_sync) TEST(libretroshare_gxs, gxs_msg_sync)

View File

@ -275,10 +275,9 @@ SOURCES += libretroshare/gxs/nxs_test/nxsdummyservices.cc \
libretroshare/gxs/nxs_test/nxsgrptestscenario.cc \ libretroshare/gxs/nxs_test/nxsgrptestscenario.cc \
libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc \ libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc \
libretroshare/gxs/nxs_test/nxstesthub.cc \ libretroshare/gxs/nxs_test/nxstesthub.cc \
libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc \
# libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc libretroshare/gxs/nxs_test/nxsmsgsync_test.cc \
# libretroshare/gxs/nxs_test/nxsmsgsync_test.cc \ libretroshare/gxs/nxs_test/nxsgrpsync_test.cc
# libretroshare/gxs/nxs_test/nxsgrpsync_test.cc \
HEADERS += libretroshare/gxs/gen_exchange/genexchangetester.h \ HEADERS += libretroshare/gxs/gen_exchange/genexchangetester.h \
libretroshare/gxs/gen_exchange/gxspublishmsgtest.h \ libretroshare/gxs/gen_exchange/gxspublishmsgtest.h \