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