2008-07-01 22:36:39 -04:00
|
|
|
#include "ftfileprovider.h"
|
2008-10-22 14:12:58 -04:00
|
|
|
#include "ftfilecreator.h"
|
2008-07-01 22:36:39 -04:00
|
|
|
|
2008-10-22 14:12:58 -04:00
|
|
|
#include "util/utest.h"
|
|
|
|
|
|
|
|
|
|
|
|
INITTEST()
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* create a random file */
|
|
|
|
uint64_t size = 100000;
|
|
|
|
uint32_t max_chunk = 10000;
|
|
|
|
uint32_t chunk = 1000;
|
|
|
|
uint64_t offset = 0;
|
|
|
|
|
|
|
|
std::string filename = "/tmp/ft_test.dta";
|
|
|
|
std::string filename2 = "/tmp/ft_test.dta.dup";
|
|
|
|
|
|
|
|
/* use creator to make it */
|
|
|
|
|
|
|
|
void *data = malloc(max_chunk);
|
|
|
|
|
|
|
|
ftFileCreator *creator = new ftFileCreator(filename, size, "hash", 0);
|
|
|
|
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;
|
2008-07-01 22:36:39 -04:00
|
|
|
}
|
|
|
|
}
|
2008-10-22 14:12:58 -04:00
|
|
|
delete creator;
|
2008-07-01 22:36:39 -04:00
|
|
|
|
2008-10-22 14:12:58 -04:00
|
|
|
std::cerr << "Created file: " << filename << " of size: " << size;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
/* load it with file provider */
|
|
|
|
creator = new ftFileCreator(filename2, size, "hash", 0);
|
|
|
|
ftFileProvider *provider = new ftFileProvider(filename, size, "hash");
|
|
|
|
|
|
|
|
/* create duplicate with file creator */
|
|
|
|
|
|
|
|
while(creator->getMissingChunk(offset, chunk))
|
|
|
|
{
|
|
|
|
if (!provider->getFileData(offset, chunk, data))
|
|
|
|
{
|
|
|
|
FAILED("Read from Test Data File");
|
|
|
|
std::cerr << "Failed to get data";
|
|
|
|
std::cerr << std::endl;
|
2008-07-01 22:36:39 -04:00
|
|
|
}
|
2008-10-22 14:12:58 -04:00
|
|
|
|
|
|
|
if (!creator->addFileData(offset, chunk, data))
|
|
|
|
{
|
|
|
|
FAILED("Write to Duplicate");
|
|
|
|
std::cerr << "Failed to add data";
|
|
|
|
std::cerr << std::endl;
|
2008-07-01 22:36:39 -04:00
|
|
|
}
|
2008-10-22 14:12:58 -04:00
|
|
|
|
|
|
|
std::cerr << "Transferred: " << chunk << " @ " << offset;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
/* reset chunk size */
|
|
|
|
chunk = (uint64_t) max_chunk * (rand() / (1.0 + RAND_MAX));
|
|
|
|
|
|
|
|
std::cerr << "ChunkSize = " << chunk << std::endl;
|
2008-07-01 22:36:39 -04:00
|
|
|
}
|
2008-07-02 00:05:58 -04:00
|
|
|
return 1;
|
2008-07-01 22:36:39 -04:00
|
|
|
}
|