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 //
57 // Note on below macros:
58 //
59 // When multiple statements are used in a macro, they should be bound
60 // together in a loop syntactically, so the macro can appear safely
61 // inside if clauses or other places that expect a single statement or
62 // a statement block. The "strange" do while construct is a generally
63 // expected best practice for defining a robust macro.
64 //
65 
70 #define ASSERT_ON_FAILURE \
71  do { \
72  if (MustAssertOnFailure ()) \
73  { \
74  *(volatile int *)0 = 0; \
75  } \
76  } while (false)
77 
82 #define CONTINUE_ON_FAILURE \
83  do { \
84  if (!MustContinueOnFailure ()) \
85  { \
86  return; \
87  } \
88  } while (false)
89 
94 #define CONTINUE_ON_FAILURE_RETURNS_BOOL \
95  do { \
96  if (!MustContinueOnFailure ()) \
97  { \
98  return IsStatusFailure (); \
99  } \
100  } while (false)
101 
102 
103 
104 // ===========================================================================
105 // Test for equality (generic version)
106 // ===========================================================================
107 
113 #define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
114  do { \
115  if (!((actual) == (limit))) \
116  { \
117  ASSERT_ON_FAILURE; \
118  std::ostringstream msgStream; \
119  msgStream << msg; \
120  std::ostringstream actualStream; \
121  actualStream << actual; \
122  std::ostringstream limitStream; \
123  limitStream << limit; \
124  ReportTestFailure (std::string (#actual) + " (actual) == " + \
125  std::string (#limit) + " (limit)", \
126  actualStream.str (), limitStream.str (), \
127  msgStream.str (), file, line); \
128  CONTINUE_ON_FAILURE; \
129  } \
130  } while (false)
131 
161 #define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg) \
162  NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
163 
169 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
170  do { \
171  if (!((actual) == (limit))) \
172  { \
173  ASSERT_ON_FAILURE; \
174  std::ostringstream msgStream; \
175  msgStream << msg; \
176  std::ostringstream actualStream; \
177  actualStream << actual; \
178  std::ostringstream limitStream; \
179  limitStream << limit; \
180  ReportTestFailure (std::string (#actual) + " (actual) == " + \
181  std::string (#limit) + " (limit)", \
182  actualStream.str (), limitStream.str (), \
183  msgStream.str (), file, line); \
184  CONTINUE_ON_FAILURE_RETURNS_BOOL; \
185  } \
186  } while (false)
187 
220 #define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg) \
221  NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
222 
231 #define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line) \
232  do { \
233  if (!((actual) == (limit))) \
234  { \
235  ASSERT_ON_FAILURE; \
236  std::ostringstream msgStream; \
237  msgStream << msg; \
238  std::ostringstream actualStream; \
239  actualStream << actual; \
240  std::ostringstream limitStream; \
241  limitStream << limit; \
242  ReportTestFailure (std::string (#actual) + " (actual) == " + \
243  std::string (#limit) + " (limit)", \
244  actualStream.str (), limitStream.str (), \
245  msgStream.str (), file, line); \
246  } \
247  } while (false)
248 
278 #define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg) \
279  NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
280 
281 // ===========================================================================
282 // Test for equality with a provided tolerance (use for floating point
283 // comparisons -- both float and double)
284 // ===========================================================================
285 
291 #define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
292  do { \
293  if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
294  { \
295  ASSERT_ON_FAILURE; \
296  std::ostringstream msgStream; \
297  msgStream << msg; \
298  std::ostringstream actualStream; \
299  actualStream << actual; \
300  std::ostringstream limitStream; \
301  limitStream << limit << " +- " << tol; \
302  std::ostringstream condStream; \
303  condStream << #actual << " (actual) < " << #limit \
304  << " (limit) + " << #tol << " (tol) && " \
305  << #actual << " (actual) > " << #limit \
306  << " (limit) - " << #tol << " (tol)"; \
307  ReportTestFailure (condStream.str (), actualStream.str (), \
308  limitStream.str (), msgStream.str (), \
309  file, line); \
310  CONTINUE_ON_FAILURE; \
311  } \
312  } while (false)
313 
373 #define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg) \
374  NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
375 
381 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line) \
382  do { \
383  if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
384  { \
385  ASSERT_ON_FAILURE; \
386  std::ostringstream msgStream; \
387  msgStream << msg; \
388  std::ostringstream actualStream; \
389  actualStream << actual; \
390  std::ostringstream limitStream; \
391  limitStream << limit << " +- " << tol; \
392  std::ostringstream condStream; \
393  condStream << #actual << " (actual) < " << #limit \
394  << " (limit) + " << #tol << " (tol) && " \
395  << #actual << " (actual) > " << #limit \
396  << " (limit) - " << #tol << " (tol)"; \
397  ReportTestFailure (condStream.str (), actualStream.str (), \
398  limitStream.str (), msgStream.str (), \
399  file, line); \
400  CONTINUE_ON_FAILURE_RETURNS_BOOL; \
401  } \
402  } while (false)
403 
466 #define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg) \
467  NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
468 
477 #define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line) \
478  do { \
479  if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
480  { \
481  ASSERT_ON_FAILURE; \
482  std::ostringstream msgStream; \
483  msgStream << msg; \
484  std::ostringstream actualStream; \
485  actualStream << actual; \
486  std::ostringstream limitStream; \
487  limitStream << limit << " +- " << tol; \
488  std::ostringstream condStream; \
489  condStream << #actual << " (actual) < " << #limit \
490  << " (limit) + " << #tol << " (tol) && " \
491  << #actual << " (actual) > " << #limit \
492  << " (limit) - " << #tol << " (tol)"; \
493  ReportTestFailure (condStream.str (), actualStream.str (), \
494  limitStream.str (), msgStream.str (), \
495  file, line); \
496  } \
497  } while (false)
498 
558 #define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg) \
559  NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
560 
561 // ===========================================================================
562 // Test for inequality
563 // ===========================================================================
564 
570 #define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
571  do { \
572  if (!((actual) != (limit))) \
573  { \
574  ASSERT_ON_FAILURE; \
575  std::ostringstream msgStream; \
576  msgStream << msg; \
577  std::ostringstream actualStream; \
578  actualStream << actual; \
579  std::ostringstream limitStream; \
580  limitStream << limit; \
581  ReportTestFailure (std::string (#actual) + " (actual) != " + \
582  std::string (#limit) + " (limit)", \
583  actualStream.str (), limitStream.str (), \
584  msgStream.str (), file, line); \
585  CONTINUE_ON_FAILURE; \
586  } \
587  } while (false)
588 
617 #define NS_TEST_ASSERT_MSG_NE(actual, limit, msg) \
618  NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
619 
625 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line) \
626  do { \
627  if (!((actual) != (limit))) \
628  { \
629  ASSERT_ON_FAILURE; \
630  std::ostringstream msgStream; \
631  msgStream << msg; \
632  std::ostringstream actualStream; \
633  actualStream << actual; \
634  std::ostringstream limitStream; \
635  limitStream << limit; \
636  ReportTestFailure (std::string (#actual) + " (actual) != " + \
637  std::string (#limit) + " (limit)", \
638  actualStream.str (), limitStream.str (), \
639  msgStream.str (), file, line); \
640  CONTINUE_ON_FAILURE_RETURNS_BOOL; \
641  } \
642  } while (false)
643 
675 #define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg) \
676  NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
677 
686 #define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line) \
687  do { \
688  if (!((actual) != (limit))) \
689  { \
690  ASSERT_ON_FAILURE; \
691  std::ostringstream msgStream; \
692  msgStream << msg; \
693  std::ostringstream actualStream; \
694  actualStream << actual; \
695  std::ostringstream limitStream; \
696  limitStream << limit; \
697  ReportTestFailure (std::string (#actual) + " (actual) != " + \
698  std::string (#limit) + " (limit)", \
699  actualStream.str (), limitStream.str (), \
700  msgStream.str (), file, line); \
701  } \
702  } while (false)
703 
732 #define NS_TEST_EXPECT_MSG_NE(actual, limit, msg) \
733  NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
734 
735 // ===========================================================================
736 // Test for less than relation
737 // ===========================================================================
738 
744 #define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
745  do { \
746  if (!((actual) < (limit))) \
747  { \
748  ASSERT_ON_FAILURE; \
749  std::ostringstream msgStream; \
750  msgStream << msg; \
751  std::ostringstream actualStream; \
752  actualStream << actual; \
753  std::ostringstream limitStream; \
754  limitStream << limit; \
755  ReportTestFailure (std::string (#actual) + " (actual) < " + \
756  std::string (#limit) + " (limit)", \
757  actualStream.str (), limitStream.str (), \
758  msgStream.str (), file, line); \
759  CONTINUE_ON_FAILURE; \
760  } \
761  } while (false)
762 
768 #define NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
769  do { \
770  if (!((actual) <= (limit))) \
771  { \
772  ASSERT_ON_FAILURE; \
773  std::ostringstream msgStream; \
774  msgStream << msg; \
775  std::ostringstream actualStream; \
776  actualStream << actual; \
777  std::ostringstream limitStream; \
778  limitStream << limit; \
779  ReportTestFailure (std::string (#actual) + " (actual) < " + \
780  std::string (#limit) + " (limit)", \
781  actualStream.str (), limitStream.str (), \
782  msgStream.str (), file, line); \
783  CONTINUE_ON_FAILURE; \
784  } \
785  } while (false)
786 
804 #define NS_TEST_ASSERT_MSG_LT(actual, limit, msg) \
805  NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
806 
825 #define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg) \
826  NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
827 
835 #define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line) \
836  do { \
837  if (!((actual) < (limit))) \
838  { \
839  ASSERT_ON_FAILURE; \
840  std::ostringstream msgStream; \
841  msgStream << msg; \
842  std::ostringstream actualStream; \
843  actualStream << actual; \
844  std::ostringstream limitStream; \
845  limitStream << limit; \
846  ReportTestFailure (std::string (#actual) + " (actual) < " + \
847  std::string (#limit) + " (limit)", \
848  actualStream.str (), limitStream.str (), \
849  msgStream.str (), file, line); \
850  } \
851  } while (false)
852 
861 #define NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
862  do { \
863  if (!((actual) <= (limit))) \
864  { \
865  ASSERT_ON_FAILURE; \
866  std::ostringstream msgStream; \
867  msgStream << msg; \
868  std::ostringstream actualStream; \
869  actualStream << actual; \
870  std::ostringstream limitStream; \
871  limitStream << limit; \
872  ReportTestFailure (std::string (#actual) + " (actual) < " + \
873  std::string (#limit) + " (limit)", \
874  actualStream.str (), limitStream.str (), \
875  msgStream.str (), file, line); \
876  } \
877  } while (false)
878 
896 #define NS_TEST_EXPECT_MSG_LT(actual, limit, msg) \
897  NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
898 
917 #define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg) \
918  NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
919 
920 // ===========================================================================
921 // Test for greater than relation
922 // ===========================================================================
923 
929 #define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
930  do { \
931  if (!((actual) > (limit))) \
932  { \
933  ASSERT_ON_FAILURE; \
934  std::ostringstream msgStream; \
935  msgStream << msg; \
936  std::ostringstream actualStream; \
937  actualStream << actual; \
938  std::ostringstream limitStream; \
939  limitStream << limit; \
940  ReportTestFailure (std::string (#actual) + " (actual) > " + \
941  std::string (#limit) + " (limit)", \
942  actualStream.str (), limitStream.str (), \
943  msgStream.str (), file, line); \
944  CONTINUE_ON_FAILURE; \
945  } \
946  } while (false)
947 
953 #define NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
954  do { \
955  if (!((actual) >= (limit))) \
956  { \
957  ASSERT_ON_FAILURE; \
958  std::ostringstream msgStream; \
959  msgStream << msg; \
960  std::ostringstream actualStream; \
961  actualStream << actual; \
962  std::ostringstream limitStream; \
963  limitStream << limit; \
964  ReportTestFailure (std::string (#actual) + " (actual) > " + \
965  std::string (#limit) + " (limit)", \
966  actualStream.str (), limitStream.str (), \
967  msgStream.str (), file, line); \
968  CONTINUE_ON_FAILURE; \
969  } \
970  } while (false)
971 
990 #define NS_TEST_ASSERT_MSG_GT(actual, limit, msg) \
991  NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
992 
1011 #define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg) \
1012  NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1013 
1021 #define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line) \
1022  do { \
1023  if (!((actual) > (limit))) \
1024  { \
1025  ASSERT_ON_FAILURE; \
1026  std::ostringstream msgStream; \
1027  msgStream << msg; \
1028  std::ostringstream actualStream; \
1029  actualStream << actual; \
1030  std::ostringstream limitStream; \
1031  limitStream << limit; \
1032  ReportTestFailure (std::string (#actual) + " (actual) > " + \
1033  std::string (#limit) + " (limit)", \
1034  actualStream.str (), limitStream.str (), \
1035  msgStream.str (), file, line); \
1036  } \
1037  } while (false)
1038 
1047 #define NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL(actual, limit, msg, file, line) \
1048  do { \
1049  if (!((actual) >= (limit))) \
1050  { \
1051  ASSERT_ON_FAILURE; \
1052  std::ostringstream msgStream; \
1053  msgStream << msg; \
1054  std::ostringstream actualStream; \
1055  actualStream << actual; \
1056  std::ostringstream limitStream; \
1057  limitStream << limit; \
1058  ReportTestFailure (std::string (#actual) + " (actual) > " + \
1059  std::string (#limit) + " (limit)", \
1060  actualStream.str (), limitStream.str (), \
1061  msgStream.str (), file, line); \
1062  } \
1063  } while (false)
1064 
1083 #define NS_TEST_EXPECT_MSG_GT(actual, limit, msg) \
1084  NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1085 
1104 #define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg) \
1105  NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
1106 
1107 namespace ns3 {
1108 
1133 bool TestDoubleIsEqual (const double a, const double b,
1134  const double epsilon = std::numeric_limits<double>::epsilon ());
1135 
1136 class TestRunnerImpl;
1137 
1147 class TestCase : private NonCopyable
1148 {
1149 public:
1152  QUICK = 1,
1155  };
1156 
1160  virtual ~TestCase ();
1161 
1165  std::string GetName (void) const;
1166 
1167 protected:
1173  TestCase (std::string name);
1174 
1181  void AddTestCase (TestCase *testCase, enum TestDuration duration);
1182 
1199  void SetDataDir (std::string directory);
1200 
1206  bool IsStatusFailure (void) const;
1212  bool IsStatusSuccess (void) const;
1213 
1219  TestCase * GetParent () const;
1220 
1237  void ReportTestFailure (std::string cond, std::string actual,
1238  std::string limit, std::string message,
1239  std::string file, int32_t line);
1245  bool MustAssertOnFailure (void) const;
1251  bool MustContinueOnFailure (void) const;
1260  std::string CreateDataDirFilename (std::string filename);
1270  std::string CreateTempDirFilename (std::string filename);
1273 private:
1274  friend class TestRunnerImpl;
1275 
1283  virtual void DoSetup (void);
1284 
1290  virtual void DoRun (void) = 0;
1291 
1299  virtual void DoTeardown (void);
1300 
1301  // methods called by TestRunnerImpl
1307  void Run (TestRunnerImpl *runner);
1311  bool IsFailed (void) const;
1312 
1317  struct Result;
1318 
1319  TestCase *m_parent;
1320  std::vector<TestCase *> m_children;
1321  std::string m_dataDir;
1323  struct Result *m_result;
1324  std::string m_name;
1326 };
1327 
1333 class TestSuite : public TestCase
1334 {
1335 public:
1340  enum Type {
1341  ALL = 0,
1342  BVT = 1,
1347  };
1348 
1355  TestSuite (std::string name, Type type = UNIT);
1356 
1363 
1364 private:
1365  // Inherited
1366  virtual void DoRun (void);
1367 
1369 };
1370 
1377 {
1378 public:
1387  static int Run (int argc, char *argv[]);
1388 };
1389 
1395 template <typename T>
1396 class TestVectors : private NonCopyable
1397 {
1398 public:
1402  TestVectors ();
1406  virtual ~TestVectors ();
1407 
1413  void Reserve (uint32_t reserve);
1414 
1420  uint32_t Add (T vector);
1421 
1426  uint32_t GetN (void) const;
1432  T Get (uint32_t i) const;
1433 
1434 private:
1435  typedef std::vector<T> TestVector;
1436  TestVector m_vectors;
1437 };
1438 
1439 template <typename T>
1441  : m_vectors ()
1442 {
1443 }
1444 
1445 template <typename T>
1446 void
1447 TestVectors<T>::Reserve (uint32_t reserve)
1448 {
1449  m_vectors.reserve (reserve);
1450 }
1451 
1452 template <typename T>
1454 {
1455 }
1456 
1457 template <typename T>
1458 uint32_t
1460 {
1461  uint32_t index = m_vectors.size ();
1462  m_vectors.push_back (vector);
1463  return index;
1464 }
1465 
1466 template <typename T>
1467 uint32_t
1469 {
1470  return m_vectors.size ();
1471 }
1472 
1473 template <typename T>
1474 T
1475 TestVectors<T>::Get (uint32_t i) const
1476 {
1477  NS_ABORT_MSG_UNLESS (m_vectors.size () > i, "TestVectors::Get(): Bad index");
1478  return m_vectors[i];
1479 }
1480 
1481 } // namespace ns3
1482 
1483 #endif /* NS3_TEST_H */
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
Definition: test.cc:471
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Definition: test.cc:476
Container for all tests.
Definition: test.cc:137
T Get(uint32_t i) const
Get the i'th test vector.
Definition: test.h:1475
A base class for (non-Singleton) objects which shouldn't be copied.
Definition: non-copyable.h:54
virtual ~TestVectors()
Virtual desctructor.
Definition: test.h:1453
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
A runner to execute tests.
Definition: test.h:1376
void Reserve(uint32_t reserve)
Set the expected length of this vector.
Definition: test.h:1447
Container for results from a TestCase.
Definition: test.cc:120
Medium length test.
Definition: test.h:1153
bool IsFailed(void) const
Check if any tests failed.
Definition: test.cc:339
std::vector< T > TestVector
Container type.
Definition: test.h:1435
encapsulates test code
Definition: test.h:1147
enum TestDuration m_duration
TestCase duration.
Definition: test.h:1325
This test suite implements a Unit Test.
Definition: test.h:1343
ns3::NonCopyable class declaration and implementation.
uint32_t GetN(void) const
Get the total number of test vectors.
Definition: test.h:1468
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Definition: test.cc:482
TestDuration
How long the test takes to execute.
Definition: test.h:1151
This test suite implements an Example Test.
Definition: test.h:1345
A simple way to store test vectors (for stimulus or from responses)
Definition: test.h:1396
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: test.cc:498
TestVectors()
Constructor.
Definition: test.h:1440
TestCase * m_parent
Pointer to my parent TestCase.
Definition: test.h:1317
TestRunnerImpl * m_runner
Pointer to the TestRunner.
Definition: test.h:1322
System-independent wall clock class ns3::SystemWallClockMs declaration.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
uint32_t Add(T vector)
Definition: test.h:1459
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
Type
Type of test.
Definition: test.h:1340
TestSuite::Type m_type
Type of this TestSuite.
Definition: test.h:1368
bool MustAssertOnFailure(void) const
Check if this run should assert on failure.
Definition: test.cc:398
TestCase(std::string name)
Constructor.
Definition: test.cc:273
virtual ~TestCase()
Destructor.
Definition: test.cc:284
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:411
This test suite implements a Performance Test.
Definition: test.h:1346
virtual void DoRun(void)=0
Implementation to actually run this TestCase.
struct Result * m_result
Results data.
Definition: test.h:1323
bool IsStatusFailure(void) const
Check if any tests failed.
Definition: test.cc:451
TestCase * GetParent() const
Get the parent of this TestCsse.
Definition: test.cc:375
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:381
void Run(TestRunnerImpl *runner)
Actually run this TestCase.
Definition: test.cc:346
bool IsStatusSuccess(void) const
Check if all tests passed.
Definition: test.cc:457
This test suite implements a System Test.
Definition: test.h:1344
#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:429
This test suite implements a Build Verification Test.
Definition: test.h:1342
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition: test.cc:464
TestVector m_vectors
The list of test vectors.
Definition: test.h:1436
std::vector< TestCase * > m_children
Vector of my children.
Definition: test.h:1320
std::string GetName(void) const
Definition: test.cc:369
Very long running test.
Definition: test.h:1154
TestSuite::Type GetTestType(void)
get the kind of test this test suite implements
Definition: test.cc:491
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:1324
std::string m_dataDir
My data directory.
Definition: test.h:1321
bool MustContinueOnFailure(void) const
Check if this run should continue on failure.
Definition: test.cc:404