Improves conformance to the Google C++ Style Guide (by Greg Miller).

This commit is contained in:
vladlosev 2011-11-04 17:56:23 +00:00
parent 829402edcf
commit 8965a6a0d2
35 changed files with 144 additions and 91 deletions

View File

@ -223,7 +223,7 @@ class GTEST_API_ SingleFailureChecker {
(substr));\ (substr));\
{\ {\
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\ ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
&gtest_failures);\ &gtest_failures);\
if (::testing::internal::AlwaysTrue()) { statement; }\ if (::testing::internal::AlwaysTrue()) { statement; }\
}\ }\

View File

@ -96,6 +96,7 @@ class GTEST_API_ TestPartResult {
// Returns true iff the test part fatally failed. // Returns true iff the test part fatally failed.
bool fatally_failed() const { return type_ == kFatalFailure; } bool fatally_failed() const { return type_ == kFatalFailure; }
private: private:
Type type_; Type type_;

View File

@ -52,6 +52,7 @@
#define GTEST_INCLUDE_GTEST_GTEST_H_ #define GTEST_INCLUDE_GTEST_GTEST_H_
#include <limits> #include <limits>
#include <ostream>
#include <vector> #include <vector>
#include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-internal.h"
@ -672,7 +673,6 @@ class GTEST_API_ TestInfo {
const TestResult* result() const { return &result_; } const TestResult* result() const { return &result_; }
private: private:
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
friend class internal::DefaultDeathTestFactory; friend class internal::DefaultDeathTestFactory;
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
@ -1456,11 +1456,11 @@ GTEST_IMPL_CMP_HELPER_(NE, !=);
// Implements the helper function for {ASSERT|EXPECT}_LE // Implements the helper function for {ASSERT|EXPECT}_LE
GTEST_IMPL_CMP_HELPER_(LE, <=); GTEST_IMPL_CMP_HELPER_(LE, <=);
// Implements the helper function for {ASSERT|EXPECT}_LT // 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 // Implements the helper function for {ASSERT|EXPECT}_GE
GTEST_IMPL_CMP_HELPER_(GE, >=); GTEST_IMPL_CMP_HELPER_(GE, >=);
// Implements the helper function for {ASSERT|EXPECT}_GT // Implements the helper function for {ASSERT|EXPECT}_GT
GTEST_IMPL_CMP_HELPER_(GT, > ); GTEST_IMPL_CMP_HELPER_(GT, >);
#undef GTEST_IMPL_CMP_HELPER_ #undef GTEST_IMPL_CMP_HELPER_

View File

@ -27,7 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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! // 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
// //
// Implements a family of generic predicate assertion macros. // 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. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\ #define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
GTEST_ASSERT_(pred_format(#v1, v1),\ GTEST_ASSERT_(pred_format(#v1, v1), \
on_failure) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use // 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. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\ #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) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use // 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. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\ #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) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use // 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. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\ #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) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use // 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. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\ #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) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use

View File

@ -812,6 +812,7 @@ class scoped_ptr {
ptr_ = p; ptr_ = p;
} }
} }
private: private:
T* ptr_; T* ptr_;
@ -1110,7 +1111,7 @@ class Notification {
// Blocks until the controller thread notifies. Must be called from a test // Blocks until the controller thread notifies. Must be called from a test
// thread. // thread.
void WaitForNotification() { void WaitForNotification() {
while(!notified_) { while (!notified_) {
SleepMilliseconds(10); SleepMilliseconds(10);
} }
} }
@ -1754,7 +1755,6 @@ class TypeWithSize<4> {
template <> template <>
class TypeWithSize<8> { class TypeWithSize<8> {
public: public:
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
typedef __int64 Int; typedef __int64 Int;
typedef unsigned __int64 UInt; typedef unsigned __int64 UInt;

View File

@ -47,10 +47,10 @@
#endif #endif
#include <string.h> #include <string.h>
#include "gtest/internal/gtest-port.h"
#include <string> #include <string>
#include "gtest/internal/gtest-port.h"
namespace testing { namespace testing {
namespace internal { namespace internal {
@ -223,14 +223,14 @@ class GTEST_API_ String {
// Converting a ::std::string or ::string containing an embedded NUL // Converting a ::std::string or ::string containing an embedded NUL
// character to a String will result in the prefix up to the first // character to a String will result in the prefix up to the first
// NUL character. // NUL character.
String(const ::std::string& str) { String(const ::std::string& str) { // NOLINT
ConstructNonNull(str.c_str(), str.length()); ConstructNonNull(str.c_str(), str.length());
} }
operator ::std::string() const { return ::std::string(c_str(), length()); } operator ::std::string() const { return ::std::string(c_str(), length()); }
#if GTEST_HAS_GLOBAL_STRING #if GTEST_HAS_GLOBAL_STRING
String(const ::string& str) { String(const ::string& str) { // NOLINT
ConstructNonNull(str.c_str(), str.length()); ConstructNonNull(str.c_str(), str.length());
} }

View File

@ -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. // Copyright 2009 Google Inc.
// All Rights Reserved. // All Rights Reserved.
@ -140,34 +142,54 @@ template <bool kIndexValid, int kIndex, class Tuple>
struct TupleElement; struct TupleElement;
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 0, GTEST_10_TUPLE_(T)> { typedef T0 type; }; struct TupleElement<true, 0, GTEST_10_TUPLE_(T)> {
typedef T0 type;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 1, GTEST_10_TUPLE_(T)> { typedef T1 type; }; struct TupleElement<true, 1, GTEST_10_TUPLE_(T)> {
typedef T1 type;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 2, GTEST_10_TUPLE_(T)> { typedef T2 type; }; struct TupleElement<true, 2, GTEST_10_TUPLE_(T)> {
typedef T2 type;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 3, GTEST_10_TUPLE_(T)> { typedef T3 type; }; struct TupleElement<true, 3, GTEST_10_TUPLE_(T)> {
typedef T3 type;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 4, GTEST_10_TUPLE_(T)> { typedef T4 type; }; struct TupleElement<true, 4, GTEST_10_TUPLE_(T)> {
typedef T4 type;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 5, GTEST_10_TUPLE_(T)> { typedef T5 type; }; struct TupleElement<true, 5, GTEST_10_TUPLE_(T)> {
typedef T5 type;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 6, GTEST_10_TUPLE_(T)> { typedef T6 type; }; struct TupleElement<true, 6, GTEST_10_TUPLE_(T)> {
typedef T6 type;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 7, GTEST_10_TUPLE_(T)> { typedef T7 type; }; struct TupleElement<true, 7, GTEST_10_TUPLE_(T)> {
typedef T7 type;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 8, GTEST_10_TUPLE_(T)> { typedef T8 type; }; struct TupleElement<true, 8, GTEST_10_TUPLE_(T)> {
typedef T8 type;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct TupleElement<true, 9, GTEST_10_TUPLE_(T)> { typedef T9 type; }; struct TupleElement<true, 9, GTEST_10_TUPLE_(T)> {
typedef T9 type;
};
} // namespace gtest_internal } // namespace gtest_internal
@ -708,37 +730,59 @@ inline GTEST_10_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
template <typename Tuple> struct tuple_size; template <typename Tuple> struct tuple_size;
template <GTEST_0_TYPENAMES_(T)> template <GTEST_0_TYPENAMES_(T)>
struct tuple_size<GTEST_0_TUPLE_(T)> { static const int value = 0; }; struct tuple_size<GTEST_0_TUPLE_(T)> {
static const int value = 0;
};
template <GTEST_1_TYPENAMES_(T)> template <GTEST_1_TYPENAMES_(T)>
struct tuple_size<GTEST_1_TUPLE_(T)> { static const int value = 1; }; struct tuple_size<GTEST_1_TUPLE_(T)> {
static const int value = 1;
};
template <GTEST_2_TYPENAMES_(T)> template <GTEST_2_TYPENAMES_(T)>
struct tuple_size<GTEST_2_TUPLE_(T)> { static const int value = 2; }; struct tuple_size<GTEST_2_TUPLE_(T)> {
static const int value = 2;
};
template <GTEST_3_TYPENAMES_(T)> template <GTEST_3_TYPENAMES_(T)>
struct tuple_size<GTEST_3_TUPLE_(T)> { static const int value = 3; }; struct tuple_size<GTEST_3_TUPLE_(T)> {
static const int value = 3;
};
template <GTEST_4_TYPENAMES_(T)> template <GTEST_4_TYPENAMES_(T)>
struct tuple_size<GTEST_4_TUPLE_(T)> { static const int value = 4; }; struct tuple_size<GTEST_4_TUPLE_(T)> {
static const int value = 4;
};
template <GTEST_5_TYPENAMES_(T)> template <GTEST_5_TYPENAMES_(T)>
struct tuple_size<GTEST_5_TUPLE_(T)> { static const int value = 5; }; struct tuple_size<GTEST_5_TUPLE_(T)> {
static const int value = 5;
};
template <GTEST_6_TYPENAMES_(T)> template <GTEST_6_TYPENAMES_(T)>
struct tuple_size<GTEST_6_TUPLE_(T)> { static const int value = 6; }; struct tuple_size<GTEST_6_TUPLE_(T)> {
static const int value = 6;
};
template <GTEST_7_TYPENAMES_(T)> template <GTEST_7_TYPENAMES_(T)>
struct tuple_size<GTEST_7_TUPLE_(T)> { static const int value = 7; }; struct tuple_size<GTEST_7_TUPLE_(T)> {
static const int value = 7;
};
template <GTEST_8_TYPENAMES_(T)> template <GTEST_8_TYPENAMES_(T)>
struct tuple_size<GTEST_8_TUPLE_(T)> { static const int value = 8; }; struct tuple_size<GTEST_8_TUPLE_(T)> {
static const int value = 8;
};
template <GTEST_9_TYPENAMES_(T)> template <GTEST_9_TYPENAMES_(T)>
struct tuple_size<GTEST_9_TUPLE_(T)> { static const int value = 9; }; struct tuple_size<GTEST_9_TUPLE_(T)> {
static const int value = 9;
};
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
struct tuple_size<GTEST_10_TUPLE_(T)> { static const int value = 10; }; struct tuple_size<GTEST_10_TUPLE_(T)> {
static const int value = 10;
};
template <int k, class Tuple> template <int k, class Tuple>
struct tuple_element { struct tuple_element {

View File

@ -118,8 +118,9 @@ struct TupleElement;
$for i [[ $for i [[
template <GTEST_$(n)_TYPENAMES_(T)> template <GTEST_$(n)_TYPENAMES_(T)>
struct TupleElement<true, $i, GTEST_$(n)_TUPLE_(T)> [[]] struct TupleElement<true, $i, GTEST_$(n)_TUPLE_(T)> {
{ typedef T$i type; }; typedef T$i type;
};
]] ]]
@ -220,7 +221,9 @@ template <typename Tuple> struct tuple_size;
$for j [[ $for j [[
template <GTEST_$(j)_TYPENAMES_(T)> template <GTEST_$(j)_TYPENAMES_(T)>
struct tuple_size<GTEST_$(j)_TUPLE_(T)> { static const int value = $j; }; struct tuple_size<GTEST_$(j)_TUPLE_(T)> {
static const int value = $j;
};
]] ]]

View File

@ -72,7 +72,7 @@ String GetTypeName() {
// so we have to demangle it. // so we have to demangle it.
# if GTEST_HAS_CXXABI_H_ # if GTEST_HAS_CXXABI_H_
using abi::__cxa_demangle; using abi::__cxa_demangle;
# endif // GTEST_HAS_CXXABI_H_ # endif // GTEST_HAS_CXXABI_H_
char* const readable_name = __cxa_demangle(name, 0, 0, &status); char* const readable_name = __cxa_demangle(name, 0, 0, &status);
const String name_str(status == 0 ? readable_name : name); const String name_str(status == 0 ? readable_name : name);
free(readable_name); free(readable_name);
@ -3300,7 +3300,9 @@ struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
// INSTANTIATE_TYPED_TEST_CASE_P(). // INSTANTIATE_TYPED_TEST_CASE_P().
template <typename T> template <typename T>
struct TypeList { typedef Types1<T> type; }; struct TypeList {
typedef Types1<T> type;
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10, typename T6, typename T7, typename T8, typename T9, typename T10,

View File

@ -70,7 +70,7 @@ String GetTypeName() {
// so we have to demangle it. // so we have to demangle it.
# if GTEST_HAS_CXXABI_H_ # if GTEST_HAS_CXXABI_H_
using abi::__cxa_demangle; using abi::__cxa_demangle;
# endif // GTEST_HAS_CXXABI_H_ # endif // GTEST_HAS_CXXABI_H_
char* const readable_name = __cxa_demangle(name, 0, 0, &status); char* const readable_name = __cxa_demangle(name, 0, 0, &status);
const String name_str(status == 0 ? readable_name : name); const String name_str(status == 0 ? readable_name : name);
free(readable_name); free(readable_name);
@ -279,7 +279,9 @@ struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
// INSTANTIATE_TYPED_TEST_CASE_P(). // INSTANTIATE_TYPED_TEST_CASE_P().
template <typename T> template <typename T>
struct TypeList { typedef Types1<T> type; }; struct TypeList {
typedef Types1<T> type;
};
$range i 1..n $range i 1..n

View File

@ -89,8 +89,7 @@ class LeakChecker : public EmptyTestEventListener {
// You can generate a failure in any event handler except // You can generate a failure in any event handler except
// OnTestPartResult. Just use an appropriate Google Test assertion to do // OnTestPartResult. Just use an appropriate Google Test assertion to do
// it. // it.
EXPECT_TRUE(difference <= 0) EXPECT_LE(difference, 0) << "Leaked " << difference << " unit(s) of Water!";
<< "Leaked " << difference << " unit(s) of Water!";
} }
int initially_allocated_; int initially_allocated_;

View File

@ -81,7 +81,7 @@ TEST(FactorialTest, Negative) {
// test case. // test case.
EXPECT_EQ(1, Factorial(-5)); EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1)); EXPECT_EQ(1, Factorial(-1));
EXPECT_TRUE(Factorial(-10) > 0); EXPECT_GT(Factorial(-10), 0);
// <TechnicalDetails> // <TechnicalDetails>
// //

View File

@ -44,7 +44,6 @@ class MyString {
const MyString& operator=(const MyString& rhs); const MyString& operator=(const MyString& rhs);
public: public:
// Clones a 0-terminated C string, allocating memory using new. // Clones a 0-terminated C string, allocating memory using new.
static const char* CloneCString(const char* a_c_string); static const char* CloneCString(const char* a_c_string);

View File

@ -79,7 +79,7 @@ const char kHelloString[] = "Hello, world!";
// Tests the c'tor that accepts a C string. // Tests the c'tor that accepts a C string.
TEST(MyString, ConstructorFromCString) { TEST(MyString, ConstructorFromCString) {
const MyString s(kHelloString); 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, EXPECT_EQ(sizeof(kHelloString)/sizeof(kHelloString[0]) - 1,
s.Length()); s.Length());
} }
@ -88,7 +88,7 @@ TEST(MyString, ConstructorFromCString) {
TEST(MyString, CopyConstructor) { TEST(MyString, CopyConstructor) {
const MyString s1(kHelloString); const MyString s1(kHelloString);
const MyString s2 = s1; const MyString s2 = s1;
EXPECT_TRUE(strcmp(s2.c_string(), kHelloString) == 0); EXPECT_EQ(0, strcmp(s2.c_string(), kHelloString));
} }
// Tests the Set method. // Tests the Set method.
@ -96,12 +96,12 @@ TEST(MyString, Set) {
MyString s; MyString s;
s.Set(kHelloString); 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 // Set should work when the input pointer is the same as the one
// already in the MyString object. // already in the MyString object.
s.Set(s.c_string()); 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? // Can we set the MyString to NULL?
s.Set(NULL); s.Set(NULL);

View File

@ -60,7 +60,7 @@ class QueueNode {
private: private:
// Creates a node with a given element value. The next pointer is // Creates a node with a given element value. The next pointer is
// set to NULL. // 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. // We disable the default assignment operator and copy c'tor.
const QueueNode& operator = (const QueueNode&); const QueueNode& operator = (const QueueNode&);
@ -72,8 +72,7 @@ class QueueNode {
template <typename E> // E is the element type. template <typename E> // E is the element type.
class Queue { class Queue {
public: public:
// Creates an empty queue. // Creates an empty queue.
Queue() : head_(NULL), last_(NULL), size_(0) {} Queue() : head_(NULL), last_(NULL), size_(0) {}
@ -168,6 +167,6 @@ public:
// We disallow copying a queue. // We disallow copying a queue.
Queue(const Queue&); Queue(const Queue&);
const Queue& operator = (const Queue&); const Queue& operator = (const Queue&);
}; };
#endif // GTEST_SAMPLES_SAMPLE3_INL_H_ #endif // GTEST_SAMPLES_SAMPLE3_INL_H_

View File

@ -101,7 +101,7 @@ TEST_F(IntegerFunctionTest, Factorial) {
// Tests factorial of negative numbers. // Tests factorial of negative numbers.
EXPECT_EQ(1, Factorial(-5)); EXPECT_EQ(1, Factorial(-5));
EXPECT_EQ(1, Factorial(-1)); EXPECT_EQ(1, Factorial(-1));
EXPECT_TRUE(Factorial(-10) > 0); EXPECT_GT(Factorial(-10), 0);
// Tests factorial of 0. // Tests factorial of 0.
EXPECT_EQ(1, Factorial(0)); EXPECT_EQ(1, Factorial(0));

View File

@ -117,7 +117,7 @@ def HeaderPreamble(n):
// Makes sure this header is not included before gtest.h. // Makes sure this header is not included before gtest.h.
#ifndef GTEST_INCLUDE_GTEST_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_ #endif // GTEST_INCLUDE_GTEST_GTEST_H_
// This header implements a family of generic predicate assertion // 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. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, on_failure)\\ #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) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED%(n)s. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED%(n)s. Don't use

View File

@ -913,6 +913,7 @@ class Arguments {
char* const* Argv() { char* const* Argv() {
return &args_[0]; return &args_[0];
} }
private: private:
std::vector<char*> args_; std::vector<char*> args_;
}; };

View File

@ -196,6 +196,7 @@ class GTestFlagSaver {
GTEST_FLAG(stream_result_to) = stream_result_to_; GTEST_FLAG(stream_result_to) = stream_result_to_;
GTEST_FLAG(throw_on_failure) = throw_on_failure_; GTEST_FLAG(throw_on_failure) = throw_on_failure_;
} }
private: private:
// Fields for saving the original values of flags. // Fields for saving the original values of flags.
bool also_run_disabled_tests_; bool also_run_disabled_tests_;

View File

@ -514,7 +514,6 @@ class CapturedStream {
public: public:
// The ctor redirects the stream to a temporary file. // The ctor redirects the stream to a temporary file.
CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
# if GTEST_OS_WINDOWS # if GTEST_OS_WINDOWS
char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT
char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT

View File

@ -3864,7 +3864,6 @@ int UnitTest::Run() {
// process. In either case the user does not want to see pop-up dialogs // process. In either case the user does not want to see pop-up dialogs
// about crashes - they are expected. // about crashes - they are expected.
if (impl()->catch_exceptions() || in_death_test_child_process) { if (impl()->catch_exceptions() || in_death_test_child_process) {
# if !GTEST_OS_WINDOWS_MOBILE # if !GTEST_OS_WINDOWS_MOBILE
// SetErrorMode doesn't exist on CE. // SetErrorMode doesn't exist on CE.
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
@ -3895,7 +3894,6 @@ int UnitTest::Run() {
0x0, // Clear the following flags: 0x0, // Clear the following flags:
_WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump. _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump.
# endif # endif
} }
#endif // GTEST_HAS_SEH #endif // GTEST_HAS_SEH

View File

@ -27,13 +27,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream> #include <stdio.h>
#include "gtest/gtest.h" #include "gtest/gtest.h"
GTEST_API_ int main(int argc, char **argv) { 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); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }

View File

@ -896,6 +896,7 @@ class MockDeathTest : public DeathTest {
virtual void Abort(AbortReason reason) { virtual void Abort(AbortReason reason) {
parent_->abort_args_.push_back(reason); parent_->abort_args_.push_back(reason);
} }
private: private:
MockDeathTestFactory* const parent_; MockDeathTestFactory* const parent_;
const TestRole role_; const TestRole role_;

View File

@ -148,8 +148,7 @@ TEST_F(LinkedPtrTest, GeneralTest) {
"A0 dtor\n" "A0 dtor\n"
"A3 dtor\n" "A3 dtor\n"
"A1 dtor\n", "A1 dtor\n",
history->GetString().c_str() history->GetString().c_str());
);
} }
} // Unnamed namespace } // Unnamed namespace

View File

@ -55,7 +55,7 @@ namespace internal {
class EventRecordingListener : public TestEventListener { class EventRecordingListener : public TestEventListener {
public: public:
EventRecordingListener(const char* name) : name_(name) {} explicit EventRecordingListener(const char* name) : name_(name) {}
protected: protected:
virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) { virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {

View File

@ -606,6 +606,7 @@ class TestGenerationEnvironment : public ::testing::Environment {
<< "has not been run as expected."; << "has not been run as expected.";
} }
} }
private: private:
TestGenerationEnvironment() : fixture_constructor_count_(0), set_up_count_(0), TestGenerationEnvironment() : fixture_constructor_count_(0), set_up_count_(0),
tear_down_count_(0), test_body_count_(0) {} tear_down_count_(0), test_body_count_(0) {}
@ -674,6 +675,7 @@ class TestGenerationTest : public TestWithParam<int> {
EXPECT_TRUE(collected_parameters_ == expected_values); EXPECT_TRUE(collected_parameters_ == expected_values);
} }
protected: protected:
int current_parameter_; int current_parameter_;
static vector<int> collected_parameters_; static vector<int> collected_parameters_;

View File

@ -43,12 +43,14 @@
// Test fixture for testing definition and instantiation of a test // Test fixture for testing definition and instantiation of a test
// in separate translation units. // in separate translation units.
class ExternalInstantiationTest : public ::testing::TestWithParam<int> {}; class ExternalInstantiationTest : public ::testing::TestWithParam<int> {
};
// Test fixture for testing instantiation of a test in multiple // Test fixture for testing instantiation of a test in multiple
// translation units. // translation units.
class InstantiationInMultipleTranslaionUnitsTest class InstantiationInMultipleTranslaionUnitsTest
: public ::testing::TestWithParam<int> {}; : public ::testing::TestWithParam<int> {
};
#endif // GTEST_HAS_PARAM_TEST #endif // GTEST_HAS_PARAM_TEST

View File

@ -92,7 +92,7 @@ TEST(ImplicitCastTest, CanUseInheritance) {
class Castable { class Castable {
public: public:
Castable(bool* converted) : converted_(converted) {} explicit Castable(bool* converted) : converted_(converted) {}
operator Base() { operator Base() {
*converted_ = true; *converted_ = true;
return Base(); return Base();
@ -111,7 +111,7 @@ TEST(ImplicitCastTest, CanUseNonConstCastOperator) {
class ConstCastable { class ConstCastable {
public: public:
ConstCastable(bool* converted) : converted_(converted) {} explicit ConstCastable(bool* converted) : converted_(converted) {}
operator Base() const { operator Base() const {
*converted_ = true; *converted_ = true;
return Base(); return Base();
@ -224,7 +224,7 @@ TEST(GtestCheckSyntaxTest, WorksWithSwitch) {
GTEST_CHECK_(true); GTEST_CHECK_(true);
} }
switch(0) switch (0)
case 0: case 0:
GTEST_CHECK_(true) << "Check failed in switch case"; GTEST_CHECK_(true) << "Check failed in switch case";
} }
@ -929,7 +929,7 @@ TEST(CaptureTest, CapturesStdoutAndStderr) {
TEST(CaptureDeathTest, CannotReenterStdoutCapture) { TEST(CaptureDeathTest, CannotReenterStdoutCapture) {
CaptureStdout(); CaptureStdout();
EXPECT_DEATH_IF_SUPPORTED(CaptureStdout();, EXPECT_DEATH_IF_SUPPORTED(CaptureStdout(),
"Only one stdout capturer can exist at a time"); "Only one stdout capturer can exist at a time");
GetCapturedStdout(); GetCapturedStdout();

View File

@ -841,7 +841,7 @@ TEST(PrintStlContainerTest, HashMultiSet) {
std::vector<int> numbers; std::vector<int> numbers;
for (size_t i = 0; i != result.length(); i++) { for (size_t i = 0; i != result.length(); i++) {
if (expected_pattern[i] == 'd') { if (expected_pattern[i] == 'd') {
ASSERT_TRUE(isdigit(static_cast<unsigned char>(result[i])) != 0); ASSERT_NE(isdigit(static_cast<unsigned char>(result[i])), 0);
numbers.push_back(result[i] - '0'); numbers.push_back(result[i] - '0');
} else { } else {
EXPECT_EQ(expected_pattern[i], result[i]) << " where result is " EXPECT_EQ(expected_pattern[i], result[i]) << " where result is "

View File

@ -96,6 +96,7 @@ class MyEnvironment : public testing::Environment {
// Was TearDown() run? // Was TearDown() run?
bool tear_down_was_run() const { return tear_down_was_run_; } bool tear_down_was_run() const { return tear_down_was_run_; }
private: private:
FailureType failure_in_set_up_; FailureType failure_in_set_up_;
bool set_up_was_run_; bool set_up_was_run_;

View File

@ -34,7 +34,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);

View File

@ -378,6 +378,7 @@ class FatalFailureInFixtureConstructorTest : public testing::Test {
<< "We should never get here, as the test fixture c'tor " << "We should never get here, as the test fixture c'tor "
<< "had a fatal failure."; << "had a fatal failure.";
} }
private: private:
void Init() { void Init() {
FAIL() << "Expected failure #1, in the test fixture c'tor."; FAIL() << "Expected failure #1, in the test fixture c'tor.";

View File

@ -27,7 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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! // 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
// Regression test for gtest_pred_impl.h // Regression test for gtest_pred_impl.h

View File

@ -71,7 +71,7 @@ namespace {
<< "Which is: " << expected_val << "\n";\ << "Which is: " << expected_val << "\n";\
::testing::internal::posix::Abort();\ ::testing::internal::posix::Abort();\
}\ }\
} while(::testing::internal::AlwaysFalse()) } while (::testing::internal::AlwaysFalse())
// Used for verifying that global environment set-up and tear-down are // Used for verifying that global environment set-up and tear-down are

View File

@ -33,8 +33,6 @@
// Google Test work. // Google Test work.
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <vector>
#include <ostream>
// Verifies that the command line flag variables can be accessed // Verifies that the command line flag variables can be accessed
// in code once <gtest/gtest.h> has been #included. // in code once <gtest/gtest.h> has been #included.
@ -58,6 +56,15 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
EXPECT_TRUE(dummy || !dummy); // Suppresses warning that dummy is unused. EXPECT_TRUE(dummy || !dummy); // Suppresses warning that dummy is unused.
} }
#include <limits.h> // For INT_MAX.
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <map>
#include <vector>
#include <ostream>
#include "gtest/gtest-spi.h" #include "gtest/gtest-spi.h"
// Indicates that this translation unit is part of Google Test's // Indicates that this translation unit is part of Google Test's
@ -69,13 +76,6 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
#include "src/gtest-internal-inl.h" #include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_ #undef GTEST_IMPLEMENTATION_
#include <limits.h> // For INT_MAX.
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <map>
namespace testing { namespace testing {
namespace internal { namespace internal {
@ -1141,7 +1141,7 @@ TEST(StringTest, Equals) {
EXPECT_TRUE(foo == "foo"); // NOLINT EXPECT_TRUE(foo == "foo"); // NOLINT
const String bar("x\0y", 3); const String bar("x\0y", 3);
EXPECT_FALSE(bar == "x"); EXPECT_NE(bar, "x");
} }
// Tests String::operator!=(). // Tests String::operator!=().
@ -1163,7 +1163,7 @@ TEST(StringTest, NotEquals) {
EXPECT_FALSE(foo != "foo"); // NOLINT EXPECT_FALSE(foo != "foo"); // NOLINT
const String bar("x\0y", 3); const String bar("x\0y", 3);
EXPECT_TRUE(bar != "x"); EXPECT_NE(bar, "x");
} }
// Tests String::length(). // Tests String::length().
@ -1902,6 +1902,7 @@ class GTestFlagSaverTest : public Test {
GTEST_FLAG(stream_result_to) = "localhost:1234"; GTEST_FLAG(stream_result_to) = "localhost:1234";
GTEST_FLAG(throw_on_failure) = true; GTEST_FLAG(throw_on_failure) = true;
} }
private: private:
// For saving Google Test flags during this test case. // For saving Google Test flags during this test case.
static GTestFlagSaver* saver_; static GTestFlagSaver* saver_;
@ -2797,7 +2798,6 @@ TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
template <typename RawType> template <typename RawType>
class FloatingPointTest : public Test { class FloatingPointTest : public Test {
protected: protected:
// Pre-calculated numbers to be used by the tests. // Pre-calculated numbers to be used by the tests.
struct TestValues { struct TestValues {
RawType close_to_positive_zero; RawType close_to_positive_zero;
@ -7278,6 +7278,7 @@ TEST(ArrayEqTest, WorksForDegeneratedArrays) {
} }
TEST(ArrayEqTest, WorksForOneDimensionalArrays) { TEST(ArrayEqTest, WorksForOneDimensionalArrays) {
// Note that a and b are distinct but compatible types.
const int a[] = { 0, 1 }; const int a[] = { 0, 1 };
long b[] = { 0, 1 }; long b[] = { 0, 1 };
EXPECT_TRUE(ArrayEq(a, b)); EXPECT_TRUE(ArrayEq(a, b));