diff options
author | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-09-08 17:55:52 (GMT) |
---|---|---|
committer | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-09-08 17:55:52 (GMT) |
commit | a2b1a8556ea64014606d78b09333d9c522430a25 (patch) | |
tree | a4f4a88d89b4f957655a479bba3f33908572fcb5 /test | |
parent | 0c5a66245b8c5939b36b2aad6f4d5ab89b724b1a (diff) | |
download | googletest-a2b1a8556ea64014606d78b09333d9c522430a25.zip googletest-a2b1a8556ea64014606d78b09333d9c522430a25.tar.gz googletest-a2b1a8556ea64014606d78b09333d9c522430a25.tar.bz2 |
Adds support for type-parameterized tests (by Zhanyong Wan); also adds case-insensitive wide string comparison to the String class (by Vlad Losev).
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest_nc.cc | 78 | ||||
-rwxr-xr-x | test/gtest_nc_test.py | 12 | ||||
-rwxr-xr-x | test/gtest_output_test.py | 2 | ||||
-rw-r--r-- | test/gtest_output_test_.cc | 91 | ||||
-rw-r--r-- | test/gtest_output_test_golden_lin.txt | 58 | ||||
-rw-r--r-- | test/gtest_output_test_golden_win.txt | 40 | ||||
-rw-r--r-- | test/gtest_unittest.cc | 76 |
7 files changed, 346 insertions, 11 deletions
diff --git a/test/gtest_nc.cc b/test/gtest_nc.cc index 001deb1..5cbaeef 100644 --- a/test/gtest_nc.cc +++ b/test/gtest_nc.cc @@ -103,6 +103,84 @@ class MyEnvironment : public testing::Environment { } }; +#elif defined(TEST_CATCHES_WRONG_CASE_IN_TYPED_TEST_P) +// Tests that the compiler catches using the wrong test case name in +// TYPED_TEST_P. + +#include <gtest/gtest.h> + +template <typename T> +class FooTest : public testing::Test { +}; + +template <typename T> +class BarTest : public testing::Test { +}; + +TYPED_TEST_CASE_P(FooTest); +TYPED_TEST_P(BarTest, A) {} // Wrong test case name. +REGISTER_TYPED_TEST_CASE_P(FooTest, A); +INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, testing::Types<int>); + +#elif defined(TEST_CATCHES_WRONG_CASE_IN_REGISTER_TYPED_TEST_CASE_P) +// Tests that the compiler catches using the wrong test case name in +// REGISTER_TYPED_TEST_CASE_P. + +#include <gtest/gtest.h> + +template <typename T> +class FooTest : public testing::Test { +}; + +template <typename T> +class BarTest : public testing::Test { +}; + +TYPED_TEST_CASE_P(FooTest); +TYPED_TEST_P(FooTest, A) {} +REGISTER_TYPED_TEST_CASE_P(BarTest, A); // Wrong test case name. +INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, testing::Types<int>); + +#elif defined(TEST_CATCHES_WRONG_CASE_IN_INSTANTIATE_TYPED_TEST_CASE_P) +// Tests that the compiler catches using the wrong test case name in +// INSTANTIATE_TYPED_TEST_CASE_P. + +#include <gtest/gtest.h> + +template <typename T> +class FooTest : public testing::Test { +}; + +template <typename T> +class BarTest : public testing::Test { +}; + +TYPED_TEST_CASE_P(FooTest); +TYPED_TEST_P(FooTest, A) {} +REGISTER_TYPED_TEST_CASE_P(FooTest, A); + +// Wrong test case name. +INSTANTIATE_TYPED_TEST_CASE_P(My, BarTest, testing::Types<int>); + +#elif defined(TEST_CATCHES_INSTANTIATE_TYPED_TESET_CASE_P_WITH_SAME_NAME_PREFIX) +// Tests that the compiler catches instantiating TYPED_TEST_CASE_P +// twice with the same name prefix. + +#include <gtest/gtest.h> + +template <typename T> +class FooTest : public testing::Test { +}; + +TYPED_TEST_CASE_P(FooTest); +TYPED_TEST_P(FooTest, A) {} +REGISTER_TYPED_TEST_CASE_P(FooTest, A); + +INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, testing::Types<int>); + +// Wrong name prefix: "My" has been used. +INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, testing::Types<double>); + #else // A sanity test. This should compile. diff --git a/test/gtest_nc_test.py b/test/gtest_nc_test.py index f63feaa..683bd37 100755 --- a/test/gtest_nc_test.py +++ b/test/gtest_nc_test.py @@ -66,6 +66,18 @@ class GTestNCTest(unittest.TestCase): ('CATCHES_CALLING_SETUP_IN_ENVIRONMENT_WITH_TYPO', [r'Setup_should_be_spelled_SetUp']), + ('CATCHES_WRONG_CASE_IN_TYPED_TEST_P', + [r'BarTest.*was not declared']), + + ('CATCHES_WRONG_CASE_IN_REGISTER_TYPED_TEST_CASE_P', + [r'BarTest.*was not declared']), + + ('CATCHES_WRONG_CASE_IN_INSTANTIATE_TYPED_TEST_CASE_P', + [r'BarTest.*not declared']), + + ('CATCHES_INSTANTIATE_TYPED_TESET_CASE_P_WITH_SAME_NAME_PREFIX', + [r'redefinition of.*My.*FooTest']), + ('SANITY', None) ] diff --git a/test/gtest_output_test.py b/test/gtest_output_test.py index 05f49dc..f91050c 100755 --- a/test/gtest_output_test.py +++ b/test/gtest_output_test.py @@ -32,6 +32,8 @@ """Tests the text output of Google C++ Testing Framework. SYNOPSIS + gtest_output_test.py --gtest_build_dir=BUILD/DIR --gengolden + # where BUILD/DIR contains the built gtest_output_test_ file. gtest_output_test.py --gengolden gtest_output_test.py """ diff --git a/test/gtest_output_test_.cc b/test/gtest_output_test_.cc index d9f3f9e..758e18d 100644 --- a/test/gtest_output_test_.cc +++ b/test/gtest_output_test_.cc @@ -699,6 +699,97 @@ TEST(ExpectFatalFailureTest, FailsWhenStatementThrows) { #endif // GTEST_HAS_EXCEPTIONS +// This #ifdef block tests the output of typed tests. +#ifdef GTEST_HAS_TYPED_TEST + +template <typename T> +class TypedTest : public testing::Test { +}; + +TYPED_TEST_CASE(TypedTest, testing::Types<int>); + +TYPED_TEST(TypedTest, Success) { + EXPECT_EQ(0, TypeParam()); +} + +TYPED_TEST(TypedTest, Failure) { + EXPECT_EQ(1, TypeParam()) << "Expected failure"; +} + +#endif // GTEST_HAS_TYPED_TEST + +// This #ifdef block tests the output of type-parameterized tests. +#ifdef GTEST_HAS_TYPED_TEST_P + +template <typename T> +class TypedTestP : public testing::Test { +}; + +TYPED_TEST_CASE_P(TypedTestP); + +TYPED_TEST_P(TypedTestP, Success) { + EXPECT_EQ(0, TypeParam()); +} + +TYPED_TEST_P(TypedTestP, Failure) { + EXPECT_EQ(1, TypeParam()) << "Expected failure"; +} + +REGISTER_TYPED_TEST_CASE_P(TypedTestP, Success, Failure); + +typedef testing::Types<unsigned char, unsigned int> UnsignedTypes; +INSTANTIATE_TYPED_TEST_CASE_P(Unsigned, TypedTestP, UnsignedTypes); + +#endif // GTEST_HAS_TYPED_TEST_P + +#ifdef GTEST_HAS_DEATH_TEST + +// We rely on the golden file to verify that tests whose test case +// name ends with DeathTest are run first. + +TEST(ADeathTest, ShouldRunFirst) { +} + +#ifdef GTEST_HAS_TYPED_TEST + +// We rely on the golden file to verify that typed tests whose test +// case name ends with DeathTest are run first. + +template <typename T> +class ATypedDeathTest : public testing::Test { +}; + +typedef testing::Types<int, double> NumericTypes; +TYPED_TEST_CASE(ATypedDeathTest, NumericTypes); + +TYPED_TEST(ATypedDeathTest, ShouldRunFirst) { +} + +#endif // GTEST_HAS_TYPED_TEST + +#ifdef GTEST_HAS_TYPED_TEST_P + + +// We rely on the golden file to verify that type-parameterized tests +// whose test case name ends with DeathTest are run first. + +template <typename T> +class ATypeParamDeathTest : public testing::Test { +}; + +TYPED_TEST_CASE_P(ATypeParamDeathTest); + +TYPED_TEST_P(ATypeParamDeathTest, ShouldRunFirst) { +} + +REGISTER_TYPED_TEST_CASE_P(ATypeParamDeathTest, ShouldRunFirst); + +INSTANTIATE_TYPED_TEST_CASE_P(My, ATypeParamDeathTest, NumericTypes); + +#endif // GTEST_HAS_TYPED_TEST_P + +#endif // GTEST_HAS_DEATH_TEST + // Two test environments for testing testing::AddGlobalTestEnvironment(). class FooEnvironment : public testing::Environment { diff --git a/test/gtest_output_test_golden_lin.txt b/test/gtest_output_test_golden_lin.txt index 1da3bf3..e068bd2 100644 --- a/test/gtest_output_test_golden_lin.txt +++ b/test/gtest_output_test_golden_lin.txt @@ -7,10 +7,25 @@ Expected: true gtest_output_test_.cc:#: Failure Value of: 3 Expected: 2 -[0;32m[==========] [mRunning 37 tests from 13 test cases. +[0;32m[==========] [mRunning 48 tests from 21 test cases. [0;32m[----------] [mGlobal test environment set-up. FooEnvironment::SetUp() called. BarEnvironment::SetUp() called. +[0;32m[----------] [m1 test from ADeathTest +[0;32m[ RUN ] [mADeathTest.ShouldRunFirst +[0;32m[ OK ] [mADeathTest.ShouldRunFirst +[0;32m[----------] [m1 test from ATypedDeathTest/0, where TypeParam = int +[0;32m[ RUN ] [mATypedDeathTest/0.ShouldRunFirst +[0;32m[ OK ] [mATypedDeathTest/0.ShouldRunFirst +[0;32m[----------] [m1 test from ATypedDeathTest/1, where TypeParam = double +[0;32m[ RUN ] [mATypedDeathTest/1.ShouldRunFirst +[0;32m[ OK ] [mATypedDeathTest/1.ShouldRunFirst +[0;32m[----------] [m1 test from My/ATypeParamDeathTest/0, where TypeParam = int +[0;32m[ RUN ] [mMy/ATypeParamDeathTest/0.ShouldRunFirst +[0;32m[ OK ] [mMy/ATypeParamDeathTest/0.ShouldRunFirst +[0;32m[----------] [m1 test from My/ATypeParamDeathTest/1, where TypeParam = double +[0;32m[ RUN ] [mMy/ATypeParamDeathTest/1.ShouldRunFirst +[0;32m[ OK ] [mMy/ATypeParamDeathTest/1.ShouldRunFirst [0;32m[----------] [m3 tests from FatalFailureTest [0;32m[ RUN ] [mFatalFailureTest.FatalFailureInSubroutine (expecting a failure that x should be 1) @@ -341,6 +356,36 @@ gtest.cc:#: Failure Expected: 1 fatal failure Actual: 0 failures [0;31m[ FAILED ] [mExpectFatalFailureTest.FailsWhenStatementReturns +[0;32m[----------] [m2 tests from TypedTest/0, where TypeParam = int +[0;32m[ RUN ] [mTypedTest/0.Success +[0;32m[ OK ] [mTypedTest/0.Success +[0;32m[ RUN ] [mTypedTest/0.Failure +gtest_output_test_.cc:#: Failure +Value of: TypeParam() + Actual: 0 +Expected: 1 +Expected failure +[0;31m[ FAILED ] [mTypedTest/0.Failure +[0;32m[----------] [m2 tests from Unsigned/TypedTestP/0, where TypeParam = unsigned char +[0;32m[ RUN ] [mUnsigned/TypedTestP/0.Success +[0;32m[ OK ] [mUnsigned/TypedTestP/0.Success +[0;32m[ RUN ] [mUnsigned/TypedTestP/0.Failure +gtest_output_test_.cc:#: Failure +Value of: TypeParam() + Actual: \0 +Expected: 1 +Expected failure +[0;31m[ FAILED ] [mUnsigned/TypedTestP/0.Failure +[0;32m[----------] [m2 tests from Unsigned/TypedTestP/1, where TypeParam = unsigned int +[0;32m[ RUN ] [mUnsigned/TypedTestP/1.Success +[0;32m[ OK ] [mUnsigned/TypedTestP/1.Success +[0;32m[ RUN ] [mUnsigned/TypedTestP/1.Failure +gtest_output_test_.cc:#: Failure +Value of: TypeParam() + Actual: 0 +Expected: 1 +Expected failure +[0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure [0;32m[----------] [mGlobal test environment tear-down BarEnvironment::TearDown() called. gtest_output_test_.cc:#: Failure @@ -350,9 +395,9 @@ FooEnvironment::TearDown() called. gtest_output_test_.cc:#: Failure Failed Expected fatal failure. -[0;32m[==========] [m37 tests from 13 test cases ran. -[0;32m[ PASSED ] [m11 tests. -[0;31m[ FAILED ] [m26 tests, listed below: +[0;32m[==========] [m48 tests from 21 test cases ran. +[0;32m[ PASSED ] [m19 tests. +[0;31m[ FAILED ] [m29 tests, listed below: [0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine [0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInNestedSubroutine [0;31m[ FAILED ] [mFatalFailureTest.NonfatalFailureInSubroutine @@ -379,8 +424,11 @@ Expected fatal failure. [0;31m[ FAILED ] [mExpectFatalFailureTest.FailsWhenThereAreTwoFatalFailures [0;31m[ FAILED ] [mExpectFatalFailureTest.FailsWhenThereIsOneNonfatalFailure [0;31m[ FAILED ] [mExpectFatalFailureTest.FailsWhenStatementReturns +[0;31m[ FAILED ] [mTypedTest/0.Failure, where TypeParam = int +[0;31m[ FAILED ] [mUnsigned/TypedTestP/0.Failure, where TypeParam = unsigned char +[0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure, where TypeParam = unsigned int -26 FAILED TESTS +29 FAILED TESTS The non-test part of the code is expected to have 2 failures. gtest_output_test_.cc:#: Failure diff --git a/test/gtest_output_test_golden_win.txt b/test/gtest_output_test_golden_win.txt index 9a13da9..b88b85e 100644 --- a/test/gtest_output_test_golden_win.txt +++ b/test/gtest_output_test_golden_win.txt @@ -5,7 +5,7 @@ gtest_output_test_.cc:#: error: Value of: false Expected: true gtest_output_test_.cc:#: error: Value of: 3 Expected: 2 -[==========] Running 40 tests from 16 test cases. +[==========] Running 46 tests from 19 test cases. [----------] Global test environment set-up. FooEnvironment::SetUp() called. BarEnvironment::SetUp() called. @@ -317,6 +317,33 @@ Expected non-fatal failure. gtest.cc:#: error: Expected: 1 fatal failure Actual: 0 failures [ FAILED ] ExpectFatalFailureTest.FailsWhenStatementReturns +[----------] 2 tests from TypedTest/0, where TypeParam = int +[ RUN ] TypedTest/0.Success +[ OK ] TypedTest/0.Success +[ RUN ] TypedTest/0.Failure +gtest_output_test_.cc:#: error: Value of: TypeParam() + Actual: 0 +Expected: 1 +Expected failure +[ FAILED ] TypedTest/0.Failure +[----------] 2 tests from Unsigned/TypedTestP/0, where TypeParam = unsigned char +[ RUN ] Unsigned/TypedTestP/0.Success +[ OK ] Unsigned/TypedTestP/0.Success +[ RUN ] Unsigned/TypedTestP/0.Failure +gtest_output_test_.cc:#: error: Value of: TypeParam() + Actual: \0 +Expected: 1 +Expected failure +[ FAILED ] Unsigned/TypedTestP/0.Failure +[----------] 2 tests from Unsigned/TypedTestP/1, where TypeParam = unsigned int +[ RUN ] Unsigned/TypedTestP/1.Success +[ OK ] Unsigned/TypedTestP/1.Success +[ RUN ] Unsigned/TypedTestP/1.Failure +gtest_output_test_.cc:#: error: Value of: TypeParam() + Actual: 0 +Expected: 1 +Expected failure +[ FAILED ] Unsigned/TypedTestP/1.Failure [----------] Global test environment tear-down BarEnvironment::TearDown() called. gtest_output_test_.cc:#: error: Failed @@ -324,9 +351,9 @@ Expected non-fatal failure. FooEnvironment::TearDown() called. gtest_output_test_.cc:#: error: Failed Expected fatal failure. -[==========] 40 tests from 16 test cases ran. -[ PASSED ] 11 tests. -[ FAILED ] 29 tests, listed below: +[==========] 46 tests from 19 test cases ran. +[ PASSED ] 14 tests. +[ FAILED ] 32 tests, listed below: [ FAILED ] FatalFailureTest.FatalFailureInSubroutine [ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine [ FAILED ] FatalFailureTest.NonfatalFailureInSubroutine @@ -356,8 +383,11 @@ Expected fatal failure. [ FAILED ] ExpectFatalFailureTest.FailsWhenThereAreTwoFatalFailures [ FAILED ] ExpectFatalFailureTest.FailsWhenThereIsOneNonfatalFailure [ FAILED ] ExpectFatalFailureTest.FailsWhenStatementReturns +[ FAILED ] TypedTest/0.Failure, where TypeParam = int +[ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char +[ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int -29 FAILED TESTS +32 FAILED TESTS The non-test part of the code is expected to have 2 failures. gtest_output_test_.cc:#: error: Value of: false diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc index eecaf4e..7c5123c 100644 --- a/test/gtest_unittest.cc +++ b/test/gtest_unittest.cc @@ -529,6 +529,18 @@ TEST(StringTest, EndsWithCaseInsensitive) { EXPECT_FALSE(String("").EndsWithCaseInsensitive("foo")); } +// Tests String::CaseInsensitiveWideCStringEquals +TEST(StringTest, CaseInsensitiveWideCStringEquals) { + EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(NULL, NULL)); + EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(NULL, L"")); + EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L"", NULL)); + EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(NULL, L"foobar")); + EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L"foobar", NULL)); + EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"foobar", L"foobar")); + EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"foobar", L"FOOBAR")); + EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"FOOBAR", L"foobar")); +} + // Tests that NULL can be assigned to a String. TEST(StringTest, CanBeAssignedNULL) { const String src(NULL); @@ -2134,6 +2146,68 @@ TEST_F(DisabledTestsTest, DISABLED_TestShouldNotRun_2) { FAIL() << "Unexpected failure: Disabled test should not be run."; } +// Tests that disabled typed tests aren't run. + +#ifdef GTEST_HAS_TYPED_TEST + +template <typename T> +class TypedTest : public Test { +}; + +typedef testing::Types<int, double> NumericTypes; +TYPED_TEST_CASE(TypedTest, NumericTypes); + +TYPED_TEST(TypedTest, DISABLED_ShouldNotRun) { + FAIL() << "Unexpected failure: Disabled typed test should not run."; +} + +template <typename T> +class DISABLED_TypedTest : public Test { +}; + +TYPED_TEST_CASE(DISABLED_TypedTest, NumericTypes); + +TYPED_TEST(DISABLED_TypedTest, ShouldNotRun) { + FAIL() << "Unexpected failure: Disabled typed test should not run."; +} + +#endif // GTEST_HAS_TYPED_TEST + +// Tests that disabled type-parameterized tests aren't run. + +#ifdef GTEST_HAS_TYPED_TEST_P + +template <typename T> +class TypedTestP : public Test { +}; + +TYPED_TEST_CASE_P(TypedTestP); + +TYPED_TEST_P(TypedTestP, DISABLED_ShouldNotRun) { + FAIL() << "Unexpected failure: " + << "Disabled type-parameterized test should not run."; +} + +REGISTER_TYPED_TEST_CASE_P(TypedTestP, DISABLED_ShouldNotRun); + +INSTANTIATE_TYPED_TEST_CASE_P(My, TypedTestP, NumericTypes); + +template <typename T> +class DISABLED_TypedTestP : public Test { +}; + +TYPED_TEST_CASE_P(DISABLED_TypedTestP); + +TYPED_TEST_P(DISABLED_TypedTestP, ShouldNotRun) { + FAIL() << "Unexpected failure: " + << "Disabled type-parameterized test should not run."; +} + +REGISTER_TYPED_TEST_CASE_P(DISABLED_TypedTestP, ShouldNotRun); + +INSTANTIATE_TYPED_TEST_CASE_P(My, DISABLED_TypedTestP, NumericTypes); + +#endif // GTEST_HAS_TYPED_TEST_P // Tests that assertion macros evaluate their arguments exactly once. @@ -3491,7 +3565,7 @@ class TestInfoTest : public Test { protected: static TestInfo * GetTestInfo(const char* test_name) { return UnitTest::GetInstance()->impl()-> - GetTestCase("TestInfoTest", NULL, NULL)-> + GetTestCase("TestInfoTest", "", NULL, NULL)-> GetTestInfo(test_name); } |