blob: 8ac084a24d4f64284464fc026847f0cbfda3bc93 [file] [log] [blame]
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -07003 * Copyright (c) 2013-2016, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070010 *
11 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
12 *
13 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
14 * terms of the GNU Lesser General Public License as published by the Free Software
15 * Foundation, either version 3 of the License, or (at your option) any later version.
16 *
17 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
18 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20 *
21 * You should have received copies of the GNU General Public License and GNU Lesser
22 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
23 * <http://www.gnu.org/licenses/>.
24 *
25 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
26 */
27
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070028#include "util/notification-stream.hpp"
29#include "simple-notification.hpp"
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080030#include "util/dummy-client-face.hpp"
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070031
32#include "boost-test.hpp"
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070033#include "../identity-management-time-fixture.hpp"
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070034
35namespace ndn {
Junxiao Shia60d9362014-11-12 09:38:21 -070036namespace util {
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070037namespace tests {
38
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070039BOOST_FIXTURE_TEST_SUITE(UtilNotificationStream, ndn::tests::IdentityManagementTimeFixture)
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070040
41BOOST_AUTO_TEST_CASE(Post)
42{
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070043 DummyClientFace face(io, m_keyChain);
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080044 util::NotificationStream<SimpleNotification> notificationStream(face,
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070045 "/localhost/nfd/NotificationStreamTest", m_keyChain);
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070046
47 SimpleNotification event1("msg1");
48 notificationStream.postNotification(event1);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080049
50 advanceClocks(time::milliseconds(1));
51
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080052 BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
53 BOOST_CHECK_EQUAL(face.sentData[0].getName(),
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070054 "/localhost/nfd/NotificationStreamTest/%FE%00");
55 SimpleNotification decoded1;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080056 BOOST_CHECK_NO_THROW(decoded1.wireDecode(face.sentData[0].getContent().blockFromValue()));
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070057 BOOST_CHECK_EQUAL(decoded1.getMessage(), "msg1");
58
59 SimpleNotification event2("msg2");
60 notificationStream.postNotification(event2);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080061
62 advanceClocks(time::milliseconds(1));
63
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080064 BOOST_REQUIRE_EQUAL(face.sentData.size(), 2);
65 BOOST_CHECK_EQUAL(face.sentData[1].getName(),
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070066 "/localhost/nfd/NotificationStreamTest/%FE%01");
67 SimpleNotification decoded2;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080068 BOOST_CHECK_NO_THROW(decoded2.wireDecode(face.sentData[1].getContent().blockFromValue()));
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070069 BOOST_CHECK_EQUAL(decoded2.getMessage(), "msg2");
70}
71
72BOOST_AUTO_TEST_SUITE_END()
73
74} // namespace tests
Junxiao Shia60d9362014-11-12 09:38:21 -070075} // namespace util
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070076} // namespace ndn