blob: adba5c7ec1c13df94784ec7bc96316d878e62388 [file] [log] [blame]
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22/**
23 * Original copyright notice from NFD:
24 *
25 * Copyright (c) 2014, Regents of the University of California,
26 * Arizona Board of Regents,
27 * Colorado State University,
28 * University Pierre & Marie Curie, Sorbonne University,
29 * Washington University in St. Louis,
30 * Beijing Institute of Technology,
31 * The University of Memphis
32 *
33 * This file is part of NFD (Named Data Networking Forwarding Daemon).
34 * See AUTHORS.md for complete list of NFD authors and contributors.
35 *
36 * NFD is free software: you can redistribute it and/or modify it under the terms
37 * of the GNU General Public License as published by the Free Software Foundation,
38 * either version 3 of the License, or (at your option) any later version.
39 *
40 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
41 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
42 * PURPOSE. See the GNU General Public License for more details.
43 *
44 * You should have received a copy of the GNU General Public License along with
45 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
46 */
47
48#include "util/notification-stream.hpp"
49#include "simple-notification.hpp"
50
51#include "boost-test.hpp"
Junxiao Shia60d9362014-11-12 09:38:21 -070052#include "util/dummy-client-face.hpp"
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070053
54namespace ndn {
Junxiao Shia60d9362014-11-12 09:38:21 -070055namespace util {
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070056namespace tests {
57
58BOOST_AUTO_TEST_SUITE(UtilNotificationStream)
59
60BOOST_AUTO_TEST_CASE(Post)
61{
62 shared_ptr<DummyClientFace> face = makeDummyClientFace();
63 ndn::KeyChain keyChain;
64 util::NotificationStream<SimpleNotification> notificationStream(*face,
65 "/localhost/nfd/NotificationStreamTest", keyChain);
66
67 SimpleNotification event1("msg1");
68 notificationStream.postNotification(event1);
69 face->processEvents();
Junxiao Shia60d9362014-11-12 09:38:21 -070070 BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
71 BOOST_CHECK_EQUAL(face->sentDatas[0].getName(),
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070072 "/localhost/nfd/NotificationStreamTest/%FE%00");
73 SimpleNotification decoded1;
Junxiao Shia60d9362014-11-12 09:38:21 -070074 BOOST_CHECK_NO_THROW(decoded1.wireDecode(face->sentDatas[0].getContent().blockFromValue()));
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070075 BOOST_CHECK_EQUAL(decoded1.getMessage(), "msg1");
76
77 SimpleNotification event2("msg2");
78 notificationStream.postNotification(event2);
79 face->processEvents();
Junxiao Shia60d9362014-11-12 09:38:21 -070080 BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 2);
81 BOOST_CHECK_EQUAL(face->sentDatas[1].getName(),
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070082 "/localhost/nfd/NotificationStreamTest/%FE%01");
83 SimpleNotification decoded2;
Junxiao Shia60d9362014-11-12 09:38:21 -070084 BOOST_CHECK_NO_THROW(decoded2.wireDecode(face->sentDatas[1].getContent().blockFromValue()));
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070085 BOOST_CHECK_EQUAL(decoded2.getMessage(), "msg2");
86}
87
88BOOST_AUTO_TEST_SUITE_END()
89
90} // namespace tests
Junxiao Shia60d9362014-11-12 09:38:21 -070091} // namespace util
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070092} // namespace ndn