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