A Discrete-Event Network Simulator
API
callback-test-suite.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17 
18 #include "ns3/callback.h"
19 #include "ns3/test.h"
20 
21 #include <stdint.h>
22 
23 using namespace ns3;
24 
42 {
43  public:
45 
47  {
48  }
49 
53  void Target1()
54  {
55  m_test1 = true;
56  }
57 
62  int Target2()
63  {
64  m_test2 = true;
65  return 2;
66  }
67 
72  void Target3(double a [[maybe_unused]])
73  {
74  m_test3 = true;
75  }
76 
83  int Target4(double a [[maybe_unused]], int b [[maybe_unused]])
84  {
85  m_test4 = true;
86  return 4;
87  }
88 
89  private:
90  void DoRun() override;
91  void DoSetup() override;
92 
93  bool m_test1;
94  bool m_test2;
95  bool m_test3;
96  bool m_test4;
97 };
98 
107 
113 void
115 {
116  gBasicCallbackTest5 = true;
117 }
118 
122 void
124 {
125  gBasicCallbackTest6 = true;
126 }
127 
133 int
135 {
136  gBasicCallbackTest7 = true;
137  return a;
138 }
139 
141  : TestCase("Check basic Callback mechanism")
142 {
143 }
144 
145 void
147 {
148  m_test1 = false;
149  m_test2 = false;
150  m_test3 = false;
151  m_test4 = false;
152  gBasicCallbackTest5 = false;
153  gBasicCallbackTest6 = false;
154  gBasicCallbackTest7 = false;
155  gBasicCallbackTest8 = false;
156 }
157 
158 void
160 {
161  //
162  // Make sure we can declare and compile a Callback pointing to a member
163  // function returning void and execute it.
164  //
166  target1();
167  NS_TEST_ASSERT_MSG_EQ(m_test1, true, "Callback did not fire");
168 
169  //
170  // Make sure we can declare and compile a Callback pointing to a member
171  // function that returns an int and execute it.
172  //
173  Callback<int> target2;
175  target2();
176  NS_TEST_ASSERT_MSG_EQ(m_test2, true, "Callback did not fire");
177 
178  //
179  // Make sure we can declare and compile a Callback pointing to a member
180  // function that returns void, takes a double parameter, and execute it.
181  //
183  target3(0.0);
184  NS_TEST_ASSERT_MSG_EQ(m_test3, true, "Callback did not fire");
185 
186  //
187  // Make sure we can declare and compile a Callback pointing to a member
188  // function that returns void, takes two parameters, and execute it.
189  //
192  target4(0.0, 1);
193  NS_TEST_ASSERT_MSG_EQ(m_test4, true, "Callback did not fire");
194 
195  //
196  // Make sure we can declare and compile a Callback pointing to a non-member
197  // function that returns void, and execute it. This is a lower level call
198  // than MakeCallback so we have got to include at least two arguments to make
199  // sure that the constructor is properly disambiguated. If the arguments are
200  // not needed, we just pass in dummy values.
201  //
203  target5();
204  NS_TEST_ASSERT_MSG_EQ(gBasicCallbackTest5, true, "Callback did not fire");
205 
206  //
207  // Make sure we can declare and compile a Callback pointing to a non-member
208  // function that returns void, takes one integer argument and execute it.
209  //
211  target6(1);
212  NS_TEST_ASSERT_MSG_EQ(gBasicCallbackTest6, true, "Callback did not fire");
213 
214  //
215  // Make sure we can declare and compile a Callback pointing to a non-member
216  // function that returns int, takes one integer argument and execute it.
217  //
219  target7(1);
220  NS_TEST_ASSERT_MSG_EQ(gBasicCallbackTest7, true, "Callback did not fire");
221 
222  //
223  // Make sure we can create a callback pointing to a lambda.
224  //
225  Callback<double, int> target8([](int p) {
226  gBasicCallbackTest8 = true;
227  return p / 2.;
228  });
229  target8(5);
230  NS_TEST_ASSERT_MSG_EQ(gBasicCallbackTest8, true, "Callback did not fire");
231 }
232 
239 {
240  public:
242 
244  {
245  }
246 
250  void Target1()
251  {
252  m_test1 = true;
253  }
254 
259  int Target2()
260  {
261  m_test2 = true;
262  return 2;
263  }
264 
269  void Target3(double a [[maybe_unused]])
270  {
271  m_test3 = true;
272  }
273 
280  int Target4(double a [[maybe_unused]], int b [[maybe_unused]])
281  {
282  m_test4 = true;
283  return 4;
284  }
285 
286  private:
287  void DoRun() override;
288  void DoSetup() override;
289 
290  bool m_test1;
291  bool m_test2;
292  bool m_test3;
293  bool m_test4;
294 };
295 
300 static bool gMakeCallbackTest5;
301 static bool gMakeCallbackTest6;
302 static bool gMakeCallbackTest7;
303 
309 void
311 {
312  gMakeCallbackTest5 = true;
313 }
314 
318 void
320 {
321  gMakeCallbackTest6 = true;
322 }
323 
329 int
331 {
332  gMakeCallbackTest7 = true;
333  return a;
334 }
335 
337  : TestCase("Check MakeCallback() mechanism")
338 {
339 }
340 
341 void
343 {
344  m_test1 = false;
345  m_test2 = false;
346  m_test3 = false;
347  m_test4 = false;
348  gMakeCallbackTest5 = false;
349  gMakeCallbackTest6 = false;
350  gMakeCallbackTest7 = false;
351 }
352 
353 void
355 {
356  //
357  // Make sure we can declare and make a Callback pointing to a member
358  // function returning void and execute it.
359  //
361  target1();
362  NS_TEST_ASSERT_MSG_EQ(m_test1, true, "Callback did not fire");
363 
364  //
365  // Make sure we can declare and make a Callback pointing to a member
366  // function that returns an int and execute it.
367  //
369  target2();
370  NS_TEST_ASSERT_MSG_EQ(m_test2, true, "Callback did not fire");
371 
372  //
373  // Make sure we can declare and make a Callback pointing to a member
374  // function that returns void, takes a double parameter, and execute it.
375  //
377  target3(0.0);
378  NS_TEST_ASSERT_MSG_EQ(m_test3, true, "Callback did not fire");
379 
380  //
381  // Make sure we can declare and make a Callback pointing to a member
382  // function that returns void, takes two parameters, and execute it.
383  //
385  target4(0.0, 1);
386  NS_TEST_ASSERT_MSG_EQ(m_test4, true, "Callback did not fire");
387 
388  //
389  // Make sure we can declare and make a Callback pointing to a non-member
390  // function that returns void, and execute it. This uses a higher level call
391  // than in the basic tests so we do not need to include any dummy arguments
392  // here.
393  //
395  target5();
396  NS_TEST_ASSERT_MSG_EQ(gMakeCallbackTest5, true, "Callback did not fire");
397 
398  //
399  // Make sure we can declare and compile a Callback pointing to a non-member
400  // function that returns void, takes one integer argument and execute it.
401  // This uses a higher level call than in the basic tests so we do not need to
402  // include any dummy arguments here.
403  //
405  target6(1);
406  NS_TEST_ASSERT_MSG_EQ(gMakeCallbackTest6, true, "Callback did not fire");
407 
408  //
409  // Make sure we can declare and compile a Callback pointing to a non-member
410  // function that returns int, takes one integer argument and execute it.
411  // This uses a higher level call than in the basic tests so we do not need to
412  // include any dummy arguments here.
413  //
415  target7(1);
416  NS_TEST_ASSERT_MSG_EQ(gMakeCallbackTest7, true, "Callback did not fire");
417 }
418 
425 {
426  public:
428 
430  {
431  }
432 
441  int BoundTarget(int a, int b, int c)
442  {
443  return a + b + c;
444  }
445 
446  private:
447  void DoRun() override;
448  void DoSetup() override;
449 };
450 
477 
480 // Note: doxygen compounds don not work due to params / return variability.
481 
486 void
488 {
490 }
491 
496 void
498 {
500 }
501 
508 int
510 {
513  return 1234;
514 }
515 
521 void
523 {
526 }
527 
534 int
536 {
539  return 1234;
540 }
541 
549 int
550 MakeBoundCallbackTarget6(int a, int b, int c)
551 {
555  return 1234;
556 }
557 
564 void
565 MakeBoundCallbackTarget7(int a, int b, int c)
566 {
570 }
571 
579 int
580 MakeBoundCallbackTarget8(int a, int b, int c)
581 {
585  return 1234;
586 }
587 
596 int
597 MakeBoundCallbackTarget9(int a, int b, int c, int d)
598 {
603  return 1234;
604 }
605 
607  : TestCase("Check MakeBoundCallback() mechanism")
608 {
609 }
610 
611 void
613 {
615  gMakeBoundCallbackTest2 = nullptr;
616  gMakeBoundCallbackTest3a = nullptr;
636 }
637 
638 void
640 {
641  //
642  // This is slightly tricky to explain. A bound Callback allows us to package
643  // up arguments for use later. The arguments are bound when the callback is
644  // created and the code that fires the Callback does not know they are there.
645  //
646  // Since the callback is *declared* according to the way it will be used, the
647  // arguments are not seen there. However, the target function of the callback
648  // will have the provided arguments present. The MakeBoundCallback template
649  // function is what connects the two together and where you provide the
650  // arguments to be bound.
651  //
652  // Here we declare a Callback that returns a void and takes no parameters.
653  // MakeBoundCallback connects this Callback to a target function that returns
654  // void and takes an integer argument. That integer argument is bound to the
655  // value 1234. When the Callback is fired, no integer argument is provided
656  // directly. The argument is provided by bound Callback mechanism.
657  //
659  target1();
661  1234,
662  "Callback did not fire or binding not correct");
663 
664  //
665  // Make sure we can bind a pointer value (a common use case).
666  //
667  bool a;
669  target2();
671  &a,
672  "Callback did not fire or binding not correct");
673 
674  //
675  // Make sure we can mix and match bound and unbound arguments. This callback
676  // returns an integer so we should see that appear.
677  //
679  int result = target3(2468);
680  NS_TEST_ASSERT_MSG_EQ(result, 1234, "Return value of callback not correct");
682  &a,
683  "Callback did not fire or binding not correct");
685  2468,
686  "Callback did not fire or argument not correct");
687 
688  //
689  // Test the TwoBound variant
690  //
692  target4();
694  3456,
695  "Callback did not fire or binding not correct");
697  5678,
698  "Callback did not fire or binding not correct");
699 
701  int resultTwoA = target5();
702  NS_TEST_ASSERT_MSG_EQ(resultTwoA, 1234, "Return value of callback not correct");
704  3456,
705  "Callback did not fire or binding not correct");
707  5678,
708  "Callback did not fire or binding not correct");
709 
711  int resultTwoB = target6(6789);
712  NS_TEST_ASSERT_MSG_EQ(resultTwoB, 1234, "Return value of callback not correct");
714  3456,
715  "Callback did not fire or binding not correct");
717  5678,
718  "Callback did not fire or binding not correct");
720  6789,
721  "Callback did not fire or argument not correct");
722 
723  //
724  // Test the ThreeBound variant
725  //
726  Callback<void> target7 = MakeBoundCallback(&MakeBoundCallbackTarget7, 2345, 3456, 4567);
727  target7();
729  2345,
730  "Callback did not fire or binding not correct");
732  3456,
733  "Callback did not fire or binding not correct");
735  4567,
736  "Callback did not fire or binding not correct");
737 
738  Callback<int> target8 = MakeBoundCallback(&MakeBoundCallbackTarget8, 2345, 3456, 4567);
739  int resultThreeA = target8();
740  NS_TEST_ASSERT_MSG_EQ(resultThreeA, 1234, "Return value of callback not correct");
742  2345,
743  "Callback did not fire or binding not correct");
745  3456,
746  "Callback did not fire or binding not correct");
748  4567,
749  "Callback did not fire or binding not correct");
750 
751  Callback<int, int> target9 = MakeBoundCallback(&MakeBoundCallbackTarget9, 2345, 3456, 4567);
752  int resultThreeB = target9(5678);
753  NS_TEST_ASSERT_MSG_EQ(resultThreeB, 1234, "Return value of callback not correct");
755  2345,
756  "Callback did not fire or binding not correct");
758  3456,
759  "Callback did not fire or binding not correct");
761  4567,
762  "Callback did not fire or binding not correct");
764  5678,
765  "Callback did not fire or binding not correct");
766 
767  //
768  // Test creating a bound callback pointing to a member function. Also, make sure that
769  // an argument can be bound to a reference.
770  //
771  int b = 1;
772  Callback<int> target10 =
773  Callback<int>(&MakeBoundCallbackTestCase::BoundTarget, this, std::ref(b), 5, 2);
774  NS_TEST_ASSERT_MSG_EQ(target10(), 8, "Bound callback returned an unexpected value");
775  b = 3;
776  NS_TEST_ASSERT_MSG_EQ(target10(), 10, "Bound callback returned an unexpected value");
777 }
778 
785 {
786  public:
788 
790  {
791  }
792 
800  int TargetMember(double a, int b)
801  {
802  return static_cast<int>(a) + b;
803  }
804 
805  private:
806  void DoRun() override;
807  void DoSetup() override;
808 };
809 
817 int
818 CallbackEqualityTarget(double a, int b)
819 {
820  return static_cast<int>(a) + b;
821 }
822 
824  : TestCase("Check Callback equality test")
825 {
826 }
827 
828 void
830 {
831 }
832 
833 void
835 {
836  //
837  // Make sure that two callbacks pointing to the same member function
838  // compare equal.
839  //
841  Callback<int, double, int> target1b =
843  NS_TEST_ASSERT_MSG_EQ(target1a.IsEqual(target1b), true, "Equality test failed");
844 
845  //
846  // Make sure that two callbacks pointing to the same member function
847  // compare equal, after binding the first argument.
848  //
850  Callback<int, int> target2b = target1b.Bind(1.5);
851  NS_TEST_ASSERT_MSG_EQ(target2a.IsEqual(target2b), true, "Equality test failed");
852 
853  //
854  // Make sure that two callbacks pointing to the same member function
855  // compare equal, after binding the first two arguments.
856  //
857  Callback<int> target3a(target2a, 2);
858  Callback<int> target3b = target1b.Bind(1.5, 2);
859  NS_TEST_ASSERT_MSG_EQ(target3a.IsEqual(target3b), true, "Equality test failed");
860 
861  //
862  // Make sure that two callbacks pointing to the same member function do
863  // not compare equal if they are bound to different arguments.
864  //
865  Callback<int> target3c = target1b.Bind(1.5, 3);
866  NS_TEST_ASSERT_MSG_EQ(target3c.IsEqual(target3b), false, "Equality test failed");
867 
868  //
869  // Make sure that two callbacks pointing to the same non-member function
870  // compare equal.
871  //
874  NS_TEST_ASSERT_MSG_EQ(target4a.IsEqual(target4b), true, "Equality test failed");
875 
876  //
877  // Make sure that two callbacks pointing to the same non-member function
878  // compare equal, after binding the first argument.
879  //
881  Callback<int, int> target5b = target4b.Bind(1.5);
882  NS_TEST_ASSERT_MSG_EQ(target5a.IsEqual(target5b), true, "Equality test failed");
883 
884  //
885  // Make sure that two callbacks pointing to the same non-member function
886  // compare equal, after binding the first two arguments.
887  //
888  Callback<int> target6a(target5a, 2);
889  Callback<int> target6b = target4b.Bind(1.5, 2);
890  NS_TEST_ASSERT_MSG_EQ(target6a.IsEqual(target6b), true, "Equality test failed");
891 
892  //
893  // Make sure that two callbacks pointing to the same non-member function do
894  // not compare equal if they are bound to different arguments.
895  //
896  Callback<int> target6c = target4b.Bind(1.5, 3);
897  NS_TEST_ASSERT_MSG_EQ(target6c.IsEqual(target6b), false, "Equality test failed");
898 
899  //
900  // Check that we cannot compare lambdas.
901  //
902  Callback<double, int, double> target7a([](int p, double d) { return d + p / 2.; });
903  Callback<double, int, double> target7b([](int p, double d) { return d + p / 2.; });
904  NS_TEST_ASSERT_MSG_EQ(target7a.IsEqual(target7b), false, "Compared lambdas?");
905 
906  //
907  // Make sure that a callback pointing to a lambda and a copy of it compare equal.
908  //
909  Callback<double, int, double> target7c(target7b);
910  NS_TEST_ASSERT_MSG_EQ(target7c.IsEqual(target7b), true, "Equality test failed");
911 
912  //
913  // Make sure that a callback pointing to a lambda and a copy of it compare equal,
914  // after binding the first argument.
915  //
916  Callback<double, double> target8b = target7b.Bind(1);
917  Callback<double, double> target8c(target7c, 1);
918  NS_TEST_ASSERT_MSG_EQ(target8b.IsEqual(target8c), true, "Equality test failed");
919 
920  //
921  // Make sure that a callback pointing to a lambda and a copy of it compare equal,
922  // after binding the first two arguments.
923  //
924  Callback<double> target9b = target8b.Bind(2.0);
925  Callback<double> target9c(target8c, 2.0);
926  NS_TEST_ASSERT_MSG_EQ(target9b.IsEqual(target9c), true, "Equality test failed");
927 
928  //
929  // Make sure that a callback pointing to a lambda and a copy of it do not compare
930  // equal if they are bound to different arguments.
931  //
932  Callback<double> target9d = target8b.Bind(4);
933  NS_TEST_ASSERT_MSG_EQ(target9d.IsEqual(target9c), false, "Equality test failed");
934 }
935 
942 {
943  public:
945 
947  {
948  }
949 
953  void Target1()
954  {
955  m_test1 = true;
956  }
957 
958  private:
959  void DoRun() override;
960  void DoSetup() override;
961 
962  bool m_test1;
963 };
964 
966  : TestCase("Check Nullify() and IsNull()")
967 {
968 }
969 
970 void
972 {
973  m_test1 = false;
974 }
975 
976 void
978 {
979  //
980  // Make sure we can declare and make a Callback pointing to a member
981  // function returning void and execute it.
982  //
984  target1();
985  NS_TEST_ASSERT_MSG_EQ(m_test1, true, "Callback did not fire");
986 
987  NS_TEST_ASSERT_MSG_EQ(target1.IsNull(), false, "Working Callback reports IsNull()");
988 
989  target1.Nullify();
990 
991  NS_TEST_ASSERT_MSG_EQ(target1.IsNull(), true, "Nullified Callback reports not IsNull()");
992 }
993 
1001 {
1002  public:
1004 
1006  {
1007  }
1008 
1012  void Target1()
1013  {
1014  m_test1 = true;
1015  }
1016 
1017  private:
1018  void DoRun() override;
1019 
1020  bool m_test1;
1021 };
1022 
1027 void TestFZero(){};
1028 void TestFOne(int){};
1029 void TestFTwo(int, int){};
1030 void TestFThree(int, int, int){};
1031 void TestFFour(int, int, int, int){};
1032 void TestFFive(int, int, int, int, int){};
1033 void TestFSix(int, int, int, int, int, int){};
1034 
1035 void TestFROne(int&){};
1036 void TestFRTwo(int&, int&){};
1037 void TestFRThree(int&, int&, int&){};
1038 void TestFRFour(int&, int&, int&, int&){};
1039 void TestFRFive(int&, int&, int&, int&, int&){};
1040 void TestFRSix(int&, int&, int&, int&, int&, int&){};
1041 
1051 {
1052  public:
1055  {
1056  }
1057 
1058  protected:
1061  {
1062  }
1063 
1066  {
1067  }
1068 
1069  private:
1072  {
1073  }
1074 };
1075 
1083 {
1084  public:
1089  void TestZero(){};
1090  void TestOne(int){};
1091  void TestTwo(int, int){};
1092  void TestThree(int, int, int){};
1093  void TestFour(int, int, int, int){};
1094  void TestFive(int, int, int, int, int){};
1095  void TestSix(int, int, int, int, int, int){};
1096  void TestCZero() const {};
1097  void TestCOne(int) const {};
1098  void TestCTwo(int, int) const {};
1099  void TestCThree(int, int, int) const {};
1100  void TestCFour(int, int, int, int) const {};
1101  void TestCFive(int, int, int, int, int) const {};
1102  void TestCSix(int, int, int, int, int, int) const {};
1103 
1111  {
1115  // as expected, fails.
1116  // MakeCallback (&CallbackTestParent::PrivateParent, this);
1117  // as expected, fails.
1118  // Pointers do not carry the access restriction info, so it is forbidden
1119  // to generate a pointer to a parent's protected function, because
1120  // this could lead to un-protect them, e.g., by making it public.
1121  // MakeCallback (&CallbackTestParent::ProtectedParent, this);
1122  }
1123 };
1124 
1126  : TestCase("Check various MakeCallback() template functions")
1127 {
1128 }
1129 
1130 void
1132 {
1133  CallbackTestClass that;
1134 
1142 
1150 
1158 
1165 
1171 
1177 
1178  that.CheckParentalRights();
1179 }
1180 
1187 {
1188  public:
1190 };
1191 
1193  : TestSuite("callback", UNIT)
1194 {
1195  AddTestCase(new BasicCallbackTestCase, TestCase::QUICK);
1196  AddTestCase(new MakeCallbackTestCase, TestCase::QUICK);
1197  AddTestCase(new MakeBoundCallbackTestCase, TestCase::QUICK);
1198  AddTestCase(new CallbackEqualityTestCase, TestCase::QUICK);
1199  AddTestCase(new NullifyCallbackTestCase, TestCase::QUICK);
1200  AddTestCase(new MakeCallbackTemplatesTestCase, TestCase::QUICK);
1201 }
1202 
static bool gBasicCallbackTest7
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest5a
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest7c
Variable to verify that a callback has been called.
int MakeBoundCallbackTarget5(int a, int b)
MakeBoundCallback 5 target function.
static bool * gMakeBoundCallbackTest2
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest6b
Variable to verify that a callback has been called.
void TestFSix(int, int, int, int, int, int)
Test function - does nothing.
int MakeCallbackTarget7(int a)
MakeCallback 7 target function.
int CallbackEqualityTarget(double a, int b)
Non-member function used to test equality of callbacks.
static int gMakeBoundCallbackTest7b
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest9a
Variable to verify that a callback has been called.
static CallbackTestSuite g_gallbackTestSuite
Static variable for test initialization.
int MakeBoundCallbackTarget8(int a, int b, int c)
MakeBoundCallback 8 target function.
static bool gMakeCallbackTest5
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest1
Variable to verify that a callback has been called.
static bool gBasicCallbackTest5
Variable to verify that a callback has been called.
void MakeCallbackTarget5()
MakeCallback 5 target function.
static bool * gMakeBoundCallbackTest3a
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest6c
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest9b
Variable to verify that a callback has been called.
int BasicCallbackTarget7(int a)
Callback 6 target function.
void MakeBoundCallbackTarget2(bool *a)
MakeBoundCallback 2 target function.
void BasicCallbackTarget5()
Callback 5 target function.
void MakeBoundCallbackTarget7(int a, int b, int c)
MakeBoundCallback 7 target function.
static int gMakeBoundCallbackTest7a
Variable to verify that a callback has been called.
void BasicCallbackTarget6(int)
Callback 6 target function.
void TestFROne(int &)
Test function - does nothing.
void TestFRTwo(int &, int &)
Test function - does nothing.
static int gMakeBoundCallbackTest4b
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest5b
Variable to verify that a callback has been called.
int MakeBoundCallbackTarget6(int a, int b, int c)
MakeBoundCallback 5 target function.
static int gMakeBoundCallbackTest6a
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest5c
Variable to verify that a callback has been called.
void TestFFive(int, int, int, int, int)
Test function - does nothing.
static bool gMakeCallbackTest7
Variable to verify that a callback has been called.
int MakeBoundCallbackTarget3(bool *a, int b)
MakeBoundCallback 3 target function.
void MakeBoundCallbackTarget4(int a, int b)
MakeBoundCallback 4 target function.
static int gMakeBoundCallbackTest3b
Variable to verify that a callback has been called.
void TestFRFive(int &, int &, int &, int &, int &)
Test function - does nothing.
void TestFFour(int, int, int, int)
Test function - does nothing.
void TestFRThree(int &, int &, int &)
Test function - does nothing.
static int gMakeBoundCallbackTest8b
Variable to verify that a callback has been called.
void TestFOne(int)
Test function - does nothing.
int MakeBoundCallbackTarget9(int a, int b, int c, int d)
MakeBoundCallback 5 target function.
void TestFThree(int, int, int)
Test function - does nothing.
static bool gBasicCallbackTest8
Variable to verify that a callback has been called.
void TestFTwo(int, int)
Test function - does nothing.
static int gMakeBoundCallbackTest9d
Variable to verify that a callback has been called.
void TestFZero()
Test function - does nothing.
static int gMakeBoundCallbackTest4a
Variable to verify that a callback has been called.
static bool gMakeCallbackTest6
Variable to verify that a callback has been called.
void TestFRSix(int &, int &, int &, int &, int &, int &)
Test function - does nothing.
void TestFRFour(int &, int &, int &, int &)
Test function - does nothing.
static int gMakeBoundCallbackTest8c
Variable to verify that a callback has been called.
void MakeCallbackTarget6(int)
MakeCallback 6 target function.
void MakeBoundCallbackTarget1(int a)
MakeBoundCallback 1 target function.
static int gMakeBoundCallbackTest9c
Variable to verify that a callback has been called.
static int gMakeBoundCallbackTest8a
Variable to verify that a callback has been called.
static bool gBasicCallbackTest6
Variable to verify that a callback has been called.
Test the basic Callback mechanism.
bool m_test2
true if Target2 has been called, false otherwise.
bool m_test3
true if Target3 has been called, false otherwise.
bool m_test1
true if Target1 has been called, false otherwise.
void Target3(double a[[maybe_unused]])
Callback 3 target function.
void Target1()
Callback 1 target function.
bool m_test4
true if Target4 has been called, false otherwise.
void DoRun() override
Implementation to actually run this TestCase.
int Target2()
Callback 2 target function.
int Target4(double a[[maybe_unused]], int b[[maybe_unused]])
Callback 4 target function.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
Test the callback equality implementation.
void DoRun() override
Implementation to actually run this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
int TargetMember(double a, int b)
Member function used to test equality of callbacks.
Derived class used to check the capability of callbacks to call public, protected,...
void TestSix(int, int, int, int, int, int)
Test function - does nothing.
void CheckParentalRights()
Tries to make a callback to public and protected functions of a class.
void TestCThree(int, int, int) const
Test function - does nothing.
void TestCSix(int, int, int, int, int, int) const
Test function - does nothing.
void TestZero()
Test function - does nothing.
void TestOne(int)
Test function - does nothing.
void TestThree(int, int, int)
Test function - does nothing.
void TestCFour(int, int, int, int) const
Test function - does nothing.
void TestCOne(int) const
Test function - does nothing.
void TestCFive(int, int, int, int, int) const
Test function - does nothing.
void TestFour(int, int, int, int)
Test function - does nothing.
void TestCZero() const
Test function - does nothing.
void TestCTwo(int, int) const
Test function - does nothing.
void TestFive(int, int, int, int, int)
Test function - does nothing.
void TestTwo(int, int)
Test function - does nothing.
Class used to check the capability of callbacks to call public, protected, and private functions.
void PrivateParent()
A private function.
void PublicParent()
A public function.
void ProtectedParent()
A protected function.
static void StaticProtectedParent()
A static protected function.
The callback Test Suite.
Test the MakeBoundCallback mechanism.
void DoRun() override
Implementation to actually run this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
int BoundTarget(int a, int b, int c)
Member function to test the creation of a bound callback pointing to a member function.
Make sure that various MakeCallback template functions compile and execute; doesn't check an results ...
bool m_test1
true if Target1 has been called, false otherwise.
void DoRun() override
Implementation to actually run this TestCase.
void Target1()
Callback 1 target function.
Test the MakeCallback mechanism.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
int Target4(double a[[maybe_unused]], int b[[maybe_unused]])
Callback 4 target function.
bool m_test1
true if Target1 has been called, false otherwise.
void Target1()
Callback 1 target function.
void Target3(double a[[maybe_unused]])
Callback 3 target function.
bool m_test2
true if Target2 has been called, false otherwise.
bool m_test4
true if Target4 has been called, false otherwise.
int Target2()
Callback 2 target function.
bool m_test3
true if Target3 has been called, false otherwise.
void DoRun() override
Implementation to actually run this TestCase.
Test the Nullify mechanism.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void Target1()
Callback 1 target function.
bool m_test1
true if Target1 has been called, false otherwise.
void DoRun() override
Implementation to actually run this TestCase.
bool IsEqual(const CallbackBase &other) const
Equality test.
Definition: callback.h:597
void Nullify()
Discard the implementation, set it to null.
Definition: callback.h:575
bool IsNull() const
Check for null implementation.
Definition: callback.h:569
auto Bind(BoundArgs &&... bargs)
Bind a variable number of arguments.
Definition: callback.h:557
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition: callback.h:765
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:144
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:704