Skip to content

Commit c019b97

Browse files
committed
Made changes to fix setup and teardown bug reported for fixtures for issue #28.
More testing is still required for multiple fixtures in multiple files.
1 parent 54320a9 commit c019b97

File tree

4 files changed

+82
-4
lines changed

4 files changed

+82
-4
lines changed

test/TestClass.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,20 @@ class TestClass
196196
void Setup()
197197
{
198198
TestSetupTeardown& setup_teardown = privateSetupTeardown();
199-
if (setup_teardown.IsSetupSet())
199+
TestString const& this_class_name = GetClassName();
200+
TestString class_name = setup_teardown.GetClassName<true>();
201+
if (setup_teardown.IsSetupSet() && this_class_name == class_name)
200202
setup_teardown.Execute<true>();
201203
}
202204

203205
void Teardown()
204206
{
205207
TestSetupTeardown& setup_teardown = privateSetupTeardown();
206-
if (setup_teardown.IsTeardownSet() && setup_teardown.IsSetupRun())
208+
TestString const& this_class_name = GetClassName();
209+
TestString class_name = setup_teardown.GetClassName<false>();
210+
if (setup_teardown.IsTeardownSet() &&
211+
setup_teardown.IsSetupRun() &&
212+
this_class_name == class_name)
207213
setup_teardown.Execute<false>();
208214
}
209215

@@ -1008,7 +1014,7 @@ class TestClass
10081014
static TestSetupTeardown setup_teardown;
10091015
return setup_teardown;
10101016
}
1011-
1017+
10121018
// Data for this test.
10131019
private:
10141020
TestMemoryLeakCheck m_leak_check;

test/TestSetupTeardown.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TestSetupTeardown
6969
}
7070

7171
template<bool const is_setup>
72-
char const* GetClassName() const throw()
72+
TestString GetClassName() const throw()
7373
{
7474
return is_setup ? GetSetupClassName() : GetTeardownClassName();
7575
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2016 Colin Girling
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include "../Test.hpp"
18+
19+
namespace
20+
{
21+
class LocalTestClass
22+
{
23+
public:
24+
LocalTestClass() : m_value(0)
25+
{
26+
}
27+
28+
int GetValue() const
29+
{
30+
return m_value;
31+
}
32+
33+
void SetValue(int value)
34+
{
35+
m_value = value;
36+
}
37+
38+
private:
39+
int m_value;
40+
};
41+
}
42+
43+
LocalTestClass g_local_test_class;
44+
45+
TEST_SETUP(LocalTestClass)
46+
{
47+
g_local_test_class.SetValue(1);
48+
}
49+
50+
TEST_TEARDOWN(LocalTestClass)
51+
{
52+
}
53+
54+
TEST_MEMBER_FUNCTION(LocalTestClass, GetValue, NA)
55+
{
56+
LocalTestClass local_test_class;
57+
CHECK_EQUAL(g_local_test_class.GetValue(), 1);
58+
CHECK_EQUAL(local_test_class.GetValue(), 0);
59+
local_test_class = g_local_test_class;
60+
CHECK_EQUAL(local_test_class.GetValue(), 1);
61+
}
62+
63+
TEST_MEMBER_FUNCTION(LocalTestClass, SetValue, int)
64+
{
65+
LocalTestClass local_test_class;
66+
CHECK_EQUAL(g_local_test_class.GetValue(), 1);
67+
CHECK_EQUAL(local_test_class.GetValue(), 0);
68+
local_test_class.SetValue(2);
69+
CHECK_EQUAL(local_test_class.GetValue(), 2);
70+
}

test/unit_tests/ide/VS2015/test_unit_tests/test_unit_tests.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<Optimization>Full</Optimization>
144144
<IntrinsicFunctions>true</IntrinsicFunctions>
145145
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);</PreprocessorDefinitions>
146+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
146147
</ClCompile>
147148
<Link>
148149
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -153,6 +154,7 @@
153154
</ItemDefinitionGroup>
154155
<ItemGroup>
155156
<ClCompile Include="..\..\..\TestClass.tests.cpp" />
157+
<ClCompile Include="..\..\..\TestMacros.tests.cpp" />
156158
<ClCompile Include="..\..\..\TestCompare.tests.cpp" />
157159
<ClCompile Include="..\..\..\TestConverterUtility.tests.cpp" />
158160
<ClCompile Include="..\..\..\TestIntegerUtility.tests.cpp" />

0 commit comments

Comments
 (0)