mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-21 20:38:50 -04:00
- added TestUtils class to handle generating random files and random SSL/PGP ids.
- fixed ftcontollertest. This should help fixing ftserver[123]test as well - improved pqiTestor using templates (lots of identical functions replaced) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6036 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
66207b81e5
commit
4e586c84ba
11 changed files with 278 additions and 195 deletions
45
libretroshare/src/tests/common/testutils.h
Normal file
45
libretroshare/src/tests/common/testutils.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <util/rsid.h>
|
||||
|
||||
class TestUtils
|
||||
{
|
||||
public:
|
||||
// Creates a random file of the given size at the given place. Useful for file transfer tests.
|
||||
//
|
||||
static bool createRandomFile(const std::string& filename,const uint64_t size)
|
||||
{
|
||||
FILE *f = fopen(filename.c_str(),"wb") ;
|
||||
|
||||
if(f == NULL)
|
||||
return 0 ;
|
||||
|
||||
uint32_t S = 5000 ;
|
||||
uint32_t *data = new uint32_t[S] ;
|
||||
|
||||
for(uint64_t i=0;i<size;i+=4*S)
|
||||
{
|
||||
for(uint32_t j=0;j<S;++j)
|
||||
data[j] = lrand48() ;
|
||||
|
||||
uint32_t to_write = std::min((uint64_t)(4*S),size - i) ;
|
||||
|
||||
if(to_write != fwrite((void*)data,1,to_write,f))
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
fclose(f) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
static std::string createRandomSSLId()
|
||||
{
|
||||
return t_RsGenericIdType<16>::random().toStdString(false);
|
||||
}
|
||||
static std::string createRandomPGPId()
|
||||
{
|
||||
return t_RsGenericIdType<8>::random().toStdString(true);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue