A Discrete-Event Network Simulator
API
test.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
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 
19 #ifndef NS3_TEST_H
20 #define NS3_TEST_H
21 
22 #include <iostream>
23 #include <fstream>
24 #include <sstream>
25 #include <string>
26 #include <vector>
27 #include <list>
28 #include <limits>
29 #include <stdint.h>
30 
31 #include "non-copyable.h"
32 #include "system-wall-clock-ms.h"
33 
56 namespace ns3 {
57 
59 namespace tests {} // namespace tests
60 
61 //
62 // Note on below macros:
63 //
64 // When multiple statements are used in a macro, they should be bound
65 // together in a loop syntactically, so the macro can appear safely
66 // inside if clauses or other places that expect a single statement or
67 // a statement block. The "strange" do while construct is a generally
68 // expected best practice for defining a robust macro.
69 //
70 
75 #define ASSERT_ON_FAILURE \
76  do { \
77  if (MustAssertOnFailure ()) \
78  { \
79  *(volatile int *)0 = 0; \
80  } \
81  } while (false)
82 
87 #define CONTINUE_ON_FAILURE \
88  do { \
89  if (!MustContinueOnFailure ()) \
90  { \
91  return; \
92  } \
93  } while (false)
94 
99 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
100  do { \
101  if (!MustContinueOnFailure ()) \
102  { \
103  return IsStatusFailure (); \
104  } \
105  } while (false)
106 
107 
108 
109 // ===========================================================================
110 // Test for equality (generic version)
111 // ===========================================================================
112 
118 #define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
119  do { \
120  if (!((actual) == (limit))) \
121  { \
122  ASSERT_ON_FAILURE; \
123  std::ostringstream msgStream; \
124  msgStream << msg; \
125  std::ostringstream actualStream; \
126  actualStream << actual; \
127  std::ostringstream limitStream; \
128  limitStream << limit; \
129  ReportTestFailure (std::string (#actual) + " (actual) == " + \
130  std::string (#limit) + " (limit)", \
131  actualStream.str (), limitStream.str (), \
132  msgStream.str (), file, line); \
133  CONTINUE_ON_FAILURE; \
134  } \
135  } while (false)
136 
166 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
167  NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
168 
174 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
175  do { \
176  if (!((actual) == (limit))) \
177  { \
178  ASSERT_ON_FAILURE; \
179  std::ostringstream msgStream; \
180  msgStream << msg; \
181  std::ostringstream actualStream; \
182  actualStream << actual; \
183  std::ostringstream limitStream; \
184  limitStream << limit; \
185  ReportTestFailure (std::string (#actual) + " (actual) == " + \
186  std::string (#limit) + " (limit)", \
187  actualStream.str (), limitStream.str (), \
188  msgStream.str (), file, line); \
189  CONTINUE_ON_FAILURE_RETURNS_BOOL; \
190  } \
191  } while (false)
192 
225 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
226  NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
227 
236 #define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
237  do { \
238  if (!((actual) == (limit))) \
239  { \
240  ASSERT_ON_FAILURE; \
241  std::ostringstream msgStream; \
242  msgStream << msg; \
243  std::ostringstream actualStream; \
244  actualStream << actual; \
245  std::ostringstream limitStream; \
246  limitStream << limit; \
247  ReportTestFailure (std::string (#actual) + " (actual) == " + \
248  std::string (#limit) + " (limit)", \
249  actualStream.str (), limitStream.str (), \
250  msgStream.str (), file, line); \
251  } \
252  } while (false)
253 
283 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
284  NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
285 
286 // ===========================================================================
287 // Test for equality with a provided tolerance (use for floating point
288 // comparisons -- both float and double)
289 // ===========================================================================
290 
296 #define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
297  do { \
298  if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
299  { \
300  ASSERT_ON_FAILURE; \
301  std::ostringstream msgStream; \
302  msgStream << msg; \
303  std::ostringstream actualStream; \
304  actualStream << actual; \
305  std::ostringstream limitStream; \
306  limitStream << limit << " +- " << tol; \
307  std::ostringstream condStream; \
308  condStream << #actual << " (actual) < " << #limit \
309  << " (limit) + " << #tol << " (tol) && " \
310  << #actual << " (actual) > " << #limit \
311  << " (limit) - " << #tol << " (tol)"; \
312  ReportTestFailure (condStream.str (), actualStream.str (), \
313  limitStream.str (), msgStream.str (), \
314  file, line); \
315  CONTINUE_ON_FAILURE; \
316  } \
317  } while (false)
318 
378 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
379  NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
380 
386 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
387  do { \
388  if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
389  { \
390  ASSERT_ON_FAILURE; \
391  std::ostringstream msgStream; \
392  msgStream << msg; \
393  std::ostringstream actualStream; \
394  actualStream << actual; \
395  std::ostringstream limitStream; \
396  limitStream << limit << " +- " << tol; \
397  std::ostringstream condStream; \
398  condStream << #actual << " (actual) < " << #limit \
399  << " (limit) + " << #tol << " (tol) && " \
400  << #actual << " (actual) > " << #limit \
401  << " (limit) - " << #tol << " (tol)"; \
402  ReportTestFailure (condStream.str (), actualStream.str (), \
403  limitStream.str (), msgStream.str (), \
404  file, line); \
405  CONTINUE_ON_FAILURE_RETURNS_BOOL; \
406  } ` \
407  } while (false)
408 
471 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
472  NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
473 
482 #define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
483  do { \
484  if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
485  { \
486  ASSERT_ON_FAILURE; \
487  std::ostringstream msgStream; \
488  msgStream << msg; \
489  std::ostringstream actualStream; \
490  actualStream << actual; \
491  std::ostringstream limitStream; \
492  limitStream << limit << " +- " << tol; \
493  std::ostringstream condStream; \
494  condStream << #actual << " (actual) < " << #limit \
495  << " (limit) + " << #tol << " (tol) && " \
496  << #actual << " (actual) > " << #limit \
497  << " (limit) - " << #tol << " (tol)"; \
498  ReportTestFailure (condStream.str (), actualStream.str (), \
499  limitStream.str (), msgStream.str (), \
500  file, line); \
501  } \
502  } while (false)
503 
563 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
564  NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
565 
566 // ===========================================================================
567 // Test for inequality
568 // ===========================================================================
569 
575 #define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
576  do { \
577  if (!((actual) != (limit))) \
578  { \
579  ASSERT_ON_FAILURE; \
580  std::ostringstream msgStream; \
581  msgStream << msg; \
582  std::ostringstream actualStream; \
583  actualStream << actual; \
584  std::ostringstream limitStream; \
585  limitStream << limit; \
586  ReportTestFailure (std::string (#actual) + " (actual) != " + \
587  std::string (#limit) + " (limit)", \
588  actualStream.str (), limitStream.str (), \
589  msgStream.str (), file, line); \
590  CONTINUE_ON_FAILURE; \
591  } \
592  } while (false)
593 
622 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
623  NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
624 
630 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
631  do { \
632  if (!((actual) != (limit))) \
633  { \
634  ASSERT_ON_FAILURE; \
635  std::ostringstream msgStream; \
636  msgStream << msg; \
637  std::ostringstream actualStream; \
638  actualStream << actual; \
639  std::ostringstream limitStream; \
640  limitStream << limit; \
641  ReportTestFailure (std::string (#actual) + " (actual) != " + \
642  std::string (#limit) + " (limit)", \
643  actualStream.str (), limitStream.str (), \
644  msgStream.str (), file, line); \
645  CONTINUE_ON_FAILURE_RETURNS_BOOL; \
646  } \
647  } while (false)
648 
680 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
681  NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
682 
691 #define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
692  do { \
693  if (!((actual) != (limit))) \
694  { \
695  ASSERT_ON_FAILURE; \
696  std::ostringstream msgStream; \
697  msgStream << msg; \
698  std::ostringstream actualStream; \
699  actualStream << actual; \
700  std::ostringstream limitStream; \
701  limitStream << limit; \
702  ReportTestFailure (std::string (#actual) + " (actual) != " + \
703  std::string (#limit) + " (limit)", \
704  actualStream.str (), limitStream.str (), \
705  msgStream.str (), file, line); \
706  } \
707  } while (false)
708 
737 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
738  NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
739 
740 // ===========================================================================
741 // Test for less than relation
742 // ===========================================================================
743 
749 #define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
750  do { \
751  if (!((actual) < (limit))) \
752  { \
753  ASSERT_ON_FAILURE; \
754  std::ostringstream msgStream; \
755  msgStream << msg; \
756  std::ostringstream actualStream; \
757  actualStream << actual; \
758  std::ostringstream limitStream; \
759  limitStream << limit; \
760  ReportTestFailure (std::string (#actual) + " (actual) < " + \
761  std::string (#limit) + " (limit)", \
762  actualStream.str (), limitStream.str (), \
763  msgStream.str (), file, line); \
764  CONTINUE_ON_FAILURE; \
765  } \
766  } while (false)
767 
773 #define NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
774  do { \
775  if (!((actual) <= (limit))) \
776  { \
777  ASSERT_ON_FAILURE; \
778  std::ostringstream msgStream; \
779  msgStream << msg; \
780  std::ostringstream actualStream; \
781  actualStream << actual; \
782  std::ostringstream limitStream; \
783  limitStream << limit; \
784  ReportTestFailure (std::string (#actual) + " (actual) < " + \
785  std::string (#limit) + " (limit)", \
786  actualStream.str (), limitStream.str (), \
787  msgStream.str (), file, line); \
788  CONTINUE_ON_FAILURE; \
789  } \
790  } while (false)
791 
809 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
810  NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
811 
830 #define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
831  NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
832 
840 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
841  do { \
842  if (!((actual) < (limit))) \
843  { \
844  ASSERT_ON_FAILURE; \
845  std::ostringstream msgStream; \
846  msgStream << msg; \
847  std::ostringstream actualStream; \
848  actualStream << actual; \
849  std::ostringstream limitStream; \
850  limitStream << limit; \
851  ReportTestFailure (std::string (#actual) + " (actual) < " + \
852  std::string (#limit) + " (limit)", \
853  actualStream.str (), limitStream.str (), \
854  msgStream.str (), file, line); \
855  } \
856  } while (false)
857 
866 #define NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
867  do { \
868  if (!((actual) <= (limit))) \
869  { \
870  ASSERT_ON_FAILURE; \
871  std::ostringstream msgStream; \
872  msgStream << msg; \
873  std::ostringstream actualStream; \
874  actualStream << actual; \
875  std::ostringstream limitStream; \
876  limitStream << limit; \
877  ReportTestFailure (std::string (#actual) + " (actual) < " + \
878  std::string (#limit) + " (limit)", \
879  actualStream.str (), limitStream.str (), \
880  msgStream.str (), file, line); \
881  } \
882  } while (false)
883 
901 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
902  NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
903 
922 #define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
923  NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
924 
925 // ===========================================================================
926 // Test for greater than relation
927 // ===========================================================================
928 
934 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
935  do { \
936  if (!((actual) > (limit))) \
937  { \
938  ASSERT_ON_FAILURE; \
939  std::ostringstream msgStream; \
940  msgStream << msg; \
941  std::ostringstream actualStream; \
942  actualStream << actual; \
943  std::ostringstream limitStream; \
944  limitStream << limit; \
945  ReportTestFailure (std::string (#actual) + " (actual) > " + \
946  std::string (#limit) + " (limit)", \
947  actualStream.str (), limitStream.str (), \
948  msgStream.str (), file, line); \
949  CONTINUE_ON_FAILURE; \
950  } \
951  } while (false)
952 
958 #define NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
959  do { \
960  if (!((actual) >= (limit))) \
961  { \
962  ASSERT_ON_FAILURE; \
963  std::ostringstream msgStream; \
964  msgStream << msg; \
965  std::ostringstream actualStream; \
966  actualStream << actual; \
967  std::ostringstream limitStream; \
968  limitStream << limit; \
969  ReportTestFailure (std::string (#actual) + " (actual) > " + \
970  std::string (#limit) + " (limit)", \
971  actualStream.str (), limitStream.str (), \
972  msgStream.str (), file, line); \
973  CONTINUE_ON_FAILURE; \
974  } \
975  } while (false)
976 
995 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
996  NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
997 
1016 #define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
1017  NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1018 
1026 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
1027  do { \
1028  if (!((actual) > (limit))) \
1029  { \
1030  ASSERT_ON_FAILURE; \
1031  std::ostringstream msgStream; \
1032  msgStream << msg; \
1033  std::ostringstream actualStream; \
1034  actualStream << actual; \
1035  std::ostringstream limitStream; \
1036  limitStream << limit; \
1037  ReportTestFailure (std::string (#actual) + " (actual) > " + \
1038  std::string (#limit) + " (limit)", \
1039  actualStream.str (), limitStream.str (), \
1040  msgStream.str (), file, line); \
1041  } \
1042  } while (false)
1043 
1052 #define NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
1053  do { \
1054  if (!((actual) >= (limit))) \
1055  { \
1056  ASSERT_ON_FAILURE; \
1057  std::ostringstream msgStream; \
1058  msgStream << msg; \
1059  std::ostringstream actualStream; \
1060  actualStream << actual; \
1061  std::ostringstream limitStream; \
1062  limitStream << limit; \
1063  ReportTestFailure (std::string (#actual) + " (actual) > " + \
1064  std::string (#limit) + " (limit)", \
1065  actualStream.str (), limitStream.str (), \
1066  msgStream.str (), file, line); \
1067  } \
1068  } while (false)
1069 
1088 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
1089  NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1090 
1109 #define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
1110  NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1111 
1112 
1137 bool TestDoubleIsEqual (const double a, const double b,
1138  const double epsilon = std::numeric_limits<double>::epsilon ());
1139 
1140 class TestRunnerImpl;
1141 
1153 class TestCase : private NonCopyable
1154 {
1155 public:
1158  {
1159  QUICK = 1,
1162  };
1163 
1167  virtual ~TestCase ();
1168 
1172  std::string GetName (void) const;
1173 
1174 protected:
1180  TestCase (std::string name);
1181 
1189  void AddTestCase (TestCase *testCase, TestDuration duration = QUICK);
1190 
1207  void SetDataDir (std::string directory);
1208 
1214  bool IsStatusFailure (void) const;
1220  bool IsStatusSuccess (void) const;
1221 
1227  TestCase * GetParent () const;
1228 
1245  void ReportTestFailure (std::string cond, std::string actual,
1246  std::string limit, std::string message,
1247  std::string file, int32_t line);
1253  bool MustAssertOnFailure (void) const;
1259  bool MustContinueOnFailure (void) const;
1268  std::string CreateDataDirFilename (std::string filename);
1278  std::string CreateTempDirFilename (std::string filename);
1281 private:
1282  friend class TestRunnerImpl;
1283 
1291  virtual void DoSetup (void);
1292 
1298  virtual void DoRun (void) = 0;
1299 
1307  virtual void DoTeardown (void);
1308 
1309  // methods called by TestRunnerImpl
1315  void Run (TestRunnerImpl *runner);
1317  bool IsFailed (void) const;
1318 
1323  struct Result;
1324 
1325  TestCase *m_parent;
1326  std::vector<TestCase *> m_children;
1327  std::string m_dataDir;
1329  struct Result *m_result;
1330  std::string m_name;
1332 };
1333 
1341 class TestSuite : public TestCase
1342 {
1343 public:
1348  enum Type
1349  {
1350  ALL = 0,
1355  };
1356 
1363  TestSuite (std::string name, Type type = UNIT);
1364 
1371 
1372 private:
1373  // Inherited
1374  virtual void DoRun (void);
1375 
1377 };
1378 
1385 {
1386 public:
1395  static int Run (int argc, char *argv[]);
1396 };
1397 
1403 template <typename T>
1404 class TestVectors : private NonCopyable
1405 {
1406 public:
1410  TestVectors ();
1414  virtual ~TestVectors ();
1415 
1421  void Reserve (uint32_t reserve);
1422 
1428  std::size_t Add (T vector);
1429 
1434  std::size_t GetN (void) const;
1440  T Get (std::size_t i) const;
1441 
1442 private:
1443  typedef std::vector<T> TestVector;
1445 };
1446 
1447 template <typename T>
1449  : m_vectors ()
1450 {}
1451 
1452 template <typename T>
1453 void
1454 TestVectors<T>::Reserve (uint32_t reserve)
1455 {
1456  m_vectors.reserve (reserve);
1457 }
1458 
1459 template <typename T>
1461 {}
1462 
1463 template <typename T>
1464 std::size_t
1466 {
1467  std::size_t index = m_vectors.size ();
1468  m_vectors.push_back (vector);
1469  return index;
1470 }
1471 
1472 template <typename T>
1473 std::size_t
1475 {
1476  return m_vectors.size ();
1477 }
1478 
1479 template <typename T>
1480 T
1481 TestVectors<T>::Get (std::size_t i) const
1482 {
1483  NS_ABORT_MSG_UNLESS (m_vectors.size () > i, "TestVectors::Get(): Bad index");
1484  return m_vectors[i];
1485 }
1486 
1487 } // namespace ns3
1488 
1489 #endif /* NS3_TEST_H */
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
Definition: test.cc:472
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Definition: test.cc:477
This test suite implements a System Test.
Definition: test.h:1352
Container for all tests.
Definition: test.cc:138
bool IsStatusFailure(void) const
Check if any tests failed.
Definition: test.cc:452
A base class for (non-Singleton) objects which shouldn&#39;t be copied.
Definition: non-copyable.h:54
virtual ~TestVectors()
Virtual destructor.
Definition: test.h:1460
A suite of tests to run.
Definition: test.h:1341
A runner to execute tests.
Definition: test.h:1384
void Reserve(uint32_t reserve)
Set the expected length of this vector.
Definition: test.h:1454
Very long running test.
Definition: test.h:1161
Container for results from a TestCase.
Definition: test.cc:120
Type
Type of test.
Definition: test.h:1348
T Get(std::size_t i) const
Get the i&#39;th test vector.
Definition: test.h:1481
bool MustAssertOnFailure(void) const
Check if this run should assert on failure.
Definition: test.cc:399
std::vector< T > TestVector
Container type.
Definition: test.h:1443
encapsulates test code
Definition: test.h:1153
enum TestDuration m_duration
TestCase duration.
Definition: test.h:1331
ns3::NonCopyable declaration.
TestSuite(std::string name, Type type=UNIT)
Construct a new test suite.
Definition: test.cc:483
A simple way to store test vectors (for stimulus or from responses)
Definition: test.h:1404
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: test.cc:499
bool IsStatusSuccess(void) const
Check if all tests passed.
Definition: test.cc:458
std::size_t GetN(void) const
Get the total number of test vectors.
Definition: test.h:1474
TestVectors()
Constructor.
Definition: test.h:1448
TestCase * m_parent
Pointer to my parent TestCase.
Definition: test.h:1323
TestRunnerImpl * m_runner
Pointer to the TestRunner.
Definition: test.h:1328
ns3::SystemWallClockMs declaration.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Medium length test.
Definition: test.h:1160
bool TestDoubleIsEqual(const double x1, const double x2, const double epsilon)
Compare two double precision floating point numbers and declare them equal if they are within some ep...
Definition: test.cc:44
TestSuite::Type m_type
Type of this TestSuite.
Definition: test.h:1376
This test suite implements a Performance Test.
Definition: test.h:1354
TestCase(std::string name)
Constructor.
Definition: test.cc:274
TestDuration
How long the test takes to execute.
Definition: test.h:1157
virtual ~TestCase()
Destructor.
Definition: test.cc:285
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
Definition: test.cc:412
virtual void DoRun(void)=0
Implementation to actually run this TestCase.
struct Result * m_result
Results data.
Definition: test.h:1329
void ReportTestFailure(std::string cond, std::string actual, std::string limit, std::string message, std::string file, int32_t line)
Log the failure of this TestCase.
Definition: test.cc:382
TestCase * GetParent() const
Get the parent of this TestCsse.
Definition: test.cc:376
void Run(TestRunnerImpl *runner)
Actually run this TestCase.
Definition: test.cc:347
bool MustContinueOnFailure(void) const
Check if this run should continue on failure.
Definition: test.cc:405
Fast test.
Definition: test.h:1159
std::string GetName(void) const
Definition: test.cc:370
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition: abort.h:144
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:430
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition: test.cc:465
TestVector m_vectors
The list of test vectors.
Definition: test.h:1444
std::vector< TestCase * > m_children
Vector of my children.
Definition: test.h:1326
This test suite implements an Example Test.
Definition: test.h:1353
std::size_t Add(T vector)
Definition: test.h:1465
This test suite implements a Unit Test.
Definition: test.h:1351
TestSuite::Type GetTestType(void)
get the kind of test this test suite implements
Definition: test.cc:492
static int Run(int argc, char *argv[])
Run the requested suite of tests, according to the given command line arguments.
Definition: test.cc:1115
std::string m_name
TestCase name.
Definition: test.h:1330
bool IsFailed(void) const
Check if any tests failed.
Definition: test.cc:340
std::string m_dataDir
My data directory.
Definition: test.h:1327