diff --git a/libretroshare/src/tests/serialiser/rsconfigitem_test.cc b/libretroshare/src/tests/serialiser/rsconfigitem_test.cc new file mode 100644 index 000000000..1ac41ae09 --- /dev/null +++ b/libretroshare/src/tests/serialiser/rsconfigitem_test.cc @@ -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& left, + const std::list& right) +{ + std::list::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& left, + const std::list& right) +{ + std::list::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::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(); REPORT("Serialise/Deserialise RsPeerNetItem"); + test_RsItem(); REPORT("Serialise/Deserialise RsPeerGroupItem"); + test_RsItem(); REPORT("Serialise/Deserialise RsPeerStunItem"); + test_RsItem(); REPORT("Serialise/Deserialise RsCacheConfig"); + test_RsItem(); REPORT("Serialise/Deserialise RsFileTransfer"); + + FINALREPORT("RsConfigItems Tests"); + + return TESTRESULT(); +} diff --git a/libretroshare/src/tests/serialiser/rsconfigitem_test.h b/libretroshare/src/tests/serialiser/rsconfigitem_test.h new file mode 100644 index 000000000..2571d5c30 --- /dev/null +++ b/libretroshare/src/tests/serialiser/rsconfigitem_test.h @@ -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&, + const std::list&); + +bool operator!=(const sockaddr_in&, const sockaddr_in&); +bool operator!=(const RsTlvIpAddressInfo&, const RsTlvIpAddressInfo& ); +bool operator!=(const std::list& left, + const std::list& right); +//bool operator==(const RsTlvPeerIdSet& left, const RsTlvPeerIdSet& right); +bool operator==(const RsTlvFileItem&, const RsTlvFileItem& ); + + + +#endif /* RSCONFIGITEM_TEST_H_ */ diff --git a/libretroshare/src/tests/serialiser/rsstatusitem_test.cc b/libretroshare/src/tests/serialiser/rsstatusitem_test.cc index c124bc751..db6d5c181 100644 --- a/libretroshare/src/tests/serialiser/rsstatusitem_test.cc +++ b/libretroshare/src/tests/serialiser/rsstatusitem_test.cc @@ -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(); REPORT("Serialise/Deserialise RsStatusItem"); FINALREPORT("RsStatusItem Tests"); diff --git a/libretroshare/src/tests/serialiser/tlvbase_test2.cc b/libretroshare/src/tests/serialiser/tlvbase_test2.cc index bc2bda548..4d3063dc2 100644 --- a/libretroshare/src/tests/serialiser/tlvbase_test2.cc +++ b/libretroshare/src/tests/serialiser/tlvbase_test2.cc @@ -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); diff --git a/libretroshare/src/tests/serialiser/tlvitems_test.cc b/libretroshare/src/tests/serialiser/tlvitems_test.cc index 0ad436155..cb6ff0857 100644 --- a/libretroshare/src/tests/serialiser/tlvitems_test.cc +++ b/libretroshare/src/tests/serialiser/tlvitems_test.cc @@ -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() { diff --git a/libretroshare/src/tests/serialiser/tlvrandom_test.cc b/libretroshare/src/tests/serialiser/tlvrandom_test.cc index 013582263..758451988 100644 --- a/libretroshare/src/tests/serialiser/tlvrandom_test.cc +++ b/libretroshare/src/tests/serialiser/tlvrandom_test.cc @@ -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); diff --git a/libretroshare/src/tests/services/chatservicetest.cc b/libretroshare/src/tests/services/chatservicetest.cc index 5df4b3db9..b2b3619cc 100644 --- a/libretroshare/src/tests/services/chatservicetest.cc +++ b/libretroshare/src/tests/services/chatservicetest.cc @@ -20,3 +20,7 @@ chatServiceTest::~chatServiceTest() { void chatServiceTest::runTests(){ } + +void chatServiceTest::insertChatItems(){ + +} diff --git a/libretroshare/src/tests/services/chatservicetest.h b/libretroshare/src/tests/services/chatservicetest.h index 3b3828f9a..c25537136 100644 --- a/libretroshare/src/tests/services/chatservicetest.h +++ b/libretroshare/src/tests/services/chatservicetest.h @@ -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; diff --git a/libretroshare/src/tests/services/distribtest.cc b/libretroshare/src/tests/services/distribtest.cc index b34a6c937..4919c13b4 100644 --- a/libretroshare/src/tests/services/distribtest.cc +++ b/libretroshare/src/tests/services/distribtest.cc @@ -24,9 +24,7 @@ */ #include "forumservicetest.h" -#include "util/utest.h" - INITTEST() // distrib services are tested here int main() diff --git a/libretroshare/src/tests/services/forumservicetest.h b/libretroshare/src/tests/services/forumservicetest.h index 046d7353c..9e0cf8ebc 100644 --- a/libretroshare/src/tests/services/forumservicetest.h +++ b/libretroshare/src/tests/services/forumservicetest.h @@ -29,6 +29,9 @@ #include "servicetest.h" #include "services/p3forums.h" +#include "util/utest.h" + + INITTEST() class forumServiceTest : public ServiceTest { diff --git a/libretroshare/src/tests/services/servicetest.cc b/libretroshare/src/tests/services/servicetest.cc index ef3956274..88f556430 100644 --- a/libretroshare/src/tests/services/servicetest.cc +++ b/libretroshare/src/tests/services/servicetest.cc @@ -34,6 +34,8 @@ ServiceTest::ServiceTest() SecurityPolicy *none = secpolicy_create(); mPersonGrp = new pqisslpersongrp(none, NULL); mPeers = new p3Peers(mConnMgr); + + mConnMgr->addFriend(fakePeer); } ServiceTest::~ServiceTest() diff --git a/libretroshare/src/tests/services/servicetest.h b/libretroshare/src/tests/services/servicetest.h index 45249cb95..ca24e9f0e 100644 --- a/libretroshare/src/tests/services/servicetest.h +++ b/libretroshare/src/tests/services/servicetest.h @@ -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 + };