* Added test for pqiarchive. (similar test can be used for pqistreamer / pqistore).

NOTE: This tests packets up to size of 1Mb. This causes the test to FAIL
   due to getRsPktMaxSize() returning 262142.... What to do? This needs to be fixed!
  
   see comments at serialiser/rsserial.cc line 448
  


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3180 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-06-20 19:54:33 +00:00
parent b23b0a5d70
commit f9e9bf58a5
4 changed files with 296 additions and 2 deletions

View File

@ -8,9 +8,10 @@ include $(RS_TOP_DIR)/tests/scripts/config.mk
###############################################################
TESTOBJ = net_test.o dht_test.o net_test1.o netiface_test.o dht_test.o
TESTOBJ += pkt_test.o pqiarchive_test.o
#conn_test.o
TESTS = net_test net_test1 netiface_test
TESTS = net_test net_test1 netiface_test pqiarchive_test
MANUAL_TESTS = dht_test
#conn_test
@ -38,6 +39,10 @@ net_test1: net_test1.o
netiface_test: netiface_test.o
$(CC) $(CFLAGS) -o netiface_test netiface_test.o $(LIBS)
pqiarchive_test: pqiarchive_test.o pkt_test.o
$(CC) $(CFLAGS) -o pqiarchive_test pkt_test.o pqiarchive_test.o $(LIBS)
clobber: remove_extra_files
remove_extra_files:

View File

@ -0,0 +1,109 @@
/*
* libretroshare/src/tests/pqi pkt_tst.cc
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2009-2010 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
/******
* pkt_tst.
*
* This is not testing serialisation.... so we only need 1 type of packet.
* using FileData packets - as these can have arbitary size.
*/
#include "pkt_test.h"
#include <iostream>
uint8_t testdata[TEST_DATA_LEN];
void generate_test_data()
{
srand(1);
int i;
for(i = 0; i < TEST_DATA_LEN; i++)
{
testdata[i] = rand() % 256;
}
}
bool check_data(void *data_in, int len)
{
int i;
uint8_t *data = (uint8_t *) data_in;
for(i = 0; i < len; i++)
{
if (data[i] != testdata[i])
{
std::cerr << "check_data() Different Byte: " << i;
std::cerr << std::endl;
return false;
}
}
return true;
}
RsFileData *gen_packet(int datasize, std::string pid)
{
/* generate some packets */
RsFileData *data = new RsFileData();
data->fd.file.filesize = TEST_PKT_SIZE;
data->fd.file.hash = TEST_PKT_HASH;
data->fd.file_offset = TEST_PKT_OFFSET;
data->fd.binData.setBinData(testdata, datasize);
data->PeerId(pid);
return data;
}
bool check_packet(RsFileData *pkt)
{
if (pkt->fd.file.filesize != TEST_PKT_SIZE)
{
std::cerr << "check_packet() FileSize Different";
std::cerr << std::endl;
return false;
}
if (pkt->fd.file.hash != TEST_PKT_HASH)
{
std::cerr << "check_packet() FileHash Different";
std::cerr << std::endl;
return false;
}
if (pkt->fd.file_offset != TEST_PKT_OFFSET)
{
std::cerr << "check_packet() FileOffset Different";
std::cerr << std::endl;
return false;
}
return check_data(pkt->fd.binData.bin_data, pkt->fd.binData.bin_len);
}

View File

@ -0,0 +1,50 @@
#ifndef RS_TEST_PACKETS
#define RS_TEST_PACKETS
/*
* libretroshare/src/tests/pqi pkt_tst.cc
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2009-2010 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
/******
* pkt_tst.
*
* This is not testing serialisation.... so we only need 1 type of packet.
* using FileData packets - as these can have arbitary size.
*/
#include "serialiser/rsbaseitems.h"
#define TEST_PKT_SIZE 1234567
#define TEST_PKT_HASH "HASHTESTHASH"
#define TEST_PKT_OFFSET 1234
#define TEST_DATA_LEN (1024 * 1024) // MB
void generate_test_data();
bool check_data(void *data_in, int len);
RsFileData *gen_packet(int datasize, std::string pid);
bool check_packet(RsFileData *pkt);
#endif

View File

@ -0,0 +1,130 @@
/*
* libretroshare/src/tests/pqi pqiarchive_test.cc
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2009-2010 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
/******
* pqiarchive test.
*
* This is not testing serialisation.... so we only need 1 type of packet.
* using FileData packets - as these can have arbitary size.
*/
#include "pqi/pqiarchive.h"
#include "pqi/pqibin.h"
#include "serialiser/rsbaseitems.h"
#include "util/rsnet.h"
#include <iostream>
#include <sstream>
#include "util/utest.h"
#include "pkt_test.h"
INITTEST();
int test_pqiarchive_generate();
int main(int argc, char **argv)
{
std::cerr << "pqiarchive_test" << std::endl;
generate_test_data();
test_pqiarchive_generate();
FINALREPORT("pqiarchive_test");
return TESTRESULT();
}
const char *archive_fname = "/tmp/rs_tst_archive.tmp";
int test_pqiarchive_generate()
{
std::string pid = "123456789012345678901234567890ZZ";
/* create a pqiarchive */
RsSerialiser *rss = new RsSerialiser();
rss->addSerialType(new RsFileItemSerialiser());
int flags = BIN_FLAGS_WRITEABLE;
BinInterface *bio_in = new BinFileInterface(archive_fname, flags);
int bio_flagsin = flags;
pqiarchive *pqia = new pqiarchive(rss, bio_in, bio_flagsin);
CHECK(pqia != NULL);
int i;
for(i = 10; i < TEST_DATA_LEN; i = (int) (i * 1.1))
{
RsFileData *pkt = gen_packet(i, pid);
pqia->SendItem(pkt);
pqia->tick();
}
/* close it up */
delete pqia;
/* setup read */
flags = BIN_FLAGS_READABLE;
rss = new RsSerialiser();
rss->addSerialType(new RsFileItemSerialiser());
bio_in = new BinFileInterface(archive_fname, flags);
bio_flagsin = flags;
pqia = new pqiarchive(rss, bio_in, bio_flagsin);
for(i = 10; i < TEST_DATA_LEN; i = (int) (i * 1.1))
//for(i = 10; i < TEST_DATA_LEN; i += 111)
{
RsItem *pkt = pqia->GetItem();
pqia->tick();
/* check the packet */
RsFileData *data = dynamic_cast<RsFileData *>(pkt);
CHECK(data != NULL);
if (data)
{
CHECK(data->fd.binData.bin_len == i);
CHECK(check_packet(data) == true);
delete data;
}
}
/* if there are anymore packets -> error! */
for(i = 0; i < 1000; i++)
{
RsItem *pkt = pqia->GetItem();
CHECK(pkt == NULL);
}
REPORT("pqiarchive_generate()");
return 1;
}