Skip to content

Commit 4993480

Browse files
committed
Added extra unit test file to prove fixtures are behaving as expected.
1 parent c019b97 commit 4993480

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 LocalFixtureTestClass
22+
{
23+
public:
24+
LocalFixtureTestClass() : 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+
LocalFixtureTestClass g_local_test_class;
43+
}
44+
45+
// Extra setup and teardown for verifying that multiple fixtures
46+
// access the correct classes.
47+
TEST_SETUP(LocalFixtureTestClass)
48+
{
49+
g_local_test_class.SetValue(2);
50+
}
51+
52+
TEST_TEARDOWN(LocalFixtureTestClass)
53+
{
54+
g_local_test_class.SetValue(-2);
55+
}
56+
57+
TEST_MEMBER_FUNCTION(LocalFixtureTestClass, GetValue, NA)
58+
{
59+
LocalFixtureTestClass local_test_class;
60+
CHECK_EQUAL(g_local_test_class.GetValue(), 2);
61+
CHECK_EQUAL(local_test_class.GetValue(), 0);
62+
local_test_class = g_local_test_class;
63+
CHECK_EQUAL(local_test_class.GetValue(), 2);
64+
}
65+
66+
TEST_MEMBER_FUNCTION(LocalFixtureTestClass, SetValue, int)
67+
{
68+
LocalFixtureTestClass local_test_class;
69+
CHECK_EQUAL(g_local_test_class.GetValue(), 2);
70+
CHECK_EQUAL(local_test_class.GetValue(), 0);
71+
local_test_class.SetValue(4);
72+
CHECK_EQUAL(local_test_class.GetValue(), 4);
73+
}

test/unit_tests/TestMacros.tests.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ namespace
3838
private:
3939
int m_value;
4040
};
41-
}
4241

43-
LocalTestClass g_local_test_class;
42+
LocalTestClass g_local_test_class;
43+
}
4444

4545
TEST_SETUP(LocalTestClass)
4646
{
@@ -49,6 +49,7 @@ TEST_SETUP(LocalTestClass)
4949

5050
TEST_TEARDOWN(LocalTestClass)
5151
{
52+
g_local_test_class.SetValue(-1);
5253
}
5354

5455
TEST_MEMBER_FUNCTION(LocalTestClass, GetValue, NA)
@@ -65,6 +66,6 @@ TEST_MEMBER_FUNCTION(LocalTestClass, SetValue, int)
6566
LocalTestClass local_test_class;
6667
CHECK_EQUAL(g_local_test_class.GetValue(), 1);
6768
CHECK_EQUAL(local_test_class.GetValue(), 0);
68-
local_test_class.SetValue(2);
69-
CHECK_EQUAL(local_test_class.GetValue(), 2);
69+
local_test_class.SetValue(3);
70+
CHECK_EQUAL(local_test_class.GetValue(), 3);
7071
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
</ItemDefinitionGroup>
155155
<ItemGroup>
156156
<ClCompile Include="..\..\..\TestClass.tests.cpp" />
157+
<ClCompile Include="..\..\..\TestFixtures.tests.cpp" />
157158
<ClCompile Include="..\..\..\TestMacros.tests.cpp" />
158159
<ClCompile Include="..\..\..\TestCompare.tests.cpp" />
159160
<ClCompile Include="..\..\..\TestConverterUtility.tests.cpp" />

0 commit comments

Comments
 (0)