A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
ipv6-address-test-suite.cc
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
5
*
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
*/
15
16
#include "ns3/ipv6-address.h"
17
#include "ns3/test.h"
18
19
using namespace
ns3
;
20
27
class
Ipv6AddressTestCase
:
public
TestCase
28
{
29
public
:
30
Ipv6AddressTestCase
();
31
~
Ipv6AddressTestCase
()
override
;
32
33
private
:
34
void
DoRun()
override
;
35
};
36
37
Ipv6AddressTestCase::Ipv6AddressTestCase
()
38
:
TestCase
(
"serialization code"
)
39
{
40
}
41
42
Ipv6AddressTestCase::~Ipv6AddressTestCase
()
43
{
44
}
45
46
void
47
Ipv6AddressTestCase::DoRun
()
48
{
49
Ipv6Address
ip =
Ipv6Address
(
"2001:db8::1"
);
50
uint8_t ipBytes[16];
51
ip.
Serialize
(ipBytes);
52
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
53
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
54
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
55
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
56
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
57
58
ip =
Ipv6Address
(
"2001:db8:1::1"
);
59
ip.
Serialize
(ipBytes);
60
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
61
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
62
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
63
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
64
NS_TEST_ASSERT_MSG_EQ
(ipBytes[5], 0x01,
"Failed string conversion"
);
65
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
66
67
// Zero padding
68
ip =
Ipv6Address
(
"2001:0db8:0001::1"
);
69
ip.
Serialize
(ipBytes);
70
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
71
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
72
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
73
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
74
NS_TEST_ASSERT_MSG_EQ
(ipBytes[5], 0x01,
"Failed string conversion"
);
75
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
76
77
ip =
Ipv6Address
(
"2001:db8:0:1::1"
);
78
ip.
Serialize
(ipBytes);
79
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
80
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
81
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
82
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
83
NS_TEST_ASSERT_MSG_EQ
(ipBytes[7], 0x01,
"Failed string conversion"
);
84
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
85
86
ip =
Ipv6Address
(
"2001:db8:0:1:0:0:0:1"
);
87
ip.
Serialize
(ipBytes);
88
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
89
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
90
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
91
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
92
NS_TEST_ASSERT_MSG_EQ
(ipBytes[7], 0x01,
"Failed string conversion"
);
93
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
94
95
// Please add more tests below
96
}
97
105
class
Ipv6AddressTestSuite
:
public
TestSuite
106
{
107
public
:
108
Ipv6AddressTestSuite
();
109
};
110
111
Ipv6AddressTestSuite::Ipv6AddressTestSuite
()
112
:
TestSuite
(
"ipv6-address"
, UNIT)
113
{
114
AddTestCase
(
new
Ipv6AddressTestCase
, TestCase::QUICK);
115
}
116
117
static
Ipv6AddressTestSuite
ipv6AddressTestSuite
;
Ipv6AddressTestCase
Ipv6Address unit tests.
Definition:
ipv6-address-test-suite.cc:28
Ipv6AddressTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
ipv6-address-test-suite.cc:47
Ipv6AddressTestCase::~Ipv6AddressTestCase
~Ipv6AddressTestCase() override
Definition:
ipv6-address-test-suite.cc:42
Ipv6AddressTestCase::Ipv6AddressTestCase
Ipv6AddressTestCase()
Definition:
ipv6-address-test-suite.cc:37
Ipv6AddressTestSuite
Ipv6Address TestSuite.
Definition:
ipv6-address-test-suite.cc:106
Ipv6AddressTestSuite::Ipv6AddressTestSuite
Ipv6AddressTestSuite()
Definition:
ipv6-address-test-suite.cc:111
ns3::Ipv6Address
Describes an IPv6 address.
Definition:
ipv6-address.h:49
ns3::Ipv6Address::Serialize
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Definition:
ipv6-address.cc:225
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
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:144
ipv6AddressTestSuite
static Ipv6AddressTestSuite ipv6AddressTestSuite
Static variable for test initialization.
Definition:
ipv6-address-test-suite.cc:117
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
network
test
ipv6-address-test-suite.cc
Generated on Sun Mar 3 2024 17:11:06 for ns-3 by
1.9.1