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  m_b = !(b != 2 || NowUs() != 11);
119  Simulator::Remove(m_idC);
120  Simulator::Schedule(MicroSeconds(10), &SimulatorEventsTestCase::EventD, this, 4);
121 }
122 
123 void
125 {
126  m_c = false;
127 }
128 
129 void
131 {
132  m_d = !(d != 4 || NowUs() != (11 + 10));
133 }
134 
135 void
137 {
138 }
139 
140 void
142 {
143  if (m_destroyId.IsExpired())
144  {
145  m_destroy = true;
146  }
147 }
148 
149 void
151 {
152  m_a = true;
153  m_b = false;
154  m_c = true;
155  m_d = false;
156 
157  Simulator::SetScheduler(m_schedulerFactory);
158 
159  EventId a = Simulator::Schedule(MicroSeconds(10), &SimulatorEventsTestCase::EventA, this, 1);
160  Simulator::Schedule(MicroSeconds(11), &SimulatorEventsTestCase::EventB, this, 2);
161  m_idC = Simulator::Schedule(MicroSeconds(12), &SimulatorEventsTestCase::EventC, this, 3);
162 
163  NS_TEST_EXPECT_MSG_EQ(!m_idC.IsExpired(), true, "");
164  NS_TEST_EXPECT_MSG_EQ(!a.IsExpired(), true, "");
165  Simulator::Cancel(a);
166  NS_TEST_EXPECT_MSG_EQ(a.IsExpired(), true, "");
167  Simulator::Run();
168  NS_TEST_EXPECT_MSG_EQ(m_a, true, "Event A did not run ?");
169  NS_TEST_EXPECT_MSG_EQ(m_b, true, "Event B did not run ?");
170  NS_TEST_EXPECT_MSG_EQ(m_c, true, "Event C did not run ?");
171  NS_TEST_EXPECT_MSG_EQ(m_d, true, "Event D did not run ?");
172 
173  EventId anId = Simulator::ScheduleNow(&SimulatorEventsTestCase::Eventfoo0, this);
174 
175  // Test copy assignment operator
176  // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
177  EventId anotherId = anId;
178 
179  NS_TEST_EXPECT_MSG_EQ(!(anId.IsExpired() || anotherId.IsExpired()),
180  true,
181  "Event should not have expired yet.");
182 
183  Simulator::Remove(anId);
184  NS_TEST_EXPECT_MSG_EQ(anId.IsExpired(), true, "Event was removed: it is now expired");
185  NS_TEST_EXPECT_MSG_EQ(anotherId.IsExpired(), true, "Event was removed: it is now expired");
186 
187  m_destroy = false;
188  m_destroyId = Simulator::ScheduleDestroy(&SimulatorEventsTestCase::Destroy, this);
189  NS_TEST_EXPECT_MSG_EQ(!m_destroyId.IsExpired(), true, "Event should not have expired yet");
192  true,
193  "Event was canceled: should have expired now");
194 
195  m_destroyId = Simulator::ScheduleDestroy(&SimulatorEventsTestCase::Destroy, this);
196  NS_TEST_EXPECT_MSG_EQ(!m_destroyId.IsExpired(), true, "Event should not have expired yet");
197  Simulator::Remove(m_destroyId);
199  true,
200  "Event was canceled: should have expired now");
201 
202  m_destroyId = Simulator::ScheduleDestroy(&SimulatorEventsTestCase::Destroy, this);
203  NS_TEST_EXPECT_MSG_EQ(!m_destroyId.IsExpired(), true, "Event should not have expired yet");
204 
205  Simulator::Run();
206  NS_TEST_EXPECT_MSG_EQ(!m_destroyId.IsExpired(), true, "Event should not have expired yet");
207  NS_TEST_EXPECT_MSG_EQ(!m_destroy, true, "Event should not have run");
208 
209  Simulator::Destroy();
210  NS_TEST_EXPECT_MSG_EQ(m_destroyId.IsExpired(), true, "Event should have expired now");
211  NS_TEST_EXPECT_MSG_EQ(m_destroy, true, "Event should have run");
212 }
213 
222 {
223  public:
230  void Ref() const {};
231  void Unref() const {};
234  private:
235  void DoRun() override;
236 
242  void bar0(){};
243  void bar1(int){};
244  void bar2(int, int){};
245  void bar3(int, int, int){};
246  void bar4(int, int, int, int){};
247  void bar5(int, int, int, int, int){};
248  void baz1(int&){};
249  void baz2(int&, int&){};
250  void baz3(int&, int&, int&){};
251  void baz4(int&, int&, int&, int&){};
252  void baz5(int&, int&, int&, int&, int&){};
253  void cbaz1(const int&){};
254  void cbaz2(const int&, const int&){};
255  void cbaz3(const int&, const int&, const int&){};
256  void cbaz4(const int&, const int&, const int&, const int&){};
257  void cbaz5(const int&, const int&, const int&, const int&, const int&){};
258 
259  void bar0c() const {};
260  void bar1c(int) const {};
261  void bar2c(int, int) const {};
262  void bar3c(int, int, int) const {};
263  void bar4c(int, int, int, int) const {};
264  void bar5c(int, int, int, int, int) const {};
265  void baz1c(int&) const {};
266  void baz2c(int&, int&) const {};
267  void baz3c(int&, int&, int&) const {};
268  void baz4c(int&, int&, int&, int&) const {};
269  void baz5c(int&, int&, int&, int&, int&) const {};
270  void cbaz1c(const int&) const {};
271  void cbaz2c(const int&, const int&) const {};
272  void cbaz3c(const int&, const int&, const int&) const {};
273  void cbaz4c(const int&, const int&, const int&, const int&) const {};
274  void cbaz5c(const int&, const int&, const int&, const int&, const int&) const {};
276 };
277 
283 static void
285 {
286 }
287 
288 static void
289 foo1(int)
290 {
291 }
292 
293 static void
294 foo2(int, int)
295 {
296 }
297 
298 static void
299 foo3(int, int, int)
300 {
301 }
302 
303 static void
304 foo4(int, int, int, int)
305 {
306 }
307 
308 static void
309 foo5(int, int, int, int, int)
310 {
311 }
312 
313 static void
314 ber1(int&)
315 {
316 }
317 
318 static void
319 ber2(int&, int&)
320 {
321 }
322 
323 static void
324 ber3(int&, int&, int&)
325 {
326 }
327 
328 static void
329 ber4(int&, int&, int&, int&)
330 {
331 }
332 
333 static void
334 ber5(int&, int&, int&, int&, int&)
335 {
336 }
337 
338 static void
339 cber1(const int&)
340 {
341 }
342 
343 static void
344 cber2(const int&, const int&)
345 {
346 }
347 
348 static void
349 cber3(const int&, const int&, const int&)
350 {
351 }
352 
353 static void
354 cber4(const int&, const int&, const int&, const int&)
355 {
356 }
357 
358 static void
359 cber5(const int&, const int&, const int&, const int&, const int&)
360 {
361 }
362 
366  : TestCase("Check that all templates are instantiated correctly. This is a compilation test, "
367  "it cannot fail at runtime.")
368 {
369 }
370 
371 void
373 {
374  // Test schedule of const methods
375  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar0c, this);
376  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar1c, this, 0);
377  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar2c, this, 0, 0);
378  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
379  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
380  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
381  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz1c, this, 0);
382  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
383  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
384  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
385  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
386  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar0c, this);
387  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar1c, this, 0);
388  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar2c, this, 0, 0);
389  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
390  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
391  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
392  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz1c, this, 0);
393  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
394  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
395  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
396  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
397  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar0c, this);
398  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar1c, this, 0);
399  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar2c, this, 0, 0);
400  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
401  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
402  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
403  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz1c, this, 0);
404  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
405  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
406  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
407  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
408  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz1c, this, 0);
409  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz2c, this, 0, 0);
410  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
411  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
412  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
413  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz1c, this, 0);
414  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz2c, this, 0, 0);
415  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
416  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
417  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
418  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz1c, this, 0);
419  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz2c, this, 0, 0);
420  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
421  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
422  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
423 
424  // Test of schedule const methods with Ptr<> pointers
425  Simulator::Schedule(Seconds(0.0),
428  Simulator::Schedule(Seconds(0.0),
431  0);
432  Simulator::Schedule(Seconds(0.0),
435  0,
436  0);
437  Simulator::Schedule(Seconds(0.0),
440  0,
441  0,
442  0);
443  Simulator::Schedule(Seconds(0.0),
446  0,
447  0,
448  0,
449  0);
450  Simulator::Schedule(Seconds(0.0),
453  0,
454  0,
455  0,
456  0,
457  0);
458  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar0c,
460  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar1c,
462  0);
463  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar2c,
465  0,
466  0);
467  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar3c,
469  0,
470  0,
471  0);
472  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar4c,
474  0,
475  0,
476  0,
477  0);
478  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar5c,
480  0,
481  0,
482  0,
483  0,
484  0);
485  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar0c,
487  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar1c,
489  0);
490  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar2c,
492  0,
493  0);
494  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar3c,
496  0,
497  0,
498  0);
499  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar4c,
501  0,
502  0,
503  0,
504  0);
505  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar5c,
507  0,
508  0,
509  0,
510  0,
511  0);
512 
513  // Test schedule of raw functions
514  Simulator::Schedule(Seconds(0.0), &foo0);
515  Simulator::Schedule(Seconds(0.0), &foo1, 0);
516  Simulator::Schedule(Seconds(0.0), &foo2, 0, 0);
517  Simulator::Schedule(Seconds(0.0), &foo3, 0, 0, 0);
518  Simulator::Schedule(Seconds(0.0), &foo4, 0, 0, 0, 0);
519  Simulator::Schedule(Seconds(0.0), &foo5, 0, 0, 0, 0, 0);
520  Simulator::Schedule(Seconds(0.0), &cber1, 0);
521  Simulator::Schedule(Seconds(0.0), &cber2, 0, 0);
522  Simulator::Schedule(Seconds(0.0), &cber3, 0, 0, 0);
523  Simulator::Schedule(Seconds(0.0), &cber4, 0, 0, 0, 0);
524  Simulator::Schedule(Seconds(0.0), &cber5, 0, 0, 0, 0, 0);
525  Simulator::ScheduleNow(&foo0);
526  Simulator::ScheduleNow(&foo1, 0);
527  Simulator::ScheduleNow(&foo2, 0, 0);
528  Simulator::ScheduleNow(&foo3, 0, 0, 0);
529  Simulator::ScheduleNow(&foo4, 0, 0, 0, 0);
530  Simulator::ScheduleNow(&foo5, 0, 0, 0, 0, 0);
531  Simulator::ScheduleNow(&cber1, 0);
532  Simulator::ScheduleNow(&cber2, 0, 0);
533  Simulator::ScheduleNow(&cber3, 0, 0, 0);
534  Simulator::ScheduleNow(&cber4, 0, 0, 0, 0);
535  Simulator::ScheduleNow(&cber5, 0, 0, 0, 0, 0);
536  Simulator::ScheduleDestroy(&foo0);
537  Simulator::ScheduleDestroy(&foo1, 0);
538  Simulator::ScheduleDestroy(&foo2, 0, 0);
539  Simulator::ScheduleDestroy(&foo3, 0, 0, 0);
540  Simulator::ScheduleDestroy(&foo4, 0, 0, 0, 0);
541  Simulator::ScheduleDestroy(&foo5, 0, 0, 0, 0, 0);
542  Simulator::ScheduleDestroy(&cber1, 0);
543  Simulator::ScheduleDestroy(&cber2, 0, 0);
544  Simulator::ScheduleDestroy(&cber3, 0, 0, 0);
545  Simulator::ScheduleDestroy(&cber4, 0, 0, 0, 0);
546  Simulator::ScheduleDestroy(&cber5, 0, 0, 0, 0, 0);
547 
548  // Test schedule of normal member methods
549  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar0, this);
550  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar1, this, 0);
551  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar2, this, 0, 0);
552  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
553  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
554  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
555  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz1, this, 0);
556  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz2, this, 0, 0);
557  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
558  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
559  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
560  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar0, this);
561  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar1, this, 0);
562  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar2, this, 0, 0);
563  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
564  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
565  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
566  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz1, this, 0);
567  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
568  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
569  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
570  Simulator::ScheduleNow(&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
571  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar0, this);
572  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar1, this, 0);
573  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar2, this, 0, 0);
574  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
575  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
576  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
577  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz1, this, 0);
578  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
579  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
580  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
581  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
582 
583  // test schedule of normal methods with Ptr<> pointers
584  Simulator::Schedule(Seconds(0.0),
587  Simulator::Schedule(Seconds(0.0),
590  0);
591  Simulator::Schedule(Seconds(0.0),
594  0,
595  0);
596  Simulator::Schedule(Seconds(0.0),
599  0,
600  0,
601  0);
602  Simulator::Schedule(Seconds(0.0),
605  0,
606  0,
607  0,
608  0);
609  Simulator::Schedule(Seconds(0.0),
612  0,
613  0,
614  0,
615  0,
616  0);
617  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase>(this));
618  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar1,
620  0);
621  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar2,
623  0,
624  0);
625  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar3,
627  0,
628  0,
629  0);
630  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar4,
632  0,
633  0,
634  0,
635  0);
636  Simulator::ScheduleNow(&SimulatorTemplateTestCase::bar5,
638  0,
639  0,
640  0,
641  0,
642  0);
643  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar0,
645  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar1,
647  0);
648  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar2,
650  0,
651  0);
652  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar3,
654  0,
655  0,
656  0);
657  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar4,
659  0,
660  0,
661  0,
662  0);
663  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::bar5,
665  0,
666  0,
667  0,
668  0,
669  0);
670 
671  // the code below does not compile, as expected.
672  // Simulator::Schedule (Seconds (0.0), &cber1, 0.0);
673 
674  // This code appears to be duplicate test code.
675  Simulator::Schedule(Seconds(0.0), &ber1, 0);
676  Simulator::Schedule(Seconds(0.0), &ber2, 0, 0);
677  Simulator::Schedule(Seconds(0.0), &ber3, 0, 0, 0);
678  Simulator::Schedule(Seconds(0.0), &ber4, 0, 0, 0, 0);
679  Simulator::Schedule(Seconds(0.0), &ber5, 0, 0, 0, 0, 0);
680  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz1, this, 0);
681  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz2, this, 0, 0);
682  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
683  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
684  Simulator::Schedule(Seconds(0.0), &SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
685  Simulator::ScheduleNow(&ber1, 0);
686  Simulator::ScheduleNow(&ber2, 0, 0);
687  Simulator::ScheduleNow(&ber3, 0, 0, 0);
688  Simulator::ScheduleNow(&ber4, 0, 0, 0, 0);
689  Simulator::ScheduleNow(&ber5, 0, 0, 0, 0, 0);
690  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz1, this, 0);
691  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz2, this, 0, 0);
692  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
693  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
694  Simulator::ScheduleNow(&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
695  Simulator::ScheduleDestroy(&ber1, 0);
696  Simulator::ScheduleDestroy(&ber2, 0, 0);
697  Simulator::ScheduleDestroy(&ber3, 0, 0, 0);
698  Simulator::ScheduleDestroy(&ber4, 0, 0, 0, 0);
699  Simulator::ScheduleDestroy(&ber5, 0, 0, 0, 0, 0);
700  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz1, this, 0);
701  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz2, this, 0, 0);
702  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
703  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
704  Simulator::ScheduleDestroy(&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
705 
706  Simulator::Run();
707  Simulator::Destroy();
708 }
709 
716 {
717  public:
719  : TestSuite("simulator")
720  {
721  ObjectFactory factory;
722  factory.SetTypeId(ListScheduler::GetTypeId());
723 
724  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
725  factory.SetTypeId(MapScheduler::GetTypeId());
726  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
727  factory.SetTypeId(HeapScheduler::GetTypeId());
728  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
729  factory.SetTypeId(CalendarScheduler::GetTypeId());
730  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
731  factory.SetTypeId(PriorityQueueScheduler::GetTypeId());
732  AddTestCase(new SimulatorEventsTestCase(factory), TestCase::QUICK);
733  }
734 };
735 
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:77
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:301
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:418
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:305
#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:1350
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
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 foo0()
Function used for scheduling.
static void ber2(int &, int &)
Function used for scheduling.