A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lollipop-counter-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' di Firenze, Italy
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19
20#include "ns3/lollipop-counter.h"
21#include "ns3/test.h"
22
23#include <limits>
24#include <string>
25
26using namespace ns3;
27
28/**
29 * \ingroup network-test
30 * \ingroup tests
31 *
32 * \brief Lollipop Counter Test
33 */
35{
36 public:
37 void DoRun() override;
39};
40
42 : TestCase("Lollipop Counter implementation")
43{
44}
45
46void
48{
51
52 bool greater;
53 bool lesser;
54 bool equal;
55 bool isComparable;
56
57 // tests with uint8_t
58 counter8a = 240;
59 counter8b = 5;
60
61 greater = counter8a > counter8b;
62 lesser = counter8a < counter8b;
63 equal = counter8a == counter8b;
64 isComparable = counter8a.IsComparable(counter8b);
65
66 NS_TEST_EXPECT_MSG_EQ(greater, true, "240 is greater than 5");
67 NS_TEST_EXPECT_MSG_EQ(lesser, false, "240 is not lesser than 5");
68 NS_TEST_EXPECT_MSG_EQ(equal, false, "240 is not equal to 5");
69 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "240 is comparable with 5");
70
71 counter8a = 250;
72 counter8b = 5;
73
74 greater = counter8a > counter8b;
75 lesser = counter8a < counter8b;
76 equal = counter8a == counter8b;
77 isComparable = counter8a.IsComparable(counter8b);
78
79 NS_TEST_EXPECT_MSG_EQ(greater, false, "250 is not greater than 5");
80 NS_TEST_EXPECT_MSG_EQ(lesser, true, "250 is lesser than 5");
81 NS_TEST_EXPECT_MSG_EQ(equal, false, "250 is not equal to 5");
82 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "250 is comparable with 5");
83
84 counter8a = 127;
85 counter8b = 1;
86
87 greater = counter8a > counter8b;
88 lesser = counter8a < counter8b;
89 equal = counter8a == counter8b;
90 isComparable = counter8a.IsComparable(counter8b);
91
92 NS_TEST_EXPECT_MSG_EQ(greater, false, "127 is not greater than 1");
93 NS_TEST_EXPECT_MSG_EQ(lesser, true, "127 is lesser than 1");
94 NS_TEST_EXPECT_MSG_EQ(equal, false, "127 is not equal to 1");
95 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "127 is comparable with 1");
96
97 counter8a = 127;
98 counter8b = 115;
99
100 greater = counter8a > counter8b;
101 lesser = counter8a < counter8b;
102 equal = counter8a == counter8b;
103 isComparable = counter8a.IsComparable(counter8b);
104
105 NS_TEST_EXPECT_MSG_EQ(greater, true, "127 is greater than 115");
106 NS_TEST_EXPECT_MSG_EQ(lesser, false, "127 is not lesser than 115");
107 NS_TEST_EXPECT_MSG_EQ(equal, false, "127 is not equal to 115");
108 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "127 is comparable with 115");
109
110 counter8a = 127;
111 counter8b = 100;
112
113 greater = counter8a > counter8b;
114 lesser = counter8a < counter8b;
115 equal = counter8a == counter8b;
116 isComparable = counter8a.IsComparable(counter8b);
117
118 NS_TEST_EXPECT_MSG_EQ(greater, false, "127 is not greater than 100");
119 NS_TEST_EXPECT_MSG_EQ(lesser, false, "127 is not lesser than 100");
120 NS_TEST_EXPECT_MSG_EQ(equal, false, "127 is not equal to 100");
121 NS_TEST_EXPECT_MSG_EQ(isComparable, false, "127 is not comparable with 100");
122
123 counter8a = 12;
124 counter8b = 233;
125
126 greater = counter8a > counter8b;
127 lesser = counter8a < counter8b;
128 equal = counter8a == counter8b;
129 isComparable = counter8a.IsComparable(counter8b);
130
131 NS_TEST_EXPECT_MSG_EQ(greater, false, "12 is not greater than 233");
132 NS_TEST_EXPECT_MSG_EQ(lesser, true, "12 is lesser than 233");
133 NS_TEST_EXPECT_MSG_EQ(equal, false, "12 is not equal to 233");
134 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "12 is comparable with 233");
135
136 counter8a = 255;
137 counter8b = counter8a++;
138 NS_TEST_EXPECT_MSG_EQ((255 == counter8b), true, "Correct interpretation of postfix operator");
139 NS_TEST_EXPECT_MSG_EQ((0 == counter8a), true, "Correct interpretation of postfix operator");
140
141 counter8a = 255;
142 counter8b = ++counter8a;
143 NS_TEST_EXPECT_MSG_EQ((0 == counter8b), true, "Correct interpretation of prefix operator");
144 NS_TEST_EXPECT_MSG_EQ((0 == counter8a), true, "Correct interpretation of prefix operator");
145}
146
147/**
148 * \ingroup network-test
149 * \ingroup tests
150 *
151 * \brief Lollipop Counter TestSuite
152 */
154{
155 public:
157
158 private:
159};
160
162 : TestSuite("lollipop-counter", Type::UNIT)
163{
164 AddTestCase(new LollipopCounterTest(), TestCase::Duration::QUICK);
165}
166
168 g_lollipopCounterTestSuite; //!< Static variable for test initialization
Lollipop Counter TestSuite.
Lollipop Counter Test.
void DoRun() override
Implementation to actually run this TestCase.
Template class implementing a Lollipop counter as defined in RFC 8505, RFC 6550, and [Perlman83].
bool IsComparable(const LollipopCounter &val) const
Checks if the counter is comparable with another counter (i.e., not desynchronized).
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:252
static LolipopCounterTestSuite g_lollipopCounterTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.