improved tests to avoid memory leak

This commit is contained in:
csoler 2017-07-24 12:16:06 +02:00
parent 764fadf0ee
commit df691bd2d7
12 changed files with 120 additions and 141 deletions

View File

@ -151,7 +151,7 @@ void init_item(RsGxsMsgMetaData* metaMsg)
RsSerialType* init_item(RsNxsGrp& nxg) void init_item(RsNxsGrp& nxg,RsSerialType **ser)
{ {
nxg.clear(); nxg.clear();
@ -160,11 +160,12 @@ RsSerialType* init_item(RsNxsGrp& nxg)
init_item(nxg.grp); init_item(nxg.grp);
init_item(nxg.meta); init_item(nxg.meta);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); if(ser)
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsNxsMsg& nxm) void init_item(RsNxsMsg& nxm,RsSerialType **ser)
{ {
nxm.clear(); nxm.clear();
@ -174,20 +175,22 @@ RsSerialType* init_item(RsNxsMsg& nxm)
init_item(nxm.meta); init_item(nxm.meta);
nxm.transactionNumber = rand()%23; nxm.transactionNumber = rand()%23;
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); if(ser)
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsNxsSyncGrpReqItem& rsg) void init_item(RsNxsSyncGrpReqItem& rsg,RsSerialType **ser)
{ {
rsg.clear(); rsg.clear();
rsg.flag = RsNxsSyncGrpItem::FLAG_USE_SYNC_HASH; rsg.flag = RsNxsSyncGrpItem::FLAG_USE_SYNC_HASH;
rsg.createdSince = rand()%2423; rsg.createdSince = rand()%2423;
randString(3124,rsg.syncHash); randString(3124,rsg.syncHash);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); if(ser)
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsNxsSyncMsgReqItem& rsgm) void init_item(RsNxsSyncMsgReqItem& rsgm,RsSerialType **ser)
{ {
rsgm.clear(); rsgm.clear();
@ -197,10 +200,11 @@ RsSerialType* init_item(RsNxsSyncMsgReqItem& rsgm)
init_random(rsgm.grpId) ; init_random(rsgm.grpId) ;
randString(SHORT_STR, rsgm.syncHash); randString(SHORT_STR, rsgm.syncHash);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); if(ser)
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsNxsSyncGrpItem& rsgl) void init_item(RsNxsSyncGrpItem& rsgl,RsSerialType **ser)
{ {
rsgl.clear(); rsgl.clear();
@ -209,10 +213,11 @@ RsSerialType* init_item(RsNxsSyncGrpItem& rsgl)
rsgl.publishTs = rand()%23; rsgl.publishTs = rand()%23;
init_random(rsgl.grpId) ; init_random(rsgl.grpId) ;
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); if(ser)
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsNxsSyncMsgItem& rsgml) void init_item(RsNxsSyncMsgItem& rsgml,RsSerialType **ser)
{ {
rsgml.clear(); rsgml.clear();
@ -221,11 +226,12 @@ RsSerialType* init_item(RsNxsSyncMsgItem& rsgml)
init_random(rsgml.grpId) ; init_random(rsgml.grpId) ;
init_random(rsgml.msgId) ; init_random(rsgml.msgId) ;
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); if(ser)
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsNxsTransacItem &rstx){ void init_item(RsNxsTransacItem &rstx,RsSerialType **ser)
{
rstx.clear(); rstx.clear();
rstx.timestamp = rand()%14141; rstx.timestamp = rand()%14141;
@ -233,7 +239,8 @@ RsSerialType* init_item(RsNxsTransacItem &rstx){
rstx.nItems = rand()%33132; rstx.nItems = rand()%33132;
rstx.transactionNumber = rand()%242112; rstx.transactionNumber = rand()%242112;
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); if(ser)
*ser = new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }

View File

@ -21,13 +21,13 @@ void init_item(RsGxsGrpMetaData* metaGrp);
void init_item(RsGxsMsgMetaData* metaMsg); void init_item(RsGxsMsgMetaData* metaMsg);
RsSerialType* init_item(RsNxsGrp& nxg); void init_item(RsNxsGrp& nxg ,RsSerialType ** = NULL);
RsSerialType* init_item(RsNxsMsg& nxm); void init_item(RsNxsMsg& nxm ,RsSerialType ** = NULL);
RsSerialType* init_item(RsNxsSyncGrpReqItem &rsg); void init_item(RsNxsSyncGrpReqItem &rsg ,RsSerialType ** = NULL);
RsSerialType* init_item(RsNxsSyncMsgReqItem &rsgm); void init_item(RsNxsSyncMsgReqItem &rsgm,RsSerialType ** = NULL);
RsSerialType* init_item(RsNxsSyncGrpItem& rsgl); void init_item(RsNxsSyncGrpItem& rsgl ,RsSerialType ** = NULL);
RsSerialType* init_item(RsNxsSyncMsgItem& rsgml); void init_item(RsNxsSyncMsgItem& rsgml ,RsSerialType ** = NULL);
RsSerialType* init_item(RsNxsTransacItem& rstx); void init_item(RsNxsTransacItem& rstx ,RsSerialType ** = NULL);
template<typename T> template<typename T>
void copy_all_but(T& ex, const std::list<T>& s, std::list<T>& d) void copy_all_but(T& ex, const std::list<T>& s, std::list<T>& d)

View File

@ -5,6 +5,7 @@
#include "libretroshare/gxs/common/data_support.h" #include "libretroshare/gxs/common/data_support.h"
#include "rsdataservice_test.h" #include "rsdataservice_test.h"
#include "gxs/rsgds.h" #include "gxs/rsgds.h"
#include "gxs/rsgxsutil.h"
#include "gxs/rsdataservice.h" #include "gxs/rsdataservice.h"
#define DATA_BASE_NAME "msg_grp_Store" #define DATA_BASE_NAME "msg_grp_Store"
@ -221,7 +222,8 @@ void test_messageStoresAndRetrieve()
// first selective retrieval // first selective retrieval
GxsMsgResult msgResult; GxsMsgResult msgResult;
GxsMsgMetaResult msgMetaResult;
RsGxsMetaDataTemporaryMapVector<RsGxsMsgMetaData> msgMetaResult ;
dStore->retrieveNxsMsgs(req, msgResult, false); dStore->retrieveNxsMsgs(req, msgResult, false);
dStore->retrieveGxsMsgMetaData(req, msgMetaResult); dStore->retrieveGxsMsgMetaData(req, msgMetaResult);

View File

@ -38,11 +38,9 @@ bool operator==(const RsGxsIdGroupItem& it1,const RsGxsIdGroupItem& it2)
return true ; return true ;
} }
RsSerialType* init_item(RsGxsIdGroupItem& item) void init_item(RsGxsIdGroupItem& item)
{ {
item.mPgpIdSign = "hello"; item.mPgpIdSign = "hello";
return new RsGxsIdSerialiser();
} }
@ -50,7 +48,7 @@ TEST(libretroshare_serialiser, RsGxsIdItem)
{ {
for(uint32_t i=0;i<20;++i) for(uint32_t i=0;i<20;++i)
{ {
test_RsItem< RsGxsIdGroupItem >(); test_RsItem< RsGxsIdGroupItem,RsGxsIdSerialiser >();
} }
} }

View File

@ -11,15 +11,14 @@
#include "rsitems/rsgxsupdateitems.h" #include "rsitems/rsgxsupdateitems.h"
#define RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM 0x0010 #define RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM 0x0010
RsSerialType* init_item(RsGxsGrpUpdateItem& i) void init_item(RsGxsGrpUpdateItem& i)
{ {
i.clear(); i.clear();
i.grpUpdateTS = rand()%2424; i.grpUpdateTS = rand()%2424;
i.peerID = RsPeerId::random(); i.peerID = RsPeerId::random();
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsGxsMsgUpdateItem& i) void init_item(RsGxsMsgUpdateItem& i)
{ {
i.clear(); i.clear();
i.peerID = RsPeerId::random(); i.peerID = RsPeerId::random();
@ -33,24 +32,19 @@ RsSerialType* init_item(RsGxsMsgUpdateItem& i)
info.time_stamp = rand()%45; info.time_stamp = rand()%45;
i.msgUpdateInfos[RsGxsGroupId::random()] = info; i.msgUpdateInfos[RsGxsGroupId::random()] = info;
} }
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsGxsServerGrpUpdateItem& i) void init_item(RsGxsServerGrpUpdateItem& i)
{ {
i.clear(); i.clear();
i.grpUpdateTS = rand()%2424; i.grpUpdateTS = rand()%2424;
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
RsSerialType* init_item(RsGxsServerMsgUpdateItem& i) void init_item(RsGxsServerMsgUpdateItem& i)
{ {
i.clear(); i.clear();
i.grpId = RsGxsGroupId::random(); i.grpId = RsGxsGroupId::random();
i.msgUpdateTS = rand()%4252; i.msgUpdateTS = rand()%4252;
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }
bool operator ==(const RsGxsGrpUpdateItem& l, const RsGxsGrpUpdateItem& r) bool operator ==(const RsGxsGrpUpdateItem& l, const RsGxsGrpUpdateItem& r)
@ -105,8 +99,8 @@ bool operator ==(const RsGxsServerMsgUpdateItem& l,
TEST(libretroshare_serialiser, RsGxsGrpUpateItem) TEST(libretroshare_serialiser, RsGxsGrpUpateItem)
{ {
test_RsItem<RsGxsGrpUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsGxsGrpUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsGxsMsgUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsGxsMsgUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsGxsServerGrpUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsGxsServerGrpUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsGxsServerMsgUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsGxsServerMsgUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }

View File

@ -33,19 +33,16 @@
#include "rstlvutil.h" #include "rstlvutil.h"
RsSerialType* init_item(RsChatMsgItem& cmi) void init_item(RsChatMsgItem& cmi)
{ {
cmi.chatFlags = rand()%34; cmi.chatFlags = rand()%34;
cmi.sendTime = rand()%422224; cmi.sendTime = rand()%422224;
randString(LARGE_STR, cmi.message); randString(LARGE_STR, cmi.message);
return new RsChatSerialiser();
} }
RsSerialType* init_item(RsChatLobbyListRequestItem& ) void init_item(RsChatLobbyListRequestItem& )
{ {
return new RsChatSerialiser();
} }
RsSerialType* init_item(RsChatLobbyListItem& cmi) void init_item(RsChatLobbyListItem& cmi)
{ {
int n = rand()%20 ; int n = rand()%20 ;
@ -59,41 +56,33 @@ RsSerialType* init_item(RsChatLobbyListItem& cmi)
info.flags = ChatLobbyFlags(RSRandom::random_u32()%3) ; info.flags = ChatLobbyFlags(RSRandom::random_u32()%3) ;
cmi.lobbies.push_back(info); cmi.lobbies.push_back(info);
} }
return new RsChatSerialiser();
} }
RsSerialType* init_item(RsChatLobbyMsgItem& cmi) void init_item(RsChatLobbyMsgItem& cmi)
{ {
RsSerialType *serial = init_item( *dynamic_cast<RsChatMsgItem*>(&cmi)) ; init_item( *dynamic_cast<RsChatMsgItem*>(&cmi)) ;
cmi.msg_id = RSRandom::random_u64() ; cmi.msg_id = RSRandom::random_u64() ;
cmi.lobby_id = RSRandom::random_u64() ; cmi.lobby_id = RSRandom::random_u64() ;
cmi.nick = "My nickname" ; cmi.nick = "My nickname" ;
cmi.parent_msg_id = RSRandom::random_u64() ; cmi.parent_msg_id = RSRandom::random_u64() ;
return serial ;
} }
RsSerialType *init_item(RsChatLobbyEventItem& cmi) void init_item(RsChatLobbyEventItem& cmi)
{ {
cmi.lobby_id = RSRandom::random_u64() ; cmi.lobby_id = RSRandom::random_u64() ;
cmi.msg_id = RSRandom::random_u64() ; cmi.msg_id = RSRandom::random_u64() ;
randString(20, cmi.nick); randString(20, cmi.nick);
cmi.event_type = RSRandom::random_u32()%256 ; cmi.event_type = RSRandom::random_u32()%256 ;
randString(20, cmi.string1); randString(20, cmi.string1);
return new RsChatSerialiser();
} }
RsSerialType* init_item(RsChatLobbyInviteItem& cmi) void init_item(RsChatLobbyInviteItem& cmi)
{ {
cmi.lobby_id = RSRandom::random_u64() ; cmi.lobby_id = RSRandom::random_u64() ;
cmi.lobby_name = "Name of the lobby" ; cmi.lobby_name = "Name of the lobby" ;
cmi.lobby_topic = "Topic of the lobby" ; cmi.lobby_topic = "Topic of the lobby" ;
return new RsChatSerialiser();
} }
RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi) void init_item(RsPrivateChatMsgConfigItem& pcmi)
{ {
pcmi.configPeerId = RsPeerId::random(); pcmi.configPeerId = RsPeerId::random();
pcmi.chatFlags = rand()%34; pcmi.chatFlags = rand()%34;
@ -101,21 +90,17 @@ RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi)
pcmi.sendTime = rand()%422224; pcmi.sendTime = rand()%422224;
randString(LARGE_STR, pcmi.message); randString(LARGE_STR, pcmi.message);
pcmi.recvTime = rand()%344443; pcmi.recvTime = rand()%344443;
return new RsChatSerialiser();
} }
RsSerialType* init_item(RsChatStatusItem& csi) void init_item(RsChatStatusItem& csi)
{ {
randString(SHORT_STR, csi.status_string); randString(SHORT_STR, csi.status_string);
csi.flags = rand()%232; csi.flags = rand()%232;
return new RsChatSerialiser();
} }
RsSerialType* init_item(RsChatAvatarItem& cai) void init_item(RsChatAvatarItem& cai)
{ {
std::string image_data; std::string image_data;
randString(LARGE_STR, image_data); randString(LARGE_STR, image_data);
@ -123,11 +108,9 @@ RsSerialType* init_item(RsChatAvatarItem& cai)
memcpy(cai.image_data, image_data.c_str(), image_data.size()); memcpy(cai.image_data, image_data.c_str(), image_data.size());
cai.image_size = image_data.size(); cai.image_size = image_data.size();
return new RsChatSerialiser();
} }
RsSerialType* init_item(RsMsgItem& mi) void init_item(RsMsgItem& mi)
{ {
init_item(mi.attachment); init_item(mi.attachment);
init_item(mi.rspeerid_msgbcc); init_item(mi.rspeerid_msgbcc);
@ -141,21 +124,17 @@ RsSerialType* init_item(RsMsgItem& mi)
mi.recvTime = rand()%44252; mi.recvTime = rand()%44252;
mi.sendTime = mi.recvTime; mi.sendTime = mi.recvTime;
mi.msgFlags = mi.recvTime; mi.msgFlags = mi.recvTime;
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
} }
RsSerialType* init_item(RsMsgTagType& mtt) void init_item(RsMsgTagType& mtt)
{ {
mtt.rgb_color = rand()%5353; mtt.rgb_color = rand()%5353;
mtt.tagId = rand()%24242; mtt.tagId = rand()%24242;
randString(SHORT_STR, mtt.text); randString(SHORT_STR, mtt.text);
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
} }
RsSerialType* init_item(RsMsgTags& mt) void init_item(RsMsgTags& mt)
{ {
mt.msgId = rand()%3334; mt.msgId = rand()%3334;
@ -163,24 +142,18 @@ RsSerialType* init_item(RsMsgTags& mt)
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
mt.tagIds.push_back(rand()%21341); mt.tagIds.push_back(rand()%21341);
} }
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
} }
RsSerialType* init_item(RsMsgSrcId& ms) void init_item(RsMsgSrcId& ms)
{ {
ms.msgId = rand()%434; ms.msgId = rand()%434;
ms.srcId = RsPeerId::random(); ms.srcId = RsPeerId::random();
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
} }
RsSerialType* init_item(RsMsgParentId& ms) void init_item(RsMsgParentId& ms)
{ {
ms.msgId = rand()%354; ms.msgId = rand()%354;
ms.msgParentId = rand()%476; ms.msgParentId = rand()%476;
return new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE);
} }
bool operator ==(const struct VisibleChatLobbyInfo& l, const struct VisibleChatLobbyInfo& r) bool operator ==(const struct VisibleChatLobbyInfo& l, const struct VisibleChatLobbyInfo& r)
@ -335,19 +308,19 @@ bool operator ==(const RsMsgParentId& msLeft, const RsMsgParentId& msRight)
TEST(libretroshare_serialiser, RsMsgItem) TEST(libretroshare_serialiser, RsMsgItem)
{ {
test_RsItem<RsChatMsgItem >(); test_RsItem<RsChatMsgItem ,RsChatSerialiser>();
test_RsItem<RsChatLobbyMsgItem >(); test_RsItem<RsChatLobbyMsgItem ,RsChatSerialiser>();
test_RsItem<RsChatLobbyInviteItem >(); test_RsItem<RsChatLobbyInviteItem ,RsChatSerialiser>();
test_RsItem<RsChatLobbyEventItem >(); test_RsItem<RsChatLobbyEventItem ,RsChatSerialiser>();
test_RsItem<RsChatLobbyListRequestItem >(); test_RsItem<RsChatLobbyListRequestItem ,RsChatSerialiser>();
test_RsItem<RsChatLobbyListItem >(); test_RsItem<RsChatLobbyListItem ,RsChatSerialiser>();
test_RsItem<RsChatStatusItem >(); test_RsItem<RsChatStatusItem ,RsChatSerialiser>();
test_RsItem<RsChatAvatarItem >(); test_RsItem<RsChatAvatarItem ,RsChatSerialiser>();
test_RsItem<RsMsgItem >(); test_RsItem<RsMsgItem ,RsMsgSerialiser>();
test_RsItem<RsMsgTagType>(); test_RsItem<RsMsgTagType ,RsMsgSerialiser>();
test_RsItem<RsMsgTags>(); test_RsItem<RsMsgTags ,RsMsgSerialiser>();
test_RsItem<RsMsgSrcId>(); test_RsItem<RsMsgSrcId ,RsMsgSerialiser>();
test_RsItem<RsMsgParentId>(); test_RsItem<RsMsgParentId ,RsMsgSerialiser>();
} }

View File

@ -10,11 +10,11 @@
TEST(libretroshare_serialiser, RsNxsItem) TEST(libretroshare_serialiser, RsNxsItem)
{ {
test_RsItem<RsNxsGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsNxsGrp,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsNxsMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsNxsMsg,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsNxsSyncGrpItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsNxsSyncGrpItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsNxsSyncMsgItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsNxsSyncMsgItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsNxsSyncGrpItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsNxsSyncGrpItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsNxsSyncMsgItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsNxsSyncMsgItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsNxsTransacItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); test_RsItem<RsNxsTransacItem,RsNxsSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
} }

View File

@ -27,12 +27,11 @@
#include "support.h" #include "support.h"
#include "rsitems/rsstatusitems.h" #include "rsitems/rsstatusitems.h"
RsSerialType* init_item(RsStatusItem& rsi) void init_item(RsStatusItem& rsi)
{ {
rsi.sendTime = rand()%5353; rsi.sendTime = rand()%5353;
rsi.status = rand()%2032; rsi.status = rand()%2032;
return new RsStatusSerialiser();
} }
bool operator ==(RsStatusItem& rsi1, RsStatusItem& rsi2) bool operator ==(RsStatusItem& rsi1, RsStatusItem& rsi2)
@ -48,5 +47,5 @@ bool operator ==(RsStatusItem& rsi1, RsStatusItem& rsi2)
TEST(libretroshare_serialiser, test_RsStatusItem) TEST(libretroshare_serialiser, test_RsStatusItem)
{ {
test_RsItem<RsStatusItem >(); test_RsItem<RsStatusItem,RsStatusSerialiser >();
} }

View File

@ -172,6 +172,8 @@ int test_TlvSet(std::vector<RsTlvItem *> items, int maxsize)
test_CreateTlvStack(std::cerr, items, data, &size); test_CreateTlvStack(std::cerr, items, data, &size);
test_StepThroughTlvStack(std::cerr, data, size); test_StepThroughTlvStack(std::cerr, data, size);
free(data) ;
return 1; return 1;
} }

View File

@ -237,11 +237,12 @@ TEST(libretroshare_serialiser, RsTurtleItem)
//test_RsItem<RsTurtleFileMapItem >(); //test_RsItem<RsTurtleFileMapItem >();
//test_RsItem<RsTurtleFileDataItem >(); //test_RsItem<RsTurtleFileDataItem >();
//test_RsItem<RsTurtleFileRequestItem >(); //test_RsItem<RsTurtleFileRequestItem >();
test_RsItem<RsTurtleTunnelOkItem >();
test_RsItem<RsTurtleOpenTunnelItem >(); test_RsItem<RsTurtleTunnelOkItem ,RsTurtleSerialiser>();
test_RsItem<RsTurtleSearchResultItem >(); test_RsItem<RsTurtleOpenTunnelItem ,RsTurtleSerialiser>();
test_RsItem<RsTurtleStringSearchRequestItem >(); test_RsItem<RsTurtleSearchResultItem ,RsTurtleSerialiser>();
test_RsItem<RsTurtleRegExpSearchRequestItem >(); test_RsItem<RsTurtleStringSearchRequestItem ,RsTurtleSerialiser>();
test_RsItem<RsTurtleRegExpSearchRequestItem ,RsTurtleSerialiser>();
} }
} }

View File

@ -100,15 +100,17 @@ bool operator==(const RsTlvKeySignatureSet& , const RsTlvKeySignatureSet& );
* @param T the item you want to test * @param T the item you want to test
*/ */
template<class T> int test_RsItem() template<class ItemClass,class ItemSerialiser> int test_RsItem()
{ {
/* make a serialisable RsTurtleItem */ /* make a serialisable RsTurtleItem */
RsSerialiser srl; RsSerialiser srl;
/* initialise */ /* initialise */
T rsfi ; ItemClass rsfi ;
RsSerialType *rsfis = init_item(rsfi) ; RsSerialType *rsfis = new ItemSerialiser;
init_item(rsfi);
/* attempt to serialise it before we add it to the serialiser */ /* attempt to serialise it before we add it to the serialiser */
std::cerr << "### These errors are expected." << std::endl; std::cerr << "### These errors are expected." << std::endl;
@ -149,7 +151,7 @@ template<class T> int test_RsItem()
EXPECT_TRUE(sersize2 == sersize); EXPECT_TRUE(sersize2 == sersize);
T *outfi = dynamic_cast<T *>(output); ItemClass *outfi = dynamic_cast<ItemClass *>(output);
EXPECT_TRUE(outfi != NULL); EXPECT_TRUE(outfi != NULL);
if (!outfi) if (!outfi)
@ -173,22 +175,24 @@ template<class T> int test_RsItem()
EXPECT_TRUE(done2) ; EXPECT_TRUE(done2) ;
EXPECT_TRUE(sersize2 == sersize); EXPECT_TRUE(sersize2 == sersize);
std::cerr << "Deleting output" <<std::endl;
delete output ; delete output ;
delete[] buffer ; delete[] buffer ;
delete rsfis;
return 1; return 1;
} }
template<class T> int test_RsItem(uint16_t servtype) template<class ItemClass,class ItemSerialiser> int test_RsItem(uint16_t servtype)
{ {
/* make a serialisable RsTurtleItem */ /* make a serialisable RsTurtleItem */
RsSerialiser srl; RsSerialiser srl;
/* initialise */ /* initialise */
T rsfi(servtype) ; ItemClass rsfi(servtype) ;
RsSerialType *rsfis = init_item(rsfi) ; // deleted on destruction of srl RsSerialType *rsfis = new ItemSerialiser(servtype) ;
init_item(rsfi) ; // deleted on destruction of srl
/* attempt to serialise it before we add it to the serialiser */ /* attempt to serialise it before we add it to the serialiser */
std::cerr << "### These errors are expected." << std::endl; std::cerr << "### These errors are expected." << std::endl;
@ -223,7 +227,7 @@ template<class T> int test_RsItem(uint16_t servtype)
EXPECT_TRUE(output != NULL); EXPECT_TRUE(output != NULL);
EXPECT_TRUE(sersize2 == sersize); EXPECT_TRUE(sersize2 == sersize);
T *outfi = dynamic_cast<T *>(output); ItemClass *outfi = dynamic_cast<ItemClass *>(output);
EXPECT_TRUE(outfi != NULL); EXPECT_TRUE(outfi != NULL);
@ -240,7 +244,6 @@ template<class T> int test_RsItem(uint16_t servtype)
delete[] buffer ; delete[] buffer ;
delete output ; delete output ;
delete rsfis ;
return 1; return 1;
} }

View File

@ -45,8 +45,8 @@ TEST(libretroshare_serialiser, test_RsTlvStack)
/* now create a set of TLV items for the random generator */ /* now create a set of TLV items for the random generator */
RsTlvBinaryData *bd1 = new RsTlvBinaryData(123); RsTlvBinaryData bd1(123);
RsTlvBinaryData *bd2 = new RsTlvBinaryData(125); RsTlvBinaryData bd2(125);
char data[BIN_LEN] = {0}; char data[BIN_LEN] = {0};
int i; int i;
@ -55,31 +55,31 @@ TEST(libretroshare_serialiser, test_RsTlvStack)
data[i] = i%13; data[i] = i%13;
} }
bd1->setBinData(data, 5); bd1.setBinData(data, 5);
bd2->setBinData(data, 21); bd2.setBinData(data, 21);
RsTlvFileItem *fi1 = new RsTlvFileItem(); RsTlvFileItem fi1;
RsTlvFileItem *fi2 = new RsTlvFileItem(); RsTlvFileItem fi2;
/* initialise */ /* initialise */
fi1->filesize = 101010; fi1.filesize = 101010;
fi1->hash = RsFileHash("123456789ABCDEF67890123456789ABCDEF67890");//SHA1_SIZE*2 = 40 fi1.hash = RsFileHash("123456789ABCDEF67890123456789ABCDEF67890");//SHA1_SIZE*2 = 40
fi1->name = "TestFile.txt"; fi1.name = "TestFile.txt";
fi1->pop = 12; fi1.pop = 12;
fi1->age = 456; fi1.age = 456;
fi2->filesize = 101010; fi2.filesize = 101010;
fi2->hash = RsFileHash("123456789ABCDEF67890123456789ABCDEF67890");//SHA1_SIZE*2 = 40 fi2.hash = RsFileHash("123456789ABCDEF67890123456789ABCDEF67890");//SHA1_SIZE*2 = 40
fi2->name = "TestFile.txt"; fi2.name = "TestFile.txt";
fi2->pop = 0; fi2.pop = 0;
fi2->age = 0;; fi2.age = 0;;
std::vector<RsTlvItem *> items; std::vector<RsTlvItem *> items;
items.resize(4); items.resize(4);
items[0] = bd1; items[0] = &bd1;
items[1] = bd2; items[1] = &bd2;
items[2] = fi1; items[2] = &fi1;
items[3] = fi2; items[3] = &fi2;
test_TlvSet(items, 1024); test_TlvSet(items, 1024);
} }