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 
28 using namespace ns3;
29 
31 {
32 public:
33  SimulatorEventsTestCase (ObjectFactory schedulerFactory);
34  virtual void DoRun (void);
35  void EventA (int a);
36  void EventB (int b);
37  void EventC (int c);
38  void EventD (int d);
39  void Eventfoo0 (void);
40  uint64_t NowUs (void);
41  void destroy (void);
42  bool m_b;
43  bool m_a;
44  bool m_c;
45  bool m_d;
47  bool m_destroy;
50 };
51 
53  : TestCase ("Check that basic event handling is working with " +
54  schedulerFactory.GetTypeId ().GetName ()),
55  m_schedulerFactory (schedulerFactory)
56 {}
57 uint64_t
59 {
60  uint64_t ns = Now ().GetNanoSeconds ();
61  return ns / 1000;
62 }
63 
64 void
66 {
67  NS_UNUSED (a);
68  m_a = false;
69 }
70 
71 void
73 {
74  if (b != 2 || NowUs () != 11)
75  {
76  m_b = false;
77  }
78  else
79  {
80  m_b = true;
81  }
82  Simulator::Remove (m_idC);
83  Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::EventD, this, 4);
84 }
85 
86 void
88 {
89  NS_UNUSED (c);
90  m_c = false;
91 }
92 
93 void
95 {
96  if (d != 4 || NowUs () != (11 + 10))
97  {
98  m_d = false;
99  }
100  else
101  {
102  m_d = true;
103  }
104 }
105 
106 void
108 {}
109 
110 void
112 {
113  if (m_destroyId.IsExpired ())
114  {
115  m_destroy = true;
116  }
117 }
118 void
120 {
121  m_a = true;
122  m_b = false;
123  m_c = true;
124  m_d = false;
125 
126  Simulator::SetScheduler (m_schedulerFactory);
127 
128  EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::EventA, this, 1);
129  Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::EventB, this, 2);
130  m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::EventC, this, 3);
131 
132  NS_TEST_EXPECT_MSG_EQ (!m_idC.IsExpired (), true, "");
133  NS_TEST_EXPECT_MSG_EQ (!a.IsExpired (), true, "");
134  Simulator::Cancel (a);
135  NS_TEST_EXPECT_MSG_EQ (a.IsExpired (), true, "");
136  Simulator::Run ();
137  NS_TEST_EXPECT_MSG_EQ (m_a, true, "Event A did not run ?");
138  NS_TEST_EXPECT_MSG_EQ (m_b, true, "Event B did not run ?");
139  NS_TEST_EXPECT_MSG_EQ (m_c, true, "Event C did not run ?");
140  NS_TEST_EXPECT_MSG_EQ (m_d, true, "Event D did not run ?");
141 
142  EventId anId = Simulator::ScheduleNow (&SimulatorEventsTestCase::Eventfoo0, this);
143  EventId anotherId = anId;
144  NS_TEST_EXPECT_MSG_EQ (!(anId.IsExpired () || anotherId.IsExpired ()), true, "Event should not have expired yet.");
145 
146  Simulator::Remove (anId);
147  NS_TEST_EXPECT_MSG_EQ (anId.IsExpired (), true, "Event was removed: it is now expired");
148  NS_TEST_EXPECT_MSG_EQ (anotherId.IsExpired (), true, "Event was removed: it is now expired");
149 
150  m_destroy = false;
151  m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
152  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
153  m_destroyId.Cancel ();
154  NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
155 
156  m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
157  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
158  Simulator::Remove (m_destroyId);
159  NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
160 
161  m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
162  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
163 
164  Simulator::Run ();
165  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
166  NS_TEST_EXPECT_MSG_EQ (!m_destroy, true, "Event should not have run");
167 
168  Simulator::Destroy ();
169  NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event should have expired now");
170  NS_TEST_EXPECT_MSG_EQ (m_destroy, true, "Event should have run");
171 }
172 
174 {
175 public:
177  // only here for testing of Ptr<>
178  void Ref (void) const
179  {}
180  void Unref (void) const
181  {}
182 
183 private:
184  virtual void DoRun (void);
185 
186  /* *NS_CHECK_STYLE_OFF* */
187  void bar0 (void) {}
188  void bar1 (int) {}
189  void bar2 (int, int) {}
190  void bar3 (int, int, int) {}
191  void bar4 (int, int, int, int) {}
192  void bar5 (int, int, int, int, int) {}
193  void baz1 (int &) {}
194  void baz2 (int &, int &) {}
195  void baz3 (int &, int &, int &) {}
196  void baz4 (int &, int &, int &, int &) {}
197  void baz5 (int &, int &, int &, int &, int &) {}
198  void cbaz1 (const int &) {}
199  void cbaz2 (const int &, const int &) {}
200  void cbaz3 (const int &, const int &, const int &) {}
201  void cbaz4 (const int &, const int &, const int &, const int &) {}
202  void cbaz5 (const int &, const int &, const int &, const int &, const int &) {}
203 
204  void bar0c (void) const {}
205  void bar1c (int) const {}
206  void bar2c (int, int) const {}
207  void bar3c (int, int, int) const {}
208  void bar4c (int, int, int, int) const {}
209  void bar5c (int, int, int, int, int) const {}
210  void baz1c (int &) const {}
211  void baz2c (int &, int &) const {}
212  void baz3c (int &, int &, int &) const {}
213  void baz4c (int &, int &, int &, int &) const {}
214  void baz5c (int &, int &, int &, int &, int &) const {}
215  void cbaz1c (const int &) const {}
216  void cbaz2c (const int &, const int &) const {}
217  void cbaz3c (const int &, const int &, const int &) const {}
218  void cbaz4c (const int &, const int &, const int &, const int &) const {}
219  void cbaz5c (const int &, const int &, const int &, const int &, const int &) const {}
220  /* *NS_CHECK_STYLE_ON* */
221 
222 };
223 
224 static void foo0 (void)
225 {}
226 static void foo1 (int)
227 {}
228 static void foo2 (int, int)
229 {}
230 static void foo3 (int, int, int)
231 {}
232 static void foo4 (int, int, int, int)
233 {}
234 static void foo5 (int, int, int, int, int)
235 {}
236 static void ber1 (int &)
237 {}
238 static void ber2 (int &, int &)
239 {}
240 static void ber3 (int &, int &, int &)
241 {}
242 static void ber4 (int &, int &, int &, int &)
243 {}
244 static void ber5 (int &, int &, int &, int &, int &)
245 {}
246 static void cber1 (const int &)
247 {}
248 static void cber2 (const int &, const int &)
249 {}
250 static void cber3 (const int &, const int &, const int &)
251 {}
252 static void cber4 (const int &, const int &, const int &, const int &)
253 {}
254 static void cber5 (const int &, const int &, const int &, const int &, const int &)
255 {}
256 
258  : TestCase ("Check that all templates are instantiated correctly. This is a compilation test, it cannot fail at runtime.")
259 {}
260 void
262 {
263  // Test schedule of const methods
264  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, this);
265  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, this, 0);
266  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, this, 0, 0);
267  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
268  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
269  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
270  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1c, this, 0);
271  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
272  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
273  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
274  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
275  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, this);
276  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, this, 0);
277  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
278  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
279  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
280  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
281  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1c, this, 0);
282  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
283  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
284  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
285  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
286  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, this);
287  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, this, 0);
288  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
289  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
290  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
291  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
292  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1c, this, 0);
293  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
294  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
295  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
296  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
297  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1c, this, 0);
298  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2c, this, 0, 0);
299  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
300  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
301  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
302  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1c, this, 0);
303  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
304  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
305  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
306  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
307  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1c, this, 0);
308  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
309  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
310  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
311  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
312 
313  // Test of schedule const methods with Ptr<> pointers
315  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
316  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
317  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
318  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
319  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
321  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
322  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
323  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
324  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
325  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
326  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
327  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
328  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
329  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
330  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
331  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
332 
333 
334  // Test schedule of raw functions
335  Simulator::Schedule (Seconds (0.0), &foo0);
336  Simulator::Schedule (Seconds (0.0), &foo1, 0);
337  Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
338  Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0);
339  Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0);
340  Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
341  Simulator::Schedule (Seconds (0.0), &cber1, 0);
342  Simulator::Schedule (Seconds (0.0), &cber2, 0, 0);
343  Simulator::Schedule (Seconds (0.0), &cber3, 0, 0, 0);
344  Simulator::Schedule (Seconds (0.0), &cber4, 0, 0, 0, 0);
345  Simulator::Schedule (Seconds (0.0), &cber5, 0, 0, 0, 0, 0);
346  Simulator::ScheduleNow (&foo0);
347  Simulator::ScheduleNow (&foo1, 0);
348  Simulator::ScheduleNow (&foo2, 0, 0);
349  Simulator::ScheduleNow (&foo3, 0, 0, 0);
350  Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
351  Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
352  Simulator::ScheduleNow (&cber1, 0);
353  Simulator::ScheduleNow (&cber2, 0, 0);
354  Simulator::ScheduleNow (&cber3, 0, 0, 0);
355  Simulator::ScheduleNow (&cber4, 0, 0, 0, 0);
356  Simulator::ScheduleNow (&cber5, 0, 0, 0, 0, 0);
357  Simulator::ScheduleDestroy (&foo0);
358  Simulator::ScheduleDestroy (&foo1, 0);
359  Simulator::ScheduleDestroy (&foo2, 0, 0);
360  Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
361  Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
362  Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
363  Simulator::ScheduleDestroy (&cber1, 0);
364  Simulator::ScheduleDestroy (&cber2, 0, 0);
365  Simulator::ScheduleDestroy (&cber3, 0, 0, 0);
366  Simulator::ScheduleDestroy (&cber4, 0, 0, 0, 0);
367  Simulator::ScheduleDestroy (&cber5, 0, 0, 0, 0, 0);
368 
369 
370  // Test schedule of normal member methods
371  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, this);
372  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, this, 0);
373  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, this, 0, 0);
374  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
375  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
376  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
377  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1, this, 0);
378  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2, this, 0, 0);
379  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
380  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
381  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
382  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, this);
383  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, this, 0);
384  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, this, 0, 0);
385  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
386  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
387  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
388  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1, this, 0);
389  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
390  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
391  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
392  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
393  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, this);
394  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, this, 0);
395  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, this, 0, 0);
396  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
397  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
398  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
399  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1, this, 0);
400  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
401  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
402  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
403  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
404 
405 
406  // test schedule of normal methods with Ptr<> pointers
407  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
408  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
409  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
410  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
411  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
412  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
413  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
414  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
415  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
416  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
417  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
418  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
419  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
420  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
421  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
422  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
423  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
424  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
425 
426 
427  // the code below does not compile, as expected.
428  //Simulator::Schedule (Seconds (0.0), &cber1, 0.0);
429 
430 
431  // This code appears to be duplicate test code.
432  Simulator::Schedule (Seconds (0.0), &ber1, 0);
433  Simulator::Schedule (Seconds (0.0), &ber2, 0, 0);
434  Simulator::Schedule (Seconds (0.0), &ber3, 0, 0, 0);
435  Simulator::Schedule (Seconds (0.0), &ber4, 0, 0, 0, 0);
436  Simulator::Schedule (Seconds (0.0), &ber5, 0, 0, 0, 0, 0);
437  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1, this, 0);
438  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2, this, 0, 0);
439  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
440  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
441  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
442  Simulator::ScheduleNow (&ber1, 0);
443  Simulator::ScheduleNow (&ber2, 0, 0);
444  Simulator::ScheduleNow (&ber3, 0, 0, 0);
445  Simulator::ScheduleNow (&ber4, 0, 0, 0, 0);
446  Simulator::ScheduleNow (&ber5, 0, 0, 0, 0, 0);
447  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1, this, 0);
448  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2, this, 0, 0);
449  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
450  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
451  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
452  Simulator::ScheduleDestroy (&ber1, 0);
453  Simulator::ScheduleDestroy (&ber2, 0, 0);
454  Simulator::ScheduleDestroy (&ber3, 0, 0, 0);
455  Simulator::ScheduleDestroy (&ber4, 0, 0, 0, 0);
456  Simulator::ScheduleDestroy (&ber5, 0, 0, 0, 0, 0);
457  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1, this, 0);
458  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2, this, 0, 0);
459  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
460  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
461  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
462 
463 
464  Simulator::Run ();
465  Simulator::Destroy ();
466 }
467 
469 {
470 public:
472  : TestSuite ("simulator")
473  {
474  ObjectFactory factory;
475  factory.SetTypeId (ListScheduler::GetTypeId ());
476 
477  AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
478  factory.SetTypeId (MapScheduler::GetTypeId ());
479  AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
480  factory.SetTypeId (HeapScheduler::GetTypeId ());
481  AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
482  factory.SetTypeId (CalendarScheduler::GetTypeId ());
483  AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
484  factory.SetTypeId (PriorityQueueScheduler::GetTypeId ());
485  AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
486  }
static void ber5(int &, int &, int &, int &, int &)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
static void cber4(const int &, const int &, const int &, const int &)
void bar4(int, int, int, int)
static void ber4(int &, int &, int &, int &)
void baz3(int &, int &, int &)
void baz5c(int &, int &, int &, int &, int &) const
static void foo5(int, int, int, int, int)
A suite of tests to run.
Definition: test.h:1343
static void cber5(const int &, const int &, const int &, const int &, const int &)
void baz5(int &, int &, int &, int &, int &)
void bar3c(int, int, int) const
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
#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:283
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
SimulatorEventsTestCase(ObjectFactory schedulerFactory)
encapsulates test code
Definition: test.h:1153
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:65
void cbaz5c(const int &, const int &, const int &, const int &, const int &) const
static void foo0(void)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void cbaz3c(const int &, const int &, const int &) const
void baz3c(int &, int &, int &) const
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
static void ber3(int &, int &, int &)
static void foo3(int, int, int)
void baz4c(int &, int &, int &, int &) const
void bar5c(int, int, int, int, int) const
void bar4c(int, int, int, int) const
void cbaz5(const int &, const int &, const int &, const int &, const int &)
static void foo1(int)
static void ber1(int &)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:391
void baz4(int &, int &, int &, int &)
virtual void DoRun(void)
Implementation to actually run this TestCase.
static void cber3(const int &, const int &, const int &)
void bar5(int, int, int, int, int)
SimulatorTestSuite g_simulatorTestSuite
Instantiate subclasses of ns3::Object.
void baz2c(int &, int &) const
static void cber1(const int &)
An identifier for simulation events.
Definition: event-id.h:53
void cbaz4(const int &, const int &, const int &, const int &)
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
static void ber2(int &, int &)
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
void cbaz1c(const int &) const
static void foo2(int, int)
static void cber2(const int &, const int &)
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1294
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
void cbaz2c(const int &, const int &) const
void cbaz3(const int &, const int &, const int &)
void cbaz2(const int &, const int &)
static void foo4(int, int, int, int)
void cbaz4c(const int &, const int &, const int &, const int &) const