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