Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, 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. |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 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 Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 30 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace tests { |
| 34 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 35 | BOOST_FIXTURE_TEST_SUITE(TestNotificationStream, BaseFixture) |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 36 | |
| 37 | BOOST_AUTO_TEST_CASE(Post) |
| 38 | { |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 39 | shared_ptr<ndn::util::DummyClientFace> face = ndn::util::makeDummyClientFace(); |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 40 | ndn::KeyChain keyChain; |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 41 | NotificationStream<ndn::util::DummyClientFace> notificationStream(*face, |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 42 | "/localhost/nfd/NotificationStreamTest", keyChain); |
| 43 | |
| 44 | SimpleNotification event1("msg1"); |
| 45 | notificationStream.postNotification(event1); |
| 46 | face->processEvents(); |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 47 | BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1); |
| 48 | BOOST_CHECK_EQUAL(face->sentDatas[0].getName(), |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 49 | "/localhost/nfd/NotificationStreamTest/%FE%00"); |
| 50 | SimpleNotification decoded1; |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 51 | BOOST_CHECK_NO_THROW(decoded1.wireDecode(face->sentDatas[0].getContent().blockFromValue())); |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(decoded1.getMessage(), "msg1"); |
| 53 | |
| 54 | SimpleNotification event2("msg2"); |
| 55 | notificationStream.postNotification(event2); |
| 56 | face->processEvents(); |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 57 | BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 2); |
| 58 | BOOST_CHECK_EQUAL(face->sentDatas[1].getName(), |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 59 | "/localhost/nfd/NotificationStreamTest/%FE%01"); |
| 60 | SimpleNotification decoded2; |
Junxiao Shi | 376f737 | 2014-11-17 18:03:31 -0700 | [diff] [blame] | 61 | BOOST_CHECK_NO_THROW(decoded2.wireDecode(face->sentDatas[1].getContent().blockFromValue())); |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 62 | BOOST_CHECK_EQUAL(decoded2.getMessage(), "msg2"); |
| 63 | } |
| 64 | |
| 65 | BOOST_AUTO_TEST_SUITE_END() |
| 66 | |
| 67 | } // namespace tests |
| 68 | } // namespace nfd |