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