fixed more tests. Added checking for initialized partials and download directories in RsDiscSpace

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6043 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-12-27 10:23:38 +00:00
parent 8720ab968e
commit 3b678beca9
7 changed files with 50 additions and 38 deletions

View File

@ -38,6 +38,10 @@ class TestUtils
return true ; return true ;
} }
static std::string createRandomFileHash()
{
return t_RsGenericIdType<20>::random().toStdString(false);
}
static std::string createRandomSSLId() static std::string createRandomSSLId()
{ {
return t_RsGenericIdType<16>::random().toStdString(false); return t_RsGenericIdType<16>::random().toStdString(false);

View File

@ -34,9 +34,12 @@
#endif #endif
#include "util/rsdir.h" #include "util/rsdir.h"
#include <common/fileutils.h> #include "util/utest.h"
#include <common/testutils.h>
#include <common/argstream.h> #include <common/argstream.h>
INITTEST() ;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int c; int c;
@ -58,7 +61,7 @@ int main(int argc, char **argv)
std::cerr << "Creating a dummy input file in /tmp, of size " << S << std::endl; std::cerr << "Creating a dummy input file in /tmp, of size " << S << std::endl;
inputfile = "crc_test_data.bin" ; inputfile = "crc_test_data.bin" ;
if(!FileUtils::createRandomFile(inputfile,S)) if(!TestUtils::createRandomFile(inputfile,S))
return 1 ; return 1 ;
} }
@ -114,7 +117,8 @@ int main(int argc, char **argv)
std::cerr << std::endl; std::cerr << std::endl;
} }
return 0 ; FINALREPORT("CRC32 test") ;
return TESTRESULT() ;
} }

View File

@ -38,7 +38,7 @@
#include <sstream> #include <sstream>
#include <util/utest.h> #include <util/utest.h>
#include <common/fileutils.h> #include <common/testutils.h>
#include "ft/ftextralist.h" #include "ft/ftextralist.h"
#include "ft/ftdatamultiplex.h" #include "ft/ftdatamultiplex.h"
#include "ft/ftfilesearch.h" #include "ft/ftfilesearch.h"
@ -91,7 +91,7 @@ int main(int argc, char **argv)
ss << "file_" << i << ".bin" ; ss << "file_" << i << ".bin" ;
uint64_t size = lrand48()%1000 + 200000 ; uint64_t size = lrand48()%1000 + 200000 ;
std::string filename = ss.str() ; std::string filename = ss.str() ;
if(!FileUtils::createRandomFile(filename,size)) if(!TestUtils::createRandomFile(filename,size))
return 1 ; return 1 ;
std::cerr << " file: " << filename << ", size=" << size << std::endl; std::cerr << " file: " << filename << ", size=" << size << std::endl;
} }

View File

@ -16,7 +16,7 @@ static int test_fill(ftFileCreator *creator);
int main() int main()
{ {
/* use ftcreator to create a file on tmp drive */ /* use ftcreator to create a file on tmp drive */
ftFileCreator fcreator("/tmp/rs-ftfc-test.dta",100000,"hash", false); ftFileCreator fcreator("/tmp/rs-ftfc-test.dta",100000,"hash", true);
test_timeout(&fcreator); test_timeout(&fcreator);
test_fill(&fcreator); test_fill(&fcreator);
@ -128,8 +128,6 @@ int test_fill(ftFileCreator *creator)
REPORT("Test Fill"); REPORT("Test Fill");
int res = TESTRESULT(); return 1;
std::cerr << "Test result: " << res << std::endl;
return res ;
} }

View File

@ -2,6 +2,9 @@
#include "ft/ftfilecreator.h" #include "ft/ftfilecreator.h"
#include "util/utest.h" #include "util/utest.h"
#include "util/rsdir.h"
#include "util/rsdiscspace.h"
#include "common/testutils.h"
#include <stdlib.h> #include <stdlib.h>
#include "util/rswin.h" #include "util/rswin.h"
@ -10,10 +13,13 @@ INITTEST()
int main() int main()
{ {
std::string ownId = "00000000000000000000000" ; std::string ownId = TestUtils::createRandomSSLId() ;
RsDiscSpace::setPartialsPath("/tmp") ;
RsDiscSpace::setDownloadPath("/tmp") ;
/* create a random file */ /* create a random file */
uint64_t size = 100000; uint64_t size = 10000000;
uint32_t max_chunk = 10000; uint32_t max_chunk = 10000;
uint32_t chunk = 1000; uint32_t chunk = 1000;
uint64_t offset = 0; uint64_t offset = 0;
@ -21,41 +27,24 @@ int main()
std::string filename = "/tmp/ft_test.dta"; std::string filename = "/tmp/ft_test.dta";
std::string filename2 = "/tmp/ft_test.dta.dup"; std::string filename2 = "/tmp/ft_test.dta.dup";
std::string hash = TestUtils::createRandomFileHash() ;
/* use creator to make it */ /* use creator to make it */
void *data = malloc(max_chunk); TestUtils::createRandomFile(filename,size) ;
for(int i = 0; i < max_chunk; i++)
{
((uint8_t *) data)[i] = 'a' + i % 27;
if (i % 27 == 26)
{
((uint8_t *) data)[i] = '\n';
}
}
ftFileCreator *creator = new ftFileCreator(filename, size, "hash", true);
for(offset = 0; offset != size; offset += chunk)
{
if (!creator->addFileData(offset, chunk, data))
{
FAILED("Create Test Data File");
std::cerr << "Failed to add data (CREATE)";
std::cerr << std::endl;
}
}
delete creator;
std::cerr << "Created file: " << filename << " of size: " << size; std::cerr << "Created file: " << filename << " of size: " << size;
std::cerr << std::endl; std::cerr << std::endl;
/* load it with file provider */ /* load it with file provider */
creator = new ftFileCreator(filename2, size, "hash", true); ftFileCreator *creator = new ftFileCreator(filename2, size, hash, true);
ftFileProvider *provider = new ftFileProvider(filename, size, "hash"); ftFileProvider *provider = new ftFileProvider(filename, size, hash);
/* create duplicate with file creator */ /* create duplicate with file creator */
std::string peer_id = "dummyId"; std::string peer_id = TestUtils::createRandomSSLId() ;
uint32_t size_hint = 10000; uint32_t size_hint = 10000;
bool toOld = false; bool toOld = false;
unsigned char *data = new unsigned char[max_chunk];
while(creator->getMissingChunk(peer_id, size_hint, offset, chunk, toOld)) while(creator->getMissingChunk(peer_id, size_hint, offset, chunk, toOld))
{ {
@ -93,5 +82,18 @@ int main()
std::cerr << "ChunkSize = " << chunk << std::endl; std::cerr << "ChunkSize = " << chunk << std::endl;
} }
return 1; std::string path,hash2 ;
RsDirUtil::hashFile(filename ,path,hash,size) ;
RsDirUtil::hashFile(filename2,path,hash2,size) ;
std::cerr << "Checking hash1 : " << hash << std::endl;
std::cerr << "Checking hash2 : " << hash2 << std::endl;
CHECK(hash == hash2) ;
FINALREPORT("ftfilecreatortest") ;
return TESTRESULT();
} }

View File

@ -42,12 +42,12 @@
#include "pqi/p3connmgr.h" //#include "pqi/p3connmgr.h"
#include "pqi/authssltest.h" #include "pqi/authssltest.h"
#include "pqi/authgpgtest.h" #include "pqi/authgpgtest.h"
#include "pqi/p3dhtmgr.h" #include "pqi/p3dhtmgr.h"
#include "upnp/upnphandler.h" #include "upnp/upnphandler_linux.h"
#include "util/rsnet.h" #include "util/rsnet.h"
#include <iostream> #include <iostream>

View File

@ -24,6 +24,7 @@
*/ */
#include <iostream> #include <iostream>
#include <stdexcept>
#include "retroshare/rsfiles.h" #include "retroshare/rsfiles.h"
#include "retroshare/rsiface.h" #include "retroshare/rsiface.h"
#include "retroshare/rsinit.h" #include "retroshare/rsinit.h"
@ -129,6 +130,9 @@ bool RsDiscSpace::checkForDiscSpace(RsDiscSpace::DiscLocation loc)
{ {
RsStackMutex m(_mtx) ; // Locked RsStackMutex m(_mtx) ; // Locked
if(_partials_path == "" || _download_path == "")
throw std::runtime_error("Download path and partial path not properly set in RsDiscSpace. Please call RsDiscSpace::setPartialsPath() and RsDiscSpace::setDownloadPath()") ;
time_t now = time(NULL) ; time_t now = time(NULL) ;
if(_last_check[loc]+DELAY_BETWEEN_CHECKS < now) if(_last_check[loc]+DELAY_BETWEEN_CHECKS < now)