A Discrete-Event Network Simulator
API
simulator-test-suite.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2005,2006 INRIA
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 */
20#include "ns3/test.h"
21#include "ns3/simulator.h"
22#include "ns3/list-scheduler.h"
23#include "ns3/heap-scheduler.h"
24#include "ns3/map-scheduler.h"
25#include "ns3/calendar-scheduler.h"
26#include "ns3/priority-queue-scheduler.h"
27
28using namespace ns3;
29
47{
48public:
53 SimulatorEventsTestCase (ObjectFactory schedulerFactory);
54 virtual void DoRun (void);
60 void EventA (int value);
61 void EventB (int value);
62 void EventC (int value);
63 void EventD (int value);
69 void Eventfoo0 (void);
70
75 uint64_t NowUs (void);
79 void Destroy (void);
84 bool m_a;
85 bool m_b;
86 bool m_c;
87 bool m_d;
94};
95
97 : TestCase ("Check that basic event handling is working with " +
98 schedulerFactory.GetTypeId ().GetName ()),
99 m_schedulerFactory (schedulerFactory)
100{}
101uint64_t
103{
104 uint64_t ns = Now ().GetNanoSeconds ();
105 return ns / 1000;
106}
107
108void
109SimulatorEventsTestCase::EventA ([[maybe_unused]] int a)
110{
111 m_a = false;
112}
113
114void
116{
117 if (b != 2 || NowUs () != 11)
118 {
119 m_b = false;
120 }
121 else
122 {
123 m_b = true;
124 }
125 Simulator::Remove (m_idC);
126 Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::EventD, this, 4);
127}
128
129void
130SimulatorEventsTestCase::EventC ([[maybe_unused]] int c)
131{
132 m_c = false;
133}
134
135void
137{
138 if (d != 4 || NowUs () != (11 + 10))
139 {
140 m_d = false;
141 }
142 else
143 {
144 m_d = true;
145 }
146}
147
148void
150{}
151
152void
154{
155 if (m_destroyId.IsExpired ())
156 {
157 m_destroy = true;
158 }
159}
160void
162{
163 m_a = true;
164 m_b = false;
165 m_c = true;
166 m_d = false;
167
168 Simulator::SetScheduler (m_schedulerFactory);
169
170 EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::EventA, this, 1);
171 Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::EventB, this, 2);
172 m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::EventC, this, 3);
173
174 NS_TEST_EXPECT_MSG_EQ (!m_idC.IsExpired (), true, "");
175 NS_TEST_EXPECT_MSG_EQ (!a.IsExpired (), true, "");
176 Simulator::Cancel (a);
177 NS_TEST_EXPECT_MSG_EQ (a.IsExpired (), true, "");
178 Simulator::Run ();
179 NS_TEST_EXPECT_MSG_EQ (m_a, true, "Event A did not run ?");
180 NS_TEST_EXPECT_MSG_EQ (m_b, true, "Event B did not run ?");
181 NS_TEST_EXPECT_MSG_EQ (m_c, true, "Event C did not run ?");
182 NS_TEST_EXPECT_MSG_EQ (m_d, true, "Event D did not run ?");
183
184 EventId anId = Simulator::ScheduleNow (&SimulatorEventsTestCase::Eventfoo0, this);
185 EventId anotherId = anId;
186 NS_TEST_EXPECT_MSG_EQ (!(anId.IsExpired () || anotherId.IsExpired ()), true, "Event should not have expired yet.");
187
188 Simulator::Remove (anId);
189 NS_TEST_EXPECT_MSG_EQ (anId.IsExpired (), true, "Event was removed: it is now expired");
190 NS_TEST_EXPECT_MSG_EQ (anotherId.IsExpired (), true, "Event was removed: it is now expired");
191
192 m_destroy = false;
193 m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::Destroy, this);
194 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
196 NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
197
198 m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::Destroy, this);
199 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
200 Simulator::Remove (m_destroyId);
201 NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
202
203 m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::Destroy, this);
204 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
205
206 Simulator::Run ();
207 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
208 NS_TEST_EXPECT_MSG_EQ (!m_destroy, true, "Event should not have run");
209
210 Simulator::Destroy ();
211 NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event should have expired now");
212 NS_TEST_EXPECT_MSG_EQ (m_destroy, true, "Event should have run");
213}
214
215
224{
225public:
232 void Ref (void) const {};
233 void Unref (void) const {};
236private:
237 virtual void DoRun (void);
238
239 /* *NS_CHECK_STYLE_OFF* */
245 void bar0 (void) {}
246 void bar1 (int) {}
247 void bar2 (int, int) {}
248 void bar3 (int, int, int) {}
249 void bar4 (int, int, int, int) {}
250 void bar5 (int, int, int, int, int) {}
251 void baz1 (int &) {}
252 void baz2 (int &, int &) {}
253 void baz3 (int &, int &, int &) {}
254 void baz4 (int &, int &, int &, int &) {}
255 void baz5 (int &, int &, int &, int &, int &) {}
256 void cbaz1 (const int &) {}
257 void cbaz2 (const int &, const int &) {}
258 void cbaz3 (const int &, const int &, const int &) {}
259 void cbaz4 (const int &, const int &, const int &, const int &) {}
260 void cbaz5 (const int &, const int &, const int &, const int &, const int &) {}
261
262 void bar0c (void) const {}
263 void bar1c (int) const {}
264 void bar2c (int, int) const {}
265 void bar3c (int, int, int) const {}
266 void bar4c (int, int, int, int) const {}
267 void bar5c (int, int, int, int, int) const {}
268 void baz1c (int &) const {}
269 void baz2c (int &, int &) const {}
270 void baz3c (int &, int &, int &) const {}
271 void baz4c (int &, int &, int &, int &) const {}
272 void baz5c (int &, int &, int &, int &, int &) const {}
273 void cbaz1c (const int &) const {}
274 void cbaz2c (const int &, const int &) const {}
275 void cbaz3c (const int &, const int &, const int &) const {}
276 void cbaz4c (const int &, const int &, const int &, const int &) const {}
277 void cbaz5c (const int &, const int &, const int &, const int &, const int &) const {}
279 /* *NS_CHECK_STYLE_ON* */
280
281};
282
288static void foo0 (void)
289{}
290static void foo1 (int)
291{}
292static void foo2 (int, int)
293{}
294static void foo3 (int, int, int)
295{}
296static void foo4 (int, int, int, int)
297{}
298static void foo5 (int, int, int, int, int)
299{}
300static void ber1 (int &)
301{}
302static void ber2 (int &, int &)
303{}
304static void ber3 (int &, int &, int &)
305{}
306static void ber4 (int &, int &, int &, int &)
307{}
308static void ber5 (int &, int &, int &, int &, int &)
309{}
310static void cber1 (const int &)
311{}
312static void cber2 (const int &, const int &)
313{}
314static void cber3 (const int &, const int &, const int &)
315{}
316static void cber4 (const int &, const int &, const int &, const int &)
317{}
318static void cber5 (const int &, const int &, const int &, const int &, const int &)
319{}
323 : TestCase ("Check that all templates are instantiated correctly. This is a compilation test, it cannot fail at runtime.")
324{}
325void
327{
328 // Test schedule of const methods
329 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, this);
330 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, this, 0);
331 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, this, 0, 0);
332 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
333 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
334 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
335 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1c, this, 0);
336 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
337 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
338 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
339 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
340 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, this);
341 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, this, 0);
342 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
343 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
344 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
345 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
346 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1c, this, 0);
347 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
348 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
349 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
350 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
351 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, this);
352 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, this, 0);
353 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
354 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
355 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
356 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
357 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1c, this, 0);
358 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
359 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
360 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
361 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
362 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1c, this, 0);
363 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2c, this, 0, 0);
364 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
365 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
366 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
367 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1c, this, 0);
368 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
369 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
370 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
371 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
372 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1c, this, 0);
373 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
374 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
375 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
376 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
377
378 // Test of schedule const methods with Ptr<> pointers
381 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
382 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
383 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
384 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
387 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
388 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
389 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
390 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
392 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
393 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
394 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
395 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
396 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
397
398
399 // Test schedule of raw functions
400 Simulator::Schedule (Seconds (0.0), &foo0);
401 Simulator::Schedule (Seconds (0.0), &foo1, 0);
402 Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
403 Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0);
404 Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0);
405 Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
406 Simulator::Schedule (Seconds (0.0), &cber1, 0);
407 Simulator::Schedule (Seconds (0.0), &cber2, 0, 0);
408 Simulator::Schedule (Seconds (0.0), &cber3, 0, 0, 0);
409 Simulator::Schedule (Seconds (0.0), &cber4, 0, 0, 0, 0);
410 Simulator::Schedule (Seconds (0.0), &cber5, 0, 0, 0, 0, 0);
411 Simulator::ScheduleNow (&foo0);
412 Simulator::ScheduleNow (&foo1, 0);
413 Simulator::ScheduleNow (&foo2, 0, 0);
414 Simulator::ScheduleNow (&foo3, 0, 0, 0);
415 Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
416 Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
417 Simulator::ScheduleNow (&cber1, 0);
418 Simulator::ScheduleNow (&cber2, 0, 0);
419 Simulator::ScheduleNow (&cber3, 0, 0, 0);
420 Simulator::ScheduleNow (&cber4, 0, 0, 0, 0);
421 Simulator::ScheduleNow (&cber5, 0, 0, 0, 0, 0);
422 Simulator::ScheduleDestroy (&foo0);
423 Simulator::ScheduleDestroy (&foo1, 0);
424 Simulator::ScheduleDestroy (&foo2, 0, 0);
425 Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
426 Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
427 Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
428 Simulator::ScheduleDestroy (&cber1, 0);
429 Simulator::ScheduleDestroy (&cber2, 0, 0);
430 Simulator::ScheduleDestroy (&cber3, 0, 0, 0);
431 Simulator::ScheduleDestroy (&cber4, 0, 0, 0, 0);
432 Simulator::ScheduleDestroy (&cber5, 0, 0, 0, 0, 0);
433
434
435 // Test schedule of normal member methods
436 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, this);
437 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, this, 0);
438 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, this, 0, 0);
439 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
440 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
441 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
442 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1, this, 0);
443 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2, this, 0, 0);
444 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
445 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
446 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
447 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, this);
448 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, this, 0);
449 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, this, 0, 0);
450 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
451 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
452 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
453 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1, this, 0);
454 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
455 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
456 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
457 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
458 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, this);
459 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, this, 0);
460 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, this, 0, 0);
461 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
462 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
463 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
464 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1, this, 0);
465 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
466 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
467 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
468 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
469
470
471 // test schedule of normal methods with Ptr<> pointers
472 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
473 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
474 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
475 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
476 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
477 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
478 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
479 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
480 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
481 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
482 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
483 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
484 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
485 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
486 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
487 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
488 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
489 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
490
491
492 // the code below does not compile, as expected.
493 //Simulator::Schedule (Seconds (0.0), &cber1, 0.0);
494
495
496 // This code appears to be duplicate test code.
497 Simulator::Schedule (Seconds (0.0), &ber1, 0);
498 Simulator::Schedule (Seconds (0.0), &ber2, 0, 0);
499 Simulator::Schedule (Seconds (0.0), &ber3, 0, 0, 0);
500 Simulator::Schedule (Seconds (0.0), &ber4, 0, 0, 0, 0);
501 Simulator::Schedule (Seconds (0.0), &ber5, 0, 0, 0, 0, 0);
502 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1, this, 0);
503 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2, this, 0, 0);
504 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
505 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
506 Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
507 Simulator::ScheduleNow (&ber1, 0);
508 Simulator::ScheduleNow (&ber2, 0, 0);
509 Simulator::ScheduleNow (&ber3, 0, 0, 0);
510 Simulator::ScheduleNow (&ber4, 0, 0, 0, 0);
511 Simulator::ScheduleNow (&ber5, 0, 0, 0, 0, 0);
512 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1, this, 0);
513 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2, this, 0, 0);
514 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
515 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
516 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
517 Simulator::ScheduleDestroy (&ber1, 0);
518 Simulator::ScheduleDestroy (&ber2, 0, 0);
519 Simulator::ScheduleDestroy (&ber3, 0, 0, 0);
520 Simulator::ScheduleDestroy (&ber4, 0, 0, 0, 0);
521 Simulator::ScheduleDestroy (&ber5, 0, 0, 0, 0, 0);
522 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1, this, 0);
523 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2, this, 0, 0);
524 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
525 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
526 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
527
528
529 Simulator::Run ();
530 Simulator::Destroy ();
531}
532
533
540{
541public:
543 : TestSuite ("simulator")
544 {
545 ObjectFactory factory;
546 factory.SetTypeId (ListScheduler::GetTypeId ());
547
548 AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
549 factory.SetTypeId (MapScheduler::GetTypeId ());
550 AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
551 factory.SetTypeId (HeapScheduler::GetTypeId ());
552 AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
553 factory.SetTypeId (CalendarScheduler::GetTypeId ());
554 AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
555 factory.SetTypeId (PriorityQueueScheduler::GetTypeId ());
556 AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
557 }
558};
559
Check that basic event handling is working with different Simulator implementations.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void EventD(int value)
Test Event.
void EventC(int value)
Test Event.
bool m_c
Checks that events are properly handled.
SimulatorEventsTestCase(ObjectFactory schedulerFactory)
Constructor.
uint64_t NowUs(void)
Get the simulator time.
bool m_a
Checks that events are properly handled.
bool m_destroy
Checks that events are properly handled.
bool m_b
Checks that events are properly handled.
void Eventfoo0(void)
Test Event.
void EventB(int value)
Test Event.
ObjectFactory m_schedulerFactory
Scheduler factory.
EventId m_destroyId
Event to check event lifetime.
void Destroy(void)
Checks that the events has been detroyed.
void EventA(int value)
Test Event.
bool m_d
Checks that events are properly handled.
Check that all templates are instantiated correctly.
void bar2(int, int)
Function used for scheduling.
void bar4(int, int, int, int)
Function used for scheduling.
void bar1c(int) const
Function used for scheduling.
void cbaz2(const int &, const int &)
Function used for scheduling.
void Ref(void) const
Ref and Unref - only here for testing of Ptr<>
void baz5c(int &, int &, int &, int &, int &) const
Function used for scheduling.
void baz1(int &)
Function used for scheduling.
void Unref(void) const
Ref and Unref - only here for testing of Ptr<>
void cbaz4c(const int &, const int &, const int &, const int &) const
Function used for scheduling.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void baz3c(int &, int &, int &) const
Function used for scheduling.
void baz4c(int &, int &, int &, int &) const
Function used for scheduling.
void cbaz2c(const int &, const int &) const
Function used for scheduling.
void baz4(int &, int &, int &, int &)
Function used for scheduling.
void baz1c(int &) const
Function used for scheduling.
void cbaz5c(const int &, const int &, const int &, const int &, const int &) const
Function used for scheduling.
void cbaz5(const int &, const int &, const int &, const int &, const int &)
Function used for scheduling.
void bar5(int, int, int, int, int)
Function used for scheduling.
void baz2c(int &, int &) const
Function used for scheduling.
void baz5(int &, int &, int &, int &, int &)
Function used for scheduling.
void bar0(void)
Function used for scheduling.
void bar0c(void) const
Function used for scheduling.
void bar1(int)
Function used for scheduling.
void cbaz1(const int &)
Function used for scheduling.
void cbaz3(const int &, const int &, const int &)
Function used for scheduling.
void bar4c(int, int, int, int) const
Function used for scheduling.
void bar3c(int, int, int) const
Function used for scheduling.
void cbaz3c(const int &, const int &, const int &) const
Function used for scheduling.
void cbaz1c(const int &) const
Function used for scheduling.
void cbaz4(const int &, const int &, const int &, const int &)
Function used for scheduling.
void baz2(int &, int &)
Function used for scheduling.
void bar5c(int, int, int, int, int) const
Function used for scheduling.
void bar2c(int, int) const
Function used for scheduling.
void bar3(int, int, int)
Function used for scheduling.
void baz3(int &, int &, int &)
Function used for scheduling.
The simulator Test Suite.
An identifier for simulation events.
Definition: event-id.h:54
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:65
Instantiate subclasses of ns3::Object.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:391
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
#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
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1260
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static void ber5(int &, int &, int &, int &, int &)
Function used for scheduling.
static void foo3(int, int, int)
Function used for scheduling.
static void ber4(int &, int &, int &, int &)
Function used for scheduling.
static void cber5(const int &, const int &, const int &, const int &, const int &)
Function used for scheduling.
static void cber1(const int &)
Function used for scheduling.
static void ber3(int &, int &, int &)
Function used for scheduling.
static SimulatorTestSuite g_simulatorTestSuite
Static variable for test initialization.
static void cber3(const int &, const int &, const int &)
Function used for scheduling.
static void foo4(int, int, int, int)
Function used for scheduling.
static void foo2(int, int)
Function used for scheduling.
static void cber2(const int &, const int &)
Function used for scheduling.
static void cber4(const int &, const int &, const int &, const int &)
Function used for scheduling.
static void ber1(int &)
Function used for scheduling.
static void foo5(int, int, int, int, int)
Function used for scheduling.
static void foo1(int)
Function used for scheduling.
static void ber2(int &, int &)
Function used for scheduling.
static void foo0(void)
Function used for scheduling.