View | Details | Raw Unified | Return to bug 2142
Collapse All | Expand All

(-)a/src/core/examples/sample-simulator.cc (-4 / +35 lines)
 Lines 33-38    Link Here 
33
33
34
using namespace ns3;
34
using namespace ns3;
35
35
36
/// Counter of successful events.
37
int g_Score = 0;
38
///
39
const int EXPECTED = 4;
40
41
void Score (bool cond, std::string where)
42
{
43
  if (cond)
44
    {
45
      ++g_Score;
46
      std::cout << " (+" << where << ")";
47
    }
48
  else
49
    {
50
      g_Score = -100;
51
      std::cout << " (" << where << ":FAIL)";
52
    }
53
}
54
36
/** Simple model object to illustrate event handling. */
55
/** Simple model object to illustrate event handling. */
37
class MyModel
56
class MyModel
38
{
57
{
 Lines 60-66    Link Here 
60
{
79
{
61
  std::cout << "Member method received event at "
80
  std::cout << "Member method received event at "
62
            << Simulator::Now ().GetSeconds ()
81
            << Simulator::Now ().GetSeconds ()
63
            << "s started at " << value << "s" << std::endl;
82
            << "s started at " << value << "s: ";
83
84
  Score (Simulator::Now() == Seconds(20), "now");
85
  Score (value == 10.0, "then");
86
  std::cout << std::endl;
64
}
87
}
65
88
66
/**
89
/**
 Lines 72-78    Link Here 
72
ExampleFunction (MyModel *model)
95
ExampleFunction (MyModel *model)
73
{
96
{
74
  std::cout << "ExampleFunction received event at "
97
  std::cout << "ExampleFunction received event at "
75
            << Simulator::Now ().GetSeconds () << "s" << std::endl;
98
            << Simulator::Now ().GetSeconds () << "s: ";
99
  Score (Simulator::Now() == Seconds(10), "now");
100
  std::cout << std::endl;
76
  model->Start ();
101
  model->Start ();
77
}
102
}
78
103
 Lines 83-96    Link Here 
83
RandomFunction (void)
108
RandomFunction (void)
84
{
109
{
85
  std::cout << "RandomFunction received event at "
110
  std::cout << "RandomFunction received event at "
86
            << Simulator::Now ().GetSeconds () << "s" << std::endl;
111
            << Simulator::Now ().GetSeconds () << "s: ";
112
  Score (true, "now");
113
  std::cout << std::endl;
87
}
114
}
88
115
89
/** Simple function event handler; the corresponding event is cancelled. */
116
/** Simple function event handler; the corresponding event is cancelled. */
90
static void
117
static void
91
CancelledEvent (void)
118
CancelledEvent (void)
92
{
119
{
93
  std::cout << "I should never be called... " << std::endl;
120
  std::cout << "I should never be called... ";
121
  Score (false, "never");
122
  std::cout << std::endl;
94
}
123
}
95
124
96
int main (int argc, char *argv[])
125
int main (int argc, char *argv[])
 Lines 113-116    Link Here 
113
  Simulator::Run ();
142
  Simulator::Run ();
114
143
115
  Simulator::Destroy ();
144
  Simulator::Destroy ();
145
146
  return (g_Score == EXPECTED ? 0 : 1);
116
}
147
}

Return to bug 2142