blob: 60de483ded4b4909e1cb0095e089af716cab2faf [file] [log] [blame]
Junxiao Shi57df2882015-11-11 06:12:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -04002/*
3 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shi57df2882015-11-11 06:12:35 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Davide Pesavento2cae8ca2019-04-18 20:48:05 -040026#include "common/counter.hpp"
Junxiao Shi57df2882015-11-11 06:12:35 -070027
28#include "tests/test-common.hpp"
29
30namespace nfd {
31namespace tests {
32
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040033BOOST_AUTO_TEST_SUITE(TestCounter)
Junxiao Shi57df2882015-11-11 06:12:35 -070034
35BOOST_AUTO_TEST_CASE(PacketCnt)
36{
37 PacketCounter counter;
38
39 uint64_t observation = counter; // implicit conversion
40 BOOST_CHECK_EQUAL(observation, 0);
41
42 ++counter;
43 BOOST_CHECK_EQUAL(counter, 1);
44 ++counter;
45 ++counter;
46 BOOST_CHECK_EQUAL(counter, 3);
47
48 counter.set(2);
49 BOOST_CHECK_EQUAL(counter, 2);
50}
51
52BOOST_AUTO_TEST_CASE(ByteCnt)
53{
54 ByteCounter counter;
55
56 uint64_t observation = counter; // implicit conversion
57 BOOST_CHECK_EQUAL(observation, 0);
58
59 counter += 20;
60 BOOST_CHECK_EQUAL(counter, 20);
61 counter += 80;
62 counter += 90;
63 BOOST_CHECK_EQUAL(counter, 190);
64
65 counter.set(21);
66 BOOST_CHECK_EQUAL(counter, 21);
67}
68
69BOOST_AUTO_TEST_CASE(SizeCnt)
70{
71 std::vector<int> v;
Eric Newberry73bcad32017-04-25 17:57:35 -070072 SizeCounter<std::vector<int>> counter1(&v);
73 SizeCounter<std::vector<int>> counter2;
74 counter2.observe(&v);
Junxiao Shi57df2882015-11-11 06:12:35 -070075
Eric Newberry73bcad32017-04-25 17:57:35 -070076 size_t observation1 = counter1; // implicit conversion
77 size_t observation2 = counter2;
78 BOOST_CHECK_EQUAL(observation1, 0);
79 BOOST_CHECK_EQUAL(observation2, 0);
Junxiao Shi57df2882015-11-11 06:12:35 -070080
81 v.resize(249);
Eric Newberry73bcad32017-04-25 17:57:35 -070082 BOOST_CHECK_EQUAL(counter1, 249);
83 BOOST_CHECK_EQUAL(counter2, 249);
Junxiao Shi57df2882015-11-11 06:12:35 -070084
85 v.resize(98);
Eric Newberry73bcad32017-04-25 17:57:35 -070086 BOOST_CHECK_EQUAL(counter1, 98);
87 BOOST_CHECK_EQUAL(counter2, 98);
Junxiao Shi57df2882015-11-11 06:12:35 -070088}
89
90BOOST_AUTO_TEST_SUITE_END() // TestCounter
91
92} // namespace tests
93} // namespace nfd