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
ipv6-address-test-suite.cc
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*/
4
5
#include "ns3/ipv6-address.h"
6
#include "ns3/test.h"
7
8
using namespace
ns3
;
9
10
/**
11
* @ingroup network-test
12
* @ingroup tests
13
*
14
* Ipv6Address unit tests.
15
*/
16
class
Ipv6AddressTestCase
:
public
TestCase
17
{
18
public
:
19
Ipv6AddressTestCase
();
20
~Ipv6AddressTestCase
()
override
;
21
22
private
:
23
void
DoRun
()
override
;
24
};
25
26
Ipv6AddressTestCase::Ipv6AddressTestCase
()
27
:
TestCase
(
"serialization code"
)
28
{
29
}
30
31
Ipv6AddressTestCase::~Ipv6AddressTestCase
()
32
{
33
}
34
35
void
36
Ipv6AddressTestCase::DoRun
()
37
{
38
Ipv6Address
ip =
Ipv6Address
(
"2001:db8::1"
);
39
uint8_t ipBytes[16];
40
ip.
Serialize
(ipBytes);
41
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
42
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
43
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
44
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
45
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
46
47
ip =
Ipv6Address
(
"2001:db8:1::1"
);
48
ip.
Serialize
(ipBytes);
49
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
50
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
51
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
52
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
53
NS_TEST_ASSERT_MSG_EQ
(ipBytes[5], 0x01,
"Failed string conversion"
);
54
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
55
56
// Zero padding
57
ip =
Ipv6Address
(
"2001:0db8:0001::1"
);
58
ip.
Serialize
(ipBytes);
59
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
60
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
61
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
62
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
63
NS_TEST_ASSERT_MSG_EQ
(ipBytes[5], 0x01,
"Failed string conversion"
);
64
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
65
66
ip =
Ipv6Address
(
"2001:db8:0:1::1"
);
67
ip.
Serialize
(ipBytes);
68
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
69
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
70
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
71
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
72
NS_TEST_ASSERT_MSG_EQ
(ipBytes[7], 0x01,
"Failed string conversion"
);
73
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
74
75
ip =
Ipv6Address
(
"2001:db8:0:1:0:0:0:1"
);
76
ip.
Serialize
(ipBytes);
77
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
78
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
79
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
80
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
81
NS_TEST_ASSERT_MSG_EQ
(ipBytes[7], 0x01,
"Failed string conversion"
);
82
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
83
84
// Please add more tests below
85
}
86
87
/**
88
* @ingroup network-test
89
* @ingroup tests
90
*
91
* @brief Ipv6Address TestSuite
92
*
93
*/
94
class
Ipv6AddressTestSuite
:
public
TestSuite
95
{
96
public
:
97
Ipv6AddressTestSuite
();
98
};
99
100
Ipv6AddressTestSuite::Ipv6AddressTestSuite
()
101
:
TestSuite
(
"ipv6-address"
,
Type
::UNIT)
102
{
103
AddTestCase
(
new
Ipv6AddressTestCase
, TestCase::Duration::QUICK);
104
}
105
106
static
Ipv6AddressTestSuite
ipv6AddressTestSuite
;
//!< Static variable for test initialization
Ipv6AddressTestCase
Ipv6Address unit tests.
Definition
ipv6-address-test-suite.cc:17
Ipv6AddressTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
ipv6-address-test-suite.cc:36
Ipv6AddressTestCase::~Ipv6AddressTestCase
~Ipv6AddressTestCase() override
Definition
ipv6-address-test-suite.cc:31
Ipv6AddressTestCase::Ipv6AddressTestCase
Ipv6AddressTestCase()
Definition
ipv6-address-test-suite.cc:26
Ipv6AddressTestSuite
Ipv6Address TestSuite.
Definition
ipv6-address-test-suite.cc:95
Ipv6AddressTestSuite::Ipv6AddressTestSuite
Ipv6AddressTestSuite()
Definition
ipv6-address-test-suite.cc:100
ns3::Ipv6Address
Describes an IPv6 address.
Definition
ipv6-address.h:38
ns3::Ipv6Address::Serialize
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Definition
ipv6-address.cc:220
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
NS_TEST_ASSERT_MSG_EQ
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition
test.h:134
ipv6AddressTestSuite
static Ipv6AddressTestSuite ipv6AddressTestSuite
Static variable for test initialization.
Definition
ipv6-address-test-suite.cc:106
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
network
test
ipv6-address-test-suite.cc
Generated on Fri Dec 13 2024 09:20:47 for ns-3 by
1.11.0