From 3b678beca9baaf42f92c2808ea0eaea0337ee4b0 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 27 Dec 2012 10:23:38 +0000 Subject: [PATCH] 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 --- libretroshare/src/tests/common/testutils.h | 4 ++ libretroshare/src/tests/ft/ftcrc32test.cc | 10 +++- libretroshare/src/tests/ft/ftdataplextest.cc | 4 +- .../src/tests/ft/ftfilecreatortest.cc | 6 +- .../src/tests/ft/ftfileprovidertest.cc | 56 ++++++++++--------- .../src/tests/pqi/p3connmgr_reset_test.cc | 4 +- libretroshare/src/util/rsdiscspace.cc | 4 ++ 7 files changed, 50 insertions(+), 38 deletions(-) diff --git a/libretroshare/src/tests/common/testutils.h b/libretroshare/src/tests/common/testutils.h index b2cda54a0..f5323139c 100644 --- a/libretroshare/src/tests/common/testutils.h +++ b/libretroshare/src/tests/common/testutils.h @@ -38,6 +38,10 @@ class TestUtils return true ; } + static std::string createRandomFileHash() + { + return t_RsGenericIdType<20>::random().toStdString(false); + } static std::string createRandomSSLId() { return t_RsGenericIdType<16>::random().toStdString(false); diff --git a/libretroshare/src/tests/ft/ftcrc32test.cc b/libretroshare/src/tests/ft/ftcrc32test.cc index d1220ed2f..144dda053 100644 --- a/libretroshare/src/tests/ft/ftcrc32test.cc +++ b/libretroshare/src/tests/ft/ftcrc32test.cc @@ -34,9 +34,12 @@ #endif #include "util/rsdir.h" -#include +#include "util/utest.h" +#include #include +INITTEST() ; + int main(int argc, char **argv) { 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; inputfile = "crc_test_data.bin" ; - if(!FileUtils::createRandomFile(inputfile,S)) + if(!TestUtils::createRandomFile(inputfile,S)) return 1 ; } @@ -114,7 +117,8 @@ int main(int argc, char **argv) std::cerr << std::endl; } - return 0 ; + FINALREPORT("CRC32 test") ; + return TESTRESULT() ; } diff --git a/libretroshare/src/tests/ft/ftdataplextest.cc b/libretroshare/src/tests/ft/ftdataplextest.cc index 21a30d8b0..7872aa72d 100644 --- a/libretroshare/src/tests/ft/ftdataplextest.cc +++ b/libretroshare/src/tests/ft/ftdataplextest.cc @@ -38,7 +38,7 @@ #include #include -#include +#include #include "ft/ftextralist.h" #include "ft/ftdatamultiplex.h" #include "ft/ftfilesearch.h" @@ -91,7 +91,7 @@ int main(int argc, char **argv) ss << "file_" << i << ".bin" ; uint64_t size = lrand48()%1000 + 200000 ; std::string filename = ss.str() ; - if(!FileUtils::createRandomFile(filename,size)) + if(!TestUtils::createRandomFile(filename,size)) return 1 ; std::cerr << " file: " << filename << ", size=" << size << std::endl; } diff --git a/libretroshare/src/tests/ft/ftfilecreatortest.cc b/libretroshare/src/tests/ft/ftfilecreatortest.cc index f92329047..700b407b3 100644 --- a/libretroshare/src/tests/ft/ftfilecreatortest.cc +++ b/libretroshare/src/tests/ft/ftfilecreatortest.cc @@ -16,7 +16,7 @@ static int test_fill(ftFileCreator *creator); int main() { /* 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_fill(&fcreator); @@ -128,8 +128,6 @@ int test_fill(ftFileCreator *creator) REPORT("Test Fill"); - int res = TESTRESULT(); - std::cerr << "Test result: " << res << std::endl; - return res ; + return 1; } diff --git a/libretroshare/src/tests/ft/ftfileprovidertest.cc b/libretroshare/src/tests/ft/ftfileprovidertest.cc index 2a12aa1ae..5a717a6c4 100644 --- a/libretroshare/src/tests/ft/ftfileprovidertest.cc +++ b/libretroshare/src/tests/ft/ftfileprovidertest.cc @@ -2,6 +2,9 @@ #include "ft/ftfilecreator.h" #include "util/utest.h" +#include "util/rsdir.h" +#include "util/rsdiscspace.h" +#include "common/testutils.h" #include #include "util/rswin.h" @@ -10,10 +13,13 @@ INITTEST() int main() { - std::string ownId = "00000000000000000000000" ; + std::string ownId = TestUtils::createRandomSSLId() ; + + RsDiscSpace::setPartialsPath("/tmp") ; + RsDiscSpace::setDownloadPath("/tmp") ; /* create a random file */ - uint64_t size = 100000; + uint64_t size = 10000000; uint32_t max_chunk = 10000; uint32_t chunk = 1000; uint64_t offset = 0; @@ -21,41 +27,24 @@ int main() std::string filename = "/tmp/ft_test.dta"; std::string filename2 = "/tmp/ft_test.dta.dup"; + std::string hash = TestUtils::createRandomFileHash() ; + /* use creator to make it */ - void *data = malloc(max_chunk); - 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; + TestUtils::createRandomFile(filename,size) ; std::cerr << "Created file: " << filename << " of size: " << size; std::cerr << std::endl; /* load it with file provider */ - creator = new ftFileCreator(filename2, size, "hash", true); - ftFileProvider *provider = new ftFileProvider(filename, size, "hash"); + ftFileCreator *creator = new ftFileCreator(filename2, size, hash, true); + ftFileProvider *provider = new ftFileProvider(filename, size, hash); /* create duplicate with file creator */ - std::string peer_id = "dummyId"; + std::string peer_id = TestUtils::createRandomSSLId() ; uint32_t size_hint = 10000; bool toOld = false; + unsigned char *data = new unsigned char[max_chunk]; while(creator->getMissingChunk(peer_id, size_hint, offset, chunk, toOld)) { @@ -93,5 +82,18 @@ int main() 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(); } + diff --git a/libretroshare/src/tests/pqi/p3connmgr_reset_test.cc b/libretroshare/src/tests/pqi/p3connmgr_reset_test.cc index 971ec4164..686e256c9 100644 --- a/libretroshare/src/tests/pqi/p3connmgr_reset_test.cc +++ b/libretroshare/src/tests/pqi/p3connmgr_reset_test.cc @@ -42,12 +42,12 @@ -#include "pqi/p3connmgr.h" +//#include "pqi/p3connmgr.h" #include "pqi/authssltest.h" #include "pqi/authgpgtest.h" #include "pqi/p3dhtmgr.h" -#include "upnp/upnphandler.h" +#include "upnp/upnphandler_linux.h" #include "util/rsnet.h" #include diff --git a/libretroshare/src/util/rsdiscspace.cc b/libretroshare/src/util/rsdiscspace.cc index 39392e512..dc4f51adc 100644 --- a/libretroshare/src/util/rsdiscspace.cc +++ b/libretroshare/src/util/rsdiscspace.cc @@ -24,6 +24,7 @@ */ #include +#include #include "retroshare/rsfiles.h" #include "retroshare/rsiface.h" #include "retroshare/rsinit.h" @@ -129,6 +130,9 @@ bool RsDiscSpace::checkForDiscSpace(RsDiscSpace::DiscLocation loc) { 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) ; if(_last_check[loc]+DELAY_BETWEEN_CHECKS < now)