blob: 431b8c2897e862e4219c24d3a819163ae78b7151 [file] [log] [blame]
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento74daf742018-11-23 18:14:13 -05002/*
Davide Pesavento923ba442019-02-12 22:00:38 -05003 * Copyright (c) 2014-2019 Regents of the University of California,
Davide Pesaventob5f8bcc2017-02-05 17:58:05 -05004 * 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 Pesavento7e780642018-11-24 15:51:34 -050028#ifndef NDN_TESTS_UNIT_UTIL_SIMPLE_NOTIFICATION_HPP
29#define NDN_TESTS_UNIT_UTIL_SIMPLE_NOTIFICATION_HPP
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070030
Davide Pesavento7e780642018-11-24 15:51:34 -050031#include "ndn-cxx/encoding/encoding-buffer.hpp"
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070032
33namespace ndn {
Junxiao Shia60d9362014-11-12 09:38:21 -070034namespace util {
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070035namespace tests {
36
37class SimpleNotification
38{
39public:
Davide Pesaventoeee3e822016-11-26 19:19:34 +010040 SimpleNotification() = default;
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070041
42 explicit
43 SimpleNotification(const Block& block)
44 {
45 wireDecode(block);
46 }
47
48 SimpleNotification(const std::string& message)
49 : m_message(message)
50 {
51 }
52
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070053 Block
54 wireEncode() const
55 {
56 ndn::EncodingBuffer buffer;
Alexander Afanasyev74633892015-02-08 18:08:46 -080057 buffer.prependByteArrayBlock(0x8888,
58 reinterpret_cast<const uint8_t*>(m_message.c_str()),
59 m_message.size());
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -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')
Davide Pesavento923ba442019-02-12 22:00:38 -050071 NDN_THROW(tlv::Error("0x07 error"));
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070072 }
73
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070074 const std::string&
75 getMessage() const
76 {
77 return m_message;
78 }
79
80 void
81 setMessage(const std::string& message)
82 {
83 m_message = message;
84 }
85
86private:
87 std::string m_message;
88};
89
90} // namespace tests
Junxiao Shia60d9362014-11-12 09:38:21 -070091} // namespace util
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070092} // namespace ndn
93
Davide Pesavento7e780642018-11-24 15:51:34 -050094#endif // NDN_TESTS_UNIT_UTIL_SIMPLE_NOTIFICATION_HPP