updating tests:

serialiser:

added tests for rsconfigitems
added regression reporting for tlvrandom_test
fixed rstatusitem_tests
fixed tlvbase_test2 tests, any fix rstlvipaddrv4 from this revision should not break regression

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4320 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2011-06-22 21:38:26 +00:00
parent e877f31409
commit f3fbac7d77
12 changed files with 452 additions and 36 deletions

View File

@ -0,0 +1,328 @@
/*
* libretroshare/src/tests/serialiser: rsconfigitemstest.cc
*
* RetroShare Serialiser tests.
*
* Copyright 2011 by Christopher Evi-Parker
*
* 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".
*
*/
#include "rsconfigitem_test.h"
#include "util/utest.h"
#include "support.h"
INITTEST()
RsSerialType* init_item(RsPeerNetItem& rpn)
{
randString(SHORT_STR, rpn.dyndns);
randString(SHORT_STR, rpn.gpg_id);
randString(SHORT_STR, rpn.location);
randString(SHORT_STR, rpn.pid);
rpn.lastContact = rand()%42424;
rpn.netMode = rand()%313190;
rpn.visState = rand()%63635;
inet_aton("10.0.0.111", &(rpn.currentlocaladdr.sin_addr));
rpn.currentlocaladdr.sin_port = htons(1111);
inet_aton("123.1.2.123", &(rpn.currentremoteaddr.sin_addr));
rpn.currentremoteaddr.sin_port = htons(1234);
RsTlvIpAddressInfo ipa1, ipa2;
ipa1.addr = rpn.currentlocaladdr;
ipa1.seenTime = rand()%40149013;
ipa1.source = rand()%13423;
ipa2.addr = rpn.currentremoteaddr;
ipa2.seenTime = rand()%40139013;
ipa2.source = rand()%1343443;
rpn.extAddrList.addrs.push_back(ipa1);
rpn.extAddrList.addrs.push_back(ipa2);
rpn.localAddrList.addrs.push_back(ipa1);
rpn.localAddrList.addrs.push_back(ipa2);
return new RsPeerConfigSerialiser();
}
RsSerialType* init_item(RsPeerOldNetItem& rpon)
{
return new RsPeerConfigSerialiser();
}
RsSerialType* init_item(RsPeerGroupItem& rpgi){
rpgi.flag = rand()%134344;
randString(SHORT_STR, rpgi.id);
randString(SHORT_STR, rpgi.name);
std::string p1, p2, p3;
randString(SHORT_STR, p1);
randString(SHORT_STR, p2);
randString(SHORT_STR, p3);
rpgi.peerIds.push_back(p1);
rpgi.peerIds.push_back(p2);
rpgi.peerIds.push_back(p3);
return new RsPeerConfigSerialiser();
}
RsSerialType* init_item(CompressedChunkMap& map)
{
map._map.clear() ;
for(uint32_t i=0;i<15;++i)
map._map.push_back(rand()) ;
return new RsTurtleSerialiser();
}
RsSerialType* init_item(RsPeerStunItem& rpsi)
{
std::string p1, p2, p3;
randString(SHORT_STR, p1);
randString(SHORT_STR, p2);
randString(SHORT_STR, p3);
rpsi.stunList.ids.push_back(p1);
rpsi.stunList.ids.push_back(p2);
rpsi.stunList.ids.push_back(p3);
rpsi.stunList.mType = TLV_TYPE_PEERSET;
return new RsPeerConfigSerialiser();
}
RsSerialType* init_item(RsCacheConfig& rcc)
{
rcc.cachesubid = rand()%2342;
rcc.cachetypeid = rand()%323;
rcc.recvd = rand()%2252243;
rcc.size = rand()%02203;
randString(SHORT_STR, rcc.hash);
randString(SHORT_STR, rcc.name);
randString(SHORT_STR, rcc.path);
randString(SHORT_STR, rcc.pid);
return new RsCacheConfigSerialiser();
}
RsSerialType* init_item(RsFileTransfer& rft)
{
std::string p1, p2, p3;
randString(SHORT_STR, p1);
randString(SHORT_STR, p2);
randString(SHORT_STR, p3);
rft.allPeerIds.ids.push_back(p1);
rft.allPeerIds.ids.push_back(p2);
rft.allPeerIds.ids.push_back(p3);
rft.allPeerIds.mType = TLV_TYPE_PEERSET;
//
// rft.compressed_chunk_map._map.clear();
// const int mapSize = 15;
// rft.compressed_chunk_map._map.resize(mapSize);
// for(int i=0; i<mapSize; i++)
// rft.compressed_chunk_map._map[i] = rand();
init_item(rft.compressed_chunk_map);
randString(SHORT_STR, rft.cPeerId);
rft.chunk_strategy = rand()%4242;
rft.crate = rand()%4242;
rft.flags = rand()%42422;
rft.in = rand()%2323;
rft.lrate = rand()%25234;
rft.ltransfer = rand()%42232;
rft.state = rand()%42122;
rft.transferred = rand()%42242;
rft.trate = rand()%1212;
init_item(rft.file);
return new RsFileConfigSerialiser();
}
bool operator==(const RsPeerNetItem& left, const RsPeerNetItem& right)
{
if(left.dyndns != right.dyndns) return false;
if(left.gpg_id != right.gpg_id) return false;
if(left.location != right.location) return false;
if(left.pid != right.pid) return false;
if(left.lastContact != right.lastContact) return false;
if(left.netMode != right.netMode) return false;
if(left.visState != right.visState) return false;
if(left.currentlocaladdr != right.currentlocaladdr) return false;
if(left.currentremoteaddr != right.currentremoteaddr) return false;
if(!(left.extAddrList.addrs == right.extAddrList.addrs)) return false;
if(!(left.localAddrList.addrs == right.localAddrList.addrs)) return false;
return true;
}
bool operator==(const std::list<RsTlvIpAddressInfo>& left,
const std::list<RsTlvIpAddressInfo>& right)
{
std::list<RsTlvIpAddressInfo>::const_iterator cit1 = left.begin(),
cit2 = right.begin();
for(; cit1 != left.end() ; cit1++, cit2++){
if(*cit1 != *cit2)
return false;
}
return true;
}
bool operator!=(const sockaddr_in& left, const sockaddr_in& right)
{
if(left.sin_addr.s_addr != right.sin_addr.s_addr) return true;
if(left.sin_port != right.sin_port) return true;
return false;
}
bool operator!=(const RsTlvIpAddressInfo& left, const RsTlvIpAddressInfo& right)
{
if(left.addr != right.addr) return true;
if(left.seenTime != right.seenTime) return true;
if(left.source != right.source) return true;
return false;
}
bool operator==(const RsPeerOldNetItem& left, const RsPeerOldNetItem& right)
{
return false;
}
bool operator==(const RsPeerGroupItem& left, const RsPeerGroupItem& right)
{
if(left.flag != right.flag) return false;
if(left.id != right.id) return false;
if(left.name != right.name) return false;
if(left.peerIds != right.peerIds) return false;
return true;
}
bool operator!=(const std::list<std::string>& left,
const std::list<std::string>& right)
{
std::list<std::string>::const_iterator cit1 = left.begin(),
cit2 = right.begin();
for(; cit1 != left.end(); cit1++, cit2++){
if(*cit1 != *cit2)
return true;
}
return false;
}
bool operator==(const RsPeerStunItem& left, const RsPeerStunItem& right)
{
if(!(left.stunList == right.stunList)) return false;
return true;
}
//bool operator==(const RsTlvPeerIdSet& left, const RsTlvPeerIdSet& right)
//{
// if(left.mType != right.mType) return false;
//
// std::list<std::string>::iterator cit1 = left.ids.begin(),
// cit2 = right.ids.begin();
//
// for(; cit1 != left.ids.end(); cit1++, cit2++){
//
// if(*cit1 != *cit2)
// return false;
// }
//
// return true;
//}
bool operator==(const RsCacheConfig& left, const RsCacheConfig& right)
{
if(left.cachesubid != right.cachesubid) return false;
if(left.cachetypeid != right.cachetypeid) return false;
if(left.hash != right.hash) return false;
if(left.path != right.path) return false;
if(left.pid != right.pid) return false;
if(left.recvd != right.recvd) return false;
if(left.size != right.size) return false;
return true;
}
bool operator==(const RsFileTransfer& left, const RsFileTransfer& right)
{
if(!(left.allPeerIds == right.allPeerIds)) return false;
if(left.cPeerId != right.cPeerId) return false;
if(left.chunk_strategy != right.chunk_strategy) return false;
if(left.compressed_chunk_map._map != right.compressed_chunk_map._map) return false;
if(left.crate != right.crate) return false;
if(!(left.file == right.file)) return false;
if(left.flags != right.flags) return false;
if(left.in != right.in) return false;
if(left.lrate != right.lrate) return false;
if(left.ltransfer != right.ltransfer) return false;
if(left.state != right.state) return false;
if(left.transferred != right.transferred) return false;
if(left.trate != right.trate) return false;
return true;
}
int main()
{
std::cerr << "RsConfigItems Tests" << std::endl;
test_RsItem<RsPeerNetItem>(); REPORT("Serialise/Deserialise RsPeerNetItem");
test_RsItem<RsPeerGroupItem>(); REPORT("Serialise/Deserialise RsPeerGroupItem");
test_RsItem<RsPeerStunItem>(); REPORT("Serialise/Deserialise RsPeerStunItem");
test_RsItem<RsCacheConfig>(); REPORT("Serialise/Deserialise RsCacheConfig");
test_RsItem<RsFileTransfer>(); REPORT("Serialise/Deserialise RsFileTransfer");
FINALREPORT("RsConfigItems Tests");
return TESTRESULT();
}

View File

@ -0,0 +1,59 @@
/*
* libretroshare/src/serialiser: rsconfigitem_test.h
*
* RetroShare Serialiser tests.
*
* Copyright 2011 by Christopher Evi-Parker.
*
* 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".
*
*/
#ifndef RSCONFIGITEM_TEST_H_
#define RSCONFIGITEM_TEST_H_
#include "serialiser/rsconfigitems.h"
#include "turtle/rsturtleitem.h"
RsSerialType* init_item(CompressedChunkMap& map);
RsSerialType* init_item(RsPeerNetItem& );
RsSerialType* init_item(RsPeerOldNetItem& );
RsSerialType* init_item(RsPeerGroupItem& );
RsSerialType* init_item(RsPeerStunItem& );
RsSerialType* init_item(RsCacheConfig& );
RsSerialType* init_item(RsFileTransfer& );
bool operator==(const RsPeerNetItem&, const RsPeerNetItem& );
bool operator==(const RsPeerOldNetItem&, const RsPeerOldNetItem& );
bool operator==(const RsPeerGroupItem&, const RsPeerGroupItem& );
bool operator==(const RsPeerStunItem&, const RsPeerStunItem& );
bool operator==(const RsCacheConfig&, const RsCacheConfig& );
bool operator==(const RsFileTransfer&, const RsFileTransfer& );
bool operator==(const std::list<RsTlvIpAddressInfo>&,
const std::list<RsTlvIpAddressInfo>&);
bool operator!=(const sockaddr_in&, const sockaddr_in&);
bool operator!=(const RsTlvIpAddressInfo&, const RsTlvIpAddressInfo& );
bool operator!=(const std::list<std::string>& left,
const std::list<std::string>& right);
//bool operator==(const RsTlvPeerIdSet& left, const RsTlvPeerIdSet& right);
bool operator==(const RsTlvFileItem&, const RsTlvFileItem& );
#endif /* RSCONFIGITEM_TEST_H_ */

View File

@ -32,18 +32,27 @@ INITTEST();
RsSerialType* init_item(RsStatusItem& rsi)
{
rsi.sendTime = rand()%5353;
rsi.status = rand()%2032;
return new RsStatusSerialiser();
}
bool operator ==(RsStatusItem& rsi1, RsStatusItem& rsi2)
{
return false;
// note: recv time is not serialised
if(rsi1.sendTime != rsi2.sendTime) return false;
if(rsi1.status != rsi2.status) return false;
return true;
}
int main()
{
std::cerr << "RsStatusItem Tests" << std::endl;
test_RsItem<RsStatusItem >(); REPORT("Serialise/Deserialise RsStatusItem");
FINALREPORT("RsStatusItem Tests");

View File

@ -138,7 +138,7 @@ static int test_RsTlvIPAddr()
test_IpAddr(&addr, 1234);
inet_aton("128.255.255.1", &(addr.sin_addr));
addr.sin_port = htons(0);
addr.sin_port = htons(1);
test_IpAddr(&addr, 1234);

View File

@ -52,7 +52,7 @@ int main()
return TESTRESULT();
}
#define BIN_LEN 523456 /* bigger than 64k */
#define BIN_LEN 65536 /* bigger than 64k */
int test_RsTlvBinData()
{

View File

@ -51,7 +51,7 @@
INITTEST();
#define TEST_LENGTH 30
#define TEST_LENGTH 10
static int test_TlvRandom(void *data, uint32_t len, uint32_t offset);
@ -99,8 +99,8 @@ int main()
#define BIN_LEN 523456 /* bigger than 64k */
int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset);
int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset);
bool test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset);
bool test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset);
int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
@ -130,44 +130,44 @@ int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
/* try to decode - with all types first */
std::cerr << "test_TlvRandom:: Testing Files " << std::endl;
test_TlvItem(&bindata, data, len, offset);
test_TlvItem(&fileitem, data, len, offset);
test_TlvItem(&fileset, data, len, offset);
test_TlvItem(&filedata, data, len, offset);
CHECK(test_TlvItem(&bindata, data, len, offset));
CHECK(test_TlvItem(&fileitem, data, len, offset));
CHECK(test_TlvItem(&fileset, data, len, offset));
CHECK(test_TlvItem(&filedata, data, len, offset));
std::cerr << "test_TlvRandom:: Testing Sets " << std::endl;
test_TlvItem(&peerset, data, len, offset);
test_TlvItem(&servset, data, len, offset);
test_TlvItem(&kv, data, len, offset);
test_TlvItem(&kvset, data, len, offset);
test_TlvItem(&kvwide, data, len, offset);
test_TlvItem(&kvwideset, data, len, offset);
CHECK(test_TlvItem(&peerset, data, len, offset));
CHECK(test_TlvItem(&servset, data, len, offset));
CHECK(test_TlvItem(&kv, data, len, offset));
CHECK(test_TlvItem(&kvset, data, len, offset));
CHECK(test_TlvItem(&kvwide, data, len, offset));
CHECK(test_TlvItem(&kvwideset, data, len, offset));
std::cerr << "test_TlvRandom:: Testing Keys " << std::endl;
test_TlvItem(&skey, data, len, offset);
test_TlvItem(&skeyset, data, len, offset);
test_TlvItem(&keysign, data, len, offset);
CHECK(test_TlvItem(&skey, data, len, offset));
CHECK(test_TlvItem(&skeyset, data, len, offset));
CHECK(test_TlvItem(&keysign, data, len, offset));
/* now set the type correctly before decoding */
std::cerr << "test_TlvRandom:: Testing Files (TYPESET)" << std::endl;
test_SetTlvItem(&bindata, TLV_TYPE_IMAGE, data, len, offset);
test_SetTlvItem(&fileitem,TLV_TYPE_FILEITEM, data, len, offset);
test_SetTlvItem(&fileset, TLV_TYPE_FILESET, data, len, offset);
test_SetTlvItem(&filedata, TLV_TYPE_FILEDATA, data, len, offset);
CHECK(test_SetTlvItem(&bindata, TLV_TYPE_IMAGE, data, len, offset));
CHECK(test_SetTlvItem(&fileitem,TLV_TYPE_FILEITEM, data, len, offset));
CHECK(test_SetTlvItem(&fileset, TLV_TYPE_FILESET, data, len, offset));
CHECK(test_SetTlvItem(&filedata, TLV_TYPE_FILEDATA, data, len, offset));
std::cerr << "test_TlvRandom:: Testing Sets (TYPESET)" << std::endl;
test_SetTlvItem(&peerset, TLV_TYPE_PEERSET, data, len, offset);
test_SetTlvItem(&servset, TLV_TYPE_SERVICESET, data, len, offset);
test_SetTlvItem(&kv, TLV_TYPE_KEYVALUE, data, len, offset);
test_SetTlvItem(&kvset, TLV_TYPE_KEYVALUESET, data, len, offset);
test_SetTlvItem(&kvwide, TLV_TYPE_WKEYVALUE, data, len, offset);
test_SetTlvItem(&kvwideset, TLV_TYPE_WKEYVALUESET, data, len, offset);
CHECK(test_SetTlvItem(&peerset, TLV_TYPE_PEERSET, data, len, offset));
CHECK(test_SetTlvItem(&servset, TLV_TYPE_SERVICESET, data, len, offset));
CHECK(test_SetTlvItem(&kv, TLV_TYPE_KEYVALUE, data, len, offset));
CHECK(test_SetTlvItem(&kvset, TLV_TYPE_KEYVALUESET, data, len, offset));
CHECK(test_SetTlvItem(&kvwide, TLV_TYPE_WKEYVALUE, data, len, offset));
CHECK(test_SetTlvItem(&kvwideset, TLV_TYPE_WKEYVALUESET, data, len, offset));
std::cerr << "test_TlvRandom:: Testing Keys (TYPESET)" << std::endl;
test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY, data, len, offset);
test_SetTlvItem(&skeyset, TLV_TYPE_SECURITYKEYSET, data, len, offset);
test_SetTlvItem(&keysign, TLV_TYPE_KEYSIGNATURE, data, len, offset);
CHECK(test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY, data, len, offset));
CHECK(test_SetTlvItem(&skeyset, TLV_TYPE_SECURITYKEYSET, data, len, offset));
CHECK(test_SetTlvItem(&keysign, TLV_TYPE_KEYSIGNATURE, data, len, offset));
return 26; /* number of tests */
}
int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset)
bool test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset)
{
uint32_t tmp_offset = offset;
if (item->GetTlv(data, size, &tmp_offset))
@ -175,15 +175,17 @@ int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset)
std::cerr << "TLV decoded Random!";
std::cerr << std::endl;
item->print(std::cerr, 20);
return false;
}
else
{
std::cerr << "TLV failed to decode";
std::cerr << std::endl;
return true;
}
}
int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset)
bool test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset)
{
/* set TLV type first! */
void *typedata = (((uint8_t *) data) + offset);

View File

@ -20,3 +20,7 @@ chatServiceTest::~chatServiceTest() {
void chatServiceTest::runTests(){
}
void chatServiceTest::insertChatItems(){
}

View File

@ -10,6 +10,7 @@
#include "servicetest.h"
#include "services/p3chatservice.h"
#include "util/utest.h"
class chatServiceTest: public ServiceTest {
@ -20,6 +21,8 @@ public:
public:
void runTests();
void insertChatItems();
private:
p3ChatService* mChat;

View File

@ -24,9 +24,7 @@
*/
#include "forumservicetest.h"
#include "util/utest.h"
INITTEST()
// distrib services are tested here
int main()

View File

@ -29,6 +29,9 @@
#include "servicetest.h"
#include "services/p3forums.h"
#include "util/utest.h"
INITTEST()
class forumServiceTest : public ServiceTest {

View File

@ -34,6 +34,8 @@ ServiceTest::ServiceTest()
SecurityPolicy *none = secpolicy_create();
mPersonGrp = new pqisslpersongrp(none, NULL);
mPeers = new p3Peers(mConnMgr);
mConnMgr->addFriend(fakePeer);
}
ServiceTest::~ServiceTest()

View File

@ -34,6 +34,7 @@
/*!
* A convenience class from which tests derive from
* This enables user to test in shallow manner the public methods
@ -50,6 +51,11 @@ public:
*/
virtual void runTests() = 0;
/*!
* use this to populate the service with messages
*/
void sendItem(RsItem* item);
protected:
@ -59,6 +65,8 @@ protected:
p3Peers* mPeers;
pqipersongrp* mPersonGrp;
std::string fakePeer; // ssl id of fake receiving peer
};