mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-16 11:24:24 -05:00
93d785b8ff
* added new tlv type rstlvwide key value pair for internationalisation * profile interface method not fully implemented yet * blog methods implemented * added extra constructor to facilitate extensibility (rename packet type) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@625 b45a01b8-16f6-495d-af2f-9b41ad6348cc
193 lines
4.4 KiB
C++
Executable File
193 lines
4.4 KiB
C++
Executable File
|
||
/*
|
||
* 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;
|
||
}
|
||
|