mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added new tests for msgitem and refactored support functions. testnotes added to keep track of whats left to be done
pls make notes in file when you add tests git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3333 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2053e08e46
commit
7318fdf9c8
@ -60,7 +60,10 @@ class RsChatItem: public RsItem
|
||||
virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* For sending chat msgs
|
||||
* @see p3ChatService
|
||||
*/
|
||||
class RsChatMsgItem: public RsChatItem
|
||||
{
|
||||
public:
|
||||
|
@ -10,12 +10,14 @@ 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
|
||||
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
|
||||
TESTS += tlvtypes_test distribitem_test rsmsgitem_test
|
||||
TESTS += rsstatusitem_test
|
||||
|
||||
#rsbaseitem_test
|
||||
|
||||
@ -45,18 +47,23 @@ rstlvwidetest : rstlvwidetest.o
|
||||
tlvrandom_test : tlvrandom_test.o
|
||||
$(CC) $(CFLAGS) -o tlvrandom_test tlvrandom_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rsturtleitem_test : rsturtleitem_test.o
|
||||
rsturtleitem_test : rsturtleitem_test.o support.o
|
||||
$(CC) $(CFLAGS) -o rsturtleitem_test rsturtleitem_test.o $(OBJ) $(LIBS)
|
||||
|
||||
rstunnelitem_test : rstunnelitem_test.o
|
||||
$(CC) $(CFLAGS) -o rstunnelitem_test rstunnelitem_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 distrib_test distribitem_test.o support.o $(OBJ) $(LIBS)
|
||||
$(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
|
||||
|
56
libretroshare/src/tests/serialiser/TestNotes.txt
Normal file
56
libretroshare/src/tests/serialiser/TestNotes.txt
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
Few test still need to be done. Needs to be automated
|
||||
|
||||
used support(.h/.cc) file for testing RsItems
|
||||
|
||||
Components and Tests.
|
||||
============================================================
|
||||
------------------------------------------------------------
|
||||
Basic Items
|
||||
------------------------------------------------------------
|
||||
rsbaseitems.cc : needed
|
||||
rsbaseserial.cc : needed
|
||||
rsconfigitems.cc : needed
|
||||
rsserial.cc : needed
|
||||
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------
|
||||
Compound TLV Components
|
||||
------------------------------------------------------------
|
||||
|
||||
rstlvaddrs.cc : needed
|
||||
rstlvbase.cc : not finished, tlvbase_test
|
||||
rstlvfileitem.cc : tlvtypes_test
|
||||
rstlvimage.cc : tlvtypes_test
|
||||
rstlvkeys.cc : tlvtypes_test
|
||||
rstlvkvwide.cc : rstlvwidetest
|
||||
rstlvtypes.cc : tlvtypes_test
|
||||
rstlvutil.cc : no need
|
||||
|
||||
------------------------------------------------------------
|
||||
Service Components
|
||||
------------------------------------------------------------
|
||||
rstunnelitems.cc : rstunnelitem_test & rsturtleitem_test
|
||||
rsdistribitem.cc : distribitem_test
|
||||
rsmsgitem.cc : msgitem_test
|
||||
rsdiscitems.cc : needed
|
||||
rsrankitems.cc : needed
|
||||
rsblogitems.cc : distribitem_test
|
||||
rschannelitems.cc : distribitem_test
|
||||
rsforumitems.cc : distribitem_test
|
||||
rsstatusitems.cc : needed
|
||||
rsgameitems.cc : TBC
|
||||
rsphotoitems.cc : TBC
|
||||
|
||||
============================================================
|
||||
Test Specifics
|
||||
============================================================
|
||||
|
||||
------------------------------------------------------------
|
||||
Basic Components
|
||||
------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -38,68 +38,10 @@
|
||||
|
||||
INITTEST()
|
||||
|
||||
#define SHORT_STR 100
|
||||
#define LARGE_STR 1000
|
||||
|
||||
/** base rs distrib items **/
|
||||
|
||||
|
||||
|
||||
void init_item(RsTlvSecurityKey& sk)
|
||||
{
|
||||
int randnum = rand()%313131;
|
||||
|
||||
sk.endTS = randnum;
|
||||
sk.keyFlags = randnum;
|
||||
sk.startTS = randnum;
|
||||
randString(SHORT_STR, sk.keyId);
|
||||
|
||||
std::string randomStr;
|
||||
randString(LARGE_STR, randomStr);
|
||||
|
||||
sk.keyData.setBinData(randomStr.c_str(), randomStr.size());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsTlvKeySignature& ks)
|
||||
{
|
||||
randString(SHORT_STR, ks.keyId);
|
||||
|
||||
std::string signData;
|
||||
randString(LARGE_STR, signData);
|
||||
|
||||
ks.signData.setBinData(signData.c_str(), signData.size());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsTlvImage& im)
|
||||
{
|
||||
std::string imageData;
|
||||
randString(LARGE_STR, imageData);
|
||||
im.binData.setBinData(imageData.c_str(), imageData.size());
|
||||
im.image_type = RSTLV_IMAGE_TYPE_PNG;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvBinaryData& bd1, const RsTlvBinaryData& bd2)
|
||||
{
|
||||
if(bd1.tlvtype != bd2.tlvtype) return false;
|
||||
if(bd1.bin_len != bd2.bin_len) return false;
|
||||
|
||||
unsigned char *bin1 = (unsigned char*)(bd1.bin_data),
|
||||
*bin2 = (unsigned char*)(bd2.bin_data);
|
||||
|
||||
for(uint32_t i=0; i < bd1.bin_len; bin1++, bin2++, i++)
|
||||
{
|
||||
if(*bin1 != *bin2)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsDistribGrp& grp)
|
||||
{
|
||||
@ -137,63 +79,6 @@ RsSerialType* init_item(RsDistribGrp& grp)
|
||||
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvSecurityKey& sk1, const RsTlvSecurityKey& sk2)
|
||||
{
|
||||
|
||||
if(sk1.startTS != sk2.startTS) return false;
|
||||
if(sk1.endTS != sk2.endTS) return false;
|
||||
if(sk1.keyFlags != sk2.keyFlags) return false;
|
||||
if(sk1.keyId != sk2.keyId) return false;
|
||||
if(!(sk1.keyData == sk1.keyData)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvKeySignature& ks1, const RsTlvKeySignature& ks2)
|
||||
{
|
||||
|
||||
if(ks1.keyId != ks2.keyId) return false;
|
||||
if(!(ks1.signData == ks2.signData)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvPeerIdSet& pids1, const RsTlvPeerIdSet& pids2)
|
||||
{
|
||||
std::list<std::string>::const_iterator it1 = pids1.ids.begin(),
|
||||
it2 = pids2.ids.begin();
|
||||
|
||||
|
||||
for(; ((it1 != pids1.ids.end()) && (it2 != pids2.ids.end())); it1++, it2++)
|
||||
{
|
||||
if(*it1 != *it2) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
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(RsDistribGrpKey& gk)
|
||||
{
|
||||
@ -241,114 +126,6 @@ bool operator==(const RsDistribSignedMsg& sMsg1,const RsDistribSignedMsg& sMsg2
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvImage& img1, const RsTlvImage& img2)
|
||||
{
|
||||
if(img1.image_type != img2.image_type) return false;
|
||||
if(!(img1.binData == img2.binData)) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/** channels, forums and blogs **/
|
||||
|
||||
void init_item(RsTlvHashSet& hs)
|
||||
{
|
||||
std::string hash;
|
||||
|
||||
for(int i=0; i < 10; i++)
|
||||
{
|
||||
randString(SHORT_STR, hash);
|
||||
hs.ids.push_back(hash);
|
||||
}
|
||||
|
||||
hs.mType = TLV_TYPE_HASHSET;
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsTlvPeerIdSet& ps)
|
||||
{
|
||||
std::string peer;
|
||||
|
||||
for(int i=0; i < 10; i++)
|
||||
{
|
||||
randString(SHORT_STR, peer);
|
||||
ps.ids.push_back(peer);
|
||||
}
|
||||
|
||||
ps.mType = TLV_TYPE_PEERSET;
|
||||
return;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvHashSet& hs1,const RsTlvHashSet& hs2)
|
||||
{
|
||||
if(hs1.mType != hs2.mType) return false;
|
||||
|
||||
std::list<std::string>::const_iterator it1 = hs1.ids.begin(),
|
||||
it2 = hs2.ids.begin();
|
||||
|
||||
for(; ((it1 != hs1.ids.end()) && (it2 != hs2.ids.end())); it1++, it2++)
|
||||
{
|
||||
if(*it1 != *it2) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void init_item(RsTlvFileItem& fi)
|
||||
{
|
||||
fi.age = rand()%200;
|
||||
fi.filesize = rand()%34030313;
|
||||
randString(SHORT_STR, fi.hash);
|
||||
randString(SHORT_STR, fi.name);
|
||||
randString(SHORT_STR, fi.path);
|
||||
fi.piecesize = rand()%232;
|
||||
fi.pop = rand()%2354;
|
||||
init_item(fi.hashset);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsTlvFileSet& fSet){
|
||||
|
||||
randString(LARGE_STR, fSet.comment);
|
||||
randString(SHORT_STR, fSet.title);
|
||||
RsTlvFileItem fi1, fi2;
|
||||
init_item(fi1);
|
||||
init_item(fi2);
|
||||
fSet.items.push_back(fi1);
|
||||
fSet.items.push_back(fi2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvFileSet& fs1,const RsTlvFileSet& fs2)
|
||||
{
|
||||
if(fs1.comment != fs2.comment) return false;
|
||||
if(fs1.title != fs2.title) return false;
|
||||
|
||||
std::list<RsTlvFileItem>::const_iterator it1 = fs1.items.begin(),
|
||||
it2 = fs2.items.begin();
|
||||
|
||||
for(; ((it1 != fs1.items.end()) && (it2 != fs2.items.end())); it1++, it2++)
|
||||
if(!(*it1 == *it2)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvFileItem& fi1,const RsTlvFileItem& fi2)
|
||||
{
|
||||
if(fi1.age != fi2.age) return false;
|
||||
if(fi1.filesize != fi2.filesize) return false;
|
||||
if(fi1.hash != fi2.hash) return false;
|
||||
if(!(fi1.hashset == fi2.hashset)) return false;
|
||||
if(fi1.name != fi2.name) return false;
|
||||
if(fi1.path != fi2.path) return false;
|
||||
if(fi1.piecesize != fi2.piecesize) return false;
|
||||
if(fi1.pop != fi2.pop) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsChannelMsg& chMsg)
|
||||
{
|
||||
@ -428,6 +205,31 @@ RsSerialType* init_item(RsBlogMsg& bMsg)
|
||||
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);
|
||||
@ -472,6 +274,8 @@ bool operator==(const RsForumReadStatus& frs1, const RsForumReadStatus& frs2)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator==(const RsBlogMsg& bMsg1,const RsBlogMsg& bMsg2)
|
||||
{
|
||||
|
||||
@ -495,85 +299,17 @@ bool operator==(const RsBlogMsg& bMsg1,const RsBlogMsg& bMsg2)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param T item you want to serialise
|
||||
*/
|
||||
template<class T> int test_RsDistribItem()
|
||||
{
|
||||
|
||||
/* make a serialisable RsTurtleItem */
|
||||
|
||||
RsSerialiser srl;
|
||||
|
||||
/* initialise */
|
||||
T rsfi ;
|
||||
RsSerialType *rsfis = init_item(rsfi) ;
|
||||
|
||||
/* attempt to serialise it before we add it to the serialiser */
|
||||
|
||||
CHECK(0 == srl.size(&rsfi));
|
||||
|
||||
static const uint32_t MAX_BUFSIZE = 16000 ;
|
||||
|
||||
char *buffer = new char[MAX_BUFSIZE];
|
||||
uint32_t sersize = MAX_BUFSIZE;
|
||||
|
||||
CHECK(false == srl.serialise(&rsfi, (void *) buffer, &sersize));
|
||||
|
||||
/* now add to serialiser */
|
||||
|
||||
srl.addSerialType(rsfis);
|
||||
|
||||
uint32_t size = srl.size(&rsfi);
|
||||
bool done = srl.serialise(&rsfi, (void *) buffer, &sersize);
|
||||
|
||||
std::cerr << "test_Item() size: " << size << std::endl;
|
||||
std::cerr << "test_Item() done: " << done << std::endl;
|
||||
std::cerr << "test_Item() sersize: " << sersize << std::endl;
|
||||
|
||||
std::cerr << "test_Item() serialised:" << std::endl;
|
||||
// displayRawPacket(std::cerr, (void *) buffer, sersize);
|
||||
|
||||
CHECK(done == true);
|
||||
|
||||
uint32_t sersize2 = sersize;
|
||||
RsItem *output = srl.deserialise((void *) buffer, &sersize2);
|
||||
|
||||
CHECK(output != NULL);
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
T *outfi = dynamic_cast<T *>(output);
|
||||
|
||||
CHECK(outfi != NULL);
|
||||
|
||||
if (outfi)
|
||||
CHECK(*outfi == rsfi) ;
|
||||
|
||||
sersize2 = MAX_BUFSIZE;
|
||||
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||
|
||||
CHECK(done2) ;
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
// displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||
|
||||
delete[] buffer ;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
std::cerr << "RsDistribItem Tests" << std::endl;
|
||||
|
||||
test_RsDistribItem<RsDistribGrp>(); REPORT("Serialise/Deserialise RsDistribGrp");
|
||||
test_RsDistribItem<RsDistribGrpKey>(); REPORT("Serialise/Deserialise RsDistribGrpKey");
|
||||
test_RsDistribItem<RsDistribSignedMsg>(); REPORT("Serialise/Deserialise RsDistribSignedMsg");
|
||||
test_RsDistribItem<RsChannelMsg>(); REPORT("Serialise/Deserialise RsChannelMsg");
|
||||
test_RsDistribItem<RsForumMsg>(); REPORT("Serialise/Deserialise RsForumMsg");
|
||||
test_RsDistribItem<RsForumReadStatus>(); REPORT("Serialise/Deserialise RsForumReadStatus");
|
||||
test_RsDistribItem<RsBlogMsg>(); REPORT("Serialise/Deserialise RsBlogMsg");
|
||||
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");
|
||||
|
@ -25,13 +25,13 @@
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsdistribitems.h"
|
||||
#include "serialiser/rschannelitems.h"
|
||||
#include "serialiser/rsforumitems.h"
|
||||
#include "serialiser/rsblogitems.h"
|
||||
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
|
||||
RsSerialType* init_item(RsDistribGrp&);
|
||||
RsSerialType* init_item(RsDistribGrpKey&);
|
||||
@ -49,22 +49,6 @@ bool operator==(const RsForumMsg& , const RsForumMsg& );
|
||||
bool operator==(const RsForumReadStatus&, const RsForumReadStatus& );
|
||||
bool operator==(const RsBlogMsg& , const RsBlogMsg& );
|
||||
|
||||
void init_item(RsTlvSecurityKey&);
|
||||
void init_item(RsTlvKeySignature&);
|
||||
void init_item(RsTlvBinaryData&);
|
||||
void init_item(RsTlvFileItem&);
|
||||
void init_item(RsTlvFileSet&);
|
||||
void init_item(RsTlvHashSet&);
|
||||
void init_item(RsTlvPeerIdSet&);
|
||||
void init_item(RsTlvImage&);
|
||||
|
||||
bool operator==(const RsTlvSecurityKey&, const RsTlvSecurityKey& );
|
||||
bool operator==(const RsTlvKeySignature&, const RsTlvKeySignature& );
|
||||
bool operator==(const RsTlvBinaryData&, const RsTlvBinaryData&);
|
||||
bool operator==(const RsTlvFileItem&, const RsTlvFileItem&);
|
||||
bool operator==(const RsTlvFileSet&, const RsTlvFileSet& );
|
||||
bool operator==(const RsTlvHashSet&, const RsTlvHashSet&);
|
||||
bool operator==(const RsTlvImage&, const RsTlvImage& );
|
||||
|
||||
|
||||
|
||||
|
160
libretroshare/src/tests/serialiser/rsmsgitem_test.cc
Normal file
160
libretroshare/src/tests/serialiser/rsmsgitem_test.cc
Normal file
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* libretroshare/src/tests/serialiser: msgitem_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/rsmsgitems.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
#include "support.h"
|
||||
#include "rsmsgitem_test.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
RsSerialType* init_item(RsChatMsgItem& cmi)
|
||||
{
|
||||
cmi.chatFlags = rand()%34;
|
||||
cmi.sendTime = rand()%422224;
|
||||
randString(LARGE_STR, cmi.message);
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsChatStatusItem& csi)
|
||||
{
|
||||
|
||||
randString(SHORT_STR, csi.status_string);
|
||||
csi.flags = rand()%232;
|
||||
|
||||
return new RsChatSerialiser();
|
||||
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsChatAvatarItem& cai)
|
||||
{
|
||||
std::string image_data;
|
||||
randString(LARGE_STR, image_data);
|
||||
cai.image_data = new unsigned char[image_data.size()];
|
||||
|
||||
memcpy(cai.image_data, image_data.c_str(), image_data.size());
|
||||
cai.image_size = image_data.size();
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsMsgItem& mi)
|
||||
{
|
||||
init_item(mi.attachment);
|
||||
init_item(mi.msgbcc);
|
||||
init_item(mi.msgcc);
|
||||
init_item(mi.msgto);
|
||||
|
||||
randString(LARGE_STR, mi.message);
|
||||
randString(SHORT_STR, mi.subject);
|
||||
|
||||
mi.recvTime = rand()%32;
|
||||
mi.sendTime = mi.recvTime;
|
||||
mi.msgFlags = mi.recvTime;
|
||||
|
||||
return new RsMsgSerialiser();
|
||||
}
|
||||
|
||||
bool operator ==(const RsChatMsgItem& cmiLeft,const RsChatMsgItem& cmiRight)
|
||||
{
|
||||
|
||||
if(cmiLeft.chatFlags != cmiRight.chatFlags) return false;
|
||||
if(cmiLeft.message != cmiRight.message) return false;
|
||||
if(cmiLeft.sendTime != cmiRight.sendTime) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsChatStatusItem& csiLeft, const RsChatStatusItem& csiRight)
|
||||
{
|
||||
if(csiLeft.flags != csiRight.flags) return false;
|
||||
if(csiLeft.status_string != csiRight.status_string) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator ==(const RsChatAvatarItem& caiLeft, const RsChatAvatarItem& caiRight)
|
||||
{
|
||||
unsigned char* image_dataLeft = (unsigned char*)caiLeft.image_data;
|
||||
unsigned char* image_dataRight = (unsigned char*)caiRight.image_data;
|
||||
|
||||
// make image sizes are the same to prevent dereferencing garbage
|
||||
if(caiLeft.image_size == caiRight.image_size)
|
||||
{
|
||||
image_dataLeft = (unsigned char*)caiLeft.image_data;
|
||||
image_dataRight = (unsigned char*)caiRight.image_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < caiLeft.image_size; i++)
|
||||
if(image_dataLeft[i] != image_dataRight[i]) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool operator ==(const RsMsgItem& miLeft, const RsMsgItem& miRight)
|
||||
{
|
||||
if(miLeft.message != miRight.message) return false;
|
||||
if(miLeft.msgFlags != miRight.msgFlags) return false;
|
||||
if(miLeft.recvTime != miRight.recvTime) return false;
|
||||
if(miLeft.sendTime != miRight.sendTime) return false;
|
||||
if(miLeft.subject != miRight.subject) return false;
|
||||
|
||||
if(!(miLeft.attachment == miRight.attachment)) return false;
|
||||
if(!(miLeft.msgbcc == miRight.msgbcc)) return false;
|
||||
if(!(miLeft.msgcc == miRight.msgcc)) return false;
|
||||
if(!(miLeft.msgto == miRight.msgto)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
test_RsItem<RsChatMsgItem >(); REPORT("Serialise/Deserialise RsChatMsgItem");
|
||||
test_RsItem<RsChatStatusItem >(); REPORT("Serialise/Deserialise RsChatStatusItem");
|
||||
test_RsItem<RsChatAvatarItem >(); REPORT("Serialise/Deserialise RsChatAvatarItem");
|
||||
test_RsItem<RsMsgItem >(); REPORT("Serialise/Deserialise RsMsgItem");
|
||||
|
||||
FINALREPORT("RsMsgItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
47
libretroshare/src/tests/serialiser/rsmsgitem_test.h
Normal file
47
libretroshare/src/tests/serialiser/rsmsgitem_test.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef MSGITEM_TEST_H_
|
||||
#define MSGITEM_TEST_H_
|
||||
|
||||
/*
|
||||
* libretroshare/src/tests/serialiser: msgitem_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/rsmsgitems.h"
|
||||
|
||||
|
||||
RsSerialType* init_item(RsChatMsgItem& );
|
||||
RsSerialType* init_item(RsChatStatusItem& );
|
||||
RsSerialType* init_item(RsChatAvatarItem& );
|
||||
RsSerialType* init_item(RsMsgItem& );
|
||||
|
||||
bool operator ==(const RsChatMsgItem& ,const RsChatMsgItem& );
|
||||
bool operator ==(const RsChatStatusItem& , const RsChatStatusItem& );
|
||||
bool operator ==(const RsChatAvatarItem&, const RsChatAvatarItem& );
|
||||
|
||||
// TODO: does not test for msgId
|
||||
bool operator ==(const RsMsgItem&, const RsMsgItem& );
|
||||
|
||||
|
||||
#endif /* MSGITEM_TEST_H_ */
|
51
libretroshare/src/tests/serialiser/rsstatusitem_test.cc
Normal file
51
libretroshare/src/tests/serialiser/rsstatusitem_test.cc
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* libretroshare/src/tests/serialiser: rsstatusitem_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 "support.h"
|
||||
#include "rsstatusitem_test.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
RsSerialType* init_item(RsStatusItem& rsi)
|
||||
{
|
||||
|
||||
return new RsStatusSerialiser();
|
||||
}
|
||||
|
||||
bool operator ==(RsStatusItem& rsi1, RsStatusItem& rsi2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
test_RsItem<RsStatusItem >(); REPORT("Serialise/Deserialise RsStatusItem");
|
||||
FINALREPORT("RsStatusItem Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
35
libretroshare/src/tests/serialiser/rsstatusitem_test.h
Normal file
35
libretroshare/src/tests/serialiser/rsstatusitem_test.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef RSSTATUS_TEST_H_
|
||||
#define RSSTATUS_TEST_H_
|
||||
|
||||
/*
|
||||
* libretroshare/src/tests/serialiser: rsstatusitem_test.h
|
||||
*
|
||||
* 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 "serialiser/rsstatusitems.h"
|
||||
|
||||
RsSerialType* init_item(RsStatusItem& );
|
||||
|
||||
bool operator ==(RsStatusItem& , RsStatusItem& );
|
||||
|
||||
#endif /* RSSTATUS_TEST_H_ */
|
@ -32,10 +32,11 @@
|
||||
#include <serialiser/rstunnelitems.h>
|
||||
#include <serialiser/rstlvutil.h>
|
||||
#include "util/utest.h"
|
||||
#include "support.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
void init_item(RsTunnelDataItem& item)
|
||||
|
||||
RsTunnelSerialiser* init_item(RsTunnelDataItem& item)
|
||||
{
|
||||
uint32_t S = lrand48()%20000 ;
|
||||
item.encoded_data = malloc(S) ;
|
||||
@ -45,6 +46,8 @@ void init_item(RsTunnelDataItem& item)
|
||||
item.sourcePeerId = "67641e38df0e75432033d222eae93fff" ;
|
||||
item.relayPeerId = "6013bfc2cea7ab823af7a79fb3ca0df1" ;
|
||||
item.destPeerId = "1d5768db7cd4720d0eb75cc1917da332" ;
|
||||
|
||||
return new RsTunnelSerialiser();
|
||||
}
|
||||
bool operator==(const RsTunnelDataItem& it1,const RsTunnelDataItem& it2)
|
||||
{
|
||||
@ -58,7 +61,8 @@ bool operator==(const RsTunnelDataItem& it1,const RsTunnelDataItem& it2)
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
void init_item(RsTunnelHandshakeItem& item)
|
||||
|
||||
RsTunnelSerialiser* init_item(RsTunnelHandshakeItem& item)
|
||||
{
|
||||
item.sourcePeerId = "67641e38df0e75432033d222eae93fff" ;
|
||||
item.relayPeerId = "6013bfc2cea7ab823af7a79fb3ca0df1" ;
|
||||
@ -69,6 +73,8 @@ void init_item(RsTunnelHandshakeItem& item)
|
||||
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)
|
||||
{
|
||||
@ -81,68 +87,7 @@ bool operator==(const RsTunnelHandshakeItem& it1,const RsTunnelHandshakeItem& it
|
||||
return true ;
|
||||
}
|
||||
|
||||
template<class T> int test_RsItem()
|
||||
{
|
||||
/* make a serialisable RsTurtleItem */
|
||||
|
||||
RsSerialiser srl;
|
||||
|
||||
/* initialise */
|
||||
T rsfi ;
|
||||
init_item(rsfi) ;
|
||||
|
||||
/* attempt to serialise it before we add it to the serialiser */
|
||||
|
||||
CHECK(0 == srl.size(&rsfi));
|
||||
|
||||
static const uint32_t MAX_BUFSIZE = 22000 ;
|
||||
|
||||
char *buffer = new char[MAX_BUFSIZE];
|
||||
uint32_t sersize = MAX_BUFSIZE;
|
||||
|
||||
CHECK(false == srl.serialise(&rsfi, (void *) buffer, &sersize));
|
||||
|
||||
/* now add to serialiser */
|
||||
|
||||
RsTunnelSerialiser *rsfis = new RsTunnelSerialiser();
|
||||
srl.addSerialType(rsfis);
|
||||
|
||||
uint32_t size = srl.size(&rsfi);
|
||||
bool done = srl.serialise(&rsfi, (void *) buffer, &sersize);
|
||||
|
||||
std::cerr << "test_Item() size: " << size << std::endl;
|
||||
std::cerr << "test_Item() done: " << done << std::endl;
|
||||
std::cerr << "test_Item() sersize: " << sersize << std::endl;
|
||||
|
||||
std::cerr << "test_Item() serialised:" << std::endl;
|
||||
displayRawPacket(std::cerr, (void *) buffer, sersize);
|
||||
|
||||
CHECK(done == true);
|
||||
|
||||
uint32_t sersize2 = sersize;
|
||||
RsItem *output = srl.deserialise((void *) buffer, &sersize2);
|
||||
|
||||
CHECK(output != NULL);
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
T *outfi = dynamic_cast<T *>(output);
|
||||
|
||||
CHECK(outfi != NULL);
|
||||
|
||||
if (outfi)
|
||||
CHECK(*outfi == rsfi) ;
|
||||
|
||||
sersize2 = MAX_BUFSIZE;
|
||||
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||
|
||||
CHECK(done2) ;
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||
|
||||
delete[] buffer ;
|
||||
return 1;
|
||||
}
|
||||
INITTEST();
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -31,15 +31,18 @@
|
||||
#include <sstream>
|
||||
#include "turtle/rsturtleitem.h"
|
||||
#include <serialiser/rstlvutil.h>
|
||||
#include "support.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
void init_item(CompressedChunkMap& map)
|
||||
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)
|
||||
{
|
||||
@ -58,10 +61,11 @@ bool operator==(const RsTurtleFileMapRequestItem& it1,const RsTurtleFileMapReque
|
||||
|
||||
return true ;
|
||||
}
|
||||
void init_item(RsTurtleFileMapRequestItem& item)
|
||||
RsSerialType* init_item(RsTurtleFileMapRequestItem& item)
|
||||
{
|
||||
item.direction = 1 ;
|
||||
item.tunnel_id = 0x4ff823e2 ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileMapItem& it1,const RsTurtleFileMapItem& it2)
|
||||
{
|
||||
@ -71,13 +75,14 @@ bool operator==(const RsTurtleFileMapItem& it1,const RsTurtleFileMapItem& it2)
|
||||
|
||||
return true ;
|
||||
}
|
||||
void init_item(RsTurtleFileMapItem& item)
|
||||
RsSerialType* init_item(RsTurtleFileMapItem& item)
|
||||
{
|
||||
item.direction = 1 ;
|
||||
item.tunnel_id = 0xf48fe232 ;
|
||||
init_item(item.compressed_map) ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
void init_item(RsTurtleFileDataItem& item)
|
||||
RsSerialType* init_item(RsTurtleFileDataItem& item)
|
||||
{
|
||||
static const uint32_t S = 3456 ;
|
||||
item.tunnel_id = 0x33eef982 ;
|
||||
@ -86,6 +91,7 @@ void init_item(RsTurtleFileDataItem& item)
|
||||
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)
|
||||
{
|
||||
@ -97,11 +103,12 @@ bool operator==(const RsTurtleFileDataItem& i1,const RsTurtleFileDataItem& i2)
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
void init_item(RsTurtleFileRequestItem& item)
|
||||
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)
|
||||
{
|
||||
@ -111,10 +118,11 @@ bool operator==(const RsTurtleFileRequestItem& it1,const RsTurtleFileRequestItem
|
||||
|
||||
return true ;
|
||||
}
|
||||
void init_item(RsTurtleTunnelOkItem& item)
|
||||
RsSerialType* init_item(RsTurtleTunnelOkItem& item)
|
||||
{
|
||||
item.tunnel_id = lrand48() ;
|
||||
item.request_id = lrand48() ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleTunnelOkItem& it1,const RsTurtleTunnelOkItem& it2)
|
||||
{
|
||||
@ -122,12 +130,13 @@ bool operator==(const RsTurtleTunnelOkItem& it1,const RsTurtleTunnelOkItem& it2)
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
return true ;
|
||||
}
|
||||
void init_item(RsTurtleOpenTunnelItem& item)
|
||||
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)
|
||||
{
|
||||
@ -137,7 +146,7 @@ bool operator==(const RsTurtleOpenTunnelItem& it1,const RsTurtleOpenTunnelItem&
|
||||
if(it1.file_hash != it2.file_hash) return false ;
|
||||
return true ;
|
||||
}
|
||||
void init_item(RsTurtleRegExpSearchRequestItem& item)
|
||||
RsSerialType* init_item(RsTurtleRegExpSearchRequestItem& item)
|
||||
{
|
||||
item.request_id = lrand48() ;
|
||||
item.depth = lrand48() ;
|
||||
@ -148,6 +157,7 @@ void init_item(RsTurtleRegExpSearchRequestItem& item)
|
||||
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)
|
||||
{
|
||||
@ -161,11 +171,12 @@ bool operator==(const RsTurtleRegExpSearchRequestItem& it1,const RsTurtleRegExpS
|
||||
for(uint32_t i=0;i<it1.expr._strings.size();++i) if(it1.expr._strings[i] != it2.expr._strings[i]) return false ;
|
||||
return true ;
|
||||
}
|
||||
void init_item(RsTurtleStringSearchRequestItem& item)
|
||||
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)
|
||||
{
|
||||
@ -175,11 +186,12 @@ bool operator==(const RsTurtleStringSearchRequestItem& it1,const RsTurtleStringS
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
void init_item(TurtleFileInfo& info)
|
||||
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)
|
||||
{
|
||||
@ -188,7 +200,7 @@ bool operator==(const TurtleFileInfo& it1,const TurtleFileInfo& it2)
|
||||
if(it1.size != it2.size) return false ;
|
||||
return true ;
|
||||
}
|
||||
void init_item(RsTurtleSearchResultItem& item)
|
||||
RsSerialType* init_item(RsTurtleSearchResultItem& item)
|
||||
{
|
||||
item.depth = lrand48() ;
|
||||
item.request_id = lrand48() ;
|
||||
@ -200,6 +212,7 @@ void init_item(RsTurtleSearchResultItem& item)
|
||||
init_item(f) ;
|
||||
item.result.push_back(f) ;
|
||||
}
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleSearchResultItem& it1,const RsTurtleSearchResultItem& it2)
|
||||
{
|
||||
@ -216,84 +229,21 @@ bool operator==(const RsTurtleSearchResultItem& it1,const RsTurtleSearchResultIt
|
||||
return true ;
|
||||
}
|
||||
|
||||
template<class T> int test_RsTurtleItem()
|
||||
{
|
||||
/* make a serialisable RsTurtleItem */
|
||||
|
||||
RsSerialiser srl;
|
||||
|
||||
/* initialise */
|
||||
T rsfi ;
|
||||
init_item(rsfi) ;
|
||||
|
||||
/* attempt to serialise it before we add it to the serialiser */
|
||||
|
||||
CHECK(0 == srl.size(&rsfi));
|
||||
|
||||
static const uint32_t MAX_BUFSIZE = 16000 ;
|
||||
|
||||
char *buffer = new char[MAX_BUFSIZE];
|
||||
uint32_t sersize = MAX_BUFSIZE;
|
||||
|
||||
CHECK(false == srl.serialise(&rsfi, (void *) buffer, &sersize));
|
||||
|
||||
/* now add to serialiser */
|
||||
|
||||
RsTurtleSerialiser *rsfis = new RsTurtleSerialiser();
|
||||
srl.addSerialType(rsfis);
|
||||
|
||||
uint32_t size = srl.size(&rsfi);
|
||||
bool done = srl.serialise(&rsfi, (void *) buffer, &sersize);
|
||||
|
||||
std::cerr << "test_Item() size: " << size << std::endl;
|
||||
std::cerr << "test_Item() done: " << done << std::endl;
|
||||
std::cerr << "test_Item() sersize: " << sersize << std::endl;
|
||||
|
||||
std::cerr << "test_Item() serialised:" << std::endl;
|
||||
displayRawPacket(std::cerr, (void *) buffer, sersize);
|
||||
|
||||
CHECK(done == true);
|
||||
|
||||
uint32_t sersize2 = sersize;
|
||||
RsItem *output = srl.deserialise((void *) buffer, &sersize2);
|
||||
|
||||
CHECK(output != NULL);
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
T *outfi = dynamic_cast<T *>(output);
|
||||
|
||||
CHECK(outfi != NULL);
|
||||
|
||||
if (outfi)
|
||||
CHECK(*outfi == rsfi) ;
|
||||
|
||||
sersize2 = MAX_BUFSIZE;
|
||||
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||
|
||||
CHECK(done2) ;
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||
|
||||
delete[] buffer ;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsTurtleItem Tests" << std::endl;
|
||||
|
||||
for(uint32_t i=0;i<20;++i)
|
||||
{
|
||||
test_RsTurtleItem<RsTurtleFileMapRequestItem>(); REPORT("Serialise/Deserialise RsTurtleFileMapRequestItem");
|
||||
test_RsTurtleItem<RsTurtleFileMapItem >(); REPORT("Serialise/Deserialise RsTurtleFileMapItem");
|
||||
test_RsTurtleItem<RsTurtleFileDataItem >(); REPORT("Serialise/Deserialise RsTurtleFileDataItem");
|
||||
test_RsTurtleItem<RsTurtleFileRequestItem >(); REPORT("Serialise/Deserialise RsTurtleFileRequestItem");
|
||||
test_RsTurtleItem<RsTurtleTunnelOkItem >(); REPORT("Serialise/Deserialise RsTurtleTunnelOkItem ");
|
||||
test_RsTurtleItem<RsTurtleOpenTunnelItem >(); REPORT("Serialise/Deserialise RsTurtleOpenTunnelItem ");
|
||||
test_RsTurtleItem<RsTurtleSearchResultItem >(); REPORT("Serialise/Deserialise RsTurtleSearchResultItem ");
|
||||
test_RsTurtleItem<RsTurtleStringSearchRequestItem >(); REPORT("Serialise/Deserialise RsTurtleStringSearchRequestItem ");
|
||||
test_RsTurtleItem<RsTurtleRegExpSearchRequestItem >(); REPORT("Serialise/Deserialise RsTurtleRegExpSearchRequestItem ");
|
||||
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");
|
||||
|
@ -26,8 +26,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "support.h"
|
||||
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
void randString(const uint32_t length, std::string& outStr)
|
||||
{
|
||||
@ -36,7 +35,7 @@ void randString(const uint32_t length, std::string& outStr)
|
||||
|
||||
stringData = new char[length];
|
||||
|
||||
for(int i=0; i != length; i++)
|
||||
for(uint32_t i=0; i != length; i++)
|
||||
stringData[i] = alpha + (rand() % 26);
|
||||
|
||||
outStr.assign(stringData, length);
|
||||
@ -52,7 +51,7 @@ void randString(const uint32_t length, std::wstring& outStr)
|
||||
|
||||
stringData = new wchar_t[length];
|
||||
|
||||
for(int i=0; i != length; i++)
|
||||
for(uint32_t i=0; i != length; i++)
|
||||
stringData[i] = (alpha + (rand() % 26));
|
||||
|
||||
outStr.assign(stringData, length);
|
||||
@ -60,3 +59,207 @@ void randString(const uint32_t length, std::wstring& outStr)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvSecurityKey& sk1, const RsTlvSecurityKey& sk2)
|
||||
{
|
||||
|
||||
if(sk1.startTS != sk2.startTS) return false;
|
||||
if(sk1.endTS != sk2.endTS) return false;
|
||||
if(sk1.keyFlags != sk2.keyFlags) return false;
|
||||
if(sk1.keyId != sk2.keyId) return false;
|
||||
if(!(sk1.keyData == sk1.keyData)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvKeySignature& ks1, const RsTlvKeySignature& ks2)
|
||||
{
|
||||
|
||||
if(ks1.keyId != ks2.keyId) return false;
|
||||
if(!(ks1.signData == ks2.signData)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvPeerIdSet& pids1, const RsTlvPeerIdSet& pids2)
|
||||
{
|
||||
std::list<std::string>::const_iterator it1 = pids1.ids.begin(),
|
||||
it2 = pids2.ids.begin();
|
||||
|
||||
|
||||
for(; ((it1 != pids1.ids.end()) && (it2 != pids2.ids.end())); it1++, it2++)
|
||||
{
|
||||
if(*it1 != *it2) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void init_item(RsTlvImage& im)
|
||||
{
|
||||
std::string imageData;
|
||||
randString(LARGE_STR, imageData);
|
||||
im.binData.setBinData(imageData.c_str(), imageData.size());
|
||||
im.image_type = RSTLV_IMAGE_TYPE_PNG;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvBinaryData& bd1, const RsTlvBinaryData& bd2)
|
||||
{
|
||||
if(bd1.tlvtype != bd2.tlvtype) return false;
|
||||
if(bd1.bin_len != bd2.bin_len) return false;
|
||||
|
||||
unsigned char *bin1 = (unsigned char*)(bd1.bin_data),
|
||||
*bin2 = (unsigned char*)(bd2.bin_data);
|
||||
|
||||
for(uint32_t i=0; i < bd1.bin_len; bin1++, bin2++, i++)
|
||||
{
|
||||
if(*bin1 != *bin2)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void init_item(RsTlvSecurityKey& sk)
|
||||
{
|
||||
int randnum = rand()%313131;
|
||||
|
||||
sk.endTS = randnum;
|
||||
sk.keyFlags = randnum;
|
||||
sk.startTS = randnum;
|
||||
randString(SHORT_STR, sk.keyId);
|
||||
|
||||
std::string randomStr;
|
||||
randString(LARGE_STR, randomStr);
|
||||
|
||||
sk.keyData.setBinData(randomStr.c_str(), randomStr.size());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsTlvKeySignature& ks)
|
||||
{
|
||||
randString(SHORT_STR, ks.keyId);
|
||||
|
||||
std::string signData;
|
||||
randString(LARGE_STR, signData);
|
||||
|
||||
ks.signData.setBinData(signData.c_str(), signData.size());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const RsTlvImage& img1, const RsTlvImage& img2)
|
||||
{
|
||||
if(img1.image_type != img2.image_type) return false;
|
||||
if(!(img1.binData == img2.binData)) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/** channels, forums and blogs **/
|
||||
|
||||
void init_item(RsTlvHashSet& hs)
|
||||
{
|
||||
std::string hash;
|
||||
|
||||
for(int i=0; i < 10; i++)
|
||||
{
|
||||
randString(SHORT_STR, hash);
|
||||
hs.ids.push_back(hash);
|
||||
}
|
||||
|
||||
hs.mType = TLV_TYPE_HASHSET;
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsTlvPeerIdSet& ps)
|
||||
{
|
||||
std::string peer;
|
||||
|
||||
for(int i=0; i < 10; i++)
|
||||
{
|
||||
randString(SHORT_STR, peer);
|
||||
ps.ids.push_back(peer);
|
||||
}
|
||||
|
||||
ps.mType = TLV_TYPE_PEERSET;
|
||||
return;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvHashSet& hs1,const RsTlvHashSet& hs2)
|
||||
{
|
||||
if(hs1.mType != hs2.mType) return false;
|
||||
|
||||
std::list<std::string>::const_iterator it1 = hs1.ids.begin(),
|
||||
it2 = hs2.ids.begin();
|
||||
|
||||
for(; ((it1 != hs1.ids.end()) && (it2 != hs2.ids.end())); it1++, it2++)
|
||||
{
|
||||
if(*it1 != *it2) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void init_item(RsTlvFileItem& fi)
|
||||
{
|
||||
fi.age = rand()%200;
|
||||
fi.filesize = rand()%34030313;
|
||||
randString(SHORT_STR, fi.hash);
|
||||
randString(SHORT_STR, fi.name);
|
||||
randString(SHORT_STR, fi.path);
|
||||
fi.piecesize = rand()%232;
|
||||
fi.pop = rand()%2354;
|
||||
init_item(fi.hashset);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsTlvFileSet& fSet){
|
||||
|
||||
randString(LARGE_STR, fSet.comment);
|
||||
randString(SHORT_STR, fSet.title);
|
||||
RsTlvFileItem fi1, fi2;
|
||||
init_item(fi1);
|
||||
init_item(fi2);
|
||||
fSet.items.push_back(fi1);
|
||||
fSet.items.push_back(fi2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvFileSet& fs1,const RsTlvFileSet& fs2)
|
||||
{
|
||||
if(fs1.comment != fs2.comment) return false;
|
||||
if(fs1.title != fs2.title) return false;
|
||||
|
||||
std::list<RsTlvFileItem>::const_iterator it1 = fs1.items.begin(),
|
||||
it2 = fs2.items.begin();
|
||||
|
||||
for(; ((it1 != fs1.items.end()) && (it2 != fs2.items.end())); it1++, it2++)
|
||||
if(!(*it1 == *it2)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvFileItem& fi1,const RsTlvFileItem& fi2)
|
||||
{
|
||||
if(fi1.age != fi2.age) return false;
|
||||
if(fi1.filesize != fi2.filesize) return false;
|
||||
if(fi1.hash != fi2.hash) return false;
|
||||
if(!(fi1.hashset == fi2.hashset)) return false;
|
||||
if(fi1.name != fi2.name) return false;
|
||||
if(fi1.path != fi2.path) return false;
|
||||
if(fi1.piecesize != fi2.piecesize) return false;
|
||||
if(fi1.pop != fi2.pop) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* RetroShare Serialiser tests.
|
||||
*
|
||||
* Copyright 2007-2008 by Christopher Evi-Parker
|
||||
* Copyright 2007-2008 by Christopher Evi-Parker, Cyril Soler
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
@ -28,8 +28,134 @@
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "util/utest.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This contains functions that may be useful for testing throughout the
|
||||
* retroshare's serialiser
|
||||
* package, if you find a function you keep using everywhere, might be a good idea to add it here
|
||||
*/
|
||||
|
||||
|
||||
#define SHORT_STR 100
|
||||
#define LARGE_STR 1000
|
||||
|
||||
void randString(const uint32_t, std::string&);
|
||||
void randString(const uint32_t, std::wstring&);
|
||||
|
||||
|
||||
/* for testing compound tlv items */
|
||||
|
||||
void init_item(RsTlvSecurityKey&);
|
||||
void init_item(RsTlvKeySignature&);
|
||||
void init_item(RsTlvBinaryData&);
|
||||
void init_item(RsTlvFileItem&);
|
||||
void init_item(RsTlvFileSet&);
|
||||
void init_item(RsTlvHashSet&);
|
||||
void init_item(RsTlvPeerIdSet&);
|
||||
void init_item(RsTlvImage&);
|
||||
void init_item(RsTlvPeerIdSet&);
|
||||
|
||||
bool operator==(const RsTlvSecurityKey&, const RsTlvSecurityKey& );
|
||||
bool operator==(const RsTlvKeySignature&, const RsTlvKeySignature& );
|
||||
bool operator==(const RsTlvBinaryData&, const RsTlvBinaryData&);
|
||||
bool operator==(const RsTlvFileItem&, const RsTlvFileItem&);
|
||||
bool operator==(const RsTlvFileSet&, const RsTlvFileSet& );
|
||||
bool operator==(const RsTlvHashSet&, const RsTlvHashSet&);
|
||||
bool operator==(const RsTlvImage&, const RsTlvImage& );
|
||||
bool operator==(const RsTlvPeerIdSet& , const RsTlvPeerIdSet& );
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* This templated test function which allows you to test
|
||||
* retroshare serialiser items (except compound tlv items)
|
||||
* you the function must implement a function
|
||||
*
|
||||
* 'RsSerialType* init_item(YourRsItem& rs_item)'
|
||||
* which returns valid serialiser that
|
||||
* can serialiser rs_item. You also need to implement an operator
|
||||
*
|
||||
* Also need to implement a function
|
||||
* 'bool operator =(YourRsItem& rs_itemL, YourRsItem& rs_temR)'
|
||||
* which allows this function to test for equality between both parameters.
|
||||
* rs_temR is the result of deserialising the left operand (1st parameter).
|
||||
* not YourRsItem in specifier in about functions should be a derived type from RsItem
|
||||
*
|
||||
* @param T the item you want to test
|
||||
*/
|
||||
|
||||
template<class T> int test_RsItem()
|
||||
{
|
||||
/* make a serialisable RsTurtleItem */
|
||||
|
||||
RsSerialiser srl;
|
||||
|
||||
/* initialise */
|
||||
T rsfi ;
|
||||
RsSerialType *rsfis = init_item(rsfi) ;
|
||||
|
||||
/* attempt to serialise it before we add it to the serialiser */
|
||||
|
||||
CHECK(0 == srl.size(&rsfi));
|
||||
|
||||
static const uint32_t MAX_BUFSIZE = 22000 ;
|
||||
|
||||
char *buffer = new char[MAX_BUFSIZE];
|
||||
uint32_t sersize = MAX_BUFSIZE;
|
||||
|
||||
CHECK(false == srl.serialise(&rsfi, (void *) buffer, &sersize));
|
||||
|
||||
/* now add to serialiser */
|
||||
|
||||
srl.addSerialType(rsfis);
|
||||
|
||||
uint32_t size = srl.size(&rsfi);
|
||||
bool done = srl.serialise(&rsfi, (void *) buffer, &sersize);
|
||||
|
||||
std::cerr << "test_Item() size: " << size << std::endl;
|
||||
std::cerr << "test_Item() done: " << done << std::endl;
|
||||
std::cerr << "test_Item() sersize: " << sersize << std::endl;
|
||||
|
||||
std::cerr << "test_Item() serialised:" << std::endl;
|
||||
//displayRawPacket(std::cerr, (void *) buffer, sersize);
|
||||
|
||||
CHECK(done == true);
|
||||
|
||||
uint32_t sersize2 = sersize;
|
||||
RsItem *output = srl.deserialise((void *) buffer, &sersize2);
|
||||
|
||||
CHECK(output != NULL);
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
T *outfi = dynamic_cast<T *>(output);
|
||||
|
||||
CHECK(outfi != NULL);
|
||||
|
||||
if (outfi)
|
||||
CHECK(*outfi == rsfi) ;
|
||||
|
||||
sersize2 = MAX_BUFSIZE;
|
||||
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||
|
||||
CHECK(done2) ;
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
// displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||
|
||||
delete[] buffer ;
|
||||
//delete rsfis;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#endif /* SUPPORT_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user