A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
address-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2025 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/address.h"
10
#include "ns3/test.h"
11
12
#include <map>
13
#include <string>
14
15
using namespace
ns3
;
16
17
/**
18
* @ingroup network-test
19
* @ingroup tests
20
*
21
* @brief Address classes Test
22
*/
23
class
AddressTest
:
public
TestCase
24
{
25
public
:
26
void
DoRun
()
override
;
27
AddressTest
();
28
};
29
30
AddressTest::AddressTest
()
31
:
TestCase
(
"Address class implementation"
)
32
{
33
}
34
35
void
36
AddressTest::DoRun
()
37
{
38
Address
addrA;
39
Address
addrB;
40
Address
addrC;
41
42
// tests comparison of non-initialized addresses
43
NS_TEST_EXPECT_MSG_EQ
(addrA == addrB,
true
,
"Non-initialized addresses must be equal"
);
44
45
uint8_t bufferA[10]{1, 8, 0, 0, 0, 0, 0, 0, 0, 1};
46
uint8_t bufferB[10]{1, 8, 0, 0, 0, 0, 0, 0, 0, 2};
47
uint8_t bufferC[10]{1, 8, 0, 0, 0, 0, 0, 0, 0, 3};
48
49
addrA.
CopyAllFrom
(bufferA, 10);
50
addrB.
CopyAllFrom
(bufferB, 10);
51
addrC.
CopyAllFrom
(bufferC, 10);
52
53
// tests comparison of initialized addresses
54
NS_TEST_EXPECT_MSG_EQ
(addrA < addrB,
true
,
"Initialized addresses must be different, A < B"
);
55
NS_TEST_EXPECT_MSG_EQ
(addrA < addrC,
true
,
"Initialized addresses must be different, A < C"
);
56
NS_TEST_EXPECT_MSG_EQ
(addrB < addrC,
true
,
"Initialized addresses must be different, B < C"
);
57
58
std::map<Address, int8_t> theMap;
59
theMap.insert({addrC, 2});
60
theMap.insert({addrB, 1});
61
theMap.insert({addrA, 0});
62
63
int8_t
test
= -1;
64
for
(
auto
[k,
v
] : theMap)
65
{
66
NS_TEST_EXPECT_MSG_EQ
(
v
==
test
+ 1,
true
,
"Address map sorting must be correct"
);
67
test
=
v
;
68
}
69
}
70
71
/**
72
* @ingroup network-test
73
* @ingroup tests
74
*
75
* @brief Address TestSuite
76
*/
77
class
AddressTestSuite
:
public
TestSuite
78
{
79
public
:
80
AddressTestSuite
();
81
82
private
:
83
};
84
85
AddressTestSuite::AddressTestSuite
()
86
:
TestSuite
(
"address"
,
Type
::UNIT)
87
{
88
AddTestCase
(
new
AddressTest
(),
TestCase::Duration::QUICK
);
89
}
90
91
static
AddressTestSuite
g_addressTestSuite
;
//!< Static variable for test initialization
g_addressTestSuite
static AddressTestSuite g_addressTestSuite
Static variable for test initialization.
Definition
address-test.cc:91
v
uint32_t v
Definition
cairo-wideint.c:749
AddressTest
Address classes Test.
Definition
address-test.cc:24
AddressTest::AddressTest
AddressTest()
Definition
address-test.cc:30
AddressTest::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
address-test.cc:36
AddressTestSuite
Address TestSuite.
Definition
address-test.cc:78
AddressTestSuite::AddressTestSuite
AddressTestSuite()
Definition
address-test.cc:85
int8_t
ns3::Address
a polymophic address class
Definition
address.h:114
ns3::Address::CopyAllFrom
uint32_t CopyAllFrom(const uint8_t *buffer, uint8_t len)
Definition
address.cc:102
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:293
ns3::TestCase::Duration::QUICK
@ QUICK
Fast test.
Definition
test.h:1057
ns3::TestCase::TestCase
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1271
ns3::TestSuite::TestSuite
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition
test.cc:491
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:240
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
test
-ns3 Test suite for the ns3 wrapper script
src
network
test
address-test.cc
Generated on
for ns-3 by
1.15.0