LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2012,2014 University of Zagreb | 3 * Copyright (c) 2012,2014 University of Zagreb |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Vedran Miletić <rivanvx@gmail.com> | 18 * Author: Vedran Miletić <rivanvx@gmail.com> |
19 */ | 19 */ |
20 | 20 |
21 // Include a header file from your module to test. | 21 // Include a header file from your module to test. |
22 #include "ns3/failure-repair-model.h" | 22 #include "ns3/failure-repair-model.h" |
23 #include "ns3/simple-start-stop-object.h" | |
24 #include "ns3/simulator.h" | |
25 | 23 |
26 // An essential include is test.h | 24 // An essential include is test.h |
27 #include "ns3/test.h" | 25 #include "ns3/test.h" |
28 | 26 |
29 // Do not put your test classes in namespace ns3. You may find it useful | 27 // Do not put your test classes in namespace ns3. You may find it useful |
30 // to use the using directive to access the ns3 namespace directly | 28 // to use the using directive to access the ns3 namespace directly |
31 using namespace ns3; | 29 using namespace ns3; |
32 | 30 |
33 // =========================================================================== | 31 // This is an example TestCase. |
34 // Test case to make sure that an Object Start and Stop functions work properly | 32 class FailureRepairModelTestCase1 : public TestCase |
35 // =========================================================================== | |
36 class StartStopTestCase : public TestCase | |
37 { | 33 { |
38 public: | 34 public: |
39 StartStopTestCase (); | 35 FailureRepairModelTestCase1 (); |
40 virtual ~StartStopTestCase (); | 36 virtual ~FailureRepairModelTestCase1 (); |
41 | 37 |
42 private: | 38 private: |
43 virtual void DoRun (void); | 39 virtual void DoRun (void); |
44 }; | 40 }; |
45 | 41 |
46 StartStopTestCase::StartStopTestCase () : TestCase ("Check Start and Stop functi
onality") | 42 // Add some help text to this case to describe what it is intended to test |
| 43 FailureRepairModelTestCase1::FailureRepairModelTestCase1 () |
| 44 : TestCase ("FailureRepairModel test case (does nothing)") |
47 { | 45 { |
48 } | 46 } |
49 | 47 |
50 StartStopTestCase::~StartStopTestCase () | 48 // This destructor does nothing but we include it as a reminder that |
| 49 // the test case should clean up after itself |
| 50 FailureRepairModelTestCase1::~FailureRepairModelTestCase1 () |
51 { | 51 { |
52 } | 52 } |
53 | 53 |
| 54 // |
| 55 // This method is the pure virtual method from class TestCase that every |
| 56 // TestCase must implement |
| 57 // |
54 void | 58 void |
55 StartStopTestCase::DoRun (void) | 59 FailureRepairModelTestCase1::DoRun (void) |
56 { | 60 { |
57 Ptr<SimpleStartStopObject> objA = CreateObject<SimpleStartStopObject> (); | 61 // A wide variety of test macros are available in src/core/test.h |
58 | 62 NS_TEST_ASSERT_MSG_EQ (true, true, "true doesn't equal true for some reason"); |
59 // | 63 // Use this one for floating point comparisons |
60 // Object is stopped by default | 64 NS_TEST_ASSERT_MSG_EQ_TOL (0.01, 0.01, 0.001, "Numbers are not equal within to
lerance"); |
61 // | |
62 NS_TEST_ASSERT_MSG_EQ (objA->IsStarted (), 0, "Object is unexpectedly started"
); | |
63 | |
64 // | |
65 // Start an Object and test for it's state | |
66 // | |
67 objA->Start (); | |
68 NS_TEST_ASSERT_MSG_EQ (objA->IsStarted (), 1, "Object is unexpectedly not star
ted"); | |
69 | |
70 // | |
71 // Stop an Object and test for it's state | |
72 // | |
73 objA->Stop (); | |
74 NS_TEST_ASSERT_MSG_EQ (objA->IsStarted (), 0, "Object is unexpectedly started"
); | |
75 | |
76 // | |
77 // Start an Object two times and test for it's state | |
78 // | |
79 objA->Start (); | |
80 objA->Start (); | |
81 NS_TEST_ASSERT_MSG_EQ (objA->IsStarted (), 1, "Object is unexpectedly not star
ted"); | |
82 | |
83 // | |
84 // Stop an Object two times and test for it's state | |
85 // | |
86 objA->Stop (); | |
87 objA->Stop (); | |
88 NS_TEST_ASSERT_MSG_EQ (objA->IsStarted (), 0, "Object is unexpectedly started"
); | |
89 | |
90 // | |
91 // Simulator::Run and Simulator::Destroy don't affect state of an Object | |
92 // | |
93 Simulator::Run (); | |
94 NS_TEST_ASSERT_MSG_EQ (objA->IsStarted (), 0, "Object is unexpectedly started"
); | |
95 objA->Start (); | |
96 Simulator::Destroy (); | |
97 NS_TEST_ASSERT_MSG_EQ (objA->IsStarted (), 1, "Object is unexpectedly not star
ted"); | |
98 } | |
99 | |
100 // =========================================================================== | |
101 // Test case to make sure that an Object Start and Stop tracking | |
102 // =========================================================================== | |
103 class StartStopTrackingTestCase : public TestCase | |
104 { | |
105 public: | |
106 StartStopTrackingTestCase (); | |
107 virtual ~StartStopTrackingTestCase (); | |
108 | |
109 private: | |
110 virtual void DoRun (void); | |
111 }; | |
112 | |
113 StartStopTrackingTestCase::StartStopTrackingTestCase () : TestCase ("Check Start
and Stop tracking") | |
114 { | |
115 } | |
116 | |
117 StartStopTrackingTestCase::~StartStopTrackingTestCase () | |
118 { | |
119 } | |
120 | |
121 void | |
122 StartStopTrackingTestCase::DoRun (void) | |
123 { | |
124 | |
125 } | 65 } |
126 | 66 |
127 // The TestSuite class names the TestSuite, identifies what type of TestSuite, | 67 // The TestSuite class names the TestSuite, identifies what type of TestSuite, |
128 // and enables the TestCases to be run. Typically, only the constructor for | 68 // and enables the TestCases to be run. Typically, only the constructor for |
129 // this class must be defined | 69 // this class must be defined |
130 // | 70 // |
131 class FailureRepairTestSuite : public TestSuite | 71 class FailureRepairModelTestSuite : public TestSuite |
132 { | 72 { |
133 public: | 73 public: |
134 FailureRepairTestSuite (); | 74 FailureRepairModelTestSuite (); |
135 }; | 75 }; |
136 | 76 |
137 FailureRepairTestSuite::FailureRepairTestSuite () | 77 FailureRepairModelTestSuite::FailureRepairModelTestSuite () |
138 : TestSuite ("failure-repair", UNIT) | 78 : TestSuite ("failure-repair-model", UNIT) |
139 { | 79 { |
140 // TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER | 80 // TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER |
141 AddTestCase (new StartStopTestCase, TestCase::QUICK); | 81 AddTestCase (new FailureRepairModelTestCase1, TestCase::QUICK); |
142 AddTestCase (new StartStopTrackingTestCase, TestCase::QUICK); | |
143 } | 82 } |
144 | 83 |
145 // Do not forget to allocate an instance of this TestSuite | 84 // Do not forget to allocate an instance of this TestSuite |
146 static FailureRepairTestSuite failureRepairTestSuite; | 85 static FailureRepairModelTestSuite failureRepairModelTestSuite; |
147 | 86 |
LEFT | RIGHT |