blob: ce6ec90a76255021842b74bac01df799dd7e5b36 [file] [log] [blame]
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventoeee3e822016-11-26 19:19:34 +01003 * Copyright (c) 2014-2016, Regents of the University of California,
Alexander Afanasyev74633892015-02-08 18:08:46 -08004 * 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.
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070010 *
11 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
12 *
13 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
14 * terms of the GNU Lesser General Public License as published by the Free Software
15 * Foundation, either version 3 of the License, or (at your option) any later version.
16 *
17 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
18 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20 *
21 * You should have received copies of the GNU General Public License and GNU Lesser
22 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
23 * <http://www.gnu.org/licenses/>.
24 *
25 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
26 */
27
Davide Pesaventoeee3e822016-11-26 19:19:34 +010028#ifndef NDN_TESTS_UNIT_TESTS_UTIL_SIMPLE_NOTIFICATION_HPP
29#define NDN_TESTS_UNIT_TESTS_UTIL_SIMPLE_NOTIFICATION_HPP
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070030
31#include "common.hpp"
32
33#include "encoding/encoding-buffer.hpp"
34#include "security/key-chain.hpp"
35
36namespace ndn {
Junxiao Shia60d9362014-11-12 09:38:21 -070037namespace util {
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070038namespace tests {
39
40class SimpleNotification
41{
42public:
Davide Pesaventoeee3e822016-11-26 19:19:34 +010043 SimpleNotification() = default;
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070044
45 explicit
46 SimpleNotification(const Block& block)
47 {
48 wireDecode(block);
49 }
50
51 SimpleNotification(const std::string& message)
52 : m_message(message)
53 {
54 }
55
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070056 Block
57 wireEncode() const
58 {
59 ndn::EncodingBuffer buffer;
Alexander Afanasyev74633892015-02-08 18:08:46 -080060 buffer.prependByteArrayBlock(0x8888,
61 reinterpret_cast<const uint8_t*>(m_message.c_str()),
62 m_message.size());
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070063 return buffer.block();
64 }
65
66 void
67 wireDecode(const Block& block)
68 {
69 m_message.assign(reinterpret_cast<const char*>(block.value()),
70 block.value_size());
71
72 // error for testing
73 if (!m_message.empty() && m_message[0] == '\x07')
Spyridon Mastorakis0d2ed2e2015-07-27 19:09:12 -070074 BOOST_THROW_EXCEPTION(tlv::Error("0x07 error"));
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070075 }
76
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070077 const std::string&
78 getMessage() const
79 {
80 return m_message;
81 }
82
83 void
84 setMessage(const std::string& message)
85 {
86 m_message = message;
87 }
88
89private:
90 std::string m_message;
91};
92
93} // namespace tests
Junxiao Shia60d9362014-11-12 09:38:21 -070094} // namespace util
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070095} // namespace ndn
96
Davide Pesaventoeee3e822016-11-26 19:19:34 +010097#endif // NDN_TESTS_UNIT_TESTS_UTIL_SIMPLE_NOTIFICATION_HPP