A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-address-test-suite.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5#include "ns3/ipv6-address.h"
6#include "ns3/test.h"
7
8using namespace ns3;
9
10/**
11 * \ingroup network-test
12 * \ingroup tests
13 *
14 * Ipv6Address unit tests.
15 */
17{
18 public:
20 ~Ipv6AddressTestCase() override;
21
22 private:
23 void DoRun() override;
24};
25
27 : TestCase("serialization code")
28{
29}
30
34
35void
37{
38 Ipv6Address ip = Ipv6Address("2001:db8::1");
39 uint8_t ipBytes[16];
40 ip.Serialize(ipBytes);
41 NS_TEST_ASSERT_MSG_EQ(ipBytes[0], 0x20, "Failed string conversion");
42 NS_TEST_ASSERT_MSG_EQ(ipBytes[1], 0x01, "Failed string conversion");
43 NS_TEST_ASSERT_MSG_EQ(ipBytes[2], 0x0d, "Failed string conversion");
44 NS_TEST_ASSERT_MSG_EQ(ipBytes[3], 0xb8, "Failed string conversion");
45 NS_TEST_ASSERT_MSG_EQ(ipBytes[15], 1, "Failed string conversion");
46
47 ip = Ipv6Address("2001:db8:1::1");
48 ip.Serialize(ipBytes);
49 NS_TEST_ASSERT_MSG_EQ(ipBytes[0], 0x20, "Failed string conversion");
50 NS_TEST_ASSERT_MSG_EQ(ipBytes[1], 0x01, "Failed string conversion");
51 NS_TEST_ASSERT_MSG_EQ(ipBytes[2], 0x0d, "Failed string conversion");
52 NS_TEST_ASSERT_MSG_EQ(ipBytes[3], 0xb8, "Failed string conversion");
53 NS_TEST_ASSERT_MSG_EQ(ipBytes[5], 0x01, "Failed string conversion");
54 NS_TEST_ASSERT_MSG_EQ(ipBytes[15], 1, "Failed string conversion");
55
56 // Zero padding
57 ip = Ipv6Address("2001:0db8:0001::1");
58 ip.Serialize(ipBytes);
59 NS_TEST_ASSERT_MSG_EQ(ipBytes[0], 0x20, "Failed string conversion");
60 NS_TEST_ASSERT_MSG_EQ(ipBytes[1], 0x01, "Failed string conversion");
61 NS_TEST_ASSERT_MSG_EQ(ipBytes[2], 0x0d, "Failed string conversion");
62 NS_TEST_ASSERT_MSG_EQ(ipBytes[3], 0xb8, "Failed string conversion");
63 NS_TEST_ASSERT_MSG_EQ(ipBytes[5], 0x01, "Failed string conversion");
64 NS_TEST_ASSERT_MSG_EQ(ipBytes[15], 1, "Failed string conversion");
65
66 ip = Ipv6Address("2001:db8:0:1::1");
67 ip.Serialize(ipBytes);
68 NS_TEST_ASSERT_MSG_EQ(ipBytes[0], 0x20, "Failed string conversion");
69 NS_TEST_ASSERT_MSG_EQ(ipBytes[1], 0x01, "Failed string conversion");
70 NS_TEST_ASSERT_MSG_EQ(ipBytes[2], 0x0d, "Failed string conversion");
71 NS_TEST_ASSERT_MSG_EQ(ipBytes[3], 0xb8, "Failed string conversion");
72 NS_TEST_ASSERT_MSG_EQ(ipBytes[7], 0x01, "Failed string conversion");
73 NS_TEST_ASSERT_MSG_EQ(ipBytes[15], 1, "Failed string conversion");
74
75 ip = Ipv6Address("2001:db8:0:1:0:0:0:1");
76 ip.Serialize(ipBytes);
77 NS_TEST_ASSERT_MSG_EQ(ipBytes[0], 0x20, "Failed string conversion");
78 NS_TEST_ASSERT_MSG_EQ(ipBytes[1], 0x01, "Failed string conversion");
79 NS_TEST_ASSERT_MSG_EQ(ipBytes[2], 0x0d, "Failed string conversion");
80 NS_TEST_ASSERT_MSG_EQ(ipBytes[3], 0xb8, "Failed string conversion");
81 NS_TEST_ASSERT_MSG_EQ(ipBytes[7], 0x01, "Failed string conversion");
82 NS_TEST_ASSERT_MSG_EQ(ipBytes[15], 1, "Failed string conversion");
83
84 // Please add more tests below
85}
86
87/**
88 * \ingroup network-test
89 * \ingroup tests
90 *
91 * \brief Ipv6Address TestSuite
92 *
93 */
95{
96 public:
98};
99
101 : TestSuite("ipv6-address", Type::UNIT)
102{
103 AddTestCase(new Ipv6AddressTestCase, TestCase::Duration::QUICK);
104}
105
106static Ipv6AddressTestSuite ipv6AddressTestSuite; //!< Static variable for test initialization
Ipv6Address unit tests.
void DoRun() override
Implementation to actually run this TestCase.
Ipv6Address TestSuite.
Describes an IPv6 address.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
#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:134
static Ipv6AddressTestSuite ipv6AddressTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.