blob: 64057e32fc92dec8186baccd9114636f78382698 [file] [log] [blame]
Junxiao Shi15b12e72014-08-09 19:56:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev95ff7112015-02-10 19:11:33 -08003 * 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 Shi15b12e72014-08-09 19:56:24 -070010 *
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#ifndef NFD_TESTS_CORE_SIMPLE_NOTIFICATION_HPP
27#define NFD_TESTS_CORE_SIMPLE_NOTIFICATION_HPP
28
29#include "common.hpp"
30
31#include "tests/test-common.hpp"
32
33namespace nfd {
34namespace tests {
35
36class SimpleNotification
37{
38public:
39 SimpleNotification()
40 {
41 }
42
43 SimpleNotification(const std::string& message)
44 : m_message(message)
45 {
46 }
47
48 ~SimpleNotification()
49 {
50 }
51
52 Block
53 wireEncode() const
54 {
55 ndn::EncodingBuffer buffer;
Alexander Afanasyev95ff7112015-02-10 19:11:33 -080056 ndn::prependByteArrayBlock(buffer,
57 0x8888,
58 reinterpret_cast<const uint8_t*>(m_message.c_str()),
59 m_message.size());
Junxiao Shi15b12e72014-08-09 19:56:24 -070060 return buffer.block();
61 }
62
63 void
64 wireDecode(const Block& block)
65 {
66 m_message.assign(reinterpret_cast<const char*>(block.value()),
67 block.value_size());
68
69 // error for testing
70 if (!m_message.empty() && m_message[0] == '\x07')
71 throw tlv::Error("0x07 error");
72 }
73
74public:
75 const std::string&
76 getMessage() const
77 {
78 return m_message;
79 }
80
81 void
82 setMessage(const std::string& message)
83 {
84 m_message = message;
85 }
86
87private:
88 std::string m_message;
89};
90
91} // namespace tests
92} // namespace nfd
93
94#endif // NFD_TESTS_CORE_SIMPLE_NOTIFICATION_HPP