20 #include "ns3/callback.h"
34 void Target1 (
void) { m_test1 =
true; }
35 int Target2 (
void) { m_test2 =
true;
return 2; }
36 void Target3 (
double a) { m_test3 =
true; }
37 int Target4 (
double a,
int b) { m_test4 =
true;
return 4; }
40 virtual void DoRun (
void);
41 virtual void DoSetup (
void);
49 static bool gBasicCallbackTest5;
50 static bool gBasicCallbackTest6;
51 static bool gBasicCallbackTest7;
54 BasicCallbackTarget5 (
void)
56 gBasicCallbackTest5 =
true;
60 BasicCallbackTarget6 (
int)
62 gBasicCallbackTest6 =
true;
66 BasicCallbackTarget7 (
int a)
68 gBasicCallbackTest7 =
true;
72 BasicCallbackTestCase::BasicCallbackTestCase ()
73 :
TestCase (
"Check basic Callback mechansim")
84 gBasicCallbackTest5 =
false;
85 gBasicCallbackTest6 =
false;
86 gBasicCallbackTest7 =
false;
98 NS_TEST_ASSERT_MSG_EQ (m_test1,
true,
"Callback did not fire");
105 target2 =
Callback<int> (
this, &BasicCallbackTestCase::Target2);
107 NS_TEST_ASSERT_MSG_EQ (m_test2,
true,
"Callback did not fire");
115 NS_TEST_ASSERT_MSG_EQ (m_test3,
true,
"Callback did not fire");
123 NS_TEST_ASSERT_MSG_EQ (m_test4,
true,
"Callback did not fire");
134 NS_TEST_ASSERT_MSG_EQ (gBasicCallbackTest5,
true,
"Callback did not fire");
143 NS_TEST_ASSERT_MSG_EQ (gBasicCallbackTest6,
true,
"Callback did not fire");
152 NS_TEST_ASSERT_MSG_EQ (gBasicCallbackTest7,
true,
"Callback did not fire");
164 void Target1 (
void) { m_test1 =
true; }
165 int Target2 (
void) { m_test2 =
true;
return 2; }
166 void Target3 (
double a) { m_test3 =
true; }
167 int Target4 (
double a,
int b) { m_test4 =
true;
return 4; }
170 virtual void DoRun (
void);
179 static bool gMakeCallbackTest5;
180 static bool gMakeCallbackTest6;
181 static bool gMakeCallbackTest7;
184 MakeCallbackTarget5 (
void)
186 gMakeCallbackTest5 =
true;
190 MakeCallbackTarget6 (
int)
192 gMakeCallbackTest6 =
true;
196 MakeCallbackTarget7 (
int a)
198 gMakeCallbackTest7 =
true;
202 MakeCallbackTestCase::MakeCallbackTestCase ()
203 :
TestCase (
"Check MakeCallback() mechanism")
214 gMakeCallbackTest5 =
false;
215 gMakeCallbackTest6 =
false;
216 gMakeCallbackTest7 =
false;
228 NS_TEST_ASSERT_MSG_EQ (m_test1,
true,
"Callback did not fire");
236 NS_TEST_ASSERT_MSG_EQ (m_test2,
true,
"Callback did not fire");
244 NS_TEST_ASSERT_MSG_EQ (m_test3,
true,
"Callback did not fire");
252 NS_TEST_ASSERT_MSG_EQ (m_test4,
true,
"Callback did not fire");
262 NS_TEST_ASSERT_MSG_EQ (gMakeCallbackTest5,
true,
"Callback did not fire");
272 NS_TEST_ASSERT_MSG_EQ (gMakeCallbackTest6,
true,
"Callback did not fire");
282 NS_TEST_ASSERT_MSG_EQ (gMakeCallbackTest7,
true,
"Callback did not fire");
295 virtual void DoRun (
void);
299 static int gMakeBoundCallbackTest1;
300 static bool *gMakeBoundCallbackTest2;
301 static bool *gMakeBoundCallbackTest3a;
302 static int gMakeBoundCallbackTest3b;
305 MakeBoundCallbackTarget1 (
int a)
307 gMakeBoundCallbackTest1 = a;
311 MakeBoundCallbackTarget2 (
bool *a)
313 gMakeBoundCallbackTest2 = a;
317 MakeBoundCallbackTarget3 (
bool *a,
int b)
319 gMakeBoundCallbackTest3a = a;
320 gMakeBoundCallbackTest3b = b;
324 MakeBoundCallbackTestCase::MakeBoundCallbackTestCase ()
325 :
TestCase (
"Check MakeBoundCallback() mechanism")
332 gMakeBoundCallbackTest1 = 0;
333 gMakeBoundCallbackTest2 = 0;
334 gMakeBoundCallbackTest3a = 0;
335 gMakeBoundCallbackTest3b = 0;
358 Callback<void> target1 = MakeBoundCallback (&MakeBoundCallbackTarget1, 1234);
360 NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest1, 1234,
"Callback did not fire or binding not correct");
366 Callback<void> target2 = MakeBoundCallback (&MakeBoundCallbackTarget2, &a);
368 NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest2, &a,
"Callback did not fire or binding not correct");
375 int result = target3 (2468);
376 NS_TEST_ASSERT_MSG_EQ (result, 1234,
"Return value of callback not correct");
377 NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest3a, &a,
"Callback did not fire or binding not correct");
378 NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest3b, 2468,
"Callback did not fire or argument not correct");
390 void Target1 (
void) { m_test1 =
true; }
393 virtual void DoRun (
void);
399 NullifyCallbackTestCase::NullifyCallbackTestCase ()
400 :
TestCase (
"Check Nullify() and IsNull()")
419 NS_TEST_ASSERT_MSG_EQ (m_test1,
true,
"Callback did not fire");
421 NS_TEST_ASSERT_MSG_EQ (target1.IsNull (),
false,
"Working Callback reports IsNull()");
425 NS_TEST_ASSERT_MSG_EQ (target1.IsNull (),
true,
"Nullified Callback reports not IsNull()");
438 void Target1 (
void) { m_test1 =
true; }
441 virtual void DoRun (
void);
446 void TestFZero (
void) {}
447 void TestFOne (
int) {}
448 void TestFTwo (
int,
int) {}
449 void TestFThree (
int,
int,
int) {}
450 void TestFFour (
int,
int,
int,
int) {}
451 void TestFFive (
int,
int,
int,
int,
int) {}
452 void TestFSix (
int,
int,
int,
int,
int,
int) {}
454 void TestFROne (
int &) {}
455 void TestFRTwo (
int &,
int &) {}
456 void TestFRThree (
int &,
int &,
int &) {}
457 void TestFRFour (
int &,
int &,
int &,
int &) {}
458 void TestFRFive (
int &,
int &,
int &,
int &,
int &) {}
459 void TestFRSix (
int &,
int &,
int &,
int &,
int &,
int &) {}
464 void PublicParent (
void) {}
466 void ProtectedParent (
void) {}
467 static void StaticProtectedParent (
void) {}
469 void PrivateParent (
void) {}
475 void TestZero (
void) {}
476 void TestOne (
int) {}
477 void TestTwo (
int,
int) {}
478 void TestThree (
int,
int,
int) {}
479 void TestFour (
int,
int,
int,
int) {}
480 void TestFive (
int,
int,
int,
int,
int) {}
481 void TestSix (
int,
int,
int,
int,
int,
int) {}
482 void TestCZero (
void)
const {}
483 void TestCOne (
int)
const {}
484 void TestCTwo (
int,
int)
const {}
485 void TestCThree (
int,
int,
int)
const {}
486 void TestCFour (
int,
int,
int,
int)
const {}
487 void TestCFive (
int,
int,
int,
int,
int)
const {}
488 void TestCSix (
int,
int,
int,
int,
int,
int)
const {}
490 void CheckParentalRights (
void)
492 MakeCallback (&CallbackTestParent::StaticProtectedParent);
494 MakeCallback (&CallbackTestClass::ProtectedParent,
this);
503 MakeCallbackTemplatesTestCase::MakeCallbackTemplatesTestCase ()
504 :
TestCase (
"Check various MakeCallback() template functions")
544 MakeBoundCallback (&TestFOne, 1);
545 MakeBoundCallback (&TestFTwo, 1);
546 MakeBoundCallback (&TestFThree, 1);
547 MakeBoundCallback (&TestFFour, 1);
548 MakeBoundCallback (&TestFFive, 1);
550 MakeBoundCallback (&TestFROne, 1);
551 MakeBoundCallback (&TestFRTwo, 1);
552 MakeBoundCallback (&TestFRThree, 1);
553 MakeBoundCallback (&TestFRFour, 1);
554 MakeBoundCallback (&TestFRFive, 1);
556 that.CheckParentalRights ();
568 CallbackTestSuite::CallbackTestSuite ()
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
virtual void DoSetup(void)
Implementation to do any local setup required for this test case.
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoSetup(void)
Implementation to do any local setup required for this test case.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoSetup(void)
Implementation to do any local setup required for this test case.
virtual void DoSetup(void)
Implementation to do any local setup required for this test case.
virtual void DoRun(void)
Implementation to actually run this test case.