updates to old tests....

moved rstlvutil to here as well.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7231 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2014-04-05 04:45:37 +00:00
parent 11fa133377
commit 7fa611b2e7
10 changed files with 284 additions and 58 deletions

View File

@ -11,7 +11,7 @@ endif
# Need to define miniupnpc version because API changed a little between v1.0 and 1.2
# put 10 for 1.0 and 12 for 1.2
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_FILE_OFFSET_BITS=64 -DSQLITE_HAS_CODEC
include $(RS_TOP_DIR)/tests/scripts/checks.mk
@ -70,8 +70,8 @@ ifdef PQI_USE_XPGP
LIBS += -lssl -lcrypto -lpthread
#LIBS += -L$(UPNPC_DIR) -lminiupnpc
LIBS += $(XLIB) -ldl -lz
LIBS += -lupnp
LIBS += -lupnp
LIBS += ../../../../../lib/sqlcipher/.libs/libsqlcipher.a
RSLIBS = $(LIBS)

View File

@ -10,23 +10,33 @@ OPS_TOP_DIR = ../../../../openpgpsdk/src
include $(RS_TOP_DIR)/tests/scripts/config.mk
###############################################################
OBJ = rstlvutil.o
TESTOBJ = tlvbase_test.o tlvbase_test2.o rstunnelitem_test.o
TESTOBJ += tlvitems_test.o tlvstack_test.o rsserial_test.o
TESTOBJ += rstlvwidetest.o tlvrandom_test.o rsturtleitem_test.o
TESTOBJ += tlvtypes_test.o support.o distribitem_test.o rsmsgitem_test.o
TESTOBJ += rsstatusitem_test.o rsconfigitem_test.o
TESTOBJ += rsgrouteritem_test.o
TESTOBJ += rsgrouteritem_test.o $(OBJ)
TESTS = tlvbase_test tlvbase_test2 rstlvwidetest
TESTS += tlvitems_test tlvstack_test rstunnelitem_test
TESTS += tlvrandom_test rsserial_test rsturtleitem_test
TESTS += tlvtypes_test distribitem_test rsmsgitem_test
TESTS += rsstatusitem_test rsconfigitem_test
TESTOBJ += rsgrouteritem_test
TESTS = tlvbase_test tlvbase_test2
#rstlvwidetest
TESTS += tlvitems_test tlvstack_test
#rstunnelitem_test
TESTS += tlvrandom_test rsturtleitem_test
#rsserial_test
TESTS += tlvtypes_test
#rsmsgitem_test
#distribitem_test
TESTS += rsstatusitem_test
#rsconfigitem_test
#TESTS += rsgrouteritem_test
#rsbaseitem_test
all: tests
all: tests
tests: $(OBJ)
tlvbase_test : tlvbase_test.o
$(CC) $(CFLAGS) -o tlvbase_test tlvbase_test.o $(OBJ) $(LIBS)
@ -43,14 +53,14 @@ tlvstack_test : tlvstack_test.o
rsserial_test : rsserial_test.o
$(CC) $(CFLAGS) -o rsserial_test rsserial_test.o $(OBJ) $(LIBS)
rsserial_test : rsgrouteritem_test.o
rsgrouteritem_test : rsgrouteritem_test.o
$(CC) $(CFLAGS) -o rsgrouteritem_test rsgrouteritem_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)
#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)

View File

@ -0,0 +1,187 @@
/*
* libretroshare/src/serialiser: rstlvutil.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".
*
*/
/* some utility functions mainly for debugging
*
*
*
*/
#include "serialiser/rstlvutil.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvitem.h"
#include "util/rsstring.h"
#include "util/utest.h"
#include <iostream>
#include <stdlib.h>
#if 0
/* print out a packet */
#include <iomanip>
#include <vector>
#endif
void displayRawPacket(std::ostream &out, void *data, uint32_t size)
{
uint32_t i;
std::string sout;
rs_sprintf(sout, "DisplayRawPacket: Size: %ld", size);
for(i = 0; i < size; i++)
{
if (i % 16 == 0)
{
sout += "\n";
}
rs_sprintf_append(sout, "%02x:", (int) (((unsigned char *) data)[i]));
}
out << sout << std::endl;
}
#define WHOLE_64K_SIZE 65536
int test_SerialiseTlvItem(std::ostream &str, RsTlvItem *in, RsTlvItem *out)
{
uint16_t initsize = in->TlvSize();
uint32_t serialOffset = 0;
uint32_t deserialOffset = 0;
str << "test_SerialiseTlvItem() Testing ... Print/Serialise/Deserialise";
str << std::endl;
/* some space to serialise into */
unsigned char serbuffer[WHOLE_64K_SIZE];
CHECK(in->SetTlv(serbuffer, WHOLE_64K_SIZE, &serialOffset));
CHECK(serialOffset == initsize); /* check that the offset matches the size */
CHECK(in->TlvSize() == initsize); /* check size hasn't changed */
REPORT("Serialise RsTlvItem");
/* now we try to read it back in! */
CHECK(out->GetTlv(serbuffer, serialOffset, &deserialOffset));
/* again check sizes */
CHECK(serialOffset == deserialOffset);
CHECK(deserialOffset == initsize);
CHECK(out->TlvSize() == initsize);
str << "Class In/Serialised/Out!" << std::endl;
in->print(str, 0);
displayRawPacket(str, serbuffer, serialOffset);
out->print(str, 0);
/* Can't check the actual data -> should add function */
REPORT("DeSerialise RsTlvFileItem");
/* print it out */
return 1;
}
/* This function checks the TLV header, and steps on to the next one
*/
bool test_StepThroughTlvStack(std::ostream &str, void *data, int size)
{
uint32_t offset = 0;
uint32_t index = 0;
while (offset + 4 <= size)
{
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[offset]) );
uint16_t tlvsize = GetTlvSize( &(((uint8_t *) data)[offset]) );
str << "Tlv Entry[" << index << "] => Offset: " << offset;
str << " Type: " << tlvtype;
str << " Size: " << tlvsize;
str << std::endl;
offset += tlvsize;
}
CHECK(offset == size); /* we match up exactly */
REPORT("Step Through RsTlvStack");
return 1;
}
int test_CreateTlvStack(std::ostream &str,
std::vector<RsTlvItem *> items, void *data, uint32_t *totalsize)
{
/* (1) select a random item
* (2) check size -> if okay serialise onto the end
* (3) loop!.
*/
uint32_t offset = 0;
uint32_t count = 0;
while(1)
{
int idx = (int) (items.size() * (rand() / (RAND_MAX + 1.0)));
uint32_t tlvsize = items[idx] -> TlvSize();
if (offset + tlvsize > *totalsize)
{
*totalsize = offset;
return count;
}
str << "Stack[" << count << "]";
str << " Offset: " << offset;
str << " TlvSize: " << tlvsize;
str << std::endl;
/* serialise it */
items[idx] -> SetTlv(data, *totalsize, &offset);
items[idx] -> print(str, 10);
count++;
}
*totalsize = offset;
return 0;
}
int test_TlvSet(std::vector<RsTlvItem *> items, int maxsize)
{
int totalsize = maxsize;
void *data = malloc(totalsize);
uint32_t size = totalsize;
test_CreateTlvStack(std::cerr, items, data, &size);
test_StepThroughTlvStack(std::cerr, data, size);
return 1;
}

View File

@ -0,0 +1,48 @@
#ifndef RS_TLV_UTIL_H
#define RS_TLV_UTIL_H
/*
* libretroshare/src/serialiser: rstlvutil.h
*
* 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".
*
*/
/* some utility functions mainly for debugging
*/
#include <inttypes.h>
#include <ostream>
#include <vector>
class RsTlvItem;
/* print out a packet */
void displayRawPacket(std::ostream &out, void *data, uint32_t size);
int test_SerialiseTlvItem(std::ostream &str, RsTlvItem *in, RsTlvItem *out);
bool test_StepThroughTlvStack(std::ostream &str, void *data, int size);
int test_CreateTlvStack(std::ostream &str,
std::vector<RsTlvItem *> items, void *data, int totalsize);
int test_TlvSet(std::vector<RsTlvItem *> items, int maxsize);
#endif

View File

@ -34,7 +34,10 @@
#include "serialiser/rsserial.h"
#include "serialiser/rstlvutil.h"
#include "serialiser/rstlvkeys.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvbinary.h"
#include "serialiser/rstlvfileitem.h"
#include "serialiser/rstlvidset.h"
#include "serialiser/rstlvimage.h"

View File

@ -32,7 +32,7 @@
*/
#include <iostream>
#include "serialiser/rstlvtypes.h"
//#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvutil.h"
#include "util/utest.h"

View File

@ -32,7 +32,7 @@
#include <string.h>
#include <iostream>
#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvbinary.h"
#include "serialiser/rstlvutil.h"
#include "util/utest.h"

View File

@ -42,10 +42,13 @@
#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 "serialiser/rstlvbinary.h"
#include "serialiser/rstlvidset.h"
#include "serialiser/rstlvfileitem.h"
#include "serialiser/rstlvkeyvalue.h"
#include "serialiser/rstlvimage.h"
#include "util/utest.h"
@ -123,8 +126,6 @@ int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
RsTlvKeyValue kv;
RsTlvKeyValueSet kvset;
RsTlvKeyValueWide kvwide;
RsTlvKeyValueWideSet kvwideset;
RsTlvImage image;
@ -139,8 +140,6 @@ int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
CHECK(test_TlvItem(&servset, data, len, offset));
CHECK(test_TlvItem(&kv, data, len, offset));
CHECK(test_TlvItem(&kvset, data, len, offset));
CHECK(test_TlvItem(&kvwide, data, len, offset));
CHECK(test_TlvItem(&kvwideset, data, len, offset));
std::cerr << "test_TlvRandom:: Testing Keys " << std::endl;
CHECK(test_TlvItem(&skey, data, len, offset));
CHECK(test_TlvItem(&skeyset, data, len, offset));
@ -157,8 +156,6 @@ int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
CHECK(test_SetTlvItem(&servset, TLV_TYPE_SERVICESET, data, len, offset));
CHECK(test_SetTlvItem(&kv, TLV_TYPE_KEYVALUE, data, len, offset));
CHECK(test_SetTlvItem(&kvset, TLV_TYPE_KEYVALUESET, data, len, offset));
CHECK(test_SetTlvItem(&kvwide, TLV_TYPE_WKEYVALUE, data, len, offset));
CHECK(test_SetTlvItem(&kvwideset, TLV_TYPE_WKEYVALUESET, data, len, offset));
std::cerr << "test_TlvRandom:: Testing Keys (TYPESET)" << std::endl;
CHECK(test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY, data, len, offset));
CHECK(test_SetTlvItem(&skeyset, TLV_TYPE_SECURITYKEYSET, data, len, offset));

View File

@ -31,7 +31,8 @@
*/
#include <iostream>
#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvfileitem.h"
#include "serialiser/rstlvbinary.h"
#include "serialiser/rstlvutil.h"
#include "util/utest.h"

View File

@ -26,7 +26,12 @@
#include <iostream>
#include <sstream>
#include "serialiser/rstlvtypes.h"
#include "serialiser/rstlvbinary.h"
#include "serialiser/rstlvfileitem.h"
#include "serialiser/rstlvstring.h"
#include "serialiser/rstlvidset.h"
#include "serialiser/rstlvkeyvalue.h"
#include "serialiser/rstlvimage.h"
#include "serialiser/rstlvutil.h"
#include "serialiser/rstlvbase.h"
#include "util/utest.h"
@ -208,7 +213,7 @@ int test_RsTlvPeerIdSet()
RsTlvPeerIdSet i1, i2; // one to set and other to get
std::string testString;
RsPeerId testId;
std::string randString[5];
randString[0] = "e$424!<21>!<21>";
@ -221,9 +226,8 @@ int test_RsTlvPeerIdSet()
for(int i = 0; i < 15 ; i++)
{
testString = randString[(rand() % 4)] + randString[(rand() % 4)];
i1.ids.push_back(testString);
testId.random();
i1.ids.push_back(testId);
}
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
@ -362,37 +366,13 @@ int test_RsTlvHashSet()
int numRandStrings = rand()%30;
std::string* randString = NULL;
std::list<std::string> randStrings;
char alpha = 'a';
char* stringData = NULL;
for(int i=0; i < numRandStrings; i++){
int stringLength = rand()%200;
stringData = new char[stringLength];
for(int i=0; i != stringLength; i++)
stringData[i] = alpha + (rand() % 26);
randString = new std::string(stringData, stringLength);
randStrings.push_back(*randString);
// release memory resources
delete randString;
delete stringData;
stringData = NULL;
randString = NULL;
}
/* store a number of random ids */
for(int i = 0; i < numRandStrings ; i++)
{
i1.ids = randStrings;
RsPeerId randId;
randId.random();
i1.ids.push_back(randId);
}
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));