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 
27 using namespace ns3;
28 
30 {
31 public:
32  SimulatorEventsTestCase (ObjectFactory schedulerFactory);
33  virtual void DoRun (void);
34  void EventA (int a);
35  void EventB (int b);
36  void EventC (int c);
37  void EventD (int d);
38  void Eventfoo0 (void);
39  uint64_t NowUs (void);
40  void destroy (void);
41  bool m_b;
42  bool m_a;
43  bool m_c;
44  bool m_d;
46  bool m_destroy;
49 };
50 
52  : TestCase ("Check that basic event handling is working with " +
53  schedulerFactory.GetTypeId ().GetName ()),
54  m_schedulerFactory (schedulerFactory)
55 {
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  void Unref (void) const {}
180 private:
181  virtual void DoRun (void);
182 
183  void bar0 (void) {}
184  void bar1 (int) {}
185  void bar2 (int, int) {}
186  void bar3 (int, int, int) {}
187  void bar4 (int, int, int, int) {}
188  void bar5 (int, int, int, int, int) {}
189  void baz1 (int &) {}
190  void baz2 (int &, int &) {}
191  void baz3 (int &, int &, int &) {}
192  void baz4 (int &, int &, int &, int &) {}
193  void baz5 (int &, int &, int &, int &, int &) {}
194  void cbaz1 (const int &) {}
195  void cbaz2 (const int &, const int &) {}
196  void cbaz3 (const int &, const int &, const int &) {}
197  void cbaz4 (const int &, const int &, const int &, const int &) {}
198  void cbaz5 (const int &, const int &, const int &, const int &, const int &) {}
199 
200  void bar0c (void) const {}
201  void bar1c (int) const {}
202  void bar2c (int, int) const {}
203  void bar3c (int, int, int) const {}
204  void bar4c (int, int, int, int) const {}
205  void bar5c (int, int, int, int, int) const {}
206  void baz1c (int &) const {}
207  void baz2c (int &, int &) const {}
208  void baz3c (int &, int &, int &) const {}
209  void baz4c (int &, int &, int &, int &) const {}
210  void baz5c (int &, int &, int &, int &, int &) const {}
211  void cbaz1c (const int &) const {}
212  void cbaz2c (const int &, const int &) const {}
213  void cbaz3c (const int &, const int &, const int &) const {}
214  void cbaz4c (const int &, const int &, const int &, const int &) const {}
215  void cbaz5c (const int &, const int &, const int &, const int &, const int &) const {}
216 
217 };
218 
219 static void foo0 (void)
220 {}
221 static void foo1 (int)
222 {}
223 static void foo2 (int, int)
224 {}
225 static void foo3 (int, int, int)
226 {}
227 static void foo4 (int, int, int, int)
228 {}
229 static void foo5 (int, int, int, int, int)
230 {}
231 static void ber1 (int &)
232 {}
233 static void ber2 (int &, int &)
234 {}
235 static void ber3 (int &, int &, int &)
236 {}
237 static void ber4 (int &, int &, int &, int &)
238 {}
239 static void ber5 (int &, int &, int &, int &, int &)
240 {}
241 static void cber1 (const int &)
242 {}
243 static void cber2 (const int &, const int &)
244 {}
245 static void cber3 (const int &, const int &, const int &)
246 {}
247 static void cber4 (const int &, const int &, const int &, const int &)
248 {}
249 static void cber5 (const int &, const int &, const int &, const int &, const int &)
250 {}
251 
253  : TestCase ("Check that all templates are instantiated correctly. This is a compilation test, it cannot fail at runtime.")
254 {
255 }
256 void
258 {
259  // Test schedule of const methods
260  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, this);
261  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, this, 0);
262  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, this, 0, 0);
263  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
264  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
265  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
266  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1c, this, 0);
267  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
268  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
269  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
270  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
271  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, this);
272  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, this, 0);
273  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
274  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
275  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
276  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
277  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1c, this, 0);
278  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
279  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
280  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
281  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
282  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, this);
283  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, this, 0);
284  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
285  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
286  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
287  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
288  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1c, this, 0);
289  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
290  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
291  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
292  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
293  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1c, this, 0);
294  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2c, this, 0, 0);
295  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
296  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
297  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
298  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1c, this, 0);
299  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
300  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
301  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
302  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
303  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1c, this, 0);
304  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
305  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
306  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
307  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
308 
309  // Test of schedule const methods with Ptr<> pointers
311  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
312  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
313  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
314  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
315  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
317  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
318  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
319  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
320  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
321  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
322  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
323  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
324  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
325  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
326  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
327  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
328 
329 
330  // Test schedule of raw functions
331  Simulator::Schedule (Seconds (0.0), &foo0);
332  Simulator::Schedule (Seconds (0.0), &foo1, 0);
333  Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
334  Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0);
335  Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0);
336  Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
337  Simulator::Schedule (Seconds (0.0), &cber1, 0);
338  Simulator::Schedule (Seconds (0.0), &cber2, 0, 0);
339  Simulator::Schedule (Seconds (0.0), &cber3, 0, 0, 0);
340  Simulator::Schedule (Seconds (0.0), &cber4, 0, 0, 0, 0);
341  Simulator::Schedule (Seconds (0.0), &cber5, 0, 0, 0, 0, 0);
342  Simulator::ScheduleNow (&foo0);
343  Simulator::ScheduleNow (&foo1, 0);
344  Simulator::ScheduleNow (&foo2, 0, 0);
345  Simulator::ScheduleNow (&foo3, 0, 0, 0);
346  Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
347  Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
348  Simulator::ScheduleNow (&cber1, 0);
349  Simulator::ScheduleNow (&cber2, 0, 0);
350  Simulator::ScheduleNow (&cber3, 0, 0, 0);
351  Simulator::ScheduleNow (&cber4, 0, 0, 0, 0);
352  Simulator::ScheduleNow (&cber5, 0, 0, 0, 0, 0);
353  Simulator::ScheduleDestroy (&foo0);
354  Simulator::ScheduleDestroy (&foo1, 0);
355  Simulator::ScheduleDestroy (&foo2, 0, 0);
356  Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
357  Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
358  Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
359  Simulator::ScheduleDestroy (&cber1, 0);
360  Simulator::ScheduleDestroy (&cber2, 0, 0);
361  Simulator::ScheduleDestroy (&cber3, 0, 0, 0);
362  Simulator::ScheduleDestroy (&cber4, 0, 0, 0, 0);
363  Simulator::ScheduleDestroy (&cber5, 0, 0, 0, 0, 0);
364 
365 
366  // Test schedule of normal member methods
367  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, this);
368  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, this, 0);
369  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, this, 0, 0);
370  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
371  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
372  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
373  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1, this, 0);
374  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2, this, 0, 0);
375  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
376  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
377  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
378  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, this);
379  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, this, 0);
380  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, this, 0, 0);
381  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
382  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
383  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
384  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1, this, 0);
385  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
386  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
387  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
388  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
389  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, this);
390  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, this, 0);
391  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, this, 0, 0);
392  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
393  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
394  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
395  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1, this, 0);
396  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
397  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
398  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
399  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
400 
401 
402  // test schedule of normal methods with Ptr<> pointers
403  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
404  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
405  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
406  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
407  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
408  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
409  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
410  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
411  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
412  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
413  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
414  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
415  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
416  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
417  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
418  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
419  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
420  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
421 
422 
423  // the code below does not compile, as expected.
424  //Simulator::Schedule (Seconds (0.0), &cber1, 0.0);
425 
426 
427  // This code appears to be duplicate test code.
428  Simulator::Schedule (Seconds (0.0), &ber1, 0);
429  Simulator::Schedule (Seconds (0.0), &ber2, 0, 0);
430  Simulator::Schedule (Seconds (0.0), &ber3, 0, 0, 0);
431  Simulator::Schedule (Seconds (0.0), &ber4, 0, 0, 0, 0);
432  Simulator::Schedule (Seconds (0.0), &ber5, 0, 0, 0, 0, 0);
433  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1, this, 0);
434  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2, this, 0, 0);
435  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
436  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
437  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
438  Simulator::ScheduleNow (&ber1, 0);
439  Simulator::ScheduleNow (&ber2, 0, 0);
440  Simulator::ScheduleNow (&ber3, 0, 0, 0);
441  Simulator::ScheduleNow (&ber4, 0, 0, 0, 0);
442  Simulator::ScheduleNow (&ber5, 0, 0, 0, 0, 0);
443  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1, this, 0);
444  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2, this, 0, 0);
445  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
446  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
447  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
448  Simulator::ScheduleDestroy (&ber1, 0);
449  Simulator::ScheduleDestroy (&ber2, 0, 0);
450  Simulator::ScheduleDestroy (&ber3, 0, 0, 0);
451  Simulator::ScheduleDestroy (&ber4, 0, 0, 0, 0);
452  Simulator::ScheduleDestroy (&ber5, 0, 0, 0, 0, 0);
453  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1, this, 0);
454  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2, this, 0, 0);
455  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
456  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
457  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
458 
459 
460  Simulator::Run ();
461  Simulator::Destroy ();
462 }
463 
465 {
466 public:
468  : TestSuite ("simulator")
469  {
470  ObjectFactory factory;
471  factory.SetTypeId (ListScheduler::GetTypeId ());
472 
473  AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
474  factory.SetTypeId (MapScheduler::GetTypeId ());
475  AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
476  factory.SetTypeId (HeapScheduler::GetTypeId ());
477  AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
478  factory.SetTypeId (CalendarScheduler::GetTypeId ());
479  AddTestCase (new SimulatorEventsTestCase (factory), TestCase::QUICK);
480  }
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:1342
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:285
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
SimulatorEventsTestCase(ObjectFactory schedulerFactory)
encapsulates test code
Definition: test.h:1155
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:59
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:367
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:1014
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:1030
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:365
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