mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 07:29:33 -05:00
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:
parent
8720ab968e
commit
3b678beca9
@ -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);
|
||||
|
@ -34,9 +34,12 @@
|
||||
#endif
|
||||
|
||||
#include "util/rsdir.h"
|
||||
#include <common/fileutils.h>
|
||||
#include "util/utest.h"
|
||||
#include <common/testutils.h>
|
||||
#include <common/argstream.h>
|
||||
|
||||
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() ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <util/utest.h>
|
||||
#include <common/fileutils.h>
|
||||
#include <common/testutils.h>
|
||||
#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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 <stdlib.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
|
@ -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 <iostream>
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#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)
|
||||
|
Loading…
Reference in New Issue
Block a user