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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#include "ns3/lollipop-counter.h"
10#include "ns3/test.h"
11
12#include <limits>
13#include <string>
14
15using namespace ns3;
16
17/**
18 * @ingroup network-test
19 * @ingroup tests
20 *
21 * @brief Lollipop Counter Test
22 */
24{
25 public:
26 void DoRun() override;
28};
29
31 : TestCase("Lollipop Counter implementation")
32{
33}
34
35void
37{
40
41 bool greater;
42 bool lesser;
43 bool equal;
44 bool isComparable;
45
46 // tests with uint8_t
47 counter8a = 240;
48 counter8b = 5;
49
50 greater = counter8a > counter8b;
51 lesser = counter8a < counter8b;
52 equal = counter8a == counter8b;
53 isComparable = counter8a.IsComparable(counter8b);
54
55 NS_TEST_EXPECT_MSG_EQ(greater, true, "240 is greater than 5");
56 NS_TEST_EXPECT_MSG_EQ(lesser, false, "240 is not lesser than 5");
57 NS_TEST_EXPECT_MSG_EQ(equal, false, "240 is not equal to 5");
58 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "240 is comparable with 5");
59
60 counter8a = 250;
61 counter8b = 5;
62
63 greater = counter8a > counter8b;
64 lesser = counter8a < counter8b;
65 equal = counter8a == counter8b;
66 isComparable = counter8a.IsComparable(counter8b);
67
68 NS_TEST_EXPECT_MSG_EQ(greater, false, "250 is not greater than 5");
69 NS_TEST_EXPECT_MSG_EQ(lesser, true, "250 is lesser than 5");
70 NS_TEST_EXPECT_MSG_EQ(equal, false, "250 is not equal to 5");
71 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "250 is comparable with 5");
72
73 counter8a = 127;
74 counter8b = 1;
75
76 greater = counter8a > counter8b;
77 lesser = counter8a < counter8b;
78 equal = counter8a == counter8b;
79 isComparable = counter8a.IsComparable(counter8b);
80
81 NS_TEST_EXPECT_MSG_EQ(greater, false, "127 is not greater than 1");
82 NS_TEST_EXPECT_MSG_EQ(lesser, true, "127 is lesser than 1");
83 NS_TEST_EXPECT_MSG_EQ(equal, false, "127 is not equal to 1");
84 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "127 is comparable with 1");
85
86 counter8a = 127;
87 counter8b = 115;
88
89 greater = counter8a > counter8b;
90 lesser = counter8a < counter8b;
91 equal = counter8a == counter8b;
92 isComparable = counter8a.IsComparable(counter8b);
93
94 NS_TEST_EXPECT_MSG_EQ(greater, true, "127 is greater than 115");
95 NS_TEST_EXPECT_MSG_EQ(lesser, false, "127 is not lesser than 115");
96 NS_TEST_EXPECT_MSG_EQ(equal, false, "127 is not equal to 115");
97 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "127 is comparable with 115");
98
99 counter8a = 127;
100 counter8b = 100;
101
102 greater = counter8a > counter8b;
103 lesser = counter8a < counter8b;
104 equal = counter8a == counter8b;
105 isComparable = counter8a.IsComparable(counter8b);
106
107 NS_TEST_EXPECT_MSG_EQ(greater, false, "127 is not greater than 100");
108 NS_TEST_EXPECT_MSG_EQ(lesser, false, "127 is not lesser than 100");
109 NS_TEST_EXPECT_MSG_EQ(equal, false, "127 is not equal to 100");
110 NS_TEST_EXPECT_MSG_EQ(isComparable, false, "127 is not comparable with 100");
111
112 counter8a = 12;
113 counter8b = 233;
114
115 greater = counter8a > counter8b;
116 lesser = counter8a < counter8b;
117 equal = counter8a == counter8b;
118 isComparable = counter8a.IsComparable(counter8b);
119
120 NS_TEST_EXPECT_MSG_EQ(greater, false, "12 is not greater than 233");
121 NS_TEST_EXPECT_MSG_EQ(lesser, true, "12 is lesser than 233");
122 NS_TEST_EXPECT_MSG_EQ(equal, false, "12 is not equal to 233");
123 NS_TEST_EXPECT_MSG_EQ(isComparable, true, "12 is comparable with 233");
124
125 counter8a = 255;
126 counter8b = counter8a++;
127 NS_TEST_EXPECT_MSG_EQ((255 == counter8b), true, "Correct interpretation of postfix operator");
128 NS_TEST_EXPECT_MSG_EQ((0 == counter8a), true, "Correct interpretation of postfix operator");
129
130 counter8a = 255;
131 counter8b = ++counter8a;
132 NS_TEST_EXPECT_MSG_EQ((0 == counter8b), true, "Correct interpretation of prefix operator");
133 NS_TEST_EXPECT_MSG_EQ((0 == counter8a), true, "Correct interpretation of prefix operator");
134}
135
136/**
137 * @ingroup network-test
138 * @ingroup tests
139 *
140 * @brief Lollipop Counter TestSuite
141 */
143{
144 public:
146
147 private:
148};
149
151 : TestSuite("lollipop-counter", Type::UNIT)
152{
153 AddTestCase(new LollipopCounterTest(), TestCase::Duration::QUICK);
154}
155
157 g_lollipopCounterTestSuite; //!< Static variable for test initialization
Lollipop Counter Test.
void DoRun() override
Implementation to actually run this TestCase.
Lollipop Counter TestSuite.
Template class implementing a Lollipop counter as defined in RFC 8505 , RFC 6550 ,...
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:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
#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:241
static LollipopCounterTestSuite g_lollipopCounterTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.