Add chatroom discovery logic
Change-Id: I1b65b7bbcf321c51cb00e8d1c05a42291601a284
diff --git a/test/dummy-client-face.hpp b/test/dummy-client-face.hpp
new file mode 100644
index 0000000..52e871e
--- /dev/null
+++ b/test/dummy-client-face.hpp
@@ -0,0 +1,141 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#ifndef NDN_TESTS_UNIT_TESTS_DUMMY_CLIENT_FACE_HPP
+#define NDN_TESTS_UNIT_TESTS_DUMMY_CLIENT_FACE_HPP
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/transport/transport.hpp>
+
+namespace chronos {
+namespace test {
+
+class DummyClientTransport : public ndn::Transport
+{
+public:
+ void
+ receive(const Block& block)
+ {
+ if (static_cast<bool>(m_receiveCallback))
+ m_receiveCallback(block);
+ }
+
+ virtual void
+ close()
+ {
+ }
+
+ virtual void
+ pause()
+ {
+ }
+
+ virtual void
+ resume()
+ {
+ }
+
+ virtual void
+ send(const Block& wire)
+ {
+ if (wire.type() == tlv::Interest) {
+ m_sentInterests->push_back(Interest(wire));
+ }
+ else if (wire.type() == tlv::Data) {
+ m_sentDatas->push_back(Data(wire));
+ }
+ }
+
+ virtual void
+ send(const Block& header, const Block& payload)
+ {
+ this->send(payload);
+ }
+
+public:
+ std::vector<Interest>* m_sentInterests;
+ std::vector<Data>* m_sentDatas;
+};
+
+
+/** \brief a client-side face for unit testing
+ */
+class DummyClientFace : public ndn::Face
+{
+public:
+ explicit
+ DummyClientFace(shared_ptr<DummyClientTransport> transport)
+ : Face(transport)
+ , m_transport(transport)
+ {
+ m_transport->m_sentInterests = &m_sentInterests;
+ m_transport->m_sentDatas = &m_sentDatas;
+ }
+
+ DummyClientFace(shared_ptr<DummyClientTransport> transport, boost::asio::io_service& ioService)
+ : Face(transport, ioService)
+ , m_transport(transport)
+ {
+ m_transport->m_sentInterests = &m_sentInterests;
+ m_transport->m_sentDatas = &m_sentDatas;
+ }
+
+ /** \brief cause the Face to receive a packet
+ */
+ template<typename Packet>
+ void
+ receive(const Packet& packet)
+ {
+ m_transport->receive(packet.wireEncode());
+ }
+
+public:
+ /** \brief sent Interests
+ * \note After .expressInterest, .processEvents must be called before
+ * the Interest would show up here.
+ */
+ std::vector<Interest> m_sentInterests;
+ /** \brief sent Datas
+ * \note After .put, .processEvents must be called before
+ * the Interest would show up here.
+ */
+ std::vector<Data> m_sentDatas;
+
+private:
+ shared_ptr<DummyClientTransport> m_transport;
+};
+
+inline shared_ptr<DummyClientFace>
+makeDummyClientFace()
+{
+ return make_shared<DummyClientFace>(make_shared<DummyClientTransport>());
+}
+
+inline shared_ptr<DummyClientFace>
+makeDummyClientFace(boost::asio::io_service& ioService)
+{
+ return make_shared<DummyClientFace>(make_shared<DummyClientTransport>(), ref(ioService));
+}
+
+} // namespace tests
+} // namespace ndn
+
+#endif // NDN_TESTS_UNIT_TESTS_DUMMY_CLIENT_FACE_HPP
diff --git a/test/test-chatroom-discovery-logic.cpp b/test/test-chatroom-discovery-logic.cpp
new file mode 100644
index 0000000..1714e8a
--- /dev/null
+++ b/test/test-chatroom-discovery-logic.cpp
@@ -0,0 +1,328 @@
+#include "chatroom-discovery-logic.hpp"
+#include <boost/test/unit_test.hpp>
+#include "dummy-client-face.hpp"
+
+namespace chronos {
+
+namespace test {
+
+using std::string;
+
+BOOST_AUTO_TEST_SUITE(TestChatroomDiscoveryLogic)
+
+class Fixture
+{
+public:
+ Fixture()
+ : face(makeDummyClientFace())
+ {
+ }
+
+ void
+ update(const ChatroomInfo& chatroomName, bool isAdd)
+ {
+ }
+
+public:
+ shared_ptr<DummyClientFace> face;
+};
+
+BOOST_FIXTURE_TEST_CASE(AddLocalChatroom, Fixture)
+{
+ ChatroomDiscoveryLogic chatroomDiscoveryLogic(face, bind(&Fixture::update, this, _1, _2));
+
+ ChatroomInfo chatroom;
+ chatroom.setName(ndn::Name::Component("lunch-talk"));
+ chatroom.addParticipant(Name("/ndn/ucla/ymj"));
+ chatroom.addParticipant(Name("/ndn/ucla/alice"));
+ chatroom.setTrustModel(ChatroomInfo::TRUST_MODEL_WEBOFTRUST);
+ chatroomDiscoveryLogic.addLocalChatroom(chatroom);
+
+ ndn::Name::Component chatroomName("lunch-talk");
+
+ BOOST_CHECK_EQUAL(chatroomDiscoveryLogic.getChatrooms().size(), 1);
+ BOOST_CHECK_EQUAL(chatroom.getName(),
+ chatroomDiscoveryLogic.getChatrooms().find(chatroomName)
+ ->second.getName());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants().size(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second.getParticipants().size());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[0].toUri(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second
+ .getParticipants()[0].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[1].toUri(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second
+ .getParticipants()[1].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getTrustModel(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second.getTrustModel());
+}
+
+BOOST_FIXTURE_TEST_CASE(RemoveLocalChatroom, Fixture)
+{
+ ChatroomDiscoveryLogic chatroomDiscoveryLogic(face, bind(&Fixture::update, this, _1, _2));
+
+ ChatroomInfo chatroom;
+ chatroom.setName(ndn::Name::Component("lunch-talk"));
+ chatroom.addParticipant(Name("/ndn/ucla/ymj"));
+ chatroom.addParticipant(Name("/ndn/ucla/alice"));
+ chatroom.setTrustModel(ChatroomInfo::TRUST_MODEL_WEBOFTRUST);
+ chatroomDiscoveryLogic.addLocalChatroom(chatroom);
+
+ ndn::Name::Component chatroomName1("lunch-talk");
+ ndn::Name::Component chatroomName2("supper-talk");
+
+ chatroomDiscoveryLogic.removeLocalChatroom(chatroomName2);
+
+ BOOST_CHECK_EQUAL(chatroomDiscoveryLogic.getChatrooms().size(), 1);
+ BOOST_CHECK_EQUAL(chatroom.getName(),
+ chatroomDiscoveryLogic.getChatrooms().find(chatroomName1)
+ ->second.getName());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants().size(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName1)->second.getParticipants().size());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[0].toUri(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName1)->second
+ .getParticipants()[0].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[1].toUri(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName1)->second
+ .getParticipants()[1].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getTrustModel(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName1)->second.getTrustModel());
+
+ chatroomDiscoveryLogic.removeLocalChatroom(chatroomName1);
+ BOOST_CHECK_EQUAL(chatroomDiscoveryLogic.getChatrooms().size(), 0);
+}
+
+BOOST_FIXTURE_TEST_CASE(sendChatroomInterestFunction, Fixture)
+{
+ ChatroomDiscoveryLogic chatroomDiscoveryLogic(face, bind(&Fixture::update, this, _1, _2));
+ chatroomDiscoveryLogic.sendDiscoveryInterest();
+
+ face->processEvents(time::milliseconds(100));
+
+ //with no exclude filter
+ BOOST_CHECK_EQUAL(face->m_sentInterests.size(), 2);//first is nfd register interest
+ BOOST_CHECK_EQUAL(face->m_sentDatas.size(), 0);
+ BOOST_CHECK_EQUAL(face->m_sentInterests[1].getName().toUri(),
+ ChatroomDiscoveryLogic::DISCOVERY_PREFIX.toUri());
+ BOOST_CHECK_EQUAL(face->m_sentInterests[1].getExclude().size(), 0);
+
+ face->m_sentInterests.clear();
+
+ //with exclude filter
+ ChatroomInfo chatroom;
+ chatroom.setName(ndn::Name::Component("lunch-talk"));
+ chatroom.addParticipant(Name("/ndn/ucla/ymj"));
+ chatroom.addParticipant(Name("/ndn/ucla/alice"));
+ chatroom.setTrustModel(ChatroomInfo::TRUST_MODEL_WEBOFTRUST);
+ chatroomDiscoveryLogic.addLocalChatroom(chatroom);
+
+ chatroomDiscoveryLogic.sendDiscoveryInterest();
+ face->processEvents(time::milliseconds(100));
+
+ BOOST_CHECK_EQUAL(face->m_sentInterests.size(), 1);
+ BOOST_CHECK_EQUAL(face->m_sentDatas.size(), 0);
+ BOOST_CHECK_EQUAL(face->m_sentInterests[0].getName().toUri(),
+ ChatroomDiscoveryLogic::DISCOVERY_PREFIX.toUri());
+ BOOST_CHECK_EQUAL(face->m_sentInterests[0].getExclude().size(), 1);
+ BOOST_CHECK_EQUAL(face->m_sentInterests[0].getExclude().toUri(), "lunch-talk");
+}
+
+BOOST_FIXTURE_TEST_CASE(onDiscoveryInterest, Fixture)
+{
+ face->m_sentInterests.clear();
+ face->m_sentDatas.clear();
+
+ Interest discovery(ChatroomDiscoveryLogic::DISCOVERY_PREFIX);
+ discovery.setMustBeFresh(true);
+ discovery.setInterestLifetime(time::milliseconds(10000));
+
+ Exclude exclude;
+ exclude.excludeOne(ndn::Name::Component("lunch-talk"));
+ discovery.setExclude(exclude);
+
+ ChatroomDiscoveryLogic chatroomDiscoveryLogic(face, bind(&Fixture::update, this, _1, _2));
+
+ ChatroomInfo chatroom1;
+ chatroom1.setName(ndn::Name::Component("lunch-talk"));
+ chatroom1.addParticipant(Name("/ndn/ucla/ymj"));
+ chatroom1.addParticipant(Name("/ndn/ucla/alice"));
+ chatroom1.setTrustModel(ChatroomInfo::TRUST_MODEL_WEBOFTRUST);
+ chatroomDiscoveryLogic.addLocalChatroom(chatroom1);
+
+ ChatroomInfo chatroom2;
+ chatroom2.setName(ndn::Name::Component("supper-talk"));
+ chatroom2.addParticipant(Name("/ndn/ucla/bob"));
+ chatroom2.addParticipant(Name("/ndn/ucla/peter"));
+ chatroom2.setTrustModel(ChatroomInfo::TRUST_MODEL_HIERARCHICAL);
+ chatroomDiscoveryLogic.addLocalChatroom(chatroom2);
+
+ //discovery
+ chatroomDiscoveryLogic.onDiscoveryInterest(ChatroomDiscoveryLogic::DISCOVERY_PREFIX, discovery);
+
+ face->processEvents(time::milliseconds(100));
+
+ BOOST_CHECK_EQUAL(face->m_sentInterests.size(), 1);//the interest is for nfd register
+ BOOST_CHECK_EQUAL(face->m_sentDatas.size(), 1);
+
+ ChatroomInfo chatroom;
+ chatroom.wireDecode(face->m_sentDatas[0].getContent().blockFromValue());
+ chatroom.setName(face->m_sentDatas[0].getName()
+ .get(ChatroomDiscoveryLogic::OFFSET_CHATROOM_NAME));
+
+ BOOST_CHECK_EQUAL(chatroom.getName(), chatroom2.getName());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants().size(),
+ chatroom2.getParticipants().size());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[0].toUri(),
+ chatroom2.getParticipants()[0].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[1].toUri(),
+ chatroom2.getParticipants()[1].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getTrustModel(),
+ chatroom2.getTrustModel());
+
+ //refreshing
+ face->m_sentInterests.clear();
+ face->m_sentDatas.clear();
+
+ Name name = ChatroomDiscoveryLogic::DISCOVERY_PREFIX;
+ name.append(Name("supper-talk"));
+
+ Interest refreshing(name);
+ refreshing.setMustBeFresh(true);
+ refreshing.setInterestLifetime(time::milliseconds(10000));
+
+ chatroomDiscoveryLogic.onDiscoveryInterest(name, refreshing);
+ face->processEvents(time::milliseconds(100));
+
+ BOOST_CHECK_EQUAL(face->m_sentInterests.size(), 0);
+ BOOST_CHECK_EQUAL(face->m_sentDatas.size(), 1);
+
+ chatroom.wireDecode(face->m_sentDatas[0].getContent().blockFromValue());
+ chatroom.setName(face->m_sentDatas[0].getName()
+ .get(ChatroomDiscoveryLogic::OFFSET_CHATROOM_NAME));
+
+ BOOST_CHECK_EQUAL(chatroom.getName(), chatroom2.getName());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants().size(),
+ chatroom2.getParticipants().size());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[0].toUri(),
+ chatroom2.getParticipants()[0].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[1].toUri(),
+ chatroom2.getParticipants()[1].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getTrustModel(),
+ chatroom2.getTrustModel());
+}
+
+BOOST_FIXTURE_TEST_CASE(refreshChatroomFunction, Fixture)
+{
+ ChatroomDiscoveryLogic chatroomDiscoveryLogic(face, bind(&Fixture::update, this, _1, _2));
+
+ ChatroomInfo chatroom1;
+ chatroom1.setName(ndn::Name::Component("lunch-talk"));
+ chatroom1.addParticipant(Name("/ndn/ucla/ymj"));
+ chatroom1.addParticipant(Name("/ndn/ucla/alice"));
+ chatroom1.setTrustModel(ChatroomInfo::TRUST_MODEL_WEBOFTRUST);
+ chatroomDiscoveryLogic.addLocalChatroom(chatroom1);
+
+ chatroomDiscoveryLogic.refreshChatroom(ndn::Name::Component("lunch-talk"));
+ face->processEvents(time::milliseconds(100));
+
+ BOOST_CHECK_EQUAL(face->m_sentInterests.size(), 2);
+ BOOST_CHECK_EQUAL(face->m_sentDatas.size(), 0);
+
+ Name name = ChatroomDiscoveryLogic::DISCOVERY_PREFIX;
+ name.append(Name("lunch-talk"));
+
+ BOOST_CHECK_EQUAL(face->m_sentInterests[1].getName().toUri(), name.toUri());
+ BOOST_CHECK_EQUAL(face->m_sentInterests[1].getExclude().size(), 0);
+}
+
+BOOST_FIXTURE_TEST_CASE(onReceiveData, Fixture)
+{
+ ChatroomDiscoveryLogic chatroomDiscoveryLogic(face, bind(&Fixture::update, this, _1, _2));
+
+ //discovery
+ Interest discovery(ChatroomDiscoveryLogic::DISCOVERY_PREFIX);
+ discovery.setMustBeFresh(true);
+ discovery.setInterestLifetime(time::milliseconds(10000));
+
+ Name dataName(ChatroomDiscoveryLogic::DISCOVERY_PREFIX);
+ dataName.append(ndn::Name::Component("lunch-talk"));
+
+ ChatroomInfo chatroom1;
+ chatroom1.setName(ndn::Name::Component("lunch-talk"));
+ chatroom1.addParticipant(Name("/ndn/ucla/ymj"));
+ chatroom1.addParticipant(Name("/ndn/ucla/alice"));
+ chatroom1.setTrustModel(ChatroomInfo::TRUST_MODEL_WEBOFTRUST);
+
+ shared_ptr<Data> chatroomInfo = make_shared<Data>(dataName);
+ chatroomInfo->setFreshnessPeriod(time::seconds(10));
+ chatroomInfo->setContent(chatroom1.wireEncode());
+
+ chatroomDiscoveryLogic.onReceiveData(discovery, *chatroomInfo, false);
+
+ face->processEvents(time::milliseconds(1000));
+
+ ndn::Name::Component chatroomName("lunch-talk");
+
+ BOOST_CHECK_EQUAL(chatroomDiscoveryLogic.getChatrooms().size(), 1);
+ BOOST_CHECK_EQUAL(chatroom1.getName(),
+ chatroomDiscoveryLogic.getChatrooms().find(chatroomName)
+ ->second.getName());
+ BOOST_CHECK_EQUAL(chatroom1.getParticipants().size(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second.getParticipants().size());
+ BOOST_CHECK_EQUAL(chatroom1.getParticipants()[0].toUri(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second
+ .getParticipants()[0].toUri());
+ BOOST_CHECK_EQUAL(chatroom1.getParticipants()[1].toUri(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second
+ .getParticipants()[1].toUri());
+ BOOST_CHECK_EQUAL(chatroom1.getTrustModel(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second.getTrustModel());
+
+ //refreshing
+ Name name = ChatroomDiscoveryLogic::DISCOVERY_PREFIX;
+ name.append(Name("lunch-talk"));
+
+ Interest refreshing(name);
+ refreshing.setMustBeFresh(true);
+ refreshing.setInterestLifetime(time::milliseconds(10000));
+
+ chatroomDiscoveryLogic.onReceiveData(discovery, *chatroomInfo, false);
+
+ face->processEvents(time::milliseconds(1000));
+
+ BOOST_CHECK_EQUAL(chatroomDiscoveryLogic.getChatrooms().size(), 1);
+ BOOST_CHECK_EQUAL(chatroom1.getName(),
+ chatroomDiscoveryLogic.getChatrooms().find(chatroomName)
+ ->second.getName());
+ BOOST_CHECK_EQUAL(chatroom1.getParticipants().size(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second.getParticipants().size());
+ BOOST_CHECK_EQUAL(chatroom1.getParticipants()[0].toUri(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second
+ .getParticipants()[0].toUri());
+ BOOST_CHECK_EQUAL(chatroom1.getParticipants()[1].toUri(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second
+ .getParticipants()[1].toUri());
+ BOOST_CHECK_EQUAL(chatroom1.getTrustModel(),
+ chatroomDiscoveryLogic
+ .getChatrooms().find(chatroomName)->second.getTrustModel());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace test
+
+} // namespace chronos
diff --git a/test/test-chatroom-info.cpp b/test/test-chatroom-info.cpp
new file mode 100644
index 0000000..a1b444e
--- /dev/null
+++ b/test/test-chatroom-info.cpp
@@ -0,0 +1,175 @@
+#include "chatroom-info.hpp"
+#include <boost/test/unit_test.hpp>
+#include <ndn-cxx/encoding/block.hpp>
+
+namespace chronos {
+
+namespace test {
+
+using std::string;
+
+BOOST_AUTO_TEST_SUITE(TestChatroomInfo)
+
+const uint8_t chatroomInfo[] = {
+ 0x81, 0x2d, // ChatroomInfo
+ 0x82, 0x01, // TrustModel
+ 0x01,
+ 0x80, 0x14,// Participant1
+ 0x07, 0x12,
+ 0x08, 0x03,
+ 0x6e, 0x64, 0x6e,
+ 0x08, 0x04,
+ 0x75, 0x63, 0x6c, 0x61,
+ 0x08, 0x05,
+ 0x61, 0x6c, 0x69, 0x63, 0x65,
+ 0x80, 0x12, // Participant2
+ 0x07, 0x10,
+ 0x08, 0x03,
+ 0x6e, 0x64, 0x6e,
+ 0x08, 0x04,
+ 0x75, 0x63, 0x6c, 0x61,
+ 0x08, 0x03,
+ 0x79, 0x6d, 0x6a
+};
+
+BOOST_AUTO_TEST_CASE(EncodeChatroom)
+{
+ //Chatroom := CHATROOM-TYPE TLV-LENGTH
+ // TrustModel
+ // Participant+
+
+ ChatroomInfo chatroom;
+ chatroom.setName(ndn::Name::Component("lunch-talk"));
+ chatroom.addParticipant(Name("/ndn/ucla/alice"));
+ chatroom.addParticipant(Name("/ndn/ucla/ymj"));
+ chatroom.setTrustModel(ChatroomInfo::TRUST_MODEL_WEBOFTRUST);
+
+ const Block& encoded = chatroom.wireEncode();
+ Block chatroomInfoBlock(chatroomInfo, sizeof(chatroomInfo));
+
+ BOOST_CHECK_EQUAL_COLLECTIONS(chatroomInfoBlock.wire(),
+ chatroomInfoBlock.wire() + chatroomInfoBlock.size(),
+ encoded.wire(),
+ encoded.wire() + encoded.size());
+}
+
+BOOST_AUTO_TEST_CASE(DecodeChatroomCorrect)
+{
+ ChatroomInfo chatroom;
+ chatroom.setName(ndn::Name::Component("lunch-talk"));
+ chatroom.addParticipant(Name("/ndn/ucla/alice"));
+ chatroom.addParticipant(Name("/ndn/ucla/ymj"));
+ chatroom.setTrustModel(ChatroomInfo::TRUST_MODEL_WEBOFTRUST);
+
+ Block chatroomInfoBlock(chatroomInfo, sizeof(chatroomInfo));
+ ChatroomInfo dechatroom;
+ dechatroom.wireDecode(chatroomInfoBlock);
+ dechatroom.setName(ndn::Name::Component("lunch-talk"));
+
+ BOOST_CHECK_EQUAL(chatroom.getName(), dechatroom.getName());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants().size(), dechatroom.getParticipants().size());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[0].toUri(), dechatroom.getParticipants()[0].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getParticipants()[1].toUri(), dechatroom.getParticipants()[1].toUri());
+ BOOST_CHECK_EQUAL(chatroom.getTrustModel(), dechatroom.getTrustModel());
+}
+
+BOOST_AUTO_TEST_CASE(DecodeChatroomError)
+{
+ const uint8_t error1[] = {
+ 0x80, 0x2d, // Wrong ChatroomInfo Type (0x81, 0x2d)
+ 0x82, 0x01, // TrustModel
+ 0x01,
+ 0x80, 0x14,// Participant1
+ 0x07, 0x12,
+ 0x08, 0x03,
+ 0x6e, 0x64, 0x6e,
+ 0x08, 0x04,
+ 0x75, 0x63, 0x6c, 0x61,
+ 0x08, 0x05,
+ 0x61, 0x6c, 0x69, 0x63, 0x65,
+ 0x80, 0x12, // Participant2
+ 0x07, 0x10,
+ 0x08, 0x03,
+ 0x6e, 0x64, 0x6e,
+ 0x08, 0x04,
+ 0x75, 0x63, 0x6c, 0x61,
+ 0x08, 0x03,
+ 0x79, 0x6d, 0x6a
+ };
+
+ Block errorBlock1(error1, sizeof(error1));
+ BOOST_CHECK_THROW(ChatroomInfo chatroom(errorBlock1), ChatroomInfo::Error);
+
+ const uint8_t error2[] = {
+ 0x81, 0x2d, // ChatroomInfo
+ 0x81, 0x01, // Wrong TrustModel Type (0x82, 0x01)
+ 0x01,
+ 0x80, 0x14,// Participant1
+ 0x07, 0x12,
+ 0x08, 0x03,
+ 0x6e, 0x64, 0x6e,
+ 0x08, 0x04,
+ 0x75, 0x63, 0x6c, 0x61,
+ 0x08, 0x05,
+ 0x61, 0x6c, 0x69, 0x63, 0x65,
+ 0x80, 0x12, // Participant2
+ 0x07, 0x10,
+ 0x08, 0x03,
+ 0x6e, 0x64, 0x6e,
+ 0x08, 0x04,
+ 0x75, 0x63, 0x6c, 0x61,
+ 0x08, 0x03,
+ 0x79, 0x6d, 0x6a
+ };
+
+ Block errorBlock2(error2, sizeof(error2));
+ BOOST_CHECK_THROW(ChatroomInfo chatroom(errorBlock2), ChatroomInfo::Error);
+
+ const uint8_t error3[] = {
+ 0x81, 0x2d, // ChatroomInfo
+ 0x82, 0x01, // TrustModel
+ 0x01,
+ 0x80, 0x14,// Participant1
+ 0x07, 0x12,
+ 0x08, 0x03,
+ 0x6e, 0x64, 0x6e,
+ 0x08, 0x04,
+ 0x75, 0x63, 0x6c, 0x61,
+ 0x08, 0x05,
+ 0x61, 0x6c, 0x69, 0x63, 0x65,
+ 0x81, 0x12, // Wrong Participant Type (0x80, 0x12)
+ 0x07, 0x10,
+ 0x08, 0x03,
+ 0x6e, 0x64, 0x6e,
+ 0x08, 0x04,
+ 0x75, 0x63, 0x6c, 0x61,
+ 0x08, 0x03,
+ 0x79, 0x6d, 0x6a
+ };
+
+ Block errorBlock3(error3, sizeof(error3));
+ BOOST_CHECK_THROW(ChatroomInfo chatroom(errorBlock3), ChatroomInfo::Error);
+
+ const uint8_t error4[] = {
+ 0x81, 0x00 // Empty ChatroomInfo
+ };
+
+ Block errorBlock4(error4, sizeof(error4));
+ BOOST_CHECK_THROW(ChatroomInfo chatroom(errorBlock4), ChatroomInfo::Error);
+
+ const uint8_t error5[] = {
+ 0x81, 0x03, // ChatroomInfo
+ 0x82, 0x01, // TrustModel
+ 0x01
+ //zero Participant
+ };
+
+ Block errorBlock5(error5, sizeof(error5));
+ BOOST_CHECK_THROW(ChatroomInfo chatroom(errorBlock5), ChatroomInfo::Error);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} //namespace test
+
+} //namespace chronos