2018-11-04 15:17:22 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* unittests/libretroshare/serialiser/rsgxsupdateitem_test.cc *
|
|
|
|
* *
|
2018-11-11 14:42:48 -05:00
|
|
|
* 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/>. *
|
|
|
|
* *
|
|
|
|
******************************************************************************/
|
2014-04-05 03:27:18 -04:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "support.h"
|
2017-05-04 09:01:25 -04:00
|
|
|
#include "rsitems/rsgxsupdateitems.h"
|
2014-04-05 03:27:18 -04:00
|
|
|
#define RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM 0x0010
|
|
|
|
|
2017-07-24 06:16:06 -04:00
|
|
|
void init_item(RsGxsGrpUpdateItem& i)
|
2014-04-05 03:27:18 -04:00
|
|
|
{
|
|
|
|
i.clear();
|
|
|
|
i.grpUpdateTS = rand()%2424;
|
2016-12-08 08:30:47 -05:00
|
|
|
i.peerID = RsPeerId::random();
|
2014-04-05 03:27:18 -04:00
|
|
|
}
|
|
|
|
|
2017-07-24 06:16:06 -04:00
|
|
|
void init_item(RsGxsMsgUpdateItem& i)
|
2014-04-05 03:27:18 -04:00
|
|
|
{
|
|
|
|
i.clear();
|
2016-12-08 08:30:47 -05:00
|
|
|
i.peerID = RsPeerId::random();
|
2014-04-05 03:27:18 -04:00
|
|
|
int numUpdates = rand()%123;
|
|
|
|
|
2016-12-08 08:30:47 -05:00
|
|
|
i.peerID = RsPeerId::random();
|
2014-04-05 03:27:18 -04:00
|
|
|
for(int j=0; j < numUpdates; j++)
|
|
|
|
{
|
2015-12-13 11:22:31 -05:00
|
|
|
struct RsGxsMsgUpdateItem::MsgUpdateInfo info;
|
|
|
|
info.message_count = rand();
|
|
|
|
info.time_stamp = rand()%45;
|
|
|
|
i.msgUpdateInfos[RsGxsGroupId::random()] = info;
|
2014-04-05 03:27:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 06:16:06 -04:00
|
|
|
void init_item(RsGxsServerGrpUpdateItem& i)
|
2014-04-05 03:27:18 -04:00
|
|
|
{
|
|
|
|
i.clear();
|
|
|
|
i.grpUpdateTS = rand()%2424;
|
|
|
|
}
|
|
|
|
|
2017-07-24 06:16:06 -04:00
|
|
|
void init_item(RsGxsServerMsgUpdateItem& i)
|
2014-04-05 03:27:18 -04:00
|
|
|
{
|
|
|
|
i.clear();
|
2015-01-11 17:19:32 -05:00
|
|
|
i.grpId = RsGxsGroupId::random();
|
2014-04-05 03:27:18 -04:00
|
|
|
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;
|
2014-04-05 03:27:18 -04:00
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2015-12-13 11:22:31 -05:00
|
|
|
bool operator ==(const RsGxsMsgUpdateItem::MsgUpdateInfo& l, const RsGxsMsgUpdateItem::MsgUpdateInfo& r)
|
|
|
|
{
|
|
|
|
return (l.message_count == r.message_count) && (l.time_stamp == r.time_stamp);
|
|
|
|
}
|
|
|
|
|
2014-04-05 03:27:18 -04:00
|
|
|
bool operator ==(const RsGxsMsgUpdateItem& l, const RsGxsMsgUpdateItem& r)
|
|
|
|
{
|
2016-12-08 08:30:47 -05:00
|
|
|
bool ok = l.peerID == r.peerID;
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2015-12-13 11:22:31 -05:00
|
|
|
const std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>& lUp = l.msgUpdateInfos, rUp = r.msgUpdateInfos;
|
2014-04-05 03:27:18 -04:00
|
|
|
|
|
|
|
ok &= lUp.size() == rUp.size();
|
|
|
|
|
2015-12-13 11:22:31 -05:00
|
|
|
std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>::const_iterator lit = lUp.begin(), rit;
|
2014-04-05 03:27:18 -04:00
|
|
|
|
|
|
|
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);
|
2014-04-05 03:27:18 -04:00
|
|
|
}
|