/* * 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 "util/rsrandom.h" #include "serialiser/rsmsgitems.h" #include "chat/rschatitems.h" #include "support.h" #include "rstlvutil.h" RsSerialType* init_item(RsChatMsgItem& cmi) { cmi.chatFlags = rand()%34; cmi.sendTime = rand()%422224; randString(LARGE_STR, cmi.message); return new RsChatSerialiser(); } RsSerialType* init_item(RsChatLobbyListRequestItem& ) { return new RsChatSerialiser(); } RsSerialType* init_item(RsChatLobbyListItem& cmi) { int n = rand()%20 ; cmi.lobby_ids.resize(n) ; cmi.lobby_names.resize(n) ; cmi.lobby_topics.resize(n) ; cmi.lobby_counts.resize(n) ; cmi.lobby_privacy_levels.resize(n) ; for(int i=0;i(&cmi)) ; cmi.msg_id = RSRandom::random_u64() ; cmi.lobby_id = RSRandom::random_u64() ; cmi.nick = "My nickname" ; cmi.subpacket_id = rand()%256 ; cmi.parent_msg_id = RSRandom::random_u64() ; return serial ; } RsSerialType *init_item(RsChatLobbyEventItem& cmi) { cmi.lobby_id = RSRandom::random_u64() ; cmi.msg_id = RSRandom::random_u64() ; randString(20, cmi.nick); cmi.event_type = RSRandom::random_u32()%256 ; randString(20, cmi.string1); return new RsChatSerialiser(); } RsSerialType* init_item(RsChatLobbyInviteItem& cmi) { cmi.lobby_id = RSRandom::random_u64() ; cmi.lobby_name = "Name of the lobby" ; return new RsChatSerialiser(); } RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi) { pcmi.configPeerId.random(); pcmi.chatFlags = rand()%34; pcmi.configFlags = rand()%21; pcmi.sendTime = rand()%422224; randString(LARGE_STR, pcmi.message); pcmi.recvTime = rand()%344443; return new RsChatSerialiser(); } RsSerialType* init_item(RsChatStatusItem& csi) { randString(SHORT_STR, csi.status_string); csi.flags = rand()%232; return new RsChatSerialiser(); } RsSerialType* init_item(RsChatAvatarItem& cai) { std::string image_data; randString(LARGE_STR, image_data); cai.image_data = new unsigned char[image_data.size()]; memcpy(cai.image_data, image_data.c_str(), image_data.size()); cai.image_size = image_data.size(); return new RsChatSerialiser(); } RsSerialType* init_item(RsMsgItem& mi) { init_item(mi.attachment); init_item(mi.rspeerid_msgbcc); init_item(mi.rspeerid_msgcc); init_item(mi.rspeerid_msgto); randString(LARGE_STR, mi.message); randString(SHORT_STR, mi.subject); mi.msgId = rand()%324232; mi.recvTime = rand()%44252; mi.sendTime = mi.recvTime; mi.msgFlags = mi.recvTime; return new RsMsgSerialiser(true); } RsSerialType* init_item(RsMsgTagType& mtt) { mtt.rgb_color = rand()%5353; mtt.tagId = rand()%24242; randString(SHORT_STR, mtt.text); return new RsMsgSerialiser(); } RsSerialType* init_item(RsMsgTags& mt) { mt.msgId = rand()%3334; int i; for (i = 0; i < 10; i++) { mt.tagIds.push_back(rand()%21341); } return new RsMsgSerialiser(); } RsSerialType* init_item(RsMsgSrcId& ms) { ms.msgId = rand()%434; ms.srcId.random(); return new RsMsgSerialiser(); } RsSerialType* init_item(RsMsgParentId& ms) { ms.msgId = rand()%354; ms.msgParentId = rand()%476; return new RsMsgSerialiser(); } bool operator ==(const RsChatLobbyListItem& cmiLeft,const RsChatLobbyListItem& cmiRight) { if(cmiLeft.lobby_ids.size() != cmiRight.lobby_ids.size()) return false; if(cmiLeft.lobby_names.size() != cmiRight.lobby_names.size()) return false; if(cmiLeft.lobby_counts.size() != cmiRight.lobby_counts.size()) return false; for(uint32_t i=0;i(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); test_RsItem(); }