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 
23 {
24 public:
26  virtual ~Ipv6AddressTestCase1 ();
27 
28 private:
29  virtual void DoRun (void);
30 };
31 
33  : TestCase ("serialization code")
34 {
35 }
36 
38 {
39 }
40 
41 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 
95 {
96 public:
98 };
99 
101  : TestSuite ("ipv6-address", UNIT)
102 {
103  AddTestCase (new Ipv6AddressTestCase1, TestCase::QUICK);
104 }
105 
107 
static Ipv6AddressTestSuite ipv6AddressTestSuite
A suite of tests to run.
Definition: test.h:1333
encapsulates test code
Definition: test.h:1147
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
#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:161
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Describes an IPv6 address.
Definition: ipv6-address.h:48
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.