Junxiao Shi | 43eac58 | 2019-08-01 12:14:46 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 152ef44 | 2023-04-22 02:02:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Junxiao Shi | 43eac58 | 2019-08-01 12:14:46 -0600 | [diff] [blame] | 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 | #include "ndn-cxx/lp/pit-token.hpp" |
Davide Pesavento | 49e1e87 | 2023-11-11 00:45:23 -0500 | [diff] [blame] | 23 | #include "ndn-cxx/lp/fields.hpp" |
Junxiao Shi | 43eac58 | 2019-08-01 12:14:46 -0600 | [diff] [blame] | 24 | #include "ndn-cxx/lp/packet.hpp" |
| 25 | |
| 26 | #include "tests/boost-test.hpp" |
Davide Pesavento | 152ef44 | 2023-04-22 02:02:29 -0400 | [diff] [blame] | 27 | |
Junxiao Shi | 43eac58 | 2019-08-01 12:14:46 -0600 | [diff] [blame] | 28 | #include <boost/lexical_cast.hpp> |
| 29 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 30 | namespace ndn::tests { |
| 31 | |
| 32 | using namespace ndn::lp; |
Junxiao Shi | 43eac58 | 2019-08-01 12:14:46 -0600 | [diff] [blame] | 33 | |
| 34 | BOOST_AUTO_TEST_SUITE(Lp) |
| 35 | BOOST_AUTO_TEST_SUITE(TestPitToken) |
| 36 | |
| 37 | BOOST_AUTO_TEST_CASE(Decode) |
| 38 | { |
| 39 | Packet pkt("6405 pit-token=6200 fragment=5001C0"_block); |
| 40 | BOOST_CHECK_THROW(PitToken(pkt.get<PitTokenField>()), ndn::tlv::Error); |
| 41 | |
| 42 | pkt.wireDecode("6406 pit-token=6201A0 fragment=5001C0"_block); |
| 43 | PitToken pitToken1(pkt.get<PitTokenField>()); |
| 44 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(pitToken1), "a0"); |
| 45 | |
| 46 | pkt.wireDecode("640A pit-token=6205A0A1A2A3A4 fragment=5001C0"_block); |
| 47 | PitToken pitToken5(pkt.get<PitTokenField>()); |
| 48 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(pitToken5), "a0a1a2a3a4"); |
| 49 | |
| 50 | pkt.wireDecode("640D pit-token=6208A0A1A2A3A4A5A6A7 fragment=5001C0"_block); |
| 51 | PitToken pitToken8(pkt.get<PitTokenField>()); |
| 52 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(pitToken8), "a0a1a2a3a4a5a6a7"); |
| 53 | |
| 54 | pkt.wireDecode("6425 pit-token=6220A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF" |
| 55 | " fragment=5001C0"_block); |
| 56 | PitToken pitToken32(pkt.get<PitTokenField>()); |
| 57 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(pitToken32), |
| 58 | "a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf"); |
| 59 | |
| 60 | pkt.wireDecode("6426 pit-token=6221A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0" |
| 61 | " fragment=5001C0"_block); |
| 62 | BOOST_CHECK_THROW(PitToken(pkt.get<PitTokenField>()), ndn::tlv::Error); |
| 63 | |
| 64 | BOOST_CHECK_EQUAL(pitToken1, pitToken1); |
| 65 | BOOST_CHECK_NE(pitToken1, pitToken5); |
| 66 | |
| 67 | pkt.wireDecode("640A pit-token=6205B0B1B2B3B4 fragment=5001C0"_block); |
| 68 | PitToken pitToken5b(pkt.get<PitTokenField>()); |
| 69 | BOOST_CHECK_NE(pitToken5, pitToken5b); |
| 70 | |
| 71 | pkt.set<PitTokenField>(pitToken5); |
| 72 | BOOST_CHECK_EQUAL(pkt.wireEncode(), "640A pit-token=6205A0A1A2A3A4 fragment=5001C0"_block); |
| 73 | PitToken pitToken5a(pkt.get<PitTokenField>()); |
| 74 | BOOST_CHECK_EQUAL(pitToken5, pitToken5a); |
| 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_SUITE_END() // TestPitToken |
| 78 | BOOST_AUTO_TEST_SUITE_END() // Lp |
| 79 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 80 | } // namespace ndn::tests |