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