A Discrete-Event Network Simulator
API
simulator-test-suite.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005,2006 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #include "ns3/calendar-scheduler.h"
20 #include "ns3/heap-scheduler.h"
21 #include "ns3/list-scheduler.h"
22 #include "ns3/map-scheduler.h"
23 #include "ns3/priority-queue-scheduler.h"
24 #include "ns3/simulator.h"
25 #include "ns3/test.h"
26 
27 using namespace ns3;
28 
46 {
47  public:
52  SimulatorEventsTestCase(ObjectFactory schedulerFactory);
53  void DoRun() override;
59  void EventA(int value);
60  void EventB(int value);
61  void EventC(int value);
62  void EventD(int value);
68  void Eventfoo0();
69 
74  uint64_t NowUs();
78  void Destroy();
83  bool m_a;
84  bool m_b;
85  bool m_c;
86  bool m_d;
87  bool m_destroy;
93 };
94 
96  : TestCase("Check that basic event handling is working with " +
97  schedulerFactory.GetTypeId().GetName()),
98  m_schedulerFactory(schedulerFactory)
99 {
100 }
101 
102 uint64_t
104 {
105  uint64_t ns = Now().GetNanoSeconds();
106  return ns / 1000;
107 }
108 
109 void
111 {
112  m_a = false;
113 }
114 
115 void
117 {
118  if (b != 2 || NowUs() != 11)
119  {
120  m_b = false;
121  }
122  else
123  {
124  m_b = true;
125  }
126  Simulator::Remove(m_idC);
127  Simulator::Schedule(MicroSeconds(10), &SimulatorEventsTestCase::EventD, this, 4);
128 }
129 
130 void
132 {
133  m_c = false;
134 }
135 
136 void
138 {
139  if (d != 4 || NowUs() != (11 + 10))
140  {
141  m_d = false;
142  }
143  else
144  {
145  m_d = true;
146  }
147 }
148 
149 void
151 {
152 }
153 
154 void
156 {
157  if (m_destroyId.IsExpired())
158  {
159  m_destroy = true;
160  }
161 }
162 
163 void
165 {
166  m_a = true;
167  m_b = false;
168  m_c = true;
169  m_d = false;
170 
171  Simulator::SetScheduler(m_schedulerFactory);
172 
173  EventId a = Simulator::Schedule(MicroSeconds(10), &SimulatorEventsTestCase::EventA, this, 1);
174  Simulator::Schedule(MicroSeconds(11), &SimulatorEventsTestCase::EventB, this, 2);
175  m_idC = Simulator::Schedule(MicroSeconds(12), &SimulatorEventsTestCase::EventC, this, 3);
176 
177  NS_TEST_EXPECT_MSG_EQ(!m_idC.IsExpired(), true, "");
178  NS_TEST_EXPECT_MSG_EQ(!a.IsExpired(), true, "");
179  Simulator::Cancel(a);
180  NS_TEST_EXPECT_MSG_EQ(a.IsExpired(), true, "");
181  Simulator::Run();
182  NS_TEST_EXPECT_MSG_EQ(m_a, true, "Event A did not run ?");
183  NS_TEST_EXPECT_MSG_EQ(m_b, true, "Event B did not run ?");
184  NS_TEST_EXPECT_MSG_EQ(m_c, true, "Event C did not run ?");
185  NS_TEST_EXPECT_MSG_EQ(m_d, true, "Event D did not run ?");
186 
187  EventId anId = Simulator::ScheduleNow(&SimulatorEventsTestCase::Eventfoo0, this);
188  EventId anotherId = anId;
189  NS_TEST_EXPECT_MSG_EQ(!(anId.IsExpired() || anotherId.IsExpired()),
190  true,
191  "Event should not have expired yet.");
192 
193  Simulator::Remove(anId);
194  NS_TEST_EXPECT_MSG_EQ(anId.IsExpired(), true, "Event was removed: it is now expired");
195  NS_TEST_EXPECT_MSG_EQ(anotherId.IsExpired(), true, "Event was removed: it is now expired");
196 
197  m_destroy = false;
198  m_destroyId = Simulator::ScheduleDestroy(&SimulatorEventsTestCase::Destroy, this);
199  NS_TEST_EXPECT_MSG_EQ(!m_destroyId.IsExpired(), true, "Event should not have expired yet");
202  true,
203  "Event was canceled: should have expired now");
204 
205  m_destroyId = Simulator::ScheduleDestroy(&SimulatorEventsTestCase::Destroy, this);
206  NS_TEST_EXPECT_MSG_EQ(!m_destroyId.IsExpired(), true, "Event should not have expired yet");
207  Simulator::Remove(m_destroyId);
209  true,
210  "Event was canceled: should have expired now");
211 
212  m_destroyId = Simulator::ScheduleDestroy(&SimulatorEventsTestCase::Destroy, this);
213  NS_TEST_EXPECT_MSG_EQ(!m_destroyId.IsExpired(), true, "Event should not have expired yet");
214 
215  Simulator::Run();
216  NS_TEST_EXPECT_MSG_EQ(!m_destroyId.IsExpired(), true, "Event should not have expired yet");
217  NS_TEST_EXPECT_MSG_EQ(!m_destroy, true, "Event should not have run");
218 
219  Simulator::Destroy();
220  NS_TEST_EXPECT_MSG_EQ(m_destroyId.IsExpired(), true, "Event should have expired now");
221  NS_TEST_EXPECT_MSG_EQ(m_destroy, true, "Event should have run");
222 }
223 
232 {
233  public:
240  void Ref() const {};
241  void Unref() const {};
244  private:
245  void DoRun() override;
246 
252  void bar0(){};
253  void bar1(int){};
254  void bar2(int, int){};
255  void bar3(int, int, int){};
256  void bar4(int, int, int, int){};
257  void bar5(int, int, int, int, int){};
258  void baz1(int&){};
259  void baz2(int&, int&){};
260  void baz3(int&, int&, int&){};
261  void baz4(int&, int&, int&, int&){};
262  void baz5(int&, int&, int&, int&, int&){};
263  void cbaz1(const int&){};
264  void cbaz2(const int&, const int&){};
265  void cbaz3(const int&, const int&, const int&){};
266  void cbaz4(const int&, const int&, const int&, const int&){};
267  void cbaz5(const int&, const int&, const int&, const int&, const int&){};
268 
269  void bar0c() const {};
270  void bar1c(int) const {};
271  void bar2c(int, int) const {};
272  void bar3c(int, int, int) const {};
273  void bar4c(int, int, int, int) const {};
274  void bar5c(int, int, int, int, int) const {};
275  void baz1c(int&) const {};
276  void baz2c(int&, int&) const {};
277  void baz3c(int&, int&, int&) const {};
278  void baz4c(int&, int&, int&, int&) const {};
279  void baz5c(int&, int&, int&, int&, int&) const {};
280  void cbaz1c(const int&) const {};
281  void cbaz2c(const int&, const int&) const {};
282  void cbaz3c(const int&, const int&, const int&) const {};
283  void cbaz4c(const int&, const int&, const int&, const int&) const {};
284  void cbaz5c(const int&, const int&, const int&, const int&, const int&) const {};
286 };
287 
293 static void
295 {
296 }
297 
298 static void
299 foo1(int)
300 {
301 }
302 
303 static void
304 foo2(int, int)
305 {
306 }
307 
308 static void
309 foo3(int, int, int)
310 {
311 }
312 
313 static void
314 foo4(int, int, int, int)
315 {
316 }
317 
318 static void
319 foo5(int, int, int, int, int)
320 {
321 }
322 
323 static void
324 ber1(int&)
325 {
326 }
327 
328 static void
329 ber2(int&, int&)
330 {
331 }
332 
333 static void
334 ber3(int&, int&, int&)
335 {
336 }
337 
338 static void
339 ber4(int&, int&, int&, int&)
340 {
341 }
342 
343 static void
344 ber5(int&, int&, int&, int&, int&)
345 {
346 }
347 
348 static void
349 cber1(const int&)
350 {
351 }
352 
353 static void
354 cber2(const int&, const int&)
355 {
356 }
357 
358 static void
359 cber3(const int&, const int&, const int&)
360 {
361 }
362 
363 static void
364 cber4(const int&, const int&, const int&, const int&)
365 {
366 }
367 
368 static void
369 cber5(const int&, const int&, const int&, const int&, const int&)
370 {
371 }
372 
376  : TestCase("Check that all templates are instantiated correctly. This is a compilation test, "
377  "it cannot fail at runtime.")
378 {
379 }
380 
381 void
383 {
384  // Test schedule of const methods
385  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar0c, this);
386  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar1c, this, 0);
387  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar2c, this, 0, 0);
388  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
389  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
390  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
391  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz1c, this, 0);
392  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
393  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
394  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
395  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
396  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar0c, this);
397  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar1c, this, 0);
398  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar2c, this, 0, 0);
399  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
400  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
401  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
402  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz1c, this, 0);
403  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
404  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
405  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
406  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
407  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar0c, this);
408  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar1c, this, 0);
409  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar2c, this, 0, 0);
410  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
411  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
412  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
413  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz1c, this, 0);
414  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
415  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
416  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
417  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
418  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz1c, this, 0);
419  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz2c, this, 0, 0);
420  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
421  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
422  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
423  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz1c, this, 0);
424  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz2c, this, 0, 0);
425  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
426  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
427  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
428  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz1c, this, 0);
429  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz2c, this, 0, 0);
430  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
431  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
432  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
433 
434  // Test of schedule const methods with Ptr<> pointers
435  Simulator::Schedule(Seconds(0.0),
438  Simulator::Schedule(Seconds(0.0),
441  0);
442  Simulator::Schedule(Seconds(0.0),
445  0,
446  0);
447  Simulator::Schedule(Seconds(0.0),
450  0,
451  0,
452  0);
453  Simulator::Schedule(Seconds(0.0),
456  0,
457  0,
458  0,
459  0);
460  Simulator::Schedule(Seconds(0.0),
463  0,
464  0,
465  0,
466  0,
467  0);
468  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar0c,
470  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar1c,
472  0);
473  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar2c,
475  0,
476  0);
477  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar3c,
479  0,
480  0,
481  0);
482  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar4c,
484  0,
485  0,
486  0,
487  0);
488  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar5c,
490  0,
491  0,
492  0,
493  0,
494  0);
495  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar0c,
497  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar1c,
499  0);
500  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar2c,
502  0,
503  0);
504  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar3c,
506  0,
507  0,
508  0);
509  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar4c,
511  0,
512  0,
513  0,
514  0);
515  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar5c,
517  0,
518  0,
519  0,
520  0,
521  0);
522 
523  // Test schedule of raw functions
524  Simulator::Schedule(Seconds(0.0), &foo0);
525  Simulator::Schedule(Seconds(0.0), &foo1, 0);
526  Simulator::Schedule(Seconds(0.0), &foo2, 0, 0);
527  Simulator::Schedule(Seconds(0.0), &foo3, 0, 0, 0);
528  Simulator::Schedule(Seconds(0.0), &foo4, 0, 0, 0, 0);
529  Simulator::Schedule(Seconds(0.0), &foo5, 0, 0, 0, 0, 0);
530  Simulator::Schedule(Seconds(0.0), &cber1, 0);
531  Simulator::Schedule(Seconds(0.0), &cber2, 0, 0);
532  Simulator::Schedule(Seconds(0.0), &cber3, 0, 0, 0);
533  Simulator::Schedule(Seconds(0.0), &cber4, 0, 0, 0, 0);
534  Simulator::Schedule(Seconds(0.0), &cber5, 0, 0, 0, 0, 0);
535  Simulator::ScheduleNow(&foo0);
536  Simulator::ScheduleNow(&foo1, 0);
537  Simulator::ScheduleNow(&foo2, 0, 0);
538  Simulator::ScheduleNow(&foo3, 0, 0, 0);
539  Simulator::ScheduleNow(&foo4, 0, 0, 0, 0);
540  Simulator::ScheduleNow(&foo5, 0, 0, 0, 0, 0);
541  Simulator::ScheduleNow(&cber1, 0);
542  Simulator::ScheduleNow(&cber2, 0, 0);
543  Simulator::ScheduleNow(&cber3, 0, 0, 0);
544  Simulator::ScheduleNow(&cber4, 0, 0, 0, 0);
545  Simulator::ScheduleNow(&cber5, 0, 0, 0, 0, 0);
546  Simulator::ScheduleDestroy(&foo0);
547  Simulator::ScheduleDestroy(&foo1, 0);
548  Simulator::ScheduleDestroy(&foo2, 0, 0);
549  Simulator::ScheduleDestroy(&foo3, 0, 0, 0);
550  Simulator::ScheduleDestroy(&foo4, 0, 0, 0, 0);
551  Simulator::ScheduleDestroy(&foo5, 0, 0, 0, 0, 0);
552  Simulator::ScheduleDestroy(&cber1, 0);
553  Simulator::ScheduleDestroy(&cber2, 0, 0);
554  Simulator::ScheduleDestroy(&cber3, 0, 0, 0);
555  Simulator::ScheduleDestroy(&cber4, 0, 0, 0, 0);
556  Simulator::ScheduleDestroy(&cber5, 0, 0, 0, 0, 0);
557 
558  // Test schedule of normal member methods
559  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar0, this);
560  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar1, this, 0);
561  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar2, this, 0, 0);
562  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
563  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
564  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
565  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz1, this, 0);
566  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz2, this, 0, 0);
567  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
568  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
569  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
570  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar0, this);
571  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar1, this, 0);
572  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar2, this, 0, 0);
573  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
574  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
575  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
576  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz1, this, 0);
577  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
578  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
579  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
580  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
581  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar0, this);
582  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar1, this, 0);
583  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar2, this, 0, 0);
584  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
585  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
586  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
587  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz1, this, 0);
588  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
589  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
590  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
591  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
592 
593  // test schedule of normal methods with Ptr<> pointers
594  Simulator::Schedule(Seconds(0.0),
597  Simulator::Schedule(Seconds(0.0),
600  0);
601  Simulator::Schedule(Seconds(0.0),
604  0,
605  0);
606  Simulator::Schedule(Seconds(0.0),
609  0,
610  0,
611  0);
612  Simulator::Schedule(Seconds(0.0),
615  0,
616  0,
617  0,
618  0);
619  Simulator::Schedule(Seconds(0.0),
622  0,
623  0,
624  0,
625  0,
626  0);
627  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase>(this));
628  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar1,
630  0);
631  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar2,
633  0,
634  0);
635  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar3,
637  0,
638  0,
639  0);
640  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar4,
642  0,
643  0,
644  0,
645  0);
646  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar5,
648  0,
649  0,
650  0,
651  0,
652  0);
653  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar0,
655  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar1,
657  0);
658  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar2,
660  0,
661  0);
662  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar3,
664  0,
665  0,
666  0);
667  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar4,
669  0,
670  0,
671  0,
672  0);
673  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar5,
675  0,
676  0,
677  0,
678  0,
679  0);
680 
681  // the code below does not compile, as expected.
682  // Simulator::Schedule (Seconds (0.0), &cber1, 0.0);
683 
684  // This code appears to be duplicate test code.
685  Simulator::Schedule(Seconds(0.0), &ber1, 0);
686  Simulator::Schedule(Seconds(0.0), &ber2, 0, 0);
687  Simulator::Schedule(Seconds(0.0), &ber3, 0, 0, 0);
688  Simulator::Schedule(Seconds(0.0), &ber4, 0, 0, 0, 0);
689  Simulator::Schedule(Seconds(0.0), &ber5, 0, 0, 0, 0, 0);
690  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz1, this, 0);
691  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz2, this, 0, 0);
692  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
693  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
694  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
695  Simulator::ScheduleNow(&ber1, 0);
696  Simulator::ScheduleNow(&ber2, 0, 0);
697  Simulator::ScheduleNow(&ber3, 0, 0, 0);
698  Simulator::ScheduleNow(&ber4, 0, 0, 0, 0);
699  Simulator::ScheduleNow(&ber5, 0, 0, 0, 0, 0);
700  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz1, this, 0);
701  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz2, this, 0, 0);
702  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
703  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
704  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
705  Simulator::ScheduleDestroy(&ber1, 0);
706  Simulator::ScheduleDestroy(&ber2, 0, 0);
707  Simulator::ScheduleDestroy(&ber3, 0, 0, 0);
708  Simulator::ScheduleDestroy(&ber4, 0, 0, 0, 0);
709  Simulator::ScheduleDestroy(&ber5, 0, 0, 0, 0, 0);
710  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz1, this, 0);
711  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz2, this, 0, 0);
712  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
713  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
714  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
715 
716  Simulator::Run();
717  Simulator::Destroy();
718 }
719 
726 {
727  public:
729  : TestSuite("simulator")
730  {
731  ObjectFactory factory;
732  factory.SetTypeId(ListScheduler::GetTypeId());
733 
734  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
735  factory.SetTypeId(MapScheduler::GetTypeId());
736  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
737  factory.SetTypeId(HeapScheduler::GetTypeId());
738  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
739  factory.SetTypeId(CalendarScheduler::GetTypeId());
740  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
741  factory.SetTypeId(PriorityQueueScheduler::GetTypeId());
742  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
743  }
744 };
745 
Check that basic event handling is working with different Simulator implementations.
void EventD(int value)
Test Event.
void Destroy()
Checks that the events has been destroyed.
uint64_t NowUs()
Get the simulator time.
void DoRun() override
Implementation to actually run this TestCase.
void EventC(int value)
Test Event.
bool m_c
Checks that events are properly handled.
SimulatorEventsTestCase(ObjectFactory schedulerFactory)
Constructor.
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 EventB(int value)
Test Event.
ObjectFactory m_schedulerFactory
Scheduler factory.
EventId m_destroyId
Event to check event lifetime.
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 bar0()
Function used for scheduling.
void cbaz2(const int &, const int &)
Function used for scheduling.
void Ref() const
Ref and Unref - only here for testing of Ptr<>
void Unref() 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 cbaz4c(const int &, const int &, const int &, const int &) const
Function used for scheduling.
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 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 bar0c() const
Function used for scheduling.
void DoRun() override
Implementation to actually run this TestCase.
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:55
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:69
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:78
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:417
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
#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:251
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1360
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Every class exported by the ns3 library is enclosed in the ns3 namespace.
value
Definition: second.py:41
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 foo0()
Function used for scheduling.
static void ber2(int &, int &)
Function used for scheduling.