Merge pull request #1941 from barkovv:master

PiperOrigin-RevId: 219134349
This commit is contained in:
Gennadiy Civil 2018-10-29 13:46:24 -04:00
commit e9085769d4
15 changed files with 157 additions and 185 deletions

View File

@ -1905,7 +1905,8 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// failure to disambiguate two overloads of this method in the ON_CALL statement // failure to disambiguate two overloads of this method in the ON_CALL statement
// is how we block callers from setting expectations on overloaded methods. // is how we block callers from setting expectations on overloaded methods.
#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \ #define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \
((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), NULL) \ ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \
nullptr) \
.Setter(__FILE__, __LINE__, #mock_expr, #call) .Setter(__FILE__, __LINE__, #mock_expr, #call)
#define ON_CALL(obj, call) \ #define ON_CALL(obj, call) \

View File

@ -867,7 +867,7 @@ void Sequence::AddExpectation(const Expectation& expectation) const {
// Creates the implicit sequence if there isn't one. // Creates the implicit sequence if there isn't one.
InSequence::InSequence() { InSequence::InSequence() {
if (internal::g_gmock_implicit_sequence.get() == NULL) { if (internal::g_gmock_implicit_sequence.get() == nullptr) {
internal::g_gmock_implicit_sequence.set(new Sequence); internal::g_gmock_implicit_sequence.set(new Sequence);
sequence_created_ = true; sequence_created_ = true;
} else { } else {
@ -880,7 +880,7 @@ InSequence::InSequence() {
InSequence::~InSequence() { InSequence::~InSequence() {
if (sequence_created_) { if (sequence_created_) {
delete internal::g_gmock_implicit_sequence.get(); delete internal::g_gmock_implicit_sequence.get();
internal::g_gmock_implicit_sequence.set(NULL); internal::g_gmock_implicit_sequence.set(nullptr);
} }
} }

View File

@ -224,8 +224,8 @@ TEST_F(FunctionMockerTest, MocksBinaryFunction) {
// Tests mocking a decimal function. // Tests mocking a decimal function.
TEST_F(FunctionMockerTest, MocksDecimalFunction) { TEST_F(FunctionMockerTest, MocksDecimalFunction) {
EXPECT_CALL(mock_foo_, Decimal(true, 'a', 0, 0, 1L, A<float>(), EXPECT_CALL(mock_foo_, Decimal(true, 'a', 0, 0, 1L, A<float>(), Lt(100), 5U,
Lt(100), 5U, NULL, "hi")) nullptr, "hi"))
.WillOnce(Return(5)); .WillOnce(Return(5));
EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi")); EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
@ -326,11 +326,11 @@ TEST_F(FunctionMockerTest, MocksUnaryFunctionWithCallType) {
// Tests mocking a decimal function with calltype. // Tests mocking a decimal function with calltype.
TEST_F(FunctionMockerTest, MocksDecimalFunctionWithCallType) { TEST_F(FunctionMockerTest, MocksDecimalFunctionWithCallType) {
EXPECT_CALL(mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(), EXPECT_CALL(mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(), Lt(100), 5U,
Lt(100), 5U, NULL, "hi")) nullptr, "hi"))
.WillOnce(Return(10)); .WillOnce(Return(10));
EXPECT_EQ(10, foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, NULL, "hi")); EXPECT_EQ(10, foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
} }
// Tests mocking functions overloaded on the const-ness of this object. // Tests mocking functions overloaded on the const-ness of this object.

View File

@ -321,7 +321,7 @@ TEST(MatcherTest, CanBeImplicitlyConstructedFromValue) {
// Tests that NULL can be used in place of Eq(NULL). // Tests that NULL can be used in place of Eq(NULL).
TEST(MatcherTest, CanBeImplicitlyConstructedFromNULL) { TEST(MatcherTest, CanBeImplicitlyConstructedFromNULL) {
Matcher<int*> m1 = NULL; Matcher<int*> m1 = nullptr;
EXPECT_TRUE(m1.Matches(nullptr)); EXPECT_TRUE(m1.Matches(nullptr));
int n = 0; int n = 0;
EXPECT_FALSE(m1.Matches(&n)); EXPECT_FALSE(m1.Matches(&n));
@ -4759,8 +4759,8 @@ TEST(IsTrueTest, IsTrueIsFalse) {
EXPECT_THAT(false, Not(IsTrue())); EXPECT_THAT(false, Not(IsTrue()));
EXPECT_THAT(0, Not(IsTrue())); EXPECT_THAT(0, Not(IsTrue()));
EXPECT_THAT(0, IsFalse()); EXPECT_THAT(0, IsFalse());
EXPECT_THAT(NULL, Not(IsTrue())); EXPECT_THAT(nullptr, Not(IsTrue()));
EXPECT_THAT(NULL, IsFalse()); EXPECT_THAT(nullptr, IsFalse());
EXPECT_THAT(-1, IsTrue()); EXPECT_THAT(-1, IsTrue());
EXPECT_THAT(-1, Not(IsFalse())); EXPECT_THAT(-1, Not(IsFalse()));
EXPECT_THAT(1, IsTrue()); EXPECT_THAT(1, IsTrue());

View File

@ -414,7 +414,7 @@ TEST(LinkTest, TestThrow) {
Mock mock; Mock mock;
EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42)); EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
EXPECT_THROW(mock.VoidFromString(NULL), int); EXPECT_THROW(mock.VoidFromString(nullptr), int);
} }
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS

View File

@ -207,7 +207,7 @@ class GTEST_API_ Message {
// tr1::type_traits-like is_pointer works, and we can overload on that. // tr1::type_traits-like is_pointer works, and we can overload on that.
template <typename T> template <typename T>
inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) { inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) {
if (pointer == NULL) { if (pointer == nullptr) {
*ss_ << "(null)"; *ss_ << "(null)";
} else { } else {
*ss_ << pointer; *ss_ << pointer;

View File

@ -186,16 +186,16 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*, // This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
// ASSERT_EXIT*, and EXPECT_EXIT*. // ASSERT_EXIT*, and EXPECT_EXIT*.
# define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ #define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::AlwaysTrue()) { \ if (::testing::internal::AlwaysTrue()) { \
const ::testing::internal::RE& gtest_regex = (regex); \ const ::testing::internal::RE& gtest_regex = (regex); \
::testing::internal::DeathTest* gtest_dt; \ ::testing::internal::DeathTest* gtest_dt; \
if (!::testing::internal::DeathTest::Create(#statement, &gtest_regex, \ if (!::testing::internal::DeathTest::Create( \
__FILE__, __LINE__, &gtest_dt)) { \ #statement, &gtest_regex, __FILE__, __LINE__, &gtest_dt)) { \
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
} \ } \
if (gtest_dt != NULL) { \ if (gtest_dt != nullptr) { \
::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \ ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \
gtest_dt_ptr(gtest_dt); \ gtest_dt_ptr(gtest_dt); \
switch (gtest_dt->AssumeRole()) { \ switch (gtest_dt->AssumeRole()) { \
@ -205,8 +205,8 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
} \ } \
break; \ break; \
case ::testing::internal::DeathTest::EXECUTE_TEST: { \ case ::testing::internal::DeathTest::EXECUTE_TEST: { \
::testing::internal::DeathTest::ReturnSentinel \ ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \
gtest_sentinel(gtest_dt); \ gtest_dt); \
GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
break; \ break; \
@ -216,8 +216,8 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
} \ } \
} \ } \
} else \ } else \
GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \ GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__) \
fail(::testing::internal::DeathTest::LastMessage()) : fail(::testing::internal::DeathTest::LastMessage())
// The symbol "fail" here expands to something into which a message // The symbol "fail" here expands to something into which a message
// can be streamed. // can be streamed.

View File

@ -1400,27 +1400,27 @@ class FlatTuple
test_case_name##_##test_name##_Test test_case_name##_##test_name##_Test
// Helper macro for defining tests. // Helper macro for defining tests.
#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\ #define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id) \
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
public:\ : public parent_class { \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ public: \
private:\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
virtual void TestBody();\ \
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\ private: \
GTEST_DISALLOW_COPY_AND_ASSIGN_(\ virtual void TestBody(); \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
};\ GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_case_name, \
\ test_name)); \
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\ }; \
::test_info_ =\ \
::testing::internal::MakeAndRegisterTestInfo(\ ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, \
#test_case_name, #test_name, NULL, NULL, \ test_name)::test_info_ = \
::testing::internal::CodeLocation(__FILE__, __LINE__), \ ::testing::internal::MakeAndRegisterTestInfo( \
(parent_id), \ #test_case_name, #test_name, nullptr, nullptr, \
parent_class::SetUpTestCase, \ ::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \
parent_class::TearDownTestCase, \ parent_class::SetUpTestCase, parent_class::TearDownTestCase, \
new ::testing::internal::TestFactoryImpl<\ new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ test_case_name, test_name)>); \
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_

View File

@ -1305,13 +1305,13 @@ inline To DownCast_(From* f) { // so we only accept pointers
GTEST_INTENTIONAL_CONST_COND_PUSH_() GTEST_INTENTIONAL_CONST_COND_PUSH_()
if (false) { if (false) {
GTEST_INTENTIONAL_CONST_COND_POP_() GTEST_INTENTIONAL_CONST_COND_POP_()
const To to = NULL; const To to = nullptr;
::testing::internal::ImplicitCast_<From*>(to); ::testing::internal::ImplicitCast_<From*>(to);
} }
#if GTEST_HAS_RTTI #if GTEST_HAS_RTTI
// RTTI: debug mode only! // RTTI: debug mode only!
GTEST_CHECK_(f == nullptr || dynamic_cast<To>(f) != NULL); GTEST_CHECK_(f == nullptr || dynamic_cast<To>(f) != nullptr);
#endif #endif
return static_cast<To>(f); return static_cast<To>(f);
} }
@ -2334,12 +2334,12 @@ inline const char* GetEnv(const char* name) {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
// We are on Windows CE, which has no environment variables. // We are on Windows CE, which has no environment variables.
static_cast<void>(name); // To prevent 'unused argument' warning. static_cast<void>(name); // To prevent 'unused argument' warning.
return NULL; return nullptr;
#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
// Environment variables which we programmatically clear will be set to the // Environment variables which we programmatically clear will be set to the
// empty string rather than unset (NULL). Handle that case. // empty string rather than unset (NULL). Handle that case.
const char* const env = getenv(name); const char* const env = getenv(name);
return (env != NULL && env[0] != '\0') ? env : NULL; return (env != nullptr && env[0] != '\0') ? env : nullptr;
#else #else
return getenv(name); return getenv(name);
#endif #endif

View File

@ -731,7 +731,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
const TestInfo* const info = impl->current_test_info(); const TestInfo* const info = impl->current_test_info();
const int death_test_index = info->result()->death_test_count(); const int death_test_index = info->result()->death_test_count();
if (flag != NULL) { if (flag != nullptr) {
// ParseInternalRunDeathTestFlag() has performed all the necessary // ParseInternalRunDeathTestFlag() has performed all the necessary
// processing. // processing.
set_write_fd(flag->write_fd()); set_write_fd(flag->write_fd());
@ -740,8 +740,8 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
// WindowsDeathTest uses an anonymous pipe to communicate results of // WindowsDeathTest uses an anonymous pipe to communicate results of
// a death test. // a death test.
SECURITY_ATTRIBUTES handles_are_inheritable = { SECURITY_ATTRIBUTES handles_are_inheritable = {sizeof(SECURITY_ATTRIBUTES),
sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; nullptr, TRUE};
HANDLE read_handle, write_handle; HANDLE read_handle, write_handle;
GTEST_DEATH_TEST_CHECK_( GTEST_DEATH_TEST_CHECK_(
::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable, ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable,
@ -754,8 +754,8 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
&handles_are_inheritable, &handles_are_inheritable,
TRUE, // The event will automatically reset to non-signaled state. TRUE, // The event will automatically reset to non-signaled state.
FALSE, // The initial state is non-signalled. FALSE, // The initial state is non-signalled.
NULL)); // The even is unnamed. nullptr)); // The even is unnamed.
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL); GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != nullptr);
const std::string filter_flag = const std::string filter_flag =
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" + std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" +
info->test_case_name() + "." + info->name(); info->test_case_name() + "." + info->name();
@ -771,8 +771,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
"|" + StreamableToString(reinterpret_cast<size_t>(event_handle_.Get())); "|" + StreamableToString(reinterpret_cast<size_t>(event_handle_.Get()));
char executable_path[_MAX_PATH + 1]; // NOLINT char executable_path[_MAX_PATH + 1]; // NOLINT
GTEST_DEATH_TEST_CHECK_( GTEST_DEATH_TEST_CHECK_(_MAX_PATH + 1 != ::GetModuleFileNameA(nullptr,
_MAX_PATH + 1 != ::GetModuleFileNameA(NULL,
executable_path, executable_path,
_MAX_PATH)); _MAX_PATH));
@ -795,16 +794,15 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE); startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE);
PROCESS_INFORMATION process_info; PROCESS_INFORMATION process_info;
GTEST_DEATH_TEST_CHECK_(::CreateProcessA( GTEST_DEATH_TEST_CHECK_(
executable_path, ::CreateProcessA(
const_cast<char*>(command_line.c_str()), executable_path, const_cast<char*>(command_line.c_str()),
NULL, // Retuned process handle is not inheritable. nullptr, // Retuned process handle is not inheritable.
NULL, // Retuned thread handle is not inheritable. nullptr, // Retuned thread handle is not inheritable.
TRUE, // Child inherits all inheritable handles (for write_handle_). TRUE, // Child inherits all inheritable handles (for write_handle_).
0x0, // Default creation flags. 0x0, // Default creation flags.
NULL, // Inherit the parent's environment. nullptr, // Inherit the parent's environment.
UnitTest::GetInstance()->original_working_dir(), UnitTest::GetInstance()->original_working_dir(), &startup_info,
&startup_info,
&process_info) != FALSE); &process_info) != FALSE);
child_handle_.Reset(process_info.hProcess); child_handle_.Reset(process_info.hProcess);
::CloseHandle(process_info.hThread); ::CloseHandle(process_info.hThread);
@ -842,9 +840,7 @@ class FuchsiaDeathTest : public DeathTestImpl {
// Utility class for accumulating command-line arguments. // Utility class for accumulating command-line arguments.
class Arguments { class Arguments {
public: public:
Arguments() { Arguments() { args_.push_back(nullptr); }
args_.push_back(NULL);
}
~Arguments() { ~Arguments() {
for (std::vector<char*>::iterator i = args_.begin(); i != args_.end(); for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
@ -967,7 +963,7 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
const TestInfo* const info = impl->current_test_info(); const TestInfo* const info = impl->current_test_info();
const int death_test_index = info->result()->death_test_count(); const int death_test_index = info->result()->death_test_count();
if (flag != NULL) { if (flag != nullptr) {
// ParseInternalRunDeathTestFlag() has performed all the necessary // ParseInternalRunDeathTestFlag() has performed all the necessary
// processing. // processing.
set_write_fd(kFuchsiaReadPipeFd); set_write_fd(kFuchsiaReadPipeFd);
@ -1316,7 +1312,8 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
fd_flags | FD_CLOEXEC)); fd_flags | FD_CLOEXEC));
struct inheritance inherit = {0}; struct inheritance inherit = {0};
// spawn is a system call. // spawn is a system call.
child_pid = spawn(args.argv[0], 0, NULL, &inherit, args.argv, GetEnviron()); child_pid =
spawn(args.argv[0], 0, nullptr, &inherit, args.argv, GetEnviron());
// Restores the current working directory. // Restores the current working directory.
GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1); GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1);
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd)); GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));

View File

@ -101,7 +101,7 @@ FilePath FilePath::GetCurrentDir() {
return FilePath(kCurrentDirectoryString); return FilePath(kCurrentDirectoryString);
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd); return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd);
#else #else
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
char* result = getcwd(cwd, sizeof(cwd)); char* result = getcwd(cwd, sizeof(cwd));
@ -109,7 +109,7 @@ FilePath FilePath::GetCurrentDir() {
// getcwd will likely fail in NaCl due to the sandbox, so return something // getcwd will likely fail in NaCl due to the sandbox, so return something
// reasonable. The user may have provided a shim implementation for getcwd, // reasonable. The user may have provided a shim implementation for getcwd,
// however, so fallback only when failure is detected. // however, so fallback only when failure is detected.
return FilePath(result == NULL ? kCurrentDirectoryString : cwd); return FilePath(result == nullptr ? kCurrentDirectoryString : cwd);
# endif // GTEST_OS_NACL # endif // GTEST_OS_NACL
return FilePath(result == nullptr ? "" : cwd); return FilePath(result == nullptr ? "" : cwd);
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
@ -136,8 +136,8 @@ const char* FilePath::FindLastPathSeparator() const {
#if GTEST_HAS_ALT_PATH_SEP_ #if GTEST_HAS_ALT_PATH_SEP_
const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator); const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator);
// Comparing two pointers of which only one is NULL is undefined. // Comparing two pointers of which only one is NULL is undefined.
if (last_alt_sep != NULL && if (last_alt_sep != nullptr &&
(last_sep == NULL || last_alt_sep > last_sep)) { (last_sep == nullptr || last_alt_sep > last_sep)) {
return last_alt_sep; return last_alt_sep;
} }
#endif #endif
@ -324,7 +324,7 @@ bool FilePath::CreateFolder() const {
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
FilePath removed_sep(this->RemoveTrailingPathSeparator()); FilePath removed_sep(this->RemoveTrailingPathSeparator());
LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
int result = CreateDirectory(unicode, NULL) ? 0 : -1; int result = CreateDirectory(unicode, nullptr) ? 0 : -1;
delete [] unicode; delete [] unicode;
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
int result = _mkdir(pathname_.c_str()); int result = _mkdir(pathname_.c_str());

View File

@ -142,7 +142,7 @@ size_t GetThreadCount() {
} }
procfs_info process_info; procfs_info process_info;
const int status = const int status =
devctl(fd, DCMD_PROC_INFO, &process_info, sizeof(process_info), NULL); devctl(fd, DCMD_PROC_INFO, &process_info, sizeof(process_info), nullptr);
close(fd); close(fd);
if (status == EOK) { if (status == EOK) {
return static_cast<size_t>(process_info.num_threads); return static_cast<size_t>(process_info.num_threads);
@ -156,7 +156,7 @@ size_t GetThreadCount() {
size_t GetThreadCount() { size_t GetThreadCount() {
struct procentry64 entry; struct procentry64 entry;
pid_t pid = getpid(); pid_t pid = getpid();
int status = getprocs64(&entry, sizeof(entry), NULL, 0, &pid, 1); int status = getprocs64(&entry, sizeof(entry), nullptr, 0, &pid, 1);
if (status == 1) { if (status == 1) {
return entry.pi_thcount; return entry.pi_thcount;
} else { } else {
@ -234,15 +234,15 @@ void AutoHandle::Reset(HANDLE handle) {
bool AutoHandle::IsCloseable() const { bool AutoHandle::IsCloseable() const {
// Different Windows APIs may use either of these values to represent an // Different Windows APIs may use either of these values to represent an
// invalid handle. // invalid handle.
return handle_ != NULL && handle_ != INVALID_HANDLE_VALUE; return handle_ != nullptr && handle_ != INVALID_HANDLE_VALUE;
} }
Notification::Notification() Notification::Notification()
: event_(::CreateEvent(NULL, // Default security attributes. : event_(::CreateEvent(nullptr, // Default security attributes.
TRUE, // Do not reset automatically. TRUE, // Do not reset automatically.
FALSE, // Initially unset. FALSE, // Initially unset.
NULL)) { // Anonymous event. nullptr)) { // Anonymous event.
GTEST_CHECK_(event_.Get() != NULL); GTEST_CHECK_(event_.Get() != nullptr);
} }
void Notification::Notify() { void Notification::Notify() {
@ -271,7 +271,7 @@ Mutex::~Mutex() {
if (type_ == kDynamic) { if (type_ == kDynamic) {
::DeleteCriticalSection(critical_section_); ::DeleteCriticalSection(critical_section_);
delete critical_section_; delete critical_section_;
critical_section_ = NULL; critical_section_ = nullptr;
} }
} }
@ -390,15 +390,15 @@ class ThreadWithParamSupport : public ThreadWithParamBase {
DWORD thread_id; DWORD thread_id;
// FIXME: Consider to use _beginthreadex instead. // FIXME: Consider to use _beginthreadex instead.
HANDLE thread_handle = ::CreateThread( HANDLE thread_handle = ::CreateThread(
NULL, // Default security. nullptr, // Default security.
0, // Default stack size. 0, // Default stack size.
&ThreadWithParamSupport::ThreadMain, &ThreadWithParamSupport::ThreadMain,
param, // Parameter to ThreadMainStatic param, // Parameter to ThreadMainStatic
0x0, // Default creation flags. 0x0, // Default creation flags.
&thread_id); // Need a valid pointer for the call to work under Win98. &thread_id); // Need a valid pointer for the call to work under Win98.
GTEST_CHECK_(thread_handle != NULL) << "CreateThread failed with error " GTEST_CHECK_(thread_handle != nullptr)
<< ::GetLastError() << "."; << "CreateThread failed with error " << ::GetLastError() << ".";
if (thread_handle == NULL) { if (thread_handle == nullptr) {
delete param; delete param;
} }
return thread_handle; return thread_handle;
@ -418,7 +418,7 @@ class ThreadWithParamSupport : public ThreadWithParamBase {
static DWORD WINAPI ThreadMain(void* ptr) { static DWORD WINAPI ThreadMain(void* ptr) {
// Transfers ownership. // Transfers ownership.
scoped_ptr<ThreadMainParam> param(static_cast<ThreadMainParam*>(ptr)); scoped_ptr<ThreadMainParam> param(static_cast<ThreadMainParam*>(ptr));
if (param->thread_can_start_ != NULL) if (param->thread_can_start_ != nullptr)
param->thread_can_start_->WaitForNotification(); param->thread_can_start_->WaitForNotification();
param->runnable_->Run(); param->runnable_->Run();
return 0; return 0;
@ -556,18 +556,17 @@ class ThreadLocalRegistryImpl {
HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION, HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,
FALSE, FALSE,
thread_id); thread_id);
GTEST_CHECK_(thread != NULL); GTEST_CHECK_(thread != nullptr);
// We need to pass a valid thread ID pointer into CreateThread for it // We need to pass a valid thread ID pointer into CreateThread for it
// to work correctly under Win98. // to work correctly under Win98.
DWORD watcher_thread_id; DWORD watcher_thread_id;
HANDLE watcher_thread = ::CreateThread( HANDLE watcher_thread = ::CreateThread(
NULL, // Default security. nullptr, // Default security.
0, // Default stack size 0, // Default stack size
&ThreadLocalRegistryImpl::WatcherThreadFunc, &ThreadLocalRegistryImpl::WatcherThreadFunc,
reinterpret_cast<LPVOID>(new ThreadIdAndHandle(thread_id, thread)), reinterpret_cast<LPVOID>(new ThreadIdAndHandle(thread_id, thread)),
CREATE_SUSPENDED, CREATE_SUSPENDED, &watcher_thread_id);
&watcher_thread_id); GTEST_CHECK_(watcher_thread != nullptr);
GTEST_CHECK_(watcher_thread != NULL);
// Give the watcher thread the same priority as ours to avoid being // Give the watcher thread the same priority as ours to avoid being
// blocked by it. // blocked by it.
::SetThreadPriority(watcher_thread, ::SetThreadPriority(watcher_thread,
@ -687,7 +686,7 @@ void RE::Init(const char* regex) {
// Returns true iff ch appears anywhere in str (excluding the // Returns true iff ch appears anywhere in str (excluding the
// terminating '\0' character). // terminating '\0' character).
bool IsInSet(char ch, const char* str) { bool IsInSet(char ch, const char* str) {
return ch != '\0' && strchr(str, ch) != NULL; return ch != '\0' && strchr(str, ch) != nullptr;
} }
// Returns true iff ch belongs to the given classification. Unlike // Returns true iff ch belongs to the given classification. Unlike
@ -741,7 +740,7 @@ static std::string FormatRegexSyntaxError(const char* regex, int index) {
// Generates non-fatal failures and returns false if regex is invalid; // Generates non-fatal failures and returns false if regex is invalid;
// otherwise returns true. // otherwise returns true.
bool ValidateRegex(const char* regex) { bool ValidateRegex(const char* regex) {
if (regex == NULL) { if (regex == nullptr) {
// FIXME: fix the source file location in the // FIXME: fix the source file location in the
// assertion failures to match where the regex is used in user // assertion failures to match where the regex is used in user
// code. // code.
@ -867,8 +866,7 @@ bool MatchRegexAtHead(const char* regex, const char* str) {
// exponential with respect to the regex length + the string length, // exponential with respect to the regex length + the string length,
// but usually it's must faster (often close to linear). // but usually it's must faster (often close to linear).
bool MatchRegexAnywhere(const char* regex, const char* str) { bool MatchRegexAnywhere(const char* regex, const char* str) {
if (regex == NULL || str == NULL) if (regex == nullptr || str == nullptr) return false;
return false;
if (*regex == '^') if (*regex == '^')
return MatchRegexAtHead(regex + 1, str); return MatchRegexAtHead(regex + 1, str);
@ -901,8 +899,8 @@ bool RE::PartialMatch(const char* str, const RE& re) {
// Initializes an RE from its string representation. // Initializes an RE from its string representation.
void RE::Init(const char* regex) { void RE::Init(const char* regex) {
pattern_ = full_pattern_ = NULL; pattern_ = full_pattern_ = nullptr;
if (regex != NULL) { if (regex != nullptr) {
pattern_ = posix::StrDup(regex); pattern_ = posix::StrDup(regex);
} }
@ -1259,8 +1257,8 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
#else #else
const std::string env_var = FlagToEnvVar(flag); const std::string env_var = FlagToEnvVar(flag);
const char* const string_value = posix::GetEnv(env_var.c_str()); const char* const string_value = posix::GetEnv(env_var.c_str());
return string_value == NULL ? return string_value == nullptr ? default_value
default_value : strcmp(string_value, "0") != 0; : strcmp(string_value, "0") != 0;
#endif // defined(GTEST_GET_BOOL_FROM_ENV_) #endif // defined(GTEST_GET_BOOL_FROM_ENV_)
} }
@ -1273,7 +1271,7 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
#else #else
const std::string env_var = FlagToEnvVar(flag); const std::string env_var = FlagToEnvVar(flag);
const char* const string_value = posix::GetEnv(env_var.c_str()); const char* const string_value = posix::GetEnv(env_var.c_str());
if (string_value == NULL) { if (string_value == nullptr) {
// The environment variable is not set. // The environment variable is not set.
return default_value; return default_value;
} }
@ -1316,7 +1314,7 @@ const char* StringFromGTestEnv(const char* flag, const char* default_value) {
#else #else
const std::string env_var = FlagToEnvVar(flag); const std::string env_var = FlagToEnvVar(flag);
const char* const value = posix::GetEnv(env_var.c_str()); const char* const value = posix::GetEnv(env_var.c_str());
return value == NULL ? default_value : value; return value == nullptr ? default_value : value;
#endif // defined(GTEST_GET_STRING_FROM_ENV_) #endif // defined(GTEST_GET_STRING_FROM_ENV_)
} }

View File

@ -902,11 +902,10 @@ TimeInMillis GetTimeInMillis() {
// value using delete[]. Returns the wide string, or NULL if the // value using delete[]. Returns the wide string, or NULL if the
// input is NULL. // input is NULL.
LPCWSTR String::AnsiToUtf16(const char* ansi) { LPCWSTR String::AnsiToUtf16(const char* ansi) {
if (!ansi) return NULL; if (!ansi) return nullptr;
const int length = strlen(ansi); const int length = strlen(ansi);
const int unicode_length = const int unicode_length =
MultiByteToWideChar(CP_ACP, 0, ansi, length, MultiByteToWideChar(CP_ACP, 0, ansi, length, nullptr, 0);
NULL, 0);
WCHAR* unicode = new WCHAR[unicode_length + 1]; WCHAR* unicode = new WCHAR[unicode_length + 1];
MultiByteToWideChar(CP_ACP, 0, ansi, length, MultiByteToWideChar(CP_ACP, 0, ansi, length,
unicode, unicode_length); unicode, unicode_length);
@ -919,13 +918,12 @@ LPCWSTR String::AnsiToUtf16(const char* ansi) {
// value using delete[]. Returns the ANSI string, or NULL if the // value using delete[]. Returns the ANSI string, or NULL if the
// input is NULL. // input is NULL.
const char* String::Utf16ToAnsi(LPCWSTR utf16_str) { const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
if (!utf16_str) return NULL; if (!utf16_str) return nullptr;
const int ansi_length = const int ansi_length = WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, nullptr,
WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, 0, nullptr, nullptr);
NULL, 0, NULL, NULL);
char* ansi = new char[ansi_length + 1]; char* ansi = new char[ansi_length + 1];
WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, ansi, ansi_length, nullptr,
ansi, ansi_length, NULL, NULL); nullptr);
ansi[ansi_length] = 0; ansi[ansi_length] = 0;
return ansi; return ansi;
} }
@ -1727,7 +1725,7 @@ AssertionResult HRESULTFailureHelper(const char* expr,
0, // no line width restrictions 0, // no line width restrictions
error_text, // output buffer error_text, // output buffer
kBufSize, // buf size kBufSize, // buf size
NULL); // no arguments for inserts nullptr); // no arguments for inserts
// Trims tailing white space (FormatMessage leaves a trailing CR-LF) // Trims tailing white space (FormatMessage leaves a trailing CR-LF)
for (; message_length && IsSpace(error_text[message_length - 1]); for (; message_length && IsSpace(error_text[message_length - 1]);
--message_length) { --message_length) {
@ -2399,7 +2397,7 @@ namespace internal {
static std::string FormatCxxExceptionMessage(const char* description, static std::string FormatCxxExceptionMessage(const char* description,
const char* location) { const char* location) {
Message message; Message message;
if (description != NULL) { if (description != nullptr) {
message << "C++ exception with description \"" << description << "\""; message << "C++ exception with description \"" << description << "\"";
} else { } else {
message << "Unknown C++ exception"; message << "Unknown C++ exception";
@ -2497,7 +2495,7 @@ Result HandleExceptionsInMethodIfSupported(
} catch (...) { // NOLINT } catch (...) { // NOLINT
internal::ReportFailureInUnknownLocation( internal::ReportFailureInUnknownLocation(
TestPartResult::kFatalFailure, TestPartResult::kFatalFailure,
FormatCxxExceptionMessage(NULL, location)); FormatCxxExceptionMessage(nullptr, location));
} }
return static_cast<Result>(0); return static_cast<Result>(0);
#else #else
@ -3673,8 +3671,7 @@ static bool PortableLocaltime(time_t seconds, struct tm* out) {
// MINGW <time.h> provides neither localtime_r nor localtime_s, but uses // MINGW <time.h> provides neither localtime_r nor localtime_s, but uses
// Windows' localtime(), which has a thread-local tm buffer. // Windows' localtime(), which has a thread-local tm buffer.
struct tm* tm_ptr = localtime(&seconds); // NOLINT struct tm* tm_ptr = localtime(&seconds); // NOLINT
if (tm_ptr == NULL) if (tm_ptr == nullptr) return false;
return false;
*out = *tm_ptr; *out = *tm_ptr;
return true; return true;
#else #else
@ -4729,11 +4726,11 @@ void UnitTest::AddTestPartResult(
// with clang/gcc we can achieve the same effect on x86 by invoking int3 // with clang/gcc we can achieve the same effect on x86 by invoking int3
asm("int3"); asm("int3");
#else #else
// Dereference NULL through a volatile pointer to prevent the compiler // Dereference nullptr through a volatile pointer to prevent the compiler
// from removing. We use this rather than abort() or __builtin_trap() for // from removing. We use this rather than abort() or __builtin_trap() for
// portability: Symbian doesn't implement abort() well, and some debuggers // portability: Symbian doesn't implement abort() well, and some debuggers
// don't correctly trap abort(). // don't correctly trap abort().
*static_cast<volatile int*>(NULL) = 1; *static_cast<volatile int*>(nullptr) = 1;
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
} else if (GTEST_FLAG(throw_on_failure)) { } else if (GTEST_FLAG(throw_on_failure)) {
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
@ -6025,7 +6022,7 @@ std::string TempDir() {
return "\\temp\\"; return "\\temp\\";
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
const char* temp_dir = internal::posix::GetEnv("TEMP"); const char* temp_dir = internal::posix::GetEnv("TEMP");
if (temp_dir == NULL || temp_dir[0] == '\0') if (temp_dir == nullptr || temp_dir[0] == '\0')
return "\\temp\\"; return "\\temp\\";
else if (temp_dir[strlen(temp_dir) - 1] == '\\') else if (temp_dir[strlen(temp_dir) - 1] == '\\')
return temp_dir; return temp_dir;

View File

@ -121,7 +121,7 @@ TEST_F(TestPartResultTest, type) {
// Tests TestPartResult::file_name(). // Tests TestPartResult::file_name().
TEST_F(TestPartResultTest, file_name) { TEST_F(TestPartResultTest, file_name) {
EXPECT_STREQ("foo/bar.cc", r1_.file_name()); EXPECT_STREQ("foo/bar.cc", r1_.file_name());
EXPECT_STREQ(NULL, r3_.file_name()); EXPECT_STREQ(nullptr, r3_.file_name());
EXPECT_STREQ("foo/bar.cc", r4_.file_name()); EXPECT_STREQ("foo/bar.cc", r4_.file_name());
} }

View File

@ -6181,16 +6181,9 @@ TEST_F(FlagfileTest, Empty) {
std::string flagfile_flag = std::string flagfile_flag =
std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str(); std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
const char* argv[] = { const char* argv[] = {"foo.exe", flagfile_flag.c_str(), nullptr};
"foo.exe",
flagfile_flag.c_str(),
NULL
};
const char* argv2[] = { const char* argv2[] = {"foo.exe", nullptr};
"foo.exe",
NULL
};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false); GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), false);
} }
@ -6202,16 +6195,9 @@ TEST_F(FlagfileTest, FilterNonEmpty) {
std::string flagfile_flag = std::string flagfile_flag =
std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str(); std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
const char* argv[] = { const char* argv[] = {"foo.exe", flagfile_flag.c_str(), nullptr};
"foo.exe",
flagfile_flag.c_str(),
NULL
};
const char* argv2[] = { const char* argv2[] = {"foo.exe", nullptr};
"foo.exe",
NULL
};
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("abc"), false); GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter("abc"), false);
} }
@ -6225,16 +6211,9 @@ TEST_F(FlagfileTest, SeveralFlags) {
std::string flagfile_flag = std::string flagfile_flag =
std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str(); std::string("--" GTEST_FLAG_PREFIX_ "flagfile=") + flagfile_path.c_str();
const char* argv[] = { const char* argv[] = {"foo.exe", flagfile_flag.c_str(), nullptr};
"foo.exe",
flagfile_flag.c_str(),
NULL
};
const char* argv2[] = { const char* argv2[] = {"foo.exe", nullptr};
"foo.exe",
NULL
};
Flags expected_flags; Flags expected_flags;
expected_flags.break_on_failure = true; expected_flags.break_on_failure = true;