mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
system test code for rsgenexchange
initial attempt at msg retrieval test added dummy serialiser and dummy gxs items need to make some more compile fixes but essentials in place git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5463 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5a1115e6e4
commit
e1f54c239f
234
libretroshare/src/tests/gxs/genexchangetester.cpp
Normal file
234
libretroshare/src/tests/gxs/genexchangetester.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
#include "genexchangetester.h"
|
||||
#include "support.h"
|
||||
|
||||
|
||||
GenExchangeTester::GenExchangeTester(GenExchangeTestService* testService)
|
||||
: mTestService(testService)
|
||||
{
|
||||
mTokenService = mTestService->getTokenService();
|
||||
}
|
||||
|
||||
bool GenExchangeTester::testMsgSubmissionRetrieval()
|
||||
{
|
||||
RsDummyMsg* msg = new RsDummyMsg();
|
||||
init(msg);
|
||||
uint32_t token;
|
||||
mTestService->publishDummyMsg(token, msg);
|
||||
|
||||
// poll will block until found
|
||||
pollForToken(token);
|
||||
|
||||
if(mMsgIdsIn.empty())
|
||||
return false;
|
||||
|
||||
RsGxsMessageId& msgId = mMsgIdsIn.begin()->second;
|
||||
RsGxsGroupId& grpId = mMsgIdsIn.begin()->first;
|
||||
|
||||
GxsMsgReq req;
|
||||
req.insert(std::make_pair(msgId, grpId));
|
||||
|
||||
RsTokReqOptionsV2 opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
mTokenService->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_LIST, opts, req);
|
||||
|
||||
// poll again
|
||||
pollForToken(token);
|
||||
|
||||
mTestService->getMsgDataTS(token, mMsgDataIn);
|
||||
|
||||
bool ok = true;
|
||||
|
||||
if(mMsgDataIn.size() != mMsgDataOut.size()) return false;
|
||||
|
||||
GxsMsgDataMap::iterator mit = mMsgDataOut.begin();
|
||||
|
||||
for(; mit != mMsgDataOut.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId& gId = mit->first;
|
||||
|
||||
std::vector<RsGxsMsgItem*>& msgV_1 = mit->second,
|
||||
msgV_2 = mMsgDataIn[grpId];
|
||||
std::vector<RsGxsMsgItem*>::iterator vit1, vit2;
|
||||
|
||||
for(vit1 = msgV_1.begin(); vit1 = msgV_1.end();
|
||||
vit1++)
|
||||
{
|
||||
RsDummyMsg* lMsg = dynamic_cast<RsDummyMsg*>(*vit1);
|
||||
for(vit2 = msgV_2.begin(); vit2 = msgV_2.end();
|
||||
vit2++)
|
||||
{
|
||||
RsDummyMsg* rMsg = dynamic_cast<RsDummyMsg*>(*vit2);
|
||||
|
||||
if(rMsg->meta.mMsgId == lMsg->meta.mMsgId)
|
||||
ok &= *rMsg == *lMsg;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool GenExchangeTester::testMsgIdRetrieval()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GenExchangeTester::testSpecificMsgRetrieval()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GenExchangeTester::testGrpIdRetrieval()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GenExchangeTester::testGrpStatusRequest()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// helper functions
|
||||
|
||||
void GenExchangeTester::storeMsgData(GxsMsgDataMap &msgData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GenExchangeTester::storeGrpData(GxsMsgDataMap &grpData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GenExchangeTester::storeGrpId(GxsMsgIdResult &grpIds)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GenExchangeTester::storeMsgData(GxsMsgDataMap &msgData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTester::storeMsgMeta(GxsMsgMetaMap &msgMetaData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GenExchangeTester::storeMsgIds(GxsMsgIdResult &msgIds)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTester::init(RsGroupMetaData &grpMeta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GenExchangeTester::init(RsMsgMetaData &msgMeta)
|
||||
{
|
||||
randString(LARGE_STR, msgMeta.mAuthorId);
|
||||
randString(LARGE_STR, msgMeta.mMsgName);
|
||||
randString(LARGE_STR, msgMeta.mServiceString);
|
||||
randString(LARGE_STR, msgMeta.mOrigMsgId);
|
||||
randString(LARGE_STR, msgMeta.mParentId);
|
||||
randString(LARGE_STR, msgMeta.mThreadId);
|
||||
randString(LARGE_STR, msgMeta.mGroupId);
|
||||
|
||||
randNum(msgMeta.mChildTs);
|
||||
randNum(msgMeta.mMsgStatus);
|
||||
randNum(msgMeta.mMsgFlags);
|
||||
randNum(msgMeta.mPublishTs);
|
||||
}
|
||||
|
||||
void randNum(uint32_t& num)
|
||||
{
|
||||
num = rand()%23562424;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTester::operator ==(const RsMsgMetaData& lMeta, const RsMsgMetaData& rMeta)
|
||||
{
|
||||
|
||||
if(lMeta.mAuthorId != rMeta.mAuthorId) return false;
|
||||
if(lMeta.mChildTs != rMeta.mChildTs) return false;
|
||||
if(lMeta.mGroupId != rMeta.mGroupId) return false;
|
||||
if(lMeta.mMsgFlags != rMeta.mMsgFlags) return false;
|
||||
if(lMeta.mMsgId != rMeta.mMsgId) return false;
|
||||
if(lMeta.mMsgName != rMeta.mMsgName) return false;
|
||||
if(lMeta.mMsgStatus != rMeta.mMsgStatus) return false;
|
||||
if(lMeta.mOrigMsgId != rMeta.mOrigMsgId) return false;
|
||||
if(lMeta.mParentId != rMeta.mParentId) return false;
|
||||
if(lMeta.mPublishTs != rMeta.mPublishTs) return false;
|
||||
if(lMeta.mThreadId != rMeta.mThreadId) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsDummyMsg& lMsg, const RsDummyMsg& rMsg)
|
||||
{
|
||||
if(lMsg.msgData != rMsg.msgData) return false;
|
||||
if(!(lMsg.meta == rMsg.meta)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GenExchangeTester::init(RsGxsGrpItem *grpItem)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GenExchangeTester::init(RsDummyMsg *msgItem)
|
||||
{
|
||||
randString(LARGE_STR, msgItem->msgData);
|
||||
init(msgItem->meta);
|
||||
}
|
||||
|
||||
void GenExchangeTester::pollForToken(uint32_t token)
|
||||
{
|
||||
double timeDelta = 0.2;
|
||||
|
||||
while(true)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
if(RsTokenServiceV2::GXS_REQUEST_STATUS_COMPLETE ==
|
||||
mTokenService->requestStatus(token))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GenExchangeTester::setUp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GenExchangeTester::setUpGrps()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GenExchangeTester::breakDown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
75
libretroshare/src/tests/gxs/genexchangetester.h
Normal file
75
libretroshare/src/tests/gxs/genexchangetester.h
Normal file
@ -0,0 +1,75 @@
|
||||
#ifndef GENEXCHANGETESTER_H
|
||||
#define GENEXCHANGETESTER_H
|
||||
|
||||
#include "genexchangetestservice.h"
|
||||
|
||||
/*!
|
||||
* The job of the service tester is to send dummy msg items to the GenExchange service
|
||||
* and then retrieve them (ignoring ackowledge message)
|
||||
* Also it modifies local meta items and check if it worked out
|
||||
*/
|
||||
class GenExchangeTester
|
||||
{
|
||||
public:
|
||||
|
||||
void pollForToken(uint32_t);
|
||||
|
||||
GenExchangeTester(GenExchangeTestService* testService);
|
||||
|
||||
bool testMsgSubmissionRetrieval();
|
||||
bool testMsgIdRetrieval();
|
||||
bool testSpecificMsgRetrieval();
|
||||
|
||||
bool testGrpSubmissionRetrieval();
|
||||
bool testSpecificGrpRetrieval();
|
||||
bool testGrpIdRetrieval();
|
||||
|
||||
bool testGrpSubscribeRequest();
|
||||
bool testGrpStatusRequest();
|
||||
|
||||
private:
|
||||
|
||||
// to be called at start
|
||||
void setUp();
|
||||
|
||||
// and at end of test routines, resets db and clears out maps
|
||||
void breakDown();
|
||||
|
||||
|
||||
void setUpGrps(); // to be called at start of msg tests
|
||||
|
||||
void storeMsgData(GxsMsgDataMap& msgData);
|
||||
void storeMsgMeta(GxsMsgMetaMap& msgMetaData);
|
||||
void storeMsgIds(GxsMsgIdResult& msgIds);
|
||||
|
||||
void storeGrpData(GxsMsgDataMap& grpData);
|
||||
void storeGrpMeta(GxsMsgMetaMap& grpMetaData);
|
||||
void storeGrpId(GxsMsgIdResult& grpIds);
|
||||
|
||||
void init(RsDummyGrp* grpItem);
|
||||
void init(RsGroupMetaData&);
|
||||
void init(RsDummyMsg* msgItem);
|
||||
void init(RsMsgMetaData&);
|
||||
|
||||
bool operator ==(const RsMsgMetaData& lMeta, const RsMsgMetaData& rMeta);
|
||||
bool operator ==(const RsDummyMsg& lMsg, const RsDummyMsg& rMsg);
|
||||
|
||||
private:
|
||||
|
||||
RsMutex mGenTestMutex;
|
||||
|
||||
GxsMsgDataMap mGrpDataOut, mGrpDataIn;
|
||||
GxsMsgMetaMap mGrpMetaDataOut, mGrpMetaDataIn;
|
||||
GxsMsgIdResult mGrpIdsOut, mGrpIdsIn;
|
||||
|
||||
GxsMsgDataMap mMsgDataOut, mMsgDataIn;
|
||||
GxsMsgMetaMap mMsgMetaDataOut, mMsgMetaDataIn;
|
||||
GxsMsgIdResult mMsgIdsOut, mMsgIdsIn;
|
||||
|
||||
private:
|
||||
|
||||
GenExchangeTestService* mTestService;
|
||||
RsTokenServiceV2* mTokenService;
|
||||
};
|
||||
|
||||
#endif // GENEXCHANGETESTER_H
|
52
libretroshare/src/tests/gxs/genexchangetestservice.cpp
Normal file
52
libretroshare/src/tests/gxs/genexchangetestservice.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "genexchangetestservice.h"
|
||||
|
||||
GenExchangeTestService::GenExchangeTestService(RsGeneralDataService *dataServ, RsNetworkExchangeService * netService)
|
||||
: RsGenExchange(dataServ, netService)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GenExchangeTestService::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void GenExchangeTestService::publishDummyGrp(uint32_t &token, RsDummyGrp *grp)
|
||||
{
|
||||
publishGroup(token, grp);
|
||||
}
|
||||
|
||||
void GenExchangeTestService::publishDummyMsg(uint32_t &token, RsDummyMsg *msg)
|
||||
{
|
||||
publishMsg(token, msg);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getGroupListTS(const uint32_t &token, std::list<RsGxsGroupId> &groupIds)
|
||||
{
|
||||
return getGroupList(token, groupIds);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getGroupMetaTS(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
|
||||
{
|
||||
return getGroupMeta(token, groupInfo);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getGroupDataTS(const uint32_t &token, std::vector<RsGxsGrpItem *> &grpItem)
|
||||
{
|
||||
return getGroupData(token, grpItem);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgDataTS(const uint32_t &token, GxsMsgDataMap &msgItems)
|
||||
{
|
||||
return getMsgData(token, msgItems);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgMetaTS(const uint32_t &token, GxsMsgMetaMap &msgInfo)
|
||||
{
|
||||
return getMsgMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgListTS(const uint32_t &token, GxsMsgIdResult &msgIds)
|
||||
{
|
||||
return getMsgList(token, msgIds);
|
||||
}
|
64
libretroshare/src/tests/gxs/genexchangetestservice.h
Normal file
64
libretroshare/src/tests/gxs/genexchangetestservice.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef GENEXCHANGETESTSERVICE_H
|
||||
#define GENEXCHANGETESTSERVICE_H
|
||||
|
||||
#include "gxs/rsgenexchange.h"
|
||||
#include "rsdummyservices.h"
|
||||
|
||||
class GenExchangeTestService : public RsGenExchange
|
||||
{
|
||||
public:
|
||||
GenExchangeTestService(RsGeneralDataService* dataServ, RsNetworkExchangeService*);
|
||||
|
||||
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
void publishDummyGrp(uint32_t& token, RsDummyGrp* grp);
|
||||
void publishDummyMsg(uint32_t& token, RsDummyMsg* msg);
|
||||
|
||||
|
||||
/*!
|
||||
* Retrieve group list for a given token
|
||||
* @param token
|
||||
* @param groupIds
|
||||
* @return false if token cannot be redeemed, if false you may have tried to redeem when not ready
|
||||
*/
|
||||
bool getGroupListTS(const uint32_t &token, std::list<RsGxsGroupId> &groupIds);
|
||||
|
||||
/*!
|
||||
* Retrieve msg list for a given token sectioned by group Ids
|
||||
* @param token token to be redeemed
|
||||
* @param msgIds a map of grpId -> msgList (vector)
|
||||
*/
|
||||
bool getMsgListTS(const uint32_t &token, GxsMsgIdResult &msgIds);
|
||||
|
||||
|
||||
/*!
|
||||
* retrieve group meta data associated to a request token
|
||||
* @param token
|
||||
* @param groupInfo
|
||||
*/
|
||||
bool getGroupMetaTS(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
|
||||
|
||||
/*!
|
||||
* retrieves message meta data associated to a request token
|
||||
* @param token token to be redeemed
|
||||
* @param msgInfo the meta data to be retrieved for token store here
|
||||
*/
|
||||
bool getMsgMetaTS(const uint32_t &token, GxsMsgMetaMap &msgInfo);
|
||||
|
||||
/*!
|
||||
* retrieves group data associated to a request token
|
||||
* @param token token to be redeemed for grpitem retrieval
|
||||
* @param grpItem the items to be retrieved for token are stored here
|
||||
*/
|
||||
bool getGroupDataTS(const uint32_t &token, std::vector<RsGxsGrpItem*>& grpItem);
|
||||
|
||||
/*!
|
||||
* retrieves message data associated to a request token
|
||||
* @param token token to be redeemed for message item retrieval
|
||||
* @param msgItems
|
||||
*/
|
||||
bool getMsgDataTS(const uint32_t &token, GxsMsgDataMap& msgItems);
|
||||
|
||||
};
|
||||
|
||||
#endif // GENEXCHANGETESTSERVICE_H
|
226
libretroshare/src/tests/gxs/rsdummyservices.cc
Normal file
226
libretroshare/src/tests/gxs/rsdummyservices.cc
Normal file
@ -0,0 +1,226 @@
|
||||
|
||||
|
||||
#include "rsdummyservices.h"
|
||||
|
||||
|
||||
uint32_t RsDummySerialiser::size(RsItem *item)
|
||||
{
|
||||
RsDummyMsg* msg;
|
||||
RsDummyGrp* grp;
|
||||
|
||||
if( (msg = dynamic_cast<RsDummyMsg*>(item)) != NULL )
|
||||
{
|
||||
return sizeDummyMsgItem(msg);
|
||||
}else if( (grp = dynamic_cast<RsDummyGrp*>(item)) != NULL )
|
||||
{
|
||||
return sizeDummyGrpItem(grp);
|
||||
}else
|
||||
{
|
||||
std::cerr << "RsDummySerialiser::size(RsItem *item) Error with dummy cast!\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool RsDummySerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsDummyMsg* msg;
|
||||
RsDummyGrp* grp;
|
||||
|
||||
if( (msg = dynamic_cast<RsDummyMsg*>(item)) != NULL )
|
||||
{
|
||||
return serialiseDummyMsgItem(msg, data, size);
|
||||
}else if( (grp = dynamic_cast<RsDummyGrp*>(item)) != NULL )
|
||||
{
|
||||
return serialiseDummyGrpItem(grp, data, size);
|
||||
}else
|
||||
{
|
||||
std::cerr << "RsDummySerialiser::size(RsItem *item) Error with dummy cast!\n";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsDummySerialiser::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_DUMMY != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DUMMY_MSG:
|
||||
return deserialiseDummyMsgItem(data, size);
|
||||
case RS_PKT_SUBTYPE_DUMMY_GRP:
|
||||
return deserialiseDummyGrpItem(data, size);
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsDummySerialiser::sizeDummyMsgItem(RsDummyMsg *item)
|
||||
{
|
||||
s += 8; // header
|
||||
s += GetTlvStringSize(item->msgData);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsDummySerialiser::serialiseDummyMsgItem (RsDummyMsg *item, void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t tlvsize = sizeDummyMsgItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*size < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* RsDistribMsg first */
|
||||
|
||||
ok &= SetTlvString(data, *size, &offset, 1, item->msgData);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsDummySerialiser::serialiseDummyMsgItem Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsDummyMsg * RsDummySerialiser::deserialiseDummyMsgItem(void *data, uint32_t *size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_DUMMY != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_DUMMY_MSG != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsDummyMsg *item = new RsDummyMsg();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, *size, offset, 1, item->msgData);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
uint32_t RsDummySerialiser::sizeDummyGrpItem(RsDummyGrp *item)
|
||||
{
|
||||
s += 8;
|
||||
s += GetTlvStringSize(item->grpData);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsDummySerialiser::serialiseDummyGrpItem (RsDummyGrp *item, void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t tlvsize = sizeDummyGrpItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*size < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= SetTlvString(data, *size, &offset, 1, item->grpData);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsDummySerialiser::serialiseDummyGrpItem Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsDummyGrp * RsDummySerialiser::deserialiseDummyGrpItem(void *data, uint32_t *size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_DUMMY != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_DUMMY_GRP != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsDummyGrp *item = new RsDummyGrp();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, *size, offset, 1, item->grpData);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
94
libretroshare/src/tests/gxs/rsdummyservices.h
Normal file
94
libretroshare/src/tests/gxs/rsdummyservices.h
Normal file
@ -0,0 +1,94 @@
|
||||
#ifndef RSDUMMYSERVICES_H
|
||||
#define RSDUMMYSERVICES_H
|
||||
|
||||
|
||||
// dummy services to make
|
||||
|
||||
#include "gxs/rsnxs.h"
|
||||
#include "serialiser/rsgxsitems.h"
|
||||
|
||||
class RsDummyNetService: public RsNetworkExchangeService
|
||||
{
|
||||
public:
|
||||
|
||||
RsNetworkExchangeService(){ return;}
|
||||
|
||||
void setSyncAge(uint32_t age){}
|
||||
|
||||
void requestGroupsOfPeer(const std::string& peerId){}
|
||||
|
||||
void requestMessagesOfPeer(const std::string& peerId, const std::string& grpId){}
|
||||
|
||||
void pauseSynchronisation(bool enabled) {}
|
||||
|
||||
int requestMsg(const std::string& msgId, uint8_t hops){ return 0;}
|
||||
|
||||
int requestGrp(const std::list<std::string>& grpId, uint8_t hops) { return 0;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint16_t RS_SERVICE_TYPE_DUMMY = 0x01;
|
||||
uint8_t RS_PKT_SUBTYPE_DUMMY_MSG = 0x02;
|
||||
uint8_t RS_PKT_SUBTYPE_DUMMY_GRP = 0x03;
|
||||
|
||||
|
||||
class RsDummyMsg : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsDummyMsg() : RsGxsMsgItem(RS_SERVICE_TYPE_DUMMY, RS_PKT_SUBTYPE_DUMMY_MSG) { return; }
|
||||
virtual RsDummyMsg() { return; }
|
||||
|
||||
std::string msgData;
|
||||
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0){ return out; }
|
||||
void clear() { msgData.clear(); }
|
||||
|
||||
};
|
||||
|
||||
class RsDummyGrp : public RsGxsGrpItem
|
||||
{
|
||||
RsDummyGrp() : RsGxsGrpItem(RS_SERVICE_TYPE_DUMMY, RS_PKT_SUBTYPE_DUMMY_GRP) { return; }
|
||||
virtual RsDummyGrp() { return; }
|
||||
|
||||
|
||||
|
||||
std::string grpData;
|
||||
void clear() { grpData.clear(); }
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0){ return out; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RsDummySerialiser : public RsSerialType
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
RsDummySerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DUMMY)
|
||||
{ return; }
|
||||
virtual ~RsGxsPhotoSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeDummyMsgItem(RsDummyMsg *item);
|
||||
bool serialiseDummyMsgItem (RsDummyMsg *item, void *data, uint32_t *size);
|
||||
RsDummyMsg * deserialiseDummyMsgItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeDummyGrpItem(RsDummyGrp *item);
|
||||
bool serialiseDummyGrpItem (RsDummyGrp *item, void *data, uint32_t *size);
|
||||
RsDummyGrp * deserialiseDummyGrpItem(void *data, uint32_t *size);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // RSDUMMYSERVICES_H
|
28
libretroshare/src/tests/gxs/rsgenexchange_test.cc
Normal file
28
libretroshare/src/tests/gxs/rsgenexchange_test.cc
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
#include "genexchangetester.h"
|
||||
#include "genexchangetestservice.h"
|
||||
#include "util/utest.h"
|
||||
#include "gxs/gxscoreserver.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "rsdummyservices.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
GxsCoreServer gxsCore;
|
||||
|
||||
// create data service and dummy net service
|
||||
RsDummyNetService dummyNet;
|
||||
RsDataService dataStore("./", "testServiceDb", 0, NULL);
|
||||
GenExchangeTestService testService;
|
||||
gxsCore.addService(&testService);
|
||||
createThread(gxsCore);
|
||||
|
||||
|
||||
|
||||
}
|
62
libretroshare/src/tests/gxs/rsgenexhchange_test.pro
Normal file
62
libretroshare/src/tests/gxs/rsgenexhchange_test.pro
Normal file
@ -0,0 +1,62 @@
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = rsgenexcahnge_test
|
||||
|
||||
|
||||
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
|
||||
|
||||
# PRE_TARGETDEPS += ../../libretroshare/src/lib/libretroshare.a
|
||||
PRE_TARGETDEPS += C:\Development\Rs\v0.5-gxs-b1/libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
|
||||
LIBS += C:\Development\Rs\v0.5-gxs-b1/libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
LIBS += C:\Development\Rs\v0.5-gxs-b1\openpgpsdk\openpgpsdk-build-desktop\lib\libops.a
|
||||
LIBS += C:\Development\Libraries\sqlite\sqlite-autoconf-3070900\lib\libsqlite3.a
|
||||
LIBS += -L"../../../lib"
|
||||
LIBS += -lssl -lcrypto -lgpgme -lpthreadGC2d -lminiupnpc -lz -lbz2
|
||||
# added after bitdht
|
||||
# LIBS += -lws2_32
|
||||
LIBS += -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lgdi32
|
||||
LIBS += -lole32 -lwinmm
|
||||
RC_FILE = gui/images/retroshare_win.rc
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
INCLUDEPATH += C:\Development\Rs\v0.5-gxs-b1\libretroshare\src
|
||||
|
||||
HEADERS += \
|
||||
genexchangetestservice.h \
|
||||
genexchangetester.h \
|
||||
rsdummyservices.h \
|
||||
support.h
|
||||
|
||||
SOURCES += \
|
||||
genexchangetestservice.cpp \
|
||||
genexchangetester.cpp \
|
||||
rsgenexchange_test.cc \
|
||||
support.cc \
|
||||
rsdummyservices.cc
|
Loading…
Reference in New Issue
Block a user