A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
22
class
Ipv6AddressTestCase1
:
public
TestCase
23
{
24
public
:
25
Ipv6AddressTestCase1
();
26
virtual
~
Ipv6AddressTestCase1
();
27
28
private
:
29
virtual
void
DoRun (
void
);
30
};
31
32
Ipv6AddressTestCase1::Ipv6AddressTestCase1
()
33
:
TestCase
(
"serialization code"
)
34
{
35
}
36
37
Ipv6AddressTestCase1::~Ipv6AddressTestCase1
()
38
{
39
}
40
41
void
42
Ipv6AddressTestCase1::DoRun
(
void
)
43
{
44
Ipv6Address
ip =
Ipv6Address
(
"2001:db8::1"
);
45
uint8_t ipBytes[16];
46
ip.
Serialize
(ipBytes);
47
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
48
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
49
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
50
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
51
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
52
53
ip =
Ipv6Address
(
"2001:db8:1::1"
);
54
ip.
Serialize
(ipBytes);
55
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
56
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
57
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
58
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
59
NS_TEST_ASSERT_MSG_EQ
(ipBytes[5], 0x01,
"Failed string conversion"
);
60
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
61
62
// Zero padding
63
ip =
Ipv6Address
(
"2001:0db8:0001::1"
);
64
ip.
Serialize
(ipBytes);
65
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
66
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
67
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
68
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
69
NS_TEST_ASSERT_MSG_EQ
(ipBytes[5], 0x01,
"Failed string conversion"
);
70
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
71
72
ip =
Ipv6Address
(
"2001:db8:0:1::1"
);
73
ip.
Serialize
(ipBytes);
74
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
75
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
76
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
77
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
78
NS_TEST_ASSERT_MSG_EQ
(ipBytes[7], 0x01,
"Failed string conversion"
);
79
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
80
81
ip =
Ipv6Address
(
"2001:db8:0:1:0:0:0:1"
);
82
ip.
Serialize
(ipBytes);
83
NS_TEST_ASSERT_MSG_EQ
(ipBytes[0], 0x20,
"Failed string conversion"
);
84
NS_TEST_ASSERT_MSG_EQ
(ipBytes[1], 0x01,
"Failed string conversion"
);
85
NS_TEST_ASSERT_MSG_EQ
(ipBytes[2], 0x0d,
"Failed string conversion"
);
86
NS_TEST_ASSERT_MSG_EQ
(ipBytes[3], 0xb8,
"Failed string conversion"
);
87
NS_TEST_ASSERT_MSG_EQ
(ipBytes[7], 0x01,
"Failed string conversion"
);
88
NS_TEST_ASSERT_MSG_EQ
(ipBytes[15], 1,
"Failed string conversion"
);
89
90
// Please add more tests below
91
92
}
93
94
class
Ipv6AddressTestSuite
:
public
TestSuite
95
{
96
public
:
97
Ipv6AddressTestSuite
();
98
};
99
100
Ipv6AddressTestSuite::Ipv6AddressTestSuite
()
101
:
TestSuite
(
"ipv6-address"
, UNIT)
102
{
103
AddTestCase
(
new
Ipv6AddressTestCase1
, TestCase::QUICK);
104
}
105
106
static
Ipv6AddressTestSuite
ipv6AddressTestSuite
;
107
Ipv6AddressTestCase1::Ipv6AddressTestCase1
Ipv6AddressTestCase1()
Definition:
ipv6-address-test-suite.cc:32
ipv6AddressTestSuite
static Ipv6AddressTestSuite ipv6AddressTestSuite
Definition:
ipv6-address-test-suite.cc:106
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1025
Ipv6AddressTestSuite
Definition:
ipv6-address-test-suite.cc:94
ns3::TestCase
encapsulates test code
Definition:
test.h:849
Ipv6AddressTestCase1
Definition:
ipv6-address-test-suite.cc:22
Ipv6AddressTestSuite::Ipv6AddressTestSuite
Ipv6AddressTestSuite()
Definition:
ipv6-address-test-suite.cc:100
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition:
test.cc:173
ns3::Ipv6Address
Describes an IPv6 address.
Definition:
ipv6-address.h:46
Ipv6AddressTestCase1::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
ipv6-address-test-suite.cc:42
Ipv6AddressTestCase1::~Ipv6AddressTestCase1
virtual ~Ipv6AddressTestCase1()
Definition:
ipv6-address-test-suite.cc:37
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:137
ns3::Ipv6Address::Serialize
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
Definition:
ipv6-address.cc:332
src
network
test
ipv6-address-test-suite.cc
Generated on Sat Apr 19 2014 14:07:05 for ns-3 by
1.8.6