From 4bb49ed640e34e23187ad7ea689693ef9927033f Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 4 Oct 2018 18:28:05 -0400 Subject: Apply clang-tidy modernize-use-nullptr to googletest. Now that googletest has moved to C++11, it should no longer use NULL or 0 for the null pointer. This patch converts all such usages to nullptr using clang-tidy. This prevents LLVM from issuing -Wzero-as-null-pointer-constant warnings. PiperOrigin-RevId: 215814400 --- googlemock/include/gmock/gmock-actions.h | 29 +- googlemock/include/gmock/gmock-matchers.h | 48 +- googlemock/include/gmock/gmock-spec-builders.h | 20 +- googlemock/src/gmock-spec-builders.cc | 41 +- googlemock/src/gmock.cc | 12 +- googlemock/test/gmock-actions_test.cc | 28 +- .../test/gmock-generated-function-mockers_test.cc | 2 +- googlemock/test/gmock-generated-matchers_test.cc | 4 +- googlemock/test/gmock-internal-utils_test.cc | 6 +- googlemock/test/gmock-matchers_test.cc | 124 ++-- googlemock/test/gmock-more-actions_test.cc | 3 +- googlemock/test/gmock-spec-builders_test.cc | 6 +- googlemock/test/gmock_link_test.h | 38 +- googlemock/test/gmock_stress_test.cc | 8 +- googlemock/test/gmock_test.cc | 148 +---- googletest/include/gtest/gtest-message.h | 2 +- googletest/include/gtest/gtest-printers.h | 8 +- googletest/include/gtest/gtest-test-part.h | 11 +- googletest/include/gtest/gtest.h | 41 +- googletest/include/gtest/internal/gtest-internal.h | 10 +- .../include/gtest/internal/gtest-linked_ptr.h | 4 +- .../include/gtest/internal/gtest-param-util.h | 18 +- googletest/include/gtest/internal/gtest-port.h | 27 +- .../include/gtest/internal/gtest-type-util.h | 2 +- googletest/samples/sample10_unittest.cc | 2 +- googletest/samples/sample2.cc | 2 +- googletest/samples/sample2.h | 10 +- googletest/samples/sample2_unittest.cc | 6 +- googletest/samples/sample3-inl.h | 16 +- googletest/samples/sample3_unittest.cc | 10 +- googletest/samples/sample5_unittest.cc | 12 +- googletest/samples/sample7_unittest.cc | 2 +- googletest/samples/sample8_unittest.cc | 11 +- googletest/src/gtest-death-test.cc | 20 +- googletest/src/gtest-filepath.cc | 4 +- googletest/src/gtest-internal-inl.h | 7 +- googletest/src/gtest-port.cc | 27 +- googletest/src/gtest-printers.cc | 4 +- googletest/src/gtest-test-part.cc | 3 +- googletest/src/gtest-typed-test.cc | 2 +- googletest/src/gtest.cc | 203 +++--- .../test/googletest-catch-exceptions-test_.cc | 2 +- googletest/test/googletest-death-test-test.cc | 21 +- googletest/test/googletest-linked-ptr-test.cc | 20 +- googletest/test/googletest-listener-test.cc | 2 +- googletest/test/googletest-message-test.cc | 4 +- googletest/test/googletest-output-test_.cc | 11 +- googletest/test/googletest-port-test.cc | 26 +- googletest/test/googletest-printers-test.cc | 28 +- .../test/googletest-throw-on-failure-test_.cc | 2 +- googletest/test/googletest-tuple-test.cc | 2 +- googletest/test/gtest-typed-test_test.cc | 8 +- googletest/test/gtest-unittest-api_test.cc | 12 +- googletest/test/gtest_assert_by_exception_test.cc | 3 +- googletest/test/gtest_premature_exit_test.cc | 4 +- googletest/test/gtest_stress_test.cc | 2 +- googletest/test/gtest_throw_on_failure_ex_test.cc | 3 +- googletest/test/gtest_unittest.cc | 693 ++++++--------------- 58 files changed, 711 insertions(+), 1113 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index b82313d..e3b3f09 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -137,7 +137,7 @@ template class BuiltInDefaultValue { public: static bool Exists() { return true; } - static T* Get() { return NULL; } + static T* Get() { return nullptr; } }; // The following specializations define the default values for @@ -220,11 +220,11 @@ class DefaultValue { // Unsets the default value for type T. static void Clear() { delete producer_; - producer_ = NULL; + producer_ = nullptr; } // Returns true iff the user has set the default value for type T. - static bool IsSet() { return producer_ != NULL; } + static bool IsSet() { return producer_ != nullptr; } // Returns true if T has a default return value set by the user or there // exists a built-in default value. @@ -236,8 +236,8 @@ class DefaultValue { // otherwise returns the built-in default value. Requires that Exists() // is true, which ensures that the return value is well-defined. static T Get() { - return producer_ == NULL ? - internal::BuiltInDefaultValue::Get() : producer_->Produce(); + return producer_ == nullptr ? internal::BuiltInDefaultValue::Get() + : producer_->Produce(); } private: @@ -282,12 +282,10 @@ class DefaultValue { } // Unsets the default value for type T&. - static void Clear() { - address_ = NULL; - } + static void Clear() { address_ = nullptr; } // Returns true iff the user has set the default value for type T&. - static bool IsSet() { return address_ != NULL; } + static bool IsSet() { return address_ != nullptr; } // Returns true if T has a default return value set by the user or there // exists a built-in default value. @@ -299,8 +297,8 @@ class DefaultValue { // otherwise returns the built-in default value if there is one; // otherwise aborts the process. static T& Get() { - return address_ == NULL ? - internal::BuiltInDefaultValue::Get() : *address_; + return address_ == nullptr ? internal::BuiltInDefaultValue::Get() + : *address_; } private: @@ -318,11 +316,11 @@ class DefaultValue { // Points to the user-set default value for type T. template -typename DefaultValue::ValueProducer* DefaultValue::producer_ = NULL; +typename DefaultValue::ValueProducer* DefaultValue::producer_ = nullptr; // Points to the user-set default value for type T&. template -T* DefaultValue::address_ = NULL; +T* DefaultValue::address_ = nullptr; // Implement this interface to define an action for function type F. template @@ -1108,8 +1106,9 @@ Action::Action(const Action& from) #if GTEST_LANG_CXX11 fun_(from.fun_), #endif - impl_(from.impl_ == NULL ? NULL - : new internal::ActionAdaptor(from)) { + impl_(from.impl_ == nullptr + ? nullptr + : new internal::ActionAdaptor(from)) { } // Creates an action that returns 'value'. 'value' is passed by value diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index b4961d4..0f7745e 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -94,8 +94,7 @@ class MatchResultListener { // is NULL. template MatchResultListener& operator<<(const T& x) { - if (stream_ != NULL) - *stream_ << x; + if (stream_ != nullptr) *stream_ << x; return *this; } @@ -106,7 +105,7 @@ class MatchResultListener { // the match result. A matcher's MatchAndExplain() method can use // this information to avoid generating the explanation when no one // intends to hear it. - bool IsInterested() const { return stream_ != NULL; } + bool IsInterested() const { return stream_ != nullptr; } private: ::std::ostream* const stream_; @@ -261,7 +260,7 @@ struct AnyGe { // A match result listener that ignores the explanation. class DummyMatchResultListener : public MatchResultListener { public: - DummyMatchResultListener() : MatchResultListener(NULL) {} + DummyMatchResultListener() : MatchResultListener(nullptr) {} private: GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener); @@ -333,7 +332,7 @@ class MatcherBase { const MatcherInterface* impl, typename internal::EnableIf< !internal::IsSame::value>::type* = - NULL) + nullptr) : impl_(new internal::MatcherInterfaceAdapter(impl)) {} virtual ~MatcherBase() {} @@ -375,9 +374,11 @@ class Matcher : public internal::MatcherBase { : internal::MatcherBase(impl) {} template - explicit Matcher(const MatcherInterface* impl, - typename internal::EnableIf::value>::type* = NULL) + explicit Matcher( + const MatcherInterface* impl, + typename internal::EnableIf< + !internal::IsSame::value>::type* = + nullptr) : internal::MatcherBase(impl) {} // Implicit constructor here allows people to write @@ -850,7 +851,7 @@ namespace internal { // If the explanation is not empty, prints it to the ostream. inline void PrintIfNotEmpty(const std::string& explanation, ::std::ostream* os) { - if (explanation != "" && os != NULL) { + if (explanation != "" && os != nullptr) { *os << ", " << explanation; } } @@ -1321,7 +1322,7 @@ class StrEqualityMatcher { // wchar_t* template bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - if (s == NULL) { + if (s == nullptr) { return !expect_eq_; } return MatchAndExplain(StringType(s), listener); @@ -1391,7 +1392,7 @@ class HasSubstrMatcher { // wchar_t* template bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(StringType(s), listener); + return s != nullptr && MatchAndExplain(StringType(s), listener); } // Matches anything that can convert to StringType. @@ -1448,7 +1449,7 @@ class StartsWithMatcher { // wchar_t* template bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(StringType(s), listener); + return s != nullptr && MatchAndExplain(StringType(s), listener); } // Matches anything that can convert to StringType. @@ -1504,7 +1505,7 @@ class EndsWithMatcher { // wchar_t* template bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(StringType(s), listener); + return s != nullptr && MatchAndExplain(StringType(s), listener); } // Matches anything that can convert to StringType. @@ -1557,7 +1558,7 @@ class MatchesRegexMatcher { // wchar_t* template bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(std::string(s), listener); + return s != nullptr && MatchAndExplain(std::string(s), listener); } // Matches anything that can convert to std::string. @@ -2347,8 +2348,7 @@ class PointeeMatcher { virtual bool MatchAndExplain(Pointer pointer, MatchResultListener* listener) const { - if (GetRawPointer(pointer) == NULL) - return false; + if (GetRawPointer(pointer) == nullptr) return false; *listener << "which points to "; return MatchPrintAndExplain(*pointer, matcher_, listener); @@ -2431,7 +2431,7 @@ class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase { bool MatchAndExplain(From& from, MatchResultListener* listener) const { // We don't want an std::bad_cast here, so do the cast with pointers. To* to = dynamic_cast(&from); - if (to == NULL) { + if (to == nullptr) { *listener << "which cannot be dynamic_cast to " << this->GetToName(); return false; } @@ -2485,8 +2485,7 @@ class FieldMatcher { bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, MatchResultListener* listener) const { - if (p == NULL) - return false; + if (p == nullptr) return false; *listener << "which points to an object "; // Since *p has a field, it must be a class/struct/union type and @@ -2570,8 +2569,7 @@ class PropertyMatcher { bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, MatchResultListener* listener) const { - if (p == NULL) - return false; + if (p == nullptr) return false; *listener << "which points to an object "; // Since *p has a property method, it must be a class/struct/union @@ -2615,7 +2613,7 @@ struct CallableTraits { typedef ResType(*StorageType)(ArgType); static void CheckIsValid(ResType(*f)(ArgType)) { - GTEST_CHECK_(f != NULL) + GTEST_CHECK_(f != nullptr) << "NULL function pointer is passed into ResultOf()."; } template @@ -2857,7 +2855,7 @@ class ContainerEqMatcher { return true; ::std::ostream* const os = listener->stream(); - if (os != NULL) { + if (os != nullptr) { // Something is different. Check for extra values first. bool printed_header = false; for (typename LhsStlContainer::const_iterator it = @@ -4136,11 +4134,11 @@ class AnyCastMatcher { ::testing::MatchResultListener* listener) const { if (!listener->IsInterested()) { const T* ptr = any_cast(&value); - return ptr != NULL && matcher_.Matches(*ptr); + return ptr != nullptr && matcher_.Matches(*ptr); } const T* elem = any_cast(&value); - if (elem == NULL) { + if (elem == nullptr) { *listener << "whose value is not of type '" << GetTypeName() << "'"; return false; } diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index 436e2d8..c8e864c 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -1213,7 +1213,7 @@ class TypedExpectation : public ExpectationBase { // FIXME: allow the user to control whether // unexpected calls should fail immediately or continue using a // flag --gmock_unexpected_calls_are_fatal. - return NULL; + return nullptr; } IncrementCallCount(); @@ -1498,7 +1498,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { return spec; } - return NULL; + return nullptr; } // Performs the default action of this mock function on the given @@ -1513,7 +1513,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { const std::string& call_description) const { const OnCallSpec* const spec = this->FindOnCallSpec(args); - if (spec != NULL) { + if (spec != nullptr) { return spec->GetAction().Perform(internal::move(args)); } const std::string message = @@ -1630,7 +1630,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // Adds this expectation into the implicit sequence if there is one. Sequence* const implicit_sequence = g_gmock_implicit_sequence.get(); - if (implicit_sequence != NULL) { + if (implicit_sequence != nullptr) { implicit_sequence->AddExpectation(Expectation(untyped_expectation)); } @@ -1649,7 +1649,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ::std::ostream* os) const { const OnCallSpec* const spec = FindOnCallSpec(args); - if (spec == NULL) { + if (spec == nullptr) { *os << (internal::type_equals::value ? "returning directly.\n" : "returning default value.\n"); @@ -1699,9 +1699,9 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { *static_cast(untyped_args); MutexLock l(&g_gmock_mutex); TypedExpectation* exp = this->FindMatchingExpectationLocked(args); - if (exp == NULL) { // A match wasn't found. + if (exp == nullptr) { // A match wasn't found. this->FormatUnexpectedCallMessageLocked(args, what, why); - return NULL; + return nullptr; } // This line must be done before calling GetActionForArguments(), @@ -1709,8 +1709,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // its saturation status. *is_excessive = exp->IsSaturated(); const Action* action = exp->GetActionForArguments(this, args, what, why); - if (action != NULL && action->IsDoDefault()) - action = NULL; // Normalize "do default" to NULL. + if (action != nullptr && action->IsDoDefault()) + action = nullptr; // Normalize "do default" to NULL. *untyped_action = action; return exp; } @@ -1740,7 +1740,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { return exp; } } - return NULL; + return nullptr; } // Returns a message that the arguments don't match any expectation. diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index b93f4e0..1a8def4 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -296,12 +296,12 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { stack_frames_to_skip); break; default: // FAIL - Expect(false, NULL, -1, msg); + Expect(false, nullptr, -1, msg); } } UntypedFunctionMockerBase::UntypedFunctionMockerBase() - : mock_obj_(NULL), name_("") {} + : mock_obj_(nullptr), name_("") {} UntypedFunctionMockerBase::~UntypedFunctionMockerBase() {} @@ -340,7 +340,7 @@ const void* UntypedFunctionMockerBase::MockObject() const // We protect mock_obj_ under g_gmock_mutex in case this mock // function is called from two threads concurrently. MutexLock l(&g_gmock_mutex); - Assert(mock_obj_ != NULL, __FILE__, __LINE__, + Assert(mock_obj_ != nullptr, __FILE__, __LINE__, "MockObject() must not be called before RegisterOwner() or " "SetOwnerAndName() has been called."); mock_obj = mock_obj_; @@ -357,7 +357,7 @@ const char* UntypedFunctionMockerBase::Name() const // We protect name_ under g_gmock_mutex in case this mock // function is called from two threads concurrently. MutexLock l(&g_gmock_mutex); - Assert(name_ != NULL, __FILE__, __LINE__, + Assert(name_ != nullptr, __FILE__, __LINE__, "Name() must not be called before SetOwnerAndName() has " "been called."); name = name_; @@ -414,8 +414,7 @@ UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith( this->UntypedPerformDefaultAction(untyped_args, ss.str()); // Prints the function result. - if (result != NULL) - result->PrintAsActionResult(&ss); + if (result != nullptr) result->PrintAsActionResult(&ss); ReportUninterestingCall(reaction, ss.str()); return result; @@ -425,7 +424,7 @@ UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith( ::std::stringstream ss; ::std::stringstream why; ::std::stringstream loc; - const void* untyped_action = NULL; + const void* untyped_action = nullptr; // The UntypedFindMatchingExpectation() function acquires and // releases g_gmock_mutex. @@ -433,7 +432,7 @@ UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith( this->UntypedFindMatchingExpectation( untyped_args, &untyped_action, &is_excessive, &ss, &why); - const bool found = untyped_expectation != NULL; + const bool found = untyped_expectation != nullptr; // True iff we need to print the call's arguments and return value. // This definition must be kept in sync with the uses of Expect() @@ -442,10 +441,9 @@ UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith( !found || is_excessive || LogIsVisible(kInfo); if (!need_to_report_call) { // Perform the action without printing the call information. - return - untyped_action == NULL ? - this->UntypedPerformDefaultAction(untyped_args, "") : - this->UntypedPerformAction(untyped_action, untyped_args); + return untyped_action == nullptr + ? this->UntypedPerformDefaultAction(untyped_args, "") + : this->UntypedPerformAction(untyped_action, untyped_args); } ss << " Function call: " << Name(); @@ -458,16 +456,15 @@ UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith( } UntypedActionResultHolderBase* const result = - untyped_action == NULL ? - this->UntypedPerformDefaultAction(untyped_args, ss.str()) : - this->UntypedPerformAction(untyped_action, untyped_args); - if (result != NULL) - result->PrintAsActionResult(&ss); + untyped_action == nullptr + ? this->UntypedPerformDefaultAction(untyped_args, ss.str()) + : this->UntypedPerformAction(untyped_action, untyped_args); + if (result != nullptr) result->PrintAsActionResult(&ss); ss << "\n" << why.str(); if (!found) { // No expectation matches this call - reports a failure. - Expect(false, NULL, -1, ss.str()); + Expect(false, nullptr, -1, ss.str()); } else if (is_excessive) { // We had an upper-bound violation and the failure message is in ss. Expect(false, untyped_expectation->file(), @@ -568,7 +565,7 @@ typedef std::set FunctionMockers; // expectations. struct MockObjectState { MockObjectState() - : first_used_file(NULL), first_used_line(-1), leakable(false) {} + : first_used_file(nullptr), first_used_line(-1), leakable(false) {} // Where in the source file an ON_CALL or EXPECT_CALL is first // invoked on this mock object. @@ -776,12 +773,12 @@ void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj, GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { internal::MutexLock l(&internal::g_gmock_mutex); MockObjectState& state = g_mock_object_registry.states()[mock_obj]; - if (state.first_used_file == NULL) { + if (state.first_used_file == nullptr) { state.first_used_file = file; state.first_used_line = line; const TestInfo* const test_info = UnitTest::GetInstance()->current_test_info(); - if (test_info != NULL) { + if (test_info != nullptr) { // FIXME: record the test case name when the // ON_CALL or EXPECT_CALL is invoked from SetUpTestCase() or // TearDownTestCase(). @@ -846,7 +843,7 @@ Expectation::~Expectation() {} // Adds an expectation to a sequence. void Sequence::AddExpectation(const Expectation& expectation) const { if (*last_expectation_ != expectation) { - if (last_expectation_->expectation_base() != NULL) { + if (last_expectation_->expectation_base() != nullptr) { expectation.expectation_base()->immediate_prerequisites_ += *last_expectation_; } diff --git a/googlemock/src/gmock.cc b/googlemock/src/gmock.cc index 36356c9..675e8db 100644 --- a/googlemock/src/gmock.cc +++ b/googlemock/src/gmock.cc @@ -65,12 +65,12 @@ static const char* ParseGoogleMockFlagValue(const char* str, const char* flag, bool def_optional) { // str and flag must not be NULL. - if (str == NULL || flag == NULL) return NULL; + if (str == nullptr || flag == nullptr) return nullptr; // The flag must start with "--gmock_". const std::string flag_str = std::string("--gmock_") + flag; const size_t flag_len = flag_str.length(); - if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL; + if (strncmp(str, flag_str.c_str(), flag_len) != 0) return nullptr; // Skips the flag name. const char* flag_end = str + flag_len; @@ -83,7 +83,7 @@ static const char* ParseGoogleMockFlagValue(const char* str, // If def_optional is true and there are more characters after the // flag name, or if def_optional is false, there must be a '=' after // the flag name. - if (flag_end[0] != '=') return NULL; + if (flag_end[0] != '=') return nullptr; // Returns the string after "=". return flag_end + 1; @@ -100,7 +100,7 @@ static bool ParseGoogleMockBoolFlag(const char* str, const char* flag, const char* const value_str = ParseGoogleMockFlagValue(str, flag, true); // Aborts if the parsing failed. - if (value_str == NULL) return false; + if (value_str == nullptr) return false; // Converts the string value to a bool. *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F'); @@ -119,7 +119,7 @@ static bool ParseGoogleMockStringFlag(const char* str, const char* flag, const char* const value_str = ParseGoogleMockFlagValue(str, flag, false); // Aborts if the parsing failed. - if (value_str == NULL) return false; + if (value_str == nullptr) return false; // Sets *value to the value of the flag. *value = value_str; @@ -132,7 +132,7 @@ static bool ParseGoogleMockIntFlag(const char* str, const char* flag, const char* const value_str = ParseGoogleMockFlagValue(str, flag, true); // Aborts if the parsing failed. - if (value_str == NULL) return false; + if (value_str == nullptr) return false; // Sets *value to the value of the flag. return ParseInt32(Message() << "The value of flag --" << flag, diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 06e29a1..7db5d3c 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -89,9 +89,9 @@ using testing::SetErrnoAndReturn; // Tests that BuiltInDefaultValue::Get() returns NULL. TEST(BuiltInDefaultValueTest, IsNullForPointerTypes) { - EXPECT_TRUE(BuiltInDefaultValue::Get() == NULL); - EXPECT_TRUE(BuiltInDefaultValue::Get() == NULL); - EXPECT_TRUE(BuiltInDefaultValue::Get() == NULL); + EXPECT_TRUE(BuiltInDefaultValue::Get() == nullptr); + EXPECT_TRUE(BuiltInDefaultValue::Get() == nullptr); + EXPECT_TRUE(BuiltInDefaultValue::Get() == nullptr); } // Tests that BuiltInDefaultValue::Exists() return true. @@ -196,7 +196,7 @@ TEST(BuiltInDefaultValueTest, ExistsForString) { TEST(BuiltInDefaultValueTest, WorksForConstTypes) { EXPECT_EQ("", BuiltInDefaultValue::Get()); EXPECT_EQ(0, BuiltInDefaultValue::Get()); - EXPECT_TRUE(BuiltInDefaultValue::Get() == NULL); + EXPECT_TRUE(BuiltInDefaultValue::Get() == nullptr); EXPECT_FALSE(BuiltInDefaultValue::Get()); } @@ -306,7 +306,7 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) { #if GTEST_HAS_STD_UNIQUE_PTR_ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) { EXPECT_TRUE(DefaultValue>::Exists()); - EXPECT_TRUE(DefaultValue>::Get() == NULL); + EXPECT_TRUE(DefaultValue>::Get() == nullptr); DefaultValue>::SetFactory([] { return std::unique_ptr(new int(42)); }); @@ -519,7 +519,7 @@ TEST(MakePolymorphicActionTest, WorksWhenPerformHasOneTemplateParameter) { EXPECT_EQ(0, a1.Perform(make_tuple())); Action a2 = ReturnZeroFromNullaryFunction(); - EXPECT_TRUE(a2.Perform(make_tuple()) == NULL); + EXPECT_TRUE(a2.Perform(make_tuple()) == nullptr); } // Tests that Return() works as an action for void-returning @@ -636,10 +636,10 @@ TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) { // Tests that ReturnNull() returns NULL in a pointer-returning function. TEST(ReturnNullTest, WorksInPointerReturningFunction) { const Action a1 = ReturnNull(); - EXPECT_TRUE(a1.Perform(make_tuple()) == NULL); + EXPECT_TRUE(a1.Perform(make_tuple()) == nullptr); const Action a2 = ReturnNull(); // NOLINT - EXPECT_TRUE(a2.Perform(make_tuple(true)) == NULL); + EXPECT_TRUE(a2.Perform(make_tuple(true)) == nullptr); } #if GTEST_HAS_STD_UNIQUE_PTR_ @@ -819,10 +819,10 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) { typedef void MyFunction(std::string*, const char**); Action a = SetArgPointee<0>("hi"); std::string str; - const char* ptr = NULL; + const char* ptr = nullptr; a.Perform(make_tuple(&str, &ptr)); EXPECT_EQ("hi", str); - EXPECT_TRUE(ptr == NULL); + EXPECT_TRUE(ptr == nullptr); a = SetArgPointee<1>("world"); str = ""; @@ -834,7 +834,7 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) { TEST(SetArgPointeeTest, AcceptsWideStringLiteral) { typedef void MyFunction(const wchar_t**); Action a = SetArgPointee<0>(L"world"); - const wchar_t* ptr = NULL; + const wchar_t* ptr = nullptr; a.Perform(make_tuple(&ptr)); EXPECT_STREQ(L"world", ptr); @@ -856,10 +856,10 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) { const char* const hi = "hi"; Action a = SetArgPointee<1>(hi); std::string str; - const char* ptr = NULL; + const char* ptr = nullptr; a.Perform(make_tuple(true, &str, &ptr)); EXPECT_EQ("hi", str); - EXPECT_TRUE(ptr == NULL); + EXPECT_TRUE(ptr == nullptr); char world_array[] = "world"; char* const world = world_array; @@ -874,7 +874,7 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) { typedef void MyFunction(bool, const wchar_t**); const wchar_t* const hi = L"hi"; Action a = SetArgPointee<1>(hi); - const wchar_t* ptr = NULL; + const wchar_t* ptr = nullptr; a.Perform(make_tuple(true, &ptr)); EXPECT_EQ(hi, ptr); diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc index 4c49069..820a2b6 100644 --- a/googlemock/test/gmock-generated-function-mockers_test.cc +++ b/googlemock/test/gmock-generated-function-mockers_test.cc @@ -228,7 +228,7 @@ TEST_F(FunctionMockerTest, MocksDecimalFunction) { Lt(100), 5U, NULL, "hi")) .WillOnce(Return(5)); - EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, NULL, "hi")); + EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi")); } // Tests mocking a function that takes a non-const reference. diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 0ebd470..10a4ac3 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -697,7 +697,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithIteratorRange) { // Pointers are iterators, too. EXPECT_THAT(test_vector, ElementsAreArray(a, a + GTEST_ARRAY_SIZE_(a))); // The empty range of NULL pointers should also be okay. - int* const null_int = NULL; + int* const null_int = nullptr; EXPECT_THAT(test_vector, Not(ElementsAreArray(null_int, null_int))); EXPECT_THAT((vector()), ElementsAreArray(null_int, null_int)); } @@ -770,7 +770,7 @@ MATCHER_P2(EqSumOf, x, y, std::string(negation ? "doesn't equal" : "equals") + } else { // Verifies that we can stream to the underlying stream of // result_listener. - if (result_listener->stream() != NULL) { + if (result_listener->stream() != nullptr) { *result_listener->stream() << "diff == " << (x + y - arg); } return false; diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 5f53077..7116e4f 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -158,9 +158,9 @@ TEST(GetRawPointerTest, WorksForSmartPointers) { } TEST(GetRawPointerTest, WorksForRawPointers) { - int* p = NULL; + int* p = nullptr; // Don't use EXPECT_EQ as no NULL-testing magic on Symbian. - EXPECT_TRUE(NULL == GetRawPointer(p)); + EXPECT_TRUE(nullptr == GetRawPointer(p)); int n = 1; EXPECT_EQ(&n, GetRawPointer(&n)); } @@ -492,7 +492,7 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) { AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10))); // Restores the default OS stack trace getter. - GetUnitTestImpl()->set_os_stack_trace_getter(NULL); + GetUnitTestImpl()->set_os_stack_trace_getter(nullptr); } // Tests that all logs are printed when the value of the diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 79eb552..ceff5b0 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -238,8 +238,8 @@ TEST(MatchResultListenerTest, StreamingWorks) { } TEST(MatchResultListenerTest, CanAccessUnderlyingStream) { - EXPECT_TRUE(DummyMatchResultListener().stream() == NULL); - EXPECT_TRUE(StreamMatchResultListener(NULL).stream() == NULL); + EXPECT_TRUE(DummyMatchResultListener().stream() == nullptr); + EXPECT_TRUE(StreamMatchResultListener(nullptr).stream() == nullptr); EXPECT_EQ(&std::cout, StreamMatchResultListener(&std::cout).stream()); } @@ -249,7 +249,7 @@ TEST(MatchResultListenerTest, IsInterestedWorks) { EXPECT_TRUE(StreamMatchResultListener(&std::cout).IsInterested()); EXPECT_FALSE(DummyMatchResultListener().IsInterested()); - EXPECT_FALSE(StreamMatchResultListener(NULL).IsInterested()); + EXPECT_FALSE(StreamMatchResultListener(nullptr).IsInterested()); } // Makes sure that the MatcherInterface interface doesn't @@ -283,7 +283,7 @@ class NewEvenMatcherImpl : public MatcherInterface { const bool match = x % 2 == 0; // Verifies that we can stream to a listener directly. *listener << "value % " << 2; - if (listener->stream() != NULL) { + if (listener->stream() != nullptr) { // Verifies that we can stream to a listener's underlying stream // too. *listener->stream() << " == " << (x % 2); @@ -327,7 +327,7 @@ TEST(MatcherTest, CanBeImplicitlyConstructedFromValue) { // Tests that NULL can be used in place of Eq(NULL). TEST(MatcherTest, CanBeImplicitlyConstructedFromNULL) { Matcher m1 = NULL; - EXPECT_TRUE(m1.Matches(NULL)); + EXPECT_TRUE(m1.Matches(nullptr)); int n = 0; EXPECT_FALSE(m1.Matches(&n)); } @@ -512,7 +512,7 @@ TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromStringView) { // MatcherInterface* without requiring the user to explicitly // write the type. TEST(MakeMatcherTest, ConstructsMatcherFromMatcherInterface) { - const MatcherInterface* dummy_impl = NULL; + const MatcherInterface* dummy_impl = nullptr; Matcher m = MakeMatcher(dummy_impl); } @@ -571,7 +571,7 @@ class PolymorphicIsEvenImpl { bool MatchAndExplain(const T& x, MatchResultListener* listener) const { // Verifies that we can stream to the listener directly. *listener << "% " << 2; - if (listener->stream() != NULL) { + if (listener->stream() != nullptr) { // Verifies that we can stream to the listener's underlying stream // too. *listener->stream() << " == " << (x % 2); @@ -1154,13 +1154,13 @@ TEST(NeTest, CanDescribeSelf) { // Tests that IsNull() matches any NULL pointer of any type. TEST(IsNullTest, MatchesNullPointer) { Matcher m1 = IsNull(); - int* p1 = NULL; + int* p1 = nullptr; int n = 0; EXPECT_TRUE(m1.Matches(p1)); EXPECT_FALSE(m1.Matches(&n)); Matcher m2 = IsNull(); - const char* p2 = NULL; + const char* p2 = nullptr; EXPECT_TRUE(m2.Matches(p2)); EXPECT_FALSE(m2.Matches("hi")); @@ -1174,7 +1174,7 @@ TEST(IsNullTest, MatchesNullPointer) { // gmock_matchers_test::IsNullTest_MatchesNullPointer_Test::TestBody()') // gmock-matchers.h: (instantiating: 'testing::PolymorphicMatc Matcher m3 = IsNull(); - void* p3 = NULL; + void* p3 = nullptr; EXPECT_TRUE(m3.Matches(p3)); EXPECT_FALSE(m3.Matches(reinterpret_cast(0xbeef))); #endif @@ -1217,13 +1217,13 @@ TEST(IsNullTest, CanDescribeSelf) { // Tests that NotNull() matches any non-NULL pointer of any type. TEST(NotNullTest, MatchesNonNullPointer) { Matcher m1 = NotNull(); - int* p1 = NULL; + int* p1 = nullptr; int n = 0; EXPECT_FALSE(m1.Matches(p1)); EXPECT_TRUE(m1.Matches(&n)); Matcher m2 = NotNull(); - const char* p2 = NULL; + const char* p2 = nullptr; EXPECT_FALSE(m2.Matches(p2)); EXPECT_TRUE(m2.Matches("hi")); } @@ -1324,7 +1324,7 @@ TEST(StrEqTest, MatchesEqualString) { Matcher m = StrEq(std::string("Hello")); EXPECT_TRUE(m.Matches("Hello")); EXPECT_FALSE(m.Matches("hello")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrEq("Hello"); EXPECT_TRUE(m2.Matches("Hello")); @@ -1360,7 +1360,7 @@ TEST(StrEqTest, CanDescribeSelf) { TEST(StrNeTest, MatchesUnequalString) { Matcher m = StrNe("Hello"); EXPECT_TRUE(m.Matches("")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches("Hello")); Matcher m2 = StrNe(std::string("Hello")); @@ -1385,7 +1385,7 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) { EXPECT_TRUE(m.Matches("Hello")); EXPECT_TRUE(m.Matches("hello")); EXPECT_FALSE(m.Matches("Hi")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrCaseEq("Hello"); EXPECT_TRUE(m2.Matches("hello")); @@ -1433,7 +1433,7 @@ TEST(StrCaseEqTest, CanDescribeSelf) { TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) { Matcher m = StrCaseNe("Hello"); EXPECT_TRUE(m.Matches("Hi")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches("Hello")); EXPECT_FALSE(m.Matches("hello")); @@ -1475,17 +1475,17 @@ TEST(HasSubstrTest, WorksForCStrings) { const Matcher m1 = HasSubstr("foo"); EXPECT_TRUE(m1.Matches(const_cast("I love food."))); EXPECT_FALSE(m1.Matches(const_cast("tofo"))); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = HasSubstr("foo"); EXPECT_TRUE(m2.Matches("I love food.")); EXPECT_FALSE(m2.Matches("tofo")); - EXPECT_FALSE(m2.Matches(NULL)); + EXPECT_FALSE(m2.Matches(nullptr)); const Matcher m_empty = HasSubstr(""); EXPECT_TRUE(m_empty.Matches("not empty")); EXPECT_TRUE(m_empty.Matches("")); - EXPECT_FALSE(m_empty.Matches(NULL)); + EXPECT_FALSE(m_empty.Matches(nullptr)); } #if GTEST_HAS_ABSL @@ -1720,7 +1720,7 @@ TEST(StartsWithTest, MatchesStringWithGivenPrefix) { const Matcher m1 = StartsWith(std::string("")); EXPECT_TRUE(m1.Matches("Hi")); EXPECT_TRUE(m1.Matches("")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = StartsWith("Hi"); EXPECT_TRUE(m2.Matches("Hi")); @@ -1748,7 +1748,7 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) { const Matcher m1 = EndsWith(""); EXPECT_TRUE(m1.Matches("Hi")); EXPECT_TRUE(m1.Matches("")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = EndsWith(std::string("Hi")); EXPECT_TRUE(m2.Matches("Hi")); @@ -1786,7 +1786,7 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) { const Matcher m1 = MatchesRegex("a.*z"); EXPECT_TRUE(m1.Matches("az")); EXPECT_TRUE(m1.Matches("abcz")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = MatchesRegex(new RE("a.*z")); EXPECT_TRUE(m2.Matches("azbz")); @@ -1824,7 +1824,7 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) { const Matcher m1 = ContainsRegex(std::string("a.*z")); EXPECT_TRUE(m1.Matches("az")); EXPECT_TRUE(m1.Matches("0abcz1")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = ContainsRegex(new RE("a.*z")); EXPECT_TRUE(m2.Matches("azbz")); @@ -1862,7 +1862,7 @@ TEST(StdWideStrEqTest, MatchesEqual) { Matcher m = StrEq(::std::wstring(L"Hello")); EXPECT_TRUE(m.Matches(L"Hello")); EXPECT_FALSE(m.Matches(L"hello")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrEq(L"Hello"); EXPECT_TRUE(m2.Matches(L"Hello")); @@ -1902,7 +1902,7 @@ TEST(StdWideStrEqTest, CanDescribeSelf) { TEST(StdWideStrNeTest, MatchesUnequalString) { Matcher m = StrNe(L"Hello"); EXPECT_TRUE(m.Matches(L"")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches(L"Hello")); Matcher< ::std::wstring> m2 = StrNe(::std::wstring(L"Hello")); @@ -1920,7 +1920,7 @@ TEST(StdWideStrCaseEqTest, MatchesEqualStringIgnoringCase) { EXPECT_TRUE(m.Matches(L"Hello")); EXPECT_TRUE(m.Matches(L"hello")); EXPECT_FALSE(m.Matches(L"Hi")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrCaseEq(L"Hello"); EXPECT_TRUE(m2.Matches(L"hello")); @@ -1960,7 +1960,7 @@ TEST(StdWideStrCaseEqTest, CanDescribeSelf) { TEST(StdWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) { Matcher m = StrCaseNe(L"Hello"); EXPECT_TRUE(m.Matches(L"Hi")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches(L"Hello")); EXPECT_FALSE(m.Matches(L"hello")); @@ -1990,12 +1990,12 @@ TEST(StdWideHasSubstrTest, WorksForCStrings) { const Matcher m1 = HasSubstr(L"foo"); EXPECT_TRUE(m1.Matches(const_cast(L"I love food."))); EXPECT_FALSE(m1.Matches(const_cast(L"tofo"))); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = HasSubstr(L"foo"); EXPECT_TRUE(m2.Matches(L"I love food.")); EXPECT_FALSE(m2.Matches(L"tofo")); - EXPECT_FALSE(m2.Matches(NULL)); + EXPECT_FALSE(m2.Matches(nullptr)); } // Tests that HasSubstr(s) describes itself properly. @@ -2010,7 +2010,7 @@ TEST(StdWideStartsWithTest, MatchesStringWithGivenPrefix) { const Matcher m1 = StartsWith(::std::wstring(L"")); EXPECT_TRUE(m1.Matches(L"Hi")); EXPECT_TRUE(m1.Matches(L"")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = StartsWith(L"Hi"); EXPECT_TRUE(m2.Matches(L"Hi")); @@ -2031,7 +2031,7 @@ TEST(StdWideEndsWithTest, MatchesStringWithGivenSuffix) { const Matcher m1 = EndsWith(L""); EXPECT_TRUE(m1.Matches(L"Hi")); EXPECT_TRUE(m1.Matches(L"")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = EndsWith(::std::wstring(L"Hi")); EXPECT_TRUE(m2.Matches(L"Hi")); @@ -2053,7 +2053,7 @@ TEST(GlobalWideStrEqTest, MatchesEqual) { Matcher m = StrEq(::wstring(L"Hello")); EXPECT_TRUE(m.Matches(L"Hello")); EXPECT_FALSE(m.Matches(L"hello")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrEq(L"Hello"); EXPECT_TRUE(m2.Matches(L"Hello")); @@ -2093,7 +2093,7 @@ TEST(GlobalWideStrEqTest, CanDescribeSelf) { TEST(GlobalWideStrNeTest, MatchesUnequalString) { Matcher m = StrNe(L"Hello"); EXPECT_TRUE(m.Matches(L"")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches(L"Hello")); Matcher< ::wstring> m2 = StrNe(::wstring(L"Hello")); @@ -2111,7 +2111,7 @@ TEST(GlobalWideStrCaseEqTest, MatchesEqualStringIgnoringCase) { EXPECT_TRUE(m.Matches(L"Hello")); EXPECT_TRUE(m.Matches(L"hello")); EXPECT_FALSE(m.Matches(L"Hi")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrCaseEq(L"Hello"); EXPECT_TRUE(m2.Matches(L"hello")); @@ -2151,7 +2151,7 @@ TEST(GlobalWideStrCaseEqTest, CanDescribeSelf) { TEST(GlobalWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) { Matcher m = StrCaseNe(L"Hello"); EXPECT_TRUE(m.Matches(L"Hi")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches(L"Hello")); EXPECT_FALSE(m.Matches(L"hello")); @@ -2181,12 +2181,12 @@ TEST(GlobalWideHasSubstrTest, WorksForCStrings) { const Matcher m1 = HasSubstr(L"foo"); EXPECT_TRUE(m1.Matches(const_cast(L"I love food."))); EXPECT_FALSE(m1.Matches(const_cast(L"tofo"))); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = HasSubstr(L"foo"); EXPECT_TRUE(m2.Matches(L"I love food.")); EXPECT_FALSE(m2.Matches(L"tofo")); - EXPECT_FALSE(m2.Matches(NULL)); + EXPECT_FALSE(m2.Matches(nullptr)); } // Tests that HasSubstr(s) describes itself properly. @@ -2201,7 +2201,7 @@ TEST(GlobalWideStartsWithTest, MatchesStringWithGivenPrefix) { const Matcher m1 = StartsWith(::wstring(L"")); EXPECT_TRUE(m1.Matches(L"Hi")); EXPECT_TRUE(m1.Matches(L"")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = StartsWith(L"Hi"); EXPECT_TRUE(m2.Matches(L"Hi")); @@ -2222,7 +2222,7 @@ TEST(GlobalWideEndsWithTest, MatchesStringWithGivenSuffix) { const Matcher m1 = EndsWith(L""); EXPECT_TRUE(m1.Matches(L"Hi")); EXPECT_TRUE(m1.Matches(L"")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = EndsWith(::wstring(L"Hi")); EXPECT_TRUE(m2.Matches(L"Hi")); @@ -3701,7 +3701,7 @@ TEST(PointeeTest, RawPointer) { EXPECT_TRUE(m.Matches(&n)); n = -1; EXPECT_FALSE(m.Matches(&n)); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } TEST(PointeeTest, RawPointerToConst) { @@ -3711,7 +3711,7 @@ TEST(PointeeTest, RawPointerToConst) { EXPECT_TRUE(m.Matches(&x)); x = -1; EXPECT_FALSE(m.Matches(&x)); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } TEST(PointeeTest, ReferenceToConstRawPointer) { @@ -3721,7 +3721,7 @@ TEST(PointeeTest, ReferenceToConstRawPointer) { EXPECT_TRUE(m.Matches(&n)); n = -1; EXPECT_FALSE(m.Matches(&n)); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } TEST(PointeeTest, ReferenceToNonConstRawPointer) { @@ -3732,7 +3732,7 @@ TEST(PointeeTest, ReferenceToNonConstRawPointer) { EXPECT_TRUE(m.Matches(p)); x = -1; EXPECT_FALSE(m.Matches(p)); - p = NULL; + p = nullptr; EXPECT_FALSE(m.Matches(p)); } @@ -3771,7 +3771,7 @@ TEST(WhenDynamicCastToTest, WrongTypes) { TEST(WhenDynamicCastToTest, AlreadyNull) { // Already NULL. - Base* as_base_ptr = NULL; + Base* as_base_ptr = nullptr; EXPECT_THAT(as_base_ptr, WhenDynamicCastTo(IsNull())); } @@ -3807,7 +3807,7 @@ TEST(WhenDynamicCastToTest, Describe) { TEST(WhenDynamicCastToTest, Explain) { Matcher matcher = WhenDynamicCastTo(Pointee(_)); - Base* null = NULL; + Base* null = nullptr; EXPECT_THAT(Explain(matcher, null), HasSubstr("NULL")); Derived derived; EXPECT_TRUE(matcher.Matches(&derived)); @@ -3868,7 +3868,7 @@ TEST(PointeeTest, WorksWithConstPropagatingPointers) { TEST(PointeeTest, NeverMatchesNull) { const Matcher m = Pointee(_); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } // Tests that we can write Pointee(value) instead of Pointee(Eq(value)). @@ -3879,7 +3879,7 @@ TEST(PointeeTest, MatchesAgainstAValue) { EXPECT_TRUE(m.Matches(&n)); n = -1; EXPECT_FALSE(m.Matches(&n)); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } TEST(PointeeTest, CanDescribeSelf) { @@ -3892,7 +3892,7 @@ TEST(PointeeTest, CanDescribeSelf) { TEST(PointeeTest, CanExplainMatchResult) { const Matcher m = Pointee(StartsWith("Hi")); - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); const Matcher m2 = Pointee(GreaterThan(1)); // NOLINT long n = 3; // NOLINT @@ -3929,7 +3929,7 @@ MATCHER_P(UncopyableIs, inner_matcher, "") { // A user-defined struct for testing Field(). struct AStruct { - AStruct() : x(0), y(1.0), z(5), p(NULL) {} + AStruct() : x(0), y(1.0), z(5), p(nullptr) {} AStruct(const AStruct& rhs) : x(rhs.x), y(rhs.y), z(rhs.z.value()), p(rhs.p) {} @@ -3990,7 +3990,7 @@ TEST(FieldTest, WorksForUncopyableField) { // Tests that Field(&Foo::field, ...) works when field is a pointer. TEST(FieldTest, WorksForPointerField) { // Matching against NULL. - Matcher m = Field(&AStruct::p, static_cast(NULL)); + Matcher m = Field(&AStruct::p, static_cast(nullptr)); AStruct a; EXPECT_TRUE(m.Matches(a)); a.p = "hi"; @@ -4116,7 +4116,7 @@ TEST(FieldForPointerTest, WorksForReferenceToConstPointer) { // Tests that Field() does not match the NULL pointer. TEST(FieldForPointerTest, DoesNotMatchNull) { Matcher m = Field(&AStruct::x, _); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } // Tests that Field(&Foo::field, ...) works when the argument's type @@ -4154,7 +4154,7 @@ TEST(FieldForPointerTest, CanExplainMatchResult) { AStruct a; a.x = 1; - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); EXPECT_EQ("which points to an object whose given field is 1" + OfType("int"), Explain(m, &a)); @@ -4168,7 +4168,7 @@ TEST(FieldForPointerTest, CanExplainMatchResultWithFieldName) { AStruct a; a.x = 1; - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); EXPECT_EQ( "which points to an object whose field `field_name` is 1" + OfType("int"), Explain(m, &a)); @@ -4413,7 +4413,7 @@ TEST(PropertyForPointerTest, WorksForReferenceToConstPointer) { // Tests that Property() does not match the NULL pointer. TEST(PropertyForPointerTest, WorksForReferenceToNonConstProperty) { Matcher m = Property(&AClass::x, _); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } // Tests that Property(&Foo::property, ...) works when the argument's @@ -4454,7 +4454,7 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) { AClass a; a.set_n(1); - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); EXPECT_EQ( "which points to an object whose given property is 1" + OfType("int"), Explain(m, &a)); @@ -4470,7 +4470,7 @@ TEST(PropertyForPointerTest, CanExplainMatchResultWithPropertyName) { AClass a; a.set_n(1); - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); EXPECT_EQ("which points to an object whose property `fancy_name` is 1" + OfType("int"), Explain(m, &a)); @@ -4581,7 +4581,7 @@ TEST(ResultOfTest, WorksForCompatibleMatcherTypes) { // a NULL function pointer. TEST(ResultOfDeathTest, DiesOnNullFunctionPointers) { EXPECT_DEATH_IF_SUPPORTED( - ResultOf(static_cast(NULL), + ResultOf(static_cast(nullptr), Eq(std::string("foo"))), "NULL function pointer is passed into ResultOf\\(\\)\\."); } @@ -6181,7 +6181,7 @@ TEST_P(BipartiteRandomTest, LargerNets) { testing::internal::Int32 seed = GTEST_FLAG(random_seed); if (seed == 0) { - seed = static_cast(time(NULL)); + seed = static_cast(time(nullptr)); } for (; iters > 0; --iters, ++seed) { @@ -6684,7 +6684,7 @@ class SampleVariantIntString { template friend const T& get(const SampleVariantIntString& value) { - return value.get_impl(static_cast(NULL)); + return value.get_impl(static_cast(nullptr)); } private: @@ -6743,7 +6743,7 @@ class SampleAnyType { template friend const T* any_cast(const SampleAnyType* any) { - return any->get_impl(static_cast(NULL)); + return any->get_impl(static_cast(nullptr)); } private: @@ -6751,9 +6751,9 @@ class SampleAnyType { int i_; std::string s_; - const int* get_impl(int*) const { return index_ == 0 ? &i_ : NULL; } + const int* get_impl(int*) const { return index_ == 0 ? &i_ : nullptr; } const std::string* get_impl(std::string*) const { - return index_ == 1 ? &s_ : NULL; + return index_ == 1 ? &s_ : nullptr; } }; diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 08a2df0..976b245 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -333,7 +333,8 @@ TEST(InvokeTest, FunctionWithUnusedParameters) { Action a2 = Invoke(SumOfFirst2); - EXPECT_EQ(23, a2.Perform(make_tuple(20, 3, true, static_cast(NULL)))); + EXPECT_EQ(23, + a2.Perform(make_tuple(20, 3, true, static_cast(nullptr)))); } // Tests using Invoke() with methods with parameters declared as Unused. diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 7056c43..65c9fcc 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -2041,7 +2041,7 @@ TEST(FunctionCallMessageTest, GMOCK_FLAG(verbose) = kWarningVerbosity; NaggyMock c; CaptureStdout(); - c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable()); + c.VoidMethod(false, 5, "Hi", nullptr, Printable(), Unprintable()); const std::string output = GetCapturedStdout(); EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", output); EXPECT_PRED_FORMAT2(IsNotSubstring, "Stack trace:", output); @@ -2055,7 +2055,7 @@ TEST(FunctionCallMessageTest, GMOCK_FLAG(verbose) = kInfoVerbosity; NaggyMock c; CaptureStdout(); - c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable()); + c.VoidMethod(false, 5, "Hi", nullptr, Printable(), Unprintable()); const std::string output = GetCapturedStdout(); EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", output); EXPECT_PRED_FORMAT2(IsSubstring, "Stack trace:", output); @@ -2098,7 +2098,7 @@ TEST(FunctionCallMessageTest, // A void mock function. NaggyMock c; CaptureStdout(); - c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable()); + c.VoidMethod(false, 5, "Hi", nullptr, Printable(), Unprintable()); const std::string output2 = GetCapturedStdout(); EXPECT_THAT(output2.c_str(), ContainsRegex( diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index d26670e..e85f750 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -248,7 +248,7 @@ TEST(LinkTest, TestReturnVoid) { Mock mock; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return()); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the Return action. @@ -257,7 +257,7 @@ TEST(LinkTest, TestReturn) { char ch = 'x'; EXPECT_CALL(mock, StringFromString(_)).WillOnce(Return(&ch)); - mock.StringFromString(NULL); + mock.StringFromString(nullptr); } // Tests the linkage of the ReturnNull action. @@ -265,7 +265,7 @@ TEST(LinkTest, TestReturnNull) { Mock mock; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return()); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the ReturnRef action. @@ -274,7 +274,7 @@ TEST(LinkTest, TestReturnRef) { int n = 42; EXPECT_CALL(mock, IntRefFromString(_)).WillOnce(ReturnRef(n)); - mock.IntRefFromString(NULL); + mock.IntRefFromString(nullptr); } // Tests the linkage of the Assign action. @@ -283,7 +283,7 @@ TEST(LinkTest, TestAssign) { char ch = 'x'; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Assign(&ch, 'y')); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the SetArgPointee action. @@ -314,7 +314,7 @@ TEST(LinkTest, TestSetErrnoAndReturn) { int saved_errno = errno; EXPECT_CALL(mock, IntFromString(_)).WillOnce(SetErrnoAndReturn(1, -1)); - mock.IntFromString(NULL); + mock.IntFromString(nullptr); errno = saved_errno; } @@ -328,8 +328,8 @@ TEST(LinkTest, TestInvoke) { EXPECT_CALL(mock, VoidFromString(_)) .WillOnce(Invoke(&InvokeHelper::StaticVoidFromString)) .WillOnce(Invoke(&test_invoke_helper, &InvokeHelper::VoidFromString)); - mock.VoidFromString(NULL); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); + mock.VoidFromString(nullptr); } // Tests the linkage of the InvokeWithoutArgs action. @@ -341,8 +341,8 @@ TEST(LinkTest, TestInvokeWithoutArgs) { .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid)) .WillOnce(InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid)); - mock.VoidFromString(NULL); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); + mock.VoidFromString(nullptr); } // Tests the linkage of the InvokeArgument action. @@ -360,7 +360,7 @@ TEST(LinkTest, TestWithArg) { EXPECT_CALL(mock, VoidFromString(_)) .WillOnce(WithArg<0>(Invoke(&InvokeHelper::StaticVoidFromString))); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the WithArgs action. @@ -369,7 +369,7 @@ TEST(LinkTest, TestWithArgs) { EXPECT_CALL(mock, VoidFromString(_)) .WillOnce(WithArgs<0>(Invoke(&InvokeHelper::StaticVoidFromString))); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the WithoutArgs action. @@ -377,7 +377,7 @@ TEST(LinkTest, TestWithoutArgs) { Mock mock; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(WithoutArgs(Return())); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the DoAll action. @@ -405,7 +405,7 @@ TEST(LinkTest, TestIgnoreResult) { Mock mock; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(IgnoreResult(Return(42))); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } #if GTEST_HAS_EXCEPTIONS @@ -437,7 +437,7 @@ TEST(LinkTest, TestActionMacro) { Mock mock; EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1()); - mock.IntFromString(NULL); + mock.IntFromString(nullptr); } // Tests the linkage of actions created using ACTION_P macro. @@ -449,7 +449,7 @@ TEST(LinkTest, TestActionPMacro) { Mock mock; EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42)); - mock.IntFromString(NULL); + mock.IntFromString(nullptr); } // Tests the linkage of actions created using ACTION_P2 macro. @@ -646,7 +646,7 @@ TEST(LinkTest, TestMatcherProperty) { // Tests the linkage of the ResultOf matcher. TEST(LinkTest, TestMatcherResultOf) { Matcher m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1)); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); } // Tests the linkage of the ResultOf matcher. @@ -660,7 +660,7 @@ TEST(LinkTest, TestMatcherPointee) { // Tests the linkage of the Truly matcher. TEST(LinkTest, TestMatcherTruly) { Matcher m = Truly(&InvokeHelper::StaticBoolFromString); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); } // Tests the linkage of the AllOf matcher. @@ -684,7 +684,7 @@ TEST(LinkTest, TestMatcherNot) { // Tests the linkage of the MatcherCast() function. TEST(LinkTest, TestMatcherCast) { Matcher m = MatcherCast(_); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); } #endif // GMOCK_TEST_GMOCK_LINK_TEST_H_ diff --git a/googlemock/test/gmock_stress_test.cc b/googlemock/test/gmock_stress_test.cc index 0d99bed..9ae0b1e 100644 --- a/googlemock/test/gmock_stress_test.cc +++ b/googlemock/test/gmock_stress_test.cc @@ -210,7 +210,7 @@ void TestConcurrentCallsOnSameObject(Dummy /* dummy */) { int count1 = 0; const Helper1Param param = { &foo, &count1 }; ThreadWithParam* const t = - new ThreadWithParam(Helper1, param, NULL); + new ThreadWithParam(Helper1, param, nullptr); int count2 = 0; const Helper1Param param2 = { &foo, &count2 }; @@ -264,7 +264,7 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) { foo.Bar(1); ThreadWithParam* const t = - new ThreadWithParam(Helper2, &foo, NULL); + new ThreadWithParam(Helper2, &foo, nullptr); Helper2(&foo); JoinAndDelete(t); @@ -288,8 +288,8 @@ TEST(StressTest, CanUseGMockWithThreads) { ThreadWithParam* threads[kTestThreads] = {}; for (int i = 0; i < kTestThreads; i++) { // Creates a thread to run the test function. - threads[i] = - new ThreadWithParam(test_routines[i % kRoutines], Dummy(), NULL); + threads[i] = new ThreadWithParam(test_routines[i % kRoutines], + Dummy(), nullptr); GTEST_LOG_(INFO) << "Thread #" << i << " running . . ."; } diff --git a/googlemock/test/gmock_test.cc b/googlemock/test/gmock_test.cc index 341a17d..e9840a3 100644 --- a/googlemock/test/gmock_test.cc +++ b/googlemock/test/gmock_test.cc @@ -64,59 +64,35 @@ void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N], } TEST(InitGoogleMockTest, ParsesInvalidCommandLine) { - const char* argv[] = { - NULL - }; + const char* argv[] = {nullptr}; - const char* new_argv[] = { - NULL - }; + const char* new_argv[] = {nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(InitGoogleMockTest, ParsesEmptyCommandLine) { - const char* argv[] = { - "foo.exe", - NULL - }; + const char* argv[] = {"foo.exe", nullptr}; - const char* new_argv[] = { - "foo.exe", - NULL - }; + const char* new_argv[] = {"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(InitGoogleMockTest, ParsesSingleFlag) { - const char* argv[] = { - "foo.exe", - "--gmock_verbose=info", - NULL - }; + const char* argv[] = {"foo.exe", "--gmock_verbose=info", nullptr}; - const char* new_argv[] = { - "foo.exe", - NULL - }; + const char* new_argv[] = {"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, "info"); } TEST(InitGoogleMockTest, ParsesMultipleFlags) { int old_default_behavior = GMOCK_FLAG(default_mock_behavior); - const wchar_t* argv[] = { - L"foo.exe", - L"--gmock_verbose=info", - L"--gmock_default_mock_behavior=2", - NULL - }; - - const wchar_t* new_argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", + L"--gmock_default_mock_behavior=2", nullptr}; + + const wchar_t* new_argv[] = {L"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, "info"); EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior)); @@ -125,92 +101,52 @@ TEST(InitGoogleMockTest, ParsesMultipleFlags) { } TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) { - const char* argv[] = { - "foo.exe", - "--non_gmock_flag=blah", - NULL - }; - - const char* new_argv[] = { - "foo.exe", - "--non_gmock_flag=blah", - NULL - }; + const char* argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr}; + + const char* new_argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) { - const char* argv[] = { - "foo.exe", - "--non_gmock_flag=blah", - "--gmock_verbose=error", - NULL - }; - - const char* new_argv[] = { - "foo.exe", - "--non_gmock_flag=blah", - NULL - }; + const char* argv[] = {"foo.exe", "--non_gmock_flag=blah", + "--gmock_verbose=error", nullptr}; + + const char* new_argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr}; TestInitGoogleMock(argv, new_argv, "error"); } TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) { - const wchar_t* argv[] = { - NULL - }; + const wchar_t* argv[] = {nullptr}; - const wchar_t* new_argv[] = { - NULL - }; + const wchar_t* new_argv[] = {nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(WideInitGoogleMockTest, ParsesEmptyCommandLine) { - const wchar_t* argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", nullptr}; - const wchar_t* new_argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* new_argv[] = {L"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(WideInitGoogleMockTest, ParsesSingleFlag) { - const wchar_t* argv[] = { - L"foo.exe", - L"--gmock_verbose=info", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", nullptr}; - const wchar_t* new_argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* new_argv[] = {L"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, "info"); } TEST(WideInitGoogleMockTest, ParsesMultipleFlags) { int old_default_behavior = GMOCK_FLAG(default_mock_behavior); - const wchar_t* argv[] = { - L"foo.exe", - L"--gmock_verbose=info", - L"--gmock_default_mock_behavior=2", - NULL - }; - - const wchar_t* new_argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", + L"--gmock_default_mock_behavior=2", nullptr}; + + const wchar_t* new_argv[] = {L"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, "info"); EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior)); @@ -219,34 +155,18 @@ TEST(WideInitGoogleMockTest, ParsesMultipleFlags) { } TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) { - const wchar_t* argv[] = { - L"foo.exe", - L"--non_gmock_flag=blah", - NULL - }; - - const wchar_t* new_argv[] = { - L"foo.exe", - L"--non_gmock_flag=blah", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr}; + + const wchar_t* new_argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) { - const wchar_t* argv[] = { - L"foo.exe", - L"--non_gmock_flag=blah", - L"--gmock_verbose=error", - NULL - }; - - const wchar_t* new_argv[] = { - L"foo.exe", - L"--non_gmock_flag=blah", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--non_gmock_flag=blah", + L"--gmock_verbose=error", nullptr}; + + const wchar_t* new_argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr}; TestInitGoogleMock(argv, new_argv, "error"); } diff --git a/googletest/include/gtest/gtest-message.h b/googletest/include/gtest/gtest-message.h index 5ca0416..e528d0e 100644 --- a/googletest/include/gtest/gtest-message.h +++ b/googletest/include/gtest/gtest-message.h @@ -151,7 +151,7 @@ class GTEST_API_ Message { // as "(null)". template inline Message& operator <<(T* const& pointer) { // NOLINT - if (pointer == NULL) { + if (pointer == nullptr) { *ss_ << "(null)"; } else { *ss_ << pointer; diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 39c5c46..6703b30 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -449,7 +449,7 @@ void DefaultPrintTo(WrapPrinterType /* dummy */, template void DefaultPrintTo(WrapPrinterType /* dummy */, T* p, ::std::ostream* os) { - if (p == NULL) { + if (p == nullptr) { *os << "NULL"; } else { // T is not a function type. We just call << to print p, @@ -461,7 +461,7 @@ void DefaultPrintTo(WrapPrinterType /* dummy */, template void DefaultPrintTo(WrapPrinterType /* dummy */, T* p, ::std::ostream* os) { - if (p == NULL) { + if (p == nullptr) { *os << "NULL"; } else { // T is a function type, so '*os << p' doesn't do what we want @@ -914,7 +914,7 @@ template <> class UniversalTersePrinter { public: static void Print(const char* str, ::std::ostream* os) { - if (str == NULL) { + if (str == nullptr) { *os << "NULL"; } else { UniversalPrint(std::string(str), os); @@ -934,7 +934,7 @@ template <> class UniversalTersePrinter { public: static void Print(const wchar_t* str, ::std::ostream* os) { - if (str == NULL) { + if (str == nullptr) { *os << "NULL"; } else { UniversalPrint(::std::wstring(str), os); diff --git a/googletest/include/gtest/gtest-test-part.h b/googletest/include/gtest/gtest-test-part.h index 7b30aff..fffa641 100644 --- a/googletest/include/gtest/gtest-test-part.h +++ b/googletest/include/gtest/gtest-test-part.h @@ -60,16 +60,13 @@ class GTEST_API_ TestPartResult { // C'tor. TestPartResult does NOT have a default constructor. // Always use this constructor (with parameters) to create a // TestPartResult object. - TestPartResult(Type a_type, - const char* a_file_name, - int a_line_number, + TestPartResult(Type a_type, const char* a_file_name, int a_line_number, const char* a_message) : type_(a_type), - file_name_(a_file_name == NULL ? "" : a_file_name), + file_name_(a_file_name == nullptr ? "" : a_file_name), line_number_(a_line_number), summary_(ExtractSummary(a_message)), - message_(a_message) { - } + message_(a_message) {} // Gets the outcome of the test part. Type type() const { return type_; } @@ -77,7 +74,7 @@ class GTEST_API_ TestPartResult { // Gets the name of the source file where the test part took place, or // NULL if it's unknown. const char* file_name() const { - return file_name_.empty() ? NULL : file_name_.c_str(); + return file_name_.empty() ? nullptr : file_name_.c_str(); } // Gets the line in the source file where the test part took place, diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index ba99737..4e87eeb 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -300,7 +300,8 @@ class GTEST_API_ AssertionResult { const T& success, typename internal::EnableIf< !internal::ImplicitlyConvertible::value>::type* - /*enabler*/ = NULL) + /*enabler*/ + = nullptr) : success_(success) {} #if defined(_MSC_VER) && _MSC_VER < 1910 @@ -324,7 +325,7 @@ class GTEST_API_ AssertionResult { // assertion's expectation). When nothing has been streamed into the // object, returns an empty string. const char* message() const { - return message_.get() != NULL ? message_->c_str() : ""; + return message_.get() != nullptr ? message_->c_str() : ""; } // FIXME: Remove this after making sure no clients use it. // Deprecated; please use message() instead. @@ -347,8 +348,7 @@ class GTEST_API_ AssertionResult { private: // Appends the contents of message to message_. void AppendMessage(const Message& a_message) { - if (message_.get() == NULL) - message_.reset(new ::std::string); + if (message_.get() == nullptr) message_.reset(new ::std::string); message_->append(a_message.GetString().c_str()); } @@ -512,7 +512,7 @@ class GTEST_API_ Test { // If you see an error about overriding the following function or // about it being private, you have mis-spelled SetUp() as Setup(). struct Setup_should_be_spelled_SetUp {}; - virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; } + virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; } // We disallow copying Tests. GTEST_DISALLOW_COPY_AND_ASSIGN_(Test); @@ -700,17 +700,15 @@ class GTEST_API_ TestInfo { // Returns the name of the parameter type, or NULL if this is not a typed // or a type-parameterized test. const char* type_param() const { - if (type_param_.get() != NULL) - return type_param_->c_str(); - return NULL; + if (type_param_.get() != nullptr) return type_param_->c_str(); + return nullptr; } // Returns the text representation of the value parameter, or NULL if this // is not a value-parameterized test. const char* value_param() const { - if (value_param_.get() != NULL) - return value_param_->c_str(); - return NULL; + if (value_param_.get() != nullptr) return value_param_->c_str(); + return nullptr; } // Returns the file name where this test is defined. @@ -849,9 +847,8 @@ class GTEST_API_ TestCase { // Returns the name of the parameter type, or NULL if this is not a // type-parameterized test case. const char* type_param() const { - if (type_param_.get() != NULL) - return type_param_->c_str(); - return NULL; + if (type_param_.get() != nullptr) return type_param_->c_str(); + return nullptr; } // Returns true if any test in this test case should run. @@ -1038,7 +1035,7 @@ class Environment { // If you see an error about overriding the following function or // about it being private, you have mis-spelled SetUp() as Setup(). struct Setup_should_be_spelled_SetUp {}; - virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; } + virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; } }; #if GTEST_HAS_EXCEPTIONS @@ -1514,16 +1511,14 @@ class EqHelper { // EXPECT_EQ(false, a_bool). template static AssertionResult Compare( - const char* lhs_expression, - const char* rhs_expression, - const T1& lhs, + const char* lhs_expression, const char* rhs_expression, const T1& lhs, const T2& rhs, // The following line prevents this overload from being considered if T2 // is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr) // expands to Compare("", "", NULL, my_ptr), which requires a conversion // to match the Secret* in the other overload, which would otherwise make // this template match better. - typename EnableIf::value>::type* = 0) { + typename EnableIf::value>::type* = nullptr) { return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); } @@ -1542,8 +1537,8 @@ class EqHelper { Secret* /* lhs (NULL) */, T* rhs) { // We already know that 'lhs' is a null pointer. - return CmpHelperEQ(lhs_expression, rhs_expression, - static_cast(NULL), rhs); + return CmpHelperEQ(lhs_expression, rhs_expression, static_cast(nullptr), + rhs); } }; @@ -1817,7 +1812,7 @@ class WithParamInterface { // The current parameter value. Is also available in the test fixture's // constructor. static const ParamType& GetParam() { - GTEST_CHECK_(parameter_ != NULL) + GTEST_CHECK_(parameter_ != nullptr) << "GetParam() can only be called inside a value-parameterized test " << "-- did you intend to write TEST_P instead of TEST_F?"; return *parameter_; @@ -1838,7 +1833,7 @@ class WithParamInterface { }; template -const T* WithParamInterface::parameter_ = NULL; +const T* WithParamInterface::parameter_ = nullptr; // Most value-parameterized classes can ignore the existence of // WithParamInterface, and can just inherit from ::testing::TestWithParam. diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 380a11c..ee0527a 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -587,8 +587,8 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 // returns NULL if no comma is found in 'str'. inline const char* SkipComma(const char* str) { const char* comma = strchr(str, ','); - if (comma == NULL) { - return NULL; + if (comma == nullptr) { + return nullptr; } while (IsSpace(*(++comma))) {} return comma; @@ -598,7 +598,7 @@ inline const char* SkipComma(const char* str) { // the entire string if it contains no comma. inline std::string GetPrefixUntilComma(const char* str) { const char* comma = strchr(str, ','); - return comma == NULL ? str : std::string(str, comma); + return comma == nullptr ? str : std::string(str, comma); } // Splits a given string on a given delimiter, populating a given @@ -667,7 +667,7 @@ class TypeParameterizedTest { .c_str(), StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(), GetTypeName().c_str(), - NULL, // No value parameter. + nullptr, // No value parameter. code_location, GetTypeId(), TestClass::SetUpTestCase, TestClass::TearDownTestCase, new TestFactoryImpl); @@ -980,7 +980,7 @@ struct IsHashTable { static char test(...); public: - static const bool value = sizeof(test(0, 0)) == sizeof(int); + static const bool value = sizeof(test(nullptr, nullptr)) == sizeof(int); }; template diff --git a/googletest/include/gtest/internal/gtest-linked_ptr.h b/googletest/include/gtest/internal/gtest-linked_ptr.h index 082b872..d25f7e9 100644 --- a/googletest/include/gtest/internal/gtest-linked_ptr.h +++ b/googletest/include/gtest/internal/gtest-linked_ptr.h @@ -149,7 +149,7 @@ class linked_ptr { // Take over ownership of a raw pointer. This should happen as soon as // possible after the object is created. - explicit linked_ptr(T* ptr = NULL) { capture(ptr); } + explicit linked_ptr(T* ptr = nullptr) { capture(ptr); } ~linked_ptr() { depart(); } // Copy an existing linked_ptr<>, adding ourselves to the list of references. @@ -175,7 +175,7 @@ class linked_ptr { } // Smart pointer members. - void reset(T* ptr = NULL) { + void reset(T* ptr = nullptr) { depart(); capture(ptr); } diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index d64f620..3e810f2 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -327,8 +327,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface { // detect that fact. The client code, on the other hand, is // responsible for not calling Current() on an out-of-range iterator. virtual const T* Current() const { - if (value_.get() == NULL) - value_.reset(new T(*iterator_)); + if (value_.get() == nullptr) value_.reset(new T(*iterator_)); return value_.get(); } virtual bool Equals(const ParamIteratorInterface& other) const { @@ -579,13 +578,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase { test_name_stream << test_info->test_base_name << "/" << param_name; MakeAndRegisterTestInfo( - test_case_name.c_str(), - test_name_stream.GetString().c_str(), - NULL, // No type parameter. - PrintToString(*param_it).c_str(), - code_location_, - GetTestCaseTypeId(), - TestCase::SetUpTestCase, + test_case_name.c_str(), test_name_stream.GetString().c_str(), + nullptr, // No type parameter. + PrintToString(*param_it).c_str(), code_location_, + GetTestCaseTypeId(), TestCase::SetUpTestCase, TestCase::TearDownTestCase, test_info->test_meta_factory->CreateTestFactory(*param_it)); } // for param_it @@ -676,7 +672,7 @@ class ParameterizedTestCaseRegistry { ParameterizedTestCaseInfo* GetTestCasePatternHolder( const char* test_case_name, CodeLocation code_location) { - ParameterizedTestCaseInfo* typed_test_info = NULL; + ParameterizedTestCaseInfo* typed_test_info = nullptr; for (TestCaseInfoContainer::iterator it = test_case_infos_.begin(); it != test_case_infos_.end(); ++it) { if ((*it)->GetTestCaseName() == test_case_name) { @@ -696,7 +692,7 @@ class ParameterizedTestCaseRegistry { break; } } - if (typed_test_info == NULL) { + if (typed_test_info == nullptr) { typed_test_info = new ParameterizedTestCaseInfo( test_case_name, code_location); test_case_infos_.push_back(typed_test_info); diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 786497d..899fa5b 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -1197,7 +1197,7 @@ class scoped_ptr { public: typedef T element_type; - explicit scoped_ptr(T* p = NULL) : ptr_(p) {} + explicit scoped_ptr(T* p = nullptr) : ptr_(p) {} ~scoped_ptr() { reset(); } T& operator*() const { return *ptr_; } @@ -1206,11 +1206,11 @@ class scoped_ptr { T* release() { T* const ptr = ptr_; - ptr_ = NULL; + ptr_ = nullptr; return ptr; } - void reset(T* p = NULL) { + void reset(T* p = nullptr) { if (p != ptr_) { if (IsTrue(sizeof(T) > 0)) { // Makes sure T is a complete type. delete ptr_; @@ -1360,7 +1360,7 @@ class GTEST_API_ GTestLog { __FILE__, __LINE__).GetStream() inline void LogToStderr() {} -inline void FlushInfoLog() { fflush(NULL); } +inline void FlushInfoLog() { fflush(nullptr); } #endif // !defined(GTEST_LOG_) @@ -1511,7 +1511,7 @@ inline To DownCast_(From* f) { // so we only accept pointers #if GTEST_HAS_RTTI // RTTI: debug mode only! - GTEST_CHECK_(f == NULL || dynamic_cast(f) != NULL); + GTEST_CHECK_(f == nullptr || dynamic_cast(f) != NULL); #endif return static_cast(f); } @@ -1583,7 +1583,7 @@ inline void SleepMilliseconds(int n) { 0, // 0 seconds. n * 1000L * 1000L, // And n ms. }; - nanosleep(&time, NULL); + nanosleep(&time, nullptr); } # endif // GTEST_HAS_PTHREAD @@ -1601,7 +1601,7 @@ inline void SleepMilliseconds(int n) { class Notification { public: Notification() : notified_(false) { - GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL)); + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr)); } ~Notification() { pthread_mutex_destroy(&mutex_); @@ -1710,7 +1710,7 @@ class ThreadWithParamBase { // pass into pthread_create(). extern "C" inline void* ThreadFuncWithCLinkage(void* thread) { static_cast(thread)->Run(); - return NULL; + return nullptr; } // Helper class for testing Google Test's multi-threading constructs. @@ -1739,20 +1739,19 @@ class ThreadWithParam : public ThreadWithParamBase { // The thread can be created only after all fields except thread_ // have been initialized. GTEST_CHECK_POSIX_SUCCESS_( - pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base)); + pthread_create(&thread_, nullptr, &ThreadFuncWithCLinkage, base)); } ~ThreadWithParam() { Join(); } void Join() { if (!finished_) { - GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0)); + GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, nullptr)); finished_ = true; } } virtual void Run() { - if (thread_can_start_ != NULL) - thread_can_start_->WaitForNotification(); + if (thread_can_start_ != nullptr) thread_can_start_->WaitForNotification(); func_(param_); } @@ -2115,7 +2114,7 @@ class MutexBase { class Mutex : public MutexBase { public: Mutex() { - GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL)); + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr)); has_owner_ = false; } ~Mutex() { @@ -2213,7 +2212,7 @@ class GTEST_API_ ThreadLocal { T* GetOrCreateValue() const { ThreadLocalValueHolderBase* const holder = static_cast(pthread_getspecific(key_)); - if (holder != NULL) { + if (holder != nullptr) { return CheckedDowncastToActualType(holder)->pointer(); } diff --git a/googletest/include/gtest/internal/gtest-type-util.h b/googletest/include/gtest/internal/gtest-type-util.h index 28e4112..fd4f9ed 100644 --- a/googletest/include/gtest/internal/gtest-type-util.h +++ b/googletest/include/gtest/internal/gtest-type-util.h @@ -89,7 +89,7 @@ std::string GetTypeName() { # if GTEST_HAS_CXXABI_H_ using abi::__cxa_demangle; # endif // GTEST_HAS_CXXABI_H_ - char* const readable_name = __cxa_demangle(name, 0, 0, &status); + char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status); const std::string name_str(status == 0 ? readable_name : name); free(readable_name); return CanonicalizeForStdLibVersioning(name_str); diff --git a/googletest/samples/sample10_unittest.cc b/googletest/samples/sample10_unittest.cc index 7ce9550..3da2158 100644 --- a/googletest/samples/sample10_unittest.cc +++ b/googletest/samples/sample10_unittest.cc @@ -100,7 +100,7 @@ TEST(ListenersTest, DoesNotLeak) { // specified. TEST(ListenersTest, LeaksWater) { Water* water = new Water; - EXPECT_TRUE(water != NULL); + EXPECT_TRUE(water != nullptr); } } // namespace diff --git a/googletest/samples/sample2.cc b/googletest/samples/sample2.cc index f3b722f..d8e8723 100644 --- a/googletest/samples/sample2.cc +++ b/googletest/samples/sample2.cc @@ -35,7 +35,7 @@ // Clones a 0-terminated C string, allocating memory using new. const char* MyString::CloneCString(const char* a_c_string) { - if (a_c_string == NULL) return NULL; + if (a_c_string == nullptr) return nullptr; const size_t len = strlen(a_c_string); char* const clone = new char[ len + 1 ]; diff --git a/googletest/samples/sample2.h b/googletest/samples/sample2.h index 58f360f..e9a5a70 100644 --- a/googletest/samples/sample2.h +++ b/googletest/samples/sample2.h @@ -50,15 +50,15 @@ class MyString { // C'tors // The default c'tor constructs a NULL string. - MyString() : c_string_(NULL) {} + MyString() : c_string_(nullptr) {} // Constructs a MyString by cloning a 0-terminated C string. - explicit MyString(const char* a_c_string) : c_string_(NULL) { + explicit MyString(const char* a_c_string) : c_string_(nullptr) { Set(a_c_string); } // Copy c'tor - MyString(const MyString& string) : c_string_(NULL) { + MyString(const MyString& string) : c_string_(nullptr) { Set(string.c_string_); } @@ -71,9 +71,7 @@ class MyString { // Gets the 0-terminated C string this MyString object represents. const char* c_string() const { return c_string_; } - size_t Length() const { - return c_string_ == NULL ? 0 : strlen(c_string_); - } + size_t Length() const { return c_string_ == nullptr ? 0 : strlen(c_string_); } // Sets the 0-terminated C string this MyString object represents. void Set(const char* c_string); diff --git a/googletest/samples/sample2_unittest.cc b/googletest/samples/sample2_unittest.cc index 0848826..41e31c1 100644 --- a/googletest/samples/sample2_unittest.cc +++ b/googletest/samples/sample2_unittest.cc @@ -66,7 +66,7 @@ TEST(MyString, DefaultConstructor) { // we have to live with this fact. // // - EXPECT_STREQ(NULL, s.c_string()); + EXPECT_STREQ(nullptr, s.c_string()); EXPECT_EQ(0u, s.Length()); } @@ -101,7 +101,7 @@ TEST(MyString, Set) { EXPECT_EQ(0, strcmp(s.c_string(), kHelloString)); // Can we set the MyString to NULL? - s.Set(NULL); - EXPECT_STREQ(NULL, s.c_string()); + s.Set(nullptr); + EXPECT_STREQ(nullptr, s.c_string()); } } // namespace diff --git a/googletest/samples/sample3-inl.h b/googletest/samples/sample3-inl.h index 1a29ce9..80ba6b9 100644 --- a/googletest/samples/sample3-inl.h +++ b/googletest/samples/sample3-inl.h @@ -58,7 +58,8 @@ class QueueNode { private: // Creates a node with a given element value. The next pointer is // set to NULL. - explicit QueueNode(const E& an_element) : element_(an_element), next_(NULL) {} + explicit QueueNode(const E& an_element) + : element_(an_element), next_(nullptr) {} // We disable the default assignment operator and copy c'tor. const QueueNode& operator = (const QueueNode&); @@ -72,7 +73,7 @@ template // E is the element type. class Queue { public: // Creates an empty queue. - Queue() : head_(NULL), last_(NULL), size_(0) {} + Queue() : head_(nullptr), last_(nullptr), size_(0) {} // D'tor. Clears the queue. ~Queue() { Clear(); } @@ -86,12 +87,12 @@ class Queue { for (; ;) { delete node; node = next; - if (node == NULL) break; + if (node == nullptr) break; next = node->next(); } // 2. Resets the member variables. - head_ = last_ = NULL; + head_ = last_ = nullptr; size_ = 0; } } @@ -128,14 +129,14 @@ class Queue { // the queue is empty. E* Dequeue() { if (size_ == 0) { - return NULL; + return nullptr; } const QueueNode* const old_head = head_; head_ = head_->next_; size_--; if (size_ == 0) { - last_ = NULL; + last_ = nullptr; } E* element = new E(old_head->element()); @@ -150,7 +151,8 @@ class Queue { template Queue* Map(F function) const { Queue* new_queue = new Queue(); - for (const QueueNode* node = head_; node != NULL; node = node->next_) { + for (const QueueNode* node = head_; node != nullptr; + node = node->next_) { new_queue->Enqueue(function(node->element())); } diff --git a/googletest/samples/sample3_unittest.cc b/googletest/samples/sample3_unittest.cc index e093c25..97ce55d 100644 --- a/googletest/samples/sample3_unittest.cc +++ b/googletest/samples/sample3_unittest.cc @@ -99,8 +99,8 @@ class QueueTestSmpl3 : public testing::Test { ASSERT_EQ(q->Size(), new_q->Size()); // Verifies the relationship between the elements of the two queues. - for ( const QueueNode * n1 = q->Head(), * n2 = new_q->Head(); - n1 != NULL; n1 = n1->next(), n2 = n2->next() ) { + for (const QueueNode*n1 = q->Head(), *n2 = new_q->Head(); + n1 != nullptr; n1 = n1->next(), n2 = n2->next()) { EXPECT_EQ(2 * n1->element(), n2->element()); } @@ -125,16 +125,16 @@ TEST_F(QueueTestSmpl3, DefaultConstructor) { // Tests Dequeue(). TEST_F(QueueTestSmpl3, Dequeue) { int * n = q0_.Dequeue(); - EXPECT_TRUE(n == NULL); + EXPECT_TRUE(n == nullptr); n = q1_.Dequeue(); - ASSERT_TRUE(n != NULL); + ASSERT_TRUE(n != nullptr); EXPECT_EQ(1, *n); EXPECT_EQ(0u, q1_.Size()); delete n; n = q2_.Dequeue(); - ASSERT_TRUE(n != NULL); + ASSERT_TRUE(n != nullptr); EXPECT_EQ(2, *n); EXPECT_EQ(1u, q2_.Size()); delete n; diff --git a/googletest/samples/sample5_unittest.cc b/googletest/samples/sample5_unittest.cc index d8a8788..e71b903 100644 --- a/googletest/samples/sample5_unittest.cc +++ b/googletest/samples/sample5_unittest.cc @@ -63,15 +63,13 @@ class QuickTest : public testing::Test { protected: // Remember that SetUp() is run immediately before a test starts. // This is a good place to record the start time. - virtual void SetUp() { - start_time_ = time(NULL); - } + virtual void SetUp() { start_time_ = time(nullptr); } // TearDown() is invoked immediately after a test finishes. Here we // check if the test was too slow. virtual void TearDown() { // Gets the time when the test finishes - const time_t end_time = time(NULL); + const time_t end_time = time(nullptr); // Asserts that the test took no more than ~5 seconds. Did you // know that you can use assertions in SetUp() and TearDown() as @@ -176,16 +174,16 @@ TEST_F(QueueTest, DefaultConstructor) { // Tests Dequeue(). TEST_F(QueueTest, Dequeue) { int* n = q0_.Dequeue(); - EXPECT_TRUE(n == NULL); + EXPECT_TRUE(n == nullptr); n = q1_.Dequeue(); - EXPECT_TRUE(n != NULL); + EXPECT_TRUE(n != nullptr); EXPECT_EQ(1, *n); EXPECT_EQ(0u, q1_.Size()); delete n; n = q2_.Dequeue(); - EXPECT_TRUE(n != NULL); + EXPECT_TRUE(n != nullptr); EXPECT_EQ(2, *n); EXPECT_EQ(1u, q2_.Size()); delete n; diff --git a/googletest/samples/sample7_unittest.cc b/googletest/samples/sample7_unittest.cc index c1ae8bd..e1e09b0 100644 --- a/googletest/samples/sample7_unittest.cc +++ b/googletest/samples/sample7_unittest.cc @@ -69,7 +69,7 @@ class PrimeTableTestSmpl7 : public TestWithParam { virtual void SetUp() { table_ = (*GetParam())(); } virtual void TearDown() { delete table_; - table_ = NULL; + table_ = nullptr; } protected: diff --git a/googletest/samples/sample8_unittest.cc b/googletest/samples/sample8_unittest.cc index ce75cf0..ccf5aed 100644 --- a/googletest/samples/sample8_unittest.cc +++ b/googletest/samples/sample8_unittest.cc @@ -50,8 +50,9 @@ class HybridPrimeTable : public PrimeTable { public: HybridPrimeTable(bool force_on_the_fly, int max_precalculated) : on_the_fly_impl_(new OnTheFlyPrimeTable), - precalc_impl_(force_on_the_fly ? NULL : - new PreCalculatedPrimeTable(max_precalculated)), + precalc_impl_(force_on_the_fly + ? nullptr + : new PreCalculatedPrimeTable(max_precalculated)), max_precalculated_(max_precalculated) {} virtual ~HybridPrimeTable() { delete on_the_fly_impl_; @@ -59,7 +60,7 @@ class HybridPrimeTable : public PrimeTable { } virtual bool IsPrime(int n) const { - if (precalc_impl_ != NULL && n < max_precalculated_) + if (precalc_impl_ != nullptr && n < max_precalculated_) return precalc_impl_->IsPrime(n); else return on_the_fly_impl_->IsPrime(n); @@ -67,7 +68,7 @@ class HybridPrimeTable : public PrimeTable { virtual int GetNextPrime(int p) const { int next_prime = -1; - if (precalc_impl_ != NULL && p < max_precalculated_) + if (precalc_impl_ != nullptr && p < max_precalculated_) next_prime = precalc_impl_->GetNextPrime(p); return next_prime != -1 ? next_prime : on_the_fly_impl_->GetNextPrime(p); @@ -106,7 +107,7 @@ class PrimeTableTest : public TestWithParam< ::testing::tuple > { } virtual void TearDown() { delete table_; - table_ = NULL; + table_ = nullptr; } HybridPrimeTable* table_; }; diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 0908355..b3a572a 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -281,7 +281,7 @@ static void DeathTestAbort(const std::string& message) { // the heap for any additional non-minuscule memory requirements. const InternalRunDeathTestFlag* const flag = GetUnitTestImpl()->internal_run_death_test_flag(); - if (flag != NULL) { + if (flag != nullptr) { FILE* parent = posix::FDOpen(flag->write_fd(), "w"); fputc(kDeathTestInternalError, parent); fprintf(parent, "%s", message.c_str()); @@ -361,7 +361,7 @@ static void FailFromInternalError(int fd) { // for the current test. DeathTest::DeathTest() { TestInfo* const info = GetUnitTestImpl()->current_test_info(); - if (info == NULL) { + if (info == nullptr) { DeathTestAbort("Cannot run a death test outside of a TEST or " "TEST_F construct"); } @@ -1115,9 +1115,7 @@ class ExecDeathTest : public ForkingDeathTest { // Utility class for accumulating command-line arguments. class Arguments { public: - Arguments() { - args_.push_back(NULL); - } + Arguments() { args_.push_back(nullptr); } ~Arguments() { for (std::vector::iterator i = args_.begin(); i != args_.end(); @@ -1288,7 +1286,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { static const bool stack_grows_down = StackGrowsDown(); const size_t stack_size = getpagesize(); // MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead. - void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE, + void* const stack = mmap(nullptr, stack_size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED); @@ -1320,7 +1318,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { # endif // GTEST_OS_QNX # if GTEST_OS_LINUX GTEST_DEATH_TEST_CHECK_SYSCALL_( - sigaction(SIGPROF, &saved_sigprof_action, NULL)); + sigaction(SIGPROF, &saved_sigprof_action, nullptr)); # endif // GTEST_OS_LINUX GTEST_DEATH_TEST_CHECK_(child_pid != -1); @@ -1338,7 +1336,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { const TestInfo* const info = impl->current_test_info(); const int death_test_index = info->result()->death_test_count(); - if (flag != NULL) { + if (flag != nullptr) { set_write_fd(flag->write_fd()); return EXECUTE_TEST; } @@ -1393,7 +1391,7 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex, const int death_test_index = impl->current_test_info() ->increment_death_test_count(); - if (flag != NULL) { + if (flag != nullptr) { if (death_test_index > flag->index()) { DeathTest::set_last_death_test_message( "Death test count (" + StreamableToString(death_test_index) @@ -1404,7 +1402,7 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex, if (!(flag->file() == file && flag->line() == line && flag->index() == death_test_index)) { - *test = NULL; + *test = nullptr; return true; } } @@ -1515,7 +1513,7 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id, // initialized from the GTEST_FLAG(internal_run_death_test) flag if // the flag is specified; otherwise returns NULL. InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { - if (GTEST_FLAG(internal_run_death_test) == "") return NULL; + if (GTEST_FLAG(internal_run_death_test) == "") return nullptr; // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we // can use it here. diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index a7e65c0..317d17c 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -111,7 +111,7 @@ FilePath FilePath::GetCurrentDir() { // however, so fallback only when failure is detected. return FilePath(result == NULL ? kCurrentDirectoryString : cwd); # endif // GTEST_OS_NACL - return FilePath(result == NULL ? "" : cwd); + return FilePath(result == nullptr ? "" : cwd); #endif // GTEST_OS_WINDOWS_MOBILE } @@ -352,7 +352,7 @@ FilePath FilePath::RemoveTrailingPathSeparator() const { // redundancies that might be in a pathname involving "." or "..". // FIXME: handle Windows network shares (e.g. \\server\share). void FilePath::Normalize() { - if (pathname_.c_str() == NULL) { + if (pathname_.c_str() == nullptr) { pathname_ = ""; return; } diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index f79b1ad..f05de04 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -585,14 +585,14 @@ class GTEST_API_ UnitTestImpl { // total_test_case_count() - 1. If i is not in that range, returns NULL. const TestCase* GetTestCase(int i) const { const int index = GetElementOr(test_case_indices_, i, -1); - return index < 0 ? NULL : test_cases_[i]; + return index < 0 ? nullptr : test_cases_[i]; } // Gets the i-th test case among all the test cases. i can range from 0 to // total_test_case_count() - 1. If i is not in that range, returns NULL. TestCase* GetMutableTestCase(int i) { const int index = GetElementOr(test_case_indices_, i, -1); - return index < 0 ? NULL : test_cases_[index]; + return index < 0 ? nullptr : test_cases_[index]; } // Provides access to the event listener list. @@ -1158,8 +1158,7 @@ class StreamingListener : public EmptyTestEventListener { void OnTestPartResult(const TestPartResult& test_part_result) { const char* file_name = test_part_result.file_name(); - if (file_name == NULL) - file_name = ""; + if (file_name == nullptr) file_name = ""; SendLn("event=TestPartResult&file=" + UrlEncode(file_name) + "&line=" + StreamableToString(test_part_result.line_number()) + "&message=" + UrlEncode(test_part_result.message())); diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index fecb5d1..91f285c 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -935,7 +935,7 @@ const char kUnknownFile[] = "unknown file"; // Formats a source file path and a line number as they would appear // in an error message from the compiler used to compile this code. GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) { - const std::string file_name(file == NULL ? kUnknownFile : file); + const std::string file_name(file == nullptr ? kUnknownFile : file); if (line < 0) { return file_name + ":"; @@ -954,7 +954,7 @@ GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) { // to the file location it produces, unlike FormatFileLocation(). GTEST_API_ ::std::string FormatCompilerIndependentFileLocation( const char* file, int line) { - const std::string file_name(file == NULL ? kUnknownFile : file); + const std::string file_name(file == nullptr ? kUnknownFile : file); if (line < 0) return file_name; @@ -1034,7 +1034,7 @@ class CapturedStream { const int captured_fd = mkstemp(name_template); filename_ = name_template; # endif // GTEST_OS_WINDOWS - fflush(NULL); + fflush(nullptr); dup2(captured_fd, fd_); close(captured_fd); } @@ -1046,7 +1046,7 @@ class CapturedStream { std::string GetCapturedString() { if (uncaptured_fd_ != -1) { // Restores the original stream. - fflush(NULL); + fflush(nullptr); dup2(uncaptured_fd_, fd_); close(uncaptured_fd_); uncaptured_fd_ = -1; @@ -1069,13 +1069,13 @@ class CapturedStream { GTEST_DISABLE_MSC_DEPRECATED_POP_() -static CapturedStream* g_captured_stderr = NULL; -static CapturedStream* g_captured_stdout = NULL; +static CapturedStream* g_captured_stderr = nullptr; +static CapturedStream* g_captured_stdout = nullptr; // Starts capturing an output stream (stdout/stderr). static void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) { - if (*stream != NULL) { + if (*stream != nullptr) { GTEST_LOG_(FATAL) << "Only one " << stream_name << " capturer can exist at a time."; } @@ -1087,7 +1087,7 @@ static std::string GetCapturedStream(CapturedStream** captured_stream) { const std::string content = (*captured_stream)->GetCapturedString(); delete *captured_stream; - *captured_stream = NULL; + *captured_stream = nullptr; return content; } @@ -1146,10 +1146,11 @@ std::string ReadEntireFile(FILE* file) { } #if GTEST_HAS_DEATH_TEST -static const std::vector* g_injected_test_argvs = NULL; // Owned. +static const std::vector* g_injected_test_argvs = + nullptr; // Owned. std::vector GetInjectableArgvs() { - if (g_injected_test_argvs != NULL) { + if (g_injected_test_argvs != nullptr) { return *g_injected_test_argvs; } return GetArgvs(); @@ -1174,7 +1175,7 @@ void SetInjectableArgvs(const std::vector< ::string>& new_argvs) { void ClearInjectableArgvs() { delete g_injected_test_argvs; - g_injected_test_argvs = NULL; + g_injected_test_argvs = nullptr; } #endif // GTEST_HAS_DEATH_TEST @@ -1207,7 +1208,7 @@ static std::string FlagToEnvVar(const char* flag) { // unchanged and returns false. bool ParseInt32(const Message& src_text, const char* str, Int32* value) { // Parses the environment variable as a decimal integer. - char* end = NULL; + char* end = nullptr; const long long_value = strtol(str, &end, 10); // NOLINT // Has strtol() consumed all characters in the string? @@ -1296,7 +1297,7 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { std::string OutputFlagAlsoCheckEnvVar(){ std::string default_value_for_output_flag = ""; const char* xml_output_file_env = posix::GetEnv("XML_OUTPUT_FILE"); - if (NULL != xml_output_file_env) { + if (nullptr != xml_output_file_env) { default_value_for_output_flag = std::string("xml:") + xml_output_file_env; } return default_value_for_output_flag; diff --git a/googletest/src/gtest-printers.cc b/googletest/src/gtest-printers.cc index de4d245..3c0e758 100644 --- a/googletest/src/gtest-printers.cc +++ b/googletest/src/gtest-printers.cc @@ -327,7 +327,7 @@ void UniversalPrintArray(const wchar_t* begin, size_t len, ostream* os) { // Prints the given C string to the ostream. void PrintTo(const char* s, ostream* os) { - if (s == NULL) { + if (s == nullptr) { *os << "NULL"; } else { *os << ImplicitCast_(s) << " pointing to "; @@ -344,7 +344,7 @@ void PrintTo(const char* s, ostream* os) { #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) // Prints the given wide C string to the ostream. void PrintTo(const wchar_t* s, ostream* os) { - if (s == NULL) { + if (s == nullptr) { *os << "NULL"; } else { *os << ImplicitCast_(s) << " pointing to "; diff --git a/googletest/src/gtest-test-part.cc b/googletest/src/gtest-test-part.cc index 2855e3e..515b308 100644 --- a/googletest/src/gtest-test-part.cc +++ b/googletest/src/gtest-test-part.cc @@ -41,8 +41,7 @@ using internal::GetUnitTestImpl; // in it. std::string TestPartResult::ExtractSummary(const char* message) { const char* const stack_trace = strstr(message, internal::kStackTraceMarker); - return stack_trace == NULL ? message : - std::string(message, stack_trace); + return stack_trace == nullptr ? message : std::string(message, stack_trace); } // Prints a TestPartResult object. diff --git a/googletest/src/gtest-typed-test.cc b/googletest/src/gtest-typed-test.cc index 1dc2ad3..a305ed1 100644 --- a/googletest/src/gtest-typed-test.cc +++ b/googletest/src/gtest-typed-test.cc @@ -48,7 +48,7 @@ static const char* SkipSpaces(const char* str) { static std::vector SplitIntoTestNames(const char* src) { std::vector name_vec; src = SkipSpaces(src); - for (; src != NULL; src = SkipComma(src)) { + for (; src != nullptr; src = SkipComma(src)) { name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src))); } return name_vec; diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 996be23..737fdc2 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -196,14 +196,14 @@ bool g_help_flag = false; // Utilty function to Open File for Writing static FILE* OpenFileForWriting(const std::string& output_file) { - FILE* fileout = NULL; + FILE* fileout = nullptr; FilePath output_file_path(output_file); FilePath output_dir(output_file_path.RemoveFileName()); if (output_dir.CreateDirectoriesRecursively()) { fileout = posix::FOpen(output_file.c_str(), "w"); } - if (fileout == NULL) { + if (fileout == nullptr) { GTEST_LOG_(FATAL) << "Unable to open file \"" << output_file << "\""; } return fileout; @@ -216,7 +216,7 @@ static FILE* OpenFileForWriting(const std::string& output_file) { static const char* GetDefaultFilter() { const char* const testbridge_test_only = internal::posix::GetEnv("TESTBRIDGE_TEST_ONLY"); - if (testbridge_test_only != NULL) { + if (testbridge_test_only != nullptr) { return testbridge_test_only; } return kUniversalFilter; @@ -460,9 +460,9 @@ FilePath GetCurrentExecutableName() { std::string UnitTestOptions::GetOutputFormat() { const char* const gtest_output_flag = GTEST_FLAG(output).c_str(); const char* const colon = strchr(gtest_output_flag, ':'); - return (colon == NULL) ? - std::string(gtest_output_flag) : - std::string(gtest_output_flag, colon - gtest_output_flag); + return (colon == nullptr) + ? std::string(gtest_output_flag) + : std::string(gtest_output_flag, colon - gtest_output_flag); } // Returns the name of the requested output file, or the default if none @@ -475,7 +475,7 @@ std::string UnitTestOptions::GetAbsolutePathToOutputFile() { format = std::string(kDefaultOutputFormat); const char* const colon = strchr(gtest_output_flag, ':'); - if (colon == NULL) + if (colon == nullptr) return internal::FilePath::MakeFileName( internal::FilePath( UnitTest::GetInstance()->original_working_dir()), @@ -535,7 +535,7 @@ bool UnitTestOptions::MatchesFilter( cur_pattern = strchr(cur_pattern, ':'); // Returns if no more pattern can be found. - if (cur_pattern == NULL) { + if (cur_pattern == nullptr) { return false; } @@ -556,7 +556,7 @@ bool UnitTestOptions::FilterMatchesTest(const std::string &test_case_name, const char* const dash = strchr(p, '-'); std::string positive; std::string negative; - if (dash == NULL) { + if (dash == nullptr) { positive = GTEST_FLAG(filter).c_str(); // Whole string is a positive filter negative = ""; } else { @@ -701,7 +701,7 @@ static AssertionResult HasOneFailure(const char* /* results_expr */, << r; } - if (strstr(r.message(), substr.c_str()) == NULL) { + if (strstr(r.message(), substr.c_str()) == nullptr) { return AssertionFailure() << "Expected: " << expected << " containing \"" << substr << "\"\n" << " Actual:\n" @@ -888,7 +888,7 @@ TimeInMillis GetTimeInMillis() { return static_cast(now.time) * 1000 + now.millitm; #elif GTEST_HAS_GETTIMEOFDAY_ struct timeval now; - gettimeofday(&now, NULL); + gettimeofday(&now, nullptr); return static_cast(now.tv_sec) * 1000 + now.tv_usec / 1000; #else # error "Don't know how to get the current time on your system." @@ -941,9 +941,9 @@ const char* String::Utf16ToAnsi(LPCWSTR utf16_str) { // C string is considered different to any non-NULL C string, // including the empty string. bool String::CStringEquals(const char * lhs, const char * rhs) { - if ( lhs == NULL ) return rhs == NULL; + if (lhs == nullptr) return rhs == nullptr; - if ( rhs == NULL ) return false; + if (rhs == nullptr) return false; return strcmp(lhs, rhs) == 0; } @@ -1035,10 +1035,9 @@ std::string Message::GetString() const { // Used in EXPECT_TRUE/FALSE(assertion_result). AssertionResult::AssertionResult(const AssertionResult& other) : success_(other.success_), - message_(other.message_.get() != NULL ? - new ::std::string(*other.message_) : - static_cast< ::std::string*>(NULL)) { -} + message_(other.message_.get() != nullptr + ? new ::std::string(*other.message_) + : static_cast< ::std::string*>(nullptr)) {} // Swaps two AssertionResults. void AssertionResult::swap(AssertionResult& other) { @@ -1050,8 +1049,7 @@ void AssertionResult::swap(AssertionResult& other) { // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. AssertionResult AssertionResult::operator!() const { AssertionResult negation(!success_); - if (message_.get() != NULL) - negation << *message_; + if (message_.get() != nullptr) negation << *message_; return negation; } @@ -1605,17 +1603,15 @@ namespace { // only. bool IsSubstringPred(const char* needle, const char* haystack) { - if (needle == NULL || haystack == NULL) - return needle == haystack; + if (needle == nullptr || haystack == nullptr) return needle == haystack; - return strstr(haystack, needle) != NULL; + return strstr(haystack, needle) != nullptr; } bool IsSubstringPred(const wchar_t* needle, const wchar_t* haystack) { - if (needle == NULL || haystack == NULL) - return needle == haystack; + if (needle == nullptr || haystack == nullptr) return needle == haystack; - return wcsstr(haystack, needle) != NULL; + return wcsstr(haystack, needle) != nullptr; } // StringType here can be either ::std::string or ::std::wstring. @@ -1896,7 +1892,7 @@ std::string WideStringToUtf8(const wchar_t* str, int num_chars) { // Converts a wide C string to an std::string using the UTF-8 encoding. // NULL will be converted to "(null)". std::string String::ShowWideCString(const wchar_t * wide_c_str) { - if (wide_c_str == NULL) return "(null)"; + if (wide_c_str == nullptr) return "(null)"; return internal::WideStringToUtf8(wide_c_str, -1); } @@ -1908,9 +1904,9 @@ std::string String::ShowWideCString(const wchar_t * wide_c_str) { // C string is considered different to any non-NULL C string, // including the empty string. bool String::WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs) { - if (lhs == NULL) return rhs == NULL; + if (lhs == nullptr) return rhs == nullptr; - if (rhs == NULL) return false; + if (rhs == nullptr) return false; return wcscmp(lhs, rhs) == 0; } @@ -1953,10 +1949,8 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression, // NULL C string is considered different to any non-NULL C string, // including the empty string. bool String::CaseInsensitiveCStringEquals(const char * lhs, const char * rhs) { - if (lhs == NULL) - return rhs == NULL; - if (rhs == NULL) - return false; + if (lhs == nullptr) return rhs == nullptr; + if (rhs == nullptr) return false; return posix::StrCaseCmp(lhs, rhs) == 0; } @@ -1974,9 +1968,9 @@ bool String::CaseInsensitiveCStringEquals(const char * lhs, const char * rhs) { // current locale. bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs, const wchar_t* rhs) { - if (lhs == NULL) return rhs == NULL; + if (lhs == nullptr) return rhs == nullptr; - if (rhs == NULL) return false; + if (rhs == nullptr) return false; #if GTEST_OS_WINDOWS return _wcsicmp(lhs, rhs) == 0; @@ -2309,10 +2303,10 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, // AddTestPartResult. UnitTest::GetInstance()->AddTestPartResult( result_type, - NULL, // No info about the source file where the exception occurred. - -1, // We have no info on which line caused the exception. + nullptr, // No info about the source file where the exception occurred. + -1, // We have no info on which line caused the exception. message, - ""); // No stack trace, either. + ""); // No stack trace, either. } } // namespace internal @@ -2562,16 +2556,15 @@ bool Test::IsSkipped() { // Constructs a TestInfo object. It assumes ownership of the test factory // object. TestInfo::TestInfo(const std::string& a_test_case_name, - const std::string& a_name, - const char* a_type_param, + const std::string& a_name, const char* a_type_param, const char* a_value_param, internal::CodeLocation a_code_location, internal::TypeId fixture_class_id, internal::TestFactoryBase* factory) : test_case_name_(a_test_case_name), name_(a_name), - type_param_(a_type_param ? new std::string(a_type_param) : NULL), - value_param_(a_value_param ? new std::string(a_value_param) : NULL), + type_param_(a_type_param ? new std::string(a_type_param) : nullptr), + value_param_(a_value_param ? new std::string(a_value_param) : nullptr), location_(a_code_location), fixture_class_id_(fixture_class_id), should_run_(false), @@ -2725,7 +2718,7 @@ void TestInfo::Run() { // Tells UnitTest to stop associating assertion results to this // test. - impl->set_current_test_info(NULL); + impl->set_current_test_info(nullptr); } // class TestCase @@ -2783,12 +2776,11 @@ TestCase::TestCase(const char* a_name, const char* a_type_param, Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc) : name_(a_name), - type_param_(a_type_param ? new std::string(a_type_param) : NULL), + type_param_(a_type_param ? new std::string(a_type_param) : nullptr), set_up_tc_(set_up_tc), tear_down_tc_(tear_down_tc), should_run_(false), - elapsed_time_(0) { -} + elapsed_time_(0) {} // Destructor of TestCase. TestCase::~TestCase() { @@ -2800,14 +2792,14 @@ TestCase::~TestCase() { // total_test_count() - 1. If i is not in that range, returns NULL. const TestInfo* TestCase::GetTestInfo(int i) const { const int index = GetElementOr(test_indices_, i, -1); - return index < 0 ? NULL : test_info_list_[index]; + return index < 0 ? nullptr : test_info_list_[index]; } // Returns the i-th test among all the tests. i can range from 0 to // total_test_count() - 1. If i is not in that range, returns NULL. TestInfo* TestCase::GetMutableTestInfo(int i) { const int index = GetElementOr(test_indices_, i, -1); - return index < 0 ? NULL : test_info_list_[index]; + return index < 0 ? nullptr : test_info_list_[index]; } // Adds a test to this test case. Will delete the test upon @@ -2842,7 +2834,7 @@ void TestCase::Run() { this, &TestCase::RunTearDownTestCase, "TearDownTestCase()"); repeater->OnTestCaseEnd(*this); - impl->set_current_test_case(NULL); + impl->set_current_test_case(nullptr); } // Clears the results of all tests in this test case. @@ -3001,7 +2993,8 @@ static const char* GetAnsiColorCode(GTestColor color) { case COLOR_RED: return "1"; case COLOR_GREEN: return "2"; case COLOR_YELLOW: return "3"; - default: return NULL; + default: + return nullptr; }; } @@ -3106,14 +3099,13 @@ static void PrintFullTestCommentIfPresent(const TestInfo& test_info) { const char* const type_param = test_info.type_param(); const char* const value_param = test_info.value_param(); - if (type_param != NULL || value_param != NULL) { + if (type_param != nullptr || value_param != nullptr) { printf(", where "); - if (type_param != NULL) { + if (type_param != nullptr) { printf("%s = %s", kTypeParamLabel, type_param); - if (value_param != NULL) - printf(" and "); + if (value_param != nullptr) printf(" and "); } - if (value_param != NULL) { + if (value_param != nullptr) { printf("%s = %s", kValueParamLabel, value_param); } } @@ -3197,7 +3189,7 @@ void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) { FormatCountableNoun(test_case.test_to_run_count(), "test", "tests"); ColoredPrintf(COLOR_GREEN, "[----------] "); printf("%s from %s", counts.c_str(), test_case.name()); - if (test_case.type_param() == NULL) { + if (test_case.type_param() == nullptr) { printf("\n"); } else { printf(", where %s = %s\n", kTypeParamLabel, test_case.type_param()); @@ -3421,7 +3413,7 @@ TestEventListener* TestEventRepeater::Release(TestEventListener *listener) { } } - return NULL; + return nullptr; } // Since most methods are very similar, use macros to reduce boilerplate. @@ -3695,7 +3687,7 @@ static bool PortableLocaltime(time_t seconds, struct tm* out) { *out = *tm_ptr; return true; #else - return localtime_r(&seconds, out) != NULL; + return localtime_r(&seconds, out) != nullptr; #endif } @@ -3721,7 +3713,7 @@ void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream, *stream << ""); - if (next_segment != NULL) { + if (next_segment != nullptr) { stream->write( segment, static_cast(next_segment - segment)); *stream << "]]>]]>ai_next) { sockfd_ = socket( cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol); @@ -4479,9 +4471,8 @@ class ScopedPrematureExitFile { TestEventListeners::TestEventListeners() : repeater_(new internal::TestEventRepeater()), - default_result_printer_(NULL), - default_xml_generator_(NULL) { -} + default_result_printer_(nullptr), + default_xml_generator_(nullptr) {} TestEventListeners::~TestEventListeners() { delete repeater_; } @@ -4498,9 +4489,9 @@ void TestEventListeners::Append(TestEventListener* listener) { // NULL if the listener is not found in the list. TestEventListener* TestEventListeners::Release(TestEventListener* listener) { if (listener == default_result_printer_) - default_result_printer_ = NULL; + default_result_printer_ = nullptr; else if (listener == default_xml_generator_) - default_xml_generator_ = NULL; + default_xml_generator_ = nullptr; return repeater_->Release(listener); } @@ -4519,8 +4510,7 @@ void TestEventListeners::SetDefaultResultPrinter(TestEventListener* listener) { // list. delete Release(default_result_printer_); default_result_printer_ = listener; - if (listener != NULL) - Append(listener); + if (listener != nullptr) Append(listener); } } @@ -4535,8 +4525,7 @@ void TestEventListeners::SetDefaultXmlGenerator(TestEventListener* listener) { // list. delete Release(default_xml_generator_); default_xml_generator_ = listener; - if (listener != NULL) - Append(listener); + if (listener != nullptr) Append(listener); } } @@ -4688,8 +4677,8 @@ TestEventListeners& UnitTest::listeners() { // We don't protect this under mutex_, as we only support calling it // from the main thread. Environment* UnitTest::AddEnvironment(Environment* env) { - if (env == NULL) { - return NULL; + if (env == nullptr) { + return nullptr; } impl_->environments().push_back(env); @@ -4721,7 +4710,7 @@ void UnitTest::AddTestPartResult( } } - if (os_stack_trace.c_str() != NULL && !os_stack_trace.empty()) { + if (os_stack_trace.c_str() != nullptr && !os_stack_trace.empty()) { msg << internal::kStackTraceMarker << os_stack_trace; } @@ -4809,8 +4798,9 @@ int UnitTest::Run() { // that understands the premature-exit-file protocol to report the // test as having failed. const internal::ScopedPrematureExitFile premature_exit_file( - in_death_test_child_process ? - NULL : internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE")); + in_death_test_child_process + ? nullptr + : internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE")); // Captures the value of GTEST_FLAG(catch_exceptions). This value will be // used for the duration of the program. @@ -4924,23 +4914,22 @@ namespace internal { UnitTestImpl::UnitTestImpl(UnitTest* parent) : parent_(parent), GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355 /* using this in initializer */) - default_global_test_part_result_reporter_(this), + default_global_test_part_result_reporter_(this), default_per_thread_test_part_result_reporter_(this), - GTEST_DISABLE_MSC_WARNINGS_POP_() - global_test_part_result_repoter_( + GTEST_DISABLE_MSC_WARNINGS_POP_() global_test_part_result_repoter_( &default_global_test_part_result_reporter_), per_thread_test_part_result_reporter_( &default_per_thread_test_part_result_reporter_), parameterized_test_registry_(), parameterized_tests_registered_(false), last_death_test_case_(-1), - current_test_case_(NULL), - current_test_info_(NULL), + current_test_case_(nullptr), + current_test_info_(nullptr), ad_hoc_test_result_(), - os_stack_trace_getter_(NULL), + os_stack_trace_getter_(nullptr), post_flag_parse_init_performed_(false), random_seed_(0), // Will be overridden by the flag before first use. - random_(0), // Will be reseeded before first use. + random_(0), // Will be reseeded before first use. start_timestamp_(0), elapsed_time_(0), #if GTEST_HAS_DEATH_TEST @@ -4970,10 +4959,10 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) { std::string xml_element; TestResult* test_result; // TestResult appropriate for property recording. - if (current_test_info_ != NULL) { + if (current_test_info_ != nullptr) { xml_element = "testcase"; test_result = &(current_test_info_->result_); - } else if (current_test_case_ != NULL) { + } else if (current_test_case_ != nullptr) { xml_element = "testsuite"; test_result = &(current_test_case_->ad_hoc_test_result_); } else { @@ -4987,7 +4976,7 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) { // Disables event forwarding if the control is currently in a death test // subprocess. Must not be called before InitGoogleTest. void UnitTestImpl::SuppressTestEventsIfInSubprocess() { - if (internal_run_death_test_flag_.get() != NULL) + if (internal_run_death_test_flag_.get() != nullptr) listeners()->SuppressEventForwarding(); } #endif // GTEST_HAS_DEATH_TEST @@ -5085,7 +5074,8 @@ class TestCaseNameIs { // Returns true iff the name of test_case matches name_. bool operator()(const TestCase* test_case) const { - return test_case != NULL && strcmp(test_case->name(), name_.c_str()) == 0; + return test_case != nullptr && + strcmp(test_case->name(), name_.c_str()) == 0; } private: @@ -5175,7 +5165,8 @@ bool UnitTestImpl::RunAllTests() { bool in_subprocess_for_death_test = false; #if GTEST_HAS_DEATH_TEST - in_subprocess_for_death_test = (internal_run_death_test_flag_.get() != NULL); + in_subprocess_for_death_test = + (internal_run_death_test_flag_.get() != nullptr); # if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) if (in_subprocess_for_death_test) { GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_(); @@ -5306,9 +5297,9 @@ bool UnitTestImpl::RunAllTests() { // be created, prints an error and exits. void WriteToShardStatusFileIfNeeded() { const char* const test_shard_file = posix::GetEnv(kTestShardStatusFile); - if (test_shard_file != NULL) { + if (test_shard_file != nullptr) { FILE* const file = posix::FOpen(test_shard_file, "w"); - if (file == NULL) { + if (file == nullptr) { ColoredPrintf(COLOR_RED, "Could not write to the test shard status file \"%s\" " "specified by the %s environment variable.\n", @@ -5373,7 +5364,7 @@ bool ShouldShard(const char* total_shards_env, // and aborts. Int32 Int32FromEnvOrDie(const char* var, Int32 default_val) { const char* str_val = posix::GetEnv(var); - if (str_val == NULL) { + if (str_val == nullptr) { return default_val; } @@ -5459,7 +5450,7 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { // max_length characters, only prints the first max_length characters // and "...". static void PrintOnOneLine(const char* str, int max_length) { - if (str != NULL) { + if (str != nullptr) { for (int i = 0; *str != '\0'; ++str) { if (i >= max_length) { printf("..."); @@ -5492,7 +5483,7 @@ void UnitTestImpl::ListTestsMatchingFilter() { if (!printed_test_case_name) { printed_test_case_name = true; printf("%s.", test_case->name()); - if (test_case->type_param() != NULL) { + if (test_case->type_param() != nullptr) { printf(" # %s = ", kTypeParamLabel); // We print the type parameter on a single line to make // the output easy to parse by a program. @@ -5501,7 +5492,7 @@ void UnitTestImpl::ListTestsMatchingFilter() { printf("\n"); } printf(" %s", test_info->name()); - if (test_info->value_param() != NULL) { + if (test_info->value_param() != nullptr) { printf(" # %s = ", kValueParamLabel); // We print the value parameter on a single line to make the // output easy to parse by a program. @@ -5548,7 +5539,7 @@ void UnitTestImpl::set_os_stack_trace_getter( // otherwise, creates an OsStackTraceGetter, makes it the current // getter, and returns it. OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() { - if (os_stack_trace_getter_ == NULL) { + if (os_stack_trace_getter_ == nullptr) { #ifdef GTEST_OS_STACK_TRACE_GETTER_ os_stack_trace_getter_ = new GTEST_OS_STACK_TRACE_GETTER_; #else @@ -5561,10 +5552,10 @@ OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() { // Returns the most specific TestResult currently running. TestResult* UnitTestImpl::current_test_result() { - if (current_test_info_ != NULL) { + if (current_test_info_ != nullptr) { return ¤t_test_info_->result_; } - if (current_test_case_ != NULL) { + if (current_test_case_ != nullptr) { return ¤t_test_case_->ad_hoc_test_result_; } return &ad_hoc_test_result_; @@ -5651,12 +5642,12 @@ bool SkipPrefix(const char* prefix, const char** pstr) { static const char* ParseFlagValue(const char* str, const char* flag, bool def_optional) { // str and flag must not be NULL. - if (str == NULL || flag == NULL) return NULL; + if (str == nullptr || flag == nullptr) return nullptr; // The flag must start with "--" followed by GTEST_FLAG_PREFIX_. const std::string flag_str = std::string("--") + GTEST_FLAG_PREFIX_ + flag; const size_t flag_len = flag_str.length(); - if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL; + if (strncmp(str, flag_str.c_str(), flag_len) != 0) return nullptr; // Skips the flag name. const char* flag_end = str + flag_len; @@ -5669,7 +5660,7 @@ static const char* ParseFlagValue(const char* str, const char* flag, // If def_optional is true and there are more characters after the // flag name, or if def_optional is false, there must be a '=' after // the flag name. - if (flag_end[0] != '=') return NULL; + if (flag_end[0] != '=') return nullptr; // Returns the string after "=". return flag_end + 1; @@ -5690,7 +5681,7 @@ static bool ParseBoolFlag(const char* str, const char* flag, bool* value) { const char* const value_str = ParseFlagValue(str, flag, true); // Aborts if the parsing failed. - if (value_str == NULL) return false; + if (value_str == nullptr) return false; // Converts the string value to a bool. *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F'); @@ -5707,7 +5698,7 @@ bool ParseInt32Flag(const char* str, const char* flag, Int32* value) { const char* const value_str = ParseFlagValue(str, flag, false); // Aborts if the parsing failed. - if (value_str == NULL) return false; + if (value_str == nullptr) return false; // Sets *value to the value of the flag. return ParseInt32(Message() << "The value of flag --" << flag, @@ -5725,7 +5716,7 @@ static bool ParseStringFlag(const char* str, const char* flag, String* value) { const char* const value_str = ParseFlagValue(str, flag, false); // Aborts if the parsing failed. - if (value_str == NULL) return false; + if (value_str == nullptr) return false; // Sets *value to the value of the flag. *value = value_str; @@ -5767,7 +5758,7 @@ static void PrintColorEncoded(const char* str) { // next segment. for (;;) { const char* p = strchr(str, '@'); - if (p == NULL) { + if (p == nullptr) { ColoredPrintf(color, "%s", str); return; } diff --git a/googletest/test/googletest-catch-exceptions-test_.cc b/googletest/test/googletest-catch-exceptions-test_.cc index f1708a9..75d1d2d 100644 --- a/googletest/test/googletest-catch-exceptions-test_.cc +++ b/googletest/test/googletest-catch-exceptions-test_.cc @@ -277,7 +277,7 @@ TEST(CxxExceptionTest, ThrowsNonStdCxxException) { // ones. void TerminateHandler() { fprintf(stderr, "%s\n", "Unhandled C++ exception terminating the program."); - fflush(NULL); + fflush(nullptr); exit(3); } diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc index c0c3026..a81702c 100644 --- a/googletest/test/googletest-death-test-test.cc +++ b/googletest/test/googletest-death-test-test.cc @@ -370,13 +370,13 @@ void SetSigprofActionAndTimer() { timer.it_interval.tv_sec = 0; timer.it_interval.tv_usec = 1; timer.it_value = timer.it_interval; - ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, NULL)); + ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr)); struct sigaction signal_action; memset(&signal_action, 0, sizeof(signal_action)); sigemptyset(&signal_action.sa_mask); signal_action.sa_sigaction = SigprofAction; signal_action.sa_flags = SA_RESTART | SA_SIGINFO; - ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, NULL)); + ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, nullptr)); } // Disables ITIMER_PROF timer and ignores SIGPROF signal. @@ -385,7 +385,7 @@ void DisableSigprofActionAndTimer(struct sigaction* old_signal_action) { timer.it_interval.tv_sec = 0; timer.it_interval.tv_usec = 0; timer.it_value = timer.it_interval; - ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, NULL)); + ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr)); struct sigaction signal_action; memset(&signal_action, 0, sizeof(signal_action)); sigemptyset(&signal_action.sa_mask); @@ -466,7 +466,7 @@ TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) { if (!testing::GTEST_FLAG(death_test_use_fork)) { testing::GTEST_FLAG(death_test_style) = "threadsafe"; pthread_flag = false; - ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, NULL, NULL)); + ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, nullptr, nullptr)); ASSERT_DEATH(_exit(1), ""); ASSERT_FALSE(pthread_flag); } @@ -1001,7 +1001,7 @@ bool MockDeathTestFactory::Create(const char* /*statement*/, if (create_) { *test = new MockDeathTest(this, role_, status_, passed_); } else { - *test = NULL; + *test = nullptr; } return true; } @@ -1021,9 +1021,9 @@ class MacroLogicDeathTest : public testing::Test { static void TearDownTestCase() { delete replacer_; - replacer_ = NULL; + replacer_ = nullptr; delete factory_; - factory_ = NULL; + factory_ = nullptr; } // Runs a death test that breaks the rules by returning. Such a death @@ -1037,10 +1037,9 @@ class MacroLogicDeathTest : public testing::Test { } }; -testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ - = NULL; -MockDeathTestFactory* MacroLogicDeathTest::factory_ = NULL; - +testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ = + nullptr; +MockDeathTestFactory* MacroLogicDeathTest::factory_ = nullptr; // Test that nothing happens when the factory doesn't return a DeathTest: TEST_F(MacroLogicDeathTest, NothingHappens) { diff --git a/googletest/test/googletest-linked-ptr-test.cc b/googletest/test/googletest-linked-ptr-test.cc index fa00f34..f680253 100644 --- a/googletest/test/googletest-linked-ptr-test.cc +++ b/googletest/test/googletest-linked-ptr-test.cc @@ -38,7 +38,7 @@ using testing::Message; using testing::internal::linked_ptr; int num; -Message* history = NULL; +Message* history = nullptr; // Class which tracks allocation/deallocation class A { @@ -67,7 +67,7 @@ class LinkedPtrTest : public testing::Test { virtual ~LinkedPtrTest() { delete history; - history = NULL; + history = nullptr; } }; @@ -77,18 +77,18 @@ TEST_F(LinkedPtrTest, GeneralTest) { // Use explicit function call notation here to suppress self-assign warning. a0.operator=(a0); a1 = a2; - ASSERT_EQ(a0.get(), static_cast(NULL)); - ASSERT_EQ(a1.get(), static_cast(NULL)); - ASSERT_EQ(a2.get(), static_cast(NULL)); - ASSERT_TRUE(a0 == NULL); - ASSERT_TRUE(a1 == NULL); - ASSERT_TRUE(a2 == NULL); + ASSERT_EQ(a0.get(), static_cast(nullptr)); + ASSERT_EQ(a1.get(), static_cast(nullptr)); + ASSERT_EQ(a2.get(), static_cast(nullptr)); + ASSERT_TRUE(a0 == nullptr); + ASSERT_TRUE(a1 == nullptr); + ASSERT_TRUE(a2 == nullptr); { linked_ptr a3(new A); a0 = a3; ASSERT_TRUE(a0 == a3); - ASSERT_TRUE(a0 != NULL); + ASSERT_TRUE(a0 != nullptr); ASSERT_TRUE(a0.get() == a3); ASSERT_TRUE(a0 == a3.get()); linked_ptr a4(a0); @@ -101,7 +101,7 @@ TEST_F(LinkedPtrTest, GeneralTest) { linked_ptr a6(b0); ASSERT_TRUE(b0 == a6); ASSERT_TRUE(a6 == b0); - ASSERT_TRUE(b0 != NULL); + ASSERT_TRUE(b0 != nullptr); a5 = b0; a5 = b0; a3->Use(); diff --git a/googletest/test/googletest-listener-test.cc b/googletest/test/googletest-listener-test.cc index 8355597..a4f42eb 100644 --- a/googletest/test/googletest-listener-test.cc +++ b/googletest/test/googletest-listener-test.cc @@ -47,7 +47,7 @@ using ::testing::TestPartResult; using ::testing::UnitTest; // Used by tests to register their events. -std::vector* g_events = NULL; +std::vector* g_events = nullptr; namespace testing { namespace internal { diff --git a/googletest/test/googletest-message-test.cc b/googletest/test/googletest-message-test.cc index c644585..962d519 100644 --- a/googletest/test/googletest-message-test.cc +++ b/googletest/test/googletest-message-test.cc @@ -85,7 +85,7 @@ TEST(MessageTest, StreamsPointer) { // Tests streaming a NULL non-char pointer. TEST(MessageTest, StreamsNullPointer) { - int* p = NULL; + int* p = nullptr; EXPECT_EQ("(null)", (Message() << p).GetString()); } @@ -96,7 +96,7 @@ TEST(MessageTest, StreamsCString) { // Tests streaming a NULL C string. TEST(MessageTest, StreamsNullCString) { - char* p = NULL; + char* p = nullptr; EXPECT_EQ("(null)", (Message() << p).GetString()); } diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index f6525ec..a24dfce 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -174,7 +174,7 @@ TEST(SCOPED_TRACETest, AcceptedValues) { SCOPED_TRACE("literal string"); SCOPED_TRACE(std::string("std::string")); SCOPED_TRACE(1337); // streamable type - const char* null_value = NULL; + const char* null_value = nullptr; SCOPED_TRACE(null_value); ADD_FAILURE() << "Just checking that all these values work fine."; @@ -306,9 +306,8 @@ TEST(SCOPED_TRACETest, WorksConcurrently) { printf("(expecting 6 failures)\n"); CheckPoints check_points; - ThreadWithParam thread(&ThreadWithScopedTrace, - &check_points, - NULL); + ThreadWithParam thread(&ThreadWithScopedTrace, &check_points, + nullptr); check_points.n1.WaitForNotification(); { @@ -511,7 +510,7 @@ class DeathTestAndMultiThreadsTest : public testing::Test { // Starts a thread and waits for it to begin. virtual void SetUp() { thread_.reset(new ThreadWithParam( - &ThreadRoutine, ¬ifications_, NULL)); + &ThreadRoutine, ¬ifications_, nullptr)); notifications_.spawn_thread_started.WaitForNotification(); } // Tells the thread to finish, and reaps it. @@ -966,7 +965,7 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailure) { class ExpectFailureWithThreadsTest : public ExpectFailureTest { protected: static void AddFailureInOtherThread(FailureMode failure) { - ThreadWithParam thread(&AddFailure, failure, NULL); + ThreadWithParam thread(&AddFailure, failure, nullptr); thread.Join(); } }; diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index 399316f..2de35e0 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -262,9 +262,9 @@ TEST(FormatFileLocationTest, FormatsFileLocation) { } TEST(FormatFileLocationTest, FormatsUnknownFile) { - EXPECT_PRED_FORMAT2( - IsSubstring, "unknown file", FormatFileLocation(NULL, 42)); - EXPECT_PRED_FORMAT2(IsSubstring, "42", FormatFileLocation(NULL, 42)); + EXPECT_PRED_FORMAT2(IsSubstring, "unknown file", + FormatFileLocation(nullptr, 42)); + EXPECT_PRED_FORMAT2(IsSubstring, "42", FormatFileLocation(nullptr, 42)); } TEST(FormatFileLocationTest, FormatsUknownLine) { @@ -272,7 +272,7 @@ TEST(FormatFileLocationTest, FormatsUknownLine) { } TEST(FormatFileLocationTest, FormatsUknownFileAndLine) { - EXPECT_EQ("unknown file:", FormatFileLocation(NULL, -1)); + EXPECT_EQ("unknown file:", FormatFileLocation(nullptr, -1)); } // Verifies behavior of FormatCompilerIndependentFileLocation. @@ -282,7 +282,7 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsFileLocation) { TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFile) { EXPECT_EQ("unknown file:42", - FormatCompilerIndependentFileLocation(NULL, 42)); + FormatCompilerIndependentFileLocation(nullptr, 42)); } TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownLine) { @@ -290,7 +290,7 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownLine) { } TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) { - EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(NULL, -1)); + EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(nullptr, -1)); } #if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_QNX || GTEST_OS_FUCHSIA @@ -298,7 +298,7 @@ void* ThreadFunc(void* data) { internal::Mutex* mutex = static_cast(data); mutex->Lock(); mutex->Unlock(); - return NULL; + return nullptr; } TEST(GetThreadCountTest, ReturnsCorrectValue) { @@ -965,7 +965,7 @@ TEST(ThreadLocalTest, DefaultConstructorInitializesToDefaultValues) { EXPECT_EQ(0, t1.get()); ThreadLocal t2; - EXPECT_TRUE(t2.get() == NULL); + EXPECT_TRUE(t2.get() == nullptr); } TEST(ThreadLocalTest, SingleParamConstructorInitializesToParam) { @@ -1015,7 +1015,7 @@ void AddTwo(int* param) { *param += 2; } TEST(ThreadWithParamTest, ConstructorExecutesThreadFunc) { int i = 40; - ThreadWithParam thread(&AddTwo, &i, NULL); + ThreadWithParam thread(&AddTwo, &i, nullptr); thread.Join(); EXPECT_EQ(42, i); } @@ -1055,7 +1055,7 @@ class AtomicCounterWithMutex { // functionality as we are testing them here. pthread_mutex_t memory_barrier_mutex; GTEST_CHECK_POSIX_SUCCESS_( - pthread_mutex_init(&memory_barrier_mutex, NULL)); + pthread_mutex_init(&memory_barrier_mutex, nullptr)); GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&memory_barrier_mutex)); SleepMilliseconds(random_.Generate(30)); @@ -1118,7 +1118,7 @@ TEST(MutexTest, OnlyOneThreadCanLockAtATime) { template void RunFromThread(void (func)(T), T param) { - ThreadWithParam thread(func, param, NULL); + ThreadWithParam thread(func, param, nullptr); thread.Join(); } @@ -1250,8 +1250,8 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) { ASSERT_EQ(0U, DestructorCall::List().size()); // This creates another DestructorTracker object in the new thread. - ThreadWithParam thread( - &CallThreadLocalGet, &thread_local_tracker, NULL); + ThreadWithParam thread(&CallThreadLocalGet, + &thread_local_tracker, nullptr); thread.Join(); // The thread has exited, and we should have a DestroyedTracker diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index 87fdd28..ce7806c 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -405,7 +405,7 @@ TEST(PrintCStringTest, NonConst) { // NULL C string. TEST(PrintCStringTest, Null) { - const char* p = NULL; + const char* p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -440,7 +440,7 @@ TEST(PrintWideCStringTest, NonConst) { // NULL wide C string. TEST(PrintWideCStringTest, Null) { - const wchar_t* p = NULL; + const wchar_t* p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -460,7 +460,7 @@ TEST(PrintWideCStringTest, EscapesProperly) { TEST(PrintCharPointerTest, SignedChar) { signed char* p = reinterpret_cast(0x1234); EXPECT_EQ(PrintPointer(p), Print(p)); - p = NULL; + p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -468,7 +468,7 @@ TEST(PrintCharPointerTest, SignedChar) { TEST(PrintCharPointerTest, ConstSignedChar) { signed char* p = reinterpret_cast(0x1234); EXPECT_EQ(PrintPointer(p), Print(p)); - p = NULL; + p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -476,7 +476,7 @@ TEST(PrintCharPointerTest, ConstSignedChar) { TEST(PrintCharPointerTest, UnsignedChar) { unsigned char* p = reinterpret_cast(0x1234); EXPECT_EQ(PrintPointer(p), Print(p)); - p = NULL; + p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -484,7 +484,7 @@ TEST(PrintCharPointerTest, UnsignedChar) { TEST(PrintCharPointerTest, ConstUnsignedChar) { const unsigned char* p = reinterpret_cast(0x1234); EXPECT_EQ(PrintPointer(p), Print(p)); - p = NULL; + p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -494,7 +494,7 @@ TEST(PrintCharPointerTest, ConstUnsignedChar) { TEST(PrintPointerToBuiltInTypeTest, Bool) { bool* p = reinterpret_cast(0xABCD); EXPECT_EQ(PrintPointer(p), Print(p)); - p = NULL; + p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -502,7 +502,7 @@ TEST(PrintPointerToBuiltInTypeTest, Bool) { TEST(PrintPointerToBuiltInTypeTest, Void) { void* p = reinterpret_cast(0xABCD); EXPECT_EQ(PrintPointer(p), Print(p)); - p = NULL; + p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -510,7 +510,7 @@ TEST(PrintPointerToBuiltInTypeTest, Void) { TEST(PrintPointerToBuiltInTypeTest, ConstVoid) { const void* p = reinterpret_cast(0xABCD); EXPECT_EQ(PrintPointer(p), Print(p)); - p = NULL; + p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -518,7 +518,7 @@ TEST(PrintPointerToBuiltInTypeTest, ConstVoid) { TEST(PrintPointerToPointerTest, IntPointerPointer) { int** p = reinterpret_cast(0xABCD); EXPECT_EQ(PrintPointer(p), Print(p)); - p = NULL; + p = nullptr; EXPECT_EQ("NULL", Print(p)); } @@ -1398,7 +1398,7 @@ TEST(FormatForComparisonFailureMessageTest, WorksForWCharPointerVsStdWString) { // char array vs pointer TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsPointer) { char str[] = "hi \"world\""; - char* p = NULL; + char* p = nullptr; EXPECT_EQ(PrintPointer(str), FormatForComparisonFailureMessage(str, p).c_str()); } @@ -1413,7 +1413,7 @@ TEST(FormatForComparisonFailureMessageTest, WorksForCharArrayVsCharArray) { // wchar_t array vs pointer TEST(FormatForComparisonFailureMessageTest, WorksForWCharArrayVsPointer) { wchar_t str[] = L"hi \"world\""; - wchar_t* p = NULL; + wchar_t* p = nullptr; EXPECT_EQ(PrintPointer(str), FormatForComparisonFailureMessage(str, p).c_str()); } @@ -1614,7 +1614,7 @@ TEST(UniversalTersePrintTest, WorksForCString) { UniversalTersePrint(s2, &ss2); EXPECT_EQ("\"abc\"", ss2.str()); - const char* s3 = NULL; + const char* s3 = nullptr; ::std::stringstream ss3; UniversalTersePrint(s3, &ss3); EXPECT_EQ("NULL", ss3.str()); @@ -1644,7 +1644,7 @@ TEST(UniversalPrintTest, WorksForCString) { UniversalPrint(s2, &ss2); EXPECT_EQ(PrintPointer(s2) + " pointing to \"abc\"", std::string(ss2.str())); - const char* s3 = NULL; + const char* s3 = nullptr; ::std::stringstream ss3; UniversalPrint(s3, &ss3); EXPECT_EQ("NULL", ss3.str()); diff --git a/googletest/test/googletest-throw-on-failure-test_.cc b/googletest/test/googletest-throw-on-failure-test_.cc index f9a2c64..83bb914 100644 --- a/googletest/test/googletest-throw-on-failure-test_.cc +++ b/googletest/test/googletest-throw-on-failure-test_.cc @@ -45,7 +45,7 @@ // ones. void TerminateHandler() { fprintf(stderr, "%s\n", "Unhandled C++ exception terminating the program."); - fflush(NULL); + fflush(nullptr); exit(1); } diff --git a/googletest/test/googletest-tuple-test.cc b/googletest/test/googletest-tuple-test.cc index dd82c16..7a5bf42 100644 --- a/googletest/test/googletest-tuple-test.cc +++ b/googletest/test/googletest-tuple-test.cc @@ -158,7 +158,7 @@ TEST(TupleConstructorTest, DefaultConstructorDefaultInitializesEachField) { b3 = a3; EXPECT_EQ(0.0, get<0>(b3)); EXPECT_EQ('\0', get<1>(b3)); - EXPECT_TRUE(get<2>(b3) == NULL); + EXPECT_TRUE(get<2>(b3) == nullptr); tuple a10, b10; b10 = a10; diff --git a/googletest/test/gtest-typed-test_test.cc b/googletest/test/gtest-typed-test_test.cc index 4e39869..95e9e0e 100644 --- a/googletest/test/gtest-typed-test_test.cc +++ b/googletest/test/gtest-typed-test_test.cc @@ -55,7 +55,7 @@ class CommonTest : public Test { static void TearDownTestCase() { delete shared_; - shared_ = NULL; + shared_ = nullptr; } // This 'protected:' is optional. There's no harm in making all @@ -85,7 +85,7 @@ class CommonTest : public Test { }; template -T* CommonTest::shared_ = NULL; +T* CommonTest::shared_ = nullptr; // This #ifdef block tests typed tests. #if GTEST_HAS_TYPED_TEST @@ -121,7 +121,7 @@ TYPED_TEST(CommonTest, ValuesAreCorrect) { TYPED_TEST(CommonTest, ValuesAreStillCorrect) { // Static members of the fixture class template can also be visited // via 'this'. - ASSERT_TRUE(this->shared_ != NULL); + ASSERT_TRUE(this->shared_ != nullptr); EXPECT_EQ(5, *this->shared_); // TypeParam can be used to refer to the type parameter. @@ -292,7 +292,7 @@ TYPED_TEST_P(DerivedTest, ValuesAreCorrect) { TYPED_TEST_P(DerivedTest, ValuesAreStillCorrect) { // Static members of the fixture class template can also be visited // via 'this'. - ASSERT_TRUE(this->shared_ != NULL); + ASSERT_TRUE(this->shared_ != nullptr); EXPECT_EQ(5, *this->shared_); EXPECT_EQ(2, this->value_); } diff --git a/googletest/test/gtest-unittest-api_test.cc b/googletest/test/gtest-unittest-api_test.cc index f3ea03a..7898286 100644 --- a/googletest/test/gtest-unittest-api_test.cc +++ b/googletest/test/gtest-unittest-api_test.cc @@ -76,7 +76,7 @@ class UnitTestHelper { if (0 == strcmp(test_case->name(), name)) return test_case; } - return NULL; + return nullptr; } // Returns the array of pointers to all tests in a particular test case @@ -137,7 +137,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) { } AssertionResult IsNull(const char* str) { - if (str != NULL) { + if (str != nullptr) { return testing::AssertionFailure() << "argument is " << str; } return AssertionSuccess(); @@ -145,7 +145,7 @@ AssertionResult IsNull(const char* str) { TEST(ApiTest, TestCaseImmutableAccessorsWork) { const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest"); - ASSERT_TRUE(test_case != NULL); + ASSERT_TRUE(test_case != nullptr); EXPECT_STREQ("ApiTest", test_case->name()); EXPECT_TRUE(IsNull(test_case->type_param())); @@ -181,11 +181,11 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { EXPECT_TRUE(tests[3]->should_run()); delete[] tests; - tests = NULL; + tests = nullptr; #if GTEST_HAS_TYPED_TEST test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0"); - ASSERT_TRUE(test_case != NULL); + ASSERT_TRUE(test_case != nullptr); EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name()); EXPECT_STREQ(GetTypeName().c_str(), test_case->type_param()); @@ -208,7 +208,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { TEST(ApiTest, TestCaseDisabledAccessorsWork) { const TestCase* test_case = UnitTestHelper::FindTestCase("DISABLED_Test"); - ASSERT_TRUE(test_case != NULL); + ASSERT_TRUE(test_case != nullptr); EXPECT_STREQ("DISABLED_Test", test_case->name()); EXPECT_TRUE(IsNull(test_case->type_param())); diff --git a/googletest/test/gtest_assert_by_exception_test.cc b/googletest/test/gtest_assert_by_exception_test.cc index 0eae857..7dfd48c 100644 --- a/googletest/test/gtest_assert_by_exception_test.cc +++ b/googletest/test/gtest_assert_by_exception_test.cc @@ -80,8 +80,7 @@ TEST(Test, Test) { try { AssertFalse(); } catch(const testing::AssertionException& e) { - if (strstr(e.what(), "Expected failure") != NULL) - throw; + if (strstr(e.what(), "Expected failure") != nullptr) throw; printf("%s", "A failed assertion did throw an exception of the right type, " diff --git a/googletest/test/gtest_premature_exit_test.cc b/googletest/test/gtest_premature_exit_test.cc index c1e9305..0920a97 100644 --- a/googletest/test/gtest_premature_exit_test.cc +++ b/googletest/test/gtest_premature_exit_test.cc @@ -56,7 +56,7 @@ class PrematureExitTest : public Test { premature_exit_file_path_ = GetEnv("TEST_PREMATURE_EXIT_FILE"); // Normalize NULL to "" for ease of handling. - if (premature_exit_file_path_ == NULL) { + if (premature_exit_file_path_ == nullptr) { premature_exit_file_path_ = ""; } } @@ -113,7 +113,7 @@ int main(int argc, char **argv) { // Test that the premature-exit file is deleted upon return from // RUN_ALL_TESTS(). const char* const filepath = GetEnv("TEST_PREMATURE_EXIT_FILE"); - if (filepath != NULL && *filepath != '\0') { + if (filepath != nullptr && *filepath != '\0') { if (PrematureExitTest::FileExists(filepath)) { printf( "File %s shouldn't exist after the test program finishes, but does.", diff --git a/googletest/test/gtest_stress_test.cc b/googletest/test/gtest_stress_test.cc index 95ada39..3af1403 100644 --- a/googletest/test/gtest_stress_test.cc +++ b/googletest/test/gtest_stress_test.cc @@ -163,7 +163,7 @@ void FailingThread(bool is_fatal) { } void GenerateFatalFailureInAnotherThread(bool is_fatal) { - ThreadWithParam thread(&FailingThread, is_fatal, NULL); + ThreadWithParam thread(&FailingThread, is_fatal, nullptr); thread.Join(); } diff --git a/googletest/test/gtest_throw_on_failure_ex_test.cc b/googletest/test/gtest_throw_on_failure_ex_test.cc index 93f59d4..1d95adb 100644 --- a/googletest/test/gtest_throw_on_failure_ex_test.cc +++ b/googletest/test/gtest_throw_on_failure_ex_test.cc @@ -63,8 +63,7 @@ void TestFailureThrowsRuntimeError() { try { EXPECT_EQ(2, 3) << "Expected failure"; } catch(const std::runtime_error& e) { - if (strstr(e.what(), "Expected failure") != NULL) - return; + if (strstr(e.what(), "Expected failure") != nullptr) return; printf("%s", "A failed assertion did throw an exception of the right type, " diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index c03b367..c6280ca 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -86,8 +86,8 @@ class StreamingListenerTest : public Test { StreamingListenerTest() : fake_sock_writer_(new FakeSocketWriter), streamer_(fake_sock_writer_), - test_info_obj_("FooTest", "Bar", NULL, NULL, - CodeLocation(__FILE__, __LINE__), 0, NULL) {} + test_info_obj_("FooTest", "Bar", nullptr, nullptr, + CodeLocation(__FILE__, __LINE__), nullptr, nullptr) {} protected: std::string* output() { return &(fake_sock_writer_->output_); } @@ -112,13 +112,13 @@ TEST_F(StreamingListenerTest, OnTestIterationEnd) { TEST_F(StreamingListenerTest, OnTestCaseStart) { *output() = ""; - streamer_.OnTestCaseStart(TestCase("FooTest", "Bar", NULL, NULL)); + streamer_.OnTestCaseStart(TestCase("FooTest", "Bar", nullptr, nullptr)); EXPECT_EQ("event=TestCaseStart&name=FooTest\n", *output()); } TEST_F(StreamingListenerTest, OnTestCaseEnd) { *output() = ""; - streamer_.OnTestCaseEnd(TestCase("FooTest", "Bar", NULL, NULL)); + streamer_.OnTestCaseEnd(TestCase("FooTest", "Bar", nullptr, nullptr)); EXPECT_EQ("event=TestCaseEnd&passed=1&elapsed_time=0ms\n", *output()); } @@ -439,7 +439,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { private: virtual void SetUp() { - saved_tz_ = NULL; + saved_tz_ = nullptr; GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv, strdup: deprecated */) if (getenv("TZ")) @@ -455,7 +455,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { virtual void TearDown() { SetTimeZone(saved_tz_); free(const_cast(saved_tz_)); - saved_tz_ = NULL; + saved_tz_ = nullptr; } static void SetTimeZone(const char* time_zone) { @@ -521,10 +521,10 @@ TEST_F(FormatEpochTimeInMillisAsIso8601Test, PrintsEpochStart) { // Tests that GTEST_IS_NULL_LITERAL_(x) is true when x is a null // pointer literal. TEST(NullLiteralTest, IsTrueForNullLiterals) { - EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(NULL)); - EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0)); - EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0U)); - EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0L)); + EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(nullptr)); + EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(nullptr)); + EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(nullptr)); + EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(nullptr)); } // Tests that GTEST_IS_NULL_LITERAL_(x) is false when x is not a null @@ -533,7 +533,7 @@ TEST(NullLiteralTest, IsFalseForNonNullLiterals) { EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(1)); EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(0.0)); EXPECT_FALSE(GTEST_IS_NULL_LITERAL_('a')); - EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(static_cast(NULL))); + EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(static_cast(nullptr))); } # ifdef __BORLANDC__ @@ -1032,11 +1032,11 @@ TEST(StringTest, EndsWithCaseInsensitive) { // C++Builder's preprocessor is buggy; it fails to expand macros that // appear in macro parameters after wide char literals. Provide an alias // for NULL as a workaround. -static const wchar_t* const kNull = NULL; +static const wchar_t* const kNull = nullptr; // Tests String::CaseInsensitiveWideCStringEquals TEST(StringTest, CaseInsensitiveWideCStringEquals) { - EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(NULL, NULL)); + EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(nullptr, nullptr)); EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L"")); EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(L"", kNull)); EXPECT_FALSE(String::CaseInsensitiveWideCStringEquals(kNull, L"foobar")); @@ -1157,7 +1157,7 @@ class ScopedFakeTestPartResultReporterWithThreadsTest : public ScopedFakeTestPartResultReporterTest { protected: static void AddFailureInOtherThread(FailureMode failure) { - ThreadWithParam thread(&AddFailure, failure, NULL); + ThreadWithParam thread(&AddFailure, failure, nullptr); thread.Join(); } }; @@ -1578,7 +1578,7 @@ class GTestFlagSaverTest : public Test { // be called after the last test in this test case is run. static void TearDownTestCase() { delete saver_; - saver_ = NULL; + saver_ = nullptr; } // Verifies that the Google Test flags have their default values, and then @@ -1622,7 +1622,7 @@ class GTestFlagSaverTest : public Test { static GTestFlagSaver* saver_; }; -GTestFlagSaver* GTestFlagSaverTest::saver_ = NULL; +GTestFlagSaver* GTestFlagSaverTest::saver_ = nullptr; // Google Test doesn't guarantee the order of tests. The following two // tests are designed to work regardless of their order. @@ -1947,7 +1947,7 @@ TEST(ShouldRunTestOnShardTest, IsPartitionWhenThereAreFiveShards) { // TEST, TEST_F, RUN_ALL_TESTS TEST(UnitTestTest, CanGetOriginalWorkingDir) { - ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() != NULL); + ASSERT_TRUE(UnitTest::GetInstance()->original_working_dir() != nullptr); EXPECT_STRNE(UnitTest::GetInstance()->original_working_dir(), ""); } @@ -1969,7 +1969,7 @@ void ExpectNonFatalFailureRecordingPropertyWithReservedKey( void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest( const char* key) { const TestInfo* test_info = UnitTest::GetInstance()->current_test_info(); - ASSERT_TRUE(test_info != NULL); + ASSERT_TRUE(test_info != nullptr); ExpectNonFatalFailureRecordingPropertyWithReservedKey(*test_info->result(), key); } @@ -1977,7 +1977,7 @@ void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTest( void ExpectNonFatalFailureRecordingPropertyWithReservedKeyForCurrentTestCase( const char* key) { const TestCase* test_case = UnitTest::GetInstance()->current_test_case(); - ASSERT_TRUE(test_case != NULL); + ASSERT_TRUE(test_case != nullptr); ExpectNonFatalFailureRecordingPropertyWithReservedKey( test_case->ad_hoc_test_result(), key); } @@ -2010,7 +2010,7 @@ class UnitTestRecordPropertyTest : Test::RecordProperty("test_case_key_1", "1"); const TestCase* test_case = UnitTest::GetInstance()->current_test_case(); - ASSERT_TRUE(test_case != NULL); + ASSERT_TRUE(test_case != nullptr); ASSERT_EQ(1, test_case->ad_hoc_test_result().test_property_count()); EXPECT_STREQ("test_case_key_1", @@ -2454,24 +2454,22 @@ TEST(StringAssertionTest, ASSERT_STREQ) { // Tests ASSERT_STREQ with NULL arguments. TEST(StringAssertionTest, ASSERT_STREQ_Null) { - ASSERT_STREQ(static_cast(NULL), NULL); - EXPECT_FATAL_FAILURE(ASSERT_STREQ(NULL, "non-null"), - "non-null"); + ASSERT_STREQ(static_cast(nullptr), nullptr); + EXPECT_FATAL_FAILURE(ASSERT_STREQ(nullptr, "non-null"), "non-null"); } // Tests ASSERT_STREQ with NULL arguments. TEST(StringAssertionTest, ASSERT_STREQ_Null2) { - EXPECT_FATAL_FAILURE(ASSERT_STREQ("non-null", NULL), - "non-null"); + EXPECT_FATAL_FAILURE(ASSERT_STREQ("non-null", nullptr), "non-null"); } // Tests ASSERT_STRNE. TEST(StringAssertionTest, ASSERT_STRNE) { ASSERT_STRNE("hi", "Hi"); - ASSERT_STRNE("Hi", NULL); - ASSERT_STRNE(NULL, "Hi"); - ASSERT_STRNE("", NULL); - ASSERT_STRNE(NULL, ""); + ASSERT_STRNE("Hi", nullptr); + ASSERT_STRNE(nullptr, "Hi"); + ASSERT_STRNE("", nullptr); + ASSERT_STRNE(nullptr, ""); ASSERT_STRNE("", "Hi"); ASSERT_STRNE("Hi", ""); EXPECT_FATAL_FAILURE(ASSERT_STRNE("Hi", "Hi"), @@ -2481,7 +2479,7 @@ TEST(StringAssertionTest, ASSERT_STRNE) { // Tests ASSERT_STRCASEEQ. TEST(StringAssertionTest, ASSERT_STRCASEEQ) { ASSERT_STRCASEEQ("hi", "Hi"); - ASSERT_STRCASEEQ(static_cast(NULL), NULL); + ASSERT_STRCASEEQ(static_cast(nullptr), nullptr); ASSERT_STRCASEEQ("", ""); EXPECT_FATAL_FAILURE(ASSERT_STRCASEEQ("Hi", "hi2"), @@ -2491,10 +2489,10 @@ TEST(StringAssertionTest, ASSERT_STRCASEEQ) { // Tests ASSERT_STRCASENE. TEST(StringAssertionTest, ASSERT_STRCASENE) { ASSERT_STRCASENE("hi1", "Hi2"); - ASSERT_STRCASENE("Hi", NULL); - ASSERT_STRCASENE(NULL, "Hi"); - ASSERT_STRCASENE("", NULL); - ASSERT_STRCASENE(NULL, ""); + ASSERT_STRCASENE("Hi", nullptr); + ASSERT_STRCASENE(nullptr, "Hi"); + ASSERT_STRCASENE("", nullptr); + ASSERT_STRCASENE(nullptr, ""); ASSERT_STRCASENE("", "Hi"); ASSERT_STRCASENE("Hi", ""); EXPECT_FATAL_FAILURE(ASSERT_STRCASENE("Hi", "hi"), @@ -2504,14 +2502,13 @@ TEST(StringAssertionTest, ASSERT_STRCASENE) { // Tests *_STREQ on wide strings. TEST(StringAssertionTest, STREQ_Wide) { // NULL strings. - ASSERT_STREQ(static_cast(NULL), NULL); + ASSERT_STREQ(static_cast(nullptr), nullptr); // Empty strings. ASSERT_STREQ(L"", L""); // Non-null vs NULL. - EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"non-null", NULL), - "non-null"); + EXPECT_NONFATAL_FAILURE(EXPECT_STREQ(L"non-null", nullptr), "non-null"); // Equal strings. EXPECT_STREQ(L"Hi", L"Hi"); @@ -2533,16 +2530,18 @@ TEST(StringAssertionTest, STREQ_Wide) { // Tests *_STRNE on wide strings. TEST(StringAssertionTest, STRNE_Wide) { // NULL strings. - EXPECT_NONFATAL_FAILURE({ // NOLINT - EXPECT_STRNE(static_cast(NULL), NULL); - }, ""); + EXPECT_NONFATAL_FAILURE( + { // NOLINT + EXPECT_STRNE(static_cast(nullptr), nullptr); + }, + ""); // Empty strings. EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"", L""), "L\"\""); // Non-null vs NULL. - ASSERT_STRNE(L"non-null", NULL); + ASSERT_STRNE(L"non-null", nullptr); // Equal strings. EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"Hi", L"Hi"), @@ -2564,11 +2563,11 @@ TEST(StringAssertionTest, STRNE_Wide) { // Tests that IsSubstring() returns the correct result when the input // argument type is const char*. TEST(IsSubstringTest, ReturnsCorrectResultForCString) { - EXPECT_FALSE(IsSubstring("", "", NULL, "a")); - EXPECT_FALSE(IsSubstring("", "", "b", NULL)); + EXPECT_FALSE(IsSubstring("", "", nullptr, "a")); + EXPECT_FALSE(IsSubstring("", "", "b", nullptr)); EXPECT_FALSE(IsSubstring("", "", "needle", "haystack")); - EXPECT_TRUE(IsSubstring("", "", static_cast(NULL), NULL)); + EXPECT_TRUE(IsSubstring("", "", static_cast(nullptr), nullptr)); EXPECT_TRUE(IsSubstring("", "", "needle", "two needles")); } @@ -2579,7 +2578,8 @@ TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) { EXPECT_FALSE(IsSubstring("", "", L"b", kNull)); EXPECT_FALSE(IsSubstring("", "", L"needle", L"haystack")); - EXPECT_TRUE(IsSubstring("", "", static_cast(NULL), NULL)); + EXPECT_TRUE( + IsSubstring("", "", static_cast(nullptr), nullptr)); EXPECT_TRUE(IsSubstring("", "", L"needle", L"two needles")); } @@ -3714,17 +3714,16 @@ TEST(AssertionTest, ASSERT_EQ) { #if GTEST_CAN_COMPARE_NULL TEST(AssertionTest, ASSERT_EQ_NULL) { // A success. - const char* p = NULL; + const char* p = nullptr; // Some older GCC versions may issue a spurious warning in this or the next // assertion statement. This warning should not be suppressed with // static_cast since the test verifies the ability to use bare NULL as the // expected parameter to the macro. - ASSERT_EQ(NULL, p); + ASSERT_EQ(nullptr, p); // A failure. static int n = 0; - EXPECT_FATAL_FAILURE(ASSERT_EQ(NULL, &n), - " &n\n Which is:"); + EXPECT_FATAL_FAILURE(ASSERT_EQ(nullptr, &n), " &n\n Which is:"); } #endif // GTEST_CAN_COMPARE_NULL @@ -4330,10 +4329,12 @@ TEST(AssertionWithMessageTest, SUCCEED) { TEST(AssertionWithMessageTest, ASSERT_TRUE) { ASSERT_TRUE(true) << "This should succeed."; ASSERT_TRUE(true) << true; - EXPECT_FATAL_FAILURE({ // NOLINT - ASSERT_TRUE(false) << static_cast(NULL) - << static_cast(NULL); - }, "(null)(null)"); + EXPECT_FATAL_FAILURE( + { // NOLINT + ASSERT_TRUE(false) << static_cast(nullptr) + << static_cast(nullptr); + }, + "(null)(null)"); } #if GTEST_OS_WINDOWS @@ -4442,17 +4443,16 @@ TEST(ExpectTest, EXPECT_EQ_Double) { // Tests EXPECT_EQ(NULL, pointer). TEST(ExpectTest, EXPECT_EQ_NULL) { // A success. - const char* p = NULL; + const char* p = nullptr; // Some older GCC versions may issue a spurious warning in this or the next // assertion statement. This warning should not be suppressed with // static_cast since the test verifies the ability to use bare NULL as the // expected parameter to the macro. - EXPECT_EQ(NULL, p); + EXPECT_EQ(nullptr, p); // A failure. int n = 0; - EXPECT_NONFATAL_FAILURE(EXPECT_EQ(NULL, &n), - " &n\n Which is:"); + EXPECT_NONFATAL_FAILURE(EXPECT_EQ(nullptr, &n), " &n\n Which is:"); } #endif // GTEST_CAN_COMPARE_NULL @@ -4480,7 +4480,7 @@ TEST(ExpectTest, EXPECT_NE) { "actual: 'a' (97, 0x61) vs 'a' (97, 0x61)"); EXPECT_NONFATAL_FAILURE(EXPECT_NE(2, 2), "2"); - char* const p0 = NULL; + char* const p0 = nullptr; EXPECT_NONFATAL_FAILURE(EXPECT_NE(p0, p0), "p0"); // Only way to get the Nokia compiler to compile the cast @@ -4588,7 +4588,7 @@ TEST(StreamableToStringTest, Pointer) { // Tests using StreamableToString() on a NULL non-char pointer. TEST(StreamableToStringTest, NullPointer) { - int* p = NULL; + int* p = nullptr; EXPECT_STREQ("(null)", StreamableToString(p).c_str()); } @@ -4599,7 +4599,7 @@ TEST(StreamableToStringTest, CString) { // Tests using StreamableToString() on a NULL C string. TEST(StreamableToStringTest, NullCString) { - char* p = NULL; + char* p = nullptr; EXPECT_STREQ("(null)", StreamableToString(p).c_str()); } @@ -4644,8 +4644,7 @@ TEST(StreamableTest, int) { // implemented a workaround (substituting "(null)" for NULL). This // tests whether the workaround works. TEST(StreamableTest, NullCharPtr) { - EXPECT_FATAL_FAILURE(FAIL() << static_cast(NULL), - "(null)"); + EXPECT_FATAL_FAILURE(FAIL() << static_cast(nullptr), "(null)"); } // Tests that basic IO manipulators (endl, ends, and flush) can be @@ -4898,7 +4897,7 @@ TEST(EqAssertionTest, GlobalWideString) { // Tests using char pointers in {EXPECT|ASSERT}_EQ. TEST(EqAssertionTest, CharPointer) { - char* const p0 = NULL; + char* const p0 = nullptr; // Only way to get the Nokia compiler to compile the cast // is to have a separate void* variable first. Putting // the two casts on the same line doesn't work, neither does @@ -4920,7 +4919,7 @@ TEST(EqAssertionTest, CharPointer) { // Tests using wchar_t pointers in {EXPECT|ASSERT}_EQ. TEST(EqAssertionTest, WideCharPointer) { - wchar_t* const p0 = NULL; + wchar_t* const p0 = nullptr; // Only way to get the Nokia compiler to compile the cast // is to have a separate void* variable first. Putting // the two casts on the same line doesn't work, neither does @@ -4945,9 +4944,8 @@ TEST(EqAssertionTest, WideCharPointer) { // Tests using other types of pointers in {EXPECT|ASSERT}_EQ. TEST(EqAssertionTest, OtherPointer) { - ASSERT_EQ(static_cast(NULL), - static_cast(NULL)); - EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast(NULL), + ASSERT_EQ(static_cast(nullptr), static_cast(nullptr)); + EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast(nullptr), reinterpret_cast(0x1234)), "0x1234"); } @@ -5280,12 +5278,12 @@ TEST(MessageTest, CanStreamUserTypeInUserNameSpaceWithStreamOperatorInGlobal) { // Tests streaming NULL pointers to testing::Message. TEST(MessageTest, NullPointers) { Message msg; - char* const p1 = NULL; - unsigned char* const p2 = NULL; - int* p3 = NULL; - double* p4 = NULL; - bool* p5 = NULL; - Message* p6 = NULL; + char* const p1 = nullptr; + unsigned char* const p2 = nullptr; + int* p3 = nullptr; + double* p4 = nullptr; + bool* p5 = nullptr; + Message* p6 = nullptr; msg << p1 << p2 << p3 << p4 << p5 << p6; ASSERT_STREQ("(null)(null)(null)(null)(null)(null)", @@ -5295,12 +5293,12 @@ TEST(MessageTest, NullPointers) { // Tests streaming wide strings to testing::Message. TEST(MessageTest, WideStrings) { // Streams a NULL of type const wchar_t*. - const wchar_t* const_wstr = NULL; + const wchar_t* const_wstr = nullptr; EXPECT_STREQ("(null)", (Message() << const_wstr).GetString().c_str()); // Streams a NULL of type wchar_t*. - wchar_t* wstr = NULL; + wchar_t* wstr = nullptr; EXPECT_STREQ("(null)", (Message() << wstr).GetString().c_str()); @@ -5324,15 +5322,15 @@ namespace testing { class TestInfoTest : public Test { protected: static const TestInfo* GetTestInfo(const char* test_name) { - const TestCase* const test_case = GetUnitTestImpl()-> - GetTestCase("TestInfoTest", "", NULL, NULL); + const TestCase* const test_case = + GetUnitTestImpl()->GetTestCase("TestInfoTest", "", nullptr, nullptr); for (int i = 0; i < test_case->total_test_count(); ++i) { const TestInfo* const test_info = test_case->GetTestInfo(i); if (strcmp(test_name, test_info->name()) == 0) return test_info; } - return NULL; + return nullptr; } static const TestResult* GetTestResult( @@ -5446,7 +5444,7 @@ class SetUpTestCaseTest : public Test { EXPECT_EQ(0, counter_); // Cleans up the shared resource. - shared_resource_ = NULL; + shared_resource_ = nullptr; } // This will be called before each test in this test case. @@ -5464,12 +5462,10 @@ class SetUpTestCaseTest : public Test { }; int SetUpTestCaseTest::counter_ = 0; -const char* SetUpTestCaseTest::shared_resource_ = NULL; +const char* SetUpTestCaseTest::shared_resource_ = nullptr; // A test that uses the shared resource. -TEST_F(SetUpTestCaseTest, Test1) { - EXPECT_STRNE(NULL, shared_resource_); -} +TEST_F(SetUpTestCaseTest, Test1) { EXPECT_STRNE(nullptr, shared_resource_); } // Another test that uses the shared resource. TEST_F(SetUpTestCaseTest, Test2) { @@ -5737,141 +5733,81 @@ class ParseFlagsTest : public Test { // Tests parsing an empty command line. TEST_F(ParseFlagsTest, Empty) { - const char* argv[] = { - NULL - }; + const char* argv[] = {nullptr}; - const char* argv2[] = { - NULL - }; + const char* argv2[] = {nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false); } // Tests parsing a command line that has no flag. TEST_F(ParseFlagsTest, NoFlag) { - const char* argv[] = { - "foo.exe", - NULL - }; + const char* argv[] = {"foo.exe", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false); } // Tests parsing a bad --gtest_filter flag. TEST_F(ParseFlagsTest, FilterBad) { - const char* argv[] = { - "foo.exe", - "--gtest_filter", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_filter", nullptr}; - const char* argv2[] = { - "foo.exe", - "--gtest_filter", - NULL - }; + const char* argv2[] = {"foo.exe", "--gtest_filter", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true); } // Tests parsing an empty --gtest_filter flag. TEST_F(ParseFlagsTest, FilterEmpty) { - const char* argv[] = { - "foo.exe", - "--gtest_filter=", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_filter=", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), false); } // Tests parsing a non-empty --gtest_filter flag. TEST_F(ParseFlagsTest, FilterNonEmpty) { - const char* argv[] = { - "foo.exe", - "--gtest_filter=abc", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_filter=abc", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("abc"), false); } // Tests parsing --gtest_break_on_failure. TEST_F(ParseFlagsTest, BreakOnFailureWithoutValue) { - const char* argv[] = { - "foo.exe", - "--gtest_break_on_failure", - NULL -}; + const char* argv[] = {"foo.exe", "--gtest_break_on_failure", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(true), false); } // Tests parsing --gtest_break_on_failure=0. TEST_F(ParseFlagsTest, BreakOnFailureFalse_0) { - const char* argv[] = { - "foo.exe", - "--gtest_break_on_failure=0", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_break_on_failure=0", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(false), false); } // Tests parsing --gtest_break_on_failure=f. TEST_F(ParseFlagsTest, BreakOnFailureFalse_f) { - const char* argv[] = { - "foo.exe", - "--gtest_break_on_failure=f", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_break_on_failure=f", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(false), false); } // Tests parsing --gtest_break_on_failure=F. TEST_F(ParseFlagsTest, BreakOnFailureFalse_F) { - const char* argv[] = { - "foo.exe", - "--gtest_break_on_failure=F", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_break_on_failure=F", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(false), false); } @@ -5879,48 +5815,27 @@ TEST_F(ParseFlagsTest, BreakOnFailureFalse_F) { // Tests parsing a --gtest_break_on_failure flag that has a "true" // definition. TEST_F(ParseFlagsTest, BreakOnFailureTrue) { - const char* argv[] = { - "foo.exe", - "--gtest_break_on_failure=1", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_break_on_failure=1", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::BreakOnFailure(true), false); } // Tests parsing --gtest_catch_exceptions. TEST_F(ParseFlagsTest, CatchExceptions) { - const char* argv[] = { - "foo.exe", - "--gtest_catch_exceptions", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_catch_exceptions", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::CatchExceptions(true), false); } // Tests parsing --gtest_death_test_use_fork. TEST_F(ParseFlagsTest, DeathTestUseFork) { - const char* argv[] = { - "foo.exe", - "--gtest_death_test_use_fork", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_death_test_use_fork", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::DeathTestUseFork(true), false); } @@ -5928,36 +5843,21 @@ TEST_F(ParseFlagsTest, DeathTestUseFork) { // Tests having the same flag twice with different values. The // expected behavior is that the one coming last takes precedence. TEST_F(ParseFlagsTest, DuplicatedFlags) { - const char* argv[] = { - "foo.exe", - "--gtest_filter=a", - "--gtest_filter=b", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_filter=a", "--gtest_filter=b", + nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("b"), false); } // Tests having an unrecognized flag on the command line. TEST_F(ParseFlagsTest, UnrecognizedFlag) { - const char* argv[] = { - "foo.exe", - "--gtest_break_on_failure", - "bar", // Unrecognized by Google Test. - "--gtest_filter=b", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_break_on_failure", + "bar", // Unrecognized by Google Test. + "--gtest_filter=b", nullptr}; - const char* argv2[] = { - "foo.exe", - "bar", - NULL - }; + const char* argv2[] = {"foo.exe", "bar", nullptr}; Flags flags; flags.break_on_failure = true; @@ -5967,145 +5867,82 @@ TEST_F(ParseFlagsTest, UnrecognizedFlag) { // Tests having a --gtest_list_tests flag TEST_F(ParseFlagsTest, ListTestsFlag) { - const char* argv[] = { - "foo.exe", - "--gtest_list_tests", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_list_tests", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; - GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false); + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false); } // Tests having a --gtest_list_tests flag with a "true" value TEST_F(ParseFlagsTest, ListTestsTrue) { - const char* argv[] = { - "foo.exe", - "--gtest_list_tests=1", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_list_tests=1", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; - GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false); + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(true), false); } // Tests having a --gtest_list_tests flag with a "false" value TEST_F(ParseFlagsTest, ListTestsFalse) { - const char* argv[] = { - "foo.exe", - "--gtest_list_tests=0", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_list_tests=0", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; - GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false); + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false); } // Tests parsing --gtest_list_tests=f. TEST_F(ParseFlagsTest, ListTestsFalse_f) { - const char* argv[] = { - "foo.exe", - "--gtest_list_tests=f", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_list_tests=f", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false); } // Tests parsing --gtest_list_tests=F. TEST_F(ParseFlagsTest, ListTestsFalse_F) { - const char* argv[] = { - "foo.exe", - "--gtest_list_tests=F", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_list_tests=F", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ListTests(false), false); } // Tests parsing --gtest_output (invalid). TEST_F(ParseFlagsTest, OutputEmpty) { - const char* argv[] = { - "foo.exe", - "--gtest_output", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_output", nullptr}; - const char* argv2[] = { - "foo.exe", - "--gtest_output", - NULL - }; + const char* argv2[] = {"foo.exe", "--gtest_output", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true); } // Tests parsing --gtest_output=xml TEST_F(ParseFlagsTest, OutputXml) { - const char* argv[] = { - "foo.exe", - "--gtest_output=xml", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_output=xml", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Output("xml"), false); } // Tests parsing --gtest_output=xml:file TEST_F(ParseFlagsTest, OutputXmlFile) { - const char* argv[] = { - "foo.exe", - "--gtest_output=xml:file", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_output=xml:file", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Output("xml:file"), false); } // Tests parsing --gtest_output=xml:directory/path/ TEST_F(ParseFlagsTest, OutputXmlDirectory) { - const char* argv[] = { - "foo.exe", - "--gtest_output=xml:directory/path/", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_output=xml:directory/path/", + nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Output("xml:directory/path/"), false); @@ -6113,242 +5950,140 @@ TEST_F(ParseFlagsTest, OutputXmlDirectory) { // Tests having a --gtest_print_time flag TEST_F(ParseFlagsTest, PrintTimeFlag) { - const char* argv[] = { - "foo.exe", - "--gtest_print_time", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_print_time", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; - GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false); + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false); } // Tests having a --gtest_print_time flag with a "true" value TEST_F(ParseFlagsTest, PrintTimeTrue) { - const char* argv[] = { - "foo.exe", - "--gtest_print_time=1", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_print_time=1", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; - GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false); + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(true), false); } // Tests having a --gtest_print_time flag with a "false" value TEST_F(ParseFlagsTest, PrintTimeFalse) { - const char* argv[] = { - "foo.exe", - "--gtest_print_time=0", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_print_time=0", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; - GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false); + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false); } // Tests parsing --gtest_print_time=f. TEST_F(ParseFlagsTest, PrintTimeFalse_f) { - const char* argv[] = { - "foo.exe", - "--gtest_print_time=f", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_print_time=f", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false); } // Tests parsing --gtest_print_time=F. TEST_F(ParseFlagsTest, PrintTimeFalse_F) { - const char* argv[] = { - "foo.exe", - "--gtest_print_time=F", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_print_time=F", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::PrintTime(false), false); } // Tests parsing --gtest_random_seed=number TEST_F(ParseFlagsTest, RandomSeed) { - const char* argv[] = { - "foo.exe", - "--gtest_random_seed=1000", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_random_seed=1000", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::RandomSeed(1000), false); } // Tests parsing --gtest_repeat=number TEST_F(ParseFlagsTest, Repeat) { - const char* argv[] = { - "foo.exe", - "--gtest_repeat=1000", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_repeat=1000", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Repeat(1000), false); } // Tests having a --gtest_also_run_disabled_tests flag TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFlag) { - const char* argv[] = { - "foo.exe", - "--gtest_also_run_disabled_tests", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_also_run_disabled_tests", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; - GTEST_TEST_PARSING_FLAGS_(argv, argv2, - Flags::AlsoRunDisabledTests(true), false); + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::AlsoRunDisabledTests(true), + false); } // Tests having a --gtest_also_run_disabled_tests flag with a "true" value TEST_F(ParseFlagsTest, AlsoRunDisabledTestsTrue) { - const char* argv[] = { - "foo.exe", - "--gtest_also_run_disabled_tests=1", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_also_run_disabled_tests=1", + nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; - GTEST_TEST_PARSING_FLAGS_(argv, argv2, - Flags::AlsoRunDisabledTests(true), false); + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::AlsoRunDisabledTests(true), + false); } // Tests having a --gtest_also_run_disabled_tests flag with a "false" value TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFalse) { - const char* argv[] = { - "foo.exe", - "--gtest_also_run_disabled_tests=0", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_also_run_disabled_tests=0", + nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; - GTEST_TEST_PARSING_FLAGS_(argv, argv2, - Flags::AlsoRunDisabledTests(false), false); + GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::AlsoRunDisabledTests(false), + false); } // Tests parsing --gtest_shuffle. TEST_F(ParseFlagsTest, ShuffleWithoutValue) { - const char* argv[] = { - "foo.exe", - "--gtest_shuffle", - NULL -}; + const char* argv[] = {"foo.exe", "--gtest_shuffle", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(true), false); } // Tests parsing --gtest_shuffle=0. TEST_F(ParseFlagsTest, ShuffleFalse_0) { - const char* argv[] = { - "foo.exe", - "--gtest_shuffle=0", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_shuffle=0", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(false), false); } // Tests parsing a --gtest_shuffle flag that has a "true" definition. TEST_F(ParseFlagsTest, ShuffleTrue) { - const char* argv[] = { - "foo.exe", - "--gtest_shuffle=1", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_shuffle=1", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(true), false); } // Tests parsing --gtest_stack_trace_depth=number. TEST_F(ParseFlagsTest, StackTraceDepth) { - const char* argv[] = { - "foo.exe", - "--gtest_stack_trace_depth=5", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_stack_trace_depth=5", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::StackTraceDepth(5), false); } TEST_F(ParseFlagsTest, StreamResultTo) { - const char* argv[] = { - "foo.exe", - "--gtest_stream_result_to=localhost:1234", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_stream_result_to=localhost:1234", + nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_( argv, argv2, Flags::StreamResultTo("localhost:1234"), false); @@ -6356,32 +6091,18 @@ TEST_F(ParseFlagsTest, StreamResultTo) { // Tests parsing --gtest_throw_on_failure. TEST_F(ParseFlagsTest, ThrowOnFailureWithoutValue) { - const char* argv[] = { - "foo.exe", - "--gtest_throw_on_failure", - NULL -}; + const char* argv[] = {"foo.exe", "--gtest_throw_on_failure", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false); } // Tests parsing --gtest_throw_on_failure=0. TEST_F(ParseFlagsTest, ThrowOnFailureFalse_0) { - const char* argv[] = { - "foo.exe", - "--gtest_throw_on_failure=0", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_throw_on_failure=0", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(false), false); } @@ -6389,16 +6110,9 @@ TEST_F(ParseFlagsTest, ThrowOnFailureFalse_0) { // Tests parsing a --gtest_throw_on_failure flag that has a "true" // definition. TEST_F(ParseFlagsTest, ThrowOnFailureTrue) { - const char* argv[] = { - "foo.exe", - "--gtest_throw_on_failure=1", - NULL - }; + const char* argv[] = {"foo.exe", "--gtest_throw_on_failure=1", nullptr}; - const char* argv2[] = { - "foo.exe", - NULL - }; + const char* argv2[] = {"foo.exe", nullptr}; GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false); } @@ -6540,7 +6254,7 @@ class CurrentTestInfoTest : public Test { // There should be no tests running at this point. const TestInfo* test_info = UnitTest::GetInstance()->current_test_info(); - EXPECT_TRUE(test_info == NULL) + EXPECT_TRUE(test_info == nullptr) << "There should be no tests running at this point."; } @@ -6549,7 +6263,7 @@ class CurrentTestInfoTest : public Test { static void TearDownTestCase() { const TestInfo* test_info = UnitTest::GetInstance()->current_test_info(); - EXPECT_TRUE(test_info == NULL) + EXPECT_TRUE(test_info == nullptr) << "There should be no tests running at this point."; } }; @@ -6559,7 +6273,7 @@ class CurrentTestInfoTest : public Test { TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestCase) { const TestInfo* test_info = UnitTest::GetInstance()->current_test_info(); - ASSERT_TRUE(NULL != test_info) + ASSERT_TRUE(nullptr != test_info) << "There is a test running so we should have a valid TestInfo."; EXPECT_STREQ("CurrentTestInfoTest", test_info->test_case_name()) << "Expected the name of the currently running test case."; @@ -6574,7 +6288,7 @@ TEST_F(CurrentTestInfoTest, WorksForFirstTestInATestCase) { TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestCase) { const TestInfo* test_info = UnitTest::GetInstance()->current_test_info(); - ASSERT_TRUE(NULL != test_info) + ASSERT_TRUE(nullptr != test_info) << "There is a test running so we should have a valid TestInfo."; EXPECT_STREQ("CurrentTestInfoTest", test_info->test_case_name()) << "Expected the name of the currently running test case."; @@ -7001,7 +6715,7 @@ TEST(HasFailureTest, WorksOutsideOfTestBody2) { class TestListener : public EmptyTestEventListener { public: - TestListener() : on_start_counter_(NULL), is_destroyed_(NULL) {} + TestListener() : on_start_counter_(nullptr), is_destroyed_(nullptr) {} TestListener(int* on_start_counter, bool* is_destroyed) : on_start_counter_(on_start_counter), is_destroyed_(is_destroyed) {} @@ -7013,8 +6727,7 @@ class TestListener : public EmptyTestEventListener { protected: virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) { - if (on_start_counter_ != NULL) - (*on_start_counter_)++; + if (on_start_counter_ != nullptr) (*on_start_counter_)++; } private: @@ -7026,9 +6739,9 @@ class TestListener : public EmptyTestEventListener { TEST(TestEventListenersTest, ConstructionWorks) { TestEventListeners listeners; - EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) != NULL); - EXPECT_TRUE(listeners.default_result_printer() == NULL); - EXPECT_TRUE(listeners.default_xml_generator() == NULL); + EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) != nullptr); + EXPECT_TRUE(listeners.default_result_printer() == nullptr); + EXPECT_TRUE(listeners.default_xml_generator() == nullptr); } // Tests that the TestEventListeners destructor deletes all the listeners it @@ -7037,12 +6750,12 @@ TEST(TestEventListenersTest, DestructionWorks) { bool default_result_printer_is_destroyed = false; bool default_xml_printer_is_destroyed = false; bool extra_listener_is_destroyed = false; - TestListener* default_result_printer = new TestListener( - NULL, &default_result_printer_is_destroyed); - TestListener* default_xml_printer = new TestListener( - NULL, &default_xml_printer_is_destroyed); - TestListener* extra_listener = new TestListener( - NULL, &extra_listener_is_destroyed); + TestListener* default_result_printer = + new TestListener(nullptr, &default_result_printer_is_destroyed); + TestListener* default_xml_printer = + new TestListener(nullptr, &default_xml_printer_is_destroyed); + TestListener* extra_listener = + new TestListener(nullptr, &extra_listener_is_destroyed); { TestEventListeners listeners; @@ -7167,7 +6880,7 @@ TEST(TestEventListenersTest, Release) { EXPECT_EQ(listener, listeners.Release(listener)); TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart( *UnitTest::GetInstance()); - EXPECT_TRUE(listeners.Release(listener) == NULL); + EXPECT_TRUE(listeners.Release(listener) == nullptr); } EXPECT_EQ(0, on_start_counter); EXPECT_FALSE(is_destroyed); @@ -7177,7 +6890,7 @@ TEST(TestEventListenersTest, Release) { // Tests that no events are forwarded when event forwarding is disabled. TEST(EventListenerTest, SuppressEventForwarding) { int on_start_counter = 0; - TestListener* listener = new TestListener(&on_start_counter, NULL); + TestListener* listener = new TestListener(&on_start_counter, nullptr); TestEventListeners listeners; listeners.Append(listener); @@ -7218,9 +6931,9 @@ TEST(EventListenerTest, default_result_printer) { // Replacing default_result_printer with something else should remove it // from the list and destroy it. - TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, NULL); + TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, nullptr); - EXPECT_TRUE(listeners.default_result_printer() == NULL); + EXPECT_TRUE(listeners.default_result_printer() == nullptr); EXPECT_TRUE(is_destroyed); // After broadcasting an event the counter is still the same, indicating @@ -7244,7 +6957,7 @@ TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) { TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener); EXPECT_EQ(listener, listeners.Release(listener)); - EXPECT_TRUE(listeners.default_result_printer() == NULL); + EXPECT_TRUE(listeners.default_result_printer() == nullptr); EXPECT_FALSE(is_destroyed); // Broadcasting events now should not affect default_result_printer. @@ -7277,9 +6990,9 @@ TEST(EventListenerTest, default_xml_generator) { // Replacing default_xml_generator with something else should remove it // from the list and destroy it. - TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, NULL); + TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, nullptr); - EXPECT_TRUE(listeners.default_xml_generator() == NULL); + EXPECT_TRUE(listeners.default_xml_generator() == nullptr); EXPECT_TRUE(is_destroyed); // After broadcasting an event the counter is still the same, indicating @@ -7303,7 +7016,7 @@ TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) { TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener); EXPECT_EQ(listener, listeners.Release(listener)); - EXPECT_TRUE(listeners.default_xml_generator() == NULL); + EXPECT_TRUE(listeners.default_xml_generator() == nullptr); EXPECT_FALSE(is_destroyed); // Broadcasting events now should not affect default_xml_generator. -- cgit v0.12