src/simulator/simulator.cc
author Guillaume Seguin <guillaume@segu.in>
Thu Nov 12 13:19:35 2009 +0100 (2009-11-12)
changeset 5507 915abd2b907b
parent 5493 8ffa53e9a701
child 5521 37c6c83d4252
permissions -rw-r--r--
Simulator::SetScheduler now takes an ObjectFactory
mathieu@150
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
mathieu@9
     2
/*
mathieu@9
     3
 * Copyright (c) 2005,2006 INRIA
mathieu@9
     4
 *
mathieu@9
     5
 * This program is free software; you can redistribute it and/or modify
mathieu@9
     6
 * it under the terms of the GNU General Public License version 2 as
mathieu@9
     7
 * published by the Free Software Foundation;
mathieu@9
     8
 *
mathieu@9
     9
 * This program is distributed in the hope that it will be useful,
mathieu@9
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mathieu@9
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
mathieu@9
    12
 * GNU General Public License for more details.
mathieu@9
    13
 *
mathieu@9
    14
 * You should have received a copy of the GNU General Public License
mathieu@9
    15
 * along with this program; if not, write to the Free Software
mathieu@9
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
mathieu@9
    17
 *
mathieu@9
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
mathieu@9
    19
 */
gjc@4091
    20
#include "ns3/core-config.h"
mathieu@9
    21
#include "simulator.h"
craigdo@3469
    22
#include "simulator-impl.h"
craigdo@3470
    23
#include "default-simulator-impl.h"
gjc@4091
    24
#ifdef HAVE_PTHREAD_H
gjc@4091
    25
# include "realtime-simulator-impl.h"
gjc@4091
    26
#endif
mathieu@9
    27
#include "scheduler.h"
guillaume@5507
    28
#include "map-scheduler.h"
mathieu@25
    29
#include "event-impl.h"
mathieu@9
    30
mathieu@1008
    31
#include "ns3/ptr.h"
craigdo@3470
    32
#include "ns3/string.h"
craigdo@3470
    33
#include "ns3/object-factory.h"
craigdo@3470
    34
#include "ns3/global-value.h"
raj@439
    35
#include "ns3/assert.h"
mathieu@2979
    36
#include "ns3/log.h"
raj@439
    37
mathieu@9
    38
#include <math.h>
mathieu@9
    39
#include <fstream>
mathieu@9
    40
#include <list>
mathieu@9
    41
#include <vector>
mathieu@9
    42
#include <iostream>
mathieu@9
    43
craigdo@3469
    44
NS_LOG_COMPONENT_DEFINE ("Simulator");
mathieu@9
    45
mathieu@16
    46
namespace ns3 {
mathieu@9
    47
craigdo@3470
    48
GlobalValue g_simTypeImpl = GlobalValue ("SimulatorImplementationType", 
craigdo@3470
    49
  "The object class to use as the simulator implementation",
craigdo@3470
    50
  StringValue ("ns3::DefaultSimulatorImpl"),
craigdo@3470
    51
  MakeStringChecker ());
craigdo@3470
    52
mathieu@4054
    53
GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType", 
mathieu@4054
    54
  "The object class to use as the scheduler implementation",
guillaume@5507
    55
  TypeIdValue (MapScheduler::GetTypeId ()),
guillaume@5507
    56
  MakeTypeIdChecker ());
mathieu@4054
    57
mathieu@4054
    58
mathieu@2981
    59
#ifdef NS3_LOG_ENABLE
craigdo@3470
    60
craigdo@3470
    61
//
craigdo@3470
    62
// Note:  Calls that take TimePrinter as a parameter are defined as nothing
craigdo@3470
    63
// in the logging module if NS3_LOG_ENABLE is not defined.
craigdo@3470
    64
// 
craigdo@3470
    65
mathieu@2979
    66
static void
mathieu@2979
    67
TimePrinter (std::ostream &os)
mathieu@2979
    68
{
mathieu@3920
    69
  os << Simulator::Now ().GetSeconds () << "s";
mathieu@2979
    70
}
craigdo@3470
    71
mathieu@2981
    72
#endif /* NS3_LOG_ENABLE */
mathieu@9
    73
mathieu@3809
    74
static Ptr<SimulatorImpl> *PeekImpl (void)
mathieu@9
    75
{
mathieu@3809
    76
  static Ptr<SimulatorImpl> impl = 0;
mathieu@3809
    77
  return &impl;
mathieu@3809
    78
}
mathieu@3809
    79
mathieu@3809
    80
static SimulatorImpl * GetImpl (void)
mathieu@3809
    81
{
mathieu@3809
    82
  Ptr<SimulatorImpl> &impl = *PeekImpl ();
mathieu@3503
    83
  /* Please, don't include any calls to logging macros in this function
mathieu@3503
    84
   * or pay the price, that is, stack explosions.
mathieu@3503
    85
   */
mathieu@3809
    86
  if (impl == 0) 
mathieu@150
    87
    {
mathieu@4054
    88
      {
mathieu@4054
    89
        ObjectFactory factory;
mathieu@4054
    90
        StringValue s;
mathieu@4054
    91
        
mathieu@4054
    92
        g_simTypeImpl.GetValue (s);
mathieu@4054
    93
        factory.SetTypeId (s.Get ());
mathieu@4054
    94
        impl = factory.Create<SimulatorImpl> ();
mathieu@4054
    95
      }
mathieu@4054
    96
      {
mathieu@4054
    97
        ObjectFactory factory;
mathieu@4054
    98
        StringValue s;
mathieu@4054
    99
        g_schedTypeImpl.GetValue (s);
mathieu@4054
   100
        factory.SetTypeId (s.Get ());
guillaume@5507
   101
        impl->SetScheduler (factory);
mathieu@4054
   102
      }
craigdo@3469
   103
craigdo@3470
   104
//
craigdo@3470
   105
// Note: we call LogSetTimePrinter _after_ creating the implementation
craigdo@3470
   106
// object because the act of creation can trigger calls to the logging 
craigdo@3470
   107
// framework which would call the TimePrinter function which would call 
craigdo@3470
   108
// Simulator::Now which would call Simulator::GetImpl, and, thus, get us 
craigdo@3470
   109
// in an infinite recursion until the stack explodes.
craigdo@3470
   110
//
mathieu@3005
   111
      LogSetTimePrinter (&TimePrinter);
mathieu@150
   112
    }
mathieu@3809
   113
  return PeekPointer (impl);
mathieu@9
   114
}
mathieu@9
   115
mathieu@9
   116
void
mathieu@122
   117
Simulator::Destroy (void)
mathieu@9
   118
{
craigdo@3469
   119
  NS_LOG_FUNCTION_NOARGS ();
craigdo@3469
   120
mathieu@3809
   121
  Ptr<SimulatorImpl> &impl = *PeekImpl (); 
mathieu@3809
   122
  if (impl == 0)
mathieu@2901
   123
    {
mathieu@2901
   124
      return;
mathieu@2901
   125
    }
craigdo@3469
   126
  /* Note: we have to call LogSetTimePrinter (0) below because if we do not do
craigdo@3469
   127
   * this, and restart a simulation after this call to Destroy, (which is 
craigdo@3469
   128
   * legal), Simulator::GetImpl will trigger again an infinite recursion until
craigdo@3469
   129
   * the stack explodes.
mathieu@3006
   130
   */
mathieu@3005
   131
  LogSetTimePrinter (0);
mathieu@3809
   132
  impl->Destroy ();
mathieu@3809
   133
  impl = 0;
mathieu@9
   134
}
mathieu@9
   135
craigdo@3469
   136
void
guillaume@5507
   137
Simulator::SetScheduler (ObjectFactory schedulerFactory)
craigdo@3469
   138
{
guillaume@5507
   139
  NS_LOG_FUNCTION (schedulerFactory);
guillaume@5507
   140
  GetImpl ()->SetScheduler (schedulerFactory);
craigdo@3469
   141
}
craigdo@3469
   142
mathieu@9
   143
bool 
mathieu@122
   144
Simulator::IsFinished (void)
mathieu@9
   145
{
craigdo@3469
   146
  NS_LOG_FUNCTION_NOARGS ();
craigdo@3469
   147
  return GetImpl ()->IsFinished ();
mathieu@9
   148
}
craigdo@3469
   149
mathieu@25
   150
Time
mathieu@122
   151
Simulator::Next (void)
mathieu@9
   152
{
craigdo@3469
   153
  NS_LOG_FUNCTION_NOARGS ();
craigdo@3469
   154
  return GetImpl ()->Next ();
mathieu@9
   155
}
mathieu@9
   156
mathieu@9
   157
void 
mathieu@122
   158
Simulator::Run (void)
mathieu@9
   159
{
craigdo@3469
   160
  NS_LOG_FUNCTION_NOARGS ();
craigdo@3469
   161
  GetImpl ()->Run ();
mathieu@9
   162
}
craigdo@3469
   163
mathieu@9
   164
void 
gjc@3515
   165
Simulator::RunOneEvent (void)
gjc@3515
   166
{
gjc@3515
   167
  NS_LOG_FUNCTION_NOARGS ();
gjc@3515
   168
  GetImpl ()->RunOneEvent ();
gjc@3515
   169
}
gjc@3515
   170
gjc@3515
   171
void 
mathieu@122
   172
Simulator::Stop (void)
mathieu@9
   173
{
craigdo@3469
   174
  NS_LOG_LOGIC ("stop");
craigdo@3469
   175
  GetImpl ()->Stop ();
mathieu@9
   176
}
craigdo@3469
   177
mathieu@9
   178
void 
gjc@3174
   179
Simulator::Stop (Time const &time)
mathieu@9
   180
{
craigdo@3469
   181
  NS_LOG_FUNCTION (time);
mathieu@4009
   182
  Simulator::Schedule (time, &Simulator::Stop);
mathieu@9
   183
}
craigdo@3469
   184
mathieu@25
   185
Time
mathieu@122
   186
Simulator::Now (void)
mathieu@9
   187
{
mathieu@3503
   188
  /* Please, don't include any calls to logging macros in this function
mathieu@3503
   189
   * or pay the price, that is, stack explosions.
mathieu@3503
   190
   */
craigdo@3469
   191
  return GetImpl ()->Now ();
mathieu@9
   192
}
craigdo@3469
   193
mathieu@1690
   194
Time
mathieu@1690
   195
Simulator::GetDelayLeft (const EventId &id)
mathieu@1690
   196
{
craigdo@3469
   197
  NS_LOG_FUNCTION (&id);
craigdo@3469
   198
  return GetImpl ()->GetDelayLeft (id);
mathieu@1690
   199
}
mathieu@9
   200
mathieu@146
   201
EventId
mathieu@1010
   202
Simulator::Schedule (Time const &time, const Ptr<EventImpl> &ev)
mathieu@146
   203
{
craigdo@3469
   204
  NS_LOG_FUNCTION (time << ev);
mathieu@3808
   205
  return DoSchedule (time, GetPointer (ev));
mathieu@146
   206
}
craigdo@3469
   207
mathieu@963
   208
EventId
mathieu@1010
   209
Simulator::ScheduleNow (const Ptr<EventImpl> &ev)
mathieu@146
   210
{
craigdo@3469
   211
  NS_LOG_FUNCTION (ev);
mathieu@3808
   212
  return DoScheduleNow (GetPointer (ev));
mathieu@146
   213
}
craigdo@3469
   214
mathieu@963
   215
EventId
mathieu@1010
   216
Simulator::ScheduleDestroy (const Ptr<EventImpl> &ev)
mathieu@146
   217
{
craigdo@3469
   218
  NS_LOG_FUNCTION (ev);
mathieu@3808
   219
  return DoScheduleDestroy (GetPointer (ev));
mathieu@3808
   220
}
mathieu@3808
   221
EventId 
mathieu@3808
   222
Simulator::DoSchedule (Time const &time, EventImpl *impl)
mathieu@3808
   223
{
mathieu@3808
   224
  return GetImpl ()->Schedule (time, impl);
mathieu@3808
   225
}
mathieu@3808
   226
EventId 
mathieu@3808
   227
Simulator::DoScheduleNow (EventImpl *impl)
mathieu@3808
   228
{
mathieu@3808
   229
  return GetImpl ()->ScheduleNow (impl);
mathieu@3808
   230
}
mathieu@3808
   231
EventId 
mathieu@3808
   232
Simulator::DoScheduleDestroy (EventImpl *impl)
mathieu@3808
   233
{
mathieu@3808
   234
  return GetImpl ()->ScheduleDestroy (impl);
mathieu@3808
   235
}
mathieu@3808
   236
craigdo@3469
   237
mathieu@146
   238
EventId
mathieu@146
   239
Simulator::Schedule (Time const &time, void (*f) (void))
mathieu@146
   240
{
craigdo@3469
   241
  NS_LOG_FUNCTION (time << f);
mathieu@3808
   242
  return DoSchedule (time, MakeEvent (f));
mathieu@146
   243
}
craigdo@3469
   244
mathieu@963
   245
EventId
mathieu@146
   246
Simulator::ScheduleNow (void (*f) (void))
mathieu@146
   247
{
craigdo@3469
   248
  NS_LOG_FUNCTION (f);
mathieu@3808
   249
  return DoScheduleNow (MakeEvent (f));
mathieu@146
   250
}
craigdo@3469
   251
mathieu@963
   252
EventId
mathieu@146
   253
Simulator::ScheduleDestroy (void (*f) (void))
mathieu@146
   254
{
craigdo@3469
   255
  NS_LOG_FUNCTION (f);
mathieu@3808
   256
  return DoScheduleDestroy (MakeEvent (f));
mathieu@75
   257
}
mathieu@75
   258
mathieu@25
   259
void
mathieu@1011
   260
Simulator::Remove (const EventId &ev)
mathieu@9
   261
{
craigdo@3469
   262
  NS_LOG_FUNCTION (&ev);
craigdo@3469
   263
  return GetImpl ()->Remove (ev);
mathieu@9
   264
}
mathieu@9
   265
mathieu@25
   266
void
mathieu@1011
   267
Simulator::Cancel (const EventId &ev)
mathieu@25
   268
{
craigdo@3469
   269
  NS_LOG_FUNCTION (&ev);
craigdo@3469
   270
  return GetImpl ()->Cancel (ev);
mathieu@25
   271
}
craigdo@3469
   272
mathieu@25
   273
bool 
mathieu@1011
   274
Simulator::IsExpired (const EventId &id)
mathieu@25
   275
{
craigdo@3469
   276
  NS_LOG_FUNCTION (&id);
craigdo@3469
   277
  return GetImpl ()->IsExpired (id);
mathieu@25
   278
}
mathieu@25
   279
mathieu@679
   280
Time Now (void)
mathieu@679
   281
{
craigdo@3469
   282
  NS_LOG_FUNCTION_NOARGS ();
mathieu@679
   283
  return Time (Simulator::Now ());
mathieu@679
   284
}
mathieu@679
   285
mathieu@1863
   286
Time 
mathieu@1863
   287
Simulator::GetMaximumSimulationTime (void)
mathieu@1863
   288
{
craigdo@3469
   289
  NS_LOG_FUNCTION_NOARGS ();
craigdo@3469
   290
  return GetImpl ()->GetMaximumSimulationTime ();
mathieu@1863
   291
}
mathieu@1863
   292
gjc@3479
   293
void
gjc@3479
   294
Simulator::SetImplementation (Ptr<SimulatorImpl> impl)
gjc@3479
   295
{
guillaume@4601
   296
  if (*PeekImpl () != 0)
mathieu@4510
   297
    {
mathieu@4510
   298
      NS_FATAL_ERROR ("It is not possible to set the implementation after calling any Simulator:: function. Call Simulator::SetImplementation earlier or after Simulator::Destroy.");
mathieu@4510
   299
    }
mathieu@4510
   300
  *PeekImpl () = impl;
guillaume@5493
   301
  // Set the default scheduler
guillaume@5493
   302
  ObjectFactory factory;
guillaume@5493
   303
  StringValue s;
guillaume@5493
   304
  g_schedTypeImpl.GetValue (s);
guillaume@5493
   305
  factory.SetTypeId (s.Get ());
guillaume@5507
   306
  impl->SetScheduler (factory);
mathieu@4510
   307
//
mathieu@4510
   308
// Note: we call LogSetTimePrinter _after_ creating the implementation
mathieu@4510
   309
// object because the act of creation can trigger calls to the logging 
mathieu@4510
   310
// framework which would call the TimePrinter function which would call 
mathieu@4510
   311
// Simulator::Now which would call Simulator::GetImpl, and, thus, get us 
mathieu@4510
   312
// in an infinite recursion until the stack explodes.
mathieu@4510
   313
//
mathieu@4510
   314
  LogSetTimePrinter (&TimePrinter);
gjc@3479
   315
}
mathieu@3816
   316
Ptr<SimulatorImpl>
mathieu@3816
   317
Simulator::GetImplementation (void)
craigdo@3801
   318
{
mathieu@3816
   319
  return GetImpl ();
craigdo@3801
   320
}
craigdo@3801
   321
craigdo@3801
   322
gjc@3479
   323
mathieu@1863
   324
} // namespace ns3
mathieu@9
   325
mathieu@30
   326
#include "ns3/test.h"
mathieu@2913
   327
#include "list-scheduler.h"
mathieu@2913
   328
#include "heap-scheduler.h"
mathieu@4054
   329
#include "map-scheduler.h"
mathieu@4095
   330
#include "calendar-scheduler.h"
mathieu@4095
   331
#include "ns2-calendar-scheduler.h"
mathieu@24
   332
mathieu@30
   333
namespace ns3 {
mathieu@30
   334
mathieu@5301
   335
class SimulatorEventsTestCase : public TestCase
mathieu@5301
   336
{
mathieu@5301
   337
public:
guillaume@5507
   338
  SimulatorEventsTestCase (ObjectFactory schedulerFactory);
mathieu@5301
   339
  virtual bool DoRun (void);
mathieu@5301
   340
  void A (int a);
mathieu@5301
   341
  void B (int b);
mathieu@5301
   342
  void C (int c);
mathieu@5301
   343
  void D (int d);
mathieu@5301
   344
  void foo0 (void);
mathieu@5301
   345
  uint64_t NowUs (void);
mathieu@5301
   346
  void destroy(void);
mathieu@5301
   347
  bool m_b;
mathieu@5301
   348
  bool m_a;
mathieu@5301
   349
  bool m_c;
mathieu@5301
   350
  bool m_d;
mathieu@5301
   351
  EventId m_idC;
mathieu@5301
   352
  bool m_destroy;
mathieu@5301
   353
  EventId m_destroyId;
guillaume@5507
   354
  ObjectFactory m_schedulerFactory;
mathieu@5301
   355
};
mathieu@5301
   356
guillaume@5507
   357
SimulatorEventsTestCase::SimulatorEventsTestCase (ObjectFactory schedulerFactory)
guillaume@5507
   358
  : TestCase ("Check that basic event handling is working with " + 
guillaume@5507
   359
              schedulerFactory.GetTypeId ().GetName ()),
guillaume@5507
   360
    m_schedulerFactory (schedulerFactory)
mathieu@5301
   361
{}
mathieu@5301
   362
uint64_t
mathieu@5301
   363
SimulatorEventsTestCase::NowUs (void)
mathieu@5301
   364
{
mathieu@5301
   365
  uint64_t ns = Now ().GetNanoSeconds ();
mathieu@5301
   366
  return ns / 1000;
mathieu@5301
   367
}  
mathieu@5301
   368
mathieu@5301
   369
void
mathieu@5301
   370
SimulatorEventsTestCase::A (int a)
mathieu@5301
   371
{
mathieu@5301
   372
  m_a = false;
mathieu@5301
   373
}
mathieu@5301
   374
mathieu@5301
   375
void
mathieu@5301
   376
SimulatorEventsTestCase::B (int b)
mathieu@5301
   377
{
mathieu@5301
   378
  if (b != 2 || NowUs () != 11) 
mathieu@5301
   379
    {
mathieu@5301
   380
      m_b = false;
mathieu@5301
   381
    } 
mathieu@5301
   382
  else 
mathieu@5301
   383
    {
mathieu@5301
   384
      m_b = true;
mathieu@5301
   385
    }
mathieu@5301
   386
  Simulator::Remove (m_idC);
mathieu@5301
   387
  Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::D, this, 4);
mathieu@5301
   388
}
mathieu@5301
   389
mathieu@5301
   390
void
mathieu@5301
   391
SimulatorEventsTestCase::C (int c)
mathieu@5301
   392
{
mathieu@5301
   393
  m_c = false;
mathieu@5301
   394
}
mathieu@5301
   395
mathieu@5301
   396
void
mathieu@5301
   397
SimulatorEventsTestCase::D (int d)
mathieu@5301
   398
{
mathieu@5301
   399
  if (d != 4 || NowUs () != (11+10)) 
mathieu@5301
   400
    {
mathieu@5301
   401
      m_d = false;
mathieu@5301
   402
    } 
mathieu@5301
   403
  else 
mathieu@5301
   404
    {
mathieu@5301
   405
      m_d = true;
mathieu@5301
   406
    }
mathieu@5301
   407
}
mathieu@5301
   408
mathieu@5301
   409
void
mathieu@5301
   410
SimulatorEventsTestCase::foo0(void)
mathieu@5301
   411
{}
mathieu@5301
   412
mathieu@5301
   413
void
mathieu@5301
   414
SimulatorEventsTestCase::destroy (void)
mathieu@5301
   415
{
mathieu@5301
   416
  if (m_destroyId.IsExpired ())
mathieu@5301
   417
    {
mathieu@5301
   418
      m_destroy = true; 
mathieu@5301
   419
    }
mathieu@5301
   420
}
mathieu@5301
   421
bool 
mathieu@5301
   422
SimulatorEventsTestCase::DoRun (void)
mathieu@5301
   423
{
mathieu@5301
   424
  m_a = true;
mathieu@5301
   425
  m_b = false;
mathieu@5301
   426
  m_c = true;
mathieu@5301
   427
  m_d = false;
mathieu@5301
   428
guillaume@5507
   429
  Simulator::SetScheduler (m_schedulerFactory);
guillaume@5507
   430
mathieu@5301
   431
  EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::A, this, 1);
mathieu@5301
   432
  Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::B, this, 2);
mathieu@5301
   433
  m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::C, this, 3);
mathieu@5301
   434
mathieu@5301
   435
  NS_TEST_EXPECT_MSG_EQ (!m_idC.IsExpired (), true, "");
mathieu@5301
   436
  NS_TEST_EXPECT_MSG_EQ (!a.IsExpired (), true, "");
mathieu@5301
   437
  Simulator::Cancel (a);
mathieu@5301
   438
  NS_TEST_EXPECT_MSG_EQ (a.IsExpired (), true, "");
mathieu@5301
   439
  Simulator::Run ();
mathieu@5301
   440
  NS_TEST_EXPECT_MSG_EQ (m_a, true, "Event A did not run ?");
mathieu@5301
   441
  NS_TEST_EXPECT_MSG_EQ (m_b, true, "Event B did not run ?");
mathieu@5301
   442
  NS_TEST_EXPECT_MSG_EQ (m_c, true, "Event C did not run ?");
mathieu@5301
   443
  NS_TEST_EXPECT_MSG_EQ (m_d, true, "Event D did not run ?");
mathieu@5301
   444
mathieu@5301
   445
  EventId anId = Simulator::ScheduleNow (&SimulatorEventsTestCase::foo0, this);
mathieu@5301
   446
  EventId anotherId = anId;
mathieu@5301
   447
  NS_TEST_EXPECT_MSG_EQ (!(anId.IsExpired () || anotherId.IsExpired ()), true, "Event should not have expired yet.");
mathieu@5301
   448
mathieu@5301
   449
  Simulator::Remove (anId);
mathieu@5301
   450
  NS_TEST_EXPECT_MSG_EQ (anId.IsExpired (), true, "Event was removed: it is now expired");
mathieu@5301
   451
  NS_TEST_EXPECT_MSG_EQ (anotherId.IsExpired (), true, "Event was removed: it is now expired");
mathieu@5301
   452
mathieu@5301
   453
  m_destroy = false;
mathieu@5301
   454
  m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
mathieu@5301
   455
  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
mathieu@5301
   456
  m_destroyId.Cancel ();
mathieu@5301
   457
  NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
mathieu@5301
   458
mathieu@5301
   459
  m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
mathieu@5301
   460
  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
mathieu@5301
   461
  Simulator::Remove (m_destroyId);
mathieu@5301
   462
  NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
mathieu@5301
   463
mathieu@5301
   464
  m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
mathieu@5301
   465
  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
mathieu@5301
   466
mathieu@5301
   467
  Simulator::Run ();
mathieu@5301
   468
  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
mathieu@5301
   469
  NS_TEST_EXPECT_MSG_EQ (!m_destroy, true, "Event should not have run");
mathieu@5301
   470
mathieu@5301
   471
  Simulator::Destroy ();
mathieu@5301
   472
  NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event should have expired now");
mathieu@5301
   473
  NS_TEST_EXPECT_MSG_EQ (m_destroy, true, "Event should have run");
mathieu@5301
   474
mathieu@5301
   475
  return false;
mathieu@5301
   476
}
mathieu@5301
   477
mathieu@5301
   478
class SimulatorTemplateTestCase : public TestCase
mathieu@5301
   479
{
mathieu@5301
   480
public:
mathieu@5301
   481
  SimulatorTemplateTestCase ();
mathieu@5301
   482
  // only here for testing of Ptr<>
mathieu@5301
   483
  void Ref (void) const {}
mathieu@5301
   484
  void Unref (void) const {}
mathieu@5301
   485
private:
mathieu@5301
   486
  virtual bool DoRun (void);
mathieu@5301
   487
mathieu@5301
   488
  void bar0 (void) {}
mathieu@5301
   489
  void bar1 (int) {}
mathieu@5301
   490
  void bar2 (int, int) {}
mathieu@5301
   491
  void bar3 (int, int, int) {}
mathieu@5301
   492
  void bar4 (int, int, int, int) {}
mathieu@5301
   493
  void bar5 (int, int, int, int, int) {}
mathieu@5301
   494
  void baz1 (int &) {}
mathieu@5301
   495
  void baz2 (int &, int &) {}
mathieu@5301
   496
  void baz3 (int &, int &, int &) {}
mathieu@5301
   497
  void baz4 (int &, int &, int &, int &) {}
mathieu@5301
   498
  void baz5 (int &, int &, int &, int &, int &) {}
mathieu@5301
   499
  void cbaz1 (const int &) {}
mathieu@5301
   500
  void cbaz2 (const int &, const int &) {}
mathieu@5301
   501
  void cbaz3 (const int &, const int &, const int &) {}
mathieu@5301
   502
  void cbaz4 (const int &, const int &, const int &, const int &) {}
mathieu@5301
   503
  void cbaz5 (const int &, const int &, const int &, const int &, const int &) {}
mathieu@5301
   504
mathieu@5301
   505
  void bar0c (void) const {}
mathieu@5301
   506
  void bar1c (int) const {}
mathieu@5301
   507
  void bar2c (int, int) const {}
mathieu@5301
   508
  void bar3c (int, int, int) const {}
mathieu@5301
   509
  void bar4c (int, int, int, int) const {}
mathieu@5301
   510
  void bar5c (int, int, int, int, int) const {}
mathieu@5301
   511
  void baz1c (int &) const {}
mathieu@5301
   512
  void baz2c (int &, int &) const {}
mathieu@5301
   513
  void baz3c (int &, int &, int &) const {}
mathieu@5301
   514
  void baz4c (int &, int &, int &, int &) const {}
mathieu@5301
   515
  void baz5c (int &, int &, int &, int &, int &) const {}
mathieu@5301
   516
  void cbaz1c (const int &) const {}
mathieu@5301
   517
  void cbaz2c (const int &, const int &) const {}
mathieu@5301
   518
  void cbaz3c (const int &, const int &, const int &) const {}
mathieu@5301
   519
  void cbaz4c (const int &, const int &, const int &, const int &) const {}
mathieu@5301
   520
  void cbaz5c (const int &, const int &, const int &, const int &, const int &) const {}
mathieu@5301
   521
mathieu@5301
   522
};
mathieu@5301
   523
mathieu@146
   524
static void foo0 (void)
mathieu@146
   525
{}
mathieu@146
   526
static void foo1 (int)
mathieu@146
   527
{}
mathieu@146
   528
static void foo2 (int, int)
mathieu@146
   529
{}
mathieu@146
   530
static void foo3 (int, int, int)
mathieu@146
   531
{}
mathieu@146
   532
static void foo4 (int, int, int, int)
mathieu@146
   533
{}
mathieu@146
   534
static void foo5 (int, int, int, int, int)
mathieu@945
   535
{}
mathieu@945
   536
static void ber1 (int &)
mathieu@945
   537
{}
mathieu@945
   538
static void ber2 (int &, int &)
mathieu@945
   539
{}
mathieu@945
   540
static void ber3 (int &, int &, int &)
mathieu@945
   541
{}
mathieu@945
   542
static void ber4 (int &, int &, int &, int &)
mathieu@945
   543
{}
mathieu@945
   544
static void ber5 (int &, int &, int &, int &, int &)
mathieu@945
   545
{}
mathieu@948
   546
static void cber1 (const int &)
mathieu@948
   547
{}
mathieu@948
   548
static void cber2 (const int &, const int &)
mathieu@948
   549
{}
mathieu@948
   550
static void cber3 (const int &, const int &, const int &)
mathieu@948
   551
{}
mathieu@948
   552
static void cber4 (const int &, const int &, const int &, const int &)
mathieu@948
   553
{}
mathieu@948
   554
static void cber5 (const int &, const int &, const int &, const int &, const int &)
mathieu@948
   555
{}
mathieu@146
   556
mathieu@5301
   557
SimulatorTemplateTestCase::SimulatorTemplateTestCase ()
mathieu@5301
   558
  : TestCase ("Check that all templates are instanciated correctly. This is a compilation test, it cannot fail at runtime.")
mathieu@5301
   559
{}
mathieu@5301
   560
bool 
mathieu@5301
   561
SimulatorTemplateTestCase::DoRun (void)
mathieu@2630
   562
{
mathieu@5301
   563
  // Test schedule of const methods
mathieu@5301
   564
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, this);
mathieu@5301
   565
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, this, 0);
mathieu@5301
   566
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, this, 0, 0);
mathieu@5301
   567
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
mathieu@5301
   568
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
mathieu@5301
   569
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
mathieu@5301
   570
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1c, this, 0);
mathieu@5301
   571
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
mathieu@5301
   572
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
mathieu@5301
   573
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
mathieu@5301
   574
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
mathieu@5301
   575
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, this);
mathieu@5301
   576
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, this, 0);
mathieu@5301
   577
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
mathieu@5301
   578
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
mathieu@5301
   579
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
mathieu@5301
   580
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
mathieu@5301
   581
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1c, this, 0);
mathieu@5301
   582
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
mathieu@5301
   583
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
mathieu@5301
   584
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
mathieu@5301
   585
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
mathieu@5301
   586
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, this);
mathieu@5301
   587
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, this, 0);
mathieu@5301
   588
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
mathieu@5301
   589
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
mathieu@5301
   590
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
mathieu@5301
   591
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
mathieu@5301
   592
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1c, this, 0);
mathieu@5301
   593
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
mathieu@5301
   594
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
mathieu@5301
   595
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
mathieu@5301
   596
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
mathieu@5301
   597
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1c, this, 0);
mathieu@5301
   598
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2c, this, 0, 0);
mathieu@5301
   599
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
mathieu@5301
   600
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
mathieu@5301
   601
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
mathieu@5301
   602
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1c, this, 0);
mathieu@5301
   603
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
mathieu@5301
   604
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
mathieu@5301
   605
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
mathieu@5301
   606
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
mathieu@5301
   607
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1c, this, 0);
mathieu@5301
   608
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
mathieu@5301
   609
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
mathieu@5301
   610
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
mathieu@5301
   611
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
mathieu@1294
   612
mathieu@5301
   613
  // Test of schedule const methods with Ptr<> pointers
mathieu@5301
   614
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
mathieu@5301
   615
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
mathieu@5301
   616
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
mathieu@5301
   617
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
mathieu@5301
   618
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
mathieu@5301
   619
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
mathieu@5301
   620
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
mathieu@5301
   621
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
mathieu@5301
   622
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
mathieu@5301
   623
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
mathieu@5301
   624
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
mathieu@5301
   625
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
mathieu@5301
   626
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
mathieu@5301
   627
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
mathieu@5301
   628
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
mathieu@5301
   629
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
mathieu@5301
   630
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
mathieu@5301
   631
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
mathieu@1294
   632
mathieu@30
   633
mathieu@5301
   634
  // Test schedule of raw functions
mathieu@150
   635
  Simulator::Schedule (Seconds (0.0), &foo0);
mathieu@150
   636
  Simulator::Schedule (Seconds (0.0), &foo1, 0);
mathieu@150
   637
  Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
mathieu@150
   638
  Simulator::Schedule (Seconds (0.0), &foo3, 0, 0, 0);
mathieu@150
   639
  Simulator::Schedule (Seconds (0.0), &foo4, 0, 0, 0, 0);
mathieu@150
   640
  Simulator::Schedule (Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
mathieu@948
   641
  Simulator::Schedule (Seconds (0.0), &cber1, 0);
mathieu@948
   642
  Simulator::Schedule (Seconds (0.0), &cber2, 0, 0);
mathieu@948
   643
  Simulator::Schedule (Seconds (0.0), &cber3, 0, 0, 0);
mathieu@948
   644
  Simulator::Schedule (Seconds (0.0), &cber4, 0, 0, 0, 0);
mathieu@948
   645
  Simulator::Schedule (Seconds (0.0), &cber5, 0, 0, 0, 0, 0);
mathieu@150
   646
  Simulator::ScheduleNow (&foo0);
mathieu@150
   647
  Simulator::ScheduleNow (&foo1, 0);
mathieu@150
   648
  Simulator::ScheduleNow (&foo2, 0, 0);
mathieu@150
   649
  Simulator::ScheduleNow (&foo3, 0, 0, 0);
mathieu@150
   650
  Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
mathieu@150
   651
  Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
mathieu@948
   652
  Simulator::ScheduleNow (&cber1, 0);
mathieu@948
   653
  Simulator::ScheduleNow (&cber2, 0, 0);
mathieu@948
   654
  Simulator::ScheduleNow (&cber3, 0, 0, 0);
mathieu@948
   655
  Simulator::ScheduleNow (&cber4, 0, 0, 0, 0);
mathieu@948
   656
  Simulator::ScheduleNow (&cber5, 0, 0, 0, 0, 0);
mathieu@150
   657
  Simulator::ScheduleDestroy (&foo0);
mathieu@150
   658
  Simulator::ScheduleDestroy (&foo1, 0);
mathieu@150
   659
  Simulator::ScheduleDestroy (&foo2, 0, 0);
mathieu@150
   660
  Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
mathieu@150
   661
  Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
mathieu@150
   662
  Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
mathieu@948
   663
  Simulator::ScheduleDestroy (&cber1, 0);
mathieu@948
   664
  Simulator::ScheduleDestroy (&cber2, 0, 0);
mathieu@948
   665
  Simulator::ScheduleDestroy (&cber3, 0, 0, 0);
mathieu@948
   666
  Simulator::ScheduleDestroy (&cber4, 0, 0, 0, 0);
mathieu@948
   667
  Simulator::ScheduleDestroy (&cber5, 0, 0, 0, 0, 0);
mathieu@5301
   668
mathieu@5301
   669
mathieu@5301
   670
  // Test schedule of normal member methods
mathieu@5301
   671
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, this);
mathieu@5301
   672
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, this, 0);
mathieu@5301
   673
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, this, 0, 0);
mathieu@5301
   674
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
mathieu@5301
   675
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
mathieu@5301
   676
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
mathieu@5301
   677
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1, this, 0);
mathieu@5301
   678
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2, this, 0, 0);
mathieu@5301
   679
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
mathieu@5301
   680
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
mathieu@5301
   681
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
mathieu@5301
   682
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, this);
mathieu@5301
   683
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, this, 0);
mathieu@5301
   684
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, this, 0, 0);
mathieu@5301
   685
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
mathieu@5301
   686
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
mathieu@5301
   687
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
mathieu@5301
   688
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1, this, 0);
mathieu@5301
   689
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
mathieu@5301
   690
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
mathieu@5301
   691
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
mathieu@5301
   692
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
mathieu@5301
   693
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, this);
mathieu@5301
   694
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, this, 0);
mathieu@5301
   695
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, this, 0, 0);
mathieu@5301
   696
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
mathieu@5301
   697
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
mathieu@5301
   698
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
mathieu@5301
   699
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1, this, 0);
mathieu@5301
   700
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
mathieu@5301
   701
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
mathieu@5301
   702
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
mathieu@5301
   703
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
mathieu@5301
   704
mathieu@5301
   705
mathieu@5301
   706
  // test schedule of normal methods with Ptr<> pointers
mathieu@5301
   707
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
mathieu@5301
   708
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
mathieu@5301
   709
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
mathieu@5301
   710
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
mathieu@5301
   711
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
mathieu@5301
   712
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
mathieu@5301
   713
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
mathieu@5301
   714
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
mathieu@5301
   715
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
mathieu@5301
   716
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
mathieu@5301
   717
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
mathieu@5301
   718
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
mathieu@5301
   719
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
mathieu@5301
   720
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
mathieu@5301
   721
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
mathieu@5301
   722
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
mathieu@5301
   723
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
mathieu@5301
   724
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
mathieu@181
   725
mathieu@948
   726
mathieu@948
   727
  // the code below does not compile, as expected.
mathieu@948
   728
  //Simulator::Schedule (Seconds (0.0), &cber1, 0.0);
mathieu@948
   729
mathieu@5301
   730
mathieu@5301
   731
  // This code appears to be duplicate test code.
mathieu@948
   732
  Simulator::Schedule (Seconds (0.0), &ber1, 0);
mathieu@948
   733
  Simulator::Schedule (Seconds (0.0), &ber2, 0, 0);
mathieu@948
   734
  Simulator::Schedule (Seconds (0.0), &ber3, 0, 0, 0);
mathieu@948
   735
  Simulator::Schedule (Seconds (0.0), &ber4, 0, 0, 0, 0);
mathieu@948
   736
  Simulator::Schedule (Seconds (0.0), &ber5, 0, 0, 0, 0, 0);
mathieu@5301
   737
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1, this, 0);
mathieu@5301
   738
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2, this, 0, 0);
mathieu@5301
   739
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
mathieu@5301
   740
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
mathieu@5301
   741
  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
mathieu@948
   742
  Simulator::ScheduleNow (&ber1, 0);
mathieu@948
   743
  Simulator::ScheduleNow (&ber2, 0, 0);
mathieu@948
   744
  Simulator::ScheduleNow (&ber3, 0, 0, 0);
mathieu@948
   745
  Simulator::ScheduleNow (&ber4, 0, 0, 0, 0);
mathieu@948
   746
  Simulator::ScheduleNow (&ber5, 0, 0, 0, 0, 0);
mathieu@5301
   747
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1, this, 0);
mathieu@5301
   748
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2, this, 0, 0);
mathieu@5301
   749
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
mathieu@5301
   750
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
mathieu@5301
   751
  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
mathieu@948
   752
  Simulator::ScheduleDestroy (&ber1, 0);
mathieu@948
   753
  Simulator::ScheduleDestroy (&ber2, 0, 0);
mathieu@948
   754
  Simulator::ScheduleDestroy (&ber3, 0, 0, 0);
mathieu@948
   755
  Simulator::ScheduleDestroy (&ber4, 0, 0, 0, 0);
mathieu@948
   756
  Simulator::ScheduleDestroy (&ber5, 0, 0, 0, 0, 0);
mathieu@5301
   757
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1, this, 0);
mathieu@5301
   758
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2, this, 0, 0);
mathieu@5301
   759
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
mathieu@5301
   760
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
mathieu@5301
   761
  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
mathieu@948
   762
mathieu@1008
   763
mathieu@1008
   764
  Simulator::Run ();
mathieu@1008
   765
  Simulator::Destroy ();
mathieu@2357
   766
mathieu@5301
   767
  return false;
mathieu@30
   768
}
mathieu@30
   769
mathieu@5301
   770
class SimulatorTestSuite : public TestSuite
mathieu@5301
   771
{
mathieu@5301
   772
public:
mathieu@5301
   773
  SimulatorTestSuite ()
mathieu@5301
   774
    : TestSuite ("simulator")
mathieu@5301
   775
  {
guillaume@5507
   776
    ObjectFactory factory;
guillaume@5507
   777
    factory.SetTypeId (ListScheduler::GetTypeId ());
guillaume@5507
   778
guillaume@5507
   779
    AddTestCase (new SimulatorEventsTestCase (factory));
guillaume@5507
   780
    factory.SetTypeId (MapScheduler::GetTypeId ());
guillaume@5507
   781
    AddTestCase (new SimulatorEventsTestCase (factory));
guillaume@5507
   782
    factory.SetTypeId (HeapScheduler::GetTypeId ());
guillaume@5507
   783
    AddTestCase (new SimulatorEventsTestCase (factory));
guillaume@5507
   784
    factory.SetTypeId (CalendarScheduler::GetTypeId ());
guillaume@5507
   785
    AddTestCase (new SimulatorEventsTestCase (factory));
guillaume@5507
   786
    factory.SetTypeId (Ns2CalendarScheduler::GetTypeId ());
guillaume@5507
   787
    AddTestCase (new SimulatorEventsTestCase (factory));
mathieu@5301
   788
  }
mathieu@5301
   789
} g_simulatorTestSuite;
mathieu@30
   790
mathieu@5301
   791
} // namespace ns3