RetroShare/tests/unittests/libretroshare/serialiser/rsgxsupdateitem_test.cc

120 lines
4.0 KiB
C++
Raw Normal View History

2018-11-04 15:17:22 -05:00
/*******************************************************************************
* unittests/libretroshare/serialiser/rsgxsupdateitem_test.cc *
* *
* Copyright 2013 by Crispy <retroshare.project@gmail.com> *
2018-11-04 15:17:22 -05:00
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
******************************************************************************/
#include <gtest/gtest.h>
#include "support.h"
#include "rsitems/rsgxsupdateitems.h"
#define RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM 0x0010
2017-07-24 06:16:06 -04:00
void init_item(RsGxsGrpUpdateItem& i)
{
i.clear();
i.grpUpdateTS = rand()%2424;
2016-12-08 08:30:47 -05:00
i.peerID = RsPeerId::random();
}
2017-07-24 06:16:06 -04:00
void init_item(RsGxsMsgUpdateItem& i)
{
i.clear();
2016-12-08 08:30:47 -05:00
i.peerID = RsPeerId::random();
int numUpdates = rand()%123;
2016-12-08 08:30:47 -05:00
i.peerID = RsPeerId::random();
for(int j=0; j < numUpdates; j++)
{
struct RsGxsMsgUpdateItem::MsgUpdateInfo info;
info.message_count = rand();
info.time_stamp = rand()%45;
i.msgUpdateInfos[RsGxsGroupId::random()] = info;
}
}
2017-07-24 06:16:06 -04:00
void init_item(RsGxsServerGrpUpdateItem& i)
{
i.clear();
i.grpUpdateTS = rand()%2424;
}
2017-07-24 06:16:06 -04:00
void init_item(RsGxsServerMsgUpdateItem& i)
{
i.clear();
i.grpId = RsGxsGroupId::random();
i.msgUpdateTS = rand()%4252;
}
bool operator ==(const RsGxsGrpUpdateItem& l, const RsGxsGrpUpdateItem& r)
{
bool ok = l.grpUpdateTS == r.grpUpdateTS;
2016-12-08 08:30:47 -05:00
ok &= l.peerID == r.peerID;
return ok;
}
bool operator ==(const RsGxsMsgUpdateItem::MsgUpdateInfo& l, const RsGxsMsgUpdateItem::MsgUpdateInfo& r)
{
return (l.message_count == r.message_count) && (l.time_stamp == r.time_stamp);
}
bool operator ==(const RsGxsMsgUpdateItem& l, const RsGxsMsgUpdateItem& r)
{
2016-12-08 08:30:47 -05:00
bool ok = l.peerID == r.peerID;
const std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>& lUp = l.msgUpdateInfos, rUp = r.msgUpdateInfos;
ok &= lUp.size() == rUp.size();
std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>::const_iterator lit = lUp.begin(), rit;
for(; lit != lUp.end(); lit++)
{
RsGxsGroupId key = lit->first;
if((rit = rUp.find(key)) != rUp.end())
ok &= lit->second == rit->second;
else
return false;
}
return ok;
}
bool operator ==(const RsGxsServerGrpUpdateItem& l,
const RsGxsServerGrpUpdateItem& r)
{
return l.grpUpdateTS == r.grpUpdateTS;
}
bool operator ==(const RsGxsServerMsgUpdateItem& l,
const RsGxsServerMsgUpdateItem& r)
{
bool ok = l.grpId == r.grpId;
ok &= l.msgUpdateTS == r.msgUpdateTS;
return ok;
}
TEST(libretroshare_serialiser, RsGxsGrpUpateItem)
{
2017-07-24 06:16:06 -04:00
test_RsItem<RsGxsGrpUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsGxsMsgUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsGxsServerGrpUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
test_RsItem<RsGxsServerMsgUpdateItem,RsGxsUpdateSerialiser>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}