Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 3 | * 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. |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 10 | * |
| 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 | |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 28 | #ifndef NDN_UNIT_TESTS_UTIL_SIMPLE_NOTIFICATION_HPP |
| 29 | #define NDN_UNIT_TESTS_UTIL_SIMPLE_NOTIFICATION_HPP |
| 30 | |
| 31 | #include "common.hpp" |
| 32 | |
| 33 | #include "encoding/encoding-buffer.hpp" |
| 34 | #include "security/key-chain.hpp" |
| 35 | |
| 36 | namespace ndn { |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 37 | namespace util { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 38 | namespace tests { |
| 39 | |
| 40 | class SimpleNotification |
| 41 | { |
| 42 | public: |
| 43 | SimpleNotification() |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | explicit |
| 48 | SimpleNotification(const Block& block) |
| 49 | { |
| 50 | wireDecode(block); |
| 51 | } |
| 52 | |
| 53 | SimpleNotification(const std::string& message) |
| 54 | : m_message(message) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | ~SimpleNotification() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | Block |
| 63 | wireEncode() const |
| 64 | { |
| 65 | ndn::EncodingBuffer buffer; |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 66 | buffer.prependByteArrayBlock(0x8888, |
| 67 | reinterpret_cast<const uint8_t*>(m_message.c_str()), |
| 68 | m_message.size()); |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 69 | return buffer.block(); |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | wireDecode(const Block& block) |
| 74 | { |
| 75 | m_message.assign(reinterpret_cast<const char*>(block.value()), |
| 76 | block.value_size()); |
| 77 | |
| 78 | // error for testing |
| 79 | if (!m_message.empty() && m_message[0] == '\x07') |
| 80 | throw tlv::Error("0x07 error"); |
| 81 | } |
| 82 | |
| 83 | public: |
| 84 | const std::string& |
| 85 | getMessage() const |
| 86 | { |
| 87 | return m_message; |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | setMessage(const std::string& message) |
| 92 | { |
| 93 | m_message = message; |
| 94 | } |
| 95 | |
| 96 | private: |
| 97 | std::string m_message; |
| 98 | }; |
| 99 | |
| 100 | } // namespace tests |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 101 | } // namespace util |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 102 | } // namespace ndn |
| 103 | |
| 104 | #endif // NDN_UNIT_TESTS_UTIL_CORE_SIMPLE_NOTIFICATION_HPP |