blob: e2314274d5b1a3888fb1a06ac9b15638416ecfb9 [file] [log] [blame]
Junxiao Shi15b12e72014-08-09 19:56:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "core/notification-stream.hpp"
27#include "simple-notification.hpp"
28
29#include "tests/test-common.hpp"
Junxiao Shi376f7372014-11-17 18:03:31 -070030#include <ndn-cxx/util/dummy-client-face.hpp>
Junxiao Shi15b12e72014-08-09 19:56:24 -070031
32namespace nfd {
33namespace tests {
34
35BOOST_FIXTURE_TEST_SUITE(CoreNotificationStream, BaseFixture)
36
37BOOST_AUTO_TEST_CASE(Post)
38{
Junxiao Shi376f7372014-11-17 18:03:31 -070039 shared_ptr<ndn::util::DummyClientFace> face = ndn::util::makeDummyClientFace();
Junxiao Shi15b12e72014-08-09 19:56:24 -070040 ndn::KeyChain keyChain;
Junxiao Shi376f7372014-11-17 18:03:31 -070041 NotificationStream<ndn::util::DummyClientFace> notificationStream(*face,
Junxiao Shi15b12e72014-08-09 19:56:24 -070042 "/localhost/nfd/NotificationStreamTest", keyChain);
43
44 SimpleNotification event1("msg1");
45 notificationStream.postNotification(event1);
46 face->processEvents();
Junxiao Shi376f7372014-11-17 18:03:31 -070047 BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1);
48 BOOST_CHECK_EQUAL(face->sentDatas[0].getName(),
Junxiao Shi15b12e72014-08-09 19:56:24 -070049 "/localhost/nfd/NotificationStreamTest/%FE%00");
50 SimpleNotification decoded1;
Junxiao Shi376f7372014-11-17 18:03:31 -070051 BOOST_CHECK_NO_THROW(decoded1.wireDecode(face->sentDatas[0].getContent().blockFromValue()));
Junxiao Shi15b12e72014-08-09 19:56:24 -070052 BOOST_CHECK_EQUAL(decoded1.getMessage(), "msg1");
53
54 SimpleNotification event2("msg2");
55 notificationStream.postNotification(event2);
56 face->processEvents();
Junxiao Shi376f7372014-11-17 18:03:31 -070057 BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 2);
58 BOOST_CHECK_EQUAL(face->sentDatas[1].getName(),
Junxiao Shi15b12e72014-08-09 19:56:24 -070059 "/localhost/nfd/NotificationStreamTest/%FE%01");
60 SimpleNotification decoded2;
Junxiao Shi376f7372014-11-17 18:03:31 -070061 BOOST_CHECK_NO_THROW(decoded2.wireDecode(face->sentDatas[1].getContent().blockFromValue()));
Junxiao Shi15b12e72014-08-09 19:56:24 -070062 BOOST_CHECK_EQUAL(decoded2.getMessage(), "msg2");
63}
64
65BOOST_AUTO_TEST_SUITE_END()
66
67} // namespace tests
68} // namespace nfd