mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-05 04:44:19 -04:00
Added new test structure for libretroshare
ported some of the tests across. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7233 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
3eb79bbcba
commit
2a5854188e
52 changed files with 7923 additions and 0 deletions
208
tests/unittests/libretroshare/dbase/ficachetest.cc
Normal file
208
tests/unittests/libretroshare/dbase/ficachetest.cc
Normal file
|
@ -0,0 +1,208 @@
|
|||
/*
|
||||
* RetroShare FileCache Module: ficachetest.cc
|
||||
*
|
||||
* Copyright 2004-2007 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "dbase/cachetest.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include <iostream>
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
|
||||
void handleQuery(CacheStrapper *csp, RsPeerId pid,
|
||||
std::map<RsPeerId, CacheStrapper *> &strappers);
|
||||
|
||||
/* A simple test of the CacheStrapper Code.
|
||||
*
|
||||
* create 3 different CacheStrappers, each with a Source/Store Pair and Transfer Class.
|
||||
* pass queries and responses between the CacheStrappers,
|
||||
* and ensure that the hashes in the Caches are updated.
|
||||
*
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
time_t period = 11;
|
||||
RsPeerId pid1("0x0101");
|
||||
RsPeerId pid2("0x0102");
|
||||
RsPeerId pid3("0x0103");
|
||||
|
||||
p3ConnectMgr *connMgr1 = new p3ConnectMgr();
|
||||
p3ConnectMgr *connMgr2 = connMgr1;
|
||||
p3ConnectMgr *connMgr3 = connMgr1;
|
||||
|
||||
CacheStrapper sc1(connMgr1);
|
||||
CacheStrapper sc2(connMgr2);
|
||||
CacheStrapper sc3(connMgr3);
|
||||
CacheTransfer ctt1(&sc1);
|
||||
CacheTransfer ctt2(&sc2);
|
||||
CacheTransfer ctt3(&sc3);
|
||||
|
||||
std::map<RsPeerId, CacheStrapper *> strappers;
|
||||
strappers[pid1] = &sc1;
|
||||
strappers[pid2] = &sc2;
|
||||
strappers[pid3] = &sc3;
|
||||
|
||||
|
||||
std::string nulldir = "";
|
||||
|
||||
CacheSource *csrc1 = new CacheTestSource(&sc1, nulldir);
|
||||
CacheStore *cstore1 = new CacheTestStore(&ctt1, &sc1, nulldir);
|
||||
CacheId cid1(TESTID, 0);
|
||||
|
||||
CacheSource *csrc2 = new CacheTestSource(&sc2, nulldir);
|
||||
CacheStore *cstore2 = new CacheTestStore(&ctt2, &sc2, nulldir);
|
||||
CacheId cid2(TESTID, 0);
|
||||
|
||||
CacheSource *csrc3 = new CacheTestSource(&sc3, nulldir);
|
||||
CacheStore *cstore3 = new CacheTestStore(&ctt3, &sc3, nulldir);
|
||||
CacheId cid3(TESTID, 0);
|
||||
|
||||
CachePair cp1(csrc1, cstore1, cid1);
|
||||
CachePair cp2(csrc2, cstore2, cid2);
|
||||
CachePair cp3(csrc3, cstore3, cid3);
|
||||
|
||||
sc1.addCachePair(cp1);
|
||||
sc2.addCachePair(cp2);
|
||||
sc3.addCachePair(cp3);
|
||||
|
||||
/* add in a cache to sc2 */
|
||||
RsCacheData cdata;
|
||||
|
||||
cdata.pid = pid1;
|
||||
cdata.cid = cid1;
|
||||
cdata.name = "Perm Cache";
|
||||
cdata.path = "./";
|
||||
cdata.hash = "GHJKI";
|
||||
|
||||
csrc1->refreshCache(cdata);
|
||||
|
||||
cdata.pid = pid2;
|
||||
cdata.cid = cid2;
|
||||
cdata.name = "Funny Cache";
|
||||
cdata.path = "./";
|
||||
cdata.hash = "ABCDEF";
|
||||
|
||||
csrc2->refreshCache(cdata);
|
||||
|
||||
/* now exercise it */
|
||||
|
||||
for(int i = 0; 1 ; i++)
|
||||
{
|
||||
RsPeerId src("");
|
||||
CacheStrapper *csp = NULL;
|
||||
|
||||
if (i % 5 == 1)
|
||||
{
|
||||
src = pid1;
|
||||
csp = &sc1;
|
||||
}
|
||||
else if (i % 5 == 2)
|
||||
{
|
||||
src = pid2;
|
||||
csp = &sc2;
|
||||
}
|
||||
else if (i % 5 == 3)
|
||||
{
|
||||
src = pid3;
|
||||
csp = &sc3;
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Cache Iteraton: " << time(NULL) << std::endl;
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (src != "")
|
||||
{
|
||||
handleQuery(csp, src, strappers);
|
||||
}
|
||||
|
||||
|
||||
if (i % 21 == 0)
|
||||
{
|
||||
/* print out the resources */
|
||||
sc1.listCaches(std::cerr);
|
||||
sc2.listCaches(std::cerr);
|
||||
sc3.listCaches(std::cerr);
|
||||
}
|
||||
|
||||
/* every once in a while change the cache on 2 */
|
||||
if (i % 31 == 25)
|
||||
{
|
||||
cdata.hash += "X";
|
||||
csrc2->refreshCache(cdata);
|
||||
}
|
||||
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
sleep(1);
|
||||
#else
|
||||
Sleep(1000);
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
/* tick the systems */
|
||||
|
||||
}
|
||||
|
||||
/* Cleanup - TODO */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void handleQuery(CacheStrapper *csp, RsPeerId pid,
|
||||
std::map<RsPeerId, CacheStrapper *> &strappers)
|
||||
{
|
||||
/* query */
|
||||
std::list<RsPeerId> ids;
|
||||
std::list<RsPeerId>::iterator pit;
|
||||
|
||||
std::cerr << "Cache Query from: " << pid << std::endl;
|
||||
|
||||
//csp -> sendCacheQuery(ids, time(NULL));
|
||||
for(pit = ids.begin(); pit != ids.end(); pit++)
|
||||
{
|
||||
std::cerr << "Cache Query for: " << (*pit) << std::endl;
|
||||
std::map<RsPeerId, CacheStrapper *>::iterator sit;
|
||||
if (strappers.end() != (sit = strappers.find(*pit)))
|
||||
{
|
||||
std::map<CacheId, RsCacheData> hashs;
|
||||
std::map<CacheId, RsCacheData>::iterator hit;
|
||||
(sit -> second) -> handleCacheQuery(pid, hashs);
|
||||
for(hit = hashs.begin(); hit != hashs.end(); hit++)
|
||||
{
|
||||
csp -> recvCacheResponse(hit->second, time(NULL));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Unknown Query Destination!" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
99
tests/unittests/libretroshare/dbase/fimontest.cc
Normal file
99
tests/unittests/libretroshare/dbase/fimontest.cc
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* RetroShare FileCache Module: fimontest.cc
|
||||
*
|
||||
* Copyright 2004-2007 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".
|
||||
*
|
||||
*/
|
||||
|
||||
//#include "pqi/p3connmgr.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "dbase/findex.h"
|
||||
#include "dbase/fimonitor.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void usage(char *name)
|
||||
{
|
||||
std::cerr << "Usage: " << name << " [-p <period> ] shareDir1 [shareDir2 [shareDir3 [...]]]";
|
||||
std::cerr << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* What is tested:
|
||||
* 1.
|
||||
* 2.
|
||||
* 3.
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* handle commandline arguments */
|
||||
int c;
|
||||
int period = 60; /* recheck period in seconds */
|
||||
|
||||
while((c = getopt(argc, argv,"p:")) != -1)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case 'p':
|
||||
period = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Bad Option.";
|
||||
std::cerr << std::endl;
|
||||
usage(argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::list<SharedDirInfo> rootdirs;
|
||||
|
||||
/* add all the rest of the commandline arguments to rootdirs list */
|
||||
for(; optind < argc; optind++)
|
||||
{
|
||||
SharedDirInfo dir;
|
||||
dir.filename = argv[optind];
|
||||
dir.shareflags = DIR_FLAGS_PERMISSIONS_MASK ;
|
||||
rootdirs.push_back(dir);
|
||||
std::cerr << "Adding shared directory: " << argv[optind] << std::endl;
|
||||
}
|
||||
|
||||
if (rootdirs.size() < 1)
|
||||
{
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
//p3ConnectMgr connMgr;
|
||||
NotifyBase nb;
|
||||
CacheStrapper* cs = NULL;
|
||||
|
||||
FileIndexMonitor mon(cs, &nb, "", "OWN ID", std::string("."));
|
||||
|
||||
/* setup monitor */
|
||||
mon.setSharedDirectories(rootdirs);
|
||||
|
||||
/* simulate running the thread */
|
||||
mon.run();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
127
tests/unittests/libretroshare/dbase/fisavetest.cc
Normal file
127
tests/unittests/libretroshare/dbase/fisavetest.cc
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* RetroShare FileCache Module: fisavetest.cc
|
||||
*
|
||||
* Copyright 2004-2007 by Kefei Zhou.
|
||||
*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "dbase/findex.h"
|
||||
#include <iostream>
|
||||
|
||||
static FileIndex *createBasicFileIndex(time_t age);
|
||||
|
||||
TEST(libretroshare_dbase, SaveTest)
|
||||
{
|
||||
RsPeerId peerId;
|
||||
peerId.random();
|
||||
FileIndex *fi1 = createBasicFileIndex(100);
|
||||
FileIndex *fi2 = new FileIndex(peerId);
|
||||
|
||||
std::string out ;
|
||||
fi1->printFileIndex(out);
|
||||
std::cout << out <<std::endl;
|
||||
RsFileHash fhash;
|
||||
uint64_t size;
|
||||
std::set<std::string> forbiddenroots;
|
||||
fi1->saveIndex("test.index", fhash, size, forbiddenroots);
|
||||
|
||||
std::cout << " Saved Index: Size: " << size << " Hash: " << fhash << std::endl;
|
||||
std::cout << " -- new file index -- " << std::endl;
|
||||
|
||||
fi2->loadIndex("test.index", fhash, size);
|
||||
out.clear() ;
|
||||
fi2->printFileIndex(out);
|
||||
std::cout << out << std::endl;
|
||||
|
||||
delete fi1;
|
||||
delete fi2;
|
||||
}
|
||||
|
||||
|
||||
FileIndex *createBasicFileIndex(time_t age)
|
||||
{
|
||||
RsPeerId peerId;
|
||||
peerId.random();
|
||||
FileIndex *fi = new FileIndex(peerId);
|
||||
|
||||
FileEntry fe;
|
||||
|
||||
std::list<std::string> rootdirs;
|
||||
rootdirs.push_back("base1");
|
||||
rootdirs.push_back("base2");
|
||||
rootdirs.push_back("base3");
|
||||
|
||||
fi -> setRootDirectories(rootdirs, age);
|
||||
|
||||
/* add some entries */
|
||||
fe.name = "dir1";
|
||||
fi -> updateDirEntry("base1",fe, age);
|
||||
fe.name = "dir2";
|
||||
fi -> updateDirEntry("base1",fe, age);
|
||||
|
||||
fe.name = "dir01";
|
||||
fi -> updateDirEntry("/base1/dir1/",fe, age);
|
||||
|
||||
fe.name = "dir001";
|
||||
fi -> updateDirEntry("/base1/dir1/dir01/",fe, age);
|
||||
|
||||
fe.name = "file1";
|
||||
fi -> updateFileEntry("/base1/dir1/",fe, age);
|
||||
fe.name = "file2";
|
||||
fi -> updateFileEntry("/base1/dir1/",fe, age);
|
||||
fe.name = "file3";
|
||||
fi -> updateFileEntry("/base1/dir1/",fe, age);
|
||||
fe.name = "file4";
|
||||
fi -> updateFileEntry("/base1/dir1/",fe, age);
|
||||
|
||||
|
||||
fe.name = "dir2";
|
||||
fi -> updateDirEntry("/base1",fe, age);
|
||||
fe.name = "file5";
|
||||
fi -> updateFileEntry("/base1/dir2/",fe, age);
|
||||
fe.name = "file6";
|
||||
fi -> updateFileEntry("/base1/dir2/",fe, age);
|
||||
fe.name = "file7";
|
||||
fi -> updateFileEntry("/base1/dir2/",fe, age);
|
||||
fe.name = "file8";
|
||||
fi -> updateFileEntry("/base1/",fe, age);
|
||||
|
||||
|
||||
fe.name = "dir3";
|
||||
fi -> updateDirEntry("/base1/dir2/",fe, age);
|
||||
fe.name = "file10";
|
||||
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
|
||||
fe.name = "file11";
|
||||
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
|
||||
fe.name = "file12";
|
||||
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
|
||||
|
||||
|
||||
fe.name = "dir4";
|
||||
fi -> updateDirEntry("/base3/",fe, age);
|
||||
fe.name = "file20";
|
||||
fi -> updateFileEntry("/base3/dir4/",fe, age);
|
||||
fe.name = "file21";
|
||||
fi -> updateFileEntry("/base3/dir4",fe, age);
|
||||
|
||||
return fi;
|
||||
}
|
||||
|
227
tests/unittests/libretroshare/dbase/fitest2.cc
Normal file
227
tests/unittests/libretroshare/dbase/fitest2.cc
Normal file
|
@ -0,0 +1,227 @@
|
|||
/*
|
||||
* RetroShare FileCache Module: fitest2.cc
|
||||
*
|
||||
* Copyright 2004-2007 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "dbase/findex.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static FileIndex *createBasicFileIndex(time_t age);
|
||||
|
||||
int test1(FileIndex *fi);
|
||||
int test2(FileIndex *fi);
|
||||
|
||||
TEST(libretroshare_dbase, FiTest2)
|
||||
{
|
||||
FileIndex *fi = createBasicFileIndex(100);
|
||||
|
||||
test1(fi);
|
||||
|
||||
delete fi;
|
||||
}
|
||||
|
||||
int test1(FileIndex *fi)
|
||||
{
|
||||
/* in this test we are going to get the old directories - and update them */
|
||||
time_t stamp = 200;
|
||||
|
||||
DirEntry *olddir = NULL;
|
||||
FileEntry fe;
|
||||
while((olddir = fi -> findOldDirectory(stamp)))
|
||||
{
|
||||
/* update the directories and files here */
|
||||
std::map<std::string, DirEntry *>::iterator dit;
|
||||
std::map<std::string, FileEntry *>::iterator fit;
|
||||
|
||||
/* update this dir */
|
||||
fe.name = olddir->name;
|
||||
fi -> updateDirEntry(olddir->parent->path, fe, stamp);
|
||||
|
||||
/* update subdirs */
|
||||
for(dit = olddir->subdirs.begin(); dit != olddir->subdirs.end(); dit++)
|
||||
{
|
||||
fe.name = (dit->second)->name;
|
||||
/* set the age as out-of-date so that it gets checked */
|
||||
fi -> updateDirEntry(olddir->path, fe, 0);
|
||||
}
|
||||
|
||||
/* update files */
|
||||
for(fit = olddir->files.begin(); fit != olddir->files.end(); fit++)
|
||||
{
|
||||
fe.name = (fit->second)->name;
|
||||
fi -> updateFileEntry(olddir->path, fe, stamp);
|
||||
}
|
||||
|
||||
/* clean up the dir (should have no effect) */
|
||||
fi -> removeOldDirectory(olddir->parent->path, olddir->name, stamp);
|
||||
|
||||
std::string out ;
|
||||
fi -> printFileIndex(out);
|
||||
std::cout << out << std::endl;
|
||||
}
|
||||
|
||||
std::string out ;
|
||||
fi -> printFileIndex(out);
|
||||
std::cout << out << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int test2(FileIndex *fi)
|
||||
{
|
||||
/* in this test we are going to simulate that 2 directories have disappeared */
|
||||
time_t stamp = 200;
|
||||
|
||||
DirEntry *olddir = NULL;
|
||||
FileEntry fe;
|
||||
bool missingdir = false;
|
||||
int i = 0;
|
||||
|
||||
while((olddir = fi -> findOldDirectory(stamp)))
|
||||
{
|
||||
missingdir = false;
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
std::cerr << " Simulating that dir doesnt exist :" << olddir->path;
|
||||
std::cerr << std::endl;
|
||||
missingdir = true;
|
||||
}
|
||||
i++;
|
||||
|
||||
if (!missingdir)
|
||||
{
|
||||
/* update the directories and files here */
|
||||
std::map<std::string, DirEntry *>::iterator dit;
|
||||
std::map<std::string, FileEntry *>::iterator fit;
|
||||
|
||||
/* update this dir */
|
||||
fe.name = olddir->name;
|
||||
fi -> updateDirEntry(olddir->parent->path, fe, stamp);
|
||||
|
||||
/* update subdirs */
|
||||
for(dit = olddir->subdirs.begin(); dit != olddir->subdirs.end(); dit++)
|
||||
{
|
||||
fe.name = (dit->second)->name;
|
||||
/* set the age as out-of-date so that it gets checked */
|
||||
fi -> updateDirEntry(olddir->path, fe, 0);
|
||||
}
|
||||
|
||||
/* update files */
|
||||
for(fit = olddir->files.begin(); fit != olddir->files.end(); fit++)
|
||||
{
|
||||
fe.name = (fit->second)->name;
|
||||
fi -> updateFileEntry(olddir->path, fe, stamp);
|
||||
}
|
||||
}
|
||||
/* clean up the dir */
|
||||
fi -> removeOldDirectory(olddir->parent->path, olddir->name, stamp);
|
||||
|
||||
std::string out ;
|
||||
fi -> printFileIndex(out);
|
||||
std::cout << out << std::endl;
|
||||
}
|
||||
|
||||
std::string out ;
|
||||
fi -> printFileIndex(out);
|
||||
std::cout << out << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
FileIndex *createBasicFileIndex(time_t age)
|
||||
{
|
||||
RsPeerId peerId;
|
||||
peerId.random();
|
||||
FileIndex *fi = new FileIndex(peerId);
|
||||
|
||||
FileEntry fe;
|
||||
|
||||
/* print empty FileIndex */
|
||||
std::string out ;
|
||||
fi -> printFileIndex(out);
|
||||
std::cout << out << std::endl;
|
||||
|
||||
std::list<std::string> rootdirs;
|
||||
rootdirs.push_back("base1");
|
||||
rootdirs.push_back("base2");
|
||||
rootdirs.push_back("base3");
|
||||
|
||||
fi -> setRootDirectories(rootdirs, age);
|
||||
|
||||
/* add some entries */
|
||||
fe.name = "dir1";
|
||||
fi -> updateDirEntry("base1",fe, age);
|
||||
fe.name = "file1";
|
||||
fi -> updateFileEntry("/base1/dir1/",fe, age);
|
||||
fe.name = "file2";
|
||||
fi -> updateFileEntry("/base1/dir1/",fe, age);
|
||||
fe.name = "file3";
|
||||
fi -> updateFileEntry("/base1/dir1/",fe, age);
|
||||
fe.name = "file4";
|
||||
fi -> updateFileEntry("/base1/dir1/",fe, age);
|
||||
|
||||
fe.name = "dir2";
|
||||
fi -> updateDirEntry("/base1",fe, age);
|
||||
fe.name = "file5";
|
||||
fi -> updateFileEntry("/base1/dir2/",fe, age);
|
||||
fe.name = "file6";
|
||||
fi -> updateFileEntry("/base1/dir2/",fe, age);
|
||||
fe.name = "file7";
|
||||
fi -> updateFileEntry("/base1/dir2/",fe, age);
|
||||
fe.name = "file8";
|
||||
fi -> updateFileEntry("/base1/",fe, age);
|
||||
|
||||
|
||||
fe.name = "dir3";
|
||||
fi -> updateDirEntry("/base1/dir2/",fe, age);
|
||||
fe.name = "file10";
|
||||
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
|
||||
fe.name = "file11";
|
||||
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
|
||||
fe.name = "file12";
|
||||
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
|
||||
|
||||
|
||||
fe.name = "dir4";
|
||||
fi -> updateDirEntry("/base3/",fe, age);
|
||||
fe.name = "file20";
|
||||
fi -> updateFileEntry("/base3/dir4/",fe, age);
|
||||
fe.name = "file21";
|
||||
fi -> updateFileEntry("/base3/dir4",fe, age);
|
||||
|
||||
// one that will fail.
|
||||
fe.name = "file20";
|
||||
fi -> updateFileEntry("/base3/",fe, age);
|
||||
|
||||
out.clear() ;
|
||||
fi -> printFileIndex(out);
|
||||
std::cout << out << std::endl;
|
||||
|
||||
return fi;
|
||||
}
|
||||
|
80
tests/unittests/libretroshare/dbase/searchtest.cc
Normal file
80
tests/unittests/libretroshare/dbase/searchtest.cc
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* RetroShare FileCache Module: searchtest.cc
|
||||
*
|
||||
* Copyright 2004-2007 by Kefei Zhou.
|
||||
*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "dbase/findex.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
TEST(libretroshare_dbase, SearchTest)
|
||||
{
|
||||
RsPeerId peerId;
|
||||
peerId.random();
|
||||
|
||||
std::cout << std::string::npos << std::endl;
|
||||
std::string testfile = "searchtest.index";
|
||||
RsFileHash fhash("6851c28d99a6616a86942c3914476bf11997242a");
|
||||
FileIndex *fi = new FileIndex(peerId);
|
||||
|
||||
// loading fileindex
|
||||
std::cout << std::endl << "Test load" << std::endl;
|
||||
fi->loadIndex(testfile, fhash, 1532);
|
||||
fi->printFileIndex(std::cout);
|
||||
std::cout << "FileIndex Loaded" << std::endl << std::endl;
|
||||
|
||||
std::list<FileEntry *> hashresult;
|
||||
std::list<FileEntry *> termresult;
|
||||
|
||||
// searchhash
|
||||
RsFileHash findhash("82bffa6e1cdf8419397311789391238174817481");
|
||||
|
||||
std::cout << "Search hash : " << findhash << std::endl;
|
||||
fi->searchHash(findhash, hashresult);
|
||||
|
||||
while(!hashresult.empty())
|
||||
{
|
||||
std::string out ;
|
||||
hashresult.back()->print(out);
|
||||
std::cout << out << std::endl;
|
||||
hashresult.pop_back();
|
||||
}
|
||||
|
||||
// searchterm
|
||||
std::list<std::string> terms;
|
||||
terms.push_back("paper");
|
||||
terms.push_back("doc");
|
||||
|
||||
std::cout << "Search terms" << std::endl;
|
||||
fi->searchTerms(terms, termresult);
|
||||
|
||||
while(!termresult.empty())
|
||||
{
|
||||
std::string out ;
|
||||
termresult.back()->print(out);
|
||||
std::cout << out << std::endl;
|
||||
termresult.pop_back();
|
||||
}
|
||||
|
||||
delete fi;
|
||||
}
|
270
tests/unittests/libretroshare/gxs/common/data_support.cc
Normal file
270
tests/unittests/libretroshare/gxs/common/data_support.cc
Normal file
|
@ -0,0 +1,270 @@
|
|||
#include "libretroshare/serialiser/support.h"
|
||||
#include "data_support.h"
|
||||
|
||||
|
||||
bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
|
||||
|
||||
if(l.grpId != r.grpId) return false;
|
||||
if(!(l.grp == r.grp) ) return false;
|
||||
if(!(l.meta == r.meta) ) return false;
|
||||
if(l.transactionNumber != r.transactionNumber) 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.msg == r.msg) ) return false;
|
||||
if(! (l.meta == r.meta) ) return false;
|
||||
if(l.transactionNumber != r.transactionNumber) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool operator ==(const RsGxsGrpMetaData& l, const RsGxsGrpMetaData& r)
|
||||
{
|
||||
if(!(l.signSet == r.signSet)) return false;
|
||||
if(!(l.keys == r.keys)) return false;
|
||||
if(l.mGroupFlags != r.mGroupFlags) return false;
|
||||
if(l.mPublishTs != r.mPublishTs) return false;
|
||||
if(l.mAuthorId != r.mAuthorId) return false;
|
||||
if(l.mGroupName != r.mGroupName) return false;
|
||||
if(l.mGroupId != r.mGroupId) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsMsgMetaData& l, const RsGxsMsgMetaData& r)
|
||||
{
|
||||
|
||||
if(!(l.signSet == r.signSet)) return false;
|
||||
if(l.mGroupId != r.mGroupId) return false;
|
||||
if(l.mAuthorId != r.mAuthorId) return false;
|
||||
if(l.mParentId != r.mParentId) return false;
|
||||
if(l.mOrigMsgId != r.mOrigMsgId) return false;
|
||||
if(l.mThreadId != r.mThreadId) return false;
|
||||
if(l.mMsgId != r.mMsgId) return false;
|
||||
if(l.mMsgName != r.mMsgName) return false;
|
||||
if(l.mPublishTs != r.mPublishTs) return false;
|
||||
if(l.mMsgFlags != r.mMsgFlags) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
void init_item(RsNxsGrp& nxg)
|
||||
{
|
||||
|
||||
nxg.clear();
|
||||
|
||||
nxg.grpId.random();
|
||||
nxg.transactionNumber = rand()%23;
|
||||
init_item(nxg.grp);
|
||||
init_item(nxg.meta);
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsNxsMsg& nxm)
|
||||
{
|
||||
nxm.clear();
|
||||
|
||||
nxm.msgId.random();
|
||||
nxm.grpId.random();
|
||||
init_item(nxm.msg);
|
||||
init_item(nxm.meta);
|
||||
nxm.transactionNumber = rand()%23;
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void init_item(RsGxsGrpMetaData* metaGrp)
|
||||
{
|
||||
|
||||
metaGrp->mGroupId.random();
|
||||
metaGrp->mOrigGrpId.random();
|
||||
metaGrp->mAuthorId.random();
|
||||
randString(SHORT_STR, metaGrp->mGroupName);
|
||||
|
||||
init_item(metaGrp->signSet);
|
||||
init_item(metaGrp->keys);
|
||||
|
||||
metaGrp->mPublishTs = rand()%3452;
|
||||
metaGrp->mGroupFlags = rand()%43;
|
||||
|
||||
metaGrp->mGroupStatus = rand()%313;
|
||||
metaGrp->mSubscribeFlags = rand()%2251;
|
||||
metaGrp->mMsgCount = rand()%2421;
|
||||
metaGrp->mLastPost = rand()%2211;
|
||||
metaGrp->mPop = rand()%5262;
|
||||
}
|
||||
|
||||
void init_item(RsGxsMsgMetaData* metaMsg)
|
||||
{
|
||||
|
||||
metaMsg->mGroupId.random();
|
||||
metaMsg->mMsgId.random();
|
||||
metaMsg->mThreadId.random();
|
||||
metaMsg->mParentId.random();
|
||||
metaMsg->mAuthorId.random();
|
||||
metaMsg->mOrigMsgId.random();
|
||||
randString(SHORT_STR, metaMsg->mMsgName);
|
||||
|
||||
init_item(metaMsg->signSet);
|
||||
|
||||
metaMsg->mPublishTs = rand()%313;
|
||||
metaMsg->mMsgFlags = rand()%224;
|
||||
metaMsg->mMsgStatus = rand()%4242;
|
||||
metaMsg->mChildTs = rand()%221;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
RsSerialType* init_item(RsNxsGrp& nxg)
|
||||
{
|
||||
nxg.clear();
|
||||
|
||||
nxg.grpId.random();
|
||||
nxg.transactionNumber = rand()%23;
|
||||
init_item(nxg.grp);
|
||||
init_item(nxg.meta);
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
|
||||
RsSerialType* init_item(RsNxsMsg& nxm)
|
||||
{
|
||||
nxm.clear();
|
||||
|
||||
nxm.msgId.random();
|
||||
nxm.grpId.random();
|
||||
init_item(nxm.msg);
|
||||
init_item(nxm.meta);
|
||||
nxm.transactionNumber = rand()%23;
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsNxsSyncGrp& rsg)
|
||||
{
|
||||
rsg.clear();
|
||||
rsg.flag = RsNxsSyncGrp::FLAG_USE_SYNC_HASH;
|
||||
rsg.createdSince = rand()%2423;
|
||||
randString(3124,rsg.syncHash);
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsNxsSyncMsg& rsgm)
|
||||
{
|
||||
rsgm.clear();
|
||||
|
||||
rsgm.flag = RsNxsSyncMsg::FLAG_USE_SYNC_HASH;
|
||||
rsgm.createdSince = rand()%24232;
|
||||
rsgm.transactionNumber = rand()%23;
|
||||
rsgm.grpId.random();
|
||||
randString(SHORT_STR, rsgm.syncHash);
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsNxsSyncGrpItem& rsgl)
|
||||
{
|
||||
rsgl.clear();
|
||||
|
||||
rsgl.flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
|
||||
rsgl.transactionNumber = rand()%23;
|
||||
rsgl.publishTs = rand()%23;
|
||||
rsgl.grpId.random();
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsNxsSyncMsgItem& rsgml)
|
||||
{
|
||||
rsgml.clear();
|
||||
|
||||
rsgml.flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
|
||||
rsgml.transactionNumber = rand()%23;
|
||||
rsgml.grpId.random();
|
||||
rsgml.msgId.random();
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsNxsTransac& rstx){
|
||||
|
||||
rstx.clear();
|
||||
|
||||
rstx.timestamp = rand()%14141;
|
||||
rstx.transactFlag = rand()%2424;
|
||||
rstx.nItems = rand()%33132;
|
||||
rstx.transactionNumber = rand()%242112;
|
||||
|
||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
|
||||
bool operator==(const RsNxsSyncGrp& l, const RsNxsSyncGrp& r)
|
||||
{
|
||||
|
||||
if(l.syncHash != r.syncHash) return false;
|
||||
if(l.flag != r.flag) return false;
|
||||
if(l.createdSince != r.createdSince) return false;
|
||||
if(l.transactionNumber != r.transactionNumber) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsNxsSyncMsg& l, const RsNxsSyncMsg& r)
|
||||
{
|
||||
|
||||
if(l.flag != r.flag) return false;
|
||||
if(l.createdSince != r.createdSince) return false;
|
||||
if(l.syncHash != r.syncHash) return false;
|
||||
if(l.grpId != r.grpId) return false;
|
||||
if(l.transactionNumber != r.transactionNumber) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsNxsSyncGrpItem& l, const RsNxsSyncGrpItem& r)
|
||||
{
|
||||
if(l.flag != r.flag) return false;
|
||||
if(l.publishTs != r.publishTs) return false;
|
||||
if(l.grpId != r.grpId) return false;
|
||||
if(l.transactionNumber != r.transactionNumber) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsNxsSyncMsgItem& l, const RsNxsSyncMsgItem& r)
|
||||
{
|
||||
if(l.flag != r.flag) return false;
|
||||
if(l.grpId != r.grpId) return false;
|
||||
if(l.msgId != r.msgId) return false;
|
||||
if(l.transactionNumber != r.transactionNumber) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsNxsTransac& l, const RsNxsTransac& r){
|
||||
|
||||
if(l.transactFlag != r.transactFlag) return false;
|
||||
if(l.transactionNumber != r.transactionNumber) return false;
|
||||
if(l.timestamp != r.timestamp) return false;
|
||||
if(l.nItems != r.nItems) return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
31
tests/unittests/libretroshare/gxs/common/data_support.h
Normal file
31
tests/unittests/libretroshare/gxs/common/data_support.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
#define RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM 0x012
|
||||
|
||||
bool operator==(const RsNxsGrp&, const RsNxsGrp&);
|
||||
bool operator==(const RsNxsMsg&, const RsNxsMsg&);
|
||||
bool operator==(const RsGxsGrpMetaData& l, const RsGxsGrpMetaData& r);
|
||||
bool operator==(const RsGxsMsgMetaData& l, const RsGxsMsgMetaData& r);
|
||||
bool operator==(const RsNxsSyncGrp& l, const RsNxsSyncGrp& r);
|
||||
bool operator==(const RsNxsSyncMsg& l, const RsNxsSyncMsg& r);
|
||||
bool operator==(const RsNxsSyncGrpItem& l, const RsNxsSyncGrpItem& r);
|
||||
bool operator==(const RsNxsSyncMsgItem& l, const RsNxsSyncMsgItem& r);
|
||||
bool operator==(const RsNxsTransac& l, const RsNxsTransac& r);
|
||||
|
||||
//void init_item(RsNxsGrp& nxg);
|
||||
//void init_item(RsNxsMsg& nxm);
|
||||
void init_item(RsGxsGrpMetaData* metaGrp);
|
||||
void init_item(RsGxsMsgMetaData* metaMsg);
|
||||
|
||||
|
||||
RsSerialType* init_item(RsNxsGrp& nxg);
|
||||
RsSerialType* init_item(RsNxsMsg& nxm);
|
||||
RsSerialType* init_item(RsNxsSyncGrp& rsg);
|
||||
RsSerialType* init_item(RsNxsSyncMsg& rsgm);
|
||||
RsSerialType* init_item(RsNxsSyncGrpItem& rsgl);
|
||||
RsSerialType* init_item(RsNxsSyncMsgItem& rsgml);
|
||||
RsSerialType* init_item(RsNxsTransac& rstx);
|
||||
|
|
@ -0,0 +1,335 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "libretroshare/serialiser/support.h"
|
||||
#include "libretroshare/gxs/common/data_support.h"
|
||||
#include "rsdataservice_test.h"
|
||||
#include "gxs/rsgds.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
|
||||
#define DATA_BASE_NAME "msg_grp_Store"
|
||||
|
||||
|
||||
RsGeneralDataService* dStore = NULL;
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
TEST(libretroshare_gxs, RsDataService)
|
||||
{
|
||||
|
||||
std::cerr << "RsDataService Tests" << std::endl;
|
||||
|
||||
test_groupStoreAndRetrieve();
|
||||
test_messageStoresAndRetrieve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* All memory is disposed off, good for looking
|
||||
* for memory leaks
|
||||
*/
|
||||
void test_groupStoreAndRetrieve(){
|
||||
|
||||
setUp();
|
||||
|
||||
int nGrp = rand()%32;
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps, grps_copy;
|
||||
RsNxsGrp* grp;
|
||||
RsGxsGrpMetaData* grpMeta;
|
||||
for(int i = 0; i < nGrp; i++){
|
||||
std::pair<RsNxsGrp*, RsGxsGrpMetaData*> p;
|
||||
grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
grpMeta = new RsGxsGrpMetaData();
|
||||
p.first = grp;
|
||||
p.second = grpMeta;
|
||||
init_item(*grp);
|
||||
init_item(grpMeta);
|
||||
grpMeta->mGroupId = grp->grpId;
|
||||
grps.insert(p);
|
||||
RsNxsGrp* grp_copy = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
*grp_copy = *grp;
|
||||
RsGxsGrpMetaData* grpMeta_copy = new RsGxsGrpMetaData();
|
||||
*grpMeta_copy = *grpMeta;
|
||||
grps_copy.insert(std::make_pair(grp_copy, grpMeta_copy ));
|
||||
grpMeta = NULL;
|
||||
grp = NULL;
|
||||
}
|
||||
|
||||
dStore->storeGroup(grps);
|
||||
|
||||
//use copy, a grps are deleted in store
|
||||
grps.clear();
|
||||
grps = grps_copy;
|
||||
|
||||
std::map<RsGxsGroupId, RsNxsGrp*> gR;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetaR;
|
||||
dStore->retrieveNxsGrps(gR, false, false);
|
||||
dStore->retrieveGxsGrpMetaData(grpMetaR);
|
||||
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*>::iterator mit = grps.begin();
|
||||
|
||||
bool grpMatch = true, grpMetaMatch = true;
|
||||
|
||||
for(; mit != grps.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId grpId = mit->first->grpId;
|
||||
|
||||
// check if it exists
|
||||
if(gR.find(grpId) == gR.end()) {
|
||||
grpMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsNxsGrp *l = mit->first,
|
||||
*r = gR[grpId];
|
||||
|
||||
// assign transaction number
|
||||
// to right to as tn is not stored
|
||||
// in db
|
||||
r->transactionNumber = l->transactionNumber;
|
||||
|
||||
// then do a comparison
|
||||
if(!( *l == *r)) {
|
||||
grpMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// now do a comparison of grp meta types
|
||||
|
||||
if(grpMetaR.find(grpId) == grpMetaR.end())
|
||||
{
|
||||
grpMetaMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsGxsGrpMetaData *l_Meta = mit->second,
|
||||
*r_Meta = grpMetaR[grpId];
|
||||
|
||||
if(!(*l_Meta == *r_Meta))
|
||||
{
|
||||
grpMetaMatch = false;
|
||||
break;
|
||||
}
|
||||
|
||||
/* release resources */
|
||||
delete l_Meta;
|
||||
delete r_Meta;
|
||||
delete l;
|
||||
delete r;
|
||||
|
||||
remove(grpId.toStdString().c_str());
|
||||
}
|
||||
|
||||
grpMetaR.clear();
|
||||
|
||||
EXPECT_TRUE(grpMatch);
|
||||
tearDown();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Test for both selective and
|
||||
* bulk msg retrieval
|
||||
*/
|
||||
void test_messageStoresAndRetrieve()
|
||||
{
|
||||
setUp();
|
||||
|
||||
// first create a grpId
|
||||
RsGxsGroupId grpId0, grpId1;
|
||||
|
||||
grpId0.random();
|
||||
grpId1.random();
|
||||
std::vector<RsGxsGroupId> grpV; // stores grpIds of all msgs stored and retrieved
|
||||
grpV.push_back(grpId0);
|
||||
grpV.push_back(grpId1);
|
||||
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs_copy;
|
||||
RsNxsMsg* msg = NULL;
|
||||
RsGxsMsgMetaData* msgMeta = NULL;
|
||||
int nMsgs = rand()%120;
|
||||
GxsMsgReq req;
|
||||
|
||||
std::map<RsGxsMessageId, RsNxsMsg*> VergrpId0, VergrpId1;
|
||||
std::map<RsGxsMessageId, RsGxsMsgMetaData*> VerMetagrpId0, VerMetagrpId1;
|
||||
|
||||
for(int i=0; i<nMsgs; i++)
|
||||
{
|
||||
msg = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
msgMeta = new RsGxsMsgMetaData();
|
||||
init_item(*msg);
|
||||
init_item(msgMeta);
|
||||
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
|
||||
int chosen = 0;
|
||||
if(rand()%50 > 24){
|
||||
chosen = 1;
|
||||
|
||||
}
|
||||
|
||||
const RsGxsGroupId& grpId = grpV[chosen];
|
||||
|
||||
if(chosen)
|
||||
req[grpId].push_back(msg->msgId);
|
||||
|
||||
msgMeta->mMsgId = msg->msgId;
|
||||
msgMeta->mGroupId = msg->grpId = grpId;
|
||||
|
||||
RsNxsMsg* msg_copy = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
RsGxsMsgMetaData* msgMeta_copy = new RsGxsMsgMetaData();
|
||||
|
||||
*msg_copy = *msg;
|
||||
*msgMeta_copy = *msgMeta;
|
||||
|
||||
// store msgs in map to use for verification
|
||||
std::pair<RsGxsMessageId, RsNxsMsg*> vP(msg->msgId, msg_copy);
|
||||
std::pair<RsGxsMessageId, RsGxsMsgMetaData*> vPmeta(msg->msgId, msgMeta_copy);
|
||||
|
||||
if(!chosen)
|
||||
{
|
||||
VergrpId0.insert(vP);
|
||||
VerMetagrpId0.insert(vPmeta);
|
||||
}
|
||||
else
|
||||
{
|
||||
VergrpId1.insert(vP);
|
||||
VerMetagrpId0.insert(vPmeta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
msg = NULL;
|
||||
msgMeta = NULL;
|
||||
|
||||
msgs.insert(p);
|
||||
msgs_copy.insert(std::make_pair(msg_copy, msgMeta_copy));
|
||||
}
|
||||
|
||||
req[grpV[0]] = std::vector<RsGxsMessageId>(); // assign empty list for other
|
||||
|
||||
dStore->storeMessage(msgs);
|
||||
msgs.clear();
|
||||
msgs = msgs_copy;
|
||||
|
||||
// now retrieve msgs for comparison
|
||||
// first selective retrieval
|
||||
|
||||
GxsMsgResult msgResult;
|
||||
GxsMsgMetaResult msgMetaResult;
|
||||
dStore->retrieveNxsMsgs(req, msgResult, false);
|
||||
|
||||
dStore->retrieveGxsMsgMetaData(req, msgMetaResult);
|
||||
|
||||
// now look at result for grpId 1
|
||||
std::vector<RsNxsMsg*>& result0 = msgResult[grpId0];
|
||||
std::vector<RsNxsMsg*>& result1 = msgResult[grpId1];
|
||||
std::vector<RsGxsMsgMetaData*>& resultMeta0 = msgMetaResult[grpId0];
|
||||
std::vector<RsGxsMsgMetaData*>& resultMeta1 = msgMetaResult[grpId1];
|
||||
|
||||
|
||||
|
||||
bool msgGrpId0_Match = true, msgGrpId1_Match = true;
|
||||
bool msgMetaGrpId0_Match = true, msgMetaGrpId1_Match = true;
|
||||
|
||||
// MSG test, selective retrieval
|
||||
for(std::vector<RsNxsMsg*>::size_type i = 0; i < result0.size(); i++)
|
||||
{
|
||||
RsNxsMsg* l = result0[i] ;
|
||||
|
||||
if(VergrpId0.find(l->msgId) == VergrpId0.end())
|
||||
{
|
||||
msgGrpId0_Match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsNxsMsg* r = VergrpId0[l->msgId];
|
||||
r->transactionNumber = l->transactionNumber;
|
||||
|
||||
if(!(*l == *r))
|
||||
{
|
||||
msgGrpId0_Match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(msgGrpId0_Match);
|
||||
|
||||
// META test
|
||||
for(std::vector<RsGxsMsgMetaData*>::size_type i = 0; i < resultMeta0.size(); i++)
|
||||
{
|
||||
RsGxsMsgMetaData* l = resultMeta0[i] ;
|
||||
|
||||
if(VerMetagrpId0.find(l->mMsgId) == VerMetagrpId0.end())
|
||||
{
|
||||
msgMetaGrpId0_Match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsGxsMsgMetaData* r = VerMetagrpId0[l->mMsgId];
|
||||
|
||||
if(!(*l == *r))
|
||||
{
|
||||
msgMetaGrpId0_Match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(msgMetaGrpId0_Match);
|
||||
|
||||
// MSG test, bulk retrieval
|
||||
for(std::vector<RsNxsMsg*>::size_type i = 0; i < result1.size(); i++)
|
||||
{
|
||||
RsNxsMsg* l = result1[i] ;
|
||||
|
||||
if(VergrpId1.find(l->msgId) == VergrpId1.end())
|
||||
{
|
||||
msgGrpId1_Match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
RsNxsMsg* r = VergrpId1[l->msgId];
|
||||
|
||||
r->transactionNumber = l->transactionNumber;
|
||||
|
||||
if(!(*l == *r))
|
||||
{
|
||||
msgGrpId1_Match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(msgGrpId1_Match);
|
||||
|
||||
//dStore->retrieveGxsMsgMetaData();
|
||||
std::string msgFile = grpId0.toStdString() + "-msgs";
|
||||
remove(msgFile.c_str());
|
||||
msgFile = grpId1.toStdString() + "-msgs";
|
||||
remove(msgFile.c_str());
|
||||
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: ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef RSDATASERVICE_TEST_H
|
||||
#define RSDATASERVICE_TEST_H
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "gxs/rsgds.h"
|
||||
|
||||
void test_messageStoresAndRetrieve();
|
||||
|
||||
void test_groupStoreAndRetrieve();
|
||||
|
||||
void test_storeAndDeleteGroup();
|
||||
void test_storeAndDeleteMessage();
|
||||
|
||||
void test_searchMsg();
|
||||
void test_searchGrp();
|
||||
|
||||
bool operator ==(const RsGxsGrpMetaData& l, const RsGxsGrpMetaData& r);
|
||||
bool operator ==(const RsGxsMsgMetaData& l, const RsGxsMsgMetaData& r);
|
||||
|
||||
void test_multiThreaded();
|
||||
|
||||
class DataReadWrite : RsThread
|
||||
{
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
void test_cacheSize();
|
||||
|
||||
|
||||
#endif // RSDATASERVICE_TEST_H
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "libretroshare/serialiser/support.h"
|
||||
#include "libretroshare/gxs/common/data_support.h"
|
||||
#include "gxs/rsgxsdata.h"
|
||||
|
||||
TEST(libretroshare_gxs, RsGxsData)
|
||||
{
|
||||
|
||||
RsGxsGrpMetaData grpMeta1, grpMeta2;
|
||||
RsGxsMsgMetaData msgMeta1, msgMeta2;
|
||||
|
||||
grpMeta1.clear();
|
||||
init_item(&grpMeta1);
|
||||
|
||||
msgMeta1.clear();
|
||||
init_item(&msgMeta1);
|
||||
|
||||
uint32_t pktsize = grpMeta1.serial_size();
|
||||
char grp_data[pktsize];
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= grpMeta1.serialise(grp_data, pktsize);
|
||||
grpMeta2.clear();
|
||||
ok &= grpMeta2.deserialise(grp_data, pktsize);
|
||||
|
||||
EXPECT_TRUE(grpMeta1 == grpMeta2);
|
||||
|
||||
pktsize = msgMeta1.serial_size();
|
||||
char msg_data[pktsize];
|
||||
|
||||
ok &= msgMeta1.serialise(msg_data, &pktsize);
|
||||
msgMeta2.clear();
|
||||
ok &= msgMeta2.deserialise(msg_data, &pktsize);
|
||||
|
||||
EXPECT_TRUE(msgMeta1 == msgMeta2);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,180 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-05-06T09:19:26
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
|
||||
#
|
||||
QT += core network
|
||||
|
||||
QT -= gui
|
||||
|
||||
CONFIG += gen_exchange_target
|
||||
|
||||
|
||||
CONFIG += bitdht
|
||||
|
||||
|
||||
|
||||
TARGET = gen_exchange_test
|
||||
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
CONFIG += debug
|
||||
|
||||
debug {
|
||||
# DEFINES *= DEBUG
|
||||
# DEFINES *= OPENDHT_DEBUG DHT_DEBUG CONN_DEBUG DEBUG_UDP_SORTER P3DISC_DEBUG DEBUG_UDP_LAYER FT_DEBUG EXTADDRSEARCH_DEBUG
|
||||
# DEFINES *= CONTROL_DEBUG FT_DEBUG DEBUG_FTCHUNK P3TURTLE_DEBUG
|
||||
# DEFINES *= P3TURTLE_DEBUG
|
||||
# DEFINES *= NET_DEBUG
|
||||
# DEFINES *= DISTRIB_DEBUG
|
||||
# DEFINES *= P3TURTLE_DEBUG FT_DEBUG DEBUG_FTCHUNK MPLEX_DEBUG
|
||||
# DEFINES *= STATUS_DEBUG SERV_DEBUG RSSERIAL_DEBUG #CONN_DEBUG
|
||||
|
||||
QMAKE_CXXFLAGS -= -O2 -fomit-frame-pointer
|
||||
QMAKE_CXXFLAGS *= -g -fno-omit-frame-pointer
|
||||
}
|
||||
################################# Linux ##########################################
|
||||
# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib
|
||||
linux-* {
|
||||
#CONFIG += version_detail_bash_script
|
||||
QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64
|
||||
|
||||
system(which gpgme-config >/dev/null 2>&1) {
|
||||
INCLUDEPATH += $$system(gpgme-config --cflags | sed -e "s/-I//g")
|
||||
} else {
|
||||
message(Could not find gpgme-config on your system, assuming gpgme.h is in /usr/include)
|
||||
}
|
||||
|
||||
PRE_TARGETDEPS *= ../../../lib/libretroshare.a
|
||||
|
||||
LIBS += ../../../lib/libretroshare.a
|
||||
LIBS += ../../../../../libbitdht/src/lib/libbitdht.a
|
||||
LIBS += ../../../../../openpgpsdk/src/lib/libops.a
|
||||
LIBS += -lssl -lgpgme -lupnp -lixml -lgnome-keyring -lbz2
|
||||
# We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database.
|
||||
LIBS += /home/crispy/Development/retroshare/sqlcipher/sqlcipher/.libs/libsqlite3.a
|
||||
LIBS *= -rdynamic -frtti
|
||||
DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions
|
||||
DEFINES *= UBUNTU
|
||||
}
|
||||
|
||||
linux-g++ {
|
||||
OBJECTS_DIR = temp/linux-g++/obj
|
||||
}
|
||||
|
||||
linux-g++-64 {
|
||||
OBJECTS_DIR = temp/linux-g++-64/obj
|
||||
}
|
||||
|
||||
#################################### Windows #####################################
|
||||
|
||||
win32 {
|
||||
|
||||
DEFINES *= WINDOWS_SYS \
|
||||
WIN32 \
|
||||
STATICLIB \
|
||||
MINGW
|
||||
# Switch on extra warnings
|
||||
QMAKE_CFLAGS += -Wextra
|
||||
QMAKE_CXXFLAGS += -Wextra
|
||||
|
||||
# Switch off optimization for release version
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE += -O0
|
||||
QMAKE_CFLAGS_RELEASE -= -O2
|
||||
QMAKE_CFLAGS_RELEASE += -O0
|
||||
|
||||
# Switch on optimization for debug version
|
||||
#QMAKE_CXXFLAGS_DEBUG += -O2
|
||||
#QMAKE_CFLAGS_DEBUG += -O2
|
||||
|
||||
# PRE_TARGETDEPS += ../../libretroshare/src/lib/libretroshare.a
|
||||
PRE_TARGETDEPS += ../../../../../libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
|
||||
LIBS += ../../../../../libretroshare/libretroshare-build-desktop/lib/libretroshare.a
|
||||
LIBS += C:\Development\Rs\v0.5-gxs-b1\openpgpsdk\openpgpsdk-build-desktop\lib\libops.a
|
||||
LIBS += C:\Development\Libraries\sqlite\sqlite-autoconf-3070900\lib\libsqlite3.a
|
||||
LIBS += -L"../../../../../lib"
|
||||
LIBS += -lssl -lcrypto -lgpgme -lpthreadGC2d -lminiupnpc -lz -lbz2
|
||||
# added after bitdht
|
||||
# LIBS += -lws2_32
|
||||
LIBS += -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lgdi32
|
||||
LIBS += -lole32 -lwinmm
|
||||
|
||||
# export symbols for the plugins
|
||||
#LIBS += -Wl,--export-all-symbols,--out-implib,lib/libretroshare-gui.a
|
||||
|
||||
GPG_ERROR_DIR = ../../../../libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../gpgme-1.1.8
|
||||
GPG_ERROR_DIR = ../../../../lib/libgpg-error-1.7
|
||||
GPGME_DIR = ../../../../lib/gpgme-1.1.8
|
||||
SSL_DIR = ../../../../../OpenSSL
|
||||
OPENPGPSDK_DIR = ../../../../openpgpsdk/src
|
||||
INCLUDEPATH += . $${SSL_DIR}/include $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src \
|
||||
$${OPENPGPSDK_DIR}
|
||||
|
||||
SQLITE_DIR = ../../../../../../Libraries/sqlite/sqlite-autoconf-3070900
|
||||
INCLUDEPATH += . \
|
||||
$${SQLITE_DIR}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
bitdht {
|
||||
|
||||
# Chris version.
|
||||
#LIBS += ../../libbitdht/libbitdht-build-desktop/lib/libbitdht.a
|
||||
#PRE_TARGETDEPS *= ../../libbitdht/libbitdht-build-desktop/lib/libbitdht.a
|
||||
}
|
||||
|
||||
win32 {
|
||||
# must be added after bitdht
|
||||
LIBS += -lws2_32
|
||||
}
|
||||
|
||||
version_detail_bash_script {
|
||||
DEFINES += ADD_LIBRETROSHARE_VERSION_INFO
|
||||
QMAKE_EXTRA_TARGETS += write_version_detail
|
||||
PRE_TARGETDEPS = write_version_detail
|
||||
write_version_detail.commands = ./version_detail.sh
|
||||
}
|
||||
|
||||
install_rs {
|
||||
INSTALLS += binary_rs
|
||||
binary_rs.path = $$(PREFIX)/usr/bin
|
||||
binary_rs.files = ./RetroShare
|
||||
}
|
||||
|
||||
|
||||
gen_exchange_target {
|
||||
|
||||
SOURCES += \
|
||||
../common/support.cc \
|
||||
genexchangetester.cpp \
|
||||
genexchangetestservice.cpp \
|
||||
rsdummyservices.cc \
|
||||
gxspublishgrouptest.cc \
|
||||
gxspublishmsgtest.cc \
|
||||
rsgenexchange_test.cc
|
||||
|
||||
HEADERS += ../common/support.h \
|
||||
../data_service/rsdataservice_test.h \
|
||||
gxspublishgrouptest.h \
|
||||
gxspublishmsgtest.h \
|
||||
rsdummyservices.h \
|
||||
../common/data_support.h \
|
||||
../common/support.h
|
||||
|
||||
}
|
||||
|
||||
|
||||
INCLUDEPATH += ../../../
|
||||
INCLUDEPATH += ../common
|
|
@ -0,0 +1,592 @@
|
|||
|
||||
|
||||
|
||||
#include "genexchangetester.h"
|
||||
#include "libretroshare/serialiser/support.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
|
||||
|
||||
GenExchangeTest::GenExchangeTest(GenExchangeTestService* const mTestService, RsGeneralDataService* dataService, int pollingTO)
|
||||
: mDataService(dataService), mTestService(mTestService), mTokenService(mTestService->getTokenService()),
|
||||
mPollingTO(pollingTO)
|
||||
{
|
||||
}
|
||||
|
||||
GenExchangeTest::~GenExchangeTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::pollForToken(uint32_t token, const RsTokReqOptions &opts, bool fill)
|
||||
{
|
||||
double timeDelta = 0.2;
|
||||
time_t now = time(NULL);
|
||||
time_t stopw = now + mPollingTO;
|
||||
|
||||
while(now < stopw)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
if((RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE == mTokenService->requestStatus(token)))
|
||||
{
|
||||
switch(opts.mReqType)
|
||||
{
|
||||
case GXS_REQUEST_TYPE_GROUP_DATA:
|
||||
if(fill)
|
||||
mTestService->getGroupDataTS(token, mGrpDataIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_GROUP_META:
|
||||
if(fill)
|
||||
mTestService->getGroupMetaTS(token, mGrpMetaDataIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_GROUP_IDS:
|
||||
if(fill)
|
||||
mTestService->getGroupListTS(token, mGrpIdsIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_DATA:
|
||||
if(fill)
|
||||
mTestService->getMsgDataTS(token, mMsgDataIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_META:
|
||||
if(fill)
|
||||
mTestService->getMsgMetaTS(token, mMsgMetaDataIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_IDS:
|
||||
if(fill)
|
||||
mTestService->getMsgListTS(token, mMsgIdsIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_RELATED_IDS:
|
||||
if(fill)
|
||||
mTestService->getMsgRelatedListTS(token, mMsgRelatedIdsIn);
|
||||
break;
|
||||
case GXS_REQUEST_TYPE_MSG_RELATED_DATA:
|
||||
if(fill)
|
||||
mTestService->getMsgRelatedDataTS(token, mMsgRelatedDataMapIn);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED == mTokenService->requestStatus(token))
|
||||
{
|
||||
mTokenService->cancelRequest(token);
|
||||
break;
|
||||
}
|
||||
now = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool GenExchangeTest::pollForMsgAcknowledgement(uint32_t token,
|
||||
RsGxsGrpMsgIdPair& msgId)
|
||||
{
|
||||
double timeDelta = 0.2;
|
||||
|
||||
time_t now = time(NULL);
|
||||
time_t stopw = now + mPollingTO;
|
||||
|
||||
while(now < stopw)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
if((RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE == mTokenService->requestStatus(token)))
|
||||
{
|
||||
mTestService->acknowledgeTokenMsg(token, msgId);
|
||||
return true;
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED == mTokenService->requestStatus(token))
|
||||
{
|
||||
mTokenService->cancelRequest(token);
|
||||
return false;
|
||||
}
|
||||
now = time(NULL);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
GenExchangeTestService* GenExchangeTest::getTestService()
|
||||
{
|
||||
return mTestService;
|
||||
}
|
||||
|
||||
RsTokenService* GenExchangeTest::getTokenService()
|
||||
{
|
||||
return mTokenService;
|
||||
}
|
||||
bool GenExchangeTest::pollForGrpAcknowledgement(uint32_t token,
|
||||
RsGxsGroupId& grpId)
|
||||
{
|
||||
double timeDelta = 0.2;
|
||||
time_t now = time(NULL);
|
||||
time_t stopw = now + mPollingTO;
|
||||
while(now < stopw)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
if((RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE == mTokenService->requestStatus(token)))
|
||||
{
|
||||
mTestService->acknowledgeTokenGrp(token, grpId);
|
||||
return true;
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED == mTokenService->requestStatus(token))
|
||||
{
|
||||
mTokenService->cancelRequest(token);
|
||||
return false;
|
||||
}
|
||||
now = time(NULL);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GenExchangeTest::setUp()
|
||||
{
|
||||
mDataService->resetDataStore();
|
||||
|
||||
// would be useful for genexchange services
|
||||
// to have a protected reset button
|
||||
mTestService->start();
|
||||
}
|
||||
|
||||
void GenExchangeTest::breakDown()
|
||||
{
|
||||
mDataService->resetDataStore();
|
||||
mTestService->join();
|
||||
clearAllData();
|
||||
}
|
||||
|
||||
bool msgDataSort(const RsDummyMsg* m1, const RsDummyMsg* m2)
|
||||
{
|
||||
return m1->meta.mMsgId < m2->meta.mMsgId;
|
||||
}
|
||||
|
||||
bool GenExchangeTest::compareMsgDataMaps()
|
||||
{
|
||||
DummyMsgMap::iterator mit = mMsgDataOut.begin();
|
||||
|
||||
bool ok = true;
|
||||
for(; mit != mMsgDataOut.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
std::vector<RsDummyMsg*>& v1 = mit->second,
|
||||
&v2 = mMsgDataIn[grpId];
|
||||
|
||||
if(v1.size() != v2.size())
|
||||
return false;
|
||||
|
||||
std::sort(v1.begin(), v1.end(), msgDataSort);
|
||||
std::sort(v2.begin(), v2.end(), msgDataSort);
|
||||
|
||||
ok &= Comparison<std::vector<RsDummyMsg*>, RsDummyMsg*>::comparison(v1, v2);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareMsgIdMaps()
|
||||
{
|
||||
GxsMsgIdResult::const_iterator mit = mMsgIdsOut.begin();
|
||||
bool ok = true;
|
||||
for(; mit != mMsgIdsOut.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
const std::vector<RsGxsMessageId>& v1 = mit->second,
|
||||
&v2 = mMsgIdsIn[grpId];
|
||||
|
||||
ok &= Comparison<std::vector<RsGxsMessageId>, RsGxsMessageId>::comparison(v1, v2);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareMsgMetaMaps()
|
||||
{
|
||||
GxsMsgMetaMap::iterator mit = mMsgMetaDataOut.begin();
|
||||
bool ok = true;
|
||||
for(; mit != mMsgMetaDataOut.end(); mit++)
|
||||
{
|
||||
const RsGxsGroupId& grpId = mit->first;
|
||||
const std::vector<RsMsgMetaData>& v1 = mit->second,
|
||||
&v2 = mMsgMetaDataOut[grpId];
|
||||
ok &= Comparison<std::vector<RsMsgMetaData>, RsMsgMetaData>::comparison(v1, v2);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareMsgRelateIdsMap()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareMsgRelatedDataMap()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool grpDataSort(const RsDummyGrp* g1, const RsDummyGrp* g2)
|
||||
{
|
||||
return g1->meta.mGroupId < g2->meta.mGroupId;
|
||||
}
|
||||
|
||||
bool GenExchangeTest::compareGrpData()
|
||||
{
|
||||
|
||||
std::sort(mGrpDataIn.begin(), mGrpDataIn.end(), grpDataSort);
|
||||
std::sort(mGrpDataOut.begin(), mGrpDataOut.end(), grpDataSort);
|
||||
bool ok = Comparison<std::vector<RsDummyGrp*>, RsDummyGrp*>::comparison
|
||||
(mGrpDataIn, mGrpDataOut);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool operator<(const RsGroupMetaData& l, const RsGroupMetaData& r)
|
||||
{
|
||||
return l.mGroupId < r.mGroupId;
|
||||
}
|
||||
|
||||
bool GenExchangeTest::compareGrpMeta()
|
||||
{
|
||||
|
||||
mGrpMetaDataIn.sort();
|
||||
mGrpMetaDataOut.sort();
|
||||
|
||||
bool ok = Comparison<std::list<RsGroupMetaData>, RsGroupMetaData>::comparison
|
||||
(mGrpMetaDataIn, mGrpMetaDataOut);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool GenExchangeTest::compareGrpIds()
|
||||
{
|
||||
mGrpIdsIn.sort();
|
||||
mGrpIdsOut.sort();
|
||||
bool ok = Comparison<std::list<RsGxsGroupId>, RsGxsGroupId>::comparison
|
||||
(mGrpIdsIn, mGrpIdsOut);
|
||||
return ok;
|
||||
}
|
||||
|
||||
void GenExchangeTest::createGrps(uint32_t nGrps,
|
||||
std::list<RsGxsGroupId>& groupId)
|
||||
{
|
||||
// create n groups and publish all nGrps and collect id information
|
||||
for(uint32_t i=0; i < nGrps; i++)
|
||||
{
|
||||
RsDummyGrp* grp = new RsDummyGrp();
|
||||
init(*grp);
|
||||
uint32_t token;
|
||||
mTestService->publishDummyGrp(token, grp);
|
||||
RsGxsGroupId grpId;
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
groupId.push_back(grpId);
|
||||
}
|
||||
}
|
||||
|
||||
void GenExchangeTest::init(RsMsgMetaData& msgMetaData) const
|
||||
{
|
||||
//randString(SHORT_STR, msgMeta.mAuthorId);
|
||||
randString(SHORT_STR, msgMetaData.mMsgName);
|
||||
randString(SHORT_STR, msgMetaData.mServiceString);
|
||||
msgMetaData.mOrigMsgId.random();
|
||||
msgMetaData.mParentId.random();
|
||||
msgMetaData.mThreadId.random();
|
||||
msgMetaData.mGroupId.random();
|
||||
|
||||
msgMetaData.mChildTs = randNum();
|
||||
msgMetaData.mMsgStatus = randNum();
|
||||
msgMetaData.mMsgFlags = randNum();
|
||||
msgMetaData.mPublishTs = randNum();
|
||||
}
|
||||
|
||||
uint32_t GenExchangeTest::randNum() const
|
||||
{
|
||||
return rand()%23562424;
|
||||
}
|
||||
|
||||
void GenExchangeTest::init(RsGroupMetaData& grpMetaData) const
|
||||
{
|
||||
grpMetaData.mGroupId.random();
|
||||
//randString(SHORT_STR, grpMetaData.mAuthorId);
|
||||
randString(SHORT_STR, grpMetaData.mGroupName);
|
||||
randString(SHORT_STR, grpMetaData.mServiceString);
|
||||
|
||||
|
||||
grpMetaData.mGroupFlags = randNum();
|
||||
grpMetaData.mLastPost = randNum();
|
||||
grpMetaData.mGroupStatus = randNum();
|
||||
grpMetaData.mMsgCount = randNum();
|
||||
grpMetaData.mPop = randNum();
|
||||
grpMetaData.mSignFlags = randNum();
|
||||
grpMetaData.mPublishTs = randNum();
|
||||
grpMetaData.mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN;
|
||||
}
|
||||
|
||||
void GenExchangeTest::init(RsDummyGrp& grpItem) const
|
||||
{
|
||||
randString(SHORT_STR, grpItem.grpData);
|
||||
init(grpItem.meta);
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::init(RsDummyMsg& msgItem) const
|
||||
{
|
||||
randString(SHORT_STR, msgItem.msgData);
|
||||
init(msgItem.meta);
|
||||
}
|
||||
|
||||
void GenExchangeTest::storeToMsgDataOutMaps(const DummyMsgMap& msgDataOut)
|
||||
{
|
||||
mMsgDataOut.insert(msgDataOut.begin(), msgDataOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgIdsOutMaps(const GxsMsgIdResult& msgIdsOut)
|
||||
{
|
||||
mMsgIdsOut.insert(msgIdsOut.begin(), msgIdsOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgMetaOutMaps(const GxsMsgMetaMap& msgMetaOut)
|
||||
{
|
||||
mMsgMetaDataOut.insert(msgMetaOut.begin(), msgMetaOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgDataInMaps(const DummyMsgMap& msgDataIn)
|
||||
{
|
||||
mMsgDataIn.insert(msgDataIn.begin(), msgDataIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgIdsInMaps(const GxsMsgIdResult& msgIdsIn)
|
||||
{
|
||||
mMsgIdsIn.insert(msgIdsIn.begin(), msgIdsIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToMsgMetaInMaps(const GxsMsgMetaMap& msgMetaIn)
|
||||
{
|
||||
mMsgMetaDataIn.insert(msgMetaIn.begin(), msgMetaIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpIdsOutList(
|
||||
const std::list<RsGxsGroupId>& grpIdOut)
|
||||
{
|
||||
mGrpIdsOut.insert(mGrpIdsOut.end(), grpIdOut.begin(), grpIdOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpMetaOutList(
|
||||
const std::list<RsGroupMetaData>& grpMetaOut)
|
||||
{
|
||||
mGrpMetaDataOut.insert(mGrpMetaDataOut.end(), grpMetaOut.begin(), grpMetaOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpDataOutList(
|
||||
const std::vector<RsDummyGrp*>& grpDataOut)
|
||||
{
|
||||
mGrpDataOut.insert(mGrpDataOut.end(), grpDataOut.begin(), grpDataOut.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpIdsInList(
|
||||
const std::list<RsGxsGroupId>& grpIdIn)
|
||||
{
|
||||
mGrpIdsIn.insert(mGrpIdsIn.end(), grpIdIn.begin(), grpIdIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpMetaInList(
|
||||
const std::list<RsGroupMetaData>& grpMetaIn)
|
||||
{
|
||||
mGrpMetaDataIn.insert(mGrpMetaDataIn.end(), grpMetaIn.begin(), grpMetaIn.end());
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::storeToGrpDataInList(
|
||||
const std::vector<RsDummyGrp*>& grpDataIn)
|
||||
{
|
||||
mGrpDataIn.insert(mGrpDataIn.begin(), grpDataIn.begin(), grpDataIn.end());
|
||||
}
|
||||
void GenExchangeTest::clearAllData()
|
||||
{
|
||||
clearMsgDataInMap();
|
||||
clearMsgDataOutMap();
|
||||
clearMsgIdInMap();
|
||||
clearMsgIdOutMap();
|
||||
clearMsgMetaInMap();
|
||||
clearMsgMetaOutMap();
|
||||
clearGrpDataInList();
|
||||
clearGrpDataOutList();
|
||||
clearGrpMetaInList();
|
||||
clearGrpMetaOutList();
|
||||
clearGrpIdInList();
|
||||
clearGrpIdOutList();
|
||||
}
|
||||
void GenExchangeTest::clearMsgDataInMap()
|
||||
{
|
||||
mMsgDataIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgDataOutMap()
|
||||
{
|
||||
|
||||
clearMsgDataMap(mMsgDataOut);
|
||||
}
|
||||
|
||||
void GenExchangeTest::clearMsgDataMap(DummyMsgMap& msgDataMap) const
|
||||
{
|
||||
DummyMsgMap::iterator it = msgDataMap.begin();
|
||||
|
||||
for(; it != msgDataMap.end(); it++)
|
||||
{
|
||||
deleteResVector<RsDummyMsg>(it->second);
|
||||
}
|
||||
}
|
||||
|
||||
void GenExchangeTest::clearMsgMetaInMap()
|
||||
{
|
||||
mMsgMetaDataIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgMetaOutMap()
|
||||
{
|
||||
mMsgMetaDataOut.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgIdInMap()
|
||||
{
|
||||
mMsgIdsIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgIdOutMap()
|
||||
{
|
||||
mMsgIdsOut.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearMsgRelatedIdInMap()
|
||||
{
|
||||
mMsgRelatedIdsIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpDataInList()
|
||||
{
|
||||
clearGrpDataList(mGrpDataIn);
|
||||
}
|
||||
|
||||
void GenExchangeTest::clearGrpDataList(std::vector<RsDummyGrp*>& grpData) const
|
||||
{
|
||||
deleteResVector<RsDummyGrp>(grpData);
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpDataOutList()
|
||||
{
|
||||
clearGrpDataList(mGrpDataOut);
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpMetaInList()
|
||||
{
|
||||
mGrpMetaDataIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpMetaOutList()
|
||||
{
|
||||
mGrpMetaDataOut.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpIdInList()
|
||||
{
|
||||
mGrpIdsIn.clear();
|
||||
}
|
||||
|
||||
|
||||
void GenExchangeTest::clearGrpIdOutList()
|
||||
{
|
||||
mGrpIdsOut.clear();
|
||||
}
|
||||
|
||||
|
||||
bool operator ==(const RsMsgMetaData& lMeta, const RsMsgMetaData& rMeta)
|
||||
{
|
||||
|
||||
if(lMeta.mAuthorId != rMeta.mAuthorId) return false;
|
||||
if(lMeta.mChildTs != rMeta.mChildTs) return false;
|
||||
if(lMeta.mGroupId != rMeta.mGroupId) return false;
|
||||
if(lMeta.mMsgFlags != rMeta.mMsgFlags) return false;
|
||||
if(lMeta.mMsgId != rMeta.mMsgId) return false;
|
||||
if(lMeta.mMsgName != rMeta.mMsgName) return false;
|
||||
//if(lMeta.mMsgStatus != rMeta.mMsgStatus) return false;
|
||||
if(lMeta.mOrigMsgId != rMeta.mOrigMsgId) return false;
|
||||
if(lMeta.mParentId != rMeta.mParentId) return false;
|
||||
//if(lMeta.mPublishTs != rMeta.mPublishTs) return false; // don't compare this as internally set in gxs
|
||||
if(lMeta.mThreadId != rMeta.mThreadId) return false;
|
||||
if(lMeta.mServiceString != rMeta.mServiceString) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGroupMetaData& lMeta, const RsGroupMetaData& rMeta)
|
||||
{
|
||||
if(lMeta.mAuthorId != rMeta.mAuthorId) return false;
|
||||
if(lMeta.mGroupFlags != rMeta.mGroupFlags) return false;
|
||||
if(lMeta.mGroupId != rMeta.mGroupId) return false;
|
||||
if(lMeta.mGroupName != rMeta.mGroupName) return false;
|
||||
if(lMeta.mGroupStatus != rMeta.mGroupStatus) return false;
|
||||
if(lMeta.mLastPost != rMeta.mLastPost) return false;
|
||||
if(lMeta.mMsgCount != rMeta.mMsgCount) return false;
|
||||
if(lMeta.mPop != rMeta.mPop) return false;
|
||||
// if(lMeta.mPublishTs != rMeta.mPublishTs) return false; set in gxs
|
||||
if(lMeta.mServiceString != rMeta.mServiceString) return false;
|
||||
if(lMeta.mSignFlags != rMeta.mSignFlags) return false;
|
||||
// if(lMeta.mSubscribeFlags != rMeta.mSubscribeFlags) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsDummyGrp& lGrp, const RsDummyGrp& rGrp)
|
||||
{
|
||||
|
||||
if(lGrp.grpData != rGrp.grpData) return false;
|
||||
if(! (lGrp.meta == rGrp.meta)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsDummyMsg& lMsg, const RsDummyMsg& rMsg)
|
||||
{
|
||||
if(lMsg.msgData != rMsg.msgData) return false;
|
||||
if(!(lMsg.meta == rMsg.meta)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsGrpItem& lGrp, const RsGxsGrpItem& rGrp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
#ifndef GENEXCHANGETESTER_H
|
||||
#define GENEXCHANGETESTER_H
|
||||
|
||||
#include "genexchangetestservice.h"
|
||||
#include "gxs/rsgds.h"
|
||||
#include "gxs/rsnxs.h"
|
||||
|
||||
bool operator ==(const RsMsgMetaData& lMeta, const RsMsgMetaData& rMeta);
|
||||
bool operator ==(const RsDummyMsg& lMsg, const RsDummyMsg& rMsg);
|
||||
bool operator ==(const RsGxsGrpItem& lMsg, const RsGxsGrpItem& rMsg);
|
||||
|
||||
bool operator ==(const RsGroupMetaData& lMeta, const RsGroupMetaData& rMeta);
|
||||
bool operator ==(const RsDummyGrp& lMsg, const RsDummyGrp& rMsg);
|
||||
bool operator ==(const RsGxsMsgItem& lMsg, const RsGxsMsgItem& rMsg);
|
||||
|
||||
/*!
|
||||
* The idea of GenExchangeTest is to simplify test
|
||||
* of the RsGenExchange via the RsGxsDummyService
|
||||
* One can test all publish/request/meta-modify
|
||||
* capabilities of RsGenExchange
|
||||
* Simplifications comes from: \n
|
||||
*
|
||||
* - ability to store in and out data for comparison (in data are
|
||||
* usually from requests, out data are from publications,
|
||||
* but generally what you want to compare) \n
|
||||
* - convenience function to poll tokens \n
|
||||
* - also allows filling in-data automatically from polls \n
|
||||
* - convenience interface for running tests
|
||||
*/
|
||||
class GenExchangeTest
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Constructs the GenExchangeTest with a tokenService
|
||||
* @param tokenService This is needed. If not an instance of token service,
|
||||
* behaviour of GenExchangeTest is undefined
|
||||
*/
|
||||
GenExchangeTest(GenExchangeTestService* const mTestService, RsGeneralDataService* dataService, int pollingTO = 5 /* 5 secs default */);
|
||||
|
||||
virtual ~GenExchangeTest();
|
||||
|
||||
/*!
|
||||
* This should be called in the main
|
||||
* routines to execute all tests
|
||||
* When implementing ensure units test header
|
||||
* is in same file scope as implementation
|
||||
* (you chould be using the CHECK functions
|
||||
* to assert tests has passed)
|
||||
*/
|
||||
virtual void runTests() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/*!
|
||||
* After each request and publish operation this should
|
||||
* be called to ensure the operation has completed
|
||||
* Requests will result in in data maps being filled
|
||||
* @param
|
||||
* @param opts
|
||||
* @param fill if set to true, the received that is
|
||||
* routed to IN data structures
|
||||
*/
|
||||
void pollForToken(uint32_t token, const RsTokReqOptions& opts, bool fill = false);
|
||||
|
||||
/*!
|
||||
* Allows to poll for token, and receive the message id
|
||||
* as acknowledgement. This function blocks for as long the
|
||||
* timeout value set on construction of tester
|
||||
* @param token
|
||||
* @param msgId
|
||||
*/
|
||||
bool pollForMsgAcknowledgement(uint32_t token, RsGxsGrpMsgIdPair& msgId);
|
||||
|
||||
/*!
|
||||
* Allows to poll for token, and receive the group id
|
||||
* as acknowledgement. This function blocks for as long the
|
||||
* timeout value set on construction of tester
|
||||
* @param token
|
||||
* @param msgId
|
||||
*/
|
||||
bool pollForGrpAcknowledgement(uint32_t token, RsGxsGroupId& msgId);
|
||||
|
||||
GenExchangeTestService* getTestService();
|
||||
RsTokenService* getTokenService();
|
||||
// bool testGrpMetaModRequest();
|
||||
// bool testMsgMetaModRequest();
|
||||
|
||||
// convenience functions for clearing IN and OUT data structures
|
||||
void clearMsgDataInMap();
|
||||
void clearMsgDataOutMap();
|
||||
void clearMsgMetaInMap();
|
||||
void clearMsgMetaOutMap();
|
||||
void clearMsgIdInMap();
|
||||
void clearMsgIdOutMap();
|
||||
void clearMsgRelatedIdInMap();
|
||||
void clearGrpDataInList();
|
||||
void clearGrpDataOutList();
|
||||
void clearGrpMetaInList();
|
||||
void clearGrpMetaOutList();
|
||||
void clearGrpIdInList();
|
||||
void clearGrpIdOutList();
|
||||
|
||||
/*!
|
||||
* clears up all internal
|
||||
* IN and OUT data structure for
|
||||
* both msgs and groups
|
||||
* frees resources in relation to allocated data
|
||||
*/
|
||||
void clearAllData();
|
||||
|
||||
template <class Item>
|
||||
void deleteResVector(std::vector<Item*>& v) const
|
||||
{
|
||||
typename std::vector<Item*>::iterator vit = v.begin();
|
||||
for(; vit != v.end(); vit++)
|
||||
delete *vit;
|
||||
v.clear();
|
||||
}
|
||||
|
||||
// using class to enable partial
|
||||
// function specialisation, bit of a hack in a
|
||||
// way
|
||||
template <class Cont, class Item>
|
||||
class Comparison
|
||||
{
|
||||
public:
|
||||
|
||||
static bool comparison(const Cont& l, const Cont& r)
|
||||
{
|
||||
if(l.size() != r.size()) return false;
|
||||
|
||||
typename Cont::const_iterator vit1 = l.begin(), vit2 = r.begin();
|
||||
|
||||
while(vit1 != l.end())
|
||||
{
|
||||
const Item& item1 = (*vit1);
|
||||
const Item& item2 = (*vit2);
|
||||
if(!(item1 == item2)) return false;
|
||||
|
||||
vit1++;
|
||||
vit2++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class Cont, class Item>
|
||||
class Comparison<Cont, Item*>
|
||||
{
|
||||
public:
|
||||
|
||||
static bool comparison(const Cont& l, const Cont& r)
|
||||
{
|
||||
if(l.size() != r.size())
|
||||
return false;
|
||||
|
||||
typename Cont::const_iterator vit1 = l.begin(), vit2 = r.begin();
|
||||
|
||||
while(vit1 != l.end())
|
||||
{
|
||||
const Item* item1 = (*vit1);
|
||||
const Item* item2 = (*vit2);
|
||||
if(!(*item1 == *item2))
|
||||
return false;
|
||||
|
||||
vit1++;
|
||||
vit2++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// convenience function for comparing IN and OUT data structures
|
||||
bool compareMsgDataMaps() ;
|
||||
bool compareMsgIdMaps() ;
|
||||
bool compareMsgMetaMaps() ;
|
||||
bool compareMsgRelateIdsMap() ;
|
||||
bool compareMsgRelatedDataMap() ;
|
||||
bool compareGrpData() ;
|
||||
bool compareGrpMeta() ;
|
||||
bool compareGrpIds() ;
|
||||
|
||||
void storeToMsgDataOutMaps(const DummyMsgMap& msgDataOut);
|
||||
void storeToMsgIdsOutMaps(const GxsMsgIdResult& msgIdsOut);
|
||||
void storeToMsgMetaOutMaps(const GxsMsgMetaMap& msgMetaOut);
|
||||
|
||||
void storeToMsgDataInMaps(const DummyMsgMap& msgDataOut);
|
||||
void storeToMsgIdsInMaps(const GxsMsgIdResult& msgIdsOut);
|
||||
void storeToMsgMetaInMaps(const GxsMsgMetaMap& msgMetaOut);
|
||||
|
||||
void storeToGrpIdsOutList(const std::list<RsGxsGroupId>& grpIdOut);
|
||||
void storeToGrpMetaOutList(const std::list<RsGroupMetaData>& grpMetaOut);
|
||||
void storeToGrpDataOutList(const std::vector<RsDummyGrp*>& grpDataOut);
|
||||
|
||||
void storeToGrpIdsInList(const std::list<RsGxsGroupId>& grpIdIn);
|
||||
void storeToGrpMetaInList(const std::list<RsGroupMetaData>& grpMetaOut);
|
||||
void storeToGrpDataInList(const std::vector<RsDummyGrp*>& grpDataOut);
|
||||
|
||||
/*!
|
||||
* This sets up any resources required to operate a test
|
||||
*/
|
||||
void setUp();
|
||||
|
||||
/*!
|
||||
* Call at end of test to ensure resources
|
||||
* used in tests are released
|
||||
* This can invalidate other test runs if not called
|
||||
*/
|
||||
void breakDown();
|
||||
|
||||
/*!
|
||||
* initialises item to random data
|
||||
* @param grpItem item to initialise
|
||||
*/
|
||||
void init(RsDummyGrp& grpItem) const;
|
||||
|
||||
/*!
|
||||
* Initialises meta data to random data
|
||||
* @param grpMetaData
|
||||
*/
|
||||
void init(RsGroupMetaData& grpMetaData) const;
|
||||
|
||||
/*!
|
||||
* Initialises msg item to random data
|
||||
* @param msgItem
|
||||
*/
|
||||
void init(RsDummyMsg& msgItem) const;
|
||||
|
||||
/*!
|
||||
* Initialises meta data to random data
|
||||
* @param msgMetaData
|
||||
*/
|
||||
void init(RsMsgMetaData& msgMetaData) const;
|
||||
|
||||
|
||||
void clearMsgDataMap(DummyMsgMap& msgDataMap) const;
|
||||
void clearGrpDataList(std::vector<RsDummyGrp*>& grpData) const;
|
||||
|
||||
/*!
|
||||
* Helper function which sets up groups
|
||||
* data in to be used for publication
|
||||
* group data
|
||||
* @param nGrps number of groups to publish
|
||||
* @param groupId the ids for the created groups
|
||||
*/
|
||||
void createGrps(uint32_t nGrps, std::list<RsGxsGroupId>& groupId);
|
||||
|
||||
/*!
|
||||
* @return random number
|
||||
*/
|
||||
uint32_t randNum() const;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<RsDummyGrp*> mGrpDataOut, mGrpDataIn;
|
||||
std::list<RsGroupMetaData> mGrpMetaDataOut, mGrpMetaDataIn;
|
||||
std::list<RsGxsGroupId> mGrpIdsOut, mGrpIdsIn;
|
||||
|
||||
std::map<RsGxsGroupId, std::vector<RsDummyMsg*> > mMsgDataOut, mMsgDataIn;
|
||||
GxsMsgMetaMap mMsgMetaDataOut, mMsgMetaDataIn;
|
||||
GxsMsgIdResult mMsgIdsOut, mMsgIdsIn;
|
||||
|
||||
MsgRelatedIdResult mMsgRelatedIdsOut, mMsgRelatedIdsIn;
|
||||
GxsMsgRelatedDataMap mMsgRelatedDataMapOut, mMsgRelatedDataMapIn;
|
||||
|
||||
std::vector<RsGxsGroupId> mRandGrpIds; // ids that exist to help group testing
|
||||
|
||||
private:
|
||||
|
||||
RsGeneralDataService* mDataService;
|
||||
GenExchangeTestService* mTestService;
|
||||
RsTokenService* mTokenService;
|
||||
int mPollingTO;
|
||||
};
|
||||
|
||||
#endif // GENEXCHANGETESTER_H
|
|
@ -0,0 +1,105 @@
|
|||
#include "genexchangetestservice.h"
|
||||
|
||||
GenExchangeTestService::GenExchangeTestService(RsGeneralDataService *dataServ, RsNetworkExchangeService * netService,
|
||||
RsGixs* gixs)
|
||||
: RsGenExchange(dataServ, netService, new RsDummySerialiser(), RS_SERVICE_TYPE_DUMMY, gixs, 0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RsServiceInfo GenExchangeTestService::getServiceInfo()
|
||||
{
|
||||
RsServiceInfo info;
|
||||
return info;
|
||||
}
|
||||
|
||||
void GenExchangeTestService::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void GenExchangeTestService::publishDummyGrp(uint32_t &token, RsDummyGrp *grp)
|
||||
{
|
||||
publishGroup(token, grp);
|
||||
}
|
||||
|
||||
void GenExchangeTestService::updateDummyGrp(uint32_t &token, RsGxsGroupUpdateMeta &updateMeta, RsDummyGrp *group)
|
||||
{
|
||||
//updateGroup(token, updateMeta, group);
|
||||
updateGroup(token, group);
|
||||
}
|
||||
|
||||
void GenExchangeTestService::publishDummyMsg(uint32_t &token, RsDummyMsg *msg)
|
||||
{
|
||||
publishMsg(token, msg);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getGroupListTS(const uint32_t &token, std::list<RsGxsGroupId> &groupIds)
|
||||
{
|
||||
return getGroupList(token, groupIds);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getGroupMetaTS(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
|
||||
{
|
||||
return getGroupMeta(token, groupInfo);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getGroupDataTS(const uint32_t &token, std::vector<RsDummyGrp *>& grpItem)
|
||||
{
|
||||
return getGroupDataT<RsDummyGrp>(token, grpItem);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgDataTS(const uint32_t &token, DummyMsgMap &msgItems)
|
||||
{
|
||||
return getMsgDataT<RsDummyMsg>(token, msgItems);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgRelatedDataTS(const uint32_t &token, GxsMsgRelatedDataMap &msgItems)
|
||||
{
|
||||
return getMsgRelatedData(token, msgItems);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgMetaTS(const uint32_t &token, GxsMsgMetaMap &msgInfo)
|
||||
{
|
||||
return getMsgMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgListTS(const uint32_t &token, GxsMsgIdResult &msgIds)
|
||||
{
|
||||
return getMsgList(token, msgIds);
|
||||
}
|
||||
|
||||
bool GenExchangeTestService::getMsgRelatedListTS(const uint32_t &token, MsgRelatedIdResult &msgIds)
|
||||
{
|
||||
return getMsgRelatedList(token, msgIds);
|
||||
}
|
||||
|
||||
void GenExchangeTestService::setGroupServiceStringTS(uint32_t &token, const RsGxsGroupId &grpId, const std::string &servString)
|
||||
{
|
||||
RsGenExchange::setGroupServiceString(token, grpId, servString);
|
||||
}
|
||||
|
||||
void GenExchangeTestService::setGroupStatusFlagTS(uint32_t &token, const RsGxsGroupId &grpId, const uint32_t &status, const uint32_t& mask)
|
||||
{
|
||||
RsGenExchange::setGroupStatusFlags(token, grpId, status, mask);
|
||||
}
|
||||
|
||||
void GenExchangeTestService::setGroupSubscribeFlagTS(uint32_t &token, const RsGxsGroupId &grpId, const uint32_t &status, const uint32_t& mask)
|
||||
{
|
||||
RsGenExchange::setGroupSubscribeFlags(token, grpId, status, mask);
|
||||
}
|
||||
|
||||
void GenExchangeTestService::setMsgServiceStringTS(uint32_t &token, const RsGxsGrpMsgIdPair &msgId, const std::string &servString)
|
||||
{
|
||||
RsGenExchange::setMsgServiceString(token, msgId, servString);
|
||||
}
|
||||
|
||||
void GenExchangeTestService::setMsgStatusFlagTS(uint32_t &token, const RsGxsGrpMsgIdPair &msgId, const uint32_t &status, const uint32_t& mask)
|
||||
{
|
||||
RsGenExchange::setMsgStatusFlags(token, msgId, status, mask);
|
||||
}
|
||||
|
||||
void GenExchangeTestService::service_tick()
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
#ifndef GENEXCHANGETESTSERVICE_H
|
||||
#define GENEXCHANGETESTSERVICE_H
|
||||
|
||||
#include "gxs/rsgenexchange.h"
|
||||
#include "retroshare/rsgxsifacehelper.h"
|
||||
#include "rsdummyservices.h"
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsDummyMsg*> > DummyMsgMap;
|
||||
|
||||
class GenExchangeTestService : public RsGenExchange
|
||||
{
|
||||
public:
|
||||
GenExchangeTestService(RsGeneralDataService* dataServ, RsNetworkExchangeService* nxs, RsGixs* gixs);
|
||||
|
||||
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
void publishDummyGrp(uint32_t& token, RsDummyGrp* grp);
|
||||
void updateDummyGrp(uint32_t &token, RsGxsGroupUpdateMeta& meta, RsDummyGrp *group);
|
||||
void publishDummyMsg(uint32_t& token, RsDummyMsg* msg);
|
||||
|
||||
RsServiceInfo getServiceInfo();
|
||||
|
||||
/*!
|
||||
* Retrieve group list for a given token
|
||||
* @param token
|
||||
* @param groupIds
|
||||
* @return false if token cannot be redeemed, if false you may have tried to redeem when not ready
|
||||
*/
|
||||
bool getGroupListTS(const uint32_t &token, std::list<RsGxsGroupId> &groupIds);
|
||||
|
||||
/*!
|
||||
* Retrieve msg list for a given token sectioned by group Ids
|
||||
* @param token token to be redeemed
|
||||
* @param msgIds a map of grpId -> msgList (vector)
|
||||
*/
|
||||
bool getMsgListTS(const uint32_t &token, GxsMsgIdResult &msgIds);
|
||||
|
||||
|
||||
/*!
|
||||
* retrieve group meta data associated to a request token
|
||||
* @param token
|
||||
* @param groupInfo
|
||||
*/
|
||||
bool getGroupMetaTS(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
|
||||
|
||||
/*!
|
||||
* retrieves message meta data associated to a request token
|
||||
* @param token token to be redeemed
|
||||
* @param msgInfo the meta data to be retrieved for token store here
|
||||
*/
|
||||
bool getMsgMetaTS(const uint32_t &token, GxsMsgMetaMap &msgInfo);
|
||||
|
||||
/*!
|
||||
* retrieves group data associated to a request token
|
||||
* @param token token to be redeemed for grpitem retrieval
|
||||
* @param grpItem the items to be retrieved for token are stored here
|
||||
*/
|
||||
bool getGroupDataTS(const uint32_t &token, std::vector<RsDummyGrp*>& grpItem);
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* retrieves message data associated to a request token
|
||||
* @param token token to be redeemed for message item retrieval
|
||||
* @param msgItems
|
||||
*/
|
||||
bool getMsgDataTS(const uint32_t &token, DummyMsgMap& msgItems);
|
||||
|
||||
/*!
|
||||
* Retrieve msg related list for a given token sectioned by group Ids
|
||||
* @param token token to be redeemed
|
||||
* @param msgIds a map of grpMsgIdPair -> msgList (vector)
|
||||
*/
|
||||
bool getMsgRelatedListTS(const uint32_t &token, MsgRelatedIdResult &msgIds);
|
||||
|
||||
/*!
|
||||
* retrieves msg related data msgItems as a map of msg-grpID pair to vector
|
||||
* of items
|
||||
* @param token token to be redeemed
|
||||
* @param msgItems map of msg items
|
||||
*/
|
||||
bool getMsgRelatedDataTS(const uint32_t &token, GxsMsgRelatedDataMap& msgItems);
|
||||
|
||||
|
||||
void setGroupSubscribeFlagTS(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& status, const uint32_t& mask);
|
||||
|
||||
void setGroupStatusFlagTS(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& status, const uint32_t& mask);
|
||||
|
||||
void setGroupServiceStringTS(uint32_t& token, const RsGxsGroupId& grpId, const std::string& servString);
|
||||
|
||||
void setMsgStatusFlagTS(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const uint32_t& status, const uint32_t& mask);
|
||||
|
||||
void setMsgServiceStringTS(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const std::string& servString );
|
||||
|
||||
void service_tick();
|
||||
|
||||
};
|
||||
|
||||
#endif // GENEXCHANGETESTSERVICE_H
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* gxsmsgrelatedtest.cpp
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "gxsmsgrelatedtest.h"
|
||||
|
||||
GxsMsgRelatedTest::GxsMsgRelatedTest() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
GxsMsgRelatedTest::~GxsMsgRelatedTest() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* gxsmsgrelatedtest.h
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef GXSMSGRELATEDTEST_H_
|
||||
#define GXSMSGRELATEDTEST_H_
|
||||
|
||||
#include "genexchangetester.h"
|
||||
|
||||
class GxsMsgRelatedTest: public GenExchangeTest {
|
||||
public:
|
||||
GxsMsgRelatedTest();
|
||||
virtual ~GxsMsgRelatedTest();
|
||||
|
||||
// request msg related tests
|
||||
bool testMsgRelatedChildIdRetrieval();
|
||||
bool testMsgRelatedChildDataRetrieval();
|
||||
bool testMsgRelatedChildDataRetrieval_Multi();
|
||||
bool testMsgAllVersions();
|
||||
};
|
||||
|
||||
#endif /* GXSMSGRELATEDTEST_H_ */
|
|
@ -0,0 +1,301 @@
|
|||
/*
|
||||
* gxspublishgrouptest.cc
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "gxspublishgrouptest.h"
|
||||
#include "libretroshare/serialiser/support.h"
|
||||
|
||||
#define POLLING_TIME_OUT 5
|
||||
|
||||
GxsPublishGroupTest::GxsPublishGroupTest(GenExchangeTestService* const testService,
|
||||
RsGeneralDataService* dataService)
|
||||
: GenExchangeTest(testService, dataService, POLLING_TIME_OUT)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GxsPublishGroupTest::~GxsPublishGroupTest()
|
||||
{
|
||||
}
|
||||
|
||||
bool GxsPublishGroupTest::testGrpSubmissionRetrieval()
|
||||
{
|
||||
|
||||
setUp();
|
||||
|
||||
GenExchangeTestService* testService = getTestService();
|
||||
RsTokenService* tokenService = getTokenService();
|
||||
|
||||
// create some random grps to allow msg testing
|
||||
|
||||
RsDummyGrp* dgrp1 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp3 = new RsDummyGrp();
|
||||
|
||||
RsDummyGrp* dgrp1_copy = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2_copy = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp3_copy = new RsDummyGrp();
|
||||
|
||||
init(*dgrp1);
|
||||
init(*dgrp2);
|
||||
init(*dgrp3);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = 45000;
|
||||
uint32_t token;
|
||||
RsGxsGroupId grpId;
|
||||
|
||||
std::vector<RsDummyGrp*> groupsPublished;
|
||||
|
||||
*dgrp1_copy = *dgrp1;
|
||||
testService->publishDummyGrp(token, dgrp1);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp1_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp1_copy);
|
||||
|
||||
*dgrp2_copy = *dgrp2;
|
||||
testService->publishDummyGrp(token, dgrp2);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp2_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp2_copy);
|
||||
|
||||
*dgrp3_copy = *dgrp3;
|
||||
testService->publishDummyGrp(token, dgrp3);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp3_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp3_copy);
|
||||
|
||||
|
||||
storeToGrpDataOutList(groupsPublished);
|
||||
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
tokenService->requestGroupInfo(token, 0, opts);
|
||||
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
|
||||
bool ok = compareGrpData();
|
||||
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool GxsPublishGroupTest::testSpecificGrpRetrieval()
|
||||
{
|
||||
setUp();
|
||||
|
||||
GenExchangeTestService* testService = getTestService();
|
||||
RsTokenService* tokenService = getTokenService();
|
||||
|
||||
// create some random grps to allow msg testing
|
||||
|
||||
RsDummyGrp* dgrp1 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp3 = new RsDummyGrp();
|
||||
|
||||
RsDummyGrp* dgrp1_copy = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2_copy = new RsDummyGrp();
|
||||
|
||||
init(*dgrp1);
|
||||
init(*dgrp2);
|
||||
init(*dgrp3);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = 45000;
|
||||
uint32_t token;
|
||||
RsGxsGroupId grpId;
|
||||
|
||||
std::vector<RsDummyGrp*> groupsPublished;
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
|
||||
*dgrp1_copy = *dgrp1;
|
||||
testService->publishDummyGrp(token, dgrp1);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp1_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp1_copy);
|
||||
grpIds.push_back(grpId);
|
||||
|
||||
*dgrp2_copy = *dgrp2;
|
||||
testService->publishDummyGrp(token, dgrp2);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
dgrp2_copy->meta.mGroupId = grpId;
|
||||
groupsPublished.push_back(dgrp2_copy);
|
||||
grpIds.push_back(grpId);
|
||||
|
||||
|
||||
testService->publishDummyGrp(token, dgrp3);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
|
||||
|
||||
storeToGrpDataOutList(groupsPublished);
|
||||
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
|
||||
tokenService->requestGroupInfo(token, 0, opts, grpIds);
|
||||
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
|
||||
bool ok = compareGrpData();
|
||||
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool GxsPublishGroupTest::testGrpIdRetrieval()
|
||||
{
|
||||
setUp();
|
||||
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
createGrps(5, grpIds);
|
||||
storeToGrpIdsOutList(grpIds);
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
||||
uint32_t token;
|
||||
|
||||
getTokenService()->requestGroupInfo(token, 0, opts);
|
||||
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
bool ok = compareGrpIds();
|
||||
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool GxsPublishGroupTest::testUpdateGroup()
|
||||
{
|
||||
setUp();
|
||||
|
||||
GenExchangeTestService* testService = getTestService();
|
||||
RsTokenService* tokenService = getTokenService();
|
||||
|
||||
// create some random grps to allow msg testing
|
||||
|
||||
RsDummyGrp* dgrp1 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2 = new RsDummyGrp();
|
||||
|
||||
RsDummyGrp* dgrp2_copy = new RsDummyGrp();
|
||||
|
||||
init(*dgrp1);
|
||||
init(*dgrp2);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = 45000;
|
||||
uint32_t token;
|
||||
RsGxsGroupId grpId;
|
||||
|
||||
std::vector<RsDummyGrp*> groupsPublished;
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
|
||||
std::string name = dgrp1->meta.mGroupName;
|
||||
*dgrp2 = *dgrp1;
|
||||
testService->publishDummyGrp(token, dgrp1);
|
||||
bool ok = pollForGrpAcknowledgement(token, grpId);
|
||||
|
||||
grpIds.push_back(grpId);
|
||||
RsGxsGroupUpdateMeta updateMeta(grpId);
|
||||
|
||||
updateMeta.setMetaUpdate(RsGxsGroupUpdateMeta::NAME, name);
|
||||
randString(SHORT_STR, dgrp2->grpData);
|
||||
dgrp2->meta.mGroupId = grpId;
|
||||
*dgrp2_copy = *dgrp2;
|
||||
dgrp2->grpData ="ojfosfjsofjsof";
|
||||
testService->updateDummyGrp(token, updateMeta, dgrp2);
|
||||
ok &= pollForGrpAcknowledgement(token, grpId);
|
||||
|
||||
groupsPublished.push_back(dgrp2_copy);
|
||||
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
|
||||
tokenService->requestGroupInfo(token, 0, opts, grpIds);
|
||||
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
|
||||
ok &= compareGrpData();
|
||||
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
bool GxsPublishGroupTest::testGrpMetaRetrieval()
|
||||
{
|
||||
|
||||
setUp();
|
||||
|
||||
GenExchangeTestService* testService = getTestService();
|
||||
|
||||
// create some random grps to allow msg testing
|
||||
|
||||
RsDummyGrp* dgrp1 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp2 = new RsDummyGrp();
|
||||
RsDummyGrp* dgrp3 = new RsDummyGrp();
|
||||
|
||||
init(*dgrp1);
|
||||
init(*dgrp2);
|
||||
init(*dgrp3);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = 45000;
|
||||
uint32_t token;
|
||||
RsGxsGroupId grpId;
|
||||
|
||||
RsGroupMetaData meta1(dgrp1->meta);
|
||||
RsGroupMetaData meta2(dgrp2->meta);
|
||||
RsGroupMetaData meta3(dgrp3->meta);
|
||||
|
||||
std::list<RsGroupMetaData> groupsMetaPublished;
|
||||
|
||||
testService->publishDummyGrp(token, dgrp1);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
meta1.mGroupId = grpId;
|
||||
groupsMetaPublished.push_back(meta1);
|
||||
|
||||
testService->publishDummyGrp(token, dgrp2);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
meta2.mGroupId = grpId;
|
||||
groupsMetaPublished.push_back(meta2);
|
||||
|
||||
testService->publishDummyGrp(token, dgrp3);
|
||||
pollForGrpAcknowledgement(token, grpId);
|
||||
meta3.mGroupId = grpId;
|
||||
groupsMetaPublished.push_back(meta3);
|
||||
|
||||
storeToGrpMetaOutList(groupsMetaPublished);
|
||||
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
|
||||
getTokenService()->requestGroupInfo(token, 0, opts);
|
||||
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
bool ok = compareGrpMeta();
|
||||
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
void GxsPublishGroupTest::runTests()
|
||||
{
|
||||
// CHECK(testGrpSubmissionRetrieval());
|
||||
// CHECK(testGrpIdRetrieval());
|
||||
// CHECK(testGrpMetaRetrieval());
|
||||
// CHECK(testSpecificGrpRetrieval());
|
||||
EXPECT_TRUE(testUpdateGroup());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* gxspublishgrouptest.h
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef GXSPUBLISHGROUPTEST_H_
|
||||
#define GXSPUBLISHGROUPTEST_H_
|
||||
|
||||
#include "genexchangetester.h"
|
||||
|
||||
class GxsPublishGroupTest : public GenExchangeTest {
|
||||
public:
|
||||
|
||||
GxsPublishGroupTest(GenExchangeTestService* const testService,
|
||||
RsGeneralDataService* dataService);
|
||||
virtual ~GxsPublishGroupTest();
|
||||
|
||||
void runTests();
|
||||
|
||||
private:
|
||||
|
||||
// group tests
|
||||
bool testGrpSubmissionRetrieval();
|
||||
bool testSpecificGrpRetrieval();
|
||||
bool testGrpIdRetrieval();
|
||||
bool testGrpMetaRetrieval();
|
||||
bool testUpdateGroup();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* GXSPUBLISHGROUPTEST_H_ */
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* gxspublishmsgtest.cpp
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "gxspublishmsgtest.h"
|
||||
|
||||
#define POLLING_TIME_OUT 5
|
||||
|
||||
GxsPublishMsgTest::GxsPublishMsgTest(GenExchangeTestService* const testService,
|
||||
RsGeneralDataService* dataService)
|
||||
: GenExchangeTest(testService, dataService, POLLING_TIME_OUT)
|
||||
{
|
||||
}
|
||||
|
||||
GxsPublishMsgTest::~GxsPublishMsgTest()
|
||||
{
|
||||
}
|
||||
|
||||
void GxsPublishMsgTest::runTests()
|
||||
{
|
||||
EXPECT_TRUE(testMsgSubmissionRetrieval());
|
||||
}
|
||||
|
||||
bool GxsPublishMsgTest::testMsgSubmissionRetrieval()
|
||||
{
|
||||
// start up
|
||||
setUp();
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
createGrps(4, grpIds);
|
||||
|
||||
/********************/
|
||||
|
||||
RsDummyMsg* msg = new RsDummyMsg();
|
||||
init(*msg);
|
||||
|
||||
msg->meta.mGroupId = grpIds.front();
|
||||
uint32_t token;
|
||||
RsDummyMsg* msgOut = new RsDummyMsg();
|
||||
*msgOut = *msg;
|
||||
getTestService()->publishDummyMsg(token, msg);
|
||||
|
||||
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
pollForMsgAcknowledgement(token, msgId);
|
||||
msgOut->meta.mMsgId = msgId.second;
|
||||
|
||||
DummyMsgMap msgMap;
|
||||
std::vector<RsDummyMsg*> msgV;
|
||||
msgV.push_back(msgOut);
|
||||
msgMap[msgOut->meta.mGroupId] = msgV;
|
||||
storeToMsgDataOutMaps(msgMap);
|
||||
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
|
||||
getTokenService()->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grpIds);
|
||||
|
||||
// poll again
|
||||
pollForToken(token, opts, true);
|
||||
|
||||
bool ok = compareMsgDataMaps();
|
||||
|
||||
// complete
|
||||
breakDown();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* gxspublishmsgtest.h
|
||||
*
|
||||
* Created on: 27 Apr 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef GXSPUBLISHMSGTEST_H_
|
||||
#define GXSPUBLISHMSGTEST_H_
|
||||
|
||||
#include "genexchangetester.h"
|
||||
|
||||
class GxsPublishMsgTest: public GenExchangeTest {
|
||||
public:
|
||||
GxsPublishMsgTest(GenExchangeTestService* const testService,
|
||||
RsGeneralDataService* dataService);
|
||||
virtual ~GxsPublishMsgTest();
|
||||
|
||||
void runTests();
|
||||
|
||||
// message tests
|
||||
bool testMsgSubmissionRetrieval();
|
||||
// bool testMsgIdRetrieval();
|
||||
// bool testMsgIdRetrieval_OptParents();
|
||||
// bool testMsgIdRetrieval_OptOrigMsgId();
|
||||
// bool testMsgIdRetrieval_OptLatest();
|
||||
// bool testSpecificMsgMetaRetrieval();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* GXSPUBLISHMSGTEST_H_ */
|
|
@ -0,0 +1,226 @@
|
|||
|
||||
|
||||
#include "rsdummyservices.h"
|
||||
|
||||
|
||||
uint32_t RsDummySerialiser::size(RsItem *item)
|
||||
{
|
||||
RsDummyMsg* msg;
|
||||
RsDummyGrp* grp;
|
||||
|
||||
if( (msg = dynamic_cast<RsDummyMsg*>(item)) != NULL )
|
||||
{
|
||||
return sizeDummyMsgItem(msg);
|
||||
}else if( (grp = dynamic_cast<RsDummyGrp*>(item)) != NULL )
|
||||
{
|
||||
return sizeDummyGrpItem(grp);
|
||||
}else
|
||||
{
|
||||
std::cerr << "RsDummySerialiser::size(RsItem *item) Error with dummy cast!\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool RsDummySerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsDummyMsg* msg;
|
||||
RsDummyGrp* grp;
|
||||
|
||||
if( (msg = dynamic_cast<RsDummyMsg*>(item)) != NULL )
|
||||
{
|
||||
return serialiseDummyMsgItem(msg, data, size);
|
||||
}else if( (grp = dynamic_cast<RsDummyGrp*>(item)) != NULL )
|
||||
{
|
||||
return serialiseDummyGrpItem(grp, data, size);
|
||||
}else
|
||||
{
|
||||
std::cerr << "RsDummySerialiser::size(RsItem *item) Error with dummy cast!\n";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsDummySerialiser::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_DUMMY != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DUMMY_MSG:
|
||||
return deserialiseDummyMsgItem(data, size);
|
||||
case RS_PKT_SUBTYPE_DUMMY_GRP:
|
||||
return deserialiseDummyGrpItem(data, size);
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsDummySerialiser::sizeDummyMsgItem(RsDummyMsg *item)
|
||||
{
|
||||
uint32_t s = 8; // header
|
||||
s += GetTlvStringSize(item->msgData);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsDummySerialiser::serialiseDummyMsgItem (RsDummyMsg *item, void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t tlvsize = sizeDummyMsgItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*size < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* RsDistribMsg first */
|
||||
|
||||
ok &= SetTlvString(data, *size, &offset, 1, item->msgData);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsDummySerialiser::serialiseDummyMsgItem Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsDummyMsg * RsDummySerialiser::deserialiseDummyMsgItem(void *data, uint32_t *size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_DUMMY != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_DUMMY_MSG != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsDummyMsg *item = new RsDummyMsg();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, *size, &offset, 1, item->msgData);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
uint32_t RsDummySerialiser::sizeDummyGrpItem(RsDummyGrp *item)
|
||||
{
|
||||
uint32_t s = 8;
|
||||
s += GetTlvStringSize(item->grpData);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsDummySerialiser::serialiseDummyGrpItem (RsDummyGrp *item, void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t tlvsize = sizeDummyGrpItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*size < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= SetTlvString(data, *size, &offset, 1, item->grpData);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsDummySerialiser::serialiseDummyGrpItem Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsDummyGrp * RsDummySerialiser::deserialiseDummyGrpItem(void *data, uint32_t *size)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_DUMMY != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_DUMMY_GRP != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsDummyGrp *item = new RsDummyGrp();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, *size, &offset, 1, item->grpData);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
167
tests/unittests/libretroshare/gxs/gen_exchange/rsdummyservices.h
Normal file
167
tests/unittests/libretroshare/gxs/gen_exchange/rsdummyservices.h
Normal file
|
@ -0,0 +1,167 @@
|
|||
#ifndef RSDUMMYSERVICES_H
|
||||
#define RSDUMMYSERVICES_H
|
||||
|
||||
|
||||
// dummy services to make
|
||||
|
||||
#include "gxs/rsnxs.h"
|
||||
#include "gxs/rsgixs.h"
|
||||
#include "serialiser/rsgxsitems.h"
|
||||
|
||||
class RsDummyNetService: public RsNetworkExchangeService
|
||||
{
|
||||
public:
|
||||
|
||||
RsDummyNetService(){ return;}
|
||||
virtual ~RsDummyNetService() { }
|
||||
|
||||
void setSyncAge(uint32_t age){}
|
||||
|
||||
void requestGroupsOfPeer(const std::string& peerId){}
|
||||
|
||||
void requestMessagesOfPeer(const std::string& peerId, const std::string& grpId){}
|
||||
|
||||
void pauseSynchronisation(bool enabled) {}
|
||||
|
||||
int requestMsg(const std::string& msgId, uint8_t hops){ return 0;}
|
||||
|
||||
int requestGrp(const std::list<std::string>& grpId, uint8_t hops) { return 0;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_DUMMY = 0x01;
|
||||
const uint8_t RS_PKT_SUBTYPE_DUMMY_MSG = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_DUMMY_GRP = 0x03;
|
||||
|
||||
|
||||
class RsDummyMsg : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
RsDummyMsg() : RsGxsMsgItem(RS_SERVICE_TYPE_DUMMY, RS_PKT_SUBTYPE_DUMMY_MSG) { return; }
|
||||
virtual ~RsDummyMsg() { return; }
|
||||
|
||||
std::string msgData;
|
||||
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0){ return out; }
|
||||
void clear() { msgData.clear(); }
|
||||
|
||||
};
|
||||
|
||||
class RsDummyGrp : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDummyGrp() : RsGxsGrpItem(RS_SERVICE_TYPE_DUMMY, RS_PKT_SUBTYPE_DUMMY_GRP) { return; }
|
||||
virtual ~RsDummyGrp() { return; }
|
||||
|
||||
|
||||
std::string grpData;
|
||||
void clear() { grpData.clear(); }
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0){ return out; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RsDummySerialiser : public RsSerialType
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
RsDummySerialiser()
|
||||
: RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DUMMY)
|
||||
{ return; }
|
||||
virtual ~RsDummySerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeDummyMsgItem(RsDummyMsg *item);
|
||||
bool serialiseDummyMsgItem (RsDummyMsg *item, void *data, uint32_t *size);
|
||||
RsDummyMsg * deserialiseDummyMsgItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeDummyGrpItem(RsDummyGrp *item);
|
||||
bool serialiseDummyGrpItem (RsDummyGrp *item, void *data, uint32_t *size);
|
||||
RsDummyGrp * deserialiseDummyGrpItem(void *data, uint32_t *size);
|
||||
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
* Dummy implementation of Gixs service for
|
||||
* testing
|
||||
* Limited to creating two ids upon construction which can be used
|
||||
* for signing data
|
||||
*/
|
||||
class RsGixsDummy : public RsGixs
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* constructs keys for both incoming and outgoing id (no private keys for incoming id)
|
||||
* @param
|
||||
* @param dummyId This is is the only id thats exists in this dummy interface
|
||||
*/
|
||||
RsGixsDummy(const RsGxsId& incomingId, const RsGxsId& outgoingId){}
|
||||
|
||||
virtual ~RsGixsDummy(){}
|
||||
|
||||
/*!
|
||||
*
|
||||
* @return id used for signing incoming data (should have both public and private components)
|
||||
*/
|
||||
const RsGxsId& getOutgoing(){ return mOutgoingId; }
|
||||
|
||||
/*!
|
||||
*
|
||||
* @return id used for signing outgoing data(only have public parts)
|
||||
*/
|
||||
const RsGxsId& getIncoming(){ return mIncomingId; }
|
||||
|
||||
// Key related interface - used for validating msgs and groups.
|
||||
/*!
|
||||
* Use to query a whether given key is available by its key reference
|
||||
* @param keyref the keyref of key that is being checked for
|
||||
* @return true if available, false otherwise
|
||||
*/
|
||||
bool haveKey(const RsGxsId &id){ return false;}
|
||||
|
||||
/*!
|
||||
* Use to query whether private key member of the given key reference is available
|
||||
* @param keyref the KeyRef of the key being checked for
|
||||
* @return true if private key is held here, false otherwise
|
||||
*/
|
||||
bool havePrivateKey(const RsGxsId &id){ return false; }
|
||||
|
||||
// The fetchKey has an optional peerList.. this is people that had the msg with the signature.
|
||||
// These same people should have the identity - so we ask them first.
|
||||
/*!
|
||||
* Use to request a given key reference
|
||||
* @param keyref the KeyRef of the key being requested
|
||||
* @return will
|
||||
*/
|
||||
bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers){ return false ;}
|
||||
bool requestPrivateKey(const RsGxsId &id){ return false;}
|
||||
|
||||
|
||||
/*!
|
||||
* Retrieves a key identity
|
||||
* @param keyref
|
||||
* @return a pointer to a valid profile if successful, otherwise NULL
|
||||
*
|
||||
*/
|
||||
int getKey(const RsGxsId &id, RsTlvSecurityKey &key){ return false; }
|
||||
int getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key){ return false; } // For signing outgoing messages.
|
||||
|
||||
private:
|
||||
|
||||
RsGxsId mIncomingId, mOutgoingId;
|
||||
};
|
||||
|
||||
|
||||
#endif // RSDUMMYSERVICES_H
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "genexchangetester.h"
|
||||
#include "gxspublishgrouptest.h"
|
||||
#include "gxspublishmsgtest.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "rsdummyservices.h"
|
||||
|
||||
|
||||
/*!
|
||||
* It always hard to say exactly what coverage of a test would
|
||||
* be ahead of time. Partly because its difficult to create the
|
||||
* actual conditions of a test or the permutations of different request
|
||||
* options to a module is extremely large (and there are probably ways to deal with this)
|
||||
* In so far as the genexchange test is concerned we are primarily interested that it
|
||||
* retrieves and stores data correctly
|
||||
* The auxillary (and important) requirement is authentication and ensuring the authentication
|
||||
* rules are respected. This auxillary requirement is of the "hard" situation to create as
|
||||
* genexchange depends on an external module (rsidentity) for satisfying a significant sum
|
||||
* of its authentication. This difficulty is solved with a dummy identity service.
|
||||
* Which passes all authentications (In this respect authentication) is reserved for "online"
|
||||
* testing and is relatively straight forward.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
TEST(libretroshare_gxs, RsGenExchange)
|
||||
{
|
||||
|
||||
RsGeneralDataService* dataStore = new RsDataService("./", "testServiceDb", RS_SERVICE_TYPE_DUMMY, NULL, "");
|
||||
|
||||
// we want to use default authentication which is NO authentication :)
|
||||
GenExchangeTestService testService(dataStore, NULL, NULL);
|
||||
|
||||
GxsPublishGroupTest testGrpPublishing(&testService, dataStore);
|
||||
testGrpPublishing.runTests();
|
||||
|
||||
//GxsPublishMsgTest testMsgPublishing(&testService, dataStore);
|
||||
//testMsgPublishing.runTests();
|
||||
}
|
130
tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc
Normal file
130
tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc
Normal file
|
@ -0,0 +1,130 @@
|
|||
#include "nxstesthub.h"
|
||||
|
||||
NxsTestHub::NxsTestHub(NxsTestScenario * nts, std::set<RsPeerId> &peers) : mTestScenario(nts)
|
||||
{
|
||||
|
||||
std::set<RsPeerId>::iterator sit = peers.begin();
|
||||
|
||||
for(; sit != peers.end(); sit++)
|
||||
{
|
||||
std::set<RsPeerId> msgPeers = peers;
|
||||
|
||||
// add peers all peers except one iterator currently points to
|
||||
msgPeers.erase(*sit);
|
||||
NxsNetDummyMgr* dummyMgr = new NxsNetDummyMgr(*sit, msgPeers);
|
||||
RsGeneralDataService* ds = mTestScenario->getDataService(*sit);
|
||||
NxsMessageTestObserver* obs = new NxsMessageTestObserver(ds);
|
||||
|
||||
RsServiceInfo info;
|
||||
RsGxsNetService* netService =
|
||||
new RsGxsNetService(mTestScenario->getServiceType(),
|
||||
ds, dummyMgr, obs, info);
|
||||
|
||||
|
||||
mNetServices.insert(std::make_pair(*sit, netService));
|
||||
mObservers.insert(std::make_pair(*sit, obs));
|
||||
}
|
||||
|
||||
sit = peers.begin();
|
||||
|
||||
// launch net services
|
||||
for(; sit != peers.end(); sit++)
|
||||
{
|
||||
RsGxsNetService* n = mNetServices[*sit];
|
||||
createThread(*n);
|
||||
mServices.insert(std::make_pair(*sit, n));
|
||||
}
|
||||
}
|
||||
|
||||
NxsTestHub::~NxsTestHub()
|
||||
{
|
||||
std::map<RsPeerId, RsGxsNetService*>::iterator mit = mNetServices.begin();
|
||||
|
||||
for(; mit != mNetServices.end(); mit++)
|
||||
delete mit->second;
|
||||
}
|
||||
|
||||
|
||||
void NxsTestHub::run()
|
||||
{
|
||||
double timeDelta = .2;
|
||||
|
||||
while(isRunning()){
|
||||
|
||||
// make thread sleep for a bit
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
|
||||
std::map<RsPeerId, p3Service*>::iterator mit = mServices.begin();
|
||||
|
||||
for(; mit != mServices.end(); mit++)
|
||||
{
|
||||
p3Service* s = mit->second;
|
||||
s->tick();
|
||||
}
|
||||
|
||||
mit = mServices.begin();
|
||||
|
||||
// collect msgs to send to peers from peers
|
||||
for(; mit != mServices.end(); mit++)
|
||||
{
|
||||
const RsPeerId& peer = mit->first;
|
||||
p3Service* s = mit->second;
|
||||
|
||||
// first store all the sends from all services
|
||||
RsItem* item = NULL;
|
||||
|
||||
while((item = s->send()) != NULL){
|
||||
|
||||
const RsPeerId peerToReceive = item->PeerId();
|
||||
|
||||
// set the peer this item comes from
|
||||
item->PeerId(peer);
|
||||
mPeerQueues[peerToReceive].push_back(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// now route items to peers
|
||||
std::map<RsPeerId, std::vector<RsItem*> >::iterator mit_queue = mPeerQueues.begin();
|
||||
|
||||
for(; mit_queue != mPeerQueues.end(); mit_queue++)
|
||||
{
|
||||
std::vector<RsItem*>& queueV = mit_queue->second;
|
||||
std::vector<RsItem*>::iterator vit = queueV.begin();
|
||||
const RsPeerId peerToReceive = mit_queue->first;
|
||||
for(; vit != queueV.end(); vit++)
|
||||
{
|
||||
|
||||
RsItem* item = *vit;
|
||||
p3Service* service = mServices[peerToReceive];
|
||||
|
||||
service->receive(dynamic_cast<RsRawItem*>(item));
|
||||
}
|
||||
queueV.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NxsTestHub::cleanUp()
|
||||
{
|
||||
std::map<RsPeerId, RsGxsNetService*>::iterator mit = mNetServices.begin();
|
||||
for(; mit != mNetServices.end(); mit++)
|
||||
{
|
||||
RsGxsNetService* n = mit->second;
|
||||
n->join();
|
||||
}
|
||||
|
||||
// also shut down this net service peers if this goes down
|
||||
mTestScenario->cleanUp();
|
||||
}
|
||||
|
||||
bool NxsTestHub::testsPassed()
|
||||
{
|
||||
return false;
|
||||
}
|
89
tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.h
Normal file
89
tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
#ifndef NXSTESTHUB_H
|
||||
#define NXSTESTHUB_H
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
#include "gxs/rsgxsnetservice.h"
|
||||
#include "nxstestscenario.h"
|
||||
|
||||
// it would probably be useful if the test scenario
|
||||
// provided the net dummy managers
|
||||
// hence one could envision synchronising between an arbitrary number
|
||||
// of peers
|
||||
|
||||
|
||||
class NxsNetDummyMgr : public RsNxsNetMgr
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NxsNetDummyMgr(RsPeerId ownId, std::set<RsPeerId> peers) : mOwnId(ownId), mPeers(peers) {
|
||||
|
||||
}
|
||||
|
||||
const RsPeerId& getOwnId() { return mOwnId; }
|
||||
void getOnlineList(uint32_t serviceId, std::set<RsPeerId>& ssl_peers) { ssl_peers = mPeers; }
|
||||
|
||||
private:
|
||||
|
||||
RsPeerId mOwnId;
|
||||
std::set<RsPeerId> mPeers;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* Testing of nxs services occurs through use of two services
|
||||
* When a service sends this class can interrogate the send and the receives of
|
||||
*
|
||||
* NxsScenario stores the type of synchronisation to be tested
|
||||
* Operation:
|
||||
* First NxsTestHub needs to be instantiated with a test scenario
|
||||
* * The scenario contains two databases to be used on the communicating pair of RsGxsNetService instances (net instances)
|
||||
* The Test hub has a ticker service for the p3Services which allows the netservices to search what groups and messages they have
|
||||
* and synchronise according to their subscriptions. The default is to subscribe to all groups held by other peer
|
||||
* The threads for both net instances are started which begins their processing of transactions
|
||||
*/
|
||||
class NxsTestHub : public RsThread
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
/*!
|
||||
* This construct the test hub
|
||||
* for a give scenario in mind
|
||||
*/
|
||||
NxsTestHub(NxsTestScenario*, std::set<RsPeerId>& peers);
|
||||
|
||||
|
||||
/*!
|
||||
*
|
||||
*/
|
||||
virtual ~NxsTestHub();
|
||||
|
||||
/*!
|
||||
* To be called only after this thread has
|
||||
* been shutdown
|
||||
*/
|
||||
bool testsPassed();
|
||||
|
||||
/*!
|
||||
* This simulates the p3Service ticker and calls both gxs net services tick methods
|
||||
* Also enables transport of messages between both services
|
||||
*/
|
||||
void run();
|
||||
|
||||
|
||||
void cleanUp();
|
||||
private:
|
||||
|
||||
std::map<RsPeerId, p3Service*> mServices;
|
||||
std::map<RsPeerId, RsGxsNetService*> mNetServices;
|
||||
std::map<RsPeerId, NxsMessageTestObserver*> mObservers;
|
||||
|
||||
std::map<RsPeerId, std::vector<RsItem*> > mPeerQueues;
|
||||
|
||||
NxsTestScenario *mTestScenario;
|
||||
|
||||
};
|
||||
|
||||
#endif // NXSTESTHUB_H
|
177
tests/unittests/libretroshare/gxs/nxs_test/nxstestscenario.cc
Normal file
177
tests/unittests/libretroshare/gxs/nxs_test/nxstestscenario.cc
Normal file
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* nxstestscenario.cc
|
||||
*
|
||||
* Created on: 10 Jul 2012
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "nxstestscenario.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "data_support.h"
|
||||
#include <stdio.h>
|
||||
|
||||
NxsMessageTest::NxsMessageTest(uint16_t servtype)
|
||||
: mServType(servtype), mMsgTestMtx("mMsgTestMtx")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string NxsMessageTest::getTestName()
|
||||
{
|
||||
return std::string("Nxs Message Test!");
|
||||
}
|
||||
|
||||
NxsMessageTest::~NxsMessageTest(){
|
||||
|
||||
std::map<std::string, RsGeneralDataService*>::iterator mit = mPeerStoreMap.begin();
|
||||
|
||||
for(; mit != mPeerStoreMap.end(); mit++)
|
||||
{
|
||||
delete mit->second;
|
||||
}
|
||||
|
||||
std::set<std::string>::iterator sit = mStoreNames.begin();
|
||||
|
||||
// remove db file
|
||||
for(; sit != mStoreNames.end(); sit++)
|
||||
{
|
||||
const std::string& name = *sit;
|
||||
remove(name.c_str());
|
||||
}
|
||||
}
|
||||
RsGeneralDataService* NxsMessageTest::getDataService(const std::string& peer)
|
||||
{
|
||||
if(mPeerStoreMap.find(peer) != mPeerStoreMap.end()) return NULL;
|
||||
|
||||
RsDataService* dStore = new RsDataService("./", peer, mServType);
|
||||
mStoreNames.insert(peer);
|
||||
mPeerStoreMap.insert(std::make_pair(peer, dStore));
|
||||
populateStore(dStore);
|
||||
|
||||
return dStore;
|
||||
}
|
||||
|
||||
uint16_t NxsMessageTest::getServiceType()
|
||||
{
|
||||
return mServType;
|
||||
}
|
||||
|
||||
void NxsMessageTest::populateStore(RsGeneralDataService* dStore)
|
||||
{
|
||||
|
||||
int nGrp = (rand()%2)+1;
|
||||
std::vector<std::string> grpIdList;
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
|
||||
RsNxsGrp* grp = NULL;
|
||||
RsGxsGrpMetaData* grpMeta =NULL;
|
||||
for(int i = 0; i < nGrp; i++)
|
||||
{
|
||||
std::pair<RsNxsGrp*, RsGxsGrpMetaData*> p;
|
||||
grp = new RsNxsGrp(mServType);
|
||||
grpMeta = new RsGxsGrpMetaData();
|
||||
p.first = grp;
|
||||
p.second = grpMeta;
|
||||
init_item(*grp);
|
||||
init_item(grpMeta);
|
||||
grpMeta->mGroupId = grp->grpId;
|
||||
grps.insert(p);
|
||||
grpIdList.push_back(grp->grpId);
|
||||
grpMeta = NULL;
|
||||
grp = NULL;
|
||||
}
|
||||
|
||||
dStore->storeGroup(grps);
|
||||
|
||||
int nMsgs = rand()%23;
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
|
||||
RsNxsMsg* msg = NULL;
|
||||
RsGxsMsgMetaData* msgMeta = NULL;
|
||||
|
||||
for(int i=0; i<nMsgs; i++)
|
||||
{
|
||||
msg = new RsNxsMsg(mServType);
|
||||
msgMeta = new RsGxsMsgMetaData();
|
||||
init_item(*msg);
|
||||
init_item(msgMeta);
|
||||
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
|
||||
|
||||
// pick a grp at random to associate the msg to
|
||||
const std::string& grpId = grpIdList[rand()%nGrp];
|
||||
msgMeta->mMsgId = msg->msgId;
|
||||
msgMeta->mGroupId = msg->grpId = grpId;
|
||||
|
||||
msg = NULL;
|
||||
msgMeta = NULL;
|
||||
|
||||
msgs.insert(p);
|
||||
}
|
||||
|
||||
|
||||
dStore->storeMessage(msgs);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void NxsMessageTest::cleanUp()
|
||||
{
|
||||
|
||||
std::map<std::string, RsGeneralDataService*>::iterator mit = mPeerStoreMap.begin();
|
||||
|
||||
for(; mit != mPeerStoreMap.end(); mit++)
|
||||
{
|
||||
RsGeneralDataService* d = mit->second;
|
||||
d->resetDataStore();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool NxsMessageTest::testPassed(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/*******************************/
|
||||
|
||||
NxsMessageTestObserver::NxsMessageTestObserver(RsGeneralDataService *dStore)
|
||||
:mStore(dStore)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NxsMessageTestObserver::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
|
||||
{
|
||||
std::vector<RsNxsGrp*>::iterator vit = groups.begin();
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
|
||||
|
||||
for(; vit != groups.end(); vit++)
|
||||
{
|
||||
RsNxsGrp* grp = *vit;
|
||||
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
||||
meta->deserialise(grp->meta.bin_data, grp->meta.bin_len);
|
||||
meta->mSubscribeFlags |= GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
||||
meta->mGroupId = grp->grpId;
|
||||
grps.insert(std::make_pair(grp, meta));
|
||||
}
|
||||
|
||||
mStore->storeGroup(grps);
|
||||
}
|
||||
|
||||
void NxsMessageTestObserver::notifyNewMessages(std::vector<RsNxsMsg *> &messages)
|
||||
{
|
||||
|
||||
std::vector<RsNxsMsg*>::iterator vit = messages.begin();
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
|
||||
|
||||
for(; vit != messages.end(); vit++)
|
||||
{
|
||||
RsNxsMsg* msg = *vit;
|
||||
RsGxsMsgMetaData* meta = new RsGxsMsgMetaData();
|
||||
meta->mGroupId = msg->grpId;
|
||||
meta->mMsgId = msg->msgId;
|
||||
msgs.insert(std::make_pair(msg, meta));
|
||||
}
|
||||
|
||||
mStore->storeMessage(msgs);
|
||||
}
|
||||
|
106
tests/unittests/libretroshare/gxs/nxs_test/nxstestscenario.h
Normal file
106
tests/unittests/libretroshare/gxs/nxs_test/nxstestscenario.h
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* nxstestscenario.h
|
||||
*
|
||||
* Created on: 10 Jul 2012
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef NXSTESTSCENARIO_H_
|
||||
#define NXSTESTSCENARIO_H_
|
||||
|
||||
#include <map>
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "gxs/rsnxsobserver.h"
|
||||
|
||||
/*!
|
||||
* This scenario module provides data resources
|
||||
*/
|
||||
class NxsTestScenario
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
virtual std::string getTestName() = 0;
|
||||
|
||||
/*!
|
||||
* @param peer
|
||||
* @param namePath
|
||||
* @return data service with populated with random grp/msg data, null if peer or pathname exists
|
||||
*/
|
||||
virtual RsGeneralDataService* getDataService(const RsPeerId& peer) = 0;
|
||||
|
||||
|
||||
virtual bool testPassed() = 0;
|
||||
/*!
|
||||
* Service type for this test
|
||||
* should correspond to serialiser service type
|
||||
*/
|
||||
virtual uint16_t getServiceType() = 0;
|
||||
|
||||
/*!
|
||||
* Call to remove files created
|
||||
* in the test directory
|
||||
*/
|
||||
virtual void cleanUp() = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
class NxsMessageTestObserver : public RsNxsObserver
|
||||
{
|
||||
public:
|
||||
|
||||
NxsMessageTestObserver(RsGeneralDataService* dStore);
|
||||
|
||||
/*!
|
||||
* @param messages messages are deleted after function returns
|
||||
*/
|
||||
void notifyNewMessages(std::vector<RsNxsMsg*>& messages);
|
||||
|
||||
/*!
|
||||
* @param messages messages are deleted after function returns
|
||||
*/
|
||||
void notifyNewGroups(std::vector<RsNxsGrp*>& groups);
|
||||
|
||||
private:
|
||||
|
||||
RsGeneralDataService* mStore;
|
||||
|
||||
};
|
||||
|
||||
class NxsMessageTest : public NxsTestScenario
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NxsMessageTest(uint16_t servtype);
|
||||
virtual ~NxsMessageTest();
|
||||
std::string getTestName();
|
||||
uint16_t getServiceType();
|
||||
RsGeneralDataService* getDataService(const RsPeerId& peer);
|
||||
|
||||
/*!
|
||||
* Call to remove files created
|
||||
* in the test directory
|
||||
*/
|
||||
void cleanUp();
|
||||
|
||||
bool testPassed();
|
||||
|
||||
private:
|
||||
void setUpDataBases();
|
||||
void populateStore(RsGeneralDataService* dStore);
|
||||
|
||||
private:
|
||||
|
||||
std::string mTestName;
|
||||
std::map<RsPeerId, RsGeneralDataService*> mPeerStoreMap;
|
||||
std::set<std::string> mStoreNames;
|
||||
uint16_t mServType;
|
||||
|
||||
RsMutex mMsgTestMtx;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* NXSTESTSCENARIO_H_ */
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* rsgxsnetservice_test.cc
|
||||
*
|
||||
* Created on: 11 Jul 2012
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "util/utest.h"
|
||||
#include "nxstesthub.h"
|
||||
#include "nxstestscenario.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
// first setup
|
||||
NxsMessageTest msgTest(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
std::set<std::string> peers;
|
||||
peers.insert("PeerA");
|
||||
peers.insert("PeerB");
|
||||
NxsTestHub hub(&msgTest, peers);
|
||||
|
||||
// now get things started
|
||||
createThread(hub);
|
||||
|
||||
double timeDelta = 50;
|
||||
|
||||
// put this thread to sleep for 10 secs
|
||||
// make thread sleep for a bit
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
hub.join();
|
||||
CHECK(hub.testsPassed());
|
||||
|
||||
hub.cleanUp();
|
||||
|
||||
FINALREPORT("RsGxsNetService Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
}
|
157
tests/unittests/libretroshare/serialiser/rsbaseitem_test.cc
Normal file
157
tests/unittests/libretroshare/serialiser/rsbaseitem_test.cc
Normal file
|
@ -0,0 +1,157 @@
|
|||
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "rstlvutil.h"
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, RsTlvFileItem)
|
||||
{
|
||||
RsTlvFileItem i1;
|
||||
RsTlvFileItem i2;
|
||||
|
||||
/* initialise */
|
||||
i1.filesize = 101010;
|
||||
i1.hash = "ABCDEFEGHE";
|
||||
i1.name = "TestFile.txt";
|
||||
i1.pop = 12;
|
||||
i1.age = 456;
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
EXPECT_TRUE(i1.filesize == i2.filesize);
|
||||
EXPECT_TRUE(i1.hash == i2.hash);
|
||||
EXPECT_TRUE(i1.name == i2.name);
|
||||
EXPECT_TRUE(i1.path == i2.path);
|
||||
EXPECT_TRUE(i1.pop == i2.pop);
|
||||
EXPECT_TRUE(i1.age == i2.age);
|
||||
|
||||
/* do it again without optional data */
|
||||
i1.filesize = 123;
|
||||
i1.name = "";
|
||||
i1.pop = 0;
|
||||
i1.age = 0;
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
EXPECT_TRUE(i1.filesize == i2.filesize);
|
||||
EXPECT_TRUE(i1.hash == i2.hash);
|
||||
EXPECT_TRUE(i1.name == i2.name);
|
||||
EXPECT_TRUE(i1.path == i2.path);
|
||||
EXPECT_TRUE(i1.pop == i2.pop);
|
||||
EXPECT_TRUE(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;
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
EXPECT_TRUE(i1.filesize == i2.filesize);
|
||||
EXPECT_TRUE(i1.hash == i2.hash);
|
||||
EXPECT_TRUE(i1.name == i2.name);
|
||||
EXPECT_TRUE(i1.path == i2.path);
|
||||
EXPECT_TRUE(i1.pop == i2.pop);
|
||||
EXPECT_TRUE(i1.age == i2.age);
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, 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);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &s1, &s2));
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, 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;
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &d1, &d2));
|
||||
|
||||
/* check the data is the same */
|
||||
EXPECT_TRUE(d1.file.filesize == d2.file.filesize);
|
||||
EXPECT_TRUE(d1.file.hash == d2.file.hash);
|
||||
EXPECT_TRUE(d1.file.name == d2.file.name);
|
||||
EXPECT_TRUE(d1.file.path == d2.file.path);
|
||||
EXPECT_TRUE(d1.file.pop == d2.file.pop);
|
||||
EXPECT_TRUE(d1.file.age == d2.file.age);
|
||||
|
||||
EXPECT_TRUE(d1.file_offset == d2.file_offset);
|
||||
EXPECT_TRUE(d1.binData.bin_len == d2.binData.bin_len);
|
||||
}
|
||||
|
||||
|
305
tests/unittests/libretroshare/serialiser/rsconfigitem_test.cc
Normal file
305
tests/unittests/libretroshare/serialiser/rsconfigitem_test.cc
Normal file
|
@ -0,0 +1,305 @@
|
|||
/*
|
||||
* libretroshare/src/tests/serialiser: rsconfigitemstest.cc
|
||||
*
|
||||
* RetroShare Serialiser tests.
|
||||
*
|
||||
* Copyright 2011 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 "support.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
|
||||
RsSerialType* init_item(RsPeerNetItem& rpn)
|
||||
{
|
||||
randString(SHORT_STR, rpn.dyndns);
|
||||
rpn.peerId.random();
|
||||
rpn.pgpId.random();
|
||||
randString(SHORT_STR, rpn.location);
|
||||
|
||||
rpn.lastContact = rand()%42424;
|
||||
rpn.netMode = rand()%313190;
|
||||
rpn.visState = rand()%63635;
|
||||
|
||||
|
||||
inet_aton("10.0.0.111", &(rpn.currentlocaladdr.sin_addr));
|
||||
rpn.currentlocaladdr.sin_port = htons(1111);
|
||||
|
||||
inet_aton("123.1.2.123", &(rpn.currentremoteaddr.sin_addr));
|
||||
rpn.currentremoteaddr.sin_port = htons(1234);
|
||||
|
||||
RsTlvIpAddressInfo ipa1, ipa2;
|
||||
|
||||
ipa1.addr = rpn.currentlocaladdr;
|
||||
ipa1.seenTime = rand()%40149013;
|
||||
ipa1.source = rand()%13423;
|
||||
|
||||
ipa2.addr = rpn.currentremoteaddr;
|
||||
ipa2.seenTime = rand()%40139013;
|
||||
ipa2.source = rand()%1343443;
|
||||
|
||||
rpn.extAddrList.mList.push_back(ipa1);
|
||||
rpn.extAddrList.mList.push_back(ipa2);
|
||||
|
||||
rpn.localAddrList.mList.push_back(ipa1);
|
||||
rpn.localAddrList.mList.push_back(ipa2);
|
||||
|
||||
|
||||
return new RsPeerConfigSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsPeerGroupItem& rpgi){
|
||||
|
||||
rpgi.flag = rand()%134344;
|
||||
randString(SHORT_STR, rpgi.id);
|
||||
randString(SHORT_STR, rpgi.name);
|
||||
std::string p1, p2, p3;
|
||||
randString(SHORT_STR, p1);
|
||||
randString(SHORT_STR, p2);
|
||||
randString(SHORT_STR, p3);
|
||||
|
||||
rpgi.peerIds.push_back(p1);
|
||||
rpgi.peerIds.push_back(p2);
|
||||
rpgi.peerIds.push_back(p3);
|
||||
|
||||
return new RsPeerConfigSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(CompressedChunkMap& map)
|
||||
{
|
||||
map._map.clear() ;
|
||||
for(uint32_t i=0;i<15;++i)
|
||||
map._map.push_back(rand()) ;
|
||||
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsPeerStunItem& rpsi)
|
||||
{
|
||||
std::string p1, p2, p3;
|
||||
randString(SHORT_STR, p1);
|
||||
randString(SHORT_STR, p2);
|
||||
randString(SHORT_STR, p3);
|
||||
|
||||
rpsi.stunList.ids.push_back(p1);
|
||||
rpsi.stunList.ids.push_back(p2);
|
||||
rpsi.stunList.ids.push_back(p3);
|
||||
|
||||
rpsi.stunList.mType = TLV_TYPE_PEERSET;
|
||||
|
||||
return new RsPeerConfigSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsCacheConfig& rcc)
|
||||
{
|
||||
|
||||
rcc.cachesubid = rand()%2342;
|
||||
rcc.cachetypeid = rand()%323;
|
||||
rcc.recvd = rand()%2252243;
|
||||
rcc.size = rand()%02203;
|
||||
randString(SHORT_STR, rcc.hash);
|
||||
randString(SHORT_STR, rcc.name);
|
||||
randString(SHORT_STR, rcc.path);
|
||||
randString(SHORT_STR, rcc.pid);
|
||||
|
||||
return new RsCacheConfigSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsFileTransfer& rft)
|
||||
{
|
||||
|
||||
std::string p1, p2, p3;
|
||||
randString(SHORT_STR, p1);
|
||||
randString(SHORT_STR, p2);
|
||||
randString(SHORT_STR, p3);
|
||||
|
||||
rft.allPeerIds.ids.push_back(p1);
|
||||
rft.allPeerIds.ids.push_back(p2);
|
||||
rft.allPeerIds.ids.push_back(p3);
|
||||
rft.allPeerIds.mType = TLV_TYPE_PEERSET;
|
||||
|
||||
//
|
||||
// rft.compressed_chunk_map._map.clear();
|
||||
// const int mapSize = 15;
|
||||
// rft.compressed_chunk_map._map.resize(mapSize);
|
||||
// for(int i=0; i<mapSize; i++)
|
||||
// rft.compressed_chunk_map._map[i] = rand();
|
||||
init_item(rft.compressed_chunk_map);
|
||||
|
||||
randString(SHORT_STR, rft.cPeerId);
|
||||
|
||||
rft.chunk_strategy = rand()%4242;
|
||||
rft.crate = rand()%4242;
|
||||
rft.flags = rand()%42422;
|
||||
rft.in = rand()%2323;
|
||||
rft.lrate = rand()%25234;
|
||||
rft.ltransfer = rand()%42232;
|
||||
rft.state = rand()%42122;
|
||||
rft.transferred = rand()%42242;
|
||||
rft.trate = rand()%1212;
|
||||
|
||||
init_item(rft.file);
|
||||
|
||||
return new RsFileConfigSerialiser();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator==(const RsPeerNetItem& left, const RsPeerNetItem& right)
|
||||
{
|
||||
if(left.dyndns != right.dyndns) return false;
|
||||
if(left.pgpId != right.pgpId) return false;
|
||||
if(left.location != right.location) return false;
|
||||
if(left.peerId != right.peerId) return false;
|
||||
if(left.lastContact != right.lastContact) return false;
|
||||
if(left.netMode != right.netMode) return false;
|
||||
if(left.visState != right.visState) return false;
|
||||
|
||||
if(left.currentlocaladdr != right.currentlocaladdr) return false;
|
||||
if(left.currentremoteaddr != right.currentremoteaddr) return false;
|
||||
if(!(left.extAddrList.mList == right.extAddrList.mList)) return false;
|
||||
if(!(left.localAddrList.mList == right.localAddrList.mList)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const std::list<RsTlvIpAddressInfo>& left,
|
||||
const std::list<RsTlvIpAddressInfo>& right)
|
||||
{
|
||||
std::list<RsTlvIpAddressInfo>::const_iterator cit1 = left.begin(),
|
||||
cit2 = right.begin();
|
||||
|
||||
for(; cit1 != left.end() ; cit1++, cit2++){
|
||||
|
||||
if(*cit1 != *cit2)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!=(const sockaddr_in& left, const sockaddr_in& right)
|
||||
{
|
||||
if(left.sin_addr.s_addr != right.sin_addr.s_addr) return true;
|
||||
if(left.sin_port != right.sin_port) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator!=(const RsTlvIpAddressInfo& left, const RsTlvIpAddressInfo& right)
|
||||
{
|
||||
|
||||
if(left.addr != right.addr) return true;
|
||||
if(left.seenTime != right.seenTime) return true;
|
||||
if(left.source != right.source) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const RsPeerGroupItem& left, const RsPeerGroupItem& right)
|
||||
{
|
||||
if(left.flag != right.flag) return false;
|
||||
if(left.id != right.id) return false;
|
||||
if(left.name != right.name) return false;
|
||||
if(left.peerIds != right.peerIds) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator!=(const std::list<std::string>& left,
|
||||
const std::list<std::string>& right)
|
||||
{
|
||||
std::list<std::string>::const_iterator cit1 = left.begin(),
|
||||
cit2 = right.begin();
|
||||
|
||||
for(; cit1 != left.end(); cit1++, cit2++){
|
||||
|
||||
if(*cit1 != *cit2)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const RsPeerStunItem& left, const RsPeerStunItem& right)
|
||||
{
|
||||
if(!(left.stunList == right.stunList)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//bool operator==(const RsTlvPeerIdSet& left, const RsTlvPeerIdSet& right)
|
||||
//{
|
||||
// if(left.mType != right.mType) return false;
|
||||
//
|
||||
// std::list<std::string>::iterator cit1 = left.ids.begin(),
|
||||
// cit2 = right.ids.begin();
|
||||
//
|
||||
// for(; cit1 != left.ids.end(); cit1++, cit2++){
|
||||
//
|
||||
// if(*cit1 != *cit2)
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
|
||||
bool operator==(const RsCacheConfig& left, const RsCacheConfig& right)
|
||||
{
|
||||
|
||||
if(left.cachesubid != right.cachesubid) return false;
|
||||
if(left.cachetypeid != right.cachetypeid) return false;
|
||||
if(left.hash != right.hash) return false;
|
||||
if(left.path != right.path) return false;
|
||||
if(left.pid != right.pid) return false;
|
||||
if(left.recvd != right.recvd) return false;
|
||||
if(left.size != right.size) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsFileTransfer& left, const RsFileTransfer& right)
|
||||
{
|
||||
|
||||
if(!(left.allPeerIds == right.allPeerIds)) return false;
|
||||
if(left.cPeerId != right.cPeerId) return false;
|
||||
if(left.chunk_strategy != right.chunk_strategy) return false;
|
||||
if(left.compressed_chunk_map._map != right.compressed_chunk_map._map) return false;
|
||||
if(left.crate != right.crate) return false;
|
||||
if(!(left.file == right.file)) return false;
|
||||
if(left.flags != right.flags) return false;
|
||||
if(left.in != right.in) return false;
|
||||
if(left.lrate != right.lrate) return false;
|
||||
if(left.ltransfer != right.ltransfer) return false;
|
||||
if(left.state != right.state) return false;
|
||||
if(left.transferred != right.transferred) return false;
|
||||
if(left.trate != right.trate) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, RsConfigItem)
|
||||
{
|
||||
test_RsItem<RsPeerNetItem>();
|
||||
test_RsItem<RsPeerGroupItem>();
|
||||
test_RsItem<RsPeerStunItem>();
|
||||
test_RsItem<RsCacheConfig>();
|
||||
test_RsItem<RsFileTransfer>();
|
||||
}
|
209
tests/unittests/libretroshare/serialiser/rsgrouteritem_test.cc
Normal file
209
tests/unittests/libretroshare/serialiser/rsgrouteritem_test.cc
Normal file
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* libretroshare/src/tests/serialiser: msgitem_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2010 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 <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#include "util/rsrandom.h"
|
||||
#include "grouter/grouteritems.h"
|
||||
#include "serialiser/rstlvutil.h"
|
||||
#include "support.h"
|
||||
|
||||
RsSerialType* init_item(RsGRouterGenericDataItem& cmi)
|
||||
{
|
||||
cmi.data_size = lrand48()%1000 + 1000 ;
|
||||
cmi.data_bytes = (uint8_t*)malloc(cmi.data_size) ;
|
||||
RSRandom::random_bytes(cmi.data_bytes,cmi.data_size) ;
|
||||
cmi.routing_id = RSRandom::random_u32() ;
|
||||
|
||||
Sha1CheckSum cs ;
|
||||
for(int i=0;i<5;++i) cs.fourbytes[i] = RSRandom::random_u32() ;
|
||||
cmi.destination_key = cs ;
|
||||
|
||||
return new RsGRouterSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsGRouterACKItem& cmi)
|
||||
{
|
||||
cmi.mid = RSRandom::random_u32() ;
|
||||
cmi.state = RSRandom::random_u32() ;
|
||||
|
||||
return new RsGRouterSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsGRouterPublishKeyItem& cmi)
|
||||
{
|
||||
cmi.diffusion_id = RSRandom::random_u32() ;
|
||||
cmi.service_id = RSRandom::random_u32() ;
|
||||
cmi.randomized_distance = RSRandom::random_f32() ;
|
||||
|
||||
Sha1CheckSum cs ;
|
||||
for(int i=0;i<5;++i) cs.fourbytes[i] = RSRandom::random_u32() ;
|
||||
cmi.published_key = cs ;
|
||||
cmi.description_string = "test key" ;
|
||||
|
||||
return new RsGRouterSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsGRouterRoutingInfoItem& cmi)
|
||||
{
|
||||
cmi.origin = SSLIdType::random() ;
|
||||
cmi.received_time = RSRandom::random_u64() ;
|
||||
cmi.status_flags = RSRandom::random_u32() ;
|
||||
|
||||
cmi.data_item = new RsGRouterGenericDataItem ;
|
||||
|
||||
uint32_t n = 10+(RSRandom::random_u32()%30) ;
|
||||
|
||||
for(uint32_t i=0;i<n;++i)
|
||||
{
|
||||
FriendTrialRecord ftr ;
|
||||
ftr.friend_id = SSLIdType::random() ;
|
||||
ftr.time_stamp = RSRandom::random_u64() ;
|
||||
|
||||
cmi.tried_friends.push_back(ftr) ;
|
||||
}
|
||||
|
||||
return init_item(*cmi.data_item) ;
|
||||
}
|
||||
RsSerialType* init_item(RsGRouterMatrixFriendListItem& cmi)
|
||||
{
|
||||
uint32_t n = 10+(RSRandom::random_u32()%30) ;
|
||||
|
||||
cmi.reverse_friend_indices.clear() ;
|
||||
for(uint32_t i=0;i<n;++i)
|
||||
cmi.reverse_friend_indices.push_back(SSLIdType::random()) ;
|
||||
|
||||
return new RsGRouterSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsGRouterMatrixCluesItem& cmi)
|
||||
{
|
||||
cmi.destination_key = Sha1CheckSum::random() ;
|
||||
|
||||
uint32_t n = 10+(RSRandom::random_u32()%30) ;
|
||||
|
||||
for(uint32_t i=0;i<n;++i)
|
||||
{
|
||||
RoutingMatrixHitEntry rmhe ;
|
||||
rmhe.friend_id = RSRandom::random_u32() ;
|
||||
rmhe.weight = RSRandom::random_f32() ;
|
||||
rmhe.time_stamp = RSRandom::random_u64() ;
|
||||
|
||||
cmi.clues.push_back(rmhe) ;
|
||||
}
|
||||
|
||||
return new RsGRouterSerialiser();
|
||||
}
|
||||
bool operator ==(const RsGRouterGenericDataItem& cmiLeft,const RsGRouterGenericDataItem& cmiRight)
|
||||
{
|
||||
if(cmiLeft.routing_id != cmiRight.routing_id) return false;
|
||||
if(cmiLeft.data_size != cmiRight.data_size) return false;
|
||||
if(!(cmiLeft.destination_key == cmiRight.destination_key)) return false;
|
||||
if(memcmp(cmiLeft.data_bytes,cmiRight.data_bytes,cmiLeft.data_size)) return false;
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool operator ==(const RsGRouterPublishKeyItem& cmiLeft,const RsGRouterPublishKeyItem& cmiRight)
|
||||
{
|
||||
if(cmiLeft.diffusion_id != cmiRight.diffusion_id) return false;
|
||||
if(!(cmiLeft.published_key == cmiRight.published_key)) return false;
|
||||
if(cmiLeft.service_id != cmiRight.service_id) return false;
|
||||
if(fabs(cmiLeft.randomized_distance - cmiRight.randomized_distance) > 0.001) return false;
|
||||
if(cmiLeft.description_string != cmiRight.description_string) return false;
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool operator ==(const RsGRouterACKItem& cmiLeft,const RsGRouterACKItem& cmiRight)
|
||||
{
|
||||
if(cmiLeft.mid != cmiRight.mid) return false;
|
||||
if(cmiLeft.state != cmiRight.state) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator ==(const RsGRouterMatrixCluesItem& cmiLeft,const RsGRouterMatrixCluesItem& cmiRight)
|
||||
{
|
||||
if(!(cmiLeft.destination_key == cmiRight.destination_key)) return false;
|
||||
if(cmiLeft.clues.size() != cmiRight.clues.size()) return false;
|
||||
|
||||
std::list<RoutingMatrixHitEntry>::const_iterator itl = cmiLeft.clues.begin() ;
|
||||
std::list<RoutingMatrixHitEntry>::const_iterator itr = cmiRight.clues.begin() ;
|
||||
|
||||
while(itl != cmiLeft.clues.end())
|
||||
{
|
||||
if( (*itl).friend_id != (*itr).friend_id) return false ;
|
||||
if( (*itl).time_stamp != (*itr).time_stamp) return false ;
|
||||
|
||||
++itl ;
|
||||
++itr ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator ==(const RsGRouterMatrixFriendListItem& cmiLeft,const RsGRouterMatrixFriendListItem& cmiRight)
|
||||
{
|
||||
if(cmiLeft.reverse_friend_indices.size() != cmiRight.reverse_friend_indices.size()) return false;
|
||||
|
||||
for(uint32_t i=0;i<cmiLeft.reverse_friend_indices.size();++i)
|
||||
if(cmiLeft.reverse_friend_indices[i] != cmiRight.reverse_friend_indices[i])
|
||||
return false ;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator ==(const RsGRouterRoutingInfoItem& cmiLeft,const RsGRouterRoutingInfoItem& cmiRight)
|
||||
{
|
||||
if(cmiLeft.status_flags != cmiRight.status_flags) return false ;
|
||||
if(cmiLeft.origin != cmiRight.origin) return false ;
|
||||
if(cmiLeft.received_time != cmiRight.received_time) return false ;
|
||||
if(cmiLeft.tried_friends.size() != cmiRight.tried_friends.size()) return false ;
|
||||
|
||||
std::list<FriendTrialRecord>::const_iterator itl(cmiLeft.tried_friends.begin()) ;
|
||||
std::list<FriendTrialRecord>::const_iterator itr(cmiRight.tried_friends.begin()) ;
|
||||
|
||||
while(itl != cmiLeft.tried_friends.end())
|
||||
{
|
||||
if( (*itl).friend_id != (*itr).friend_id) return false ;
|
||||
if( (*itl).time_stamp != (*itr).time_stamp) return false ;
|
||||
|
||||
++itl ;
|
||||
++itr ;
|
||||
}
|
||||
|
||||
if(!(*cmiLeft.data_item == *cmiRight.data_item)) return false ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, RsGRouterItem)
|
||||
{
|
||||
test_RsItem<RsGRouterGenericDataItem >();
|
||||
test_RsItem<RsGRouterACKItem >();
|
||||
test_RsItem<RsGRouterPublishKeyItem >();
|
||||
test_RsItem<RsGRouterRoutingInfoItem >();
|
||||
test_RsItem<RsGRouterMatrixFriendListItem >();
|
||||
test_RsItem<RsGRouterMatrixCluesItem >();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
58
tests/unittests/libretroshare/serialiser/rsgxsiditem_test.cc
Normal file
58
tests/unittests/libretroshare/serialiser/rsgxsiditem_test.cc
Normal file
|
@ -0,0 +1,58 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsturtleitems_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by 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 <gtest/gtest.h>
|
||||
|
||||
#include "serialiser/rsgxsiditems.h"
|
||||
#include "support.h"
|
||||
|
||||
|
||||
bool operator==(const RsGxsIdGroupItem& it1,const RsGxsIdGroupItem& it2)
|
||||
{
|
||||
if(it1.group.mPgpIdSign != it2.group.mPgpIdSign) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsGxsIdGroupItem& item)
|
||||
{
|
||||
item.group.mPgpIdSign = "hello";
|
||||
item.group.mPgpKnown = false;
|
||||
|
||||
return new RsGxsIdSerialiser();
|
||||
}
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, RsGxsIdItem)
|
||||
{
|
||||
for(uint32_t i=0;i<20;++i)
|
||||
{
|
||||
test_RsItem< RsGxsIdGroupItem >();
|
||||
}
|
||||
}
|
||||
|
||||
|
105
tests/unittests/libretroshare/serialiser/rsgxsupdateitem_test.cc
Normal file
105
tests/unittests/libretroshare/serialiser/rsgxsupdateitem_test.cc
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* rsgxsupdateitem_test.cc
|
||||
*
|
||||
* Created on: 9 Dec 2013
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "support.h"
|
||||
#include "serialiser/rsgxsupdateitems.h"
|
||||
#define RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM 0x0010
|
||||
|
||||
RsSerialType* init_item(RsGxsGrpUpdateItem& i)
|
||||
{
|
||||
i.clear();
|
||||
i.grpUpdateTS = rand()%2424;
|
||||
i.peerId.random();
|
||||
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsGxsMsgUpdateItem& i)
|
||||
{
|
||||
i.clear();
|
||||
i.peerId.random();
|
||||
int numUpdates = rand()%123;
|
||||
|
||||
RsPeerId peer;
|
||||
peer.random();
|
||||
for(int j=0; j < numUpdates; j++)
|
||||
{
|
||||
i.msgUpdateTS.insert(std::make_pair(peer, rand()%45));
|
||||
}
|
||||
|
||||
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsGxsServerGrpUpdateItem& i)
|
||||
{
|
||||
i.clear();
|
||||
i.grpUpdateTS = rand()%2424;
|
||||
|
||||
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsGxsServerMsgUpdateItem& i)
|
||||
{
|
||||
i.clear();
|
||||
i.grpId.random();
|
||||
i.msgUpdateTS = rand()%4252;
|
||||
return new RsGxsUpdateSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsGrpUpdateItem& l, const RsGxsGrpUpdateItem& r)
|
||||
{
|
||||
bool ok = l.grpUpdateTS == r.grpUpdateTS;
|
||||
ok &= l.peerId == r.peerId;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsMsgUpdateItem& l, const RsGxsMsgUpdateItem& r)
|
||||
{
|
||||
bool ok = l.peerId == r.peerId;
|
||||
|
||||
const std::map<RsGxsGroupId, uint32_t>& lUp = l.msgUpdateTS, rUp = r.msgUpdateTS;
|
||||
|
||||
ok &= lUp.size() == rUp.size();
|
||||
|
||||
std::map<RsGxsGroupId, uint32_t>::const_iterator lit = lUp.begin(), rit;
|
||||
|
||||
for(; lit != lUp.end(); lit++)
|
||||
{
|
||||
RsGxsGroupId key = lit->first;
|
||||
if((rit = rUp.find(key)) != rUp.end())
|
||||
ok &= lit->second == rit->second;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsServerGrpUpdateItem& l,
|
||||
const RsGxsServerGrpUpdateItem& r)
|
||||
{
|
||||
return l.grpUpdateTS == r.grpUpdateTS;
|
||||
}
|
||||
|
||||
bool operator ==(const RsGxsServerMsgUpdateItem& l,
|
||||
const RsGxsServerMsgUpdateItem& r)
|
||||
{
|
||||
bool ok = l.grpId == r.grpId;
|
||||
ok &= l.msgUpdateTS == r.msgUpdateTS;
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, RsGxsGrpUpateItem)
|
||||
{
|
||||
test_RsItem<RsGxsGrpUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
test_RsItem<RsGxsMsgUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
test_RsItem<RsGxsServerGrpUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
test_RsItem<RsGxsServerMsgUpdateItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
352
tests/unittests/libretroshare/serialiser/rsmsgitem_test.cc
Normal file
352
tests/unittests/libretroshare/serialiser/rsmsgitem_test.cc
Normal file
|
@ -0,0 +1,352 @@
|
|||
/*
|
||||
* libretroshare/src/tests/serialiser: msgitem_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2010 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 <iostream>
|
||||
|
||||
#include "util/rsrandom.h"
|
||||
#include "serialiser/rsmsgitems.h"
|
||||
|
||||
#include "support.h"
|
||||
#include "rstlvutil.h"
|
||||
|
||||
|
||||
RsSerialType* init_item(RsChatMsgItem& cmi)
|
||||
{
|
||||
cmi.chatFlags = rand()%34;
|
||||
cmi.sendTime = rand()%422224;
|
||||
randString(LARGE_STR, cmi.message);
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsChatLobbyListRequestItem& cmi)
|
||||
{
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsChatLobbyListItem& cmi)
|
||||
{
|
||||
int n = rand()%20 ;
|
||||
|
||||
cmi.lobby_ids.resize(n) ;
|
||||
cmi.lobby_names.resize(n) ;
|
||||
cmi.lobby_counts.resize(n) ;
|
||||
|
||||
for(int i=0;i<n;++i)
|
||||
{
|
||||
cmi.lobby_ids[i] = RSRandom::random_u64() ;
|
||||
randString(5+(rand()%10), cmi.lobby_names[i]);
|
||||
cmi.lobby_counts[i] = RSRandom::random_u32() ;
|
||||
}
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsChatLobbyMsgItem& cmi)
|
||||
{
|
||||
RsSerialType *serial = init_item( *dynamic_cast<RsChatMsgItem*>(&cmi)) ;
|
||||
|
||||
cmi.msg_id = RSRandom::random_u64() ;
|
||||
cmi.lobby_id = RSRandom::random_u64() ;
|
||||
cmi.nick = "My nickname" ;
|
||||
cmi.subpacket_id = rand()%256 ;
|
||||
cmi.parent_msg_id = RSRandom::random_u64() ;
|
||||
|
||||
return serial ;
|
||||
}
|
||||
RsSerialType *init_item(RsChatLobbyEventItem& cmi)
|
||||
{
|
||||
cmi.event_type = rand()%256 ;
|
||||
randString(20, cmi.string1);
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsChatLobbyInviteItem& cmi)
|
||||
{
|
||||
cmi.lobby_id = RSRandom::random_u64() ;
|
||||
cmi.lobby_name = "Name of the lobby" ;
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi)
|
||||
{
|
||||
pcmi.configPeerId.random();
|
||||
pcmi.chatFlags = rand()%34;
|
||||
pcmi.configFlags = rand()%21;
|
||||
pcmi.sendTime = rand()%422224;
|
||||
randString(LARGE_STR, pcmi.message);
|
||||
pcmi.recvTime = rand()%344443;
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsChatStatusItem& csi)
|
||||
{
|
||||
|
||||
randString(SHORT_STR, csi.status_string);
|
||||
csi.flags = rand()%232;
|
||||
|
||||
return new RsChatSerialiser();
|
||||
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsChatAvatarItem& cai)
|
||||
{
|
||||
std::string image_data;
|
||||
randString(LARGE_STR, image_data);
|
||||
cai.image_data = new unsigned char[image_data.size()];
|
||||
|
||||
memcpy(cai.image_data, image_data.c_str(), image_data.size());
|
||||
cai.image_size = image_data.size();
|
||||
|
||||
return new RsChatSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsMsgItem& mi)
|
||||
{
|
||||
init_item(mi.attachment);
|
||||
init_item(mi.rspeerid_msgbcc);
|
||||
init_item(mi.rspeerid_msgcc);
|
||||
init_item(mi.rspeerid_msgto);
|
||||
|
||||
randString(LARGE_STR, mi.message);
|
||||
randString(SHORT_STR, mi.subject);
|
||||
|
||||
mi.msgId = rand()%324232;
|
||||
mi.recvTime = rand()%44252;
|
||||
mi.sendTime = mi.recvTime;
|
||||
mi.msgFlags = mi.recvTime;
|
||||
|
||||
return new RsMsgSerialiser(true);
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsMsgTagType& mtt)
|
||||
{
|
||||
mtt.rgb_color = rand()%5353;
|
||||
mtt.tagId = rand()%24242;
|
||||
randString(SHORT_STR, mtt.text);
|
||||
|
||||
return new RsMsgSerialiser();
|
||||
}
|
||||
|
||||
|
||||
RsSerialType* init_item(RsMsgTags& mt)
|
||||
{
|
||||
mt.msgId = rand()%3334;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 10; i++) {
|
||||
mt.tagIds.push_back(rand()%21341);
|
||||
}
|
||||
|
||||
return new RsMsgSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsMsgSrcId& ms)
|
||||
{
|
||||
ms.msgId = rand()%434;
|
||||
ms.srcId.random();
|
||||
|
||||
return new RsMsgSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsMsgParentId& ms)
|
||||
{
|
||||
ms.msgId = rand()%354;
|
||||
ms.msgParentId = rand()%476;
|
||||
|
||||
return new RsMsgSerialiser();
|
||||
}
|
||||
|
||||
bool operator ==(const RsChatLobbyListItem& cmiLeft,const RsChatLobbyListItem& cmiRight)
|
||||
{
|
||||
if(cmiLeft.lobby_ids.size() != cmiRight.lobby_ids.size()) return false;
|
||||
if(cmiLeft.lobby_names.size() != cmiRight.lobby_names.size()) return false;
|
||||
if(cmiLeft.lobby_counts.size() != cmiRight.lobby_counts.size()) return false;
|
||||
|
||||
for(uint32_t i=0;i<cmiLeft.lobby_ids.size();++i)
|
||||
{
|
||||
if(cmiLeft.lobby_ids[i] != cmiRight.lobby_ids[i]) return false ;
|
||||
if(cmiLeft.lobby_names[i] != cmiRight.lobby_names[i]) return false ;
|
||||
if(cmiLeft.lobby_counts[i] != cmiRight.lobby_counts[i]) return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
bool operator ==(const RsChatLobbyListRequestItem& cmiLeft,const RsChatLobbyListRequestItem& cmiRight)
|
||||
{
|
||||
return true ;
|
||||
}
|
||||
bool operator ==(const RsChatMsgItem& cmiLeft,const RsChatMsgItem& cmiRight)
|
||||
{
|
||||
|
||||
if(cmiLeft.chatFlags != cmiRight.chatFlags) return false;
|
||||
if(cmiLeft.message != cmiRight.message) return false;
|
||||
if(cmiLeft.sendTime != cmiRight.sendTime) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsPrivateChatMsgConfigItem& pcmiLeft,const RsPrivateChatMsgConfigItem& pcmiRight)
|
||||
{
|
||||
|
||||
if(pcmiLeft.configPeerId != pcmiRight.configPeerId) return false;
|
||||
if(pcmiLeft.chatFlags != pcmiRight.chatFlags) return false;
|
||||
if(pcmiLeft.configFlags != pcmiRight.configFlags) return false;
|
||||
if(pcmiLeft.message != pcmiRight.message) return false;
|
||||
if(pcmiLeft.sendTime != pcmiRight.sendTime) return false;
|
||||
if(pcmiLeft.recvTime != pcmiRight.recvTime) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsChatStatusItem& csiLeft, const RsChatStatusItem& csiRight)
|
||||
{
|
||||
if(csiLeft.flags != csiRight.flags) return false;
|
||||
if(csiLeft.status_string != csiRight.status_string) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator ==(const RsChatLobbyMsgItem& csiLeft, const RsChatLobbyMsgItem& csiRight)
|
||||
{
|
||||
if(! ( (RsChatMsgItem&)csiLeft == (RsChatMsgItem&)csiRight))
|
||||
return false ;
|
||||
|
||||
if(csiLeft.lobby_id != csiRight.lobby_id) return false ;
|
||||
if(csiLeft.msg_id != csiRight.msg_id) return false ;
|
||||
if(csiLeft.nick != csiRight.nick) return false ;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator ==(const RsChatLobbyEventItem& csiLeft, const RsChatLobbyEventItem& csiRight)
|
||||
{
|
||||
if(csiLeft.lobby_id != csiRight.lobby_id) return false ;
|
||||
if(csiLeft.msg_id != csiRight.msg_id) return false ;
|
||||
if(csiLeft.nick != csiRight.nick) return false ;
|
||||
if(csiLeft.event_type != csiRight.event_type) return false ;
|
||||
if(csiLeft.string1 != csiRight.string1) return false ;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool operator ==(const RsChatLobbyInviteItem& csiLeft, const RsChatLobbyInviteItem& csiRight)
|
||||
{
|
||||
if(csiLeft.lobby_id != csiRight.lobby_id) return false ;
|
||||
if(csiLeft.lobby_name != csiRight.lobby_name) return false ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsChatAvatarItem& caiLeft, const RsChatAvatarItem& caiRight)
|
||||
{
|
||||
unsigned char* image_dataLeft = (unsigned char*)caiLeft.image_data;
|
||||
unsigned char* image_dataRight = (unsigned char*)caiRight.image_data;
|
||||
|
||||
// make image sizes are the same to prevent dereferencing garbage
|
||||
if(caiLeft.image_size == caiRight.image_size)
|
||||
{
|
||||
image_dataLeft = (unsigned char*)caiLeft.image_data;
|
||||
image_dataRight = (unsigned char*)caiRight.image_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < caiLeft.image_size; i++)
|
||||
if(image_dataLeft[i] != image_dataRight[i]) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool operator ==(const RsMsgItem& miLeft, const RsMsgItem& miRight)
|
||||
{
|
||||
if(miLeft.message != miRight.message) return false;
|
||||
if(miLeft.msgFlags != miRight.msgFlags) return false;
|
||||
if(miLeft.recvTime != miRight.recvTime) return false;
|
||||
if(miLeft.sendTime != miRight.sendTime) return false;
|
||||
if(miLeft.subject != miRight.subject) return false;
|
||||
if(miLeft.msgId != miRight.msgId) return false;
|
||||
|
||||
if(!(miLeft.attachment == miRight.attachment)) return false;
|
||||
if(!(miLeft.rspeerid_msgbcc == miRight.rspeerid_msgbcc)) return false;
|
||||
if(!(miLeft.rspeerid_msgcc == miRight.rspeerid_msgcc)) return false;
|
||||
if(!(miLeft.rspeerid_msgto == miRight.rspeerid_msgto)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsMsgTagType& mttLeft, const RsMsgTagType& mttRight)
|
||||
{
|
||||
if(mttLeft.rgb_color != mttRight.rgb_color) return false;
|
||||
if(mttLeft.tagId != mttRight.tagId) return false;
|
||||
if(mttLeft.text != mttRight.text) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsMsgTags& mtLeft, const RsMsgTags& mtRight)
|
||||
{
|
||||
if(mtLeft.msgId != mtRight.msgId) return false;
|
||||
if(mtLeft.tagIds != mtRight.tagIds) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsMsgSrcId& msLeft, const RsMsgSrcId& msRight)
|
||||
{
|
||||
if(msLeft.msgId != msRight.msgId) return false;
|
||||
if(msLeft.srcId != msRight.srcId) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator ==(const RsMsgParentId& msLeft, const RsMsgParentId& msRight)
|
||||
{
|
||||
if(msLeft.msgId != msRight.msgId) return false;
|
||||
if(msLeft.msgParentId != msRight.msgParentId) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, RsMsgItem)
|
||||
{
|
||||
test_RsItem<RsChatMsgItem >();
|
||||
test_RsItem<RsChatLobbyMsgItem >();
|
||||
test_RsItem<RsChatLobbyInviteItem >();
|
||||
test_RsItem<RsChatLobbyEventItem >();
|
||||
test_RsItem<RsChatLobbyListRequestItem >();
|
||||
test_RsItem<RsChatLobbyListItem >();
|
||||
test_RsItem<RsChatStatusItem >();
|
||||
test_RsItem<RsChatAvatarItem >();
|
||||
test_RsItem<RsMsgItem >();
|
||||
test_RsItem<RsMsgTagType>();
|
||||
test_RsItem<RsMsgTags>();
|
||||
test_RsItem<RsMsgSrcId>();
|
||||
test_RsItem<RsMsgParentId>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
21
tests/unittests/libretroshare/serialiser/rsnxsitems_test.cc
Normal file
21
tests/unittests/libretroshare/serialiser/rsnxsitems_test.cc
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
#include "support.h"
|
||||
#include "libretroshare/gxs/common/data_support.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
|
||||
|
||||
#define NUM_BIN_OBJECTS 5
|
||||
#define NUM_SYNC_MSGS 8
|
||||
#define NUM_SYNC_GRPS 5
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, RsNxsItem)
|
||||
{
|
||||
test_RsItem<RsNxsGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
test_RsItem<RsNxsMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
test_RsItem<RsNxsSyncGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
test_RsItem<RsNxsSyncMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
test_RsItem<RsNxsSyncGrpItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
test_RsItem<RsNxsSyncMsgItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
test_RsItem<RsNxsTransac>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
}
|
133
tests/unittests/libretroshare/serialiser/rsphotoitem_test.cc
Normal file
133
tests/unittests/libretroshare/serialiser/rsphotoitem_test.cc
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* libretroshare/src/test rsphotoitem_test.cc
|
||||
*
|
||||
* Test for photo item serialisation
|
||||
*
|
||||
* Copyright 2012-2012 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 "support.h"
|
||||
#include "serialiser/rsphotoitems.h"
|
||||
|
||||
|
||||
RsSerialType* init_item(RsGxsPhotoAlbumItem &album)
|
||||
{
|
||||
RsPhotoAlbum& a = album.album;
|
||||
|
||||
randString(SHORT_STR, a.mCaption);
|
||||
randString(SHORT_STR, a.mCategory);
|
||||
randString(SHORT_STR, a.mDescription);
|
||||
randString(SHORT_STR, a.mHashTags);
|
||||
randString(SHORT_STR, a.mOther);
|
||||
randString(SHORT_STR, a.mPhotoPath);
|
||||
randString(SHORT_STR, a.mPhotographer);
|
||||
randString(SHORT_STR, a.mWhen);
|
||||
randString(SHORT_STR, a.mWhere);
|
||||
randString(SHORT_STR, a.mThumbnail.type);
|
||||
std::string rStr;
|
||||
randString(SHORT_STR, rStr);
|
||||
|
||||
a.mThumbnail.data = new uint8_t[SHORT_STR];
|
||||
memcpy(a.mThumbnail.data, rStr.data(), SHORT_STR);
|
||||
a.mThumbnail.size = SHORT_STR;
|
||||
|
||||
return new RsGxsPhotoSerialiser();
|
||||
}
|
||||
|
||||
RsSerialType* init_item(RsGxsPhotoPhotoItem &photo)
|
||||
{
|
||||
|
||||
RsPhotoPhoto& p = photo.photo;
|
||||
|
||||
randString(SHORT_STR, p.mCaption);
|
||||
randString(SHORT_STR, p.mCategory);
|
||||
randString(SHORT_STR, p.mDescription);
|
||||
randString(SHORT_STR, p.mHashTags);
|
||||
randString(SHORT_STR, p.mOther);
|
||||
randString(SHORT_STR, p.mPhotographer);
|
||||
randString(SHORT_STR, p.mWhen);
|
||||
randString(SHORT_STR, p.mWhere);
|
||||
randString(SHORT_STR, p.mThumbnail.type);
|
||||
std::string rStr;
|
||||
randString(SHORT_STR, rStr);
|
||||
|
||||
p.mThumbnail.data = new uint8_t[SHORT_STR];
|
||||
memcpy(p.mThumbnail.data, rStr.data(), SHORT_STR);
|
||||
p.mThumbnail.size = SHORT_STR;
|
||||
|
||||
return new RsGxsPhotoSerialiser();
|
||||
}
|
||||
|
||||
bool operator == (RsPhotoThumbnail& l, RsPhotoThumbnail& r)
|
||||
{
|
||||
if(l.size != r.size) return false;
|
||||
if(l.type != r.type) return false;
|
||||
if(memcmp(l.data, r.data,l.size) != 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool operator == (RsGxsPhotoAlbumItem& l, RsGxsPhotoAlbumItem& r)
|
||||
{
|
||||
RsPhotoAlbum& la = l.album;
|
||||
RsPhotoAlbum& ra = r.album;
|
||||
|
||||
if(la.mCaption != ra.mCaption) return false;
|
||||
if(la.mCategory != ra.mCategory) return false;
|
||||
if(la.mDescription != ra.mDescription) return false;
|
||||
if(la.mHashTags != ra.mHashTags) return false;
|
||||
if(la.mOther != ra.mOther) return false;
|
||||
if(la.mPhotographer!= ra.mPhotographer) return false;
|
||||
if(la.mPhotoPath != ra.mPhotoPath) return false;
|
||||
if(la.mWhere != ra.mWhere) return false;
|
||||
if(la.mWhen != ra.mWhen) return false;
|
||||
if(!(la.mThumbnail == ra.mThumbnail)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator == (RsGxsPhotoPhotoItem& l, RsGxsPhotoPhotoItem& r)
|
||||
{
|
||||
RsPhotoPhoto& la = l.photo;
|
||||
RsPhotoPhoto& ra = r.photo;
|
||||
|
||||
if(la.mCaption != ra.mCaption) return false;
|
||||
if(la.mCategory != ra.mCategory) return false;
|
||||
if(la.mDescription != ra.mDescription) return false;
|
||||
if(la.mHashTags != ra.mHashTags) return false;
|
||||
if(la.mOther != ra.mOther) return false;
|
||||
if(la.mPhotographer!= ra.mPhotographer) return false;
|
||||
if(la.mWhere != ra.mWhere) return false;
|
||||
if(la.mWhen != ra.mWhen) return false;
|
||||
if(!(la.mThumbnail == ra.mThumbnail)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, RsPhotoItem_test)
|
||||
{
|
||||
test_RsItem<RsGxsPhotoAlbumItem>();
|
||||
test_RsItem<RsGxsPhotoPhotoItem>();
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* libretroshare/src/tests/serialiser: rsstatusitem_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2010 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 "support.h"
|
||||
#include "serialiser/rsstatusitems.h"
|
||||
|
||||
RsSerialType* init_item(RsStatusItem& rsi)
|
||||
{
|
||||
|
||||
rsi.sendTime = rand()%5353;
|
||||
rsi.status = rand()%2032;
|
||||
return new RsStatusSerialiser();
|
||||
}
|
||||
|
||||
bool operator ==(RsStatusItem& rsi1, RsStatusItem& rsi2)
|
||||
{
|
||||
// note: recv time is not serialised
|
||||
|
||||
if(rsi1.sendTime != rsi2.sendTime) return false;
|
||||
if(rsi1.status != rsi2.status) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsStatusItem)
|
||||
{
|
||||
test_RsItem<RsStatusItem >();
|
||||
}
|
177
tests/unittests/libretroshare/serialiser/rstlvutil.cc
Normal file
177
tests/unittests/libretroshare/serialiser/rstlvutil.cc
Normal file
|
@ -0,0 +1,177 @@
|
|||
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "rstlvutil.h"
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvitem.h"
|
||||
#include "util/rsstring.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];
|
||||
|
||||
EXPECT_TRUE(in->SetTlv(serbuffer, WHOLE_64K_SIZE, &serialOffset));
|
||||
|
||||
EXPECT_TRUE(serialOffset == initsize); /* check that the offset matches the size */
|
||||
EXPECT_TRUE(in->TlvSize() == initsize); /* check size hasn't changed */
|
||||
|
||||
/* now we try to read it back in! */
|
||||
EXPECT_TRUE(out->GetTlv(serbuffer, serialOffset, &deserialOffset));
|
||||
|
||||
/* again check sizes */
|
||||
EXPECT_TRUE(serialOffset == deserialOffset);
|
||||
EXPECT_TRUE(deserialOffset == initsize);
|
||||
EXPECT_TRUE(out->TlvSize() == initsize);
|
||||
|
||||
str << "Class In/Serialised/Out!" << std::endl;
|
||||
in->print(str, 0);
|
||||
displayRawPacket(str, serbuffer, serialOffset);
|
||||
out->print(str, 0);
|
||||
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;
|
||||
}
|
||||
EXPECT_TRUE(offset == size); /* we match up exactly */
|
||||
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;
|
||||
}
|
||||
|
||||
|
48
tests/unittests/libretroshare/serialiser/rstlvutil.h
Normal file
48
tests/unittests/libretroshare/serialiser/rstlvutil.h
Normal 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
|
249
tests/unittests/libretroshare/serialiser/rsturtleitem_test.cc
Normal file
249
tests/unittests/libretroshare/serialiser/rsturtleitem_test.cc
Normal file
|
@ -0,0 +1,249 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsturtleitems_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by 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 <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "turtle/rsturtleitem.h"
|
||||
#include "ft/ftturtlefiletransferitem.h"
|
||||
|
||||
#include "support.h"
|
||||
#include "rstlvutil.h"
|
||||
|
||||
|
||||
RsSerialType* init_item(CompressedChunkMap& map)
|
||||
{
|
||||
map._map.clear() ;
|
||||
for(uint32_t i=0;i<15;++i)
|
||||
map._map.push_back(rand()) ;
|
||||
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const CompressedChunkMap& m1,const CompressedChunkMap& m2)
|
||||
{
|
||||
if(m1._map.size() != m2._map.size()) return false ;
|
||||
|
||||
for(uint32_t i=0;i<m1._map.size();++i)
|
||||
if(m1._map[i] != m2._map[i])
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
bool operator==(const RsTurtleFileMapRequestItem& it1,const RsTurtleFileMapRequestItem& it2)
|
||||
{
|
||||
if(it1.direction != it2.direction) return false ;
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileMapRequestItem& item)
|
||||
{
|
||||
item.direction = 1 ;
|
||||
item.tunnel_id = 0x4ff823e2 ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileMapItem& it1,const RsTurtleFileMapItem& it2)
|
||||
{
|
||||
if(it1.direction != it2.direction) return false ;
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
if(!(it1.compressed_map == it2.compressed_map)) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileMapItem& item)
|
||||
{
|
||||
item.direction = 1 ;
|
||||
item.tunnel_id = 0xf48fe232 ;
|
||||
init_item(item.compressed_map) ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileDataItem& item)
|
||||
{
|
||||
static const uint32_t S = 3456 ;
|
||||
item.tunnel_id = 0x33eef982 ;
|
||||
item.chunk_offset = 0x25ea228437894379ull ;
|
||||
item.chunk_size = S ;
|
||||
item.chunk_data = new unsigned char[S] ;
|
||||
for(uint32_t i=0;i<S;++i)
|
||||
((unsigned char *)item.chunk_data)[i] = rand()%256 ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileDataItem& i1,const RsTurtleFileDataItem& i2)
|
||||
{
|
||||
if(i1.tunnel_id != i2.tunnel_id) return false ;
|
||||
if(i1.chunk_offset != i2.chunk_offset) return false ;
|
||||
if(i1.chunk_size != i2.chunk_size) return false ;
|
||||
for(uint32_t i=0;i<i1.chunk_size;++i)
|
||||
if( ((unsigned char *)i1.chunk_data)[i] != ((unsigned char *)i2.chunk_data)[i])
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleFileRequestItem& item)
|
||||
{
|
||||
item.tunnel_id = rand() ;
|
||||
item.chunk_offset = 0x25ea228437894379ull ;
|
||||
item.chunk_size = rand() ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleFileRequestItem& it1,const RsTurtleFileRequestItem& it2)
|
||||
{
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
if(it1.chunk_offset != it2.chunk_offset) return false ;
|
||||
if(it1.chunk_size != it2.chunk_size) return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleTunnelOkItem& item)
|
||||
{
|
||||
item.tunnel_id = rand() ;
|
||||
item.request_id = rand() ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleTunnelOkItem& it1,const RsTurtleTunnelOkItem& it2)
|
||||
{
|
||||
if(it1.tunnel_id != it2.tunnel_id) return false ;
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleOpenTunnelItem& item)
|
||||
{
|
||||
item.depth = rand() ;
|
||||
item.request_id = rand() ;
|
||||
item.partial_tunnel_id = rand() ;
|
||||
item.file_hash = std::string("c0edcfecc0844ef175d61dd589ab288d262b6bc8") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleOpenTunnelItem& it1,const RsTurtleOpenTunnelItem& it2)
|
||||
{
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.partial_tunnel_id != it2.partial_tunnel_id) return false ;
|
||||
if(it1.file_hash != it2.file_hash) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleRegExpSearchRequestItem& item)
|
||||
{
|
||||
item.request_id = rand() ;
|
||||
item.depth = rand() ;
|
||||
item.expr._tokens.clear() ;
|
||||
item.expr._ints.clear() ;
|
||||
item.expr._strings.clear() ;
|
||||
|
||||
for(uint32_t i=0;i<10u;++i) item.expr._tokens.push_back(rand()%8) ;
|
||||
for(uint32_t i=0;i<6u;++i) item.expr._ints.push_back(rand()) ;
|
||||
for(uint32_t i=0;i<8u;++i) item.expr._strings.push_back("test string") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleRegExpSearchRequestItem& it1,const RsTurtleRegExpSearchRequestItem& it2)
|
||||
{
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
if(it1.expr._tokens.size() != it2.expr._tokens.size()) return false ;
|
||||
if(it1.expr._ints.size() != it2.expr._ints.size()) return false ;
|
||||
if(it1.expr._strings.size() != it2.expr._strings.size()) return false ;
|
||||
for(uint32_t i=0;i<it1.expr._tokens.size();++i) if(it1.expr._tokens[i] != it2.expr._tokens[i]) return false ;
|
||||
for(uint32_t i=0;i<it1.expr._ints.size();++i) if(it1.expr._ints[i] != it2.expr._ints[i]) return false ;
|
||||
for(uint32_t i=0;i<it1.expr._strings.size();++i) if(it1.expr._strings[i] != it2.expr._strings[i]) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleStringSearchRequestItem& item)
|
||||
{
|
||||
item.request_id = rand() ;
|
||||
item.depth = rand() ;
|
||||
item.match_string = std::string("432hkjfdsjkhjk43r3fw") ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleStringSearchRequestItem& it1,const RsTurtleStringSearchRequestItem& it2)
|
||||
{
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
if(it1.match_string != it2.match_string)
|
||||
return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(TurtleFileInfo& info)
|
||||
{
|
||||
info.hash = "3f753e8ac3b94ab9fddfad94480f747bf4418370";
|
||||
info.name = "toto.png";
|
||||
info.size = 0x3392085443897ull ;
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const TurtleFileInfo& it1,const TurtleFileInfo& it2)
|
||||
{
|
||||
if(it1.hash != it2.hash) return false ;
|
||||
if(it1.name != it2.name) return false ;
|
||||
if(it1.size != it2.size) return false ;
|
||||
return true ;
|
||||
}
|
||||
RsSerialType* init_item(RsTurtleSearchResultItem& item)
|
||||
{
|
||||
item.depth = rand() ;
|
||||
item.request_id = rand() ;
|
||||
item.result.clear() ;
|
||||
static const uint32_t S = 10 ;
|
||||
for(uint32_t i=0;i<S;++i)
|
||||
{
|
||||
TurtleFileInfo f;
|
||||
init_item(f) ;
|
||||
item.result.push_back(f) ;
|
||||
}
|
||||
return new RsTurtleSerialiser();
|
||||
}
|
||||
bool operator==(const RsTurtleSearchResultItem& it1,const RsTurtleSearchResultItem& it2)
|
||||
{
|
||||
if(it1.request_id != it2.request_id) return false ;
|
||||
if(it1.depth != it2.depth) return false ;
|
||||
|
||||
std::list<TurtleFileInfo>::const_iterator i1(it1.result.begin()) ;
|
||||
std::list<TurtleFileInfo>::const_iterator i2(it2.result.begin()) ;
|
||||
|
||||
for(;i1!=it1.result.end() && i2!=it2.result.end();++i1,++i2)
|
||||
if( !(*i1 == *i2))
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, RsTurtleItem)
|
||||
{
|
||||
for(uint32_t i=0;i<20;++i)
|
||||
{
|
||||
//test_RsItem<RsTurtleFileMapRequestItem>();
|
||||
//test_RsItem<RsTurtleFileMapItem >();
|
||||
//test_RsItem<RsTurtleFileDataItem >();
|
||||
//test_RsItem<RsTurtleFileRequestItem >();
|
||||
test_RsItem<RsTurtleTunnelOkItem >();
|
||||
test_RsItem<RsTurtleOpenTunnelItem >();
|
||||
test_RsItem<RsTurtleSearchResultItem >();
|
||||
test_RsItem<RsTurtleStringSearchRequestItem >();
|
||||
test_RsItem<RsTurtleRegExpSearchRequestItem >();
|
||||
}
|
||||
}
|
||||
|
||||
|
328
tests/unittests/libretroshare/serialiser/support.cc
Normal file
328
tests/unittests/libretroshare/serialiser/support.cc
Normal file
|
@ -0,0 +1,328 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
void init_item(RsTlvSecurityKeySet& ks)
|
||||
{
|
||||
int n = rand()%24;
|
||||
randString(SHORT_STR, ks.groupId);
|
||||
for(int i=1; i<n; i++)
|
||||
{
|
||||
std::string a_str;
|
||||
randString(SHORT_STR, a_str);
|
||||
|
||||
RsTlvSecurityKey& a_key = ks.keys[a_str];
|
||||
init_item(a_key);
|
||||
a_key.keyId = a_str;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvSecurityKeySet& l, const RsTlvSecurityKeySet& r)
|
||||
{
|
||||
|
||||
if(l.groupId != r.groupId) return false;
|
||||
|
||||
std::map<std::string, RsTlvSecurityKey>::const_iterator l_cit = l.keys.begin(),
|
||||
r_cit = r.keys.begin();
|
||||
|
||||
for(; l_cit != l.keys.end(); l_cit++, r_cit++){
|
||||
if(l_cit->first != r_cit->first) return false;
|
||||
if(!(l_cit->second == r_cit->second)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 RsTlvKeySignatureSet& kss1, const RsTlvKeySignatureSet& kss2)
|
||||
{
|
||||
const std::map<SignType, RsTlvKeySignature>& set1 = kss1.keySignSet,
|
||||
&set2 = kss2.keySignSet;
|
||||
|
||||
if(set1.size() != set2.size()) return false;
|
||||
|
||||
std::map<SignType, RsTlvKeySignature>::const_iterator it1 = set1.begin(), it2;
|
||||
|
||||
for(; it1 != set1.end(); it1++)
|
||||
{
|
||||
SignType st1 = it1->first;
|
||||
|
||||
if( (it2 =set2.find(st1)) == set2.end())
|
||||
return false;
|
||||
|
||||
if(!(it1->second == it2->second))
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvPeerIdSet& pids1, const RsTlvPeerIdSet& pids2)
|
||||
{
|
||||
std::list<RsPeerId>::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;
|
||||
}
|
||||
void init_item(RsTlvKeySignatureSet &kss)
|
||||
{
|
||||
int numSign = rand()%21;
|
||||
|
||||
for(int i=0; i < numSign; i++)
|
||||
{
|
||||
RsTlvKeySignature sign;
|
||||
SignType sType = rand()%2452;
|
||||
init_item(sign);
|
||||
kss.keySignSet.insert(std::make_pair(sType, sign));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
for(int i=0; i < 10; i++)
|
||||
hs.ids.push_back(RsFileHash::random());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void init_item(RsTlvPeerIdSet& ps)
|
||||
{
|
||||
for(int i=0; i < 10; i++)
|
||||
ps.ids.push_back(RsPeerId::random());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool operator==(const RsTlvHashSet& hs1,const RsTlvHashSet& hs2)
|
||||
{
|
||||
std::list<RsFileHash>::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;
|
||||
fi.hash = RsFileHash::random();
|
||||
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;
|
||||
}
|
246
tests/unittests/libretroshare/serialiser/support.h
Normal file
246
tests/unittests/libretroshare/serialiser/support.h
Normal file
|
@ -0,0 +1,246 @@
|
|||
#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 <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvimage.h"
|
||||
|
||||
#include "rstlvutil.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(RsTlvSecurityKeySet&);
|
||||
void init_item(RsTlvKeySignature&);
|
||||
void init_item(RsTlvKeySignatureSet&);
|
||||
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 RsTlvSecurityKeySet&, const RsTlvSecurityKeySet& );
|
||||
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& );
|
||||
bool operator==(const RsTlvKeySignatureSet& , const RsTlvKeySignatureSet& );
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* 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 */
|
||||
|
||||
EXPECT_TRUE(0 == srl.size(&rsfi));
|
||||
|
||||
static const uint32_t MAX_BUFSIZE = 22000 ;
|
||||
|
||||
char *buffer = new char[MAX_BUFSIZE];
|
||||
uint32_t sersize = MAX_BUFSIZE;
|
||||
|
||||
EXPECT_TRUE(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);
|
||||
|
||||
EXPECT_TRUE(done == true);
|
||||
|
||||
uint32_t sersize2 = sersize;
|
||||
RsItem *output = srl.deserialise((void *) buffer, &sersize2);
|
||||
|
||||
EXPECT_TRUE(output != NULL);
|
||||
if (!output)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
EXPECT_TRUE(sersize2 == sersize);
|
||||
|
||||
T *outfi = dynamic_cast<T *>(output);
|
||||
|
||||
EXPECT_TRUE(outfi != NULL);
|
||||
if (!outfi)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!(*outfi == rsfi))
|
||||
{
|
||||
std::cerr << "Items differ: "<< std::endl;
|
||||
outfi->print(std::cerr,0) ;
|
||||
rsfi.print(std::cerr,0) ;
|
||||
}
|
||||
if (outfi)
|
||||
EXPECT_TRUE(*outfi == rsfi) ;
|
||||
|
||||
|
||||
sersize2 = MAX_BUFSIZE;
|
||||
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||
|
||||
EXPECT_TRUE(done2) ;
|
||||
EXPECT_TRUE(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 */
|
||||
|
||||
EXPECT_TRUE(0 == srl.size(&rsfi));
|
||||
|
||||
static const uint32_t MAX_BUFSIZE = 22000 ;
|
||||
|
||||
char *buffer = new char[MAX_BUFSIZE];
|
||||
uint32_t sersize = MAX_BUFSIZE;
|
||||
|
||||
EXPECT_TRUE(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);
|
||||
|
||||
EXPECT_TRUE(done == true);
|
||||
|
||||
uint32_t sersize2 = sersize;
|
||||
RsItem *output = srl.deserialise((void *) buffer, &sersize2);
|
||||
|
||||
EXPECT_TRUE(output != NULL);
|
||||
EXPECT_TRUE(sersize2 == sersize);
|
||||
|
||||
T *outfi = dynamic_cast<T *>(output);
|
||||
|
||||
EXPECT_TRUE(outfi != NULL);
|
||||
|
||||
if (outfi)
|
||||
EXPECT_TRUE(*outfi == rsfi) ;
|
||||
|
||||
sersize2 = MAX_BUFSIZE;
|
||||
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||
|
||||
EXPECT_TRUE(done2) ;
|
||||
EXPECT_TRUE(sersize2 == sersize);
|
||||
|
||||
// displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||
|
||||
delete[] buffer ;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* SUPPORT_H_ */
|
172
tests/unittests/libretroshare/serialiser/tlvbase_test.cc
Normal file
172
tests/unittests/libretroshare/serialiser/tlvbase_test.cc
Normal file
|
@ -0,0 +1,172 @@
|
|||
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <limits.h>
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "util/rsnet.h"
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvBase)
|
||||
{
|
||||
//uint32_t array[] = {0x122, 0x234};
|
||||
char data[20];
|
||||
memset((void*)data, 65, sizeof(data)); // In ASCII 'A' =65
|
||||
|
||||
|
||||
std::string out;
|
||||
|
||||
// First two bytes are type.
|
||||
data[0]=0;
|
||||
data[1]=0;
|
||||
// Next 4 bytes is size.
|
||||
data[2]=0;
|
||||
data[3]=0;
|
||||
data[4]=0;
|
||||
data[5]=10;
|
||||
uint32_t off =0;
|
||||
GetTlvString((void*)data, 20, &off, 0, out);
|
||||
|
||||
EXPECT_TRUE(out == "AAAA");
|
||||
|
||||
std::cout << "Output is : " << out << std::endl;
|
||||
|
||||
uint16_t data2[] = {0, 0, 0x0300};
|
||||
|
||||
uint16_t t = GetTlvSize((void*) data2);
|
||||
|
||||
|
||||
EXPECT_TRUE( t == ntohs(0x0300));
|
||||
|
||||
//std::cout << "GetTlvSize = " <<t <<std::endl;
|
||||
|
||||
|
||||
std::string line;
|
||||
|
||||
|
||||
//*************Test SetTlvBase***********
|
||||
{
|
||||
uint16_t data3 [3];
|
||||
off =0;
|
||||
uint32_t *offset = &off;
|
||||
uint32_t const SIZE_SetTlvBase=6;
|
||||
uint32_t val_before = *offset;
|
||||
uint32_t base_set_size = 0x1234567;
|
||||
SetTlvBase((void *)data3, SIZE_SetTlvBase, offset, 0x0011, base_set_size);
|
||||
|
||||
EXPECT_TRUE(*offset - val_before == SIZE_SetTlvBase);
|
||||
EXPECT_TRUE(0x0011 == ntohs(data3[0]));
|
||||
EXPECT_TRUE(base_set_size == ntohl(*((uint32_t *) &(data3[1]))));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test GetTlvUInt32 & SetTlvGetUInt32
|
||||
*/
|
||||
{
|
||||
uint16_t data4[5];
|
||||
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, 10, offset, 0x0011, out);
|
||||
EXPECT_TRUE(*offset - pre_set_off == 10);
|
||||
|
||||
uint32_t readPos = 0;
|
||||
offset = &readPos;
|
||||
uint32_t in =0;
|
||||
ok &= GetTlvUInt32((void*)data4, 10, offset, 0x0011, &in);
|
||||
EXPECT_TRUE(*offset - pre_set_off == 10);
|
||||
EXPECT_TRUE(in == out);
|
||||
|
||||
std::cerr<<"in = " <<in <<std::endl;
|
||||
std::cout << "*offset = " <<*offset <<std::endl;
|
||||
std::cout <<std::hex << data4[3]<< " " <<data4[4] <<std::endl;
|
||||
}
|
||||
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < UINT_MAX / 2; i *= 2, i += 111)
|
||||
{
|
||||
uint16_t data4[5];
|
||||
data4[0] = htons(5); /* type */
|
||||
*((uint32_t *) &(data4[1])) = htonl(10); /* length */
|
||||
uint32_t int_val = i;
|
||||
*((uint32_t *) &(data4[3])) = htonl(int_val); /* value */
|
||||
uint32_t got;
|
||||
uint32_t off = 0;
|
||||
uint32_t *offset = &off;
|
||||
GetTlvUInt32((void*)data4, 10, offset, 5, &got);
|
||||
EXPECT_TRUE(got == int_val);
|
||||
std::cout << " got = " << std::hex << got <<std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test GetTlvString()
|
||||
*/
|
||||
{
|
||||
std::string teststring = "Hello RS!";
|
||||
uint16_t data5[6 + 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);
|
||||
uint32_t tlvsize = GetTlvStringSize(teststring);
|
||||
EXPECT_TRUE(tlvsize == *offset);
|
||||
EXPECT_TRUE(data5[0] == htons(TLV_TYPE_STR_NAME));
|
||||
uint32_t encoded_size = ntohl(*((uint32_t *) &(data5[1])));
|
||||
EXPECT_TRUE(tlvsize == encoded_size);
|
||||
std::cerr << "tlvsize: " << tlvsize << " encoded_size: " << encoded_size;
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::string str((char*) ((char*)data5 +6) ,strlen("Hello RS!"));
|
||||
EXPECT_TRUE(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);
|
||||
EXPECT_TRUE(out_str == "Hello RS!");
|
||||
EXPECT_TRUE(*offset == sizeof(uint16_t)*3 + out_str.size());
|
||||
uint16_t data6[3];
|
||||
*offset =0;
|
||||
EXPECT_TRUE(SetTlvSize((void*)data6, sizeof(data6), 0x00000022));
|
||||
std::cout << std::hex << data6[1] <<std::endl;
|
||||
|
||||
}
|
||||
}
|
158
tests/unittests/libretroshare/serialiser/tlvbase_test2.cc
Normal file
158
tests/unittests/libretroshare/serialiser/tlvbase_test2.cc
Normal file
|
@ -0,0 +1,158 @@
|
|||
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "rstlvutil.h"
|
||||
#include "util/rsnet.h"
|
||||
|
||||
|
||||
int test_OneString(std::string input, uint16_t type);
|
||||
|
||||
TEST(libretroshare_serialiser, 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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
EXPECT_TRUE(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);
|
||||
|
||||
EXPECT_TRUE(outOffset == initsize); /* check that the offset matches the size */
|
||||
|
||||
std::cerr << "DeSerialising" << std::endl;
|
||||
|
||||
/* fails if type is wrong! */
|
||||
EXPECT_TRUE(0 == GetTlvString((void*)tlvdata, outOffset, &inOffset, type-1, OutString));
|
||||
EXPECT_TRUE(GetTlvString((void*)tlvdata, outOffset, &inOffset, type, OutString));
|
||||
|
||||
EXPECT_TRUE(initsize == inOffset); /* check that the offset matches the size */
|
||||
EXPECT_TRUE(input == OutString); /* check that strings match */
|
||||
std::cerr << "Deserialised: Size: " << inOffset << std::endl;
|
||||
std::cerr << "Deserialised: String: " << OutString << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test_IpAddr(struct sockaddr_in *addr, uint16_t type);
|
||||
|
||||
TEST(libretroshare_serialiser, 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(1);
|
||||
|
||||
test_IpAddr(&addr, 1234);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
EXPECT_TRUE(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);
|
||||
|
||||
EXPECT_TRUE(outOffset == initsize); /* check that the offset matches the size */
|
||||
|
||||
std::cerr << "DeSerialising" << std::endl;
|
||||
|
||||
/* fails if type is wrong! */
|
||||
EXPECT_TRUE(0 == GetTlvIpAddrPortV4((void*)tlvdata, outOffset, &inOffset, type-1, &outaddr));
|
||||
EXPECT_TRUE(GetTlvIpAddrPortV4((void*)tlvdata, outOffset, &inOffset, type, &outaddr));
|
||||
|
||||
EXPECT_TRUE(initsize == inOffset); /* check that the offset matches the size */
|
||||
EXPECT_TRUE(addr->sin_addr.s_addr == outaddr.sin_addr.s_addr); /* check that IP match */
|
||||
EXPECT_TRUE(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;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
66
tests/unittests/libretroshare/serialiser/tlvitems_test.cc
Normal file
66
tests/unittests/libretroshare/serialiser/tlvitems_test.cc
Normal file
|
@ -0,0 +1,66 @@
|
|||
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
|
||||
#include "rstlvutil.h"
|
||||
|
||||
#define BIN_LEN 65536 /* bigger than 64k */
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvBinData2)
|
||||
{
|
||||
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);
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &d1, &d2));
|
||||
|
||||
EXPECT_TRUE(d1.bin_len == d2.bin_len);
|
||||
EXPECT_TRUE(0 == memcmp(d1.bin_data, d2.bin_data, d1.bin_len));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
24
tests/unittests/libretroshare/serialiser/tlvkey_test.cc
Normal file
24
tests/unittests/libretroshare/serialiser/tlvkey_test.cc
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "support.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvKeySignatureSet)
|
||||
{
|
||||
RsTlvKeySignatureSet set;
|
||||
|
||||
init_item(set);
|
||||
|
||||
char data[set.TlvSize()];
|
||||
uint32_t offset = 0;
|
||||
set.SetTlv(data, set.TlvSize(), &offset);
|
||||
|
||||
RsTlvKeySignatureSet setConfirm;
|
||||
|
||||
offset = 0;
|
||||
setConfirm.GetTlv(data, set.TlvSize(), &offset);
|
||||
|
||||
EXPECT_TRUE(setConfirm == set);
|
||||
|
||||
}
|
184
tests/unittests/libretroshare/serialiser/tlvrandom_test.cc
Normal file
184
tests/unittests/libretroshare/serialiser/tlvrandom_test.cc
Normal file
|
@ -0,0 +1,184 @@
|
|||
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvkeyvalue.h"
|
||||
#include "serialiser/rstlvimage.h"
|
||||
#include "rstlvutil.h"
|
||||
|
||||
#define TEST_LENGTH 10
|
||||
|
||||
|
||||
#define BIN_LEN 523456 /* bigger than 64k */
|
||||
|
||||
bool test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset);
|
||||
bool 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;
|
||||
|
||||
RsTlvImage image;
|
||||
|
||||
/* try to decode - with all types first */
|
||||
std::cerr << "test_TlvRandom:: Testing Files " << std::endl;
|
||||
EXPECT_TRUE(test_TlvItem(&bindata, data, len, offset));
|
||||
EXPECT_TRUE(test_TlvItem(&fileitem, data, len, offset));
|
||||
EXPECT_TRUE(test_TlvItem(&fileset, data, len, offset));
|
||||
EXPECT_TRUE(test_TlvItem(&filedata, data, len, offset));
|
||||
std::cerr << "test_TlvRandom:: Testing Sets " << std::endl;
|
||||
EXPECT_TRUE(test_TlvItem(&peerset, data, len, offset));
|
||||
EXPECT_TRUE(test_TlvItem(&servset, data, len, offset));
|
||||
EXPECT_TRUE(test_TlvItem(&kv, data, len, offset));
|
||||
EXPECT_TRUE(test_TlvItem(&kvset, data, len, offset));
|
||||
std::cerr << "test_TlvRandom:: Testing Keys " << std::endl;
|
||||
EXPECT_TRUE(test_TlvItem(&skey, data, len, offset));
|
||||
EXPECT_TRUE(test_TlvItem(&skeyset, data, len, offset));
|
||||
EXPECT_TRUE(test_TlvItem(&keysign, data, len, offset));
|
||||
|
||||
/* now set the type correctly before decoding */
|
||||
std::cerr << "test_TlvRandom:: Testing Files (TYPESET)" << std::endl;
|
||||
EXPECT_TRUE(test_SetTlvItem(&bindata, TLV_TYPE_IMAGE, data, len, offset));
|
||||
EXPECT_TRUE(test_SetTlvItem(&fileitem,TLV_TYPE_FILEITEM, data, len, offset));
|
||||
EXPECT_TRUE(test_SetTlvItem(&fileset, TLV_TYPE_FILESET, data, len, offset));
|
||||
EXPECT_TRUE(test_SetTlvItem(&filedata, TLV_TYPE_FILEDATA, data, len, offset));
|
||||
std::cerr << "test_TlvRandom:: Testing Sets (TYPESET)" << std::endl;
|
||||
EXPECT_TRUE(test_SetTlvItem(&peerset, TLV_TYPE_PEERSET, data, len, offset));
|
||||
EXPECT_TRUE(test_SetTlvItem(&servset, TLV_TYPE_SERVICESET, data, len, offset));
|
||||
EXPECT_TRUE(test_SetTlvItem(&kv, TLV_TYPE_KEYVALUE, data, len, offset));
|
||||
EXPECT_TRUE(test_SetTlvItem(&kvset, TLV_TYPE_KEYVALUESET, data, len, offset));
|
||||
std::cerr << "test_TlvRandom:: Testing Keys (TYPESET)" << std::endl;
|
||||
EXPECT_TRUE(test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY, data, len, offset));
|
||||
EXPECT_TRUE(test_SetTlvItem(&skeyset, TLV_TYPE_SECURITYKEYSET, data, len, offset));
|
||||
EXPECT_TRUE(test_SetTlvItem(&keysign, TLV_TYPE_KEYSIGNATURE, data, len, offset));
|
||||
|
||||
return 26; /* number of tests */
|
||||
}
|
||||
|
||||
bool 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);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "TLV failed to decode";
|
||||
std::cerr << std::endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool 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);
|
||||
}
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvRandom)
|
||||
{
|
||||
/* random data array to work through */
|
||||
uint32_t dsize = 100000;
|
||||
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;
|
||||
|
||||
srand(startTs);
|
||||
for(i = 0; i < dsize; i++)
|
||||
{
|
||||
data[i] = rand() % 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;
|
||||
}
|
||||
}
|
87
tests/unittests/libretroshare/serialiser/tlvstack_test.cc
Normal file
87
tests/unittests/libretroshare/serialiser/tlvstack_test.cc
Normal file
|
@ -0,0 +1,87 @@
|
|||
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvbinary.h"
|
||||
|
||||
#include "rstlvutil.h"
|
||||
|
||||
#define BIN_LEN 1024
|
||||
|
||||
TEST(libretroshare_serialiser, 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);
|
||||
}
|
||||
|
||||
|
303
tests/unittests/libretroshare/serialiser/tlvtypes_test.cc
Normal file
303
tests/unittests/libretroshare/serialiser/tlvtypes_test.cc
Normal file
|
@ -0,0 +1,303 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: tlvfileitem_test.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie, Chris 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 <gtest/gtest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#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/rstlvbase.h"
|
||||
|
||||
#include "rstlvutil.h"
|
||||
|
||||
#define RAND_SEED 1352534
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvFileItem)
|
||||
{
|
||||
RsTlvFileItem i1;
|
||||
RsTlvFileItem i2;
|
||||
|
||||
/* initialise */
|
||||
i1.filesize = 101010;
|
||||
i1.hash = "ABCDEFEGHE";
|
||||
i1.name = "TestFile.txt";
|
||||
i1.pop = 12;
|
||||
i1.age = 456;
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
EXPECT_TRUE(i1.filesize == i2.filesize);
|
||||
EXPECT_TRUE(i1.hash == i2.hash);
|
||||
EXPECT_TRUE(i1.name == i2.name);
|
||||
EXPECT_TRUE(i1.path == i2.path);
|
||||
EXPECT_TRUE(i1.pop == i2.pop);
|
||||
EXPECT_TRUE(i1.age == i2.age);
|
||||
|
||||
/* do it again without optional data */
|
||||
i1.filesize = 123;
|
||||
i1.name = "";
|
||||
i1.pop = 0;
|
||||
i1.age = 0;
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
EXPECT_TRUE(i1.filesize == i2.filesize);
|
||||
EXPECT_TRUE(i1.hash == i2.hash);
|
||||
EXPECT_TRUE(i1.name == i2.name);
|
||||
EXPECT_TRUE(i1.path == i2.path);
|
||||
EXPECT_TRUE(i1.pop == i2.pop);
|
||||
EXPECT_TRUE(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;
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
|
||||
/* check the data is the same */
|
||||
EXPECT_TRUE(i1.filesize == i2.filesize);
|
||||
EXPECT_TRUE(i1.hash == i2.hash);
|
||||
EXPECT_TRUE(i1.name == i2.name);
|
||||
EXPECT_TRUE(i1.path == i2.path);
|
||||
EXPECT_TRUE(i1.pop == i2.pop);
|
||||
EXPECT_TRUE(i1.age == i2.age);
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, 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);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &s1, &s2));
|
||||
}
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, 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;
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &d1, &d2));
|
||||
|
||||
/* check the data is the same */
|
||||
EXPECT_TRUE(d1.file.filesize == d2.file.filesize);
|
||||
EXPECT_TRUE(d1.file.hash == d2.file.hash);
|
||||
EXPECT_TRUE(d1.file.name == d2.file.name);
|
||||
EXPECT_TRUE(d1.file.path == d2.file.path);
|
||||
EXPECT_TRUE(d1.file.pop == d2.file.pop);
|
||||
EXPECT_TRUE(d1.file.age == d2.file.age);
|
||||
|
||||
EXPECT_TRUE(d1.file_offset == d2.file_offset);
|
||||
EXPECT_TRUE(d1.binData.bin_len == d2.binData.bin_len);
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvPeerIdSet)
|
||||
{
|
||||
|
||||
RsTlvPeerIdSet i1, i2; // one to set and other to get
|
||||
|
||||
RsPeerId testId;
|
||||
|
||||
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++)
|
||||
{
|
||||
testId.random();
|
||||
i1.ids.push_back(testId);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvServiceIdSet)
|
||||
{
|
||||
RsTlvServiceIdSet i1, i2; // one to set and other to get
|
||||
srand(RAND_SEED);
|
||||
|
||||
|
||||
/* store random numbers */
|
||||
for(int i = 0; i < 15 ; i++)
|
||||
{
|
||||
i1.ids.push_back(1 + rand() % 12564);
|
||||
}
|
||||
std::cout << "error here!!!?";
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvKeyValue)
|
||||
{
|
||||
RsTlvKeyValue i1, i2; // one to set and other to get
|
||||
|
||||
i1.key = "whatever";
|
||||
i1.value = "better work";
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvKeyValueSet)
|
||||
{
|
||||
RsTlvKeyValueSet i1, i2; // one to set and other to get
|
||||
srand(RAND_SEED);
|
||||
|
||||
/* 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);
|
||||
|
||||
}
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvBinData)
|
||||
{
|
||||
RsTlvBinaryData b1(TLV_TYPE_BIN_IMAGE), b2(TLV_TYPE_BIN_IMAGE);
|
||||
unsigned char* data = NULL;
|
||||
const uint32_t bin_size = 16000;
|
||||
char alpha = 'a';
|
||||
|
||||
data = new unsigned char[bin_size];
|
||||
srand(RAND_SEED);
|
||||
|
||||
|
||||
// initialise binary data with random values
|
||||
for(int i=0; i != bin_size; i++)
|
||||
data[i] = alpha + (rand() % 26);
|
||||
|
||||
|
||||
b1.setBinData(data, bin_size);
|
||||
delete data;
|
||||
|
||||
//do check
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &b1, &b2));
|
||||
}
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvImage)
|
||||
{
|
||||
|
||||
RsTlvImage image1, image2;
|
||||
unsigned char* image_data = NULL;
|
||||
const uint32_t bin_size = 16000;
|
||||
char alpha = 'a';
|
||||
|
||||
image_data = new unsigned char[bin_size];
|
||||
srand(RAND_SEED);
|
||||
|
||||
|
||||
// initialise binary data with random values
|
||||
for(int i=0; i != bin_size; i++)
|
||||
image_data[i] = alpha + (rand() % 26);
|
||||
|
||||
image1.image_type = RSTLV_IMAGE_TYPE_PNG;
|
||||
image1.binData.setBinData(image_data, bin_size);
|
||||
|
||||
delete image_data;
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &image1, &image2));
|
||||
}
|
||||
|
||||
|
||||
TEST(libretroshare_serialiser, test_RsTlvHashSet)
|
||||
{
|
||||
RsTlvPeerIdSet i1, i2; // one to set and other to get
|
||||
srand(RAND_SEED);
|
||||
|
||||
int numRandStrings = rand()%30;
|
||||
|
||||
/* store a number of random ids */
|
||||
|
||||
for(int i = 0; i < numRandStrings ; i++)
|
||||
{
|
||||
RsPeerId randId;
|
||||
randId.random();
|
||||
i1.ids.push_back(randId);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||
}
|
8
tests/unittests/unittests.cc
Normal file
8
tests/unittests/unittests.cc
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
|
306
tests/unittests/unittests.pro
Normal file
306
tests/unittests/unittests.pro
Normal file
|
@ -0,0 +1,306 @@
|
|||
QT += network xml script
|
||||
CONFIG += bitdht
|
||||
|
||||
CONFIG += gxs debug
|
||||
|
||||
LIBS += -lgtest
|
||||
|
||||
gxs {
|
||||
DEFINES += RS_ENABLE_GXS
|
||||
}
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = unittests
|
||||
|
||||
################################# Linux ##########################################
|
||||
# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib
|
||||
linux-* {
|
||||
#CONFIG += version_detail_bash_script
|
||||
QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64
|
||||
|
||||
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a
|
||||
PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a
|
||||
|
||||
LIBS += ../../libretroshare/src/lib/libretroshare.a
|
||||
LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2
|
||||
LIBS += -lssl -lupnp -lixml -lXss -lgnome-keyring
|
||||
LIBS *= -lcrypto -ldl -lX11 -lz
|
||||
|
||||
gxs {
|
||||
LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a
|
||||
|
||||
# We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database.
|
||||
LIBS += ../../../lib/sqlcipher/.libs/libsqlcipher.a
|
||||
}
|
||||
|
||||
LIBS *= -lglib-2.0
|
||||
LIBS *= -rdynamic
|
||||
DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions
|
||||
DEFINES *= UBUNTU
|
||||
}
|
||||
|
||||
linux-g++ {
|
||||
OBJECTS_DIR = temp/linux-g++/obj
|
||||
}
|
||||
|
||||
linux-g++-64 {
|
||||
OBJECTS_DIR = temp/linux-g++-64/obj
|
||||
}
|
||||
|
||||
#################### Cross compilation for windows under Linux ###################
|
||||
|
||||
win32-x-g++ {
|
||||
OBJECTS_DIR = temp/win32-x-g++/obj
|
||||
|
||||
LIBS += ../../libretroshare/src/lib.win32xgcc/libretroshare.a
|
||||
LIBS += ../../../../lib/win32-x-g++-v0.5/libssl.a
|
||||
LIBS += ../../../../lib/win32-x-g++-v0.5/libcrypto.a
|
||||
LIBS += ../../../../lib/win32-x-g++-v0.5/libgpgme.dll.a
|
||||
LIBS += ../../../../lib/win32-x-g++-v0.5/libminiupnpc.a
|
||||
LIBS += ../../../../lib/win32-x-g++-v0.5/libz.a
|
||||
LIBS += -L${HOME}/.wine/drive_c/pthreads/lib -lpthreadGCE2
|
||||
LIBS += -lQtUiTools
|
||||
LIBS += -lws2_32 -luuid -lole32 -liphlpapi -lcrypt32 -gdi32
|
||||
LIBS += -lole32 -lwinmm
|
||||
|
||||
DEFINES *= WINDOWS_SYS WIN32 WIN32_CROSS_UBUNTU
|
||||
|
||||
INCLUDEPATH += ../../../../gpgme-1.1.8/src/
|
||||
INCLUDEPATH += ../../../../libgpg-error-1.7/src/
|
||||
|
||||
RC_FILE = gui/images/retroshare_win.rc
|
||||
}
|
||||
|
||||
#################################### Windows #####################################
|
||||
|
||||
win32 {
|
||||
# Switch on extra warnings
|
||||
QMAKE_CFLAGS += -Wextra
|
||||
QMAKE_CXXFLAGS += -Wextra
|
||||
|
||||
# Switch off optimization for release version
|
||||
QMAKE_CXXFLAGS_RELEASE -= -O2
|
||||
QMAKE_CXXFLAGS_RELEASE += -O0
|
||||
QMAKE_CFLAGS_RELEASE -= -O2
|
||||
QMAKE_CFLAGS_RELEASE += -O0
|
||||
|
||||
# Switch on optimization for debug version
|
||||
#QMAKE_CXXFLAGS_DEBUG += -O2
|
||||
#QMAKE_CFLAGS_DEBUG += -O2
|
||||
|
||||
OBJECTS_DIR = temp/obj
|
||||
#LIBS += -L"D/Qt/2009.03/qt/plugins/imageformats"
|
||||
#QTPLUGIN += qjpeg
|
||||
|
||||
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a
|
||||
PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a
|
||||
|
||||
LIBS += ../../libretroshare/src/lib/libretroshare.a
|
||||
LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2
|
||||
LIBS += -L"$$PWD/../../../lib"
|
||||
|
||||
gxs {
|
||||
LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a
|
||||
LIBS += -lsqlcipher
|
||||
}
|
||||
|
||||
LIBS += -lssl -lcrypto -lpthread -lminiupnpc -lz
|
||||
# added after bitdht
|
||||
# LIBS += -lws2_32
|
||||
LIBS += -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lgdi32
|
||||
LIBS += -lole32 -lwinmm
|
||||
RC_FILE = gui/images/retroshare_win.rc
|
||||
|
||||
# export symbols for the plugins
|
||||
LIBS += -Wl,--export-all-symbols,--out-implib,lib/libretroshare-gui.a
|
||||
|
||||
# create lib directory
|
||||
QMAKE_PRE_LINK = $(CHK_DIR_EXISTS) lib $(MKDIR) lib
|
||||
|
||||
DEFINES *= WINDOWS_SYS WIN32_LEAN_AND_MEAN _USE_32BIT_TIME_T
|
||||
|
||||
INCLUDEPATH += .
|
||||
}
|
||||
|
||||
##################################### MacOS ######################################
|
||||
|
||||
macx {
|
||||
# ENABLE THIS OPTION FOR Univeral Binary BUILD.
|
||||
CONFIG += ppc x86
|
||||
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4
|
||||
|
||||
CONFIG += version_detail_bash_script
|
||||
LIBS += ../../libretroshare/src/lib/libretroshare.a
|
||||
LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2
|
||||
LIBS += -lssl -lcrypto -lz
|
||||
#LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan
|
||||
LIBS += ../../../miniupnpc-1.0/libminiupnpc.a
|
||||
LIBS += -framework CoreFoundation
|
||||
LIBS += -framework Security
|
||||
|
||||
gxs {
|
||||
LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a
|
||||
|
||||
LIBS += ../../../lib/libsqlcipher.a
|
||||
#LIBS += -lsqlite3
|
||||
|
||||
}
|
||||
|
||||
|
||||
INCLUDEPATH += .
|
||||
#DEFINES* = MAC_IDLE # for idle feature
|
||||
CONFIG -= uitools
|
||||
|
||||
|
||||
}
|
||||
|
||||
##################################### FreeBSD ######################################
|
||||
|
||||
freebsd-* {
|
||||
INCLUDEPATH *= /usr/local/include/gpgme
|
||||
LIBS *= ../../libretroshare/src/lib/libretroshare.a
|
||||
LIBS *= -lssl
|
||||
LIBS *= -lgpgme
|
||||
LIBS *= -lupnp
|
||||
LIBS *= -lgnome-keyring
|
||||
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a
|
||||
|
||||
gxs {
|
||||
LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a
|
||||
LIBS += -lsqlite3
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
##################################### OpenBSD ######################################
|
||||
|
||||
openbsd-* {
|
||||
INCLUDEPATH *= /usr/local/include
|
||||
|
||||
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a
|
||||
PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a
|
||||
|
||||
LIBS *= ../../libretroshare/src/lib/libretroshare.a
|
||||
LIBS *= ../../openpgpsdk/src/lib/libops.a -lbz2
|
||||
LIBS *= -lssl -lcrypto
|
||||
LIBS *= -lgpgme
|
||||
LIBS *= -lupnp
|
||||
LIBS *= -lgnome-keyring
|
||||
PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a
|
||||
|
||||
gxs {
|
||||
LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a
|
||||
LIBS += -lsqlite3
|
||||
}
|
||||
|
||||
LIBS *= -rdynamic
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################## Common stuff ######################################
|
||||
|
||||
# On Linux systems that alredy have libssl and libcrypto it is advisable
|
||||
# to rename the patched version of SSL to something like libsslxpgp.a and libcryptoxpg.a
|
||||
|
||||
# ###########################################
|
||||
|
||||
bitdht {
|
||||
LIBS += ../../libbitdht/src/lib/libbitdht.a
|
||||
PRE_TARGETDEPS *= ../../libbitdht/src/lib/libbitdht.a
|
||||
}
|
||||
|
||||
win32 {
|
||||
# must be added after bitdht
|
||||
LIBS += -lws2_32
|
||||
}
|
||||
|
||||
DEPENDPATH += . \
|
||||
|
||||
INCLUDEPATH += ../../libretroshare/src/
|
||||
|
||||
# Input
|
||||
|
||||
|
||||
#
|
||||
# gui/channels/ChannelUserNotify.h \
|
||||
# gui/settings/ForumPage.h \
|
||||
|
||||
SOURCES += unittests.cc \
|
||||
|
||||
################################ Serialiser ################################
|
||||
HEADERS += libretroshare/serialiser/support.h \
|
||||
libretroshare/serialiser/rstlvutil.h \
|
||||
|
||||
SOURCES += libretroshare/serialiser/rsturtleitem_test.cc \
|
||||
libretroshare/serialiser/rsbaseitem_test.cc \
|
||||
libretroshare/serialiser/rsgxsupdateitem_test.cc \
|
||||
libretroshare/serialiser/rsmsgitem_test.cc \
|
||||
libretroshare/serialiser/rsstatusitem_test.cc \
|
||||
libretroshare/serialiser/rsnxsitems_test.cc \
|
||||
libretroshare/serialiser/rsgxsiditem_test.cc \
|
||||
libretroshare/serialiser/rsphotoitem_test.cc \
|
||||
libretroshare/serialiser/tlvbase_test2.cc \
|
||||
libretroshare/serialiser/tlvrandom_test.cc \
|
||||
libretroshare/serialiser/tlvbase_test.cc \
|
||||
libretroshare/serialiser/tlvstack_test.cc \
|
||||
libretroshare/serialiser/tlvitems_test.cc \
|
||||
libretroshare/serialiser/tlvtypes_test.cc \
|
||||
libretroshare/serialiser/tlvkey_test.cc \
|
||||
libretroshare/serialiser/support.cc \
|
||||
libretroshare/serialiser/rstlvutil.cc \
|
||||
|
||||
# Still to convert these.
|
||||
# libretroshare/serialiser/rsconfigitem_test.cc \
|
||||
# libretroshare/serialiser/rsgrouteritem_test.cc \
|
||||
|
||||
|
||||
################################## GXS #####################################
|
||||
|
||||
HEADERS += libretroshare/gxs/common/data_support.h \
|
||||
|
||||
SOURCES += libretroshare/gxs/common/data_support.cc \
|
||||
|
||||
#HEADERS += libretroshare/gxs/nxs_test/nxstesthub.h \
|
||||
# libretroshare/gxs/nxs_test/nxstestscenario.h \
|
||||
#
|
||||
#SOURCES += libretroshare/gxs/nxs_test/nxstesthub.cc \
|
||||
# libretroshare/gxs/nxs_test/nxstestscenario.cc \
|
||||
# libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc \
|
||||
|
||||
HEADERS += libretroshare/gxs/gen_exchange/genexchangetester.h \
|
||||
libretroshare/gxs/gen_exchange/gxspublishmsgtest.h \
|
||||
libretroshare/gxs/gen_exchange/genexchangetestservice.h \
|
||||
libretroshare/gxs/gen_exchange/gxspublishgrouptest.h \
|
||||
libretroshare/gxs/gen_exchange/rsdummyservices.h \
|
||||
|
||||
# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.h \
|
||||
|
||||
SOURCES += libretroshare/gxs/gen_exchange/gxspublishgrouptest.cc \
|
||||
libretroshare/gxs/gen_exchange/gxspublishmsgtest.cc \
|
||||
libretroshare/gxs/gen_exchange/rsdummyservices.cc \
|
||||
libretroshare/gxs/gen_exchange/rsgenexchange_test.cc \
|
||||
libretroshare/gxs/gen_exchange/genexchangetester.cc \
|
||||
libretroshare/gxs/gen_exchange/genexchangetestservice.cc \
|
||||
|
||||
# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.cc \
|
||||
|
||||
HEADERS += libretroshare/gxs/data_service/rsdataservice_test.h \
|
||||
|
||||
SOURCES += libretroshare/gxs/data_service/rsdataservice_test.cc \
|
||||
libretroshare/gxs/data_service/rsgxsdata_test.cc \
|
||||
|
||||
|
||||
################################ dbase #####################################
|
||||
|
||||
#HEADERS += libretroshare/dbase
|
||||
|
||||
SOURCES += libretroshare/dbase/fisavetest.cc \
|
||||
libretroshare/dbase/fitest2.cc \
|
||||
libretroshare/dbase/searchtest.cc \
|
||||
|
||||
# libretroshare/dbase/ficachetest.cc \
|
||||
# libretroshare/dbase/fimontest.cc \
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue