Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Original copyright notice from NFD: |
| 24 | * |
| 25 | * Copyright (c) 2014, Regents of the University of California, |
| 26 | * Arizona Board of Regents, |
| 27 | * Colorado State University, |
| 28 | * University Pierre & Marie Curie, Sorbonne University, |
| 29 | * Washington University in St. Louis, |
| 30 | * Beijing Institute of Technology, |
| 31 | * The University of Memphis |
| 32 | * |
| 33 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 34 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 35 | * |
| 36 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 37 | * of the GNU General Public License as published by the Free Software Foundation, |
| 38 | * either version 3 of the License, or (at your option) any later version. |
| 39 | * |
| 40 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 41 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 42 | * PURPOSE. See the GNU General Public License for more details. |
| 43 | * |
| 44 | * You should have received a copy of the GNU General Public License along with |
| 45 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 46 | */ |
| 47 | |
| 48 | #ifndef NDN_UNIT_TESTS_UTIL_SIMPLE_NOTIFICATION_HPP |
| 49 | #define NDN_UNIT_TESTS_UTIL_SIMPLE_NOTIFICATION_HPP |
| 50 | |
| 51 | #include "common.hpp" |
| 52 | |
| 53 | #include "encoding/encoding-buffer.hpp" |
| 54 | #include "security/key-chain.hpp" |
| 55 | |
| 56 | namespace ndn { |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 57 | namespace util { |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 58 | namespace tests { |
| 59 | |
| 60 | class SimpleNotification |
| 61 | { |
| 62 | public: |
| 63 | SimpleNotification() |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | explicit |
| 68 | SimpleNotification(const Block& block) |
| 69 | { |
| 70 | wireDecode(block); |
| 71 | } |
| 72 | |
| 73 | SimpleNotification(const std::string& message) |
| 74 | : m_message(message) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | ~SimpleNotification() |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | Block |
| 83 | wireEncode() const |
| 84 | { |
| 85 | ndn::EncodingBuffer buffer; |
| 86 | prependByteArrayBlock(buffer, |
| 87 | 0x8888, |
| 88 | reinterpret_cast<const uint8_t*>(m_message.c_str()), |
| 89 | m_message.size()); |
| 90 | return buffer.block(); |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | wireDecode(const Block& block) |
| 95 | { |
| 96 | m_message.assign(reinterpret_cast<const char*>(block.value()), |
| 97 | block.value_size()); |
| 98 | |
| 99 | // error for testing |
| 100 | if (!m_message.empty() && m_message[0] == '\x07') |
| 101 | throw tlv::Error("0x07 error"); |
| 102 | } |
| 103 | |
| 104 | public: |
| 105 | const std::string& |
| 106 | getMessage() const |
| 107 | { |
| 108 | return m_message; |
| 109 | } |
| 110 | |
| 111 | void |
| 112 | setMessage(const std::string& message) |
| 113 | { |
| 114 | m_message = message; |
| 115 | } |
| 116 | |
| 117 | private: |
| 118 | std::string m_message; |
| 119 | }; |
| 120 | |
| 121 | } // namespace tests |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 122 | } // namespace util |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 123 | } // namespace ndn |
| 124 | |
| 125 | #endif // NDN_UNIT_TESTS_UTIL_CORE_SIMPLE_NOTIFICATION_HPP |