@@ -29,7 +29,7 @@ limitations under the License.
2929#include " TestStdioFileFunctor.hpp"
3030#include " TestMemoryLeakCheck.hpp"
3131#include " TestMemoryCounter.hpp"
32- #include " TestSetupTeardownFunctor .hpp"
32+ #include " TestSetupTeardown .hpp"
3333
3434#include < cstring>
3535#include < climits>
@@ -73,6 +73,8 @@ class TestClass
7373 , m_test_number(0 )
7474 , m_logged(false )
7575 {
76+ GetSharedData ().SetClassName (class_name);
77+
7678 // Ensure that the next constructor can complete
7779 // the snapshot memory leak checking.
7880 TestClass*& prev_test = GetPreviousTest ();
@@ -189,58 +191,50 @@ class TestClass
189191 return str;
190192 }
191193
192- private:
193- // Setup and tear down functionality, called via Execute function.
194- template <bool const is_setup>
195- void SetupTeardown ()
196- {
197- TestSetupTeardownFunctor*& setup_or_teardown = GetSetupOrTeardown<is_setup>();
198-
199- if (setup_or_teardown != NULL )
200- {
201- setup_or_teardown->Execute ();
202- setup_or_teardown = NULL ;
203- }
204- }
205-
206- // Setting the setup and tear down functions, which get called later.
207- // See TEST_SETUP and TEST_TEARDOWN macros for usage.
208- template <bool const is_setup>
209- static void SetSetupTeardown (TestSetupTeardownFunctor& setup_teardown_functor)
210- {
211- TestSetupTeardownFunctor*& setup_or_teardown = GetSetupOrTeardown<is_setup>();
212-
213- TestString class_name;
214- if (setup_or_teardown != NULL )
215- class_name.Assign (setup_or_teardown->GetClassName ());
216-
217- // If setup_or_teardown is null or class name has changed then set the functor.
218- if (class_name != setup_teardown_functor.GetClassName ())
219- setup_or_teardown = &setup_teardown_functor;
220- }
221-
222194// Call the user defined setup and tear down functions via TestClass::Execute.
223195public:
224196 void Setup ()
225197 {
226- SetupTeardown<true >();
198+ TestSetupTeardown& setup_teardown = privateSetupTeardown ();
199+ if (setup_teardown.IsSetupSet ())
200+ setup_teardown.Execute <true >();
227201 }
228202
229203 void Teardown ()
230204 {
231- SetupTeardown<false >();
205+ TestSetupTeardown& setup_teardown = privateSetupTeardown ();
206+ if (setup_teardown.IsTeardownSet () && setup_teardown.IsSetupRun ())
207+ setup_teardown.Execute <false >();
232208 }
233209
234210// Set the appropriate class objects via using the TEST_SETUP and TEST_TEARDOWN macros.
235211public:
236212 static void SetSetup (TestSetupTeardownFunctor& setup_functor)
237213 {
238- SetSetupTeardown<true >(setup_functor);
214+ TestSetupTeardown& setup_teardown = privateSetupTeardown ();
215+
216+ if (setup_teardown.IsSetupRun () &&
217+ (setup_teardown.GetSetupClassName () != setup_functor.GetClassName ()))
218+ {
219+ // If tear down execute is not run before setting new setup functor,
220+ // Then the class has changed and we need to complete the previous
221+ // tear down before starting a new class fixture.
222+ setup_teardown.Execute <false >();
223+ }
224+
225+ setup_teardown.SetSetupFunctor (setup_functor);
239226 }
240227
241228 static void SetTeardown (TestSetupTeardownFunctor& teardown_functor)
242229 {
243- SetSetupTeardown<false >(teardown_functor);
230+ TestSetupTeardown& setup_teardown = privateSetupTeardown ();
231+ setup_teardown.SetTeardownFunctor (teardown_functor);
232+ }
233+
234+ static void ClearSetupTeardown ()
235+ {
236+ TestSetupTeardown& setup_teardown = privateSetupTeardown ();
237+ setup_teardown.Clear ();
244238 }
245239
246240// General helper functions.
@@ -1009,24 +1003,12 @@ class TestClass
10091003 return prev_test;
10101004 }
10111005
1012- static TestSetupTeardownFunctor*& GetSetup ()
1006+ static TestSetupTeardown& privateSetupTeardown ()
10131007 {
1014- static TestSetupTeardownFunctor* setup_functor ;
1015- return setup_functor ;
1008+ static TestSetupTeardown setup_teardown ;
1009+ return setup_teardown ;
10161010 }
1017-
1018- static TestSetupTeardownFunctor*& GetTeardown ()
1019- {
1020- static TestSetupTeardownFunctor* teardown_functor;
1021- return teardown_functor;
1022- }
1023-
1024- template <bool const is_setup>
1025- static TestSetupTeardownFunctor*& GetSetupOrTeardown ()
1026- {
1027- return is_setup ? GetSetup () : GetTeardown ();
1028- }
1029-
1011+
10301012// Data for this test.
10311013private:
10321014 TestMemoryLeakCheck m_leak_check;
0 commit comments