mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
temporary changes (lrand48 - rand(), s/random - s/rand() to turtle tunnel, and tlv random tests to allow windows
compatability. added some explicit headers to distrib items test again for compatability. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3349 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7b4364035e
commit
cf75bee791
@ -1,71 +1,71 @@
|
||||
|
||||
RS_TOP_DIR = ../..
|
||||
##### Define any flags that are needed for this section #######
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/tests/scripts/config.mk
|
||||
###############################################################
|
||||
|
||||
TESTOBJ = tlvbase_test.o tlvbase_test2.o rstunnelitem_test.o
|
||||
TESTOBJ += tlvitems_test.o tlvstack_test.o rsserial_test.o
|
||||
TESTOBJ += rstlvwidetest.o tlvrandom_test.o rsturtleitem_test.o
|
||||
TESTOBJ += tlvtypes_test.o support.o distribitem_test.o rsmsgitem_test.o
|
||||
TESTOBJ += rsstatusitem_test.o
|
||||
|
||||
TESTS = tlvbase_test tlvbase_test2 rstlvwidetest
|
||||
TESTS += tlvitems_test tlvstack_test rstunnelitem_test
|
||||
TESTS += tlvrandom_test rsserial_test rsturtleitem_test
|
||||
TESTS += tlvtypes_test distribitem_test rsmsgitem_test
|
||||
TESTS += rsstatusitem_test
|
||||
|
||||
#rsbaseitem_test
|
||||
|
||||
all: tests
|
||||
|
||||
tlvbase_test : tlvbase_test.o
|
||||
$(CC) $(CFLAGS) -o tlvbase_test tlvbase_test.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvbase_test2 : tlvbase_test2.o
|
||||
$(CC) $(CFLAGS) -o tlvbase_test2 tlvbase_test2.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvitems_test : tlvitems_test.o
|
||||
$(CC) $(CFLAGS) -o tlvitems_test tlvitems_test.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvstack_test : tlvstack_test.o
|
||||
$(CC) $(CFLAGS) -o tlvstack_test tlvstack_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rsserial_test : rsserial_test.o
|
||||
$(CC) $(CFLAGS) -o rsserial_test rsserial_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rsbaseitem_test : rsbaseitem_test.o
|
||||
$(CC) $(CFLAGS) -o rsbaseitem_test rsbaseitem_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rstlvwidetest : rstlvwidetest.o
|
||||
$(CC) $(CFLAGS) -o rstlvwidetest rstlvwidetest.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvrandom_test : tlvrandom_test.o
|
||||
$(CC) $(CFLAGS) -o tlvrandom_test tlvrandom_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rsturtleitem_test : rsturtleitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o rsturtleitem_test rsturtleitem_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rstunnelitem_test : rstunnelitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o rstunnelitem_test rstunnelitem_test.o support.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvtypes_test : tlvtypes_test.o
|
||||
$(CC) $(CFLAGS) -o tlvtypes_test tlvtypes_test.o $(OBJ) $(LIBS)
|
||||
|
||||
distribitem_test : distribitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o distribitem_test distribitem_test.o support.o $(OBJ) $(LIBS)
|
||||
|
||||
rsmsgitem_test : rsmsgitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o rsmsgitem_test rsmsgitem_test.o support.o $(OBJ) $(LIBS)
|
||||
|
||||
rsstatusitem_test : rsstatusitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o rsstatusitem_test rsstatusitem_test.o support.o $(OBJ) $(LIBS)
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/scripts/rules.mk
|
||||
###############################################################
|
||||
|
||||
|
||||
RS_TOP_DIR = ../..
|
||||
##### Define any flags that are needed for this section #######
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/tests/scripts/config.mk
|
||||
###############################################################
|
||||
|
||||
TESTOBJ = tlvbase_test.o tlvbase_test2.o rstunnelitem_test.o
|
||||
TESTOBJ += tlvitems_test.o tlvstack_test.o rsserial_test.o
|
||||
TESTOBJ += rstlvwidetest.o tlvrandom_test.o rsturtleitem_test.o
|
||||
TESTOBJ += tlvtypes_test.o support.o distribitem_test.o rsmsgitem_test.o
|
||||
TESTOBJ += rsstatusitem_test.o
|
||||
|
||||
TESTS = tlvbase_test tlvbase_test2 rstlvwidetest
|
||||
TESTS += tlvitems_test tlvstack_test rstunnelitem_test
|
||||
TESTS += tlvrandom_test rsserial_test rsturtleitem_test
|
||||
TESTS += tlvtypes_test distribitem_test rsmsgitem_test
|
||||
TESTS += rsstatusitem_test
|
||||
|
||||
#rsbaseitem_test
|
||||
|
||||
all: tests
|
||||
|
||||
tlvbase_test : tlvbase_test.o
|
||||
$(CC) $(CFLAGS) -o tlvbase_test tlvbase_test.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvbase_test2 : tlvbase_test2.o
|
||||
$(CC) $(CFLAGS) -o tlvbase_test2 tlvbase_test2.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvitems_test : tlvitems_test.o
|
||||
$(CC) $(CFLAGS) -o tlvitems_test tlvitems_test.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvstack_test : tlvstack_test.o
|
||||
$(CC) $(CFLAGS) -o tlvstack_test tlvstack_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rsserial_test : rsserial_test.o
|
||||
$(CC) $(CFLAGS) -o rsserial_test rsserial_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rsbaseitem_test : rsbaseitem_test.o
|
||||
$(CC) $(CFLAGS) -o rsbaseitem_test rsbaseitem_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rstlvwidetest : rstlvwidetest.o
|
||||
$(CC) $(CFLAGS) -o rstlvwidetest rstlvwidetest.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvrandom_test : tlvrandom_test.o
|
||||
$(CC) $(CFLAGS) -o tlvrandom_test tlvrandom_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rsturtleitem_test : rsturtleitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o rsturtleitem_test rsturtleitem_test.o support.o $(OBJ) $(LIBS)
|
||||
|
||||
rstunnelitem_test : rstunnelitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o rstunnelitem_test rstunnelitem_test.o support.o $(OBJ) $(LIBS)
|
||||
|
||||
tlvtypes_test : tlvtypes_test.o
|
||||
$(CC) $(CFLAGS) -o tlvtypes_test tlvtypes_test.o $(OBJ) $(LIBS)
|
||||
|
||||
distribitem_test : distribitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o distribitem_test distribitem_test.o support.o $(OBJ) $(LIBS)
|
||||
|
||||
rsmsgitem_test : rsmsgitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o rsmsgitem_test rsmsgitem_test.o support.o $(OBJ) $(LIBS)
|
||||
|
||||
rsstatusitem_test : rsstatusitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o rsstatusitem_test rsstatusitem_test.o support.o $(OBJ) $(LIBS)
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/scripts/rules.mk
|
||||
###############################################################
|
||||
|
||||
|
@ -1,320 +1,320 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: distribitem_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2010 by Christopher Evi-Parker.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "serialiser/rsdistribitems.h"
|
||||
#include "serialiser/rschannelitems.h"
|
||||
#include "serialiser/rsforumitems.h"
|
||||
#include "serialiser/rsblogitems.h"
|
||||
#include "retroshare/rsdistrib.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
#include "support.h"
|
||||
|
||||
#include "distribitem_test.h"
|
||||
|
||||
INITTEST()
|
||||
|
||||
/** base rs distrib items **/
|
||||
|
||||
|
||||
|
||||
|
||||
RsSerialType* init_item(RsDistribGrp& grp)
|
||||
{
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
/* create Keys */
|
||||
|
||||
/* Create Group Description */
|
||||
|
||||
randString(SHORT_STR, grp.grpName);
|
||||
randString(LARGE_STR, grp.grpDesc);
|
||||
|
||||
grp.timestamp = now;
|
||||
grp.grpFlags = (RS_DISTRIB_PRIVACY_MASK | RS_DISTRIB_AUTHEN_MASK);
|
||||
grp.grpControlFlags = 0;
|
||||
|
||||
init_item(grp.grpPixmap);
|
||||
|
||||
/* set keys */
|
||||
|
||||
RsTlvSecurityKey publish_key;
|
||||
|
||||
init_item(grp.adminKey);
|
||||
init_item(publish_key);
|
||||
init_item(grp.adminSignature);
|
||||
|
||||
grp.publishKeys.keys[publish_key.keyId] = publish_key;
|
||||
grp.publishKeys.groupId = grp.adminKey.keyId;
|
||||
grp.grpId = grp.adminKey.keyId;
|
||||
|
||||
init_item(grp.grpControlList);
|
||||
|
||||
return new RsDistribSerialiser();
|
||||
|
||||
}
|
||||
|
||||
|
||||
RsSerialType* init_item(RsDistribGrpKey& gk)
|
||||
{
|
||||
|
||||
init_item(gk.key);
|
||||
gk.grpId = gk.key.keyId;
|
||||
|
||||
return new RsDistribSerialiser();
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const RsDistribGrpKey& gk1, const RsDistribGrpKey& gk2)
|
||||
{
|
||||
if(gk1.grpId != gk1.grpId) return false;
|
||||
if(!(gk1.key == gk2.key)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsDistribSignedMsg& sMsg)
|
||||
{
|
||||
|
||||
RsChannelMsg chMsg;
|
||||
RsSerialType* ser = init_item(chMsg);
|
||||
uint32_t chMsgSize = ser->size(&chMsg);
|
||||
char* chMsgData = new char[chMsgSize];
|
||||
ser->serialise(&chMsg, chMsgData, &chMsgSize);
|
||||
delete ser;
|
||||
|
||||
sMsg.packet.setBinData(chMsgData, chMsgSize);
|
||||
sMsg.flags = rand()%300;
|
||||
randString(SHORT_STR, sMsg.grpId);
|
||||
|
||||
return new RsDistribSerialiser();
|
||||
}
|
||||
|
||||
bool operator==(const RsDistribSignedMsg& sMsg1,const RsDistribSignedMsg& sMsg2)
|
||||
{
|
||||
|
||||
if(!(sMsg1.packet == sMsg2.packet)) return false;
|
||||
if(sMsg1.grpId != sMsg2.grpId) return false;
|
||||
if(sMsg1.flags != sMsg2.flags) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RsSerialType* init_item(RsChannelMsg& chMsg)
|
||||
{
|
||||
randString(SHORT_STR, chMsg.grpId);
|
||||
randString(LARGE_STR, chMsg.message);
|
||||
randString(SHORT_STR, chMsg.subject);
|
||||
randString(SHORT_STR, chMsg.threadId);
|
||||
chMsg.timestamp = rand()%31452;
|
||||
init_item(chMsg.thumbnail);
|
||||
init_item(chMsg.attachment);
|
||||
|
||||
return new RsChannelSerialiser();
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const RsChannelMsg& chMsg1,const RsChannelMsg& chMsg2)
|
||||
{
|
||||
|
||||
if(chMsg1.grpId != chMsg2.grpId) return false;
|
||||
if(chMsg1.message != chMsg2.message) return false;
|
||||
if(!(chMsg1.attachment == chMsg2.attachment)) return false;
|
||||
if(chMsg1.subject != chMsg2.subject) return false;
|
||||
if(chMsg2.threadId != chMsg2.threadId) return false;
|
||||
if(chMsg1.timestamp != chMsg2.timestamp) return false;
|
||||
if(!(chMsg1.thumbnail.binData == chMsg2.thumbnail.binData)) return false;
|
||||
if(chMsg1.thumbnail.image_type != chMsg2.thumbnail.image_type) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsForumMsg& fMsg)
|
||||
{
|
||||
|
||||
fMsg.timestamp = rand()%242;
|
||||
randString(SHORT_STR, fMsg.grpId);
|
||||
randString(LARGE_STR, fMsg.msg);
|
||||
randString(SHORT_STR, fMsg.parentId);
|
||||
randString(SHORT_STR, fMsg.srcId);
|
||||
randString(SHORT_STR, fMsg.threadId);
|
||||
randString(SHORT_STR, fMsg.title);
|
||||
|
||||
return new RsForumSerialiser();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator==(const RsForumMsg& fMsg1, const RsForumMsg& fMsg2)
|
||||
{
|
||||
if(fMsg1.grpId != fMsg2.grpId) return false;
|
||||
if(fMsg1.msg != fMsg2.msg) return false;
|
||||
if(fMsg1.parentId != fMsg2.parentId) return false;
|
||||
if(fMsg1.srcId != fMsg2.srcId) return false;
|
||||
if(fMsg1.threadId != fMsg2.threadId) return false;
|
||||
if(fMsg1.timestamp != fMsg2.timestamp) return false;
|
||||
if(fMsg1.title != fMsg2.title) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsBlogMsg& bMsg)
|
||||
{
|
||||
bMsg.timestamp = rand()%223;
|
||||
randString(SHORT_STR, bMsg.grpId);
|
||||
randString(LARGE_STR, bMsg.message);
|
||||
randString(SHORT_STR, bMsg.subject);
|
||||
randString(SHORT_STR, bMsg.parentId);
|
||||
randString(SHORT_STR, bMsg.threadId);
|
||||
RsTlvImage image;
|
||||
int nImages = rand()%5;
|
||||
|
||||
for(int i=0; i < nImages; i++)
|
||||
{
|
||||
init_item(image);
|
||||
bMsg.graphic_set.push_back(image);
|
||||
}
|
||||
|
||||
return new RsBlogSerialiser();
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const RsDistribGrp& g1, const RsDistribGrp& g2)
|
||||
{
|
||||
|
||||
if(g1.grpCategory != g2.grpCategory) return false;
|
||||
if(g1.grpControlFlags != g2.grpControlFlags) return false;
|
||||
if(!(g1.grpControlList == g2.grpControlList)) return false;
|
||||
if(g1.grpDesc != g2.grpDesc) return false;
|
||||
if(g1.grpFlags != g2.grpFlags) return false;
|
||||
if(g1.grpId != g2.grpId) return false;
|
||||
if(g1.grpName != g2.grpName) return false;
|
||||
if(g1.timestamp != g2.timestamp) return false;
|
||||
|
||||
// admin key
|
||||
|
||||
if(!(g1.adminKey == g2.adminKey)) return false;
|
||||
if(!(g1.adminSignature == g2.adminSignature)) return false;
|
||||
if(g1.grpPixmap.image_type != g2.grpPixmap.image_type) return false;
|
||||
if(!(g1.grpPixmap.binData == g2.grpPixmap.binData)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RsSerialType* init_item(RsForumReadStatus& fRdStatus)
|
||||
{
|
||||
randString(SHORT_STR, fRdStatus.forumId);
|
||||
fRdStatus.save_type = rand()%42;
|
||||
|
||||
std::map<std::string, uint32_t>::iterator mit = fRdStatus.msgReadStatus.begin();
|
||||
|
||||
std::string id;
|
||||
uint32_t status = 0;
|
||||
|
||||
int numMaps = rand()%12;
|
||||
|
||||
for(int i = 0; i < numMaps; i++)
|
||||
{
|
||||
randString(SHORT_STR, id);
|
||||
status = rand()%23;
|
||||
|
||||
fRdStatus.msgReadStatus.insert(std::pair<std::string, uint32_t>(id, status));
|
||||
}
|
||||
|
||||
return new RsForumSerialiser();
|
||||
}
|
||||
|
||||
bool operator==(const RsForumReadStatus& frs1, const RsForumReadStatus& frs2)
|
||||
{
|
||||
if(frs1.forumId != frs2.forumId) return false;
|
||||
if(frs1.save_type != frs2.save_type) return false;
|
||||
|
||||
if(frs1.msgReadStatus.size() != frs2.msgReadStatus.size()) return false;
|
||||
|
||||
std::map<std::string, uint32_t>::const_iterator mit
|
||||
= frs1.msgReadStatus.begin();
|
||||
|
||||
|
||||
|
||||
for(;mit != frs1.msgReadStatus.end(); mit++)
|
||||
{
|
||||
if(mit->second != frs2.msgReadStatus.find(mit->first)->second) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator==(const RsBlogMsg& bMsg1,const RsBlogMsg& bMsg2)
|
||||
{
|
||||
|
||||
if(bMsg1.timestamp != bMsg2.timestamp) return false;
|
||||
if(bMsg1.grpId != bMsg2.grpId) return false;
|
||||
if(bMsg1.message != bMsg2.message) return false;
|
||||
if(bMsg1.subject != bMsg2.subject) return false;
|
||||
if(bMsg1.threadId != bMsg2.threadId) return false;
|
||||
if(bMsg1.parentId != bMsg2.parentId) return false;
|
||||
|
||||
std::list<RsTlvImage >::const_iterator it1 = bMsg1.graphic_set.begin(),
|
||||
it2 = bMsg2.graphic_set.begin();
|
||||
|
||||
if(bMsg1.graphic_set.size() != bMsg2.graphic_set.size()) return false;
|
||||
|
||||
for(; it1 != bMsg1.graphic_set.end() ; it1++, it2++)
|
||||
{
|
||||
if(!(*it1 == *it2)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
||||
std::cerr << "RsDistribItem Tests" << std::endl;
|
||||
|
||||
test_RsItem<RsDistribGrp>(); REPORT("Serialise/Deserialise RsDistribGrp");
|
||||
test_RsItem<RsDistribGrpKey>(); REPORT("Serialise/Deserialise RsDistribGrpKey");
|
||||
test_RsItem<RsDistribSignedMsg>(); REPORT("Serialise/Deserialise RsDistribSignedMsg");
|
||||
test_RsItem<RsChannelMsg>(); REPORT("Serialise/Deserialise RsChannelMsg");
|
||||
test_RsItem<RsForumMsg>(); REPORT("Serialise/Deserialise RsForumMsg");
|
||||
test_RsItem<RsForumReadStatus>(); REPORT("Serialise/Deserialise RsForumReadStatus");
|
||||
test_RsItem<RsBlogMsg>(); REPORT("Serialise/Deserialise RsBlogMsg");
|
||||
|
||||
|
||||
FINALREPORT("RsDistribItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
|
||||
<<<<<<< .mine
|
||||
/*
|
||||
* libretroshare/src/serialiser: distribitem_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2010 by Christopher Evi-Parker.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include "serialiser/rsdistribitems.h"
|
||||
#include "serialiser/rschannelitems.h"
|
||||
#include "serialiser/rsforumitems.h"
|
||||
#include "serialiser/rsblogitems.h"
|
||||
#include "rsiface/rsdistrib.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
#include "support.h"
|
||||
|
||||
#include "distribitem_test.h"
|
||||
|
||||
INITTEST()
|
||||
|
||||
/** base rs distrib items **/
|
||||
|
||||
|
||||
|
||||
|
||||
RsSerialType* init_item(RsDistribGrp& grp)
|
||||
{
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
/* create Keys */
|
||||
|
||||
/* Create Group Description */
|
||||
|
||||
randString(SHORT_STR, grp.grpName);
|
||||
randString(LARGE_STR, grp.grpDesc);
|
||||
|
||||
grp.timestamp = now;
|
||||
grp.grpFlags = (RS_DISTRIB_PRIVACY_MASK | RS_DISTRIB_AUTHEN_MASK);
|
||||
grp.grpControlFlags = 0;
|
||||
|
||||
init_item(grp.grpPixmap);
|
||||
|
||||
/* set keys */
|
||||
|
||||
RsTlvSecurityKey publish_key;
|
||||
|
||||
init_item(grp.adminKey);
|
||||
init_item(publish_key);
|
||||
init_item(grp.adminSignature);
|
||||
|
||||
grp.publishKeys.keys[publish_key.keyId] = publish_key;
|
||||
grp.publishKeys.groupId = grp.adminKey.keyId;
|
||||
grp.grpId = grp.adminKey.keyId;
|
||||
|
||||
init_item(grp.grpControlList);
|
||||
|
||||
return new RsDistribSerialiser();
|
||||
|
||||
}
|
||||
|
||||
|
||||
RsSerialType* init_item(RsDistribGrpKey& gk)
|
||||
{
|
||||
|
||||
init_item(gk.key);
|
||||
gk.grpId = gk.key.keyId;
|
||||
|
||||
return new RsDistribSerialiser();
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const RsDistribGrpKey& gk1, const RsDistribGrpKey& gk2)
|
||||
{
|
||||
if(gk1.grpId != gk1.grpId) return false;
|
||||
if(!(gk1.key == gk2.key)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsDistribSignedMsg& sMsg)
|
||||
{
|
||||
|
||||
RsChannelMsg chMsg;
|
||||
RsSerialType* ser = init_item(chMsg);
|
||||
uint32_t chMsgSize = ser->size(&chMsg);
|
||||
char* chMsgData = new char[chMsgSize];
|
||||
ser->serialise(&chMsg, chMsgData, &chMsgSize);
|
||||
delete ser;
|
||||
|
||||
sMsg.packet.setBinData(chMsgData, chMsgSize);
|
||||
sMsg.flags = rand()%300;
|
||||
randString(SHORT_STR, sMsg.grpId);
|
||||
|
||||
return new RsDistribSerialiser();
|
||||
}
|
||||
|
||||
bool operator==(const RsDistribSignedMsg& sMsg1,const RsDistribSignedMsg& sMsg2)
|
||||
{
|
||||
|
||||
if(!(sMsg1.packet == sMsg2.packet)) return false;
|
||||
if(sMsg1.grpId != sMsg2.grpId) return false;
|
||||
if(sMsg1.flags != sMsg2.flags) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RsSerialType* init_item(RsChannelMsg& chMsg)
|
||||
{
|
||||
randString(SHORT_STR, chMsg.grpId);
|
||||
randString(LARGE_STR, chMsg.message);
|
||||
randString(SHORT_STR, chMsg.subject);
|
||||
randString(SHORT_STR, chMsg.threadId);
|
||||
chMsg.timestamp = rand()%31452;
|
||||
init_item(chMsg.thumbnail);
|
||||
init_item(chMsg.attachment);
|
||||
|
||||
return new RsChannelSerialiser();
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const RsChannelMsg& chMsg1,const RsChannelMsg& chMsg2)
|
||||
{
|
||||
|
||||
if(chMsg1.grpId != chMsg2.grpId) return false;
|
||||
if(chMsg1.message != chMsg2.message) return false;
|
||||
if(!(chMsg1.attachment == chMsg2.attachment)) return false;
|
||||
if(chMsg1.subject != chMsg2.subject) return false;
|
||||
if(chMsg2.threadId != chMsg2.threadId) return false;
|
||||
if(chMsg1.timestamp != chMsg2.timestamp) return false;
|
||||
if(!(chMsg1.thumbnail.binData == chMsg2.thumbnail.binData)) return false;
|
||||
if(chMsg1.thumbnail.image_type != chMsg2.thumbnail.image_type) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsForumMsg& fMsg)
|
||||
{
|
||||
|
||||
fMsg.timestamp = rand()%242;
|
||||
randString(SHORT_STR, fMsg.grpId);
|
||||
randString(LARGE_STR, fMsg.msg);
|
||||
randString(SHORT_STR, fMsg.parentId);
|
||||
randString(SHORT_STR, fMsg.srcId);
|
||||
randString(SHORT_STR, fMsg.threadId);
|
||||
randString(SHORT_STR, fMsg.title);
|
||||
|
||||
return new RsForumSerialiser();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator==(const RsForumMsg& fMsg1, const RsForumMsg& fMsg2)
|
||||
{
|
||||
if(fMsg1.grpId != fMsg2.grpId) return false;
|
||||
if(fMsg1.msg != fMsg2.msg) return false;
|
||||
if(fMsg1.parentId != fMsg2.parentId) return false;
|
||||
if(fMsg1.srcId != fMsg2.srcId) return false;
|
||||
if(fMsg1.threadId != fMsg2.threadId) return false;
|
||||
if(fMsg1.timestamp != fMsg2.timestamp) return false;
|
||||
if(fMsg1.title != fMsg2.title) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsBlogMsg& bMsg)
|
||||
{
|
||||
bMsg.timestamp = rand()%223;
|
||||
randString(SHORT_STR, bMsg.grpId);
|
||||
randString(LARGE_STR, bMsg.message);
|
||||
randString(SHORT_STR, bMsg.subject);
|
||||
randString(SHORT_STR, bMsg.parentId);
|
||||
randString(SHORT_STR, bMsg.threadId);
|
||||
RsTlvImage image;
|
||||
int nImages = rand()%5;
|
||||
|
||||
for(int i=0; i < nImages; i++)
|
||||
{
|
||||
init_item(image);
|
||||
bMsg.graphic_set.push_back(image);
|
||||
}
|
||||
|
||||
return new RsBlogSerialiser();
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const RsDistribGrp& g1, const RsDistribGrp& g2)
|
||||
{
|
||||
|
||||
if(g1.grpCategory != g2.grpCategory) return false;
|
||||
if(g1.grpControlFlags != g2.grpControlFlags) return false;
|
||||
if(!(g1.grpControlList == g2.grpControlList)) return false;
|
||||
if(g1.grpDesc != g2.grpDesc) return false;
|
||||
if(g1.grpFlags != g2.grpFlags) return false;
|
||||
if(g1.grpId != g2.grpId) return false;
|
||||
if(g1.grpName != g2.grpName) return false;
|
||||
if(g1.timestamp != g2.timestamp) return false;
|
||||
|
||||
// admin key
|
||||
|
||||
if(!(g1.adminKey == g2.adminKey)) return false;
|
||||
if(!(g1.adminSignature == g2.adminSignature)) return false;
|
||||
if(g1.grpPixmap.image_type != g2.grpPixmap.image_type) return false;
|
||||
if(!(g1.grpPixmap.binData == g2.grpPixmap.binData)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RsSerialType* init_item(RsForumReadStatus& fRdStatus)
|
||||
{
|
||||
randString(SHORT_STR, fRdStatus.forumId);
|
||||
fRdStatus.save_type = rand()%42;
|
||||
|
||||
std::map<std::string, uint32_t>::iterator mit = fRdStatus.msgReadStatus.begin();
|
||||
|
||||
std::string id;
|
||||
uint32_t status = 0;
|
||||
|
||||
int numMaps = rand()%12;
|
||||
|
||||
for(int i = 0; i < numMaps; i++)
|
||||
{
|
||||
randString(SHORT_STR, id);
|
||||
status = rand()%23;
|
||||
|
||||
fRdStatus.msgReadStatus.insert(std::pair<std::string, uint32_t>(id, status));
|
||||
}
|
||||
|
||||
return new RsForumSerialiser();
|
||||
}
|
||||
|
||||
bool operator==(const RsForumReadStatus& frs1, const RsForumReadStatus& frs2)
|
||||
{
|
||||
if(frs1.forumId != frs2.forumId) return false;
|
||||
if(frs1.save_type != frs2.save_type) return false;
|
||||
|
||||
if(frs1.msgReadStatus.size() != frs2.msgReadStatus.size()) return false;
|
||||
|
||||
std::map<std::string, uint32_t>::const_iterator mit
|
||||
= frs1.msgReadStatus.begin();
|
||||
|
||||
|
||||
|
||||
for(;mit != frs1.msgReadStatus.end(); mit++)
|
||||
{
|
||||
if(mit->second != frs2.msgReadStatus.find(mit->first)->second) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator==(const RsBlogMsg& bMsg1,const RsBlogMsg& bMsg2)
|
||||
{
|
||||
|
||||
if(bMsg1.timestamp != bMsg2.timestamp) return false;
|
||||
if(bMsg1.grpId != bMsg2.grpId) return false;
|
||||
if(bMsg1.message != bMsg2.message) return false;
|
||||
if(bMsg1.subject != bMsg2.subject) return false;
|
||||
if(bMsg1.threadId != bMsg2.threadId) return false;
|
||||
if(bMsg1.parentId != bMsg2.parentId) return false;
|
||||
|
||||
std::list<RsTlvImage >::const_iterator it1 = bMsg1.graphic_set.begin(),
|
||||
it2 = bMsg2.graphic_set.begin();
|
||||
|
||||
if(bMsg1.graphic_set.size() != bMsg2.graphic_set.size()) return false;
|
||||
|
||||
for(; it1 != bMsg1.graphic_set.end() ; it1++, it2++)
|
||||
{
|
||||
if(!(*it1 == *it2)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
||||
std::cerr << "RsDistribItem Tests" << std::endl;
|
||||
|
||||
test_RsItem<RsDistribGrp>(); REPORT("Serialise/Deserialise RsDistribGrp");
|
||||
test_RsItem<RsDistribGrpKey>(); REPORT("Serialise/Deserialise RsDistribGrpKey");
|
||||
test_RsItem<RsDistribSignedMsg>(); REPORT("Serialise/Deserialise RsDistribSignedMsg");
|
||||
test_RsItem<RsChannelMsg>(); REPORT("Serialise/Deserialise RsChannelMsg");
|
||||
test_RsItem<RsForumMsg>(); REPORT("Serialise/Deserialise RsForumMsg");
|
||||
test_RsItem<RsForumReadStatus>(); REPORT("Serialise/Deserialise RsForumReadStatus");
|
||||
test_RsItem<RsBlogMsg>(); REPORT("Serialise/Deserialise RsBlogMsg");
|
||||
|
||||
|
||||
FINALREPORT("RsDistribItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
|
@ -1,108 +1,109 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstunnelitems_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Cyril Soler
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <serialiser/rstunnelitems.h>
|
||||
#include <serialiser/rstlvutil.h>
|
||||
#include "util/utest.h"
|
||||
#include "support.h"
|
||||
|
||||
|
||||
|
||||
RsTunnelSerialiser* init_item(RsTunnelDataItem& item)
|
||||
{
|
||||
uint32_t S = lrand48()%20000 ;
|
||||
item.encoded_data = malloc(S) ;
|
||||
item.encoded_data_len = S ;
|
||||
for(uint32_t i=0;i<S;++i)
|
||||
((unsigned char *)item.encoded_data)[i] = lrand48()%256 ;
|
||||
item.sourcePeerId = "67641e38df0e75432033d222eae93fff" ;
|
||||
item.relayPeerId = "6013bfc2cea7ab823af7a79fb3ca0df1" ;
|
||||
item.destPeerId = "1d5768db7cd4720d0eb75cc1917da332" ;
|
||||
|
||||
return new RsTunnelSerialiser();
|
||||
}
|
||||
bool operator==(const RsTunnelDataItem& it1,const RsTunnelDataItem& it2)
|
||||
{
|
||||
if(it1.encoded_data_len != it2.encoded_data_len) return false ;
|
||||
if(it1.sourcePeerId != it2.sourcePeerId) return false ;
|
||||
if(it1.relayPeerId != it2.relayPeerId) return false ;
|
||||
if(it1.destPeerId != it2.destPeerId) return false ;
|
||||
|
||||
for(uint32_t i=0;i<it1.encoded_data_len;++i)
|
||||
if( ((unsigned char *)it1.encoded_data)[i] != ((unsigned char *)it2.encoded_data)[i])
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
RsTunnelSerialiser* init_item(RsTunnelHandshakeItem& item)
|
||||
{
|
||||
item.sourcePeerId = "67641e38df0e75432033d222eae93fff" ;
|
||||
item.relayPeerId = "6013bfc2cea7ab823af7a79fb3ca0df1" ;
|
||||
item.destPeerId = "1d5768db7cd4720d0eb75cc1917da332" ;
|
||||
|
||||
item.sslCertPEM = "" ;
|
||||
uint32_t s=lrand48()%20 ;
|
||||
for(uint32_t i=0;i<s;++i)
|
||||
item.sslCertPEM += "6013bfc2cea7ab823af7a79fb3ca0df1" ;
|
||||
item.connection_accepted = lrand48() ;
|
||||
|
||||
return new RsTunnelSerialiser();
|
||||
}
|
||||
bool operator==(const RsTunnelHandshakeItem& it1,const RsTunnelHandshakeItem& it2)
|
||||
{
|
||||
if(it1.sourcePeerId != it2.sourcePeerId) return false ;
|
||||
if(it1.relayPeerId != it2.relayPeerId) return false ;
|
||||
if(it1.destPeerId != it2.destPeerId) return false ;
|
||||
if(it1.sslCertPEM != it2.sslCertPEM) return false ;
|
||||
if(it1.connection_accepted != it2.connection_accepted) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
INITTEST();
|
||||
|
||||
int main()
|
||||
{
|
||||
// srand48(1) ; // always use the same random numbers
|
||||
std::cerr << "RsTurtleItem Tests" << std::endl;
|
||||
|
||||
for(uint32_t i=0;i<20;++i)
|
||||
{
|
||||
test_RsItem<RsTunnelDataItem >(); REPORT("Serialise/Deserialise RsTunnelDataItem");
|
||||
test_RsItem<RsTunnelHandshakeItem>(); REPORT("Serialise/Deserialise RsTunnelHandshakeItem");
|
||||
}
|
||||
|
||||
FINALREPORT("RstunnelItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rstunnelitems_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Cyril Soler
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <serialiser/rstunnelitems.h>
|
||||
#include <serialiser/rstlvutil.h>
|
||||
#include "util/utest.h"
|
||||
#include "support.h"
|
||||
|
||||
|
||||
|
||||
RsTunnelSerialiser* init_item(RsTunnelDataItem& item)
|
||||
{
|
||||
uint32_t S = rand()%20000 ;
|
||||
item.encoded_data = malloc(S) ;
|
||||
item.encoded_data_len = S ;
|
||||
for(uint32_t i=0;i<S;++i)
|
||||
((unsigned char *)item.encoded_data)[i] = rand()%256 ;
|
||||
item.sourcePeerId = "67641e38df0e75432033d222eae93fff" ;
|
||||
item.relayPeerId = "6013bfc2cea7ab823af7a79fb3ca0df1" ;
|
||||
item.destPeerId = "1d5768db7cd4720d0eb75cc1917da332" ;
|
||||
|
||||
return new RsTunnelSerialiser();
|
||||
}
|
||||
bool operator==(const RsTunnelDataItem& it1,const RsTunnelDataItem& it2)
|
||||
{
|
||||
if(it1.encoded_data_len != it2.encoded_data_len) return false ;
|
||||
if(it1.sourcePeerId != it2.sourcePeerId) return false ;
|
||||
if(it1.relayPeerId != it2.relayPeerId) return false ;
|
||||
if(it1.destPeerId != it2.destPeerId) return false ;
|
||||
|
||||
for(uint32_t i=0;i<it1.encoded_data_len;++i)
|
||||
if( ((unsigned char *)it1.encoded_data)[i] != ((unsigned char *)it2.encoded_data)[i])
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
RsTunnelSerialiser* init_item(RsTunnelHandshakeItem& item)
|
||||
{
|
||||
item.sourcePeerId = "67641e38df0e75432033d222eae93fff" ;
|
||||
item.relayPeerId = "6013bfc2cea7ab823af7a79fb3ca0df1" ;
|
||||
item.destPeerId = "1d5768db7cd4720d0eb75cc1917da332" ;
|
||||
|
||||
item.sslCertPEM = "" ;
|
||||
uint32_t s=rand()%20 ;
|
||||
for(uint32_t i=0;i<s;++i)
|
||||
item.sslCertPEM += "6013bfc2cea7ab823af7a79fb3ca0df1" ;
|
||||
item.connection_accepted = rand() ;
|
||||
|
||||
return new RsTunnelSerialiser();
|
||||
}
|
||||
bool operator==(const RsTunnelHandshakeItem& it1,const RsTunnelHandshakeItem& it2)
|
||||
{
|
||||
if(it1.sourcePeerId != it2.sourcePeerId) return false ;
|
||||
if(it1.relayPeerId != it2.relayPeerId) return false ;
|
||||
if(it1.destPeerId != it2.destPeerId) return false ;
|
||||
if(it1.sslCertPEM != it2.sslCertPEM) return false ;
|
||||
if(it1.connection_accepted != it2.connection_accepted) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
INITTEST();
|
||||
|
||||
int main()
|
||||
{
|
||||
// srand48(1) ; // always use the same random numbers
|
||||
std::cerr << "RsTurtleItem Tests" << std::endl;
|
||||
|
||||
for(uint32_t i=0;i<20;++i)
|
||||
{
|
||||
test_RsItem<RsTunnelDataItem >(); REPORT("Serialise/Deserialise RsTunnelDataItem");
|
||||
test_RsItem<RsTunnelHandshakeItem>(); REPORT("Serialise/Deserialise RsTunnelHandshakeItem");
|
||||
}
|
||||
|
||||
FINALREPORT("RstunnelItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,254 +1,254 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsturtleitems_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Cyril Soler
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "turtle/rsturtleitem.h"
|
||||
#include <serialiser/rstlvutil.h>
|
||||
#include "support.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
RsSerialType* init_item(CompressedChunkMap& map)
|
||||
{
|
||||
map._map.clear() ;
|
||||
for(uint i=0;i<15;++i)
|
||||
map._map.push_back(lrand48()) ;
|
||||
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const CompressedChunkMap& m1,const CompressedChunkMap& m2)
|
||||
{
|
||||
if(m1._map.size() != m2._map.size()) return false ;
|
||||
|
||||
for(uint32_t i=0;i<m1._map.size();++i)
|
||||
if(m1._map[i] != m2._map[i])
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool operator==(const RsTurtleFileMapRequestItem& it1,const RsTurtleFileMapRequestItem& it2)
|
||||
{
|
||||
if(it1.direction != it2.direction) return false ;
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileMapRequestItem& item)
|
||||
{
|
||||
item.direction = 1 ;
|
||||
item.tunnel_id = 0x4ff823e2 ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileMapItem& it1,const RsTurtleFileMapItem& it2)
|
||||
{
|
||||
if(it1.direction != it2.direction) return false ;
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
if(!(it1.compressed_map == it2.compressed_map)) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileMapItem& item)
|
||||
{
|
||||
item.direction = 1 ;
|
||||
item.tunnel_id = 0xf48fe232 ;
|
||||
init_item(item.compressed_map) ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileDataItem& item)
|
||||
{
|
||||
static const uint32_t S = 3456 ;
|
||||
item.tunnel_id = 0x33eef982 ;
|
||||
item.chunk_offset = 0x25ea228437894379ull ;
|
||||
item.chunk_size = S ;
|
||||
item.chunk_data = new unsigned char[S] ;
|
||||
for(uint32_t i=0;i<S;++i)
|
||||
((unsigned char *)item.chunk_data)[i] = lrand48()%256 ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileDataItem& i1,const RsTurtleFileDataItem& i2)
|
||||
{
|
||||
if(i1.tunnel_id != i2.tunnel_id) return false ;
|
||||
if(i1.chunk_offset != i2.chunk_offset) return false ;
|
||||
if(i1.chunk_size != i2.chunk_size) return false ;
|
||||
for(uint32_t i=0;i<i1.chunk_size;++i)
|
||||
if( ((unsigned char *)i1.chunk_data)[i] != ((unsigned char *)i2.chunk_data)[i])
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileRequestItem& item)
|
||||
{
|
||||
item.tunnel_id = lrand48() ;
|
||||
item.chunk_offset = 0x25ea228437894379ull ;
|
||||
item.chunk_size = lrand48() ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileRequestItem& it1,const RsTurtleFileRequestItem& it2)
|
||||
{
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
if(it1.chunk_offset != it2.chunk_offset) return false ;
|
||||
if(it1.chunk_size != it2.chunk_size) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleTunnelOkItem& item)
|
||||
{
|
||||
item.tunnel_id = lrand48() ;
|
||||
item.request_id = lrand48() ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleTunnelOkItem& it1,const RsTurtleTunnelOkItem& it2)
|
||||
{
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleOpenTunnelItem& item)
|
||||
{
|
||||
item.depth = lrand48() ;
|
||||
item.request_id = lrand48() ;
|
||||
item.partial_tunnel_id = lrand48() ;
|
||||
item.file_hash = std::string("c0edcfecc0844ef175d61dd589ab288d262b6bc8") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleOpenTunnelItem& it1,const RsTurtleOpenTunnelItem& it2)
|
||||
{
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.partial_tunnel_id != it2.partial_tunnel_id) return false ;
|
||||
if(it1.file_hash != it2.file_hash) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleRegExpSearchRequestItem& item)
|
||||
{
|
||||
item.request_id = lrand48() ;
|
||||
item.depth = lrand48() ;
|
||||
item.expr._tokens.clear() ;
|
||||
item.expr._ints.clear() ;
|
||||
item.expr._strings.clear() ;
|
||||
|
||||
for(uint32_t i=0;i<10u;++i) item.expr._tokens.push_back(lrand48()%8) ;
|
||||
for(uint32_t i=0;i<6u;++i) item.expr._ints.push_back(lrand48()) ;
|
||||
for(uint32_t i=0;i<8u;++i) item.expr._strings.push_back("test string") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleRegExpSearchRequestItem& it1,const RsTurtleRegExpSearchRequestItem& it2)
|
||||
{
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
if(it1.expr._tokens.size() != it2.expr._tokens.size()) return false ;
|
||||
if(it1.expr._ints.size() != it2.expr._ints.size()) return false ;
|
||||
if(it1.expr._strings.size() != it2.expr._strings.size()) return false ;
|
||||
for(uint32_t i=0;i<it1.expr._tokens.size();++i) if(it1.expr._tokens[i] != it2.expr._tokens[i]) return false ;
|
||||
for(uint32_t i=0;i<it1.expr._ints.size();++i) if(it1.expr._ints[i] != it2.expr._ints[i]) return false ;
|
||||
for(uint32_t i=0;i<it1.expr._strings.size();++i) if(it1.expr._strings[i] != it2.expr._strings[i]) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleStringSearchRequestItem& item)
|
||||
{
|
||||
item.request_id = lrand48() ;
|
||||
item.depth = lrand48() ;
|
||||
item.match_string = std::string("432hkjfdsjkhjk43r3fw") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleStringSearchRequestItem& it1,const RsTurtleStringSearchRequestItem& it2)
|
||||
{
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
if(it1.match_string != it2.match_string)
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(TurtleFileInfo& info)
|
||||
{
|
||||
info.hash = "3f753e8ac3b94ab9fddfad94480f747bf4418370";
|
||||
info.name = "toto.png";
|
||||
info.size = 0x3392085443897ull ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const TurtleFileInfo& it1,const TurtleFileInfo& it2)
|
||||
{
|
||||
if(it1.hash != it2.hash) return false ;
|
||||
if(it1.name != it2.name) return false ;
|
||||
if(it1.size != it2.size) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleSearchResultItem& item)
|
||||
{
|
||||
item.depth = lrand48() ;
|
||||
item.request_id = lrand48() ;
|
||||
item.result.clear() ;
|
||||
static const uint32_t S = 10 ;
|
||||
for(uint32_t i=0;i<S;++i)
|
||||
{
|
||||
TurtleFileInfo f;
|
||||
init_item(f) ;
|
||||
item.result.push_back(f) ;
|
||||
}
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleSearchResultItem& it1,const RsTurtleSearchResultItem& it2)
|
||||
{
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
|
||||
std::list<TurtleFileInfo>::const_iterator i1(it1.result.begin()) ;
|
||||
std::list<TurtleFileInfo>::const_iterator i2(it2.result.begin()) ;
|
||||
|
||||
for(;i1!=it1.result.end() && i2!=it2.result.end();++i1,++i2)
|
||||
if( !(*i1 == *i2))
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsTurtleItem Tests" << std::endl;
|
||||
|
||||
for(uint32_t i=0;i<20;++i)
|
||||
{
|
||||
test_RsItem<RsTurtleFileMapRequestItem>(); REPORT("Serialise/Deserialise RsTurtleFileMapRequestItem");
|
||||
test_RsItem<RsTurtleFileMapItem >(); REPORT("Serialise/Deserialise RsTurtleFileMapItem");
|
||||
test_RsItem<RsTurtleFileDataItem >(); REPORT("Serialise/Deserialise RsTurtleFileDataItem");
|
||||
test_RsItem<RsTurtleFileRequestItem >(); REPORT("Serialise/Deserialise RsTurtleFileRequestItem");
|
||||
test_RsItem<RsTurtleTunnelOkItem >(); REPORT("Serialise/Deserialise RsTurtleTunnelOkItem ");
|
||||
test_RsItem<RsTurtleOpenTunnelItem >(); REPORT("Serialise/Deserialise RsTurtleOpenTunnelItem ");
|
||||
test_RsItem<RsTurtleSearchResultItem >(); REPORT("Serialise/Deserialise RsTurtleSearchResultItem ");
|
||||
test_RsItem<RsTurtleStringSearchRequestItem >(); REPORT("Serialise/Deserialise RsTurtleStringSearchRequestItem ");
|
||||
test_RsItem<RsTurtleRegExpSearchRequestItem >(); REPORT("Serialise/Deserialise RsTurtleRegExpSearchRequestItem ");
|
||||
}
|
||||
|
||||
FINALREPORT("RsturtleItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsturtleitems_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Cyril Soler
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "turtle/rsturtleitem.h"
|
||||
#include <serialiser/rstlvutil.h>
|
||||
#include "support.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
RsSerialType* init_item(CompressedChunkMap& map)
|
||||
{
|
||||
map._map.clear() ;
|
||||
for(uint32_t i=0;i<15;++i)
|
||||
map._map.push_back(rand()) ;
|
||||
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const CompressedChunkMap& m1,const CompressedChunkMap& m2)
|
||||
{
|
||||
if(m1._map.size() != m2._map.size()) return false ;
|
||||
|
||||
for(uint32_t i=0;i<m1._map.size();++i)
|
||||
if(m1._map[i] != m2._map[i])
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool operator==(const RsTurtleFileMapRequestItem& it1,const RsTurtleFileMapRequestItem& it2)
|
||||
{
|
||||
if(it1.direction != it2.direction) return false ;
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileMapRequestItem& item)
|
||||
{
|
||||
item.direction = 1 ;
|
||||
item.tunnel_id = 0x4ff823e2 ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileMapItem& it1,const RsTurtleFileMapItem& it2)
|
||||
{
|
||||
if(it1.direction != it2.direction) return false ;
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
if(!(it1.compressed_map == it2.compressed_map)) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileMapItem& item)
|
||||
{
|
||||
item.direction = 1 ;
|
||||
item.tunnel_id = 0xf48fe232 ;
|
||||
init_item(item.compressed_map) ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileDataItem& item)
|
||||
{
|
||||
static const uint32_t S = 3456 ;
|
||||
item.tunnel_id = 0x33eef982 ;
|
||||
item.chunk_offset = 0x25ea228437894379ull ;
|
||||
item.chunk_size = S ;
|
||||
item.chunk_data = new unsigned char[S] ;
|
||||
for(uint32_t i=0;i<S;++i)
|
||||
((unsigned char *)item.chunk_data)[i] = rand()%256 ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileDataItem& i1,const RsTurtleFileDataItem& i2)
|
||||
{
|
||||
if(i1.tunnel_id != i2.tunnel_id) return false ;
|
||||
if(i1.chunk_offset != i2.chunk_offset) return false ;
|
||||
if(i1.chunk_size != i2.chunk_size) return false ;
|
||||
for(uint32_t i=0;i<i1.chunk_size;++i)
|
||||
if( ((unsigned char *)i1.chunk_data)[i] != ((unsigned char *)i2.chunk_data)[i])
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileRequestItem& item)
|
||||
{
|
||||
item.tunnel_id = rand() ;
|
||||
item.chunk_offset = 0x25ea228437894379ull ;
|
||||
item.chunk_size = rand() ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileRequestItem& it1,const RsTurtleFileRequestItem& it2)
|
||||
{
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
if(it1.chunk_offset != it2.chunk_offset) return false ;
|
||||
if(it1.chunk_size != it2.chunk_size) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleTunnelOkItem& item)
|
||||
{
|
||||
item.tunnel_id = rand() ;
|
||||
item.request_id = rand() ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleTunnelOkItem& it1,const RsTurtleTunnelOkItem& it2)
|
||||
{
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleOpenTunnelItem& item)
|
||||
{
|
||||
item.depth = rand() ;
|
||||
item.request_id = rand() ;
|
||||
item.partial_tunnel_id = rand() ;
|
||||
item.file_hash = std::string("c0edcfecc0844ef175d61dd589ab288d262b6bc8") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleOpenTunnelItem& it1,const RsTurtleOpenTunnelItem& it2)
|
||||
{
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.partial_tunnel_id != it2.partial_tunnel_id) return false ;
|
||||
if(it1.file_hash != it2.file_hash) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleRegExpSearchRequestItem& item)
|
||||
{
|
||||
item.request_id = rand() ;
|
||||
item.depth = rand() ;
|
||||
item.expr._tokens.clear() ;
|
||||
item.expr._ints.clear() ;
|
||||
item.expr._strings.clear() ;
|
||||
|
||||
for(uint32_t i=0;i<10u;++i) item.expr._tokens.push_back(rand()%8) ;
|
||||
for(uint32_t i=0;i<6u;++i) item.expr._ints.push_back(rand()) ;
|
||||
for(uint32_t i=0;i<8u;++i) item.expr._strings.push_back("test string") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleRegExpSearchRequestItem& it1,const RsTurtleRegExpSearchRequestItem& it2)
|
||||
{
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
if(it1.expr._tokens.size() != it2.expr._tokens.size()) return false ;
|
||||
if(it1.expr._ints.size() != it2.expr._ints.size()) return false ;
|
||||
if(it1.expr._strings.size() != it2.expr._strings.size()) return false ;
|
||||
for(uint32_t i=0;i<it1.expr._tokens.size();++i) if(it1.expr._tokens[i] != it2.expr._tokens[i]) return false ;
|
||||
for(uint32_t i=0;i<it1.expr._ints.size();++i) if(it1.expr._ints[i] != it2.expr._ints[i]) return false ;
|
||||
for(uint32_t i=0;i<it1.expr._strings.size();++i) if(it1.expr._strings[i] != it2.expr._strings[i]) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleStringSearchRequestItem& item)
|
||||
{
|
||||
item.request_id = rand() ;
|
||||
item.depth = rand() ;
|
||||
item.match_string = std::string("432hkjfdsjkhjk43r3fw") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleStringSearchRequestItem& it1,const RsTurtleStringSearchRequestItem& it2)
|
||||
{
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
if(it1.match_string != it2.match_string)
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(TurtleFileInfo& info)
|
||||
{
|
||||
info.hash = "3f753e8ac3b94ab9fddfad94480f747bf4418370";
|
||||
info.name = "toto.png";
|
||||
info.size = 0x3392085443897ull ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const TurtleFileInfo& it1,const TurtleFileInfo& it2)
|
||||
{
|
||||
if(it1.hash != it2.hash) return false ;
|
||||
if(it1.name != it2.name) return false ;
|
||||
if(it1.size != it2.size) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleSearchResultItem& item)
|
||||
{
|
||||
item.depth = rand() ;
|
||||
item.request_id = rand() ;
|
||||
item.result.clear() ;
|
||||
static const uint32_t S = 10 ;
|
||||
for(uint32_t i=0;i<S;++i)
|
||||
{
|
||||
TurtleFileInfo f;
|
||||
init_item(f) ;
|
||||
item.result.push_back(f) ;
|
||||
}
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleSearchResultItem& it1,const RsTurtleSearchResultItem& it2)
|
||||
{
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
|
||||
std::list<TurtleFileInfo>::const_iterator i1(it1.result.begin()) ;
|
||||
std::list<TurtleFileInfo>::const_iterator i2(it2.result.begin()) ;
|
||||
|
||||
for(;i1!=it1.result.end() && i2!=it2.result.end();++i1,++i2)
|
||||
if( !(*i1 == *i2))
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsTurtleItem Tests" << std::endl;
|
||||
|
||||
for(uint32_t i=0;i<20;++i)
|
||||
{
|
||||
test_RsItem<RsTurtleFileMapRequestItem>(); REPORT("Serialise/Deserialise RsTurtleFileMapRequestItem");
|
||||
test_RsItem<RsTurtleFileMapItem >(); REPORT("Serialise/Deserialise RsTurtleFileMapItem");
|
||||
test_RsItem<RsTurtleFileDataItem >(); REPORT("Serialise/Deserialise RsTurtleFileDataItem");
|
||||
test_RsItem<RsTurtleFileRequestItem >(); REPORT("Serialise/Deserialise RsTurtleFileRequestItem");
|
||||
test_RsItem<RsTurtleTunnelOkItem >(); REPORT("Serialise/Deserialise RsTurtleTunnelOkItem ");
|
||||
test_RsItem<RsTurtleOpenTunnelItem >(); REPORT("Serialise/Deserialise RsTurtleOpenTunnelItem ");
|
||||
test_RsItem<RsTurtleSearchResultItem >(); REPORT("Serialise/Deserialise RsTurtleSearchResultItem ");
|
||||
test_RsItem<RsTurtleStringSearchRequestItem >(); REPORT("Serialise/Deserialise RsTurtleStringSearchRequestItem ");
|
||||
test_RsItem<RsTurtleRegExpSearchRequestItem >(); REPORT("Serialise/Deserialise RsTurtleRegExpSearchRequestItem ");
|
||||
}
|
||||
|
||||
FINALREPORT("RsturtleItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,194 +1,195 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: tlvrandom_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2009 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
* tlvrandom_test.
|
||||
*
|
||||
* This test is designed to attempt to break the TLV serialiser.
|
||||
*
|
||||
* To do this we throw random data at the serialisers and try to decode it.
|
||||
* As the serialiser will only attempt to deserialise if the tlvtype matches
|
||||
* we cheat a little, and make this match - to increase to actual deserialise
|
||||
* attempts.
|
||||
*
|
||||
* This test runs for 30 seconds and attempts to do as
|
||||
* many deserialisation as possible.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rstlvkvwide.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
#define TEST_LENGTH 30
|
||||
|
||||
static int test_TlvRandom(void *data, uint32_t len, uint32_t offset);
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "TlvRandom Tests" << std::endl;
|
||||
|
||||
/* random data array to work through */
|
||||
uint32_t dsize = 10000000;
|
||||
uint32_t i;
|
||||
uint8_t *data = (uint8_t *) malloc(dsize);
|
||||
|
||||
if (!data)
|
||||
{
|
||||
std::cerr << "Failed to allocate array";
|
||||
std::cerr << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
time_t startTs = time(NULL);
|
||||
time_t endTs = startTs + TEST_LENGTH;
|
||||
|
||||
srandom(startTs);
|
||||
for(i = 0; i < dsize; i++)
|
||||
{
|
||||
data[i] = random() % 256;
|
||||
}
|
||||
|
||||
std::cerr << "TlvRandom Tests: setup data." << std::endl;
|
||||
|
||||
int count = 0;
|
||||
for(i = 0; endTs > time(NULL); i += 2)
|
||||
{
|
||||
uint32_t len = dsize - i;
|
||||
count += test_TlvRandom(&(data[i]), len, i);
|
||||
|
||||
std::cerr << "Run: " << count << " tests";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
FINALREPORT("RsTlvItems Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
#define BIN_LEN 523456 /* bigger than 64k */
|
||||
|
||||
int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset);
|
||||
int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset);
|
||||
|
||||
|
||||
int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
|
||||
{
|
||||
uint32_t tmpoffset = 0;
|
||||
|
||||
/* List of all the TLV types it could be! */
|
||||
RsTlvSecurityKey skey;
|
||||
RsTlvSecurityKeySet skeyset;
|
||||
RsTlvKeySignature keysign;
|
||||
|
||||
RsTlvBinaryData bindata(TLV_TYPE_IMAGE);
|
||||
|
||||
RsTlvFileItem fileitem;
|
||||
RsTlvFileSet fileset;
|
||||
RsTlvFileData filedata;
|
||||
|
||||
RsTlvPeerIdSet peerset;
|
||||
RsTlvServiceIdSet servset;
|
||||
|
||||
RsTlvKeyValue kv;
|
||||
RsTlvKeyValueSet kvset;
|
||||
RsTlvKeyValueWide kvwide;
|
||||
RsTlvKeyValueWideSet kvwideset;
|
||||
|
||||
RsTlvImage image;
|
||||
|
||||
/* try to decode - with all types first */
|
||||
std::cerr << "test_TlvRandom:: Testing Files " << std::endl;
|
||||
test_TlvItem(&bindata, data, len, offset);
|
||||
test_TlvItem(&fileitem, data, len, offset);
|
||||
test_TlvItem(&fileset, data, len, offset);
|
||||
test_TlvItem(&filedata, data, len, offset);
|
||||
std::cerr << "test_TlvRandom:: Testing Sets " << std::endl;
|
||||
test_TlvItem(&peerset, data, len, offset);
|
||||
test_TlvItem(&servset, data, len, offset);
|
||||
test_TlvItem(&kv, data, len, offset);
|
||||
test_TlvItem(&kvset, data, len, offset);
|
||||
test_TlvItem(&kvwide, data, len, offset);
|
||||
test_TlvItem(&kvwideset, data, len, offset);
|
||||
std::cerr << "test_TlvRandom:: Testing Keys " << std::endl;
|
||||
test_TlvItem(&skey, data, len, offset);
|
||||
test_TlvItem(&skeyset, data, len, offset);
|
||||
test_TlvItem(&keysign, data, len, offset);
|
||||
|
||||
/* now set the type correctly before decoding */
|
||||
std::cerr << "test_TlvRandom:: Testing Files (TYPESET)" << std::endl;
|
||||
test_SetTlvItem(&bindata, TLV_TYPE_IMAGE, data, len, offset);
|
||||
test_SetTlvItem(&fileitem,TLV_TYPE_FILEITEM, data, len, offset);
|
||||
test_SetTlvItem(&fileset, TLV_TYPE_FILESET, data, len, offset);
|
||||
test_SetTlvItem(&filedata, TLV_TYPE_FILEDATA, data, len, offset);
|
||||
std::cerr << "test_TlvRandom:: Testing Sets (TYPESET)" << std::endl;
|
||||
test_SetTlvItem(&peerset, TLV_TYPE_PEERSET, data, len, offset);
|
||||
test_SetTlvItem(&servset, TLV_TYPE_SERVICESET, data, len, offset);
|
||||
test_SetTlvItem(&kv, TLV_TYPE_KEYVALUE, data, len, offset);
|
||||
test_SetTlvItem(&kvset, TLV_TYPE_KEYVALUESET, data, len, offset);
|
||||
test_SetTlvItem(&kvwide, TLV_TYPE_WKEYVALUE, data, len, offset);
|
||||
test_SetTlvItem(&kvwideset, TLV_TYPE_WKEYVALUESET, data, len, offset);
|
||||
std::cerr << "test_TlvRandom:: Testing Keys (TYPESET)" << std::endl;
|
||||
test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY, data, len, offset);
|
||||
test_SetTlvItem(&skeyset, TLV_TYPE_SECURITYKEYSET, data, len, offset);
|
||||
test_SetTlvItem(&keysign, TLV_TYPE_KEYSIGNATURE, data, len, offset);
|
||||
|
||||
return 26; /* number of tests */
|
||||
}
|
||||
|
||||
int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset)
|
||||
{
|
||||
uint32_t tmp_offset = offset;
|
||||
if (item->GetTlv(data, size, &tmp_offset))
|
||||
{
|
||||
std::cerr << "TLV decoded Random!";
|
||||
std::cerr << std::endl;
|
||||
item->print(std::cerr, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "TLV failed to decode";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset)
|
||||
{
|
||||
/* set TLV type first! */
|
||||
void *typedata = (((uint8_t *) data) + offset);
|
||||
SetTlvType(typedata, size - offset, type);
|
||||
|
||||
return test_TlvItem(item, data, size, offset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: tlvrandom_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2009 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
* tlvrandom_test.
|
||||
*
|
||||
* This test is designed to attempt to break the TLV serialiser.
|
||||
*
|
||||
* To do this we throw random data at the serialisers and try to decode it.
|
||||
* As the serialiser will only attempt to deserialise if the tlvtype matches
|
||||
* we cheat a little, and make this match - to increase to actual deserialise
|
||||
* attempts.
|
||||
*
|
||||
* This test runs for 30 seconds and attempts to do as
|
||||
* many deserialisation as possible.
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rstlvkvwide.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
#define TEST_LENGTH 30
|
||||
|
||||
static int test_TlvRandom(void *data, uint32_t len, uint32_t offset);
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "TlvRandom Tests" << std::endl;
|
||||
|
||||
/* random data array to work through */
|
||||
uint32_t dsize = 10000000;
|
||||
uint32_t i;
|
||||
uint8_t *data = (uint8_t *) malloc(dsize);
|
||||
|
||||
if (!data)
|
||||
{
|
||||
std::cerr << "Failed to allocate array";
|
||||
std::cerr << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
time_t startTs = time(NULL);
|
||||
time_t endTs = startTs + TEST_LENGTH;
|
||||
|
||||
srand(startTs);
|
||||
for(i = 0; i < dsize; i++)
|
||||
{
|
||||
data[i] = rand() % 256;
|
||||
}
|
||||
|
||||
std::cerr << "TlvRandom Tests: setup data." << std::endl;
|
||||
|
||||
int count = 0;
|
||||
for(i = 0; endTs > time(NULL); i += 2)
|
||||
{
|
||||
uint32_t len = dsize - i;
|
||||
count += test_TlvRandom(&(data[i]), len, i);
|
||||
|
||||
std::cerr << "Run: " << count << " tests";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
FINALREPORT("RsTlvItems Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
#define BIN_LEN 523456 /* bigger than 64k */
|
||||
|
||||
int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset);
|
||||
int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset);
|
||||
|
||||
|
||||
int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
|
||||
{
|
||||
uint32_t tmpoffset = 0;
|
||||
|
||||
/* List of all the TLV types it could be! */
|
||||
RsTlvSecurityKey skey;
|
||||
RsTlvSecurityKeySet skeyset;
|
||||
RsTlvKeySignature keysign;
|
||||
|
||||
RsTlvBinaryData bindata(TLV_TYPE_IMAGE);
|
||||
|
||||
RsTlvFileItem fileitem;
|
||||
RsTlvFileSet fileset;
|
||||
RsTlvFileData filedata;
|
||||
|
||||
RsTlvPeerIdSet peerset;
|
||||
RsTlvServiceIdSet servset;
|
||||
|
||||
RsTlvKeyValue kv;
|
||||
RsTlvKeyValueSet kvset;
|
||||
RsTlvKeyValueWide kvwide;
|
||||
RsTlvKeyValueWideSet kvwideset;
|
||||
|
||||
RsTlvImage image;
|
||||
|
||||
/* try to decode - with all types first */
|
||||
std::cerr << "test_TlvRandom:: Testing Files " << std::endl;
|
||||
test_TlvItem(&bindata, data, len, offset);
|
||||
test_TlvItem(&fileitem, data, len, offset);
|
||||
test_TlvItem(&fileset, data, len, offset);
|
||||
test_TlvItem(&filedata, data, len, offset);
|
||||
std::cerr << "test_TlvRandom:: Testing Sets " << std::endl;
|
||||
test_TlvItem(&peerset, data, len, offset);
|
||||
test_TlvItem(&servset, data, len, offset);
|
||||
test_TlvItem(&kv, data, len, offset);
|
||||
test_TlvItem(&kvset, data, len, offset);
|
||||
test_TlvItem(&kvwide, data, len, offset);
|
||||
test_TlvItem(&kvwideset, data, len, offset);
|
||||
std::cerr << "test_TlvRandom:: Testing Keys " << std::endl;
|
||||
test_TlvItem(&skey, data, len, offset);
|
||||
test_TlvItem(&skeyset, data, len, offset);
|
||||
test_TlvItem(&keysign, data, len, offset);
|
||||
|
||||
/* now set the type correctly before decoding */
|
||||
std::cerr << "test_TlvRandom:: Testing Files (TYPESET)" << std::endl;
|
||||
test_SetTlvItem(&bindata, TLV_TYPE_IMAGE, data, len, offset);
|
||||
test_SetTlvItem(&fileitem,TLV_TYPE_FILEITEM, data, len, offset);
|
||||
test_SetTlvItem(&fileset, TLV_TYPE_FILESET, data, len, offset);
|
||||
test_SetTlvItem(&filedata, TLV_TYPE_FILEDATA, data, len, offset);
|
||||
std::cerr << "test_TlvRandom:: Testing Sets (TYPESET)" << std::endl;
|
||||
test_SetTlvItem(&peerset, TLV_TYPE_PEERSET, data, len, offset);
|
||||
test_SetTlvItem(&servset, TLV_TYPE_SERVICESET, data, len, offset);
|
||||
test_SetTlvItem(&kv, TLV_TYPE_KEYVALUE, data, len, offset);
|
||||
test_SetTlvItem(&kvset, TLV_TYPE_KEYVALUESET, data, len, offset);
|
||||
test_SetTlvItem(&kvwide, TLV_TYPE_WKEYVALUE, data, len, offset);
|
||||
test_SetTlvItem(&kvwideset, TLV_TYPE_WKEYVALUESET, data, len, offset);
|
||||
std::cerr << "test_TlvRandom:: Testing Keys (TYPESET)" << std::endl;
|
||||
test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY, data, len, offset);
|
||||
test_SetTlvItem(&skeyset, TLV_TYPE_SECURITYKEYSET, data, len, offset);
|
||||
test_SetTlvItem(&keysign, TLV_TYPE_KEYSIGNATURE, data, len, offset);
|
||||
|
||||
return 26; /* number of tests */
|
||||
}
|
||||
|
||||
int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset)
|
||||
{
|
||||
uint32_t tmp_offset = offset;
|
||||
if (item->GetTlv(data, size, &tmp_offset))
|
||||
{
|
||||
std::cerr << "TLV decoded Random!";
|
||||
std::cerr << std::endl;
|
||||
item->print(std::cerr, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "TLV failed to decode";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset)
|
||||
{
|
||||
/* set TLV type first! */
|
||||
void *typedata = (((uint8_t *) data) + offset);
|
||||
SetTlvType(typedata, size - offset, type);
|
||||
|
||||
return test_TlvItem(item, data, size, offset);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user