Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 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" |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 50 | #include "util/dummy-client-face.hpp" |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 51 | |
| 52 | #include "boost-test.hpp" |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 53 | #include "../unit-test-time-fixture.hpp" |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 54 | |
| 55 | namespace ndn { |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 56 | namespace util { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 57 | namespace tests { |
| 58 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 59 | BOOST_FIXTURE_TEST_SUITE(UtilNotificationStream, ndn::tests::UnitTestTimeFixture) |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 60 | |
| 61 | BOOST_AUTO_TEST_CASE(Post) |
| 62 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 63 | shared_ptr<DummyClientFace> face = makeDummyClientFace(io); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 64 | ndn::KeyChain keyChain; |
| 65 | util::NotificationStream<SimpleNotification> notificationStream(*face, |
| 66 | "/localhost/nfd/NotificationStreamTest", keyChain); |
| 67 | |
| 68 | SimpleNotification event1("msg1"); |
| 69 | notificationStream.postNotification(event1); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 70 | |
| 71 | advanceClocks(time::milliseconds(1)); |
| 72 | |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 73 | BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 1); |
| 74 | BOOST_CHECK_EQUAL(face->sentDatas[0].getName(), |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 75 | "/localhost/nfd/NotificationStreamTest/%FE%00"); |
| 76 | SimpleNotification decoded1; |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 77 | BOOST_CHECK_NO_THROW(decoded1.wireDecode(face->sentDatas[0].getContent().blockFromValue())); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 78 | BOOST_CHECK_EQUAL(decoded1.getMessage(), "msg1"); |
| 79 | |
| 80 | SimpleNotification event2("msg2"); |
| 81 | notificationStream.postNotification(event2); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 82 | |
| 83 | advanceClocks(time::milliseconds(1)); |
| 84 | |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 85 | BOOST_REQUIRE_EQUAL(face->sentDatas.size(), 2); |
| 86 | BOOST_CHECK_EQUAL(face->sentDatas[1].getName(), |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 87 | "/localhost/nfd/NotificationStreamTest/%FE%01"); |
| 88 | SimpleNotification decoded2; |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 89 | BOOST_CHECK_NO_THROW(decoded2.wireDecode(face->sentDatas[1].getContent().blockFromValue())); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 90 | BOOST_CHECK_EQUAL(decoded2.getMessage(), "msg2"); |
| 91 | } |
| 92 | |
| 93 | BOOST_AUTO_TEST_SUITE_END() |
| 94 | |
| 95 | } // namespace tests |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 96 | } // namespace util |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 97 | } // namespace ndn |