mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 00:49:28 -05:00
added tests for gxs update items
- need to fix to allow saving sync config git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs_finale@6936 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e50f017572
commit
972674173d
110
libretroshare/src/tests/serialiser/rsgxsupdateitem_test.cc
Normal file
110
libretroshare/src/tests/serialiser/rsgxsupdateitem_test.cc
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* rsgxsupdateitem_test.cc
|
||||
*
|
||||
* Created on: 9 Dec 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "support.h"
|
||||
#include "rsgxsupdateitem_test.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
RsSerialType* init_item(RsGxsGrpUpdateItem& i)
|
||||
{
|
||||
i.clear();
|
||||
i.grpUpdateTS = rand()%2424;
|
||||
randString(SHORT_STR, i.peerId);
|
||||
return new RsGxsUpdateSerialiser(0);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsGxsMsgUpdateItem& i)
|
||||
{
|
||||
i.clear();
|
||||
randString(SHORT_STR, i.peerId);
|
||||
int numUpdates = rand()%123;
|
||||
|
||||
std::string peer;
|
||||
for(int j=0; j < numUpdates; j++)
|
||||
{
|
||||
randString(SHORT_STR, peer);
|
||||
i.msgUpdateTS.insert(std::make_pair(peer, rand()%45));
|
||||
}
|
||||
|
||||
return new RsGxsUpdateSerialiser(0);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsGxsServerGrpUpdateItem& i)
|
||||
{
|
||||
i.clear();
|
||||
i.grpUpdateTS = rand()%2424;
|
||||
|
||||
return new RsGxsUpdateSerialiser(0);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsGxsServerMsgUpdateItem& i)
|
||||
{
|
||||
i.clear();
|
||||
randString(SHORT_STR, i.grpId);
|
||||
i.msgUpdateTS = rand()%4252;
|
||||
return new RsGxsUpdateSerialiser(0);
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsGrpUpdateItem& l, const RsGxsGrpUpdateItem& r)
|
||||
{
|
||||
bool ok = l.grpUpdateTS == r.grpUpdateTS;
|
||||
ok &= l.peerId == r.peerId;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsMsgUpdateItem& l, const RsGxsMsgUpdateItem& r)
|
||||
{
|
||||
bool ok = l.peerId == r.peerId;
|
||||
|
||||
const std::map<std::string, uint32_t>& lUp = l.msgUpdateTS, rUp = r.msgUpdateTS;
|
||||
|
||||
ok &= lUp.size() == rUp.size();
|
||||
|
||||
std::map<std::string, uint32_t>::const_iterator lit = lUp.begin(), rit;
|
||||
|
||||
for(; lit != lUp.end(); lit++)
|
||||
{
|
||||
std::string key = lit->first;
|
||||
if((rit = rUp.find(key)) != rUp.end())
|
||||
ok &= lit->second == rit->second;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsServerGrpUpdateItem& l,
|
||||
const RsGxsServerGrpUpdateItem& r)
|
||||
{
|
||||
return l.grpUpdateTS == r.grpUpdateTS;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsServerMsgUpdateItem& l,
|
||||
const RsGxsServerMsgUpdateItem& r)
|
||||
{
|
||||
bool ok = l.grpId == r.grpId;
|
||||
ok &= l.msgUpdateTS == r.msgUpdateTS;
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsGxsUpdateItem Tests" << std::endl;
|
||||
|
||||
test_RsItem<RsGxsGrpUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGxsGrpUpdateItem");
|
||||
test_RsItem<RsGxsMsgUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGxsMsgUpdateItem");
|
||||
test_RsItem<RsGxsServerGrpUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGxsServerGrpUpdateItem");
|
||||
test_RsItem<RsGxsServerMsgUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGxsServerMsgUpdateItem");
|
||||
|
||||
FINALREPORT("RsGxsUpdateItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
25
libretroshare/src/tests/serialiser/rsgxsupdateitem_test.h
Normal file
25
libretroshare/src/tests/serialiser/rsgxsupdateitem_test.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* rsgxsupdateitem_test.h
|
||||
*
|
||||
* Created on: 9 Dec 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef RSGXSUPDATEITEM_TEST_H_
|
||||
#define RSGXSUPDATEITEM_TEST_H_
|
||||
|
||||
#include "serialiser/rsgxsupdateitems.h"
|
||||
#include "support.h"
|
||||
|
||||
|
||||
RsSerialType* init_item(RsGxsGrpUpdateItem& i);
|
||||
RsSerialType* init_item(RsGxsMsgUpdateItem& i);
|
||||
RsSerialType* init_item(RsGxsServerGrpUpdateItem& i);
|
||||
RsSerialType* init_item(RsGxsServerMsgUpdateItem& i);
|
||||
|
||||
bool operator==(const RsGxsGrpUpdateItem& l, const RsGxsGrpUpdateItem& r);
|
||||
bool operator==(const RsGxsMsgUpdateItem& l, const RsGxsMsgUpdateItem& r);
|
||||
bool operator==(const RsGxsServerGrpUpdateItem& l, const RsGxsServerGrpUpdateItem& r);
|
||||
bool operator==(const RsGxsServerMsgUpdateItem& l, const RsGxsServerMsgUpdateItem& r);
|
||||
|
||||
#endif /* RSGXSUPDATEITEM_TEST_H_ */
|
Loading…
Reference in New Issue
Block a user