blob: 2df3014b74d06a9a24f3753a512c931693c72dad [file] [log] [blame]
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento0f830802018-01-16 23:58:58 -05002/*
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -05003 * Copyright (c) 2014-2020 Regents of the University of California,
Davide Pesaventob5f8bcc2017-02-05 17:58:05 -05004 * 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
Davide Pesavento7e780642018-11-24 15:51:34 -050028#include "ndn-cxx/util/notification-stream.hpp"
29#include "ndn-cxx/util/dummy-client-face.hpp"
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070030
Davide Pesavento7e780642018-11-24 15:51:34 -050031#include "tests/boost-test.hpp"
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050032#include "tests/unit/io-key-chain-fixture.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050033#include "tests/unit/util/simple-notification.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
Davide Pesaventoeee3e822016-11-26 19:19:34 +010039BOOST_AUTO_TEST_SUITE(Util)
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050040BOOST_FIXTURE_TEST_SUITE(TestNotificationStream, ndn::tests::IoKeyChainFixture)
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070041
42BOOST_AUTO_TEST_CASE(Post)
43{
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050044 DummyClientFace face(m_io, m_keyChain);
45 NotificationStream<SimpleNotification> notificationStream(face,
46 "/localhost/nfd/NotificationStreamTest",
47 m_keyChain);
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070048
49 SimpleNotification event1("msg1");
50 notificationStream.postNotification(event1);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080051
Davide Pesavento0f830802018-01-16 23:58:58 -050052 advanceClocks(1_ms);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080053
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080054 BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
Davide Pesavento0f830802018-01-16 23:58:58 -050055 BOOST_CHECK_EQUAL(face.sentData[0].getName(), "/localhost/nfd/NotificationStreamTest/%FE%00");
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070056 SimpleNotification decoded1;
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080057 BOOST_CHECK_NO_THROW(decoded1.wireDecode(face.sentData[0].getContent().blockFromValue()));
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070058 BOOST_CHECK_EQUAL(decoded1.getMessage(), "msg1");
59
60 SimpleNotification event2("msg2");
61 notificationStream.postNotification(event2);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080062
Davide Pesavento0f830802018-01-16 23:58:58 -050063 advanceClocks(1_ms);
Alexander Afanasyevd3a55b22014-11-18 19:23:28 -080064
Alexander Afanasyev9bdbb832015-12-30 12:54:22 -080065 BOOST_REQUIRE_EQUAL(face.sentData.size(), 2);
Davide Pesavento0f830802018-01-16 23:58:58 -050066 BOOST_CHECK_EQUAL(face.sentData[1].getName(), "/localhost/nfd/NotificationStreamTest/%FE%01");
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070067 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
Davide Pesaventoeee3e822016-11-26 19:19:34 +010072BOOST_AUTO_TEST_SUITE_END() // TestNotificationStream
73BOOST_AUTO_TEST_SUITE_END() // Util
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070074
75} // namespace tests
Junxiao Shia60d9362014-11-12 09:38:21 -070076} // namespace util
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070077} // namespace ndn