From 93fed47dbf8e6bc3d39d3f769cb5039551747257 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). git-svn-id: http://googletest.googlecode.com/svn/trunk@607 861a406c-534a-0410-8894-cb66d6ee9925 --- include/gtest/gtest-spi.h | 2 +- include/gtest/gtest-test-part.h | 1 + include/gtest/gtest.h | 6 +- include/gtest/gtest_pred_impl.h | 12 ++-- include/gtest/internal/gtest-port.h | 4 +- include/gtest/internal/gtest-string.h | 8 +-- include/gtest/internal/gtest-tuple.h | 88 ++++++++++++++++++++------- include/gtest/internal/gtest-tuple.h.pump | 9 ++- include/gtest/internal/gtest-type-util.h | 6 +- include/gtest/internal/gtest-type-util.h.pump | 6 +- samples/sample10_unittest.cc | 3 +- samples/sample1_unittest.cc | 2 +- samples/sample2.h | 1 - samples/sample2_unittest.cc | 8 +-- samples/sample3-inl.h | 7 +-- samples/sample5_unittest.cc | 2 +- scripts/gen_gtest_pred_impl.py | 4 +- src/gtest-death-test.cc | 1 + src/gtest-internal-inl.h | 1 + src/gtest-port.cc | 1 - src/gtest.cc | 2 - src/gtest_main.cc | 5 +- 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 ++++---- 35 files changed, 144 insertions(+), 91 deletions(-) diff --git a/include/gtest/gtest-spi.h b/include/gtest/gtest-spi.h index b226e55..f63fa9a 100644 --- a/include/gtest/gtest-spi.h +++ b/include/gtest/gtest-spi.h @@ -223,7 +223,7 @@ class GTEST_API_ SingleFailureChecker { (substr));\ {\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ - ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\ + ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \ >est_failures);\ if (::testing::internal::AlwaysTrue()) { statement; }\ }\ diff --git a/include/gtest/gtest-test-part.h b/include/gtest/gtest-test-part.h index 8aeea14..4615147 100644 --- a/include/gtest/gtest-test-part.h +++ b/include/gtest/gtest-test-part.h @@ -96,6 +96,7 @@ class GTEST_API_ TestPartResult { // Returns true iff the test part fatally failed. bool fatally_failed() const { return type_ == kFatalFailure; } + private: Type type_; diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index c196990..2d570a2 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -52,6 +52,7 @@ #define GTEST_INCLUDE_GTEST_GTEST_H_ #include +#include #include #include "gtest/internal/gtest-internal.h" @@ -672,7 +673,6 @@ class GTEST_API_ TestInfo { const TestResult* result() const { return &result_; } private: - #if GTEST_HAS_DEATH_TEST friend class internal::DefaultDeathTestFactory; #endif // GTEST_HAS_DEATH_TEST @@ -1456,11 +1456,11 @@ GTEST_IMPL_CMP_HELPER_(NE, !=); // Implements the helper function for {ASSERT|EXPECT}_LE GTEST_IMPL_CMP_HELPER_(LE, <=); // Implements the helper function for {ASSERT|EXPECT}_LT -GTEST_IMPL_CMP_HELPER_(LT, < ); +GTEST_IMPL_CMP_HELPER_(LT, <); // Implements the helper function for {ASSERT|EXPECT}_GE GTEST_IMPL_CMP_HELPER_(GE, >=); // Implements the helper function for {ASSERT|EXPECT}_GT -GTEST_IMPL_CMP_HELPER_(GT, > ); +GTEST_IMPL_CMP_HELPER_(GT, >); #undef GTEST_IMPL_CMP_HELPER_ diff --git a/include/gtest/gtest_pred_impl.h b/include/gtest/gtest_pred_impl.h index 3805f85..30ae712 100644 --- a/include/gtest/gtest_pred_impl.h +++ b/include/gtest/gtest_pred_impl.h @@ -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! // // Implements a family of generic predicate assertion macros. @@ -98,7 +98,7 @@ AssertionResult AssertPred1Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1. // Don't use this in your code. #define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\ - GTEST_ASSERT_(pred_format(#v1, v1),\ + GTEST_ASSERT_(pred_format(#v1, v1), \ on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use @@ -144,7 +144,7 @@ AssertionResult AssertPred2Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2. // Don't use this in your code. #define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\ - GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),\ + GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \ on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use @@ -197,7 +197,7 @@ AssertionResult AssertPred3Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3. // Don't use this in your code. #define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\ - GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3),\ + GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \ on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use @@ -257,7 +257,7 @@ AssertionResult AssertPred4Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4. // Don't use this in your code. #define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\ - GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4),\ + GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \ on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use @@ -324,7 +324,7 @@ AssertionResult AssertPred5Helper(const char* pred_text, // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5. // Don't use this in your code. #define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\ - GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5),\ + GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \ on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 0493892..3c8463b 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -812,6 +812,7 @@ class scoped_ptr { ptr_ = p; } } + private: T* ptr_; @@ -1110,7 +1111,7 @@ class Notification { // Blocks until the controller thread notifies. Must be called from a test // thread. void WaitForNotification() { - while(!notified_) { + while (!notified_) { SleepMilliseconds(10); } } @@ -1754,7 +1755,6 @@ class TypeWithSize<4> { template <> class TypeWithSize<8> { public: - #if GTEST_OS_WINDOWS typedef __int64 Int; typedef unsigned __int64 UInt; diff --git a/include/gtest/internal/gtest-string.h b/include/gtest/internal/gtest-string.h index dc3a07b..a902450 100644 --- a/include/gtest/internal/gtest-string.h +++ b/include/gtest/internal/gtest-string.h @@ -47,10 +47,10 @@ #endif #include -#include "gtest/internal/gtest-port.h" - #include +#include "gtest/internal/gtest-port.h" + namespace testing { namespace internal { @@ -223,14 +223,14 @@ class GTEST_API_ String { // Converting a ::std::string or ::string containing an embedded NUL // character to a String will result in the prefix up to the first // NUL character. - String(const ::std::string& str) { + String(const ::std::string& str) { // NOLINT ConstructNonNull(str.c_str(), str.length()); } operator ::std::string() const { return ::std::string(c_str(), length()); } #if GTEST_HAS_GLOBAL_STRING - String(const ::string& str) { + String(const ::string& str) { // NOLINT ConstructNonNull(str.c_str(), str.length()); } diff --git a/include/gtest/internal/gtest-tuple.h b/include/gtest/internal/gtest-tuple.h index d1af50e..399e84d 100644 --- a/include/gtest/internal/gtest-tuple.h +++ b/include/gtest/internal/gtest-tuple.h @@ -1,4 +1,6 @@ -// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! +// This file was GENERATED by command: +// pump.py gtest-tuple.h.pump +// DO NOT EDIT BY HAND!!! // Copyright 2009 Google Inc. // All Rights Reserved. @@ -140,34 +142,54 @@ template struct TupleElement; template -struct TupleElement { typedef T0 type; }; +struct TupleElement { + typedef T0 type; +}; template -struct TupleElement { typedef T1 type; }; +struct TupleElement { + typedef T1 type; +}; template -struct TupleElement { typedef T2 type; }; +struct TupleElement { + typedef T2 type; +}; template -struct TupleElement { typedef T3 type; }; +struct TupleElement { + typedef T3 type; +}; template -struct TupleElement { typedef T4 type; }; +struct TupleElement { + typedef T4 type; +}; template -struct TupleElement { typedef T5 type; }; +struct TupleElement { + typedef T5 type; +}; template -struct TupleElement { typedef T6 type; }; +struct TupleElement { + typedef T6 type; +}; template -struct TupleElement { typedef T7 type; }; +struct TupleElement { + typedef T7 type; +}; template -struct TupleElement { typedef T8 type; }; +struct TupleElement { + typedef T8 type; +}; template -struct TupleElement { typedef T9 type; }; +struct TupleElement { + typedef T9 type; +}; } // namespace gtest_internal @@ -708,37 +730,59 @@ inline GTEST_10_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2, template struct tuple_size; template -struct tuple_size { static const int value = 0; }; +struct tuple_size { + static const int value = 0; +}; template -struct tuple_size { static const int value = 1; }; +struct tuple_size { + static const int value = 1; +}; template -struct tuple_size { static const int value = 2; }; +struct tuple_size { + static const int value = 2; +}; template -struct tuple_size { static const int value = 3; }; +struct tuple_size { + static const int value = 3; +}; template -struct tuple_size { static const int value = 4; }; +struct tuple_size { + static const int value = 4; +}; template -struct tuple_size { static const int value = 5; }; +struct tuple_size { + static const int value = 5; +}; template -struct tuple_size { static const int value = 6; }; +struct tuple_size { + static const int value = 6; +}; template -struct tuple_size { static const int value = 7; }; +struct tuple_size { + static const int value = 7; +}; template -struct tuple_size { static const int value = 8; }; +struct tuple_size { + static const int value = 8; +}; template -struct tuple_size { static const int value = 9; }; +struct tuple_size { + static const int value = 9; +}; template -struct tuple_size { static const int value = 10; }; +struct tuple_size { + static const int value = 10; +}; template struct tuple_element { diff --git a/include/gtest/internal/gtest-tuple.h.pump b/include/gtest/internal/gtest-tuple.h.pump index ef51909..238e8fc 100644 --- a/include/gtest/internal/gtest-tuple.h.pump +++ b/include/gtest/internal/gtest-tuple.h.pump @@ -118,8 +118,9 @@ struct TupleElement; $for i [[ template -struct TupleElement [[]] -{ typedef T$i type; }; +struct TupleElement { + typedef T$i type; +}; ]] @@ -220,7 +221,9 @@ template struct tuple_size; $for j [[ template -struct tuple_size { static const int value = $j; }; +struct tuple_size { + static const int value = $j; +}; ]] diff --git a/include/gtest/internal/gtest-type-util.h b/include/gtest/internal/gtest-type-util.h index 597aeaf..ed58fce 100644 --- a/include/gtest/internal/gtest-type-util.h +++ b/include/gtest/internal/gtest-type-util.h @@ -72,7 +72,7 @@ String GetTypeName() { // so we have to demangle it. # if GTEST_HAS_CXXABI_H_ using abi::__cxa_demangle; -# endif // GTEST_HAS_CXXABI_H_ +# endif // GTEST_HAS_CXXABI_H_ char* const readable_name = __cxa_demangle(name, 0, 0, &status); const String name_str(status == 0 ? readable_name : name); free(readable_name); @@ -3300,7 +3300,9 @@ struct Templates -struct TypeList { typedef Types1 type; }; +struct TypeList { + typedef Types1 type; +}; template { // INSTANTIATE_TYPED_TEST_CASE_P(). template -struct TypeList { typedef Types1 type; }; +struct TypeList { + typedef Types1 type; +}; $range i 1..n diff --git a/samples/sample10_unittest.cc b/samples/sample10_unittest.cc index 2813d04..0051cd5 100644 --- a/samples/sample10_unittest.cc +++ b/samples/sample10_unittest.cc @@ -89,8 +89,7 @@ class LeakChecker : public EmptyTestEventListener { // You can generate a failure in any event handler except // OnTestPartResult. Just use an appropriate Google Test assertion to do // it. - EXPECT_TRUE(difference <= 0) - << "Leaked " << difference << " unit(s) of Water!"; + EXPECT_LE(difference, 0) << "Leaked " << difference << " unit(s) of Water!"; } int initially_allocated_; diff --git a/samples/sample1_unittest.cc b/samples/sample1_unittest.cc index a8a7c79..aefc4f1 100644 --- a/samples/sample1_unittest.cc +++ b/samples/sample1_unittest.cc @@ -81,7 +81,7 @@ TEST(FactorialTest, Negative) { // test case. EXPECT_EQ(1, Factorial(-5)); EXPECT_EQ(1, Factorial(-1)); - EXPECT_TRUE(Factorial(-10) > 0); + EXPECT_GT(Factorial(-10), 0); // // diff --git a/samples/sample2.h b/samples/sample2.h index 5b57e60..cb485c7 100644 --- a/samples/sample2.h +++ b/samples/sample2.h @@ -44,7 +44,6 @@ class MyString { const MyString& operator=(const MyString& rhs); public: - // Clones a 0-terminated C string, allocating memory using new. static const char* CloneCString(const char* a_c_string); diff --git a/samples/sample2_unittest.cc b/samples/sample2_unittest.cc index 3792fa5..4fa19b7 100644 --- a/samples/sample2_unittest.cc +++ b/samples/sample2_unittest.cc @@ -79,7 +79,7 @@ const char kHelloString[] = "Hello, world!"; // Tests the c'tor that accepts a C string. TEST(MyString, ConstructorFromCString) { const MyString s(kHelloString); - EXPECT_TRUE(strcmp(s.c_string(), kHelloString) == 0); + EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); EXPECT_EQ(sizeof(kHelloString)/sizeof(kHelloString[0]) - 1, s.Length()); } @@ -88,7 +88,7 @@ TEST(MyString, ConstructorFromCString) { TEST(MyString, CopyConstructor) { const MyString s1(kHelloString); const MyString s2 = s1; - EXPECT_TRUE(strcmp(s2.c_string(), kHelloString) == 0); + EXPECT_EQ(0, strcmp(s2.c_string(), kHelloString)); } // Tests the Set method. @@ -96,12 +96,12 @@ TEST(MyString, Set) { MyString s; s.Set(kHelloString); - EXPECT_TRUE(strcmp(s.c_string(), kHelloString) == 0); + EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); // Set should work when the input pointer is the same as the one // already in the MyString object. s.Set(s.c_string()); - EXPECT_TRUE(strcmp(s.c_string(), kHelloString) == 0); + EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); // Can we set the MyString to NULL? s.Set(NULL); diff --git a/samples/sample3-inl.h b/samples/sample3-inl.h index 46369a0..7e3084d 100644 --- a/samples/sample3-inl.h +++ b/samples/sample3-inl.h @@ -60,7 +60,7 @@ class QueueNode { private: // Creates a node with a given element value. The next pointer is // set to NULL. - QueueNode(const E& an_element) : element_(an_element), next_(NULL) {} + explicit QueueNode(const E& an_element) : element_(an_element), next_(NULL) {} // We disable the default assignment operator and copy c'tor. const QueueNode& operator = (const QueueNode&); @@ -72,8 +72,7 @@ class QueueNode { template // E is the element type. class Queue { -public: - + public: // Creates an empty queue. Queue() : head_(NULL), last_(NULL), size_(0) {} @@ -168,6 +167,6 @@ public: // We disallow copying a queue. Queue(const Queue&); const Queue& operator = (const Queue&); - }; +}; #endif // GTEST_SAMPLES_SAMPLE3_INL_H_ diff --git a/samples/sample5_unittest.cc b/samples/sample5_unittest.cc index f63c29e..43d8e57 100644 --- a/samples/sample5_unittest.cc +++ b/samples/sample5_unittest.cc @@ -101,7 +101,7 @@ TEST_F(IntegerFunctionTest, Factorial) { // Tests factorial of negative numbers. EXPECT_EQ(1, Factorial(-5)); EXPECT_EQ(1, Factorial(-1)); - EXPECT_TRUE(Factorial(-10) > 0); + EXPECT_GT(Factorial(-10), 0); // Tests factorial of 0. EXPECT_EQ(1, Factorial(0)); diff --git a/scripts/gen_gtest_pred_impl.py b/scripts/gen_gtest_pred_impl.py index d35b4f0..3e7ab04 100755 --- a/scripts/gen_gtest_pred_impl.py +++ b/scripts/gen_gtest_pred_impl.py @@ -117,7 +117,7 @@ def HeaderPreamble(n): // Makes sure this header is not included before gtest.h. #ifndef GTEST_INCLUDE_GTEST_GTEST_H_ -#error Do not include gtest_pred_impl.h directly. Include gtest.h instead. +# error Do not include gtest_pred_impl.h directly. Include gtest.h instead. #endif // GTEST_INCLUDE_GTEST_GTEST_H_ // This header implements a family of generic predicate assertion @@ -256,7 +256,7 @@ AssertionResult AssertPred%(n)sHelper(const char* pred_text""" % DEFS // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT%(n)s. // Don't use this in your code. #define GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, on_failure)\\ - GTEST_ASSERT_(pred_format(%(vts)s, %(vs)s),\\ + GTEST_ASSERT_(pred_format(%(vts)s, %(vs)s), \\ on_failure) // Internal macro for implementing {EXPECT|ASSERT}_PRED%(n)s. Don't use diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc index 0a0f83b..36a2e3a 100644 --- a/src/gtest-death-test.cc +++ b/src/gtest-death-test.cc @@ -913,6 +913,7 @@ class Arguments { char* const* Argv() { return &args_[0]; } + private: std::vector args_; }; diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h index d869f0f..1ea31a1 100644 --- a/src/gtest-internal-inl.h +++ b/src/gtest-internal-inl.h @@ -196,6 +196,7 @@ class GTestFlagSaver { GTEST_FLAG(stream_result_to) = stream_result_to_; GTEST_FLAG(throw_on_failure) = throw_on_failure_; } + private: // Fields for saving the original values of flags. bool also_run_disabled_tests_; diff --git a/src/gtest-port.cc b/src/gtest-port.cc index 6e8dca2..9648eee 100644 --- a/src/gtest-port.cc +++ b/src/gtest-port.cc @@ -514,7 +514,6 @@ class CapturedStream { public: // The ctor redirects the stream to a temporary file. CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { - # if GTEST_OS_WINDOWS char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT diff --git a/src/gtest.cc b/src/gtest.cc index e407ee9..f2e84af 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -3864,7 +3864,6 @@ int UnitTest::Run() { // process. In either case the user does not want to see pop-up dialogs // about crashes - they are expected. if (impl()->catch_exceptions() || in_death_test_child_process) { - # if !GTEST_OS_WINDOWS_MOBILE // SetErrorMode doesn't exist on CE. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | @@ -3895,7 +3894,6 @@ int UnitTest::Run() { 0x0, // Clear the following flags: _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump. # endif - } #endif // GTEST_HAS_SEH diff --git a/src/gtest_main.cc b/src/gtest_main.cc index a09bbe0..f302822 100644 --- a/src/gtest_main.cc +++ b/src/gtest_main.cc @@ -27,13 +27,12 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include #include "gtest/gtest.h" GTEST_API_ int main(int argc, char **argv) { - std::cout << "Running main() from gtest_main.cc\n"; - + printf("Running main() from gtest_main.cc\n"); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc index 54f5a1a..5a4a989 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 0d5508a..6fcf512 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 2aa08ef..1008608 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 94a53d9..cf61866 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 d0f6556..26ea122 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 b0177cf..75471c3 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 58044ab..58d9622 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 ec9aa2c..3cff19e 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 e3a85f1..292599a 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 13dbec4..031ae83 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 35dc9bc..a84eff8 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 5223dc0..481012a 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 0d624fd..8cd58be 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