blob: df3fc5b79331174a0a2c2550d0ae9e7d8888dbc2 [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"
30#include "tests/dummy-client-face.hpp"
31
32
33namespace nfd {
34namespace tests {
35
36BOOST_FIXTURE_TEST_SUITE(CoreNotificationStream, BaseFixture)
37
38BOOST_AUTO_TEST_CASE(Post)
39{
40 shared_ptr<DummyClientFace> face = makeDummyClientFace();
41 ndn::KeyChain keyChain;
42 NotificationStream<DummyClientFace> notificationStream(*face,
43 "/localhost/nfd/NotificationStreamTest", keyChain);
44
45 SimpleNotification event1("msg1");
46 notificationStream.postNotification(event1);
47 face->processEvents();
48 BOOST_REQUIRE_EQUAL(face->m_sentDatas.size(), 1);
49 BOOST_CHECK_EQUAL(face->m_sentDatas[0].getName(),
50 "/localhost/nfd/NotificationStreamTest/%FE%00");
51 SimpleNotification decoded1;
52 BOOST_CHECK_NO_THROW(decoded1.wireDecode(face->m_sentDatas[0].getContent().blockFromValue()));
53 BOOST_CHECK_EQUAL(decoded1.getMessage(), "msg1");
54
55 SimpleNotification event2("msg2");
56 notificationStream.postNotification(event2);
57 face->processEvents();
58 BOOST_REQUIRE_EQUAL(face->m_sentDatas.size(), 2);
59 BOOST_CHECK_EQUAL(face->m_sentDatas[1].getName(),
60 "/localhost/nfd/NotificationStreamTest/%FE%01");
61 SimpleNotification decoded2;
62 BOOST_CHECK_NO_THROW(decoded2.wireDecode(face->m_sentDatas[1].getContent().blockFromValue()));
63 BOOST_CHECK_EQUAL(decoded2.getMessage(), "msg2");
64}
65
66BOOST_AUTO_TEST_SUITE_END()
67
68} // namespace tests
69} // namespace nfd