/* * libretroshare/src/tests/serialiser: msgitem_test.cc * * RetroShare Serialiser. * * Copyright 2010 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 #include #include #include #include "grouter/grouteritems.h" #include "support.h" #include "rstlvutil.h" RsSerialType* init_item(RsGRouterGenericDataItem& cmi) { cmi.routing_id = RSRandom::random_u32() ; cmi.destination_key = GRouterKeyId::random() ; cmi.data_size = lrand48()%1000 + 1000 ; cmi.data_bytes = (uint8_t*)malloc(cmi.data_size) ; RSRandom::random_bytes(cmi.data_bytes,cmi.data_size) ; init_item(cmi.signature) ; cmi.randomized_distance = RSRandom::random_u32() ; cmi.flags = RSRandom::random_u32() ; return new RsGRouterSerialiser(); } RsSerialType* init_item(RsGRouterReceiptItem& cmi) { cmi.mid = RSRandom::random_u64() ; cmi.state = RSRandom::random_u32() ; cmi.destination_key = GRouterKeyId::random() ; init_item(cmi.signature) ; return new RsGRouterSerialiser(); } RsSerialType* init_item(RsGRouterRoutingInfoItem& cmi) { cmi.origin = SSLIdType::random() ; cmi.received_time = RSRandom::random_u64() ; cmi.last_sent = RSRandom::random_u64() ; cmi.status_flags = RSRandom::random_u32() ; cmi.data_item = new RsGRouterGenericDataItem ; init_item(*cmi.data_item) ; uint32_t n = 10+(RSRandom::random_u32()%30) ; for(uint32_t i=0;idestination_key ; cmi.client_id = RSRandom::random_u32() ; return new RsGRouterSerialiser(); } RsSerialType* init_item(RsGRouterMatrixFriendListItem& cmi) { uint32_t n = 10+(RSRandom::random_u32()%30) ; cmi.reverse_friend_indices.clear() ; for(uint32_t i=0;i::const_iterator itl = cmiLeft.clues.begin() ; std::list::const_iterator itr = cmiRight.clues.begin() ; while(itl != cmiLeft.clues.end()) { if( (*itl).friend_id != (*itr).friend_id) return false ; if( (*itl).time_stamp != (*itr).time_stamp) return false ; ++itl ; ++itr ; } return true; } bool operator ==(const RsGRouterMatrixFriendListItem& cmiLeft,const RsGRouterMatrixFriendListItem& cmiRight) { if(cmiLeft.reverse_friend_indices.size() != cmiRight.reverse_friend_indices.size()) return false; for(uint32_t i=0;i::const_iterator itl(cmiLeft.tried_friends.begin()) ; std::list::const_iterator itr(cmiRight.tried_friends.begin()) ; // while(itl != cmiLeft.tried_friends.end()) // { // if( (*itl).friend_id != (*itr).friend_id) return false ; // if( (*itl).time_stamp != (*itr).time_stamp) return false ; // if( fabs((*itl).probability - (*itr).probability)<0.001) return false ; // if( (*itl).nb_friends != (*itr).nb_friends) return false ; // // ++itl ; // ++itr ; // } if(cmiLeft.destination_key != cmiRight.destination_key) return false ; if(cmiLeft.client_id != cmiRight.client_id) return false ; if(!(*cmiLeft.data_item == *cmiRight.data_item)) return false ; return true; } TEST(libretroshare_serialiser, RsGRouterItem) { test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); }