From 5eef86d9fd9f164e0e2225cc5595c6a613a33341 Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Sun, 18 May 2014 16:44:19 +0000 Subject: [PATCH] - 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 --- .../libretroshare/gxs/common/data_support.h | 8 +++++ .../gxs/nxs_test/nxsgrpsync_test.cc | 4 +-- .../gxs/nxs_test/nxsgrptestscenario.cc | 34 ++++++++++++++++++ .../gxs/nxs_test/nxsgrptestscenario.h | 8 ++++- .../gxs/nxs_test/nxsmsgsync_test.cc | 3 +- .../gxs/nxs_test/nxsmsgtestscenario.cc | 35 +++++++++++++++++++ .../gxs/nxs_test/nxsmsgtestscenario.h | 8 ++++- .../libretroshare/gxs/nxs_test/nxstesthub.cc | 1 + .../gxs/nxs_test/nxstestscenario.h | 2 ++ .../gxs/nxs_test/rsgxsnetservice_test.cc | 1 + tests/unittests/unittests.pro | 7 ++-- 11 files changed, 100 insertions(+), 11 deletions(-) diff --git a/tests/unittests/libretroshare/gxs/common/data_support.h b/tests/unittests/libretroshare/gxs/common/data_support.h index 5c886a487..384c6cbb9 100644 --- a/tests/unittests/libretroshare/gxs/common/data_support.h +++ b/tests/unittests/libretroshare/gxs/common/data_support.h @@ -29,3 +29,11 @@ RsSerialType* init_item(RsNxsSyncGrpItem& rsgl); RsSerialType* init_item(RsNxsSyncMsgItem& rsgml); RsSerialType* init_item(RsNxsTransac& rstx); +template +void copy_all_but(T& ex, const std::list& s, std::list& d) +{ + typename std::list::const_iterator cit = s.begin(); + for(; cit != s.end(); cit++) + if(*cit != ex) + d.push_back(*cit); +} diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.cc index fa401be91..b01f715f0 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.cc @@ -31,10 +31,8 @@ NxsGrpSync::NxsGrpSync() for(; it != mPeerIds.end(); it++) { // data stores - RsGeneralDataService* ds = new RsDataService("./", "grp_store_" + - it->toStdString(), mServType, NULL, "key"); + RsGeneralDataService* ds = createDataStore(*it, mServType); mDataServices.insert(std::make_pair(*it, ds)); - // net managers std::list otherPeers; copy_all_but(*it, mPeerIds, otherPeers); diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsgrptestscenario.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxsgrptestscenario.cc index 7f5c23a35..8919b2a94 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsgrptestscenario.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsgrptestscenario.cc @@ -51,6 +51,40 @@ bool NxsGrpTestScenario::checkDeepTestPassed() 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 */ diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsgrptestscenario.h b/tests/unittests/libretroshare/gxs/nxs_test/nxsgrptestscenario.h index 59e741298..51d5757d3 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsgrptestscenario.h +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsgrptestscenario.h @@ -22,11 +22,17 @@ public: virtual bool checkTestPassed(); virtual bool checkDeepTestPassed(); + void cleanTestScenario(); protected: - RsDataService* createDataStore(const RsPeerId& peerId); virtual const ExpectedMap& getExpectedMap() = 0; + RsGeneralDataService* createDataStore(const RsPeerId& peerId, uint16_t servType); + +private: + + typedef std::map DataPeerMap; + DataPeerMap mDataPeerMap; }; } /* namespace rs_nxs_test */ diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc index 863d13d91..d9cd602ae 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc @@ -32,8 +32,7 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync() for(; it != mPeerIds.end(); it++) { // data stores - RsGeneralDataService* ds = new RsDataService("./", "data_store_" + - it->toStdString(), mServType, NULL, "key"); + RsGeneralDataService* ds = createDataStore(*it, mServType); mDataServices.insert(std::make_pair(*it, ds)); // net managers diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc index c21c8987a..27de84696 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc @@ -67,6 +67,41 @@ bool NxsMsgTestScenario::checkDeepTestPassed() { 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 */ diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgtestscenario.h b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgtestscenario.h index ca615d6fd..323a54660 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgtestscenario.h +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgtestscenario.h @@ -22,11 +22,17 @@ public: bool checkTestPassed(); bool checkDeepTestPassed(); + void cleanTestScenario(); protected: - RsDataService* createDataStore(const RsPeerId& peerId); + RsGeneralDataService* createDataStore(const RsPeerId& peerId, uint16_t servType); virtual const ExpectedMap& getExpectedMap() = 0; + +private: + + typedef std::map DataPeerMap; + DataPeerMap mDataPeerMap; }; } /* namespace rs_nxs_test */ diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc index a8184e3d5..deed48a19 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc @@ -138,6 +138,7 @@ void rs_nxs_test::NxsTestHub::EndTest() mit->second->join(); } + mTestScenario->cleanTestScenario(); } void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid, diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxstestscenario.h b/tests/unittests/libretroshare/gxs/nxs_test/nxstestscenario.h index 3741d90b6..4d01c2d7d 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxstestscenario.h +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxstestscenario.h @@ -38,6 +38,8 @@ namespace rs_nxs_test virtual uint16_t getServiceType() = 0; virtual RsServiceInfo getServiceInfo() = 0; + virtual void cleanTestScenario() = 0; + }; } diff --git a/tests/unittests/libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc b/tests/unittests/libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc index d4d3e9428..bb173f357 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc @@ -24,6 +24,7 @@ TEST(libretroshare_gxs, gxs_grp_sync) tHub.EndTest(); ASSERT_TRUE(tHub.testsPassed()); + } TEST(libretroshare_gxs, gxs_msg_sync) diff --git a/tests/unittests/unittests.pro b/tests/unittests/unittests.pro index c2ff4871c..fc0d41297 100644 --- a/tests/unittests/unittests.pro +++ b/tests/unittests/unittests.pro @@ -275,10 +275,9 @@ SOURCES += libretroshare/gxs/nxs_test/nxsdummyservices.cc \ libretroshare/gxs/nxs_test/nxsgrptestscenario.cc \ libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc \ libretroshare/gxs/nxs_test/nxstesthub.cc \ - -# libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc -# libretroshare/gxs/nxs_test/nxsmsgsync_test.cc \ -# libretroshare/gxs/nxs_test/nxsgrpsync_test.cc \ + libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc \ + libretroshare/gxs/nxs_test/nxsmsgsync_test.cc \ + libretroshare/gxs/nxs_test/nxsgrpsync_test.cc HEADERS += libretroshare/gxs/gen_exchange/genexchangetester.h \ libretroshare/gxs/gen_exchange/gxspublishmsgtest.h \