A Discrete-Event Network Simulator
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 
28 {
29  public:
31  ~Ipv6AddressTestCase() override;
32 
33  private:
34  void DoRun() override;
35 };
36 
38  : TestCase("serialization code")
39 {
40 }
41 
43 {
44 }
45 
46 void
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 
106 {
107  public:
109 };
110 
112  : TestSuite("ipv6-address", UNIT)
113 {
114  AddTestCase(new Ipv6AddressTestCase, TestCase::QUICK);
115 }
116 
Ipv6Address unit tests.
void DoRun() override
Implementation to actually run this TestCase.
Ipv6Address TestSuite.
Describes an IPv6 address.
Definition: ipv6-address.h:49
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
#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
static Ipv6AddressTestSuite ipv6AddressTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.