mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-22 07:41:20 -04:00
added more extensive test for rsdataservice and subsequent bug fixes.
added test for RsNxsTransac item. applied rule of three to RsTlvBinaryData (destructor, assign op, copy constructor implemented) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5196 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
36103b29a1
commit
822e395f93
17 changed files with 1107 additions and 73 deletions
81
libretroshare/src/tests/gxs/data_support.cc
Normal file
81
libretroshare/src/tests/gxs/data_support.cc
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include "support.h"
|
||||
#include "data_support.h"
|
||||
|
||||
|
||||
bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
|
||||
|
||||
if(!(l.adminSign == r.adminSign)) return false;
|
||||
if(!(l.idSign == r.idSign)) return false;
|
||||
if(l.timeStamp != r.timeStamp) return false;
|
||||
if(l.grpFlag != r.grpFlag) return false;
|
||||
if(l.identity != r.identity) return false;
|
||||
if(l.grpId != r.grpId) return false;
|
||||
if(l.keys.groupId != r.keys.groupId) return false;
|
||||
if(!(l.grp == r.grp) ) return false;
|
||||
|
||||
std::map<std::string, RsTlvSecurityKey>::const_iterator mit =
|
||||
l.keys.keys.begin(), mit_end = l.keys.keys.end();
|
||||
|
||||
for(; mit != mit_end; mit++){
|
||||
const RsTlvSecurityKey& lk = l.keys.keys.find(mit->first)->second;
|
||||
const RsTlvSecurityKey& rk = r.keys.keys.find(mit->first)->second;
|
||||
|
||||
if(! ( lk == rk) ) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsNxsMsg& l, const RsNxsMsg& r){
|
||||
|
||||
if(l.msgId != r.msgId) return false;
|
||||
if(l.grpId != r.grpId) return false;
|
||||
if(l.identity != r.identity) return false;
|
||||
if(l.timeStamp != r.timeStamp) return false;
|
||||
if(l.msgFlag != r.msgFlag) return false;
|
||||
if(! (l.msg == r.msg) ) return false;
|
||||
if(! (l.publishSign == r.publishSign) ) return false;
|
||||
if(! (l.idSign == r.idSign) ) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void init_item(RsNxsGrp* nxg)
|
||||
{
|
||||
|
||||
randString(SHORT_STR, nxg->identity);
|
||||
randString(SHORT_STR, nxg->grpId);
|
||||
nxg->timeStamp = rand()%23;
|
||||
nxg->grpFlag = rand()%242;
|
||||
init_item(nxg->grp);
|
||||
|
||||
init_item(nxg->adminSign);
|
||||
init_item(nxg->idSign);
|
||||
|
||||
int nKey = rand()%12;
|
||||
nxg->keys.groupId = nxg->grpId;
|
||||
for(int i=0; i < nKey; i++){
|
||||
RsTlvSecurityKey k;
|
||||
init_item(k);
|
||||
nxg->keys.keys[k.keyId] = k;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void init_item(RsNxsMsg* nxm)
|
||||
{
|
||||
randString(SHORT_STR, nxm->msgId);
|
||||
randString(SHORT_STR, nxm->grpId);
|
||||
randString(SHORT_STR, nxm->identity);
|
||||
|
||||
init_item(nxm->publishSign);
|
||||
init_item(nxm->idSign);
|
||||
init_item(nxm->msg);
|
||||
nxm->msgFlag = rand()%4252;
|
||||
nxm->timeStamp = rand()%246;
|
||||
|
||||
return;
|
||||
}
|
12
libretroshare/src/tests/gxs/data_support.h
Normal file
12
libretroshare/src/tests/gxs/data_support.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef DATA_SUPPORT_H
|
||||
#define DATA_SUPPORT_H
|
||||
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
|
||||
bool operator==(const RsNxsGrp&, const RsNxsGrp&);
|
||||
bool operator==(const RsNxsMsg&, const RsNxsMsg&);
|
||||
|
||||
void init_item(RsNxsGrp* nxg);
|
||||
void init_item(RsNxsMsg* nxm);
|
||||
|
||||
#endif // DATA_SUPPORT_H
|
|
@ -1,19 +1,29 @@
|
|||
|
||||
#include "support.h"
|
||||
#include "data_support.h"
|
||||
#include "rsdataservice_test.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
|
||||
#define DATA_BASE_NAME "msg_grp_Store"
|
||||
|
||||
INITTEST();
|
||||
RsGeneralDataService* dStore = NULL;
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::cerr << "RsDataService Tests" << std::endl;
|
||||
|
||||
test_groupStoreAndRetrieve(); REPORT("test_groupStoreAndRetrieve");
|
||||
|
||||
test_messageStoresAndRetrieve(); REPORT("test_messageStoresAndRetrieve");
|
||||
|
||||
test_messageVersionRetrieve(); REPORT("test_messageVersionRetrieve");
|
||||
|
||||
test_groupVersionRetrieve(); REPORT("test_groupVersionRetrieve");
|
||||
|
||||
FINALREPORT("RsDataService Tests");
|
||||
|
||||
|
@ -24,9 +34,210 @@ int main()
|
|||
|
||||
|
||||
|
||||
bool test_groupStoreAndRetrieve(){
|
||||
void test_groupStoreAndRetrieve(){
|
||||
|
||||
setUp();
|
||||
|
||||
int nGrp = rand()%32;
|
||||
std::set<RsNxsGrp*> s;
|
||||
RsNxsGrp* grp;
|
||||
for(int i = 0; i < nGrp; i++){
|
||||
grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
init_item(grp);
|
||||
s.insert(grp);
|
||||
}
|
||||
|
||||
dStore->storeGroup(s);
|
||||
|
||||
std::map<std::string, RsNxsGrp*> gm;
|
||||
dStore->retrieveGrps(gm, false);
|
||||
|
||||
// now match grps together
|
||||
|
||||
// simple check,are they the same size
|
||||
CHECK(gm.size() == s.size());
|
||||
|
||||
std::set<RsNxsGrp*>::iterator sit = s.begin();
|
||||
std::map<std::string, RsNxsGrp*>::iterator mit;
|
||||
bool matched = true;
|
||||
|
||||
for(; sit != s.end(); sit++){
|
||||
RsNxsGrp* g1 = *sit;
|
||||
mit = gm.find(g1->grpId);
|
||||
|
||||
if(mit == gm.end()){
|
||||
matched = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
RsNxsGrp* g2 = gm[g1->grpId];
|
||||
|
||||
if(! (*g1 == *g2) )
|
||||
matched = false;
|
||||
|
||||
|
||||
// remove grp file
|
||||
if(g1)
|
||||
remove(g1->grpId.c_str());
|
||||
}
|
||||
|
||||
CHECK(matched);
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_messageStoresAndRetrieve(){
|
||||
|
||||
setUp();
|
||||
|
||||
int nMsgs = rand()%32;
|
||||
std::set<RsNxsMsg*> s;
|
||||
RsNxsMsg* msg;
|
||||
std::string grpId;
|
||||
randString(SHORT_STR, grpId);
|
||||
for(int i = 0; i < nMsgs; i++){
|
||||
msg = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
init_item(msg);
|
||||
msg->grpId = grpId;
|
||||
s.insert(msg);
|
||||
}
|
||||
|
||||
dStore->storeMessage(s);
|
||||
|
||||
std::map<std::string, RsNxsMsg*> msgs;
|
||||
dStore->retrieveMsgs(grpId, msgs, false);
|
||||
|
||||
CHECK(msgs.size() == s.size());
|
||||
|
||||
std::set<RsNxsMsg*>::iterator sit = s.begin();
|
||||
std::map<std::string, RsNxsMsg*>::iterator mit;
|
||||
bool matched = true;
|
||||
|
||||
for(; sit != s.end(); sit++){
|
||||
RsNxsMsg* m1 = *sit;
|
||||
mit = msgs.find(m1->msgId);
|
||||
|
||||
if(mit == msgs.end()){
|
||||
matched = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
RsNxsMsg* m2 = msgs[m1->msgId];
|
||||
|
||||
if(! (*m1 == *m2) )
|
||||
matched = false;
|
||||
}
|
||||
|
||||
CHECK(matched);
|
||||
|
||||
std::string msgFile = grpId + "-msgs";
|
||||
remove(msgFile.c_str());
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
void test_messageVersionRetrieve(){
|
||||
|
||||
setUp();
|
||||
|
||||
// place two messages in store and attempt to retrieve them
|
||||
std::set<RsNxsMsg*> s;
|
||||
RsNxsMsg* msg1 = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||
RsNxsMsg* msg2 = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||
RsNxsMsg* msg3 = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||
std::string grpId;
|
||||
randString(SHORT_STR, grpId);
|
||||
msg1->grpId = grpId;
|
||||
msg2->grpId = grpId;
|
||||
msg3->grpId = grpId;
|
||||
init_item(msg1);
|
||||
init_item(msg2);
|
||||
init_item(msg3);
|
||||
s.insert(msg1); s.insert(msg2); s.insert(msg3);
|
||||
|
||||
dStore->storeMessage(s);
|
||||
|
||||
RsGxsMsgId msgId;
|
||||
msgId.grpId = msg2->grpId;
|
||||
msgId.idSign = msg2->idSign;
|
||||
msgId.msgId = msg2->msgId;
|
||||
RsNxsMsg* msg2_r = dStore->retrieveMsgVersion(msgId);
|
||||
|
||||
CHECK(msg2_r != NULL);
|
||||
|
||||
if(msg2_r)
|
||||
CHECK(*msg2 == *msg2_r);
|
||||
|
||||
delete msg1;
|
||||
delete msg2;
|
||||
delete msg3;
|
||||
delete msg2_r;
|
||||
|
||||
std::string msgFile = grpId + "-msgs";
|
||||
remove(msgFile.c_str());
|
||||
|
||||
tearDown();
|
||||
}
|
||||
|
||||
void test_groupVersionRetrieve(){
|
||||
|
||||
setUp();
|
||||
|
||||
std::set<RsNxsGrp*> grps;
|
||||
RsNxsGrp* group1 = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
RsNxsGrp* group2 = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||
RsNxsGrp* group3 = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||
RsNxsGrp* group2_r = NULL;
|
||||
|
||||
init_item(group1);
|
||||
init_item(group2);
|
||||
init_item(group3);
|
||||
|
||||
grps.insert(group1); grps.insert(group2); grps.insert(group3);
|
||||
|
||||
RsGxsGrpId grpId;
|
||||
grpId.grpId = group2->grpId;
|
||||
grpId.adminSign = group2->adminSign;
|
||||
|
||||
dStore->storeGroup(grps);
|
||||
group2_r = dStore->retrieveGrpVersion(grpId);
|
||||
|
||||
|
||||
CHECK(group2_r != NULL);
|
||||
|
||||
if(group2_r)
|
||||
CHECK(*group2 == *group2_r);
|
||||
|
||||
|
||||
delete group1;
|
||||
delete group2;
|
||||
delete group3;
|
||||
delete group2_r;
|
||||
|
||||
tearDown();
|
||||
|
||||
}
|
||||
|
||||
void setUp(){
|
||||
dStore = new RsDataService(".", DATA_BASE_NAME, RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
void tearDown(){
|
||||
|
||||
dStore->resetDataStore(); // reset to clean up store files except db
|
||||
delete dStore;
|
||||
dStore = NULL;
|
||||
int rc = remove(DATA_BASE_NAME);
|
||||
|
||||
if(rc == 0){
|
||||
std::cerr << "Successful tear down" << std::endl;
|
||||
}
|
||||
else{
|
||||
std::cerr << "Tear down failed" << std::endl;
|
||||
perror("Error: ");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,20 +2,22 @@
|
|||
#define RSDATASERVICE_TEST_H
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "gxs/rsgds.h"
|
||||
|
||||
bool test_messageStoresAndRetrieve();
|
||||
bool test_messageVersionRetrieve();
|
||||
void test_messageStoresAndRetrieve();
|
||||
void test_messageVersionRetrieve();
|
||||
|
||||
bool test_groupStoreAndRetrieve();
|
||||
bool test_groupVersionRetrieve();
|
||||
void test_groupStoreAndRetrieve();
|
||||
void test_groupVersionRetrieve();
|
||||
|
||||
bool test_storeAndDeleteGroup();
|
||||
bool test_storeAndDeleteMessage();
|
||||
void test_storeAndDeleteGroup();
|
||||
void test_storeAndDeleteMessage();
|
||||
|
||||
bool test_searchMsg();
|
||||
bool test_searchGrp();
|
||||
void test_searchMsg();
|
||||
void test_searchGrp();
|
||||
|
||||
bool test_multiThreaded();
|
||||
void test_multiThreaded();
|
||||
|
||||
class DataReadWrite : RsThread
|
||||
{
|
||||
|
@ -24,6 +26,9 @@ class DataReadWrite : RsThread
|
|||
|
||||
};
|
||||
|
||||
bool test_cacheSize();
|
||||
void test_cacheSize();
|
||||
|
||||
void init_item(RsNxsGrp*);
|
||||
void init_item(RsNxsMsg*);
|
||||
|
||||
#endif // RSDATASERVICE_TEST_H
|
||||
|
|
272
libretroshare/src/tests/gxs/support.cc
Normal file
272
libretroshare/src/tests/gxs/support.cc
Normal file
|
@ -0,0 +1,272 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: t_support.h.cc
|
||||
*
|
||||
* RetroShare Serialiser tests.
|
||||
*
|
||||
* Copyright 2007-2008 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 <stdlib.h>
|
||||
|
||||
#include "support.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
void randString(const uint32_t length, std::string& outStr)
|
||||
{
|
||||
char alpha = 'a';
|
||||
char* stringData = NULL;
|
||||
|
||||
stringData = new char[length];
|
||||
|
||||
for(uint32_t i=0; i != length; i++)
|
||||
stringData[i] = alpha + (rand() % 26);
|
||||
|
||||
outStr.assign(stringData, length);
|
||||
delete[] stringData;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void randString(const uint32_t length, std::wstring& outStr)
|
||||
{
|
||||
wchar_t alpha = L'a';
|
||||
wchar_t* stringData = NULL;
|
||||
|
||||
stringData = new wchar_t[length];
|
||||
|
||||
for(uint32_t i=0; i != length; i++)
|
||||
stringData[i] = (alpha + (rand() % 26));
|
||||
|
||||
outStr.assign(stringData, length);
|
||||
delete[] stringData;
|
||||
|
||||
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(RsTlvBinaryData& bd){
|
||||
bd.TlvClear();
|
||||
std::string data;
|
||||
randString(LARGE_STR, data);
|
||||
bd.setBinData(data.data(), data.length());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
222
libretroshare/src/tests/gxs/support.h
Normal file
222
libretroshare/src/tests/gxs/support.h
Normal file
|
@ -0,0 +1,222 @@
|
|||
#ifndef SUPPORT_H_
|
||||
#define SUPPORT_H_
|
||||
|
||||
/*
|
||||
* libretroshare/src/tests/serialiser:
|
||||
*
|
||||
* RetroShare Serialiser tests.
|
||||
*
|
||||
* 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
|
||||
* 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>
|
||||
#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;
|
||||
}
|
||||
|
||||
template<class T> int test_RsItem(uint16_t servtype)
|
||||
{
|
||||
/* make a serialisable RsTurtleItem */
|
||||
|
||||
RsSerialiser srl;
|
||||
|
||||
/* initialise */
|
||||
T rsfi(servtype) ;
|
||||
RsSerialType *rsfis = init_item(rsfi) ; // deleted on destruction of srl
|
||||
|
||||
/* 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 ;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* SUPPORT_H_ */
|
|
@ -97,6 +97,17 @@ RsSerialType* init_item(RsSyncGrpMsgList& rsgml)
|
|||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsNxsTransac& rstx){
|
||||
|
||||
rstx.clear();
|
||||
|
||||
rstx.timeout = rand()%14141;
|
||||
rstx.transactFlag = rand()%2424;
|
||||
rstx.nItems = rand()%33132;
|
||||
rstx.transactionId = rand()%242112;
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
|
||||
|
||||
|
@ -176,6 +187,17 @@ bool operator==(const RsSyncGrpMsgList& l, const RsSyncGrpMsgList& r)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsNxsTransac& l, const RsNxsTransac& r){
|
||||
|
||||
if(l.transactFlag != r.transactFlag) return false;
|
||||
if(l.transactionId != r.transactionId) return false;
|
||||
if(l.timeout != r.timeout) return false;
|
||||
if(l.nItems != r.nItems) return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "RsNxsItem Tests" << std::endl;
|
||||
|
@ -186,6 +208,7 @@ int main()
|
|||
test_RsItem<RsSyncGrpMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsg");
|
||||
test_RsItem<RsSyncGrpList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpList");
|
||||
test_RsItem<RsSyncGrpMsgList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsgList");
|
||||
test_RsItem<RsNxsTransac>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsNxsTransac");
|
||||
|
||||
FINALREPORT("RsNxsItem Tests");
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ RsSerialType* init_item(RsSyncGrp&);
|
|||
RsSerialType* init_item(RsSyncGrpMsg&);
|
||||
RsSerialType* init_item(RsSyncGrpList&);
|
||||
RsSerialType* init_item(RsSyncGrpMsgList&);
|
||||
RsSerialType* init_item(RsNxsTransac& );
|
||||
|
||||
bool operator==(const RsNxsGrp&, const RsNxsGrp&);
|
||||
bool operator==(const RsNxsMsg&, const RsNxsMsg&);
|
||||
|
@ -17,6 +18,7 @@ bool operator==(const RsSyncGrp&, const RsSyncGrp&);
|
|||
bool operator==(const RsSyncGrpMsg&, const RsSyncGrpMsg&);
|
||||
bool operator==(const RsSyncGrpList&, const RsSyncGrpList&);
|
||||
bool operator==(const RsSyncGrpMsgList&, const RsSyncGrpMsgList&);
|
||||
bool operator==(const RsNxsTransac&, const RsNxsTransac& );
|
||||
|
||||
|
||||
#endif // RSNXSITEMS_TEST_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue