* fixed ftdata testharness functions (ftdata.h)

* Added existing ft tests to tests directory (don't work yet!)
 * Added dbase tests to tests directory (don't work yet!)
 * moved net_setup test to tests/general directory (don't work yet!)



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3176 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-06-20 12:24:05 +00:00
parent bf6f74c16a
commit 05bc4ba76e
22 changed files with 3288 additions and 23 deletions

View file

@ -0,0 +1,53 @@
RS_TOP_DIR = ../..
##### Define any flags that are needed for this section #######
###############################################################
###############################################################
include $(RS_TOP_DIR)/tests/scripts/config.mk
###############################################################
TESTOBJ = fitest2.o fisavetest.o searchtest.o
#ficachetest.o
TESTS = fitest2 fisavetest searchtest
#ficachetest
ifeq ($(OS),Linux)
TESTOBJ += fimontest.o
TESTS += fimontest
endif
ifeq ($(OS),MacOSX)
TESTOBJ += fimontest.o
TESTS += fimontest
endif
all: tests
fitest2 : fitest2.o $(OBJ)
$(CC) $(CFLAGS) -o fitest2 fitest2.o $(OBJ) $(LIBS)
fisavetest : fisavetest.o $(OBJ)
$(CC) $(CFLAGS) -o fisavetest fisavetest.o $(OBJ) $(LIBS)
fimontest : fimontest.o $(OBJ)
$(CC) $(CFLAGS) -o fimontest fimontest.o $(OBJ) $(LIBS)
ficachetest : ficachetest.o $(OBJ)
$(CC) $(CFLAGS) -o ficachetest ficachetest.o $(OBJ) $(LIBS)
searchtest : searchtest.o $(OBJ)
$(CC) $(CFLAGS) -o searchtest searchtest.o $(OBJ) $(LIBS)
clobber: rmtestfiles
rmtestfiles:
$(RM) test.index
###############################################################
include $(RS_TOP_DIR)/tests/scripts/rules.mk
###############################################################

View file

@ -0,0 +1,207 @@
/*
* 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 <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 = NULL;
p3ConnectMgr *connMgr2 = NULL;
p3ConnectMgr *connMgr3 = NULL;
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, nulldir);
CacheId cid1(TESTID, 0);
CacheSource *csrc2 = new CacheTestSource(&sc2, nulldir);
CacheStore *cstore2 = new CacheTestStore(&ctt2, nulldir);
CacheId cid2(TESTID, 0);
CacheSource *csrc3 = new CacheTestSource(&sc3, nulldir);
CacheStore *cstore3 = new CacheTestStore(&ctt3, 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 */
CacheData 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, CacheData> hashs;
std::map<CacheId, CacheData>::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;
}
}
}

View file

@ -0,0 +1,90 @@
/*
* 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 "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);
}
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 = RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE;
rootdirs.push_back(dir);
std::cerr << "Adding shared directory: " << argv[optind] << std::endl;
}
if (rootdirs.size() < 1)
{
usage(argv[0]);
}
sleep(1);
FileIndexMonitor mon(NULL,NULL, "", "OWN ID");
/* setup monitor */
mon.setPeriod(period);
mon.setSharedDirectories(rootdirs);
/* simulate running the thread */
mon.run();
return 1;
}

View file

@ -0,0 +1,119 @@
/*
* 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 "dbase/findex.h"
#include <iostream>
FileIndex *createBasicFileIndex(time_t age);
int main()
{
FileIndex *fi1 = createBasicFileIndex(100);
FileIndex *fi2 = new FileIndex("A SILLY ID");
fi1->printFileIndex(std::cout);
std::string 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);
fi2->printFileIndex(std::cout);
delete fi1;
delete fi2;
return 1;
}
FileIndex *createBasicFileIndex(time_t age)
{
FileIndex *fi = new FileIndex("A SILLY ID");
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;
}

View file

@ -0,0 +1,213 @@
/*
* 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 "dbase/findex.h"
#include <iostream>
FileIndex *createBasicFileIndex(time_t age);
int test1(FileIndex *fi);
int test2(FileIndex *fi);
int main()
{
FileIndex *fi = createBasicFileIndex(100);
test1(fi);
delete fi;
return 1;
}
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);
fi -> printFileIndex(std::cout);
}
fi -> printFileIndex(std::cout);
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);
fi -> printFileIndex(std::cout);
}
fi -> printFileIndex(std::cout);
return 1;
}
FileIndex *createBasicFileIndex(time_t age)
{
FileIndex *fi = new FileIndex("A SILLY ID");
FileEntry fe;
/* print empty FileIndex */
fi -> printFileIndex(std::cout);
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);
fi -> printFileIndex(std::cout);
return fi;
}

View file

@ -0,0 +1,74 @@
/*
* 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 "dbase/findex.h"
#include <iostream>
#include <fstream>
int main()
{
std::cout << std::string::npos << std::endl;
std::string testfile = "searchtest.index";
std::string fhash = "6851c28d99a6616a86942c3914476bf11997242a";
FileIndex *fi = new FileIndex("DUMB ID");
// 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
std::string findhash = "82bffa6e1cdf8419397311789391238174817481";
std::cout << "Search hash : " << findhash << std::endl;
fi->searchHash(findhash, hashresult);
while(!hashresult.empty())
{
hashresult.back()->print(std::cout);
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())
{
termresult.back()->print(std::cout);
termresult.pop_back();
}
delete fi;
return 1;
}