mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-20 23:10:39 -04:00
* Moved final serialiser test over, and test notes from ft.
* removed tests from lib directories for serialiser / dbase / ft git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3177 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
05bc4ba76e
commit
3855be974b
29 changed files with 1 additions and 4669 deletions
|
@ -1,75 +0,0 @@
|
|||
|
||||
RS_TOP_DIR = ..
|
||||
##### Define any flags that are needed for this section #######
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/scripts/config.mk
|
||||
###############################################################
|
||||
|
||||
RSOBJ = rsserial.o rsbaseserial.o rstlvbase.o rstlvtypes.o
|
||||
RSOBJ += rstlvfileitem.o # TLV Objs
|
||||
RSOBJ += rstlvkeys.o # TLV Objs
|
||||
RSOBJ += rstlvimage.o # TLV Objs
|
||||
RSOBJ += rstlvutil.o # TLV Objs
|
||||
RSOBJ += rstlvkvwide.o # TLV Objs
|
||||
RSOBJ += rsbaseitems.o rsconfigitems.o rsdiscitems.o # RsItems
|
||||
RSOBJ += rsmsgitems.o rsrankitems.o # RsItems
|
||||
RSOBJ += rsphotoitems.o # RsItems
|
||||
RSOBJ += rsgameitems.o # RsItems
|
||||
RSOBJ += rsdistribitems.o # RsItems
|
||||
RSOBJ += rsforumitems.o # RsItems
|
||||
RSOBJ += rschannelitems.o # RsItems
|
||||
RSOBJ += rsqblogitems.o # RsItems
|
||||
RSOBJ += rsstatusitems.o # RsItems
|
||||
|
||||
TESTOBJ = tlvbase_test.o tlvbase_test2.o tlvfileitem_test.o
|
||||
TESTOBJ += tlvitems_test.o tlvstack_test.o tlvconfig_test.o
|
||||
TESTOBJ += rsserial_test.o rstlvwidetest.o tlvrandom_test.o
|
||||
|
||||
#rsbaseitem_test.o
|
||||
|
||||
TESTS = tlvbase_test tlvbase_test2 tlvfileitem_test
|
||||
TESTS += tlvitems_test tlvstack_test tlvconfig_test
|
||||
TESTS += rstlvwidetest tlvrandom_test
|
||||
#rsserial_test
|
||||
|
||||
#rsbaseitem_test
|
||||
|
||||
all: librs 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)
|
||||
|
||||
tlvfileitem_test : tlvfileitem_test.o
|
||||
$(CC) $(CFLAGS) -o tlvfileitem_test tlvfileitem_test.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)
|
||||
|
||||
tlvconfig_test : tlvconfig_test.o
|
||||
$(CC) $(CFLAGS) -o tlvconfig_test tlvconfig_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)
|
||||
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/scripts/rules.mk
|
||||
###############################################################
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbaseitem_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
* tlvfileitem test.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
static int test_RsFileItem();
|
||||
static int test_RsFileData();
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsFile[Item/Data/...] Tests" << std::endl;
|
||||
|
||||
test_RsFileItem();
|
||||
test_RsFileData();
|
||||
|
||||
FINALREPORT("RsTlvFile[Item/Data/...] Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
int test_RsTlvFileItem()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
RsTlvFileItem i1;
|
||||
RsTlvFileItem i2;
|
||||
|
||||
/* initialise */
|
||||
i1.filesize = 101010;
|
||||
i1.hash = "ABCDEFEGHE";
|
||||
i1.name = "TestFile.txt";
|
||||
i1.pop = 12;
|
||||
i1.age = 456;
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
CHECK(i1.filesize == i2.filesize);
|
||||
CHECK(i1.hash == i2.hash);
|
||||
CHECK(i1.name == i2.name);
|
||||
CHECK(i1.path == i2.path);
|
||||
CHECK(i1.pop == i2.pop);
|
||||
CHECK(i1.age == i2.age);
|
||||
|
||||
/* do it again without optional data */
|
||||
i1.filesize = 123;
|
||||
i1.name = "";
|
||||
i1.pop = 0;
|
||||
i1.age = 0;
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
CHECK(i1.filesize == i2.filesize);
|
||||
CHECK(i1.hash == i2.hash);
|
||||
CHECK(i1.name == i2.name);
|
||||
CHECK(i1.path == i2.path);
|
||||
CHECK(i1.pop == i2.pop);
|
||||
CHECK(i1.age == i2.age);
|
||||
|
||||
/* one more time - long file name, some optional data */
|
||||
i1.filesize = 123;
|
||||
i1.name = "A Very Long File name that should fit in easily ??? with som $&%&^%* strange char (**$^%#&^$#*^%(&^ in there too!!!! ~~~!!$#(^$)$)(&%^)&\" oiyu thend";
|
||||
i1.pop = 666;
|
||||
i1.age = 0;
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
CHECK(i1.filesize == i2.filesize);
|
||||
CHECK(i1.hash == i2.hash);
|
||||
CHECK(i1.name == i2.name);
|
||||
CHECK(i1.path == i2.path);
|
||||
CHECK(i1.pop == i2.pop);
|
||||
CHECK(i1.age == i2.age);
|
||||
|
||||
REPORT("Serialise/Deserialise RsTlvFileItem");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_RsTlvFileSet()
|
||||
{
|
||||
RsTlvFileSet s1;
|
||||
RsTlvFileSet s2;
|
||||
|
||||
int i = 0;
|
||||
for(i = 0; i < 15; i++)
|
||||
{
|
||||
RsTlvFileItem fi;
|
||||
fi.filesize = 16 + i * i;
|
||||
fi.hash = "ABCDEF";
|
||||
std::ostringstream out;
|
||||
out << "File" << i << "_inSet.txt";
|
||||
fi.name = out.str();
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
fi.age = 10 * i;
|
||||
}
|
||||
else
|
||||
{
|
||||
fi.age = 0;
|
||||
}
|
||||
fi.pop = 0;
|
||||
|
||||
s1.items.push_back(fi);
|
||||
}
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &s1, &s2));
|
||||
|
||||
/* check the data is the same - TODO */
|
||||
|
||||
REPORT("Serialise/Deserialise RsTlvFileSet");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int test_RsTlvFileData()
|
||||
{
|
||||
RsTlvFileData d1;
|
||||
RsTlvFileData d2;
|
||||
|
||||
/* initialise */
|
||||
d1.file.filesize = 101010;
|
||||
d1.file.hash = "ABCDEFEGHE";
|
||||
d1.file.name = "";
|
||||
d1.file.age = 0;
|
||||
d1.file.pop = 0;
|
||||
|
||||
char data[15];
|
||||
d1.binData.setBinData(data, 15);
|
||||
|
||||
d1.file_offset = 222;
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &d1, &d2));
|
||||
|
||||
/* check the data is the same */
|
||||
CHECK(d1.file.filesize == d2.file.filesize);
|
||||
CHECK(d1.file.hash == d2.file.hash);
|
||||
CHECK(d1.file.name == d2.file.name);
|
||||
CHECK(d1.file.path == d2.file.path);
|
||||
CHECK(d1.file.pop == d2.file.pop);
|
||||
CHECK(d1.file.age == d2.file.age);
|
||||
|
||||
CHECK(d1.file_offset == d2.file_offset);
|
||||
CHECK(d1.binData.bin_len == d2.binData.bin_len);
|
||||
|
||||
REPORT("Serialise/Deserialise RsTlvFileData");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -1,136 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsserial_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
* tlvfileitem test.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rsbaseitems.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
static int test_RsFileItem();
|
||||
static int test_RsFileData();
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsFile[Item/Data/...] Tests" << std::endl;
|
||||
|
||||
|
||||
test_RsFileItem();
|
||||
//test_RsFileData();
|
||||
|
||||
FINALREPORT("RsTlvFile[Item/Data/...] Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
int test_RsFileItem()
|
||||
{
|
||||
/* make a serialisable FileItem */
|
||||
|
||||
RsSerialiser srl;
|
||||
RsFileRequest rsfi;
|
||||
|
||||
/* initialise */
|
||||
rsfi.file.filesize = 101010;
|
||||
rsfi.file.hash = "ABCDEFEGHE";
|
||||
rsfi.file.name = "TestFile.txt";
|
||||
rsfi.file.pop = 12;
|
||||
rsfi.file.age = 456;
|
||||
|
||||
/* attempt to serialise it before we add it to the serialiser */
|
||||
|
||||
CHECK(0 == srl.size(&rsfi));
|
||||
|
||||
#define MAX_BUFSIZE 16000
|
||||
|
||||
char buffer[MAX_BUFSIZE];
|
||||
uint32_t sersize = MAX_BUFSIZE;
|
||||
|
||||
CHECK(false == srl.serialise(&rsfi, (void *) buffer, &sersize));
|
||||
|
||||
|
||||
/* now add to serialiser */
|
||||
|
||||
RsFileItemSerialiser *rsfis = new RsFileItemSerialiser();
|
||||
srl.addSerialType(rsfis);
|
||||
|
||||
uint32_t size = srl.size(&rsfi);
|
||||
bool done = srl.serialise(&rsfi, (void *) buffer, &sersize);
|
||||
|
||||
std::cerr << "test_RsFileItem() size: " << size << std::endl;
|
||||
std::cerr << "test_RsFileItem() done: " << done << std::endl;
|
||||
std::cerr << "test_RsFileItem() sersize: " << sersize << std::endl;
|
||||
|
||||
std::cerr << "test_RsFileItem() 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);
|
||||
|
||||
RsFileRequest *outfi = dynamic_cast<RsFileRequest *>(output);
|
||||
|
||||
CHECK(outfi != NULL);
|
||||
|
||||
if (outfi)
|
||||
{
|
||||
/* check the data is the same */
|
||||
CHECK(rsfi.file.filesize == outfi->file.filesize);
|
||||
CHECK(rsfi.file.hash == outfi->file.hash);
|
||||
CHECK(rsfi.file.name == outfi->file.name);
|
||||
CHECK(rsfi.file.path == outfi->file.path);
|
||||
CHECK(rsfi.file.pop == outfi->file.pop);
|
||||
CHECK(rsfi.file.age == outfi->file.age);
|
||||
}
|
||||
|
||||
sersize2 = MAX_BUFSIZE;
|
||||
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||
|
||||
CHECK(sersize2 == sersize);
|
||||
|
||||
displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||
|
||||
|
||||
REPORT("Serialise/Deserialise RsFileRequest");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rstlvkvwidetest.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Chris 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 <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "serialiser/rstlvkvwide.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
|
||||
INITTEST();
|
||||
|
||||
/* define utility functions to test out with */
|
||||
|
||||
//static int testRstlvWide();
|
||||
static int testRsTlvWideSet();
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsTlvWideTest[Item/Data/...] Tests" << std::endl;
|
||||
|
||||
testRsTlvWideSet();
|
||||
|
||||
FINALREPORT("RsTlvWideTest[Item/Data/...] Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
int testRsTlvWideSet()
|
||||
{
|
||||
RsTlvKeyValueWideSet i1, i2; // one to set and other to get
|
||||
RsTlvKeyValueWide i_pair; // input pair
|
||||
RsTlvFileItem hello;
|
||||
|
||||
std::string randString("it should work now.");
|
||||
int j, k;
|
||||
|
||||
std::cerr << "entering loop now" << std::endl;
|
||||
/* store a 15 random pairs */
|
||||
|
||||
for(int i = 0; i < 15 ; i++)
|
||||
{
|
||||
j = rand() % 4;
|
||||
k = rand() % 4;
|
||||
std::cerr << "j: " << j << " k: " << k << std::endl;
|
||||
i_pair.wKey.assign(randString.begin(), randString.end());
|
||||
std::cerr << "loop count:" << i << std::endl;
|
||||
i_pair.wValue.assign(randString.begin(), randString.end());
|
||||
std::cerr << "loop count:" << i << std::endl;
|
||||
i1.wPairs.push_back(i_pair);
|
||||
|
||||
i_pair.TlvClear();
|
||||
}
|
||||
|
||||
std::cerr << "out of loop now" << std::endl;
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/*check that the data is the same*/
|
||||
|
||||
REPORT("Serialize/Deserialize RsTlvKeyValueWideSet");
|
||||
|
||||
return 1;
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: tlvbase_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Horatio.
|
||||
*
|
||||
* 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 <string.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "util/utest.h"
|
||||
#include "util/rsnet.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
static int test_RsTlvBase();
|
||||
int main()
|
||||
{
|
||||
std::cerr << " RsTlvBase Tests" <<std::endl;
|
||||
|
||||
test_RsTlvBase();
|
||||
FINALREPORT("RsTlvBase Tests");
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int test_RsTlvBase()
|
||||
{
|
||||
//uint32_t array[] = {0x122, 0x234};
|
||||
char data[20];
|
||||
memset((void*)data, 65, sizeof(data)); // In ASCII 'A' =65
|
||||
|
||||
|
||||
std::string out;
|
||||
|
||||
data[0]=0;
|
||||
data[1]=0;
|
||||
data[2]=0;
|
||||
data[3]=8;
|
||||
uint32_t off =0;
|
||||
GetTlvString((void*)data, 20, &off, 0, out);
|
||||
|
||||
CHECK(out == "AAAA");
|
||||
|
||||
std::cout << "Output is : " << out << std::endl;
|
||||
|
||||
uint16_t data2[] = {0, 0x0300};
|
||||
|
||||
uint16_t t = GetTlvSize((void*) data2);
|
||||
|
||||
|
||||
CHECK( t == ntohs(0x0300));
|
||||
|
||||
//std::cout << "GetTlvSize = " <<t <<std::endl;
|
||||
|
||||
|
||||
std::string line;
|
||||
|
||||
|
||||
//*************Test SetTlvBase***********
|
||||
{
|
||||
uint16_t data3 [2];
|
||||
off =0;
|
||||
uint32_t *offset = &off;
|
||||
uint32_t const SIZE_SetTlvBase=4;
|
||||
uint32_t val_before = *offset;
|
||||
SetTlvBase((void *)data3, SIZE_SetTlvBase, offset, 0x0011, 0x0001);
|
||||
|
||||
CHECK(*offset - val_before == SIZE_SetTlvBase);
|
||||
CHECK(0x0011 == ntohs(data3[0]));
|
||||
CHECK(0x0001 == ntohs(data3[1]));
|
||||
|
||||
|
||||
}
|
||||
|
||||
REPORT("Test SetTlvBase");
|
||||
|
||||
|
||||
/**
|
||||
* test GetTlvUInt32 & SetTlvGetUInt32
|
||||
*/
|
||||
{
|
||||
uint16_t data4[4];
|
||||
bool ok = true;
|
||||
uint32_t off =0;
|
||||
uint32_t pre_set_off = off;
|
||||
uint32_t* offset = &off;
|
||||
uint32_t out = 3324;
|
||||
*offset =0;
|
||||
ok = SetTlvUInt32((void*)data4, 8, offset, 0x0011, out);
|
||||
CHECK(*offset - pre_set_off == 8);
|
||||
|
||||
uint32_t readPos = 0;
|
||||
offset = &readPos;
|
||||
uint32_t in =0;
|
||||
ok &= GetTlvUInt32((void*)data4, 8, offset, 0x0011, &in);
|
||||
CHECK(*offset - pre_set_off == 8);
|
||||
CHECK(in == out);
|
||||
|
||||
std::cerr<<"in = " <<in <<std::endl;
|
||||
std::cout << "*offset = " <<*offset <<std::endl;
|
||||
std::cout <<std::hex << data4[2]<< " " <<data4[3] <<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
{
|
||||
uint16_t data4[4];
|
||||
data4[0] = 0x0500; /* type (little-endian?) */
|
||||
data4[1] = 0x0800; /* size (little-endian?) */
|
||||
data4[3]=0x0000;
|
||||
data4[2] = 0xFFFF;
|
||||
uint32_t got;
|
||||
uint32_t off =0;
|
||||
uint32_t*offset = &off;
|
||||
GetTlvUInt32((void*)data4, 8, offset, 5, &got);
|
||||
CHECK(got ==0xFFFF0000);
|
||||
std::cout << " got = " << std::hex << got <<std::endl;
|
||||
|
||||
}
|
||||
|
||||
REPORT("Test TlvUInt32");
|
||||
|
||||
|
||||
/**
|
||||
* Test GetTlvString()
|
||||
*/
|
||||
{
|
||||
std::string teststring = "Hello RS!";
|
||||
uint16_t data5[4 + 20];
|
||||
uint32_t pos =0;
|
||||
uint32_t* offset = &pos;
|
||||
uint32_t pre_pos = pos;
|
||||
SetTlvString((void*)data5, sizeof(data5), offset, TLV_TYPE_STR_NAME, teststring);
|
||||
uint16_t tlvsize = GetTlvStringSize(teststring);
|
||||
CHECK(tlvsize == *offset);
|
||||
CHECK(data5[0] == htons(TLV_TYPE_STR_NAME));
|
||||
CHECK(data5[1] == htons(tlvsize));
|
||||
|
||||
std::string str((char*) ((char*)data5 +4) ,strlen("Hello RS!"));
|
||||
CHECK(str == "Hello RS!");
|
||||
|
||||
// std::cout <<str <<std::endl;
|
||||
|
||||
|
||||
std::string out_str;
|
||||
|
||||
pos =0;
|
||||
GetTlvString((void*)data5, sizeof(data5), offset, TLV_TYPE_STR_NAME, out_str);
|
||||
CHECK(out_str == "Hello RS!");
|
||||
CHECK(*offset == sizeof(uint16_t)*2 + out_str.size());
|
||||
uint16_t data6[2];
|
||||
*offset =0;
|
||||
SetTlvSize((void*)data6, sizeof(data6), 0x00000022);
|
||||
std::cout << std::hex << data6[1] <<std::endl;
|
||||
|
||||
}
|
||||
REPORT("Test TlvString");
|
||||
return 0;
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: tlvbase_test2.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/******************************************************************
|
||||
* tlvfileitem test.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
#include "util/rsnet.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
static int test_RsTlvString();
|
||||
static int test_RsTlvUInt32();
|
||||
static int test_RsTlvIPAddr();
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsTlvBase Tests" << std::endl;
|
||||
|
||||
test_RsTlvString();
|
||||
test_RsTlvUInt32();
|
||||
test_RsTlvIPAddr();
|
||||
|
||||
FINALREPORT("RsTlvBase Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
int test_RsTlvUInt32()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_OneString(std::string input, uint16_t type);
|
||||
|
||||
int test_RsTlvString()
|
||||
{
|
||||
std::string nullString;
|
||||
std::string oneString = "1";
|
||||
std::string shortString = "ab cd";
|
||||
std::string longString = "abcd efgh ijkl mnop qrst uvw";
|
||||
|
||||
std::cerr << "test_RsTlvString() Testing" << std::endl;
|
||||
test_OneString(nullString, 1234);
|
||||
test_OneString(oneString, 12);
|
||||
test_OneString(shortString, 79);
|
||||
test_OneString(longString, 7654);
|
||||
|
||||
REPORT("Serialise RsTlvFileItem");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int test_OneString(std::string input, uint16_t type)
|
||||
{
|
||||
/* an array to work from */
|
||||
char tlvdata[2048];
|
||||
std::string OutString;
|
||||
|
||||
std::cerr << "test_OneString() Testing ... Print/Serialise/Deserialise";
|
||||
std::cerr << std::endl;
|
||||
/* start with SetTlvString() */
|
||||
|
||||
uint16_t initsize = GetTlvStringSize(input);
|
||||
uint32_t outOffset = 0;
|
||||
uint32_t inOffset = 0;
|
||||
|
||||
std::cerr << "Serialising: " << input << std::endl;
|
||||
CHECK(SetTlvString((void*)tlvdata, 2048, &outOffset, type, input));
|
||||
std::cerr << "Init Size: " << initsize << std::endl;
|
||||
std::cerr << "Serialised Size: " << outOffset << std::endl;
|
||||
displayRawPacket(std::cerr, tlvdata, outOffset);
|
||||
|
||||
CHECK(outOffset == initsize); /* check that the offset matches the size */
|
||||
|
||||
std::cerr << "DeSerialising" << std::endl;
|
||||
|
||||
/* fails if type is wrong! */
|
||||
CHECK(0 == GetTlvString((void*)tlvdata, outOffset, &inOffset, type-1, OutString));
|
||||
CHECK(GetTlvString((void*)tlvdata, outOffset, &inOffset, type, OutString));
|
||||
|
||||
CHECK(initsize == inOffset); /* check that the offset matches the size */
|
||||
CHECK(input == OutString); /* check that strings match */
|
||||
std::cerr << "Deserialised: Size: " << inOffset << std::endl;
|
||||
std::cerr << "Deserialised: String: " << OutString << std::endl;
|
||||
|
||||
REPORT("Serialise OneString");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_IpAddr(struct sockaddr_in *addr, uint16_t type);
|
||||
|
||||
static int test_RsTlvIPAddr()
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
|
||||
inet_aton("10.0.0.111", &(addr.sin_addr));
|
||||
addr.sin_port = htons(1111);
|
||||
|
||||
test_IpAddr(&addr, 1234);
|
||||
|
||||
inet_aton("255.255.255.1", &(addr.sin_addr));
|
||||
addr.sin_port = htons(9999);
|
||||
|
||||
test_IpAddr(&addr, 1234);
|
||||
|
||||
inet_aton("128.255.255.1", &(addr.sin_addr));
|
||||
addr.sin_port = htons(0);
|
||||
|
||||
test_IpAddr(&addr, 1234);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_IpAddr(struct sockaddr_in *addr, uint16_t type)
|
||||
{
|
||||
/* an array to work from */
|
||||
char tlvdata[2048];
|
||||
struct sockaddr_in outaddr;
|
||||
|
||||
std::cerr << "test_IpAddr() Testing ... Print/Serialise/Deserialise";
|
||||
std::cerr << std::endl;
|
||||
/* start with SetTlvString() */
|
||||
|
||||
uint16_t initsize = GetTlvIpAddrPortV4Size();
|
||||
uint32_t outOffset = 0;
|
||||
uint32_t inOffset = 0;
|
||||
|
||||
std::cerr << "Serialising IPAddr: " << inet_ntoa(addr->sin_addr) << std::endl;
|
||||
std::cerr << " Port : " << ntohs(addr->sin_port) << std::endl;
|
||||
|
||||
CHECK(SetTlvIpAddrPortV4((void*)tlvdata, 2048, &outOffset, type, addr));
|
||||
std::cerr << "Init Size: " << initsize << std::endl;
|
||||
std::cerr << "Serialised Size: " << outOffset << std::endl;
|
||||
displayRawPacket(std::cerr, tlvdata, outOffset);
|
||||
|
||||
CHECK(outOffset == initsize); /* check that the offset matches the size */
|
||||
|
||||
std::cerr << "DeSerialising" << std::endl;
|
||||
|
||||
/* fails if type is wrong! */
|
||||
CHECK(0 == GetTlvIpAddrPortV4((void*)tlvdata, outOffset, &inOffset, type-1, &outaddr));
|
||||
CHECK(GetTlvIpAddrPortV4((void*)tlvdata, outOffset, &inOffset, type, &outaddr));
|
||||
|
||||
CHECK(initsize == inOffset); /* check that the offset matches the size */
|
||||
CHECK(addr->sin_addr.s_addr == outaddr.sin_addr.s_addr); /* check that IP match */
|
||||
CHECK(addr->sin_port == outaddr.sin_port); /* check that Port match */
|
||||
std::cerr << "Deserialised: Size: " << inOffset << std::endl;
|
||||
std::cerr << "Deserialised IPAddr: " << inet_ntoa(outaddr.sin_addr) << std::endl;
|
||||
std::cerr << " Port : " << ntohs(outaddr.sin_port) << std::endl;
|
||||
|
||||
REPORT("Serialise OneIP/Port");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: tlvconfig_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Chris 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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/******************************************************************
|
||||
* tlvfileitem test.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkvwide.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
static int testRsTlvPeerIdSet();
|
||||
static int testRsTlvServiceIdSet();
|
||||
static int testRsTlvKeyValue();
|
||||
static int testRsTlvKeyValueSet();
|
||||
static int testRsTlvWideSet();
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsTlvConfig[Item/Data/...] Tests" << std::endl;
|
||||
|
||||
testRsTlvPeerIdSet();
|
||||
testRsTlvServiceIdSet();//tbd
|
||||
testRsTlvKeyValue();//tbd
|
||||
testRsTlvKeyValueSet();//tbd
|
||||
testRsTlvWideSet();
|
||||
|
||||
|
||||
FINALREPORT("RsTlvConfig[Item/Data/...] Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
int testRsTlvPeerIdSet()
|
||||
{
|
||||
|
||||
RsTlvPeerIdSet i1, i2; // one to set and other to get
|
||||
|
||||
std::string testString;
|
||||
|
||||
std::string randString[5];
|
||||
randString[0] = "e$424!<21>!<21>";
|
||||
randString[1] = "e~:@L{L{KHKG";
|
||||
randString[2] = "e{@O**/*/*";
|
||||
randString[3] = "e?<<BNMB>HG<48>!<21>%$";
|
||||
randString[4] = "e><?<NVBCEE<45>$$%*^";
|
||||
|
||||
/* store a number of random ids */
|
||||
|
||||
for(int i = 0; i < 15 ; i++)
|
||||
{
|
||||
testString = randString[(rand() % 4)] + randString[(rand() % 4)];
|
||||
|
||||
i1.ids.push_back(testString);
|
||||
}
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/*check that the data is the same*/
|
||||
|
||||
REPORT("Serialize/Deserialize RsTlvPeerIdSet");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int testRsTlvServiceIdSet()
|
||||
{
|
||||
RsTlvServiceIdSet i1, i2; // one to set and other to get
|
||||
|
||||
|
||||
/* store random numbers */
|
||||
for(int i = 0; i < 15 ; i++)
|
||||
{
|
||||
i1.ids.push_back(1 + rand() % 12564);
|
||||
}
|
||||
std::cout << "error here!!!?";
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/*check that the data is the same*/
|
||||
REPORT("Serialize/Deserialize RsTlvServiceIdSet");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int testRsTlvKeyValue()
|
||||
{
|
||||
RsTlvKeyValue i1, i2; // one to set and other to get
|
||||
|
||||
i1.key = "whatever";
|
||||
i1.value = "better work";
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/*check that the data is the same*/
|
||||
REPORT("Serialize/Deserialize RsTlvKeyValue");
|
||||
|
||||
return 1;
|
||||
}
|
||||
int testRsTlvKeyValueSet()
|
||||
{
|
||||
RsTlvKeyValueSet i1, i2; // one to set and other to get
|
||||
|
||||
/* instantiate the objects values */
|
||||
|
||||
std::string randString[5];
|
||||
randString[0] = "e$424!<21>!<21>";
|
||||
randString[1] = "e~:@L{L{KHKG";
|
||||
randString[2] = "e{@O**/*/*";
|
||||
randString[3] = "e?<<BNMB>HG<48>!<21>%$";
|
||||
randString[4] = "e><?<NVBCEE<45>$$%*^";
|
||||
|
||||
for(int i = 0; i < 15; i++)
|
||||
{
|
||||
RsTlvKeyValue kv;
|
||||
|
||||
kv.key = randString[(rand() % 4)] + randString[(rand() % 4)];
|
||||
kv.value = randString[(rand() % 4)] + randString[(rand() % 4)];
|
||||
|
||||
i1.pairs.push_back(kv);
|
||||
|
||||
}
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/*check that the data is the same*/
|
||||
REPORT("Serialize/Deserialize RsTlvKeyValueSet");
|
||||
}
|
||||
|
||||
int testRsTlvWideSet()
|
||||
{
|
||||
RsTlvKeyValueWideSet i1, i2; // one to set and other to get
|
||||
RsTlvKeyValueWide i_pair; // input pair
|
||||
RsTlvFileItem hello;
|
||||
|
||||
std::string randString[5];
|
||||
randString[0] = "e$424!<21>!<21>";
|
||||
randString[1] = "e~:@L{L{KHKG";
|
||||
randString[2] = "e{@O**/*/*";
|
||||
randString[3] = "e?<<BNMB>HG<48>!<21>%$";
|
||||
randString[4] = "e><?<NVBCEE<45>$$%*^";
|
||||
|
||||
/* store a 15 random pairs */
|
||||
|
||||
for(int i = 0; i < 15 ; i++)
|
||||
{
|
||||
i_pair.wKey.assign(randString[(rand() % 4)].begin(), randString[(rand() % 4)].end());
|
||||
i_pair.wValue.assign(randString[(rand() % 4)].begin(), randString[(rand() % 4)].end());
|
||||
i1.wPairs.push_back(i_pair);
|
||||
}
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/*check that the data is the same*/
|
||||
|
||||
REPORT("Serialize/Deserialize RsTlvKeyValueWideSet");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,190 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: tlvfileitem_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
* tlvfileitem test.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
static int test_RsTlvFileItem();
|
||||
static int test_RsTlvFileSet();
|
||||
static int test_RsTlvFileData();
|
||||
static int test_RsTlvFileStack();
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsTlvFile[Item/Data/...] Tests" << std::endl;
|
||||
|
||||
test_RsTlvFileItem();
|
||||
test_RsTlvFileData();
|
||||
test_RsTlvFileSet();
|
||||
|
||||
FINALREPORT("RsTlvFile[Item/Data/...] Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
int test_RsTlvFileItem()
|
||||
{
|
||||
RsTlvFileItem i1;
|
||||
RsTlvFileItem i2;
|
||||
|
||||
/* initialise */
|
||||
i1.filesize = 101010;
|
||||
i1.hash = "ABCDEFEGHE";
|
||||
i1.name = "TestFile.txt";
|
||||
i1.pop = 12;
|
||||
i1.age = 456;
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
CHECK(i1.filesize == i2.filesize);
|
||||
CHECK(i1.hash == i2.hash);
|
||||
CHECK(i1.name == i2.name);
|
||||
CHECK(i1.path == i2.path);
|
||||
CHECK(i1.pop == i2.pop);
|
||||
CHECK(i1.age == i2.age);
|
||||
|
||||
/* do it again without optional data */
|
||||
i1.filesize = 123;
|
||||
i1.name = "";
|
||||
i1.pop = 0;
|
||||
i1.age = 0;
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
CHECK(i1.filesize == i2.filesize);
|
||||
CHECK(i1.hash == i2.hash);
|
||||
CHECK(i1.name == i2.name);
|
||||
CHECK(i1.path == i2.path);
|
||||
CHECK(i1.pop == i2.pop);
|
||||
CHECK(i1.age == i2.age);
|
||||
|
||||
/* one more time - long file name, some optional data */
|
||||
i1.filesize = 123;
|
||||
i1.name = "A Very Long File name that should fit in easily ??? with som $&%&^%* strange char (**$^%#&^$#*^%(&^ in there too!!!! ~~~!!$#(^$)$)(&%^)&\" oiyu thend";
|
||||
i1.pop = 666;
|
||||
i1.age = 0;
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
CHECK(i1.filesize == i2.filesize);
|
||||
CHECK(i1.hash == i2.hash);
|
||||
CHECK(i1.name == i2.name);
|
||||
CHECK(i1.path == i2.path);
|
||||
CHECK(i1.pop == i2.pop);
|
||||
CHECK(i1.age == i2.age);
|
||||
|
||||
REPORT("Serialise/Deserialise RsTlvFileItem");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_RsTlvFileSet()
|
||||
{
|
||||
RsTlvFileSet s1;
|
||||
RsTlvFileSet s2;
|
||||
|
||||
int i = 0;
|
||||
for(i = 0; i < 15; i++)
|
||||
{
|
||||
RsTlvFileItem fi;
|
||||
fi.filesize = 16 + i * i;
|
||||
fi.hash = "ABCDEF";
|
||||
std::ostringstream out;
|
||||
out << "File" << i << "_inSet.txt";
|
||||
fi.name = out.str();
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
fi.age = 10 * i;
|
||||
}
|
||||
else
|
||||
{
|
||||
fi.age = 0;
|
||||
}
|
||||
fi.pop = 0;
|
||||
|
||||
s1.items.push_back(fi);
|
||||
}
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &s1, &s2));
|
||||
|
||||
/* check the data is the same - TODO */
|
||||
|
||||
REPORT("Serialise/Deserialise RsTlvFileSet");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int test_RsTlvFileData()
|
||||
{
|
||||
RsTlvFileData d1;
|
||||
RsTlvFileData d2;
|
||||
|
||||
/* initialise */
|
||||
d1.file.filesize = 101010;
|
||||
d1.file.hash = "ABCDEFEGHE";
|
||||
d1.file.name = "";
|
||||
d1.file.age = 0;
|
||||
d1.file.pop = 0;
|
||||
|
||||
char data[15];
|
||||
d1.binData.setBinData(data, 15);
|
||||
|
||||
d1.file_offset = 222;
|
||||
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &d1, &d2));
|
||||
|
||||
/* check the data is the same */
|
||||
CHECK(d1.file.filesize == d2.file.filesize);
|
||||
CHECK(d1.file.hash == d2.file.hash);
|
||||
CHECK(d1.file.name == d2.file.name);
|
||||
CHECK(d1.file.path == d2.file.path);
|
||||
CHECK(d1.file.pop == d2.file.pop);
|
||||
CHECK(d1.file.age == d2.file.age);
|
||||
|
||||
CHECK(d1.file_offset == d2.file_offset);
|
||||
CHECK(d1.binData.bin_len == d2.binData.bin_len);
|
||||
|
||||
REPORT("Serialise/Deserialise RsTlvFileData");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: tlvitems_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
* tlvfileitem test.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
static int test_RsTlvBinData();
|
||||
static int test_RsTlvStepping();
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsTlvItems Tests" << std::endl;
|
||||
|
||||
test_RsTlvBinData();
|
||||
|
||||
FINALREPORT("RsTlvItems Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
#define BIN_LEN 523456 /* bigger than 64k */
|
||||
|
||||
int test_RsTlvBinData()
|
||||
{
|
||||
RsTlvBinaryData d1(1023);
|
||||
RsTlvBinaryData d2(1023);
|
||||
|
||||
char data[BIN_LEN] = {0};
|
||||
int i, j;
|
||||
for(i = 0; i < BIN_LEN; i++)
|
||||
{
|
||||
data[i] = i%13;
|
||||
}
|
||||
|
||||
for(j = 1; j < BIN_LEN; j *= 2)
|
||||
{
|
||||
d1.setBinData(data, j);
|
||||
CHECK(test_SerialiseTlvItem(std::cerr, &d1, &d2));
|
||||
|
||||
CHECK(d1.bin_len == d2.bin_len);
|
||||
CHECK(0 == memcmp(d1.bin_data, d2.bin_data, d1.bin_len));
|
||||
}
|
||||
|
||||
REPORT("Serialise/Deserialise RsTlvBinData");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_RsTlvStepping()
|
||||
{
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,194 +0,0 @@
|
|||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: tlvstack_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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".
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************
|
||||
* tlvfileitem test.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "util/utest.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
static int test_RsTlvStack();
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsTlvItem Stack Tests" << std::endl;
|
||||
|
||||
test_RsTlvStack();
|
||||
|
||||
FINALREPORT("RsTlvItem Stack Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
||||
|
||||
|
||||
#define BIN_LEN 53
|
||||
|
||||
int test_RsTlvStack()
|
||||
{
|
||||
|
||||
/* now create a set of TLV items for the random generator */
|
||||
|
||||
RsTlvBinaryData *bd1 = new RsTlvBinaryData(123);
|
||||
RsTlvBinaryData *bd2 = new RsTlvBinaryData(125);
|
||||
|
||||
char data[BIN_LEN] = {0};
|
||||
int i;
|
||||
for(i = 0; i < BIN_LEN; i++)
|
||||
{
|
||||
data[i] = i%13;
|
||||
}
|
||||
|
||||
bd1->setBinData(data, 5);
|
||||
bd2->setBinData(data, 21);
|
||||
|
||||
RsTlvFileItem *fi1 = new RsTlvFileItem();
|
||||
RsTlvFileItem *fi2 = new RsTlvFileItem();
|
||||
|
||||
/* initialise */
|
||||
fi1->filesize = 101010;
|
||||
fi1->hash = "ABCDEFEGHE";
|
||||
fi1->name = "TestFile.txt";
|
||||
fi1->pop = 12;
|
||||
fi1->age = 456;
|
||||
|
||||
fi2->filesize = 101010;
|
||||
fi2->hash = "ABCDEFEGHE";
|
||||
fi2->name = "TestFile.txt";
|
||||
fi2->pop = 0;
|
||||
fi2->age = 0;;
|
||||
|
||||
std::vector<RsTlvItem *> items;
|
||||
items.resize(4);
|
||||
items[0] = bd1;
|
||||
items[1] = bd2;
|
||||
items[2] = fi1;
|
||||
items[3] = fi2;
|
||||
|
||||
test_TlvSet(items, 1024);
|
||||
|
||||
REPORT("Serialise/Deserialise RsTlvBinData");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue