mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-24 15:09:33 -05:00
Added another convenience class to simplify testing
(automates comparisons) fixed some unit tests caused by copy constructor removal git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7302 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
71a02003be
commit
4cab2aaa65
@ -21,26 +21,43 @@ public:
|
||||
RsSharedPtr() : mShared(NULL), mCount(NULL) {}
|
||||
|
||||
RsSharedPtr(T* shared)
|
||||
: mShared(shared), mCount(new int(0))
|
||||
: mShared(shared), mCount(new int(0)), mSharedPtrMutex(new RsMutex("SharedMutex"))
|
||||
{
|
||||
mCount++;
|
||||
}
|
||||
|
||||
RsSharedPtr(const RsSharedPtr<T>& rsp)
|
||||
{
|
||||
rsp.lock();
|
||||
mShared = rsp.mShared;
|
||||
mCount = rsp.mCount;
|
||||
mCount++;
|
||||
mSharedPtrMutex = rsp.mSharedPtrMutex;
|
||||
rsp.unlock();
|
||||
|
||||
}
|
||||
|
||||
void operator=(const RsSharedPtr<T>& rsp)
|
||||
{
|
||||
rsp.lock();
|
||||
mSharedPtrMutex = rsp.mSharedPtrMutex;
|
||||
DecrementAndDeleteIfLast();
|
||||
mShared = rsp.mShared;
|
||||
RepointAndIncrement(rsp.mCount);
|
||||
|
||||
mSharedPtrMutex->unlock();
|
||||
}
|
||||
|
||||
T* release() { mCount--; T* temp = mShared; mShared = NULL; return temp; }
|
||||
T* release() {
|
||||
|
||||
lock();
|
||||
|
||||
mCount--; T* temp = mShared; mShared = NULL;
|
||||
|
||||
unlock();
|
||||
|
||||
return temp;
|
||||
}
|
||||
T* get() { return mShared; }
|
||||
|
||||
T& operator*(){ return *mShared; }
|
||||
@ -72,10 +89,14 @@ private:
|
||||
|
||||
}
|
||||
|
||||
void lock() const { mSharedPtrMutex->lock(); }
|
||||
void unlock() const { mSharedPtrMutex->unlock(); }
|
||||
|
||||
private:
|
||||
|
||||
int* mCount;
|
||||
T* mShared;
|
||||
RsMutex* mSharedPtrMutex;
|
||||
|
||||
};
|
||||
|
||||
|
@ -29,8 +29,6 @@ NxsGrpSync::NxsGrpSync()
|
||||
|
||||
for(int i =0; i < numPeers; i++)
|
||||
{
|
||||
|
||||
|
||||
RsPeerId id = RsPeerId::random();
|
||||
mPeerIds.push_back(id);
|
||||
}
|
||||
@ -68,8 +66,8 @@ NxsGrpSync::NxsGrpSync()
|
||||
init_item(meta);
|
||||
grp->metaData = meta;
|
||||
meta->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
||||
RsNxsGrp* grp_copy = grp->clone();
|
||||
|
||||
RsGxsGroupId grpId = grp->grpId;
|
||||
|
||||
RsGeneralDataService::GrpStoreMap gsp;
|
||||
gsp.insert(std::make_pair(grp, meta));
|
||||
@ -78,9 +76,8 @@ NxsGrpSync::NxsGrpSync()
|
||||
// the expected result is that each peer has the group of the others
|
||||
it = mPeerIds.begin();
|
||||
for(; it != mPeerIds.end(); it++)
|
||||
{
|
||||
if(mit->first != *it)
|
||||
mExpectedResult[*it].push_back(grp_copy);
|
||||
{
|
||||
mExpectedResult[*it].push_back(grpId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,31 +96,6 @@ RsGeneralDataService* NxsGrpSync::getDataService(const RsPeerId& peerId)
|
||||
return mDataServices[peerId];
|
||||
}
|
||||
|
||||
bool NxsGrpSync::checkTestPassed()
|
||||
{
|
||||
// look at data store, as all peers should have same
|
||||
// number of groups
|
||||
DataMap::iterator mit = mDataServices.begin();
|
||||
std::list<int> vals;
|
||||
for(; mit != mDataServices.end(); mit++)
|
||||
{
|
||||
RsGxsGroupId::std_vector grpIds;
|
||||
mit->second->retrieveGroupIds(grpIds);
|
||||
vals.push_back(grpIds.size());
|
||||
}
|
||||
|
||||
std::list<int>::iterator lit = vals.begin();
|
||||
int prev = *lit;
|
||||
bool passed = true;
|
||||
for(; lit != vals.end(); lit++)
|
||||
{
|
||||
passed &= *lit == prev;
|
||||
prev = *lit;
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
RsNxsNetMgr* NxsGrpSync::getDummyNetManager(const RsPeerId& peerId)
|
||||
{
|
||||
return mNxsNetMgrs[peerId];
|
||||
@ -161,3 +133,8 @@ RsServiceInfo rs_nxs_test::NxsGrpSync::getServiceInfo() {
|
||||
return mServInfo;
|
||||
}
|
||||
|
||||
const NxsGrpTestScenario::ExpectedMap& rs_nxs_test::NxsGrpSync::getExpectedMap() {
|
||||
return mExpectedResult;
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,13 +8,12 @@
|
||||
#ifndef NXSGRPSYNC_TEST_H_
|
||||
#define NXSGRPSYNC_TEST_H_
|
||||
|
||||
|
||||
#include "nxstestscenario.h"
|
||||
#include "nxsgrptestscenario.h"
|
||||
|
||||
namespace rs_nxs_test
|
||||
{
|
||||
|
||||
class NxsGrpSync : public NxsTestScenario
|
||||
class NxsGrpSync : public NxsGrpTestScenario
|
||||
{
|
||||
public:
|
||||
|
||||
@ -23,18 +22,20 @@ namespace rs_nxs_test
|
||||
|
||||
void getPeers(std::list<RsPeerId>& peerIds);
|
||||
RsGeneralDataService* getDataService(const RsPeerId& peerId);
|
||||
bool checkTestPassed();
|
||||
RsNxsNetMgr* getDummyNetManager(const RsPeerId& peerId);
|
||||
RsGcxs* getDummyCircles(const RsPeerId& peerId);
|
||||
RsGixsReputation* getDummyReputations(const RsPeerId& peerId);
|
||||
uint16_t getServiceType();
|
||||
RsServiceInfo getServiceInfo();
|
||||
|
||||
protected:
|
||||
|
||||
const ExpectedMap& getExpectedMap();
|
||||
|
||||
private:
|
||||
|
||||
std::list<RsPeerId> mPeerIds;
|
||||
typedef std::map<RsPeerId, RsGeneralDataService*> DataMap;
|
||||
typedef std::map<RsPeerId, std::list<RsNxsGrp*> > ExpectedMap;
|
||||
|
||||
DataMap mDataServices;
|
||||
std::map<RsPeerId, RsNxsNetMgr*> mNxsNetMgrs;
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* nxsgrptestscenario.cpp
|
||||
*
|
||||
* Created on: 23 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "nxsgrptestscenario.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace rs_nxs_test {
|
||||
|
||||
NxsGrpTestScenario::NxsGrpTestScenario() {
|
||||
}
|
||||
|
||||
NxsGrpTestScenario::~NxsGrpTestScenario() {
|
||||
}
|
||||
|
||||
bool NxsGrpTestScenario::checkTestPassed()
|
||||
{
|
||||
const ExpectedMap& exMap = getExpectedMap();
|
||||
|
||||
ExpectedMap::const_iterator mit = exMap.begin();
|
||||
|
||||
bool passed = true;
|
||||
|
||||
for(; mit != exMap.end(); mit++)
|
||||
{
|
||||
const RsPeerId& pid = mit->first;
|
||||
RsGxsGroupId::std_vector expGrpIds = mit->second;
|
||||
RsGeneralDataService* ds = getDataService(pid);
|
||||
RsGxsGroupId::std_vector grpIds;
|
||||
ds->retrieveGroupIds(grpIds);
|
||||
|
||||
RsGxsGroupId::std_vector result(expGrpIds.size()+grpIds.size());
|
||||
std::sort(grpIds.begin(), grpIds.end());
|
||||
std::sort(expGrpIds.begin(), expGrpIds.end());
|
||||
RsGxsGroupId::std_vector::iterator it = std::set_difference(grpIds.begin(), grpIds.end(),
|
||||
expGrpIds.begin(), expGrpIds.end(), result.begin());
|
||||
|
||||
result.resize(it - result.begin());
|
||||
|
||||
passed &= result.size() == 0;
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
bool NxsGrpTestScenario::checkDeepTestPassed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* namespace rs_nxs_test */
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* nxsgrptestscenario.h
|
||||
*
|
||||
* Created on: 23 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef NXSGRPTESTSCENARIO_H_
|
||||
#define NXSGRPTESTSCENARIO_H_
|
||||
|
||||
#include "nxstestscenario.h"
|
||||
|
||||
namespace rs_nxs_test {
|
||||
|
||||
class NxsGrpTestScenario : public NxsTestScenario {
|
||||
public:
|
||||
|
||||
typedef std::map<RsPeerId, RsGxsGroupId::std_vector > ExpectedMap;
|
||||
|
||||
NxsGrpTestScenario();
|
||||
virtual ~NxsGrpTestScenario();
|
||||
|
||||
bool checkTestPassed();
|
||||
bool checkDeepTestPassed();
|
||||
|
||||
protected:
|
||||
|
||||
RsDataService* createDataStore(const RsPeerId& peerId);
|
||||
virtual const ExpectedMap& getExpectedMap() = 0;
|
||||
};
|
||||
|
||||
} /* namespace rs_nxs_test */
|
||||
#endif /* NXSGRPTESTSCENARIO_H_ */
|
@ -8,41 +8,39 @@
|
||||
#ifndef NXSMSGSYNC_TEST_H_
|
||||
#define NXSMSGSYNC_TEST_H_
|
||||
|
||||
#include "nxstestscenario.h"
|
||||
|
||||
|
||||
|
||||
class NxsMessageTest : public NxsTestScenario
|
||||
class NxsMessageTest : public rs_nxs_test::NxsTestScenario
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NxsMessageTest(uint16_t servtype);
|
||||
virtual ~NxsMessageTest();
|
||||
std::string getTestName();
|
||||
NxsMessageTest();
|
||||
void getPeers(std::list<RsPeerId>& peerIds);
|
||||
RsGeneralDataService* getDataService(const RsPeerId& peerId);
|
||||
bool checkTestPassed();
|
||||
RsNxsNetMgr* getDummyNetManager(const RsPeerId& peerId);
|
||||
RsGcxs* getDummyCircles(const RsPeerId& peerId);
|
||||
RsGixsReputation* getDummyReputations(const RsPeerId& peerId);
|
||||
uint16_t getServiceType();
|
||||
RsGeneralDataService* getDataService(const RsPeerId& peer);
|
||||
|
||||
/*!
|
||||
* Call to remove files created
|
||||
* in the test directory
|
||||
*/
|
||||
void cleanUp();
|
||||
|
||||
bool testPassed();
|
||||
|
||||
private:
|
||||
void setUpDataBases();
|
||||
void populateStore(RsGeneralDataService* dStore);
|
||||
RsServiceInfo getServiceInfo();
|
||||
|
||||
private:
|
||||
|
||||
std::string mTestName;
|
||||
std::map<RsPeerId, RsGeneralDataService*> mPeerStoreMap;
|
||||
std::set<std::string> mStoreNames;
|
||||
std::list<RsPeerId> mPeerIds;
|
||||
typedef std::map<RsPeerId, RsGeneralDataService*> DataMap;
|
||||
typedef std::map<RsPeerId, std::list<RsNxsGrp*> > ExpectedMap;
|
||||
|
||||
DataMap mDataServices;
|
||||
std::map<RsPeerId, RsNxsNetMgr*> mNxsNetMgrs;
|
||||
RsGixsReputation* mRep;
|
||||
RsGcxs* mCircles;
|
||||
RsServiceInfo mServInfo;
|
||||
|
||||
ExpectedMap mExpectedResult;
|
||||
|
||||
uint16_t mServType;
|
||||
|
||||
RsMutex mMsgTestMtx;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -31,12 +31,14 @@ namespace rs_nxs_test
|
||||
virtual void getPeers(std::list<RsPeerId>& peerIds) = 0;
|
||||
virtual RsGeneralDataService* getDataService(const RsPeerId& peerId) = 0;
|
||||
virtual bool checkTestPassed() = 0;
|
||||
virtual bool checkDeepTestPassed() = 0;
|
||||
virtual RsNxsNetMgr* getDummyNetManager(const RsPeerId& peerId) = 0;
|
||||
virtual RsGcxs* getDummyCircles(const RsPeerId& peerId) = 0;
|
||||
virtual RsGixsReputation* getDummyReputations(const RsPeerId& peerId) = 0;
|
||||
virtual uint16_t getServiceType() = 0;
|
||||
virtual RsServiceInfo getServiceInfo() = 0;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ TEST(libretroshare_gxs, gxs_grp_sync)
|
||||
tHub.StartTest();
|
||||
|
||||
// wait for ten seconds
|
||||
rs_nxs_test::NxsTestHub::Wait(10);
|
||||
rs_nxs_test::NxsTestHub::Wait(15);
|
||||
|
||||
tHub.EndTest();
|
||||
|
||||
|
@ -45,7 +45,7 @@ TEST(libretroshare_serialiser, RsTlvFileItem)
|
||||
|
||||
/* initialise */
|
||||
i1.filesize = 101010;
|
||||
i1.hash = "ABCDEFEGHE";
|
||||
i1.hash = RsFileHash("ABCDEFEGHE");
|
||||
i1.name = "TestFile.txt";
|
||||
i1.pop = 12;
|
||||
i1.age = 456;
|
||||
@ -103,7 +103,7 @@ TEST(libretroshare_serialiser, RsTlvFileSet)
|
||||
{
|
||||
RsTlvFileItem fi;
|
||||
fi.filesize = 16 + i * i;
|
||||
fi.hash = "ABCDEF";
|
||||
fi.hash = RsFileHash("ABCDEF");
|
||||
std::ostringstream out;
|
||||
out << "File" << i << "_inSet.txt";
|
||||
fi.name = out.str();
|
||||
@ -130,7 +130,7 @@ TEST(libretroshare_serialiser, RsTlvFileData)
|
||||
|
||||
/* initialise */
|
||||
d1.file.filesize = 101010;
|
||||
d1.file.hash = "ABCDEFEGHE";
|
||||
d1.file.hash = RsFileHash("ABCDEFEGHE");
|
||||
d1.file.name = "";
|
||||
d1.file.age = 0;
|
||||
d1.file.pop = 0;
|
||||
|
@ -136,7 +136,7 @@ RsSerialType* init_item(RsTurtleOpenTunnelItem& item)
|
||||
item.depth = rand() ;
|
||||
item.request_id = rand() ;
|
||||
item.partial_tunnel_id = rand() ;
|
||||
item.file_hash = std::string("c0edcfecc0844ef175d61dd589ab288d262b6bc8") ;
|
||||
item.file_hash = RsFileHash("c0edcfecc0844ef175d61dd589ab288d262b6bc8") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleOpenTunnelItem& it1,const RsTurtleOpenTunnelItem& it2)
|
||||
@ -189,7 +189,7 @@ bool operator==(const RsTurtleStringSearchRequestItem& it1,const RsTurtleStringS
|
||||
}
|
||||
RsSerialType* init_item(TurtleFileInfo& info)
|
||||
{
|
||||
info.hash = "3f753e8ac3b94ab9fddfad94480f747bf4418370";
|
||||
info.hash = RsFileHash("3f753e8ac3b94ab9fddfad94480f747bf4418370");
|
||||
info.name = "toto.png";
|
||||
info.size = 0x3392085443897ull ;
|
||||
return new RsTurtleSerialiser();
|
||||
|
@ -63,13 +63,13 @@ TEST(libretroshare_serialiser, test_RsTlvStack)
|
||||
|
||||
/* initialise */
|
||||
fi1->filesize = 101010;
|
||||
fi1->hash = "ABCDEFEGHE";
|
||||
fi1->hash = RsFileHash("ABCDEFEGHE");
|
||||
fi1->name = "TestFile.txt";
|
||||
fi1->pop = 12;
|
||||
fi1->age = 456;
|
||||
|
||||
fi2->filesize = 101010;
|
||||
fi2->hash = "ABCDEFEGHE";
|
||||
fi2->hash = RsFileHash("ABCDEFEGHE");
|
||||
fi2->name = "TestFile.txt";
|
||||
fi2->pop = 0;
|
||||
fi2->age = 0;;
|
||||
|
@ -47,7 +47,7 @@ TEST(libretroshare_serialiser, test_RsTlvFileItem)
|
||||
|
||||
/* initialise */
|
||||
i1.filesize = 101010;
|
||||
i1.hash = "ABCDEFEGHE";
|
||||
i1.hash = RsFileHash("ABCDEFEGHE");
|
||||
i1.name = "TestFile.txt";
|
||||
i1.pop = 12;
|
||||
i1.age = 456;
|
||||
@ -105,7 +105,7 @@ TEST(libretroshare_serialiser, test_RsTlvFileSet)
|
||||
{
|
||||
RsTlvFileItem fi;
|
||||
fi.filesize = 16 + i * i;
|
||||
fi.hash = "ABCDEF";
|
||||
fi.hash = RsFileHash("ABCDEF");
|
||||
std::ostringstream out;
|
||||
out << "File" << i << "_inSet.txt";
|
||||
fi.name = out.str();
|
||||
|
Loading…
Reference in New Issue
Block a user