Debian Codegraph @

tests/CppUTestExt/GTest2ConvertorTest.cpp

raw symbols SCIP
1 /*
2 * Copyright (c) 2011, Michael Feathers, James Grenning and Bas Vodde
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the <organization> nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifdef CPPUTEST_INCLUDE_GTEST_TESTS
29
30 #include "CppUTestExt/GTestConvertor.h"
31
32 class GTestTestingFixtureTest : public testing::Test {
33 protected:
34 bool setup_was_called;
35 char* freed_during_teardown;
36
37 void SetUp()
38 {
39 setup_was_called = true;
40 freed_during_teardown = NULL;
41 }
42
43 void TearDown()
44 {
45 delete [] freed_during_teardown;
46 }
47 };
48
49 TEST_F(GTestTestingFixtureTest, setupBeenCalled)
50 {
51 EXPECT_TRUE(setup_was_called);
52 }
53
54 TEST_F(GTestTestingFixtureTest, teardownMustBeCalledOrElseThisWillLeak)
55 {
56 freed_during_teardown = new char[100];
57 }
58
59 #endif
60
61 #undef TEST
62
63 #include "CppUTest/TestHarness.h"
64 #include "CppUTest/TestRegistry.h"
65 #include "CppUTest/TestTestingFixture.h"
66
67 TEST_GROUP(GTestConvertor)
68 {
69 };
70
71 #ifdef CPPUTEST_INCLUDE_GTEST_TESTS
72
73 /*
74 * These tests depend on the amount of GTests that are actually added (also in other files).
75 * This is due to the singleton in gtest.
76 *
77 */
78
79 TEST(GTestConvertor, correctNumberOfTestCases)
80 {
81 LONGS_EQUAL(2, ::testing::UnitTest::GetInstance()->total_test_case_count());
82 CHECK(::testing::UnitTest::GetInstance()->GetTestCase(0));
83 CHECK(::testing::UnitTest::GetInstance()->GetTestCase(1));
84 CHECK(::testing::UnitTest::GetInstance()->GetTestCase(2) == NULL);
85 }
86
87 TEST(GTestConvertor, correctNumberOfTestsInTheTestCases)
88 {
89 const ::testing::TestCase* firstTestCase = ::testing::UnitTest::GetInstance()->GetTestCase(0);
90 const ::testing::TestCase* secondTestCase = ::testing::UnitTest::GetInstance()->GetTestCase(1);
91
92 STRCMP_EQUAL("GTestSimpleTest", firstTestCase->name());
93 STRCMP_EQUAL("GTestTestingFixtureTest", secondTestCase->name());
94 LONGS_EQUAL(7, firstTestCase->total_test_count());
95 LONGS_EQUAL(2, secondTestCase->total_test_count());
96 }
97
98 TEST(GTestConvertor, testsGetAddedToCurrentTestRegistry)
99 {
100 TestTestingFixture fixture;
101 TestRegistry::getCurrentRegistry()->unDoLastAddTest();
102
103 GTestConvertor convertor(false);
104 convertor.addAllGTestToTestRegistry();
105
106 LONGS_EQUAL(9, TestRegistry::getCurrentRegistry()->countTests());
107 }
108
109 #endif