mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-11 07:40:21 -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
13 changed files with 779 additions and 476 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue