diff options
author | Gennadiy Civil <misterg@google.com> | 2018-02-23 15:47:11 (GMT) |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2018-02-23 15:47:11 (GMT) |
commit | b7e0294c5133a2d5c52a740375a05c7e5e0878fb (patch) | |
tree | 4319fb53631d7fc0dedb1bcd716c42c2867c4428 /googletest/test | |
parent | 70e1aad72c4980039ae6835abd4fb2bc9dde7031 (diff) | |
download | googletest-b7e0294c5133a2d5c52a740375a05c7e5e0878fb.zip googletest-b7e0294c5133a2d5c52a740375a05c7e5e0878fb.tar.gz googletest-b7e0294c5133a2d5c52a740375a05c7e5e0878fb.tar.bz2 |
merging unitestsrefs/pull/1473/head
Diffstat (limited to 'googletest/test')
-rw-r--r-- | googletest/test/gtest_unittest.cc | 125 |
1 files changed, 63 insertions, 62 deletions
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 2ea3ca4..a5743fc 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -5454,7 +5454,8 @@ TEST_F(SetUpTestCaseTest, Test2) { EXPECT_STREQ("123", shared_resource_); } -// The InitGoogleTestTest test case tests testing::InitGoogleTest(). + +// The ParseFlagsTest test case tests ParseGoogleTestFlagsOnly. // The Flags struct stores a copy of all Google Test flags. struct Flags { @@ -5540,8 +5541,8 @@ struct Flags { return flags; } - // Creates a Flags struct where the gtest_random_seed flag has - // the given value. + // Creates a Flags struct where the gtest_random_seed flag has the given + // value. static Flags RandomSeed(Int32 random_seed) { Flags flags; flags.random_seed = random_seed; @@ -5556,8 +5557,8 @@ struct Flags { return flags; } - // Creates a Flags struct where the gtest_shuffle flag has - // the given value. + // Creates a Flags struct where the gtest_shuffle flag has the given + // value. static Flags Shuffle(bool shuffle) { Flags flags; flags.shuffle = shuffle; @@ -5605,8 +5606,8 @@ struct Flags { bool throw_on_failure; }; -// Fixture for testing InitGoogleTest(). -class InitGoogleTestTest : public Test { +// Fixture for testing ParseGoogleTestFlagsOnly(). +class ParseFlagsTest : public Test { protected: // Clears the flags before each test. virtual void SetUp() { @@ -5667,16 +5668,16 @@ class InitGoogleTestTest : public Test { const bool saved_help_flag = ::testing::internal::g_help_flag; ::testing::internal::g_help_flag = false; -#if GTEST_HAS_STREAM_REDIRECTION +# if GTEST_HAS_STREAM_REDIRECTION CaptureStdout(); -#endif +# endif // Parses the command line. internal::ParseGoogleTestFlagsOnly(&argc1, const_cast<CharType**>(argv1)); -#if GTEST_HAS_STREAM_REDIRECTION +# if GTEST_HAS_STREAM_REDIRECTION const std::string captured_stdout = GetCapturedStdout(); -#endif +# endif // Verifies the flag values. CheckFlags(expected); @@ -5689,7 +5690,7 @@ class InitGoogleTestTest : public Test { // help message for the flags it recognizes. EXPECT_EQ(should_print_help, ::testing::internal::g_help_flag); -#if GTEST_HAS_STREAM_REDIRECTION +# if GTEST_HAS_STREAM_REDIRECTION const char* const expected_help_fragment = "This program contains tests written using"; if (should_print_help) { @@ -5698,7 +5699,7 @@ class InitGoogleTestTest : public Test { EXPECT_PRED_FORMAT2(IsNotSubstring, expected_help_fragment, captured_stdout); } -#endif // GTEST_HAS_STREAM_REDIRECTION +# endif // GTEST_HAS_STREAM_REDIRECTION ::testing::internal::g_help_flag = saved_help_flag; } @@ -5706,14 +5707,14 @@ class InitGoogleTestTest : public Test { // This macro wraps TestParsingFlags s.t. the user doesn't need // to specify the array sizes. -#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \ +# define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \ TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \ sizeof(argv2)/sizeof(*argv2) - 1, argv2, \ expected, should_print_help) }; // Tests parsing an empty command line. -TEST_F(InitGoogleTestTest, Empty) { +TEST_F(ParseFlagsTest, Empty) { const char* argv[] = { NULL }; @@ -5726,7 +5727,7 @@ TEST_F(InitGoogleTestTest, Empty) { } // Tests parsing a command line that has no flag. -TEST_F(InitGoogleTestTest, NoFlag) { +TEST_F(ParseFlagsTest, NoFlag) { const char* argv[] = { "foo.exe", NULL @@ -5741,7 +5742,7 @@ TEST_F(InitGoogleTestTest, NoFlag) { } // Tests parsing a bad --gtest_filter flag. -TEST_F(InitGoogleTestTest, FilterBad) { +TEST_F(ParseFlagsTest, FilterBad) { const char* argv[] = { "foo.exe", "--gtest_filter", @@ -5758,7 +5759,7 @@ TEST_F(InitGoogleTestTest, FilterBad) { } // Tests parsing an empty --gtest_filter flag. -TEST_F(InitGoogleTestTest, FilterEmpty) { +TEST_F(ParseFlagsTest, FilterEmpty) { const char* argv[] = { "foo.exe", "--gtest_filter=", @@ -5774,7 +5775,7 @@ TEST_F(InitGoogleTestTest, FilterEmpty) { } // Tests parsing a non-empty --gtest_filter flag. -TEST_F(InitGoogleTestTest, FilterNonEmpty) { +TEST_F(ParseFlagsTest, FilterNonEmpty) { const char* argv[] = { "foo.exe", "--gtest_filter=abc", @@ -5790,7 +5791,7 @@ TEST_F(InitGoogleTestTest, FilterNonEmpty) { } // Tests parsing --gtest_break_on_failure. -TEST_F(InitGoogleTestTest, BreakOnFailureWithoutValue) { +TEST_F(ParseFlagsTest, BreakOnFailureWithoutValue) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure", @@ -5806,7 +5807,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureWithoutValue) { } // Tests parsing --gtest_break_on_failure=0. -TEST_F(InitGoogleTestTest, BreakOnFailureFalse_0) { +TEST_F(ParseFlagsTest, BreakOnFailureFalse_0) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure=0", @@ -5822,7 +5823,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureFalse_0) { } // Tests parsing --gtest_break_on_failure=f. -TEST_F(InitGoogleTestTest, BreakOnFailureFalse_f) { +TEST_F(ParseFlagsTest, BreakOnFailureFalse_f) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure=f", @@ -5838,7 +5839,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureFalse_f) { } // Tests parsing --gtest_break_on_failure=F. -TEST_F(InitGoogleTestTest, BreakOnFailureFalse_F) { +TEST_F(ParseFlagsTest, BreakOnFailureFalse_F) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure=F", @@ -5855,7 +5856,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureFalse_F) { // Tests parsing a --gtest_break_on_failure flag that has a "true" // definition. -TEST_F(InitGoogleTestTest, BreakOnFailureTrue) { +TEST_F(ParseFlagsTest, BreakOnFailureTrue) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure=1", @@ -5871,7 +5872,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureTrue) { } // Tests parsing --gtest_catch_exceptions. -TEST_F(InitGoogleTestTest, CatchExceptions) { +TEST_F(ParseFlagsTest, CatchExceptions) { const char* argv[] = { "foo.exe", "--gtest_catch_exceptions", @@ -5887,7 +5888,7 @@ TEST_F(InitGoogleTestTest, CatchExceptions) { } // Tests parsing --gtest_death_test_use_fork. -TEST_F(InitGoogleTestTest, DeathTestUseFork) { +TEST_F(ParseFlagsTest, DeathTestUseFork) { const char* argv[] = { "foo.exe", "--gtest_death_test_use_fork", @@ -5904,7 +5905,7 @@ TEST_F(InitGoogleTestTest, DeathTestUseFork) { // Tests having the same flag twice with different values. The // expected behavior is that the one coming last takes precedence. -TEST_F(InitGoogleTestTest, DuplicatedFlags) { +TEST_F(ParseFlagsTest, DuplicatedFlags) { const char* argv[] = { "foo.exe", "--gtest_filter=a", @@ -5921,7 +5922,7 @@ TEST_F(InitGoogleTestTest, DuplicatedFlags) { } // Tests having an unrecognized flag on the command line. -TEST_F(InitGoogleTestTest, UnrecognizedFlag) { +TEST_F(ParseFlagsTest, UnrecognizedFlag) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure", @@ -5943,7 +5944,7 @@ TEST_F(InitGoogleTestTest, UnrecognizedFlag) { } // Tests having a --gtest_list_tests flag -TEST_F(InitGoogleTestTest, ListTestsFlag) { +TEST_F(ParseFlagsTest, ListTestsFlag) { const char* argv[] = { "foo.exe", "--gtest_list_tests", @@ -5959,7 +5960,7 @@ TEST_F(InitGoogleTestTest, ListTestsFlag) { } // Tests having a --gtest_list_tests flag with a "true" value -TEST_F(InitGoogleTestTest, ListTestsTrue) { +TEST_F(ParseFlagsTest, ListTestsTrue) { const char* argv[] = { "foo.exe", "--gtest_list_tests=1", @@ -5975,7 +5976,7 @@ TEST_F(InitGoogleTestTest, ListTestsTrue) { } // Tests having a --gtest_list_tests flag with a "false" value -TEST_F(InitGoogleTestTest, ListTestsFalse) { +TEST_F(ParseFlagsTest, ListTestsFalse) { const char* argv[] = { "foo.exe", "--gtest_list_tests=0", @@ -5991,7 +5992,7 @@ TEST_F(InitGoogleTestTest, ListTestsFalse) { } // Tests parsing --gtest_list_tests=f. -TEST_F(InitGoogleTestTest, ListTestsFalse_f) { +TEST_F(ParseFlagsTest, ListTestsFalse_f) { const char* argv[] = { "foo.exe", "--gtest_list_tests=f", @@ -6007,7 +6008,7 @@ TEST_F(InitGoogleTestTest, ListTestsFalse_f) { } // Tests parsing --gtest_list_tests=F. -TEST_F(InitGoogleTestTest, ListTestsFalse_F) { +TEST_F(ParseFlagsTest, ListTestsFalse_F) { const char* argv[] = { "foo.exe", "--gtest_list_tests=F", @@ -6023,7 +6024,7 @@ TEST_F(InitGoogleTestTest, ListTestsFalse_F) { } // Tests parsing --gtest_output (invalid). -TEST_F(InitGoogleTestTest, OutputEmpty) { +TEST_F(ParseFlagsTest, OutputEmpty) { const char* argv[] = { "foo.exe", "--gtest_output", @@ -6040,7 +6041,7 @@ TEST_F(InitGoogleTestTest, OutputEmpty) { } // Tests parsing --gtest_output=xml -TEST_F(InitGoogleTestTest, OutputXml) { +TEST_F(ParseFlagsTest, OutputXml) { const char* argv[] = { "foo.exe", "--gtest_output=xml", @@ -6056,7 +6057,7 @@ TEST_F(InitGoogleTestTest, OutputXml) { } // Tests parsing --gtest_output=xml:file -TEST_F(InitGoogleTestTest, OutputXmlFile) { +TEST_F(ParseFlagsTest, OutputXmlFile) { const char* argv[] = { "foo.exe", "--gtest_output=xml:file", @@ -6072,7 +6073,7 @@ TEST_F(InitGoogleTestTest, OutputXmlFile) { } // Tests parsing --gtest_output=xml:directory/path/ -TEST_F(InitGoogleTestTest, OutputXmlDirectory) { +TEST_F(ParseFlagsTest, OutputXmlDirectory) { const char* argv[] = { "foo.exe", "--gtest_output=xml:directory/path/", @@ -6089,7 +6090,7 @@ TEST_F(InitGoogleTestTest, OutputXmlDirectory) { } // Tests having a --gtest_print_time flag -TEST_F(InitGoogleTestTest, PrintTimeFlag) { +TEST_F(ParseFlagsTest, PrintTimeFlag) { const char* argv[] = { "foo.exe", "--gtest_print_time", @@ -6105,7 +6106,7 @@ TEST_F(InitGoogleTestTest, PrintTimeFlag) { } // Tests having a --gtest_print_time flag with a "true" value -TEST_F(InitGoogleTestTest, PrintTimeTrue) { +TEST_F(ParseFlagsTest, PrintTimeTrue) { const char* argv[] = { "foo.exe", "--gtest_print_time=1", @@ -6121,7 +6122,7 @@ TEST_F(InitGoogleTestTest, PrintTimeTrue) { } // Tests having a --gtest_print_time flag with a "false" value -TEST_F(InitGoogleTestTest, PrintTimeFalse) { +TEST_F(ParseFlagsTest, PrintTimeFalse) { const char* argv[] = { "foo.exe", "--gtest_print_time=0", @@ -6137,7 +6138,7 @@ TEST_F(InitGoogleTestTest, PrintTimeFalse) { } // Tests parsing --gtest_print_time=f. -TEST_F(InitGoogleTestTest, PrintTimeFalse_f) { +TEST_F(ParseFlagsTest, PrintTimeFalse_f) { const char* argv[] = { "foo.exe", "--gtest_print_time=f", @@ -6153,7 +6154,7 @@ TEST_F(InitGoogleTestTest, PrintTimeFalse_f) { } // Tests parsing --gtest_print_time=F. -TEST_F(InitGoogleTestTest, PrintTimeFalse_F) { +TEST_F(ParseFlagsTest, PrintTimeFalse_F) { const char* argv[] = { "foo.exe", "--gtest_print_time=F", @@ -6169,7 +6170,7 @@ TEST_F(InitGoogleTestTest, PrintTimeFalse_F) { } // Tests parsing --gtest_random_seed=number -TEST_F(InitGoogleTestTest, RandomSeed) { +TEST_F(ParseFlagsTest, RandomSeed) { const char* argv[] = { "foo.exe", "--gtest_random_seed=1000", @@ -6185,7 +6186,7 @@ TEST_F(InitGoogleTestTest, RandomSeed) { } // Tests parsing --gtest_repeat=number -TEST_F(InitGoogleTestTest, Repeat) { +TEST_F(ParseFlagsTest, Repeat) { const char* argv[] = { "foo.exe", "--gtest_repeat=1000", @@ -6201,7 +6202,7 @@ TEST_F(InitGoogleTestTest, Repeat) { } // Tests having a --gtest_also_run_disabled_tests flag -TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFlag) { +TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFlag) { const char* argv[] = { "foo.exe", "--gtest_also_run_disabled_tests", @@ -6218,7 +6219,7 @@ TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFlag) { } // Tests having a --gtest_also_run_disabled_tests flag with a "true" value -TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsTrue) { +TEST_F(ParseFlagsTest, AlsoRunDisabledTestsTrue) { const char* argv[] = { "foo.exe", "--gtest_also_run_disabled_tests=1", @@ -6235,7 +6236,7 @@ TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsTrue) { } // Tests having a --gtest_also_run_disabled_tests flag with a "false" value -TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFalse) { +TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFalse) { const char* argv[] = { "foo.exe", "--gtest_also_run_disabled_tests=0", @@ -6252,7 +6253,7 @@ TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFalse) { } // Tests parsing --gtest_shuffle. -TEST_F(InitGoogleTestTest, ShuffleWithoutValue) { +TEST_F(ParseFlagsTest, ShuffleWithoutValue) { const char* argv[] = { "foo.exe", "--gtest_shuffle", @@ -6268,7 +6269,7 @@ TEST_F(InitGoogleTestTest, ShuffleWithoutValue) { } // Tests parsing --gtest_shuffle=0. -TEST_F(InitGoogleTestTest, ShuffleFalse_0) { +TEST_F(ParseFlagsTest, ShuffleFalse_0) { const char* argv[] = { "foo.exe", "--gtest_shuffle=0", @@ -6283,9 +6284,8 @@ TEST_F(InitGoogleTestTest, ShuffleFalse_0) { GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(false), false); } -// Tests parsing a --gtest_shuffle flag that has a "true" -// definition. -TEST_F(InitGoogleTestTest, ShuffleTrue) { +// Tests parsing a --gtest_shuffle flag that has a "true" definition. +TEST_F(ParseFlagsTest, ShuffleTrue) { const char* argv[] = { "foo.exe", "--gtest_shuffle=1", @@ -6301,7 +6301,7 @@ TEST_F(InitGoogleTestTest, ShuffleTrue) { } // Tests parsing --gtest_stack_trace_depth=number. -TEST_F(InitGoogleTestTest, StackTraceDepth) { +TEST_F(ParseFlagsTest, StackTraceDepth) { const char* argv[] = { "foo.exe", "--gtest_stack_trace_depth=5", @@ -6316,7 +6316,7 @@ TEST_F(InitGoogleTestTest, StackTraceDepth) { GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::StackTraceDepth(5), false); } -TEST_F(InitGoogleTestTest, StreamResultTo) { +TEST_F(ParseFlagsTest, StreamResultTo) { const char* argv[] = { "foo.exe", "--gtest_stream_result_to=localhost:1234", @@ -6333,7 +6333,7 @@ TEST_F(InitGoogleTestTest, StreamResultTo) { } // Tests parsing --gtest_throw_on_failure. -TEST_F(InitGoogleTestTest, ThrowOnFailureWithoutValue) { +TEST_F(ParseFlagsTest, ThrowOnFailureWithoutValue) { const char* argv[] = { "foo.exe", "--gtest_throw_on_failure", @@ -6349,7 +6349,7 @@ TEST_F(InitGoogleTestTest, ThrowOnFailureWithoutValue) { } // Tests parsing --gtest_throw_on_failure=0. -TEST_F(InitGoogleTestTest, ThrowOnFailureFalse_0) { +TEST_F(ParseFlagsTest, ThrowOnFailureFalse_0) { const char* argv[] = { "foo.exe", "--gtest_throw_on_failure=0", @@ -6366,7 +6366,7 @@ TEST_F(InitGoogleTestTest, ThrowOnFailureFalse_0) { // Tests parsing a --gtest_throw_on_failure flag that has a "true" // definition. -TEST_F(InitGoogleTestTest, ThrowOnFailureTrue) { +TEST_F(ParseFlagsTest, ThrowOnFailureTrue) { const char* argv[] = { "foo.exe", "--gtest_throw_on_failure=1", @@ -6381,9 +6381,9 @@ TEST_F(InitGoogleTestTest, ThrowOnFailureTrue) { GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false); } -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS // Tests parsing wide strings. -TEST_F(InitGoogleTestTest, WideStrings) { +TEST_F(ParseFlagsTest, WideStrings) { const wchar_t* argv[] = { L"foo.exe", L"--gtest_filter=Foo*", @@ -6409,10 +6409,10 @@ TEST_F(InitGoogleTestTest, WideStrings) { # endif // GTEST_OS_WINDOWS #if GTEST_USE_OWN_FLAGFILE_FLAG_ -class FlagfileTest : public InitGoogleTestTest { +class FlagfileTest : public ParseFlagsTest { public: virtual void SetUp() { - InitGoogleTestTest::SetUp(); + ParseFlagsTest::SetUp(); testdata_path_.Set(internal::FilePath( testing::TempDir() + internal::GetCurrentExecutableName().string() + @@ -6423,7 +6423,7 @@ class FlagfileTest : public InitGoogleTestTest { virtual void TearDown() { testing::internal::posix::RmDir(testdata_path_.c_str()); - InitGoogleTestTest::TearDown(); + ParseFlagsTest::TearDown(); } internal::FilePath CreateFlagfile(const char* contents) { @@ -6562,6 +6562,7 @@ TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestCase) { } // namespace testing + // These two lines test that we can define tests in a namespace that // has the name "testing" and is nested in another namespace. namespace my_namespace { |