From 8965a6a0d2165f32e6413594bba6367f271f51e7 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Fri, 4 Nov 2011 17:56:23 +0000 Subject: Improves conformance to the Google C++ Style Guide (by Greg Miller). --- test/gtest-death-test_test.cc | 1 + test/gtest-linked_ptr_test.cc | 3 +-- test/gtest-listener_test.cc | 2 +- test/gtest-param-test_test.cc | 2 ++ test/gtest-param-test_test.h | 6 ++++-- test/gtest-port_test.cc | 8 ++++---- test/gtest-printers_test.cc | 2 +- test/gtest_environment_test.cc | 1 + test/gtest_no_test_unittest.cc | 1 - test/gtest_output_test_.cc | 1 + test/gtest_pred_impl_unittest.cc | 2 +- test/gtest_repeat_test.cc | 2 +- test/gtest_unittest.cc | 25 +++++++++++++------------ 13 files changed, 31 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc index 54f5a1a1..5a4a989d 100644 --- a/test/gtest-death-test_test.cc +++ b/test/gtest-death-test_test.cc @@ -896,6 +896,7 @@ class MockDeathTest : public DeathTest { virtual void Abort(AbortReason reason) { parent_->abort_args_.push_back(reason); } + private: MockDeathTestFactory* const parent_; const TestRole role_; diff --git a/test/gtest-linked_ptr_test.cc b/test/gtest-linked_ptr_test.cc index 0d5508ae..6fcf5124 100644 --- a/test/gtest-linked_ptr_test.cc +++ b/test/gtest-linked_ptr_test.cc @@ -148,8 +148,7 @@ TEST_F(LinkedPtrTest, GeneralTest) { "A0 dtor\n" "A3 dtor\n" "A1 dtor\n", - history->GetString().c_str() - ); + history->GetString().c_str()); } } // Unnamed namespace diff --git a/test/gtest-listener_test.cc b/test/gtest-listener_test.cc index 2aa08ef3..10086086 100644 --- a/test/gtest-listener_test.cc +++ b/test/gtest-listener_test.cc @@ -55,7 +55,7 @@ namespace internal { class EventRecordingListener : public TestEventListener { public: - EventRecordingListener(const char* name) : name_(name) {} + explicit EventRecordingListener(const char* name) : name_(name) {} protected: virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) { diff --git a/test/gtest-param-test_test.cc b/test/gtest-param-test_test.cc index 94a53d9f..cf618665 100644 --- a/test/gtest-param-test_test.cc +++ b/test/gtest-param-test_test.cc @@ -606,6 +606,7 @@ class TestGenerationEnvironment : public ::testing::Environment { << "has not been run as expected."; } } + private: TestGenerationEnvironment() : fixture_constructor_count_(0), set_up_count_(0), tear_down_count_(0), test_body_count_(0) {} @@ -674,6 +675,7 @@ class TestGenerationTest : public TestWithParam { EXPECT_TRUE(collected_parameters_ == expected_values); } + protected: int current_parameter_; static vector collected_parameters_; diff --git a/test/gtest-param-test_test.h b/test/gtest-param-test_test.h index d0f6556b..26ea122b 100644 --- a/test/gtest-param-test_test.h +++ b/test/gtest-param-test_test.h @@ -43,12 +43,14 @@ // Test fixture for testing definition and instantiation of a test // in separate translation units. -class ExternalInstantiationTest : public ::testing::TestWithParam {}; +class ExternalInstantiationTest : public ::testing::TestWithParam { +}; // Test fixture for testing instantiation of a test in multiple // translation units. class InstantiationInMultipleTranslaionUnitsTest - : public ::testing::TestWithParam {}; + : public ::testing::TestWithParam { +}; #endif // GTEST_HAS_PARAM_TEST diff --git a/test/gtest-port_test.cc b/test/gtest-port_test.cc index b0177cf1..75471c39 100644 --- a/test/gtest-port_test.cc +++ b/test/gtest-port_test.cc @@ -92,7 +92,7 @@ TEST(ImplicitCastTest, CanUseInheritance) { class Castable { public: - Castable(bool* converted) : converted_(converted) {} + explicit Castable(bool* converted) : converted_(converted) {} operator Base() { *converted_ = true; return Base(); @@ -111,7 +111,7 @@ TEST(ImplicitCastTest, CanUseNonConstCastOperator) { class ConstCastable { public: - ConstCastable(bool* converted) : converted_(converted) {} + explicit ConstCastable(bool* converted) : converted_(converted) {} operator Base() const { *converted_ = true; return Base(); @@ -224,7 +224,7 @@ TEST(GtestCheckSyntaxTest, WorksWithSwitch) { GTEST_CHECK_(true); } - switch(0) + switch (0) case 0: GTEST_CHECK_(true) << "Check failed in switch case"; } @@ -929,7 +929,7 @@ TEST(CaptureTest, CapturesStdoutAndStderr) { TEST(CaptureDeathTest, CannotReenterStdoutCapture) { CaptureStdout(); - EXPECT_DEATH_IF_SUPPORTED(CaptureStdout();, + EXPECT_DEATH_IF_SUPPORTED(CaptureStdout(), "Only one stdout capturer can exist at a time"); GetCapturedStdout(); diff --git a/test/gtest-printers_test.cc b/test/gtest-printers_test.cc index 58044ab5..58d96225 100644 --- a/test/gtest-printers_test.cc +++ b/test/gtest-printers_test.cc @@ -841,7 +841,7 @@ TEST(PrintStlContainerTest, HashMultiSet) { std::vector numbers; for (size_t i = 0; i != result.length(); i++) { if (expected_pattern[i] == 'd') { - ASSERT_TRUE(isdigit(static_cast(result[i])) != 0); + ASSERT_NE(isdigit(static_cast(result[i])), 0); numbers.push_back(result[i] - '0'); } else { EXPECT_EQ(expected_pattern[i], result[i]) << " where result is " diff --git a/test/gtest_environment_test.cc b/test/gtest_environment_test.cc index ec9aa2cd..3cff19e7 100644 --- a/test/gtest_environment_test.cc +++ b/test/gtest_environment_test.cc @@ -96,6 +96,7 @@ class MyEnvironment : public testing::Environment { // Was TearDown() run? bool tear_down_was_run() const { return tear_down_was_run_; } + private: FailureType failure_in_set_up_; bool set_up_was_run_; diff --git a/test/gtest_no_test_unittest.cc b/test/gtest_no_test_unittest.cc index e3a85f12..292599af 100644 --- a/test/gtest_no_test_unittest.cc +++ b/test/gtest_no_test_unittest.cc @@ -34,7 +34,6 @@ #include "gtest/gtest.h" - int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); diff --git a/test/gtest_output_test_.cc b/test/gtest_output_test_.cc index 13dbec47..031ae83b 100644 --- a/test/gtest_output_test_.cc +++ b/test/gtest_output_test_.cc @@ -378,6 +378,7 @@ class FatalFailureInFixtureConstructorTest : public testing::Test { << "We should never get here, as the test fixture c'tor " << "had a fatal failure."; } + private: void Init() { FAIL() << "Expected failure #1, in the test fixture c'tor."; diff --git a/test/gtest_pred_impl_unittest.cc b/test/gtest_pred_impl_unittest.cc index 35dc9bcf..a84eff86 100644 --- a/test/gtest_pred_impl_unittest.cc +++ b/test/gtest_pred_impl_unittest.cc @@ -27,7 +27,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// This file is AUTOMATICALLY GENERATED on 09/24/2010 by command +// This file is AUTOMATICALLY GENERATED on 10/31/2011 by command // 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND! // Regression test for gtest_pred_impl.h diff --git a/test/gtest_repeat_test.cc b/test/gtest_repeat_test.cc index 5223dc0e..481012ad 100644 --- a/test/gtest_repeat_test.cc +++ b/test/gtest_repeat_test.cc @@ -71,7 +71,7 @@ namespace { << "Which is: " << expected_val << "\n";\ ::testing::internal::posix::Abort();\ }\ - } while(::testing::internal::AlwaysFalse()) + } while (::testing::internal::AlwaysFalse()) // Used for verifying that global environment set-up and tear-down are diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc index 0d624fd7..8cd58be0 100644 --- a/test/gtest_unittest.cc +++ b/test/gtest_unittest.cc @@ -33,8 +33,6 @@ // Google Test work. #include "gtest/gtest.h" -#include -#include // Verifies that the command line flag variables can be accessed // in code once has been #included. @@ -58,6 +56,15 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { EXPECT_TRUE(dummy || !dummy); // Suppresses warning that dummy is unused. } +#include // For INT_MAX. +#include +#include +#include + +#include +#include +#include + #include "gtest/gtest-spi.h" // Indicates that this translation unit is part of Google Test's @@ -69,13 +76,6 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include "src/gtest-internal-inl.h" #undef GTEST_IMPLEMENTATION_ -#include // For INT_MAX. -#include -#include -#include - -#include - namespace testing { namespace internal { @@ -1141,7 +1141,7 @@ TEST(StringTest, Equals) { EXPECT_TRUE(foo == "foo"); // NOLINT const String bar("x\0y", 3); - EXPECT_FALSE(bar == "x"); + EXPECT_NE(bar, "x"); } // Tests String::operator!=(). @@ -1163,7 +1163,7 @@ TEST(StringTest, NotEquals) { EXPECT_FALSE(foo != "foo"); // NOLINT const String bar("x\0y", 3); - EXPECT_TRUE(bar != "x"); + EXPECT_NE(bar, "x"); } // Tests String::length(). @@ -1902,6 +1902,7 @@ class GTestFlagSaverTest : public Test { GTEST_FLAG(stream_result_to) = "localhost:1234"; GTEST_FLAG(throw_on_failure) = true; } + private: // For saving Google Test flags during this test case. static GTestFlagSaver* saver_; @@ -2797,7 +2798,6 @@ TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) { template class FloatingPointTest : public Test { protected: - // Pre-calculated numbers to be used by the tests. struct TestValues { RawType close_to_positive_zero; @@ -7278,6 +7278,7 @@ TEST(ArrayEqTest, WorksForDegeneratedArrays) { } TEST(ArrayEqTest, WorksForOneDimensionalArrays) { + // Note that a and b are distinct but compatible types. const int a[] = { 0, 1 }; long b[] = { 0, 1 }; EXPECT_TRUE(ArrayEq(a, b)); -- cgit v1.2.3