blob: 9496070adc047bc8124d62024734718c7c5f4339 [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"
Davide Pesavento49e1e872023-11-11 00:45:23 -050023#include "ndn-cxx/lp/fields.hpp"
Junxiao Shi43eac582019-08-01 12:14:46 -060024#include "ndn-cxx/lp/packet.hpp"
25
26#include "tests/boost-test.hpp"
Davide Pesavento152ef442023-04-22 02:02:29 -040027
Junxiao Shi43eac582019-08-01 12:14:46 -060028#include <boost/lexical_cast.hpp>
29
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040030namespace ndn::tests {
31
32using namespace ndn::lp;
Junxiao Shi43eac582019-08-01 12:14:46 -060033
34BOOST_AUTO_TEST_SUITE(Lp)
35BOOST_AUTO_TEST_SUITE(TestPitToken)
36
37BOOST_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
77BOOST_AUTO_TEST_SUITE_END() // TestPitToken
78BOOST_AUTO_TEST_SUITE_END() // Lp
79
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040080} // namespace ndn::tests