blob: 515926af5aa7bbad35c8bb69324b68b3418eec14 [file] [log] [blame]
Eric Newberry38982622015-08-06 21:39:55 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2015 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 * @author Eric Newberry <enewberry@email.arizona.edu>
22 */
23
24#include "lp/nack-header.hpp"
25
26#include "boost-test.hpp"
27
28namespace ndn {
29namespace lp {
30namespace tests {
31
32BOOST_AUTO_TEST_SUITE(LpNackHeader)
33
34BOOST_AUTO_TEST_CASE(Encode)
35{
36 NackHeader header;
37 header.setReason(NackReason::DUPLICATE);
38
39 Block wire;
40 BOOST_REQUIRE_NO_THROW(wire = header.wireEncode());
41
42 // Sample encoded value obtained with:
43 // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
44 // printf("0x%02x, ", *it);
45 // }
46
47 // Contains NackReason::DUPLICATE
48 static const uint8_t expectedBlock[] = {
49 0xfd, 0x03, 0x20, 0x05, 0xfd, 0x03, 0x21, 0x01, 0x64,
50 };
51
52 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
53 wire.begin(), wire.end());
54
55 BOOST_REQUIRE_NO_THROW(header.wireDecode(wire));
56}
57
58BOOST_AUTO_TEST_CASE(DecodeUnknownReasonCode)
59{
60 static const uint8_t expectedBlock[] = {
61 0xfd, 0x03, 0x20, 0x08, 0xfd, 0x03, 0x21, 0x04, 0xff, 0xff, 0xff, 0xff,
62 };
63
64 NackHeader header;
65 Block wire(expectedBlock, sizeof(expectedBlock));
66 BOOST_REQUIRE_NO_THROW(header.wireDecode(wire));
67 Block wireEncoded;
68 BOOST_REQUIRE_NO_THROW(wireEncoded = header.wireEncode());
69 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
70 wireEncoded.begin(), wireEncoded.end());
71 BOOST_CHECK_EQUAL(header.getReason(), NackReason::NONE);
72}
73
74BOOST_AUTO_TEST_CASE(DecodeOmitReason)
75{
76 static const uint8_t expectedBlock[] = {
77 0xfd, 0x03, 0x20, 0x00,
78 };
79
80 NackHeader header;
81 Block wire(expectedBlock, sizeof(expectedBlock));
82 BOOST_REQUIRE_NO_THROW(header.wireDecode(wire));
83 Block wireEncoded;
84 BOOST_REQUIRE_NO_THROW(wireEncoded = header.wireEncode());
85 BOOST_CHECK_EQUAL_COLLECTIONS(expectedBlock, expectedBlock + sizeof(expectedBlock),
86 wireEncoded.begin(), wireEncoded.end());
87 BOOST_CHECK_EQUAL(header.getReason(), NackReason::NONE);
88}
89
90BOOST_AUTO_TEST_CASE(Reason)
91{
92 NackHeader header;
93 BOOST_CHECK_EQUAL(header.getReason(), NackReason::NONE);
94
95 header.setReason(NackReason::DUPLICATE);
96 BOOST_CHECK_EQUAL(header.getReason(), NackReason::DUPLICATE);
97}
98
99BOOST_AUTO_TEST_SUITE_END()
100
101} // namespace tests
102} // namespace lp
103} // namespace ndn