A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
address-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Universita' di Firenze, Italy
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#include "ns3/address.h"
10#include "ns3/test.h"
11
12#include <map>
13#include <string>
14
15using namespace ns3;
16
17/**
18 * @ingroup network-test
19 * @ingroup tests
20 *
21 * @brief Address classes Test
22 */
23class AddressTest : public TestCase
24{
25 public:
26 void DoRun() override;
28};
29
31 : TestCase("Address class implementation")
32{
33}
34
35void
37{
38 Address addrA;
39 Address addrB;
40 Address addrC;
41
42 // tests comparison of non-initialized addresses
43 NS_TEST_EXPECT_MSG_EQ(addrA == addrB, true, "Non-initialized addresses must be equal");
44
45 uint8_t bufferA[10]{1, 8, 0, 0, 0, 0, 0, 0, 0, 1};
46 uint8_t bufferB[10]{1, 8, 0, 0, 0, 0, 0, 0, 0, 2};
47 uint8_t bufferC[10]{1, 8, 0, 0, 0, 0, 0, 0, 0, 3};
48
49 addrA.CopyAllFrom(bufferA, 10);
50 addrB.CopyAllFrom(bufferB, 10);
51 addrC.CopyAllFrom(bufferC, 10);
52
53 // tests comparison of initialized addresses
54 NS_TEST_EXPECT_MSG_EQ(addrA < addrB, true, "Initialized addresses must be different, A < B");
55 NS_TEST_EXPECT_MSG_EQ(addrA < addrC, true, "Initialized addresses must be different, A < C");
56 NS_TEST_EXPECT_MSG_EQ(addrB < addrC, true, "Initialized addresses must be different, B < C");
57
58 std::map<Address, int8_t> theMap;
59 theMap.insert({addrC, 2});
60 theMap.insert({addrB, 1});
61 theMap.insert({addrA, 0});
62
63 int8_t test = -1;
64 for (auto [k, v] : theMap)
65 {
66 NS_TEST_EXPECT_MSG_EQ(v == test + 1, true, "Address map sorting must be correct");
67 test = v;
68 }
69}
70
71/**
72 * @ingroup network-test
73 * @ingroup tests
74 *
75 * @brief Address TestSuite
76 */
78{
79 public:
81
82 private:
83};
84
90
91static AddressTestSuite g_addressTestSuite; //!< Static variable for test initialization
static AddressTestSuite g_addressTestSuite
Static variable for test initialization.
uint32_t v
Address classes Test.
void DoRun() override
Implementation to actually run this TestCase.
Address TestSuite.
a polymophic address class
Definition address.h:114
uint32_t CopyAllFrom(const uint8_t *buffer, uint8_t len)
Definition address.cc:102
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:293
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:491
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition test.h:240
Every class exported by the ns3 library is enclosed in the ns3 namespace.
-ns3 Test suite for the ns3 wrapper script