blob: 6e55b85279d86eea72f353deb744780868356e17 [file] [log] [blame]
Junxiao Shi7f012472017-12-07 20:40:47 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2017 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 "mgmt/nfd/cs-info.hpp"
23
24#include "boost-test.hpp"
25#include <boost/lexical_cast.hpp>
26
27namespace ndn {
28namespace nfd {
29namespace tests {
30
31BOOST_AUTO_TEST_SUITE(Mgmt)
32BOOST_AUTO_TEST_SUITE(Nfd)
33BOOST_AUTO_TEST_SUITE(TestCsInfo)
34
35static CsInfo
36makeCsInfo()
37{
38 return CsInfo()
39 .setNHits(12951)
40 .setNMisses(28179);
41}
42
43BOOST_AUTO_TEST_CASE(Encode)
44{
45 CsInfo csi1 = makeCsInfo();
46 Block wire = csi1.wireEncode();
47
48 static const uint8_t EXPECTED[] = {
49 0x80, 0x08, // CsInfo
50 0x81, 0x02, 0x32, 0x97, // NHits
51 0x82, 0x02, 0x6E, 0x13, // NMisses
52 };
53 BOOST_CHECK_EQUAL_COLLECTIONS(wire.begin(), wire.end(), EXPECTED, EXPECTED + sizeof(EXPECTED));
54
55 CsInfo csi2(wire);
56 BOOST_CHECK_EQUAL(csi1, csi2);
57}
58
59BOOST_AUTO_TEST_CASE(Equality)
60{
61 CsInfo csi1, csi2;
62 BOOST_CHECK_EQUAL(csi1, csi2);
63
64 csi1 = makeCsInfo();
65 BOOST_CHECK_NE(csi1, csi2);
66 csi2 = csi1;
67 BOOST_CHECK_EQUAL(csi1, csi2);
68
69 csi2.setNHits(8267);
70 BOOST_CHECK_NE(csi1, csi2);
71}
72
73BOOST_AUTO_TEST_CASE(Print)
74{
75 CsInfo csi;
76 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(csi), "CS: 0 hits, 0 misses");
77
78 csi = makeCsInfo();
79 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(csi), "CS: 12951 hits, 28179 misses");
80
81 csi.setNHits(1).setNMisses(1);
82 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(csi), "CS: 1 hit, 1 miss");
83}
84
85BOOST_AUTO_TEST_SUITE_END() // TestCsInfo
86BOOST_AUTO_TEST_SUITE_END() // Nfd
87BOOST_AUTO_TEST_SUITE_END() // Mgmt
88
89} // namespace tests
90} // namespace nfd
91} // namespace ndn