A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
event-garbage-collector-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INESC Porto
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
7 */
8
9#include "ns3/event-garbage-collector.h"
10#include "ns3/test.h"
11
12/**
13 * \file
14 * \ingroup core-tests
15 * \ingroup events
16 * \ingroup event-garbage-tests
17 * EventGarbageCollector test suite.
18 */
19
20/**
21 * \ingroup core-tests
22 * \defgroup event-garbage-tests EventGarbageCollector test suite
23 */
24
25namespace ns3
26{
27
28namespace tests
29{
30
31/**
32 * \ingroup event-garbage-tests
33 * Event garbage collector test.
34 */
36{
37 int m_counter; //!< Counter to trigger deletion of events.
38 EventGarbageCollector* m_events; //!< Object under test.
39
40 /** Callback to record event invocations. */
42
43 public:
44 /** Constructor. */
46 /** Destructor. */
48 void DoRun() override;
49};
50
52 : TestCase("EventGarbageCollector"),
53 m_counter(0),
54 m_events(nullptr)
55{
56}
57
61
62void
64{
65 m_counter++;
66 if (m_counter == 50)
67 {
68 // this should cause the remaining (50) events to be cancelled
69 delete m_events;
70 m_events = nullptr;
71 }
72}
73
74void
91
92/**
93 * \ingroup event-garbage-tests
94 * Event garbage collector test suite.
95 */
97{
98 public:
100 : TestSuite("event-garbage-collector")
101 {
103 }
104};
105
106/**
107 * \ingroup event-garbage-tests
108 * EventGarbageCollectorTestSuite instance variable.
109 */
111
112} // namespace tests
113
114} // namespace ns3
An object that tracks scheduled events and automatically cancels them when it is destroyed.
void Track(EventId event)
Tracks a new event.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
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
void EventGarbageCollectorCallback()
Callback to record event invocations.
void DoRun() override
Implementation to actually run this TestCase.
EventGarbageCollector * m_events
Object under test.
int m_counter
Counter to trigger deletion of events.
static EventGarbageCollectorTestSuite g_eventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite instance variable.
#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:241
Every class exported by the ns3 library is enclosed in the ns3 namespace.