Commit 87fdda2c authored by jgm's avatar jgm
Browse files

Unfortunately, the svn repo is a bit out of date. This commit contains 8

changes that haven't made it to svn. The descriptions of each change are listed
below.

- Fixes some python shebang lines.

- Add ElementsAreArray overloads to gmock. ElementsAreArray now makes a copy of
  its input elements before the conversion to a Matcher. ElementsAreArray can
  now take a vector as input. ElementsAreArray can now take an iterator pair as
  input.

- Templatize MatchAndExplain to allow independent string types for the matcher
  and matchee. I also templatized the ConstCharPointer version of
  MatchAndExplain to avoid calls with "char*" from using the new templated
  MatchAndExplain.

- Fixes the bug where the constructor of the return type of ElementsAre() saves
  a reference instead of a copy of the arguments.

- Extends ElementsAre() to accept arrays whose sizes aren't known.

- Switches gTest's internal FilePath class from testing::internal::String to
  std::string. testing::internal::String was introduced when gTest couldn't
  depend on std::string.  It's now deprecated.

- Switches gTest & gMock from using testing::internal::String objects to
  std::string. Some static methods of String are still in use.  We may be able
  to remove some but not all of them.  In particular, String::Format() should
  eventually be removed as it truncates the result at 4096 characters, often
  causing problems.
parent 78bf6d57
...@@ -183,11 +183,11 @@ class GTEST_API_ Message { ...@@ -183,11 +183,11 @@ class GTEST_API_ Message {
Message& operator <<(const ::wstring& wstr); Message& operator <<(const ::wstring& wstr);
#endif // GTEST_HAS_GLOBAL_WSTRING #endif // GTEST_HAS_GLOBAL_WSTRING
// Gets the text streamed to this object so far as a String. // Gets the text streamed to this object so far as an std::string.
// Each '\0' character in the buffer is replaced with "\\0". // Each '\0' character in the buffer is replaced with "\\0".
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
internal::String GetString() const { std::string GetString() const {
return internal::StringStreamToString(ss_.get()); return internal::StringStreamToString(ss_.get());
} }
......
...@@ -62,7 +62,7 @@ class GTEST_API_ TestPartResult { ...@@ -62,7 +62,7 @@ class GTEST_API_ TestPartResult {
int a_line_number, int a_line_number,
const char* a_message) const char* a_message)
: type_(a_type), : type_(a_type),
file_name_(a_file_name), file_name_(a_file_name == NULL ? "" : a_file_name),
line_number_(a_line_number), line_number_(a_line_number),
summary_(ExtractSummary(a_message)), summary_(ExtractSummary(a_message)),
message_(a_message) { message_(a_message) {
...@@ -73,7 +73,9 @@ class GTEST_API_ TestPartResult { ...@@ -73,7 +73,9 @@ class GTEST_API_ TestPartResult {
// Gets the name of the source file where the test part took place, or // Gets the name of the source file where the test part took place, or
// NULL if it's unknown. // NULL if it's unknown.
const char* file_name() const { return file_name_.c_str(); } const char* file_name() const {
return file_name_.empty() ? NULL : file_name_.c_str();
}
// Gets the line in the source file where the test part took place, // Gets the line in the source file where the test part took place,
// or -1 if it's unknown. // or -1 if it's unknown.
...@@ -102,16 +104,16 @@ class GTEST_API_ TestPartResult { ...@@ -102,16 +104,16 @@ class GTEST_API_ TestPartResult {
// Gets the summary of the failure message by omitting the stack // Gets the summary of the failure message by omitting the stack
// trace in it. // trace in it.
static internal::String ExtractSummary(const char* message); static std::string ExtractSummary(const char* message);
// The name of the source file where the test part took place, or // The name of the source file where the test part took place, or
// NULL if the source file is unknown. // "" if the source file is unknown.
internal::String file_name_; std::string file_name_;
// The line in the source file where the test part took place, or -1 // The line in the source file where the test part took place, or -1
// if the line number is unknown. // if the line number is unknown.
int line_number_; int line_number_;
internal::String summary_; // The test failure summary. std::string summary_; // The test failure summary.
internal::String message_; // The test failure message. std::string message_; // The test failure message.
}; };
// Prints a TestPartResult object. // Prints a TestPartResult object.
......
...@@ -160,9 +160,9 @@ class TestEventRepeater; ...@@ -160,9 +160,9 @@ class TestEventRepeater;
class WindowsDeathTest; class WindowsDeathTest;
class UnitTestImpl* GetUnitTestImpl(); class UnitTestImpl* GetUnitTestImpl();
void ReportFailureInUnknownLocation(TestPartResult::Type result_type, void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
const String& message); const std::string& message);
// Converts a streamable value to a String. A NULL pointer is // Converts a streamable value to an std::string. A NULL pointer is
// converted to "(null)". When the input value is a ::string, // converted to "(null)". When the input value is a ::string,
// ::std::string, ::wstring, or ::std::wstring object, each NUL // ::std::string, ::wstring, or ::std::wstring object, each NUL
// character in it is replaced with "\\0". // character in it is replaced with "\\0".
...@@ -170,7 +170,7 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, ...@@ -170,7 +170,7 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
// to the definition of the Message class, required by the ARM // to the definition of the Message class, required by the ARM
// compiler. // compiler.
template <typename T> template <typename T>
String StreamableToString(const T& streamable) { std::string StreamableToString(const T& streamable) {
return (Message() << streamable).GetString(); return (Message() << streamable).GetString();
} }
...@@ -495,9 +495,9 @@ class TestProperty { ...@@ -495,9 +495,9 @@ class TestProperty {
private: private:
// The key supplied by the user. // The key supplied by the user.
internal::String key_; std::string key_;
// The value supplied by the user. // The value supplied by the user.
internal::String value_; std::string value_;
}; };
// The result of a single Test. This includes a list of // The result of a single Test. This includes a list of
...@@ -869,7 +869,7 @@ class GTEST_API_ TestCase { ...@@ -869,7 +869,7 @@ class GTEST_API_ TestCase {
void UnshuffleTests(); void UnshuffleTests();
// Name of the test case. // Name of the test case.
internal::String name_; std::string name_;
// Name of the parameter type, or NULL if this is not a typed or a // Name of the parameter type, or NULL if this is not a typed or a
// type-parameterized test. // type-parameterized test.
const internal::scoped_ptr<const ::std::string> type_param_; const internal::scoped_ptr<const ::std::string> type_param_;
...@@ -1196,8 +1196,8 @@ class GTEST_API_ UnitTest { ...@@ -1196,8 +1196,8 @@ class GTEST_API_ UnitTest {
void AddTestPartResult(TestPartResult::Type result_type, void AddTestPartResult(TestPartResult::Type result_type,
const char* file_name, const char* file_name,
int line_number, int line_number,
const internal::String& message, const std::string& message,
const internal::String& os_stack_trace) const std::string& os_stack_trace)
GTEST_LOCK_EXCLUDED_(mutex_); GTEST_LOCK_EXCLUDED_(mutex_);
// Adds a TestProperty to the current TestResult object. If the result already // Adds a TestProperty to the current TestResult object. If the result already
...@@ -1221,7 +1221,7 @@ class GTEST_API_ UnitTest { ...@@ -1221,7 +1221,7 @@ class GTEST_API_ UnitTest {
friend internal::UnitTestImpl* internal::GetUnitTestImpl(); friend internal::UnitTestImpl* internal::GetUnitTestImpl();
friend void internal::ReportFailureInUnknownLocation( friend void internal::ReportFailureInUnknownLocation(
TestPartResult::Type result_type, TestPartResult::Type result_type,
const internal::String& message); const std::string& message);
// Creates an empty UnitTest. // Creates an empty UnitTest.
UnitTest(); UnitTest();
...@@ -1383,8 +1383,8 @@ GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring); ...@@ -1383,8 +1383,8 @@ GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
template <typename T1, typename T2> template <typename T1, typename T2>
String FormatForComparisonFailureMessage(const T1& value, std::string FormatForComparisonFailureMessage(
const T2& /* other_operand */) { const T1& value, const T2& /* other_operand */) {
return FormatForComparison<T1, T2>::Format(value); return FormatForComparison<T1, T2>::Format(value);
} }
...@@ -1701,9 +1701,9 @@ class GTEST_API_ AssertHelper { ...@@ -1701,9 +1701,9 @@ class GTEST_API_ AssertHelper {
: type(t), file(srcfile), line(line_num), message(msg) { } : type(t), file(srcfile), line(line_num), message(msg) { }
TestPartResult::Type const type; TestPartResult::Type const type;
const char* const file; const char* const file;
int const line; int const line;
String const message; std::string const message;
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData); GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
...@@ -1981,7 +1981,7 @@ class TestWithParam : public Test, public WithParamInterface<T> { ...@@ -1981,7 +1981,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {
# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) # define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
#endif #endif
// C String Comparisons. All tests treat NULL and any non-NULL string // C-string Comparisons. All tests treat NULL and any non-NULL string
// as different. Two NULLs are equal. // as different. Two NULLs are equal.
// //
// * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2 // * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2
......
...@@ -127,11 +127,11 @@ class GTEST_API_ DeathTest { ...@@ -127,11 +127,11 @@ class GTEST_API_ DeathTest {
// the last death test. // the last death test.
static const char* LastMessage(); static const char* LastMessage();
static void set_last_death_test_message(const String& message); static void set_last_death_test_message(const std::string& message);
private: private:
// A string containing a description of the outcome of the last death test. // A string containing a description of the outcome of the last death test.
static String last_death_test_message_; static std::string last_death_test_message_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest); GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
}; };
...@@ -233,7 +233,7 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status); ...@@ -233,7 +233,7 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
// RUN_ALL_TESTS was called. // RUN_ALL_TESTS was called.
class InternalRunDeathTestFlag { class InternalRunDeathTestFlag {
public: public:
InternalRunDeathTestFlag(const String& a_file, InternalRunDeathTestFlag(const std::string& a_file,
int a_line, int a_line,
int an_index, int an_index,
int a_write_fd) int a_write_fd)
...@@ -245,13 +245,13 @@ class InternalRunDeathTestFlag { ...@@ -245,13 +245,13 @@ class InternalRunDeathTestFlag {
posix::Close(write_fd_); posix::Close(write_fd_);
} }
String file() const { return file_; } const std::string& file() const { return file_; }
int line() const { return line_; } int line() const { return line_; }
int index() const { return index_; } int index() const { return index_; }
int write_fd() const { return write_fd_; } int write_fd() const { return write_fd_; }
private: private:
String file_; std::string file_;
int line_; int line_;
int index_; int index_;
int write_fd_; int write_fd_;
......
...@@ -61,11 +61,7 @@ class GTEST_API_ FilePath { ...@@ -61,11 +61,7 @@ class GTEST_API_ FilePath {
FilePath() : pathname_("") { } FilePath() : pathname_("") { }
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
explicit FilePath(const char* pathname) : pathname_(pathname) { explicit FilePath(const std::string& pathname) : pathname_(pathname) {
Normalize();
}
explicit FilePath(const String& pathname) : pathname_(pathname) {
Normalize(); Normalize();
} }
...@@ -78,7 +74,7 @@ class GTEST_API_ FilePath { ...@@ -78,7 +74,7 @@ class GTEST_API_ FilePath {
pathname_ = rhs.pathname_; pathname_ = rhs.pathname_;
} }
String ToString() const { return pathname_; } const std::string& string() const { return pathname_; }
const char* c_str() const { return pathname_.c_str(); } const char* c_str() const { return pathname_.c_str(); }
// Returns the current working directory, or "" if unsuccessful. // Returns the current working directory, or "" if unsuccessful.
...@@ -111,8 +107,8 @@ class GTEST_API_ FilePath { ...@@ -111,8 +107,8 @@ class GTEST_API_ FilePath {
const FilePath& base_name, const FilePath& base_name,
const char* extension); const char* extension);
// Returns true iff the path is NULL or "". // Returns true iff the path is "".
bool IsEmpty() const { return c_str() == NULL || *c_str() == '\0'; } bool IsEmpty() const { return pathname_.empty(); }
// If input name has a trailing separator character, removes it and returns // If input name has a trailing separator character, removes it and returns
// the name, otherwise return the name string unmodified. // the name, otherwise return the name string unmodified.
...@@ -201,7 +197,7 @@ class GTEST_API_ FilePath { ...@@ -201,7 +197,7 @@ class GTEST_API_ FilePath {
// separators. Returns NULL if no path separator was found. // separators. Returns NULL if no path separator was found.
const char* FindLastPathSeparator() const; const char* FindLastPathSeparator() const;
String pathname_; std::string pathname_;
}; // class FilePath }; // class FilePath
} // namespace internal } // namespace internal
......
...@@ -163,8 +163,8 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT ...@@ -163,8 +163,8 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT
#endif // GTEST_ELLIPSIS_NEEDS_POD_ #endif // GTEST_ELLIPSIS_NEEDS_POD_
// Appends the user-supplied message to the Google-Test-generated message. // Appends the user-supplied message to the Google-Test-generated message.
GTEST_API_ String AppendUserMessage(const String& gtest_msg, GTEST_API_ std::string AppendUserMessage(
const Message& user_msg); const std::string& gtest_msg, const Message& user_msg);
// A helper class for creating scoped traces in user programs. // A helper class for creating scoped traces in user programs.
class GTEST_API_ ScopedTrace { class GTEST_API_ ScopedTrace {
...@@ -185,7 +185,7 @@ class GTEST_API_ ScopedTrace { ...@@ -185,7 +185,7 @@ class GTEST_API_ ScopedTrace {
// c'tor and d'tor. Therefore it doesn't // c'tor and d'tor. Therefore it doesn't
// need to be used otherwise. // need to be used otherwise.
// Converts a streamable value to a String. A NULL pointer is // Converts a streamable value to an std::string. A NULL pointer is
// converted to "(null)". When the input value is a ::string, // converted to "(null)". When the input value is a ::string,
// ::std::string, ::wstring, or ::std::wstring object, each NUL // ::std::string, ::wstring, or ::std::wstring object, each NUL
// character in it is replaced with "\\0". // character in it is replaced with "\\0".
...@@ -193,7 +193,7 @@ class GTEST_API_ ScopedTrace { ...@@ -193,7 +193,7 @@ class GTEST_API_ ScopedTrace {
// to the definition of the Message class, required by the ARM // to the definition of the Message class, required by the ARM
// compiler. // compiler.
template <typename T> template <typename T>
String StreamableToString(const T& streamable); std::string StreamableToString(const T& streamable);
// Constructs and returns the message for an equality assertion // Constructs and returns the message for an equality assertion
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
...@@ -212,12 +212,12 @@ String StreamableToString(const T& streamable); ...@@ -212,12 +212,12 @@ String StreamableToString(const T& streamable);
// be inserted into the message. // be inserted into the message.
GTEST_API_ AssertionResult EqFailure(const char* expected_expression, GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
const char* actual_expression, const char* actual_expression,
const String& expected_value, const std::string& expected_value,
const String& actual_value, const std::string& actual_value,
bool ignoring_case); bool ignoring_case);
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE. // Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
GTEST_API_ String GetBoolAssertionFailureMessage( GTEST_API_ std::string GetBoolAssertionFailureMessage(
const AssertionResult& assertion_result, const AssertionResult& assertion_result,
const char* expression_text, const char* expression_text,
const char* actual_predicate_value, const char* actual_predicate_value,
...@@ -563,9 +563,9 @@ inline const char* SkipComma(const char* str) { ...@@ -563,9 +563,9 @@ inline const char* SkipComma(const char* str) {
// Returns the prefix of 'str' before the first comma in it; returns // Returns the prefix of 'str' before the first comma in it; returns
// the entire string if it contains no comma. // the entire string if it contains no comma.
inline String GetPrefixUntilComma(const char* str) { inline std::string GetPrefixUntilComma(const char* str) {
const char* comma = strchr(str, ','); const char* comma = strchr(str, ',');
return comma == NULL ? String(str) : String(str, comma - str); return comma == NULL ? str : std::string(str, comma);
} }
// TypeParameterizedTest<Fixture, TestSel, Types>::Register() // TypeParameterizedTest<Fixture, TestSel, Types>::Register()
...@@ -650,7 +650,7 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> { ...@@ -650,7 +650,7 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> {
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
// Returns the current OS stack trace as a String. // Returns the current OS stack trace as an std::string.
// //
// The maximum number of stack frames to be included is specified by // The maximum number of stack frames to be included is specified by
// the gtest_stack_trace_depth flag. The skip_count parameter // the gtest_stack_trace_depth flag. The skip_count parameter
...@@ -660,8 +660,8 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> { ...@@ -660,8 +660,8 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> {
// For example, if Foo() calls Bar(), which in turn calls // For example, if Foo() calls Bar(), which in turn calls
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
GTEST_API_ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(
int skip_count); UnitTest* unit_test, int skip_count);
// Helpers for suppressing warnings on unreachable code or constant // Helpers for suppressing warnings on unreachable code or constant
// condition. // condition.
......
...@@ -239,6 +239,9 @@ ...@@ -239,6 +239,9 @@
# define GTEST_OS_MAC 1 # define GTEST_OS_MAC 1
# if TARGET_OS_IPHONE # if TARGET_OS_IPHONE
# define GTEST_OS_IOS 1 # define GTEST_OS_IOS 1
# if TARGET_IPHONE_SIMULATOR
# define GEST_OS_IOS_SIMULATOR 1
# endif
# endif # endif
#elif defined __linux__ #elif defined __linux__
# define GTEST_OS_LINUX 1 # define GTEST_OS_LINUX 1
...@@ -635,7 +638,7 @@ using ::std::tuple_size; ...@@ -635,7 +638,7 @@ using ::std::tuple_size;
// abort() in a VC 7.1 application compiled as GUI in debug config // abort() in a VC 7.1 application compiled as GUI in debug config
// pops up a dialog window that cannot be suppressed programmatically. // pops up a dialog window that cannot be suppressed programmatically.
#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ #if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
(GTEST_OS_MAC && !GTEST_OS_IOS) || \ (GTEST_OS_MAC && (!GTEST_OS_IOS || GEST_OS_IOS_SIMULATOR)) || \
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \ (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \ GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
GTEST_OS_OPENBSD || GTEST_OS_QNX) GTEST_OS_OPENBSD || GTEST_OS_QNX)
...@@ -780,8 +783,6 @@ class Message; ...@@ -780,8 +783,6 @@ class Message;
namespace internal { namespace internal {
class String;
// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time // The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
// expression is true. For example, you could use it to verify the // expression is true. For example, you could use it to verify the
// size of a static array: // size of a static array:
...@@ -964,10 +965,9 @@ class GTEST_API_ RE { ...@@ -964,10 +965,9 @@ class GTEST_API_ RE {
private: private:
void Init(const char* regex); void Init(const char* regex);
// We use a const char* instead of a string, as Google Test may be used // We use a const char* instead of an std::string, as Google Test used to be
// where string is not available. We also do not use Google Test's own // used where std::string is not available. TODO(wan@google.com): change to
// String type here, in order to simplify dependencies between the // std::string.
// files.
const char* pattern_; const char* pattern_;
bool is_valid_; bool is_valid_;
...@@ -1150,9 +1150,9 @@ Derived* CheckedDowncastToActualType(Base* base) { ...@@ -1150,9 +1150,9 @@ Derived* CheckedDowncastToActualType(Base* base) {
// GetCapturedStderr - stops capturing stderr and returns the captured string. // GetCapturedStderr - stops capturing stderr and returns the captured string.
// //
GTEST_API_ void CaptureStdout(); GTEST_API_ void CaptureStdout();
GTEST_API_ String GetCapturedStdout(); GTEST_API_ std::string GetCapturedStdout();
GTEST_API_ void CaptureStderr(); GTEST_API_ void CaptureStderr();
GTEST_API_ String GetCapturedStderr(); GTEST_API_ std::string GetCapturedStderr();
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
...@@ -1903,7 +1903,7 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. ...@@ -1903,7 +1903,7 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
#define GTEST_DECLARE_int32_(name) \ #define GTEST_DECLARE_int32_(name) \
GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name) GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
#define GTEST_DECLARE_string_(name) \ #define GTEST_DECLARE_string_(name) \
GTEST_API_ extern ::testing::internal::String GTEST_FLAG(name) GTEST_API_ extern ::std::string GTEST_FLAG(name)
// Macros for defining flags. // Macros for defining flags.
#define GTEST_DEFINE_bool_(name, default_val, doc) \ #define GTEST_DEFINE_bool_(name, default_val, doc) \
...@@ -1911,7 +1911,7 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. ...@@ -1911,7 +1911,7 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
#define GTEST_DEFINE_int32_(name, default_val, doc) \ #define GTEST_DEFINE_int32_(name, default_val, doc) \
GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val) GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
#define GTEST_DEFINE_string_(name, default_val, doc) \ #define GTEST_DEFINE_string_(name, default_val, doc) \
GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val) GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
// Thread annotations // Thread annotations
#define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) #define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
......
...@@ -54,30 +54,7 @@ ...@@ -54,30 +54,7 @@
namespace testing { namespace testing {
namespace internal { namespace internal {
// String - a UTF-8 string class. // String - an abstract class holding static string utilities.
//
// For historic reasons, we don't use std::string.
//
// TODO(wan@google.com): replace this class with std::string or
// implement it in terms of the latter.
//
// Note that String can represent both NULL and the empty string,
// while std::string cannot represent NULL.
//
// NULL and the empty string are considered different. NULL is less
// than anything (including the empty string) except itself.
//
// This class only provides minimum functionality necessary for
// implementing Google Test. We do not intend to implement a full-fledged
// string class here.
//
// Since the purpose of this class is to provide a substitute for
// std::string on platforms where it cannot be used, we define a copy
// constructor and assignment operators such that we don't need
// conditional compilation in a lot of places.
//
// In order to make the representation efficient, the d'tor of String
// is not virtual. Therefore DO NOT INHERIT FROM String.
class GTEST_API_ String { class GTEST_API_ String {
public: public:
// Static utility methods // Static utility methods
...@@ -128,7 +105,7 @@ class GTEST_API_ String { ...@@ -128,7 +105,7 @@ class GTEST_API_ String {
// NULL will be converted to "(null)". If an error occurred during // NULL will be converted to "(null)". If an error occurred during
// the conversion, "(failed to convert from wide string)" is // the conversion, "(failed to convert from wide string)" is
// returned. // returned.
static String ShowWideCString(const wchar_t* wide_c_str); static std::string ShowWideCString(const wchar_t* wide_c_str);
// Compares two wide C strings. Returns true iff they have the same // Compares two wide C strings. Returns true iff they have the same
// content. // content.
...@@ -162,7 +139,12 @@ class GTEST_API_ String { ...@@ -162,7 +139,12 @@ class GTEST_API_ String {
static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs, static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
const wchar_t* rhs); const wchar_t* rhs);
// Formats a list of arguments to a String, using the same format // Returns true iff the given string ends with the given suffix, ignoring
// case. Any string is considered to end with an empty suffix.
static bool EndsWithCaseInsensitive(
const std::string& str, const std::string& suffix);
// Formats a list of arguments to an std::string, using the same format
// spec string as for printf. // spec string as for printf.
// //
// We do not use the StringPrintf class as it is not universally // We do not use the StringPrintf class as it is not universally
...@@ -171,156 +153,17 @@ class GTEST_API_ String { ...@@ -171,156 +153,17 @@ class GTEST_API_ String {
// The result is limited to 4096 characters (including the tailing // The result is limited to 4096 characters (including the tailing
// 0). If 4096 characters are not enough to format the input, // 0). If 4096 characters are not enough to format the input,
// "<buffer exceeded>" is returned. // "<buffer exceeded>" is returned.
static String Format(const char* format, ...); static std::string Format(const char* format, ...);
// C'tors
// The default c'tor constructs a NULL string.
String() : c_str_(NULL), length_(0) {}
// Constructs a String by cloning a 0-terminated C string.
String(const char* a_c_str) { // NOLINT
if (a_c_str == NULL) {
c_str_ = NULL;
length_ = 0;
} else {
ConstructNonNull(a_c_str, strlen(a_c_str));
}
}
// Constructs a String by copying a given number of chars from a
// buffer. E.g. String("hello", 3) creates the string "hel",
// String("a\0bcd", 4) creates "a\0bc", String(NULL, 0) creates "",
// and String(NULL, 1) results in access violation.
String(const char* buffer, size_t a_length) {
ConstructNonNull(buffer, a_length);
}
// The copy c'tor creates a new copy of the string. The two
// String objects do not share content.
String(const String& str) : c_str_(NULL), length_(0) { *this = str; }
// D'tor. String is intended to be a final class, so the d'tor
// doesn't need to be virtual.
~String() { delete[] c_str_; }
// Allows a String to be implicitly converted to an ::std::string or
// ::string, and vice versa. Converting a String containing a NULL
// pointer to ::std::string or ::string is undefined behavior.
// Converting a ::std::string or ::string containing an embedded NUL
// character to a String will result in the prefix up to the first
// NUL character.
String(const ::std::string& str) { // NOLINT
ConstructNonNull(str.c_str(), str.length());
}
operator ::std::string() const { return ::std::string(c_str(), length()); }
#if GTEST_HAS_GLOBAL_STRING
String(const ::string& str) { // NOLINT
ConstructNonNull(str.c_str(), str.length());
}
operator ::string() const { return ::string(c_str(), length()); }
#endif // GTEST_HAS_GLOBAL_STRING
// Returns true iff this is an empty string (i.e. "").
bool empty() const { return (c_str() != NULL) && (length() == 0); }
// Compares this with another String.
// Returns < 0 if this is less than rhs, 0 if this is equal to rhs, or > 0
// if this is greater than rhs.
int Compare(const String& rhs) const;
// Returns true iff this String equals the given C string. A NULL
// string and a non-NULL string are considered not equal.
bool operator==(const char* a_c_str) const { return Compare(a_c_str) == 0; }
// Returns true iff this String is less than the given String. A
// NULL string is considered less than "".
bool operator<(const String& rhs) const { return Compare(rhs) < 0; }
// Returns true iff this String doesn't equal the given C string. A NULL
// string and a non-NULL string are considered not equal.
bool operator!=(const char* a_c_str) const { return !(*this == a_c_str); }
// Returns true iff this String ends with the given suffix. *Any*
// String is considered to end with a NULL or empty suffix.
bool EndsWith(const char* suffix) const;
// Returns true iff this String ends with the given suffix, not considering
// case. Any String is considered to end with a NULL or empty suffix.
bool EndsWithCaseInsensitive(const char* suffix) const;
// Returns the length of the encapsulated string, or 0 if the
// string is NULL.
size_t length() const { return length_; }
// Gets the 0-terminated C string this String object represents.
// The String object still owns the string. Therefore the caller
// should NOT delete the return value.
const char* c_str() const { return c_str_; }
// Assigns a C string to this object. Self-assignment works.
const String& operator=(const char* a_c_str) {
return *this = String(a_c_str);
}
// Assigns a String object to this object. Self-assignment works.
const String& operator=(const String& rhs) {
if (this != &rhs) {
delete[] c_str_;
if (rhs.c_str() == NULL) {
c_str_ = NULL;
length_ = 0;
} else {
ConstructNonNull(rhs.c_str(), rhs.length());
}
}
return *this;
}
private: private:
// Constructs a non-NULL String from the given content. This String(); // Not meant to be instantiated.
// function can only be called when c_str_ has not been allocated.
// ConstructNonNull(NULL, 0) results in an empty string ("").
// ConstructNonNull(NULL, non_zero) is undefined behavior.
void ConstructNonNull(const char* buffer, size_t a_length) {
char* const str = new char[a_length + 1];
memcpy(str, buffer, a_length);
str[a_length] = '\0';
c_str_ = str;
length_ = a_length;
}
const char* c_str_;
size_t length_;
}; // class String }; // class String
// Streams a String to an ostream. Each '\0' character in the String // Gets the content of the stringstream's buffer as an std::string. Each '\0'
// is replaced with "\\0".
inline ::std::ostream& operator<<(::std::ostream& os, const String& str) {
if (str.c_str() == NULL) {
os << "(null)";
} else {
const char* const c_str = str.c_str();
for (size_t i = 0; i != str.length(); i++) {
if (c_str[i] == '\0') {
os << "\\0";
} else {
os << c_str[i];
}
}
}
return os;
}
// Gets the content of the stringstream's buffer as a String. Each '\0'
// character in the buffer is replaced with "\\0". // character in the buffer is replaced with "\\0".
GTEST_API_ String StringStreamToString(::std::stringstream* stream); GTEST_API_ std::string StringStreamToString(::std::stringstream* stream);
// Converts a streamable value to a String. A NULL pointer is // Converts a streamable value to an std::string. A NULL pointer is
// converted to "(null)". When the input value is a ::string, // converted to "(null)". When the input value is a ::string,
// ::std::string, ::wstring, or ::std::wstring object, each NUL // ::std::string, ::wstring, or ::std::wstring object, each NUL
// character in it is replaced with "\\0". // character in it is replaced with "\\0".
...@@ -329,7 +172,7 @@ GTEST_API_ String StringStreamToString(::std::stringstream* stream); ...@@ -329,7 +172,7 @@ GTEST_API_ String StringStreamToString(::std::stringstream* stream);
// to the definition of the Message class, required by the ARM // to the definition of the Message class, required by the ARM
// compiler. // compiler.
template <typename T> template <typename T>
String StreamableToString(const T& streamable); std::string StreamableToString(const T& streamable);
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
......
...@@ -62,7 +62,7 @@ namespace internal { ...@@ -62,7 +62,7 @@ namespace internal {
// NB: This function is also used in Google Mock, so don't move it inside of // NB: This function is also used in Google Mock, so don't move it inside of
// the typed-test-only section below. // the typed-test-only section below.
template <typename T> template <typename T>
String GetTypeName() { std::string GetTypeName() {
# if GTEST_HAS_RTTI # if GTEST_HAS_RTTI
const char* const name = typeid(T).name(); const char* const name = typeid(T).name();
...@@ -74,7 +74,7 @@ String GetTypeName() { ...@@ -74,7 +74,7 @@ String GetTypeName() {
using abi::__cxa_demangle; using abi::__cxa_demangle;
# endif // GTEST_HAS_CXXABI_H_ # endif // GTEST_HAS_CXXABI_H_
char* const readable_name = __cxa_demangle(name, 0, 0, &status); char* const readable_name = __cxa_demangle(name, 0, 0, &status);
const String name_str(status == 0 ? readable_name : name); const std::string name_str(status == 0 ? readable_name : name);
free(readable_name); free(readable_name);
return name_str; return name_str;
# else # else
......
...@@ -60,7 +60,7 @@ namespace internal { ...@@ -60,7 +60,7 @@ namespace internal {
// NB: This function is also used in Google Mock, so don't move it inside of // NB: This function is also used in Google Mock, so don't move it inside of
// the typed-test-only section below. // the typed-test-only section below.
template <typename T> template <typename T>
String GetTypeName() { std::string GetTypeName() {
# if GTEST_HAS_RTTI # if GTEST_HAS_RTTI
const char* const name = typeid(T).name(); const char* const name = typeid(T).name();
...@@ -72,7 +72,7 @@ String GetTypeName() { ...@@ -72,7 +72,7 @@ String GetTypeName() {
using abi::__cxa_demangle; using abi::__cxa_demangle;
# endif // GTEST_HAS_CXXABI_H_ # endif // GTEST_HAS_CXXABI_H_
char* const readable_name = __cxa_demangle(name, 0, 0, &status); char* const readable_name = __cxa_demangle(name, 0, 0, &status);
const String name_str(status == 0 ? readable_name : name); const std::string name_str(status == 0 ? readable_name : name);
free(readable_name); free(readable_name);
return name_str; return name_str;
# else # else
......
...@@ -179,7 +179,7 @@ namespace internal { ...@@ -179,7 +179,7 @@ namespace internal {
// Generates a textual description of a given exit code, in the format // Generates a textual description of a given exit code, in the format
// specified by wait(2). // specified by wait(2).
static String ExitSummary(int exit_code) { static std::string ExitSummary(int exit_code) {
Message m; Message m;
# if GTEST_OS_WINDOWS # if GTEST_OS_WINDOWS
...@@ -214,7 +214,7 @@ bool ExitedUnsuccessfully(int exit_status) { ...@@ -214,7 +214,7 @@ bool ExitedUnsuccessfully(int exit_status) {
// one thread running, or cannot determine the number of threads, prior // one thread running, or cannot determine the number of threads, prior
// to executing the given statement. It is the responsibility of the // to executing the given statement. It is the responsibility of the
// caller not to pass a thread_count of 1. // caller not to pass a thread_count of 1.
static String DeathTestThreadWarning(size_t thread_count) { static std::string DeathTestThreadWarning(size_t thread_count) {
Message msg; Message msg;
msg << "Death tests use fork(), which is unsafe particularly" msg << "Death tests use fork(), which is unsafe particularly"
<< " in a threaded context. For this test, " << GTEST_NAME_ << " "; << " in a threaded context. For this test, " << GTEST_NAME_ << " ";
...@@ -248,7 +248,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW }; ...@@ -248,7 +248,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
// message is propagated back to the parent process. Otherwise, the // message is propagated back to the parent process. Otherwise, the
// message is simply printed to stderr. In either case, the program // message is simply printed to stderr. In either case, the program
// then exits with status 1. // then exits with status 1.
void DeathTestAbort(const String& message) { void DeathTestAbort(const std::string& message) {
// On a POSIX system, this function may be called from a threadsafe-style // On a POSIX system, this function may be called from a threadsafe-style
// death test child process, which operates on a very small stack. Use // death test child process, which operates on a very small stack. Use
// the heap for any additional non-minuscule memory requirements. // the heap for any additional non-minuscule memory requirements.
...@@ -272,7 +272,7 @@ void DeathTestAbort(const String& message) { ...@@ -272,7 +272,7 @@ void DeathTestAbort(const String& message) {
# define GTEST_DEATH_TEST_CHECK_(expression) \ # define GTEST_DEATH_TEST_CHECK_(expression) \
do { \ do { \
if (!::testing::internal::IsTrue(expression)) { \ if (!::testing::internal::IsTrue(expression)) { \
DeathTestAbort(::testing::internal::String::Format( \ DeathTestAbort(::testing::internal::String::Format( \
"CHECK failed: File %s, line %d: %s", \ "CHECK failed: File %s, line %d: %s", \
__FILE__, __LINE__, #expression)); \ __FILE__, __LINE__, #expression)); \
} \ } \
...@@ -292,15 +292,15 @@ void DeathTestAbort(const String& message) { ...@@ -292,15 +292,15 @@ void DeathTestAbort(const String& message) {
gtest_retval = (expression); \ gtest_retval = (expression); \
} while (gtest_retval == -1 && errno == EINTR); \ } while (gtest_retval == -1 && errno == EINTR); \
if (gtest_retval == -1) { \ if (gtest_retval == -1) { \
DeathTestAbort(::testing::internal::String::Format( \ DeathTestAbort(::testing::internal::String::Format( \
"CHECK failed: File %s, line %d: %s != -1", \ "CHECK failed: File %s, line %d: %s != -1", \
__FILE__, __LINE__, #expression)); \ __FILE__, __LINE__, #expression)); \
} \ } \
} while (::testing::internal::AlwaysFalse()) } while (::testing::internal::AlwaysFalse())
// Returns the message describing the last system error in errno. // Returns the message describing the last system error in errno.
String GetLastErrnoDescription() { std::string GetLastErrnoDescription() {
return String(errno == 0 ? "" : posix::StrError(errno)); return errno == 0 ? "" : posix::StrError(errno);
} }
// This is called from a death test parent process to read a failure // This is called from a death test parent process to read a failure
...@@ -350,11 +350,11 @@ const char* DeathTest::LastMessage() { ...@@ -350,11 +350,11 @@ const char* DeathTest::LastMessage() {
return last_death_test_message_.c_str(); return last_death_test_message_.c_str();
} }
void DeathTest::set_last_death_test_message(const String& message) { void DeathTest::set_last_death_test_message(const std::string& message) {
last_death_test_message_ = message; last_death_test_message_ = message;
} }
String DeathTest::last_death_test_message_; std::string DeathTest::last_death_test_message_;
// Provides cross platform implementation for some death functionality. // Provides cross platform implementation for some death functionality.
class DeathTestImpl : public DeathTest { class DeathTestImpl : public DeathTest {
...@@ -529,7 +529,7 @@ bool DeathTestImpl::Passed(bool status_ok) { ...@@ -529,7 +529,7 @@ bool DeathTestImpl::Passed(bool status_ok) {
if (!spawned()) if (!spawned())
return false; return false;
const String error_message = GetCapturedStderr(); const std::string error_message = GetCapturedStderr();
bool success = false; bool success = false;
Message buffer; Message buffer;
...@@ -711,15 +711,12 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { ...@@ -711,15 +711,12 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
FALSE, // The initial state is non-signalled. FALSE, // The initial state is non-signalled.
NULL)); // The even is unnamed. NULL)); // The even is unnamed.
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL); GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL);
const String filter_flag = String::Format("--%s%s=%s.%s", const std::string filter_flag =
GTEST_FLAG_PREFIX_, kFilterFlag, std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" +
info->test_case_name(), info->test_case_name() + "." + info->name();
info->name()); const std::string internal_flag =
const String internal_flag = String::Format( std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag +
"--%s%s=%s|%d|%d|%u|%Iu|%Iu", "=" + file_ + "|" + String::Format("%d|%d|%u|%Iu|%Iu", line_,
GTEST_FLAG_PREFIX_,
kInternalRunDeathTestFlag,
file_, line_,
death_test_index, death_test_index,
static_cast<unsigned int>(::GetCurrentProcessId()), static_cast<unsigned int>(::GetCurrentProcessId()),
// size_t has the same with as pointers on both 32-bit and 64-bit // size_t has the same with as pointers on both 32-bit and 64-bit
...@@ -734,10 +731,9 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { ...@@ -734,10 +731,9 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
executable_path, executable_path,
_MAX_PATH)); _MAX_PATH));
String command_line = String::Format("%s %s \"%s\"", std::string command_line =
::GetCommandLineA(), std::string(::GetCommandLineA()) + " " + filter_flag + " \"" +
filter_flag.c_str(), internal_flag + "\"";
internal_flag.c_str());
DeathTest::set_last_death_test_message(""); DeathTest::set_last_death_test_message("");
...@@ -954,9 +950,8 @@ static int ExecDeathTestChildMain(void* child_arg) { ...@@ -954,9 +950,8 @@ static int ExecDeathTestChildMain(void* child_arg) {
UnitTest::GetInstance()->original_working_dir(); UnitTest::GetInstance()->original_working_dir();
// We can safely call chdir() as it's a direct system call. // We can safely call chdir() as it's a direct system call.
if (chdir(original_dir) != 0) { if (chdir(original_dir) != 0) {
DeathTestAbort(String::Format("chdir(\"%s\") failed: %s", DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " +
original_dir, GetLastErrnoDescription());
GetLastErrnoDescription().c_str()));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -966,10 +961,9 @@ static int ExecDeathTestChildMain(void* child_arg) { ...@@ -966,10 +961,9 @@ static int ExecDeathTestChildMain(void* child_arg) {
// invoke the test program via a valid path that contains at least // invoke the test program via a valid path that contains at least
// one path separator. // one path separator.
execve(args->argv[0], args->argv, GetEnviron()); execve(args->argv[0], args->argv, GetEnviron());
DeathTestAbort(String::Format("execve(%s, ...) in %s failed: %s", DeathTestAbort(std::string("execve(") + args->argv[0] + ", ...) in " +
args->argv[0], original_dir + " failed: " +
original_dir, GetLastErrnoDescription());
GetLastErrnoDescription().c_str()));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
# endif // !GTEST_OS_QNX # endif // !GTEST_OS_QNX
...@@ -1020,9 +1014,8 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { ...@@ -1020,9 +1014,8 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
UnitTest::GetInstance()->original_working_dir(); UnitTest::GetInstance()->original_working_dir();
// We can safely call chdir() as it's a direct system call. // We can safely call chdir() as it's a direct system call.
if (chdir(original_dir) != 0) { if (chdir(original_dir) != 0) {
DeathTestAbort(String::Format("chdir(\"%s\") failed: %s", DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " +
original_dir, GetLastErrnoDescription());
GetLastErrnoDescription().c_str()));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -1120,11 +1113,11 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { ...@@ -1120,11 +1113,11 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
// it be closed when the child process does an exec: // it be closed when the child process does an exec:
GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1); GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
const String filter_flag = const std::string filter_flag =
String::Format("--%s%s=%s.%s", String::Format("--%s%s=%s.%s",
GTEST_FLAG_PREFIX_, kFilterFlag, GTEST_FLAG_PREFIX_, kFilterFlag,
info->test_case_name(), info->name()); info->test_case_name(), info->name());
const String internal_flag = const std::string internal_flag =
String::Format("--%s%s=%s|%d|%d|%d", String::Format("--%s%s=%s|%d|%d|%d",
GTEST_FLAG_PREFIX_, kInternalRunDeathTestFlag, GTEST_FLAG_PREFIX_, kInternalRunDeathTestFlag,
file_, line_, death_test_index, pipe_fd[1]); file_, line_, death_test_index, pipe_fd[1]);
......
...@@ -116,9 +116,10 @@ FilePath FilePath::GetCurrentDir() { ...@@ -116,9 +116,10 @@ FilePath FilePath::GetCurrentDir() {
// FilePath("dir/file"). If a case-insensitive extension is not // FilePath("dir/file"). If a case-insensitive extension is not
// found, returns a copy of the original FilePath. // found, returns a copy of the original FilePath.
FilePath FilePath::RemoveExtension(const char* extension) const { FilePath FilePath::RemoveExtension(const char* extension) const {
String dot_extension(String::Format(".%s", extension)); const std::string dot_extension = std::string(".") + extension;
if (pathname_.EndsWithCaseInsensitive(dot_extension.c_str())) { if (String::EndsWithCaseInsensitive(pathname_, dot_extension)) {
return FilePath(String(pathname_.c_str(), pathname_.length() - 4)); return FilePath(pathname_.substr(
0, pathname_.length() - dot_extension.length()));
} }
return *this; return *this;
} }
...@@ -147,7 +148,7 @@ const char* FilePath::FindLastPathSeparator() const { ...@@ -147,7 +148,7 @@ const char* FilePath::FindLastPathSeparator() const {
// On Windows platform, '\' is the path separator, otherwise it is '/'. // On Windows platform, '\' is the path separator, otherwise it is '/'.
FilePath FilePath::RemoveDirectoryName() const { FilePath FilePath::RemoveDirectoryName() const {
const char* const last_sep = FindLastPathSeparator(); const char* const last_sep = FindLastPathSeparator();
return last_sep ? FilePath(String(last_sep + 1)) : *this; return last_sep ? FilePath(last_sep + 1) : *this;
} }
// RemoveFileName returns the directory path with the filename removed. // RemoveFileName returns the directory path with the filename removed.
...@@ -158,9 +159,9 @@ FilePath FilePath::RemoveDirectoryName() const { ...@@ -158,9 +159,9 @@ FilePath FilePath::RemoveDirectoryName() const {
// On Windows platform, '\' is the path separator, otherwise it is '/'. // On Windows platform, '\' is the path separator, otherwise it is '/'.
FilePath FilePath::RemoveFileName() const { FilePath FilePath::RemoveFileName() const {
const char* const last_sep = FindLastPathSeparator(); const char* const last_sep = FindLastPathSeparator();
String dir; std::string dir;
if (last_sep) { if (last_sep) {
dir = String(c_str(), last_sep + 1 - c_str()); dir = std::string(c_str(), last_sep + 1 - c_str());
} else { } else {
dir = kCurrentDirectoryString; dir = kCurrentDirectoryString;
} }
...@@ -177,11 +178,12 @@ FilePath FilePath::MakeFileName(const FilePath& directory, ...@@ -177,11 +178,12 @@ FilePath FilePath::MakeFileName(const FilePath& directory,
const FilePath& base_name, const FilePath& base_name,
int number, int number,
const char* extension) { const char* extension) {
String file; std::string file;
if (number == 0) { if (number == 0) {
file = String::Format("%s.%s", base_name.c_str(), extension); file = base_name.string() + "." + extension;
} else { } else {
file = String::Format("%s_%d.%s", base_name.c_str(), number, extension); file = base_name.string() + "_" + String::Format("%d", number).c_str()
+ "." + extension;
} }
return ConcatPaths(directory, FilePath(file)); return ConcatPaths(directory, FilePath(file));
} }
...@@ -193,8 +195,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory, ...@@ -193,8 +195,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory,
if (directory.IsEmpty()) if (directory.IsEmpty())
return relative_path; return relative_path;
const FilePath dir(directory.RemoveTrailingPathSeparator()); const FilePath dir(directory.RemoveTrailingPathSeparator());
return FilePath(String::Format("%s%c%s", dir.c_str(), kPathSeparator, return FilePath(dir.string() + kPathSeparator + relative_path.string());
relative_path.c_str()));
} }
// Returns true if pathname describes something findable in the file-system, // Returns true if pathname describes something findable in the file-system,
...@@ -338,7 +339,7 @@ bool FilePath::CreateFolder() const { ...@@ -338,7 +339,7 @@ bool FilePath::CreateFolder() const {
// On Windows platform, uses \ as the separator, other platforms use /. // On Windows platform, uses \ as the separator, other platforms use /.
FilePath FilePath::RemoveTrailingPathSeparator() const { FilePath FilePath::RemoveTrailingPathSeparator() const {
return IsDirectory() return IsDirectory()
? FilePath(String(pathname_.c_str(), pathname_.length() - 1)) ? FilePath(pathname_.substr(0, pathname_.length() - 1))
: *this; : *this;
} }
......
...@@ -202,20 +202,20 @@ class GTestFlagSaver { ...@@ -202,20 +202,20 @@ class GTestFlagSaver {
bool also_run_disabled_tests_; bool also_run_disabled_tests_;
bool break_on_failure_; bool break_on_failure_;
bool catch_exceptions_; bool catch_exceptions_;
String color_; std::string color_;
String death_test_style_; std::string death_test_style_;
bool death_test_use_fork_; bool death_test_use_fork_;
String filter_; std::string filter_;
String internal_run_death_test_; std::string internal_run_death_test_;
bool list_tests_; bool list_tests_;
String output_; std::string output_;
bool print_time_; bool print_time_;
bool pretty_; bool pretty_;
internal::Int32 random_seed_; internal::Int32 random_seed_;
internal::Int32 repeat_; internal::Int32 repeat_;
bool shuffle_; bool shuffle_;
internal::Int32 stack_trace_depth_; internal::Int32 stack_trace_depth_;
String stream_result_to_; std::string stream_result_to_;
bool throw_on_failure_; bool throw_on_failure_;
} GTEST_ATTRIBUTE_UNUSED_; } GTEST_ATTRIBUTE_UNUSED_;
...@@ -242,7 +242,7 @@ GTEST_API_ char* CodePointToUtf8(UInt32 code_point, char* str); ...@@ -242,7 +242,7 @@ GTEST_API_ char* CodePointToUtf8(UInt32 code_point, char* str);
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding // as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
// and contains invalid UTF-16 surrogate pairs, values in those pairs // and contains invalid UTF-16 surrogate pairs, values in those pairs
// will be encoded as individual Unicode characters from Basic Normal Plane. // will be encoded as individual Unicode characters from Basic Normal Plane.
GTEST_API_ String WideStringToUtf8(const wchar_t* str, int num_chars); GTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars);
// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file // Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
// if the variable is present. If a file already exists at this location, this // if the variable is present. If a file already exists at this location, this
...@@ -351,11 +351,11 @@ class TestPropertyKeyIs { ...@@ -351,11 +351,11 @@ class TestPropertyKeyIs {
// Returns true iff the test name of test property matches on key_. // Returns true iff the test name of test property matches on key_.
bool operator()(const TestProperty& test_property) const { bool operator()(const TestProperty& test_property) const {
return String(test_property.key()).Compare(key_) == 0; return test_property.key() == key_;
} }
private: private:
String key_; std::string key_;
}; };
// Class UnitTestOptions. // Class UnitTestOptions.
...@@ -373,12 +373,12 @@ class GTEST_API_ UnitTestOptions { ...@@ -373,12 +373,12 @@ class GTEST_API_ UnitTestOptions {
// Functions for processing the gtest_output flag. // Functions for processing the gtest_output flag.
// Returns the output format, or "" for normal printed output. // Returns the output format, or "" for normal printed output.
static String GetOutputFormat(); static std::string GetOutputFormat();
// Returns the absolute path of the requested output file, or the // Returns the absolute path of the requested output file, or the
// default (test_detail.xml in the original working directory) if // default (test_detail.xml in the original working directory) if
// none was explicitly specified. // none was explicitly specified.
static String GetAbsolutePathToOutputFile(); static std::string GetAbsolutePathToOutputFile();
// Functions for processing the gtest_filter flag. // Functions for processing the gtest_filter flag.
...@@ -391,8 +391,8 @@ class GTEST_API_ UnitTestOptions { ...@@ -391,8 +391,8 @@ class GTEST_API_ UnitTestOptions {
// Returns true iff the user-specified filter matches the test case // Returns true iff the user-specified filter matches the test case
// name and the test name. // name and the test name.
static bool FilterMatchesTest(const String &test_case_name, static bool FilterMatchesTest(const std::string &test_case_name,
const String &test_name); const std::string &test_name);
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// Function for supporting the gtest_catch_exception flag. // Function for supporting the gtest_catch_exception flag.
...@@ -405,7 +405,7 @@ class GTEST_API_ UnitTestOptions { ...@@ -405,7 +405,7 @@ class GTEST_API_ UnitTestOptions {
// Returns true if "name" matches the ':' separated list of glob-style // Returns true if "name" matches the ':' separated list of glob-style
// filters in "filter". // filters in "filter".
static bool MatchesFilter(const String& name, const char* filter); static bool MatchesFilter(const std::string& name, const char* filter);
}; };
// Returns the current application's name, removing directory path if that // Returns the current application's name, removing directory path if that
...@@ -418,13 +418,13 @@ class OsStackTraceGetterInterface { ...@@ -418,13 +418,13 @@ class OsStackTraceGetterInterface {
OsStackTraceGetterInterface() {} OsStackTraceGetterInterface() {}
virtual ~OsStackTraceGetterInterface() {} virtual ~OsStackTraceGetterInterface() {}
// Returns the current OS stack trace as a String. Parameters: // Returns the current OS stack trace as an std::string. Parameters:
// //
// max_depth - the maximum number of stack frames to be included // max_depth - the maximum number of stack frames to be included
// in the trace. // in the trace.
// skip_count - the number of top frames to be skipped; doesn't count // skip_count - the number of top frames to be skipped; doesn't count
// against max_depth. // against max_depth.
virtual String CurrentStackTrace(int max_depth, int skip_count) = 0; virtual string CurrentStackTrace(int max_depth, int skip_count) = 0;
// UponLeavingGTest() should be called immediately before Google Test calls // UponLeavingGTest() should be called immediately before Google Test calls
// user code. It saves some information about the current stack that // user code. It saves some information about the current stack that
...@@ -440,7 +440,7 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface { ...@@ -440,7 +440,7 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface {
public: public:
OsStackTraceGetter() : caller_frame_(NULL) {} OsStackTraceGetter() : caller_frame_(NULL) {}
virtual String CurrentStackTrace(int max_depth, int skip_count) virtual string CurrentStackTrace(int max_depth, int skip_count)
GTEST_LOCK_EXCLUDED_(mutex_); GTEST_LOCK_EXCLUDED_(mutex_);
virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_); virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_);
...@@ -465,7 +465,7 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface { ...@@ -465,7 +465,7 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface {
struct TraceInfo { struct TraceInfo {
const char* file; const char* file;
int line; int line;
String message; std::string message;
}; };
// This is the default global test part result reporter used in UnitTestImpl. // This is the default global test part result reporter used in UnitTestImpl.
...@@ -610,7 +610,7 @@ class GTEST_API_ UnitTestImpl { ...@@ -610,7 +610,7 @@ class GTEST_API_ UnitTestImpl {
// getter, and returns it. // getter, and returns it.
OsStackTraceGetterInterface* os_stack_trace_getter(); OsStackTraceGetterInterface* os_stack_trace_getter();
// Returns the current OS stack trace as a String. // Returns the current OS stack trace as an std::string.
// //
// The maximum number of stack frames to be included is specified by // The maximum number of stack frames to be included is specified by
// the gtest_stack_trace_depth flag. The skip_count parameter // the gtest_stack_trace_depth flag. The skip_count parameter
...@@ -620,7 +620,7 @@ class GTEST_API_ UnitTestImpl { ...@@ -620,7 +620,7 @@ class GTEST_API_ UnitTestImpl {
// For example, if Foo() calls Bar(), which in turn calls // For example, if Foo() calls Bar(), which in turn calls
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
// trace but Bar() and CurrentOsStackTraceExceptTop() won't. // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
String CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_; std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
// Finds and returns a TestCase with the given name. If one doesn't // Finds and returns a TestCase with the given name. If one doesn't
// exist, creates one and returns it. // exist, creates one and returns it.
...@@ -953,7 +953,7 @@ GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv); ...@@ -953,7 +953,7 @@ GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
// Returns the message describing the last system error, regardless of the // Returns the message describing the last system error, regardless of the
// platform. // platform.
GTEST_API_ String GetLastErrnoDescription(); GTEST_API_ std::string GetLastErrnoDescription();
# if GTEST_OS_WINDOWS # if GTEST_OS_WINDOWS
// Provides leak-safe Windows kernel handle ownership. // Provides leak-safe Windows kernel handle ownership.
......
...@@ -247,7 +247,7 @@ bool AtomMatchesChar(bool escaped, char pattern_char, char ch) { ...@@ -247,7 +247,7 @@ bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
} }
// Helper function used by ValidateRegex() to format error messages. // Helper function used by ValidateRegex() to format error messages.
String FormatRegexSyntaxError(const char* regex, int index) { std::string FormatRegexSyntaxError(const char* regex, int index) {
return (Message() << "Syntax error at index " << index return (Message() << "Syntax error at index " << index
<< " in simple regular expression \"" << regex << "\": ").GetString(); << " in simple regular expression \"" << regex << "\": ").GetString();
} }
...@@ -513,7 +513,7 @@ GTestLog::~GTestLog() { ...@@ -513,7 +513,7 @@ GTestLog::~GTestLog() {
class CapturedStream { class CapturedStream {
public: public:
// The ctor redirects the stream to a temporary file. // The ctor redirects the stream to a temporary file.
CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
# if GTEST_OS_WINDOWS # if GTEST_OS_WINDOWS
char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT
char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT
...@@ -565,7 +565,7 @@ class CapturedStream { ...@@ -565,7 +565,7 @@ class CapturedStream {
remove(filename_.c_str()); remove(filename_.c_str());
} }
String GetCapturedString() { std::string GetCapturedString() {
if (uncaptured_fd_ != -1) { if (uncaptured_fd_ != -1) {
// Restores the original stream. // Restores the original stream.
fflush(NULL); fflush(NULL);
...@@ -575,14 +575,14 @@ class CapturedStream { ...@@ -575,14 +575,14 @@ class CapturedStream {
} }
FILE* const file = posix::FOpen(filename_.c_str(), "r"); FILE* const file = posix::FOpen(filename_.c_str(), "r");
const String content = ReadEntireFile(file); const std::string content = ReadEntireFile(file);
posix::FClose(file); posix::FClose(file);
return content; return content;
} }
private: private:
// Reads the entire content of a file as a String. // Reads the entire content of a file as an std::string.
static String ReadEntireFile(FILE* file); static std::string ReadEntireFile(FILE* file);
// Returns the size (in bytes) of a file. // Returns the size (in bytes) of a file.
static size_t GetFileSize(FILE* file); static size_t GetFileSize(FILE* file);
...@@ -602,7 +602,7 @@ size_t CapturedStream::GetFileSize(FILE* file) { ...@@ -602,7 +602,7 @@ size_t CapturedStream::GetFileSize(FILE* file) {
} }
// Reads the entire content of a file as a string. // Reads the entire content of a file as a string.
String CapturedStream::ReadEntireFile(FILE* file) { std::string CapturedStream::ReadEntireFile(FILE* file) {
const size_t file_size = GetFileSize(file); const size_t file_size = GetFileSize(file);
char* const buffer = new char[file_size]; char* const buffer = new char[file_size];
...@@ -618,7 +618,7 @@ String CapturedStream::ReadEntireFile(FILE* file) { ...@@ -618,7 +618,7 @@ String CapturedStream::ReadEntireFile(FILE* file) {
bytes_read += bytes_last_read; bytes_read += bytes_last_read;
} while (bytes_last_read > 0 && bytes_read < file_size); } while (bytes_last_read > 0 && bytes_read < file_size);
const String content(buffer, bytes_read); const std::string content(buffer, bytes_read);
delete[] buffer; delete[] buffer;
return content; return content;
...@@ -641,8 +641,8 @@ void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) { ...@@ -641,8 +641,8 @@ void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {
} }
// Stops capturing the output stream and returns the captured string. // Stops capturing the output stream and returns the captured string.
String GetCapturedStream(CapturedStream** captured_stream) { std::string GetCapturedStream(CapturedStream** captured_stream) {
const String content = (*captured_stream)->GetCapturedString(); const std::string content = (*captured_stream)->GetCapturedString();
delete *captured_stream; delete *captured_stream;
*captured_stream = NULL; *captured_stream = NULL;
...@@ -661,10 +661,14 @@ void CaptureStderr() { ...@@ -661,10 +661,14 @@ void CaptureStderr() {
} }
// Stops capturing stdout and returns the captured string. // Stops capturing stdout and returns the captured string.
String GetCapturedStdout() { return GetCapturedStream(&g_captured_stdout); } std::string GetCapturedStdout() {
return GetCapturedStream(&g_captured_stdout);
}
// Stops capturing stderr and returns the captured string. // Stops capturing stderr and returns the captured string.
String GetCapturedStderr() { return GetCapturedStream(&g_captured_stderr); } std::string GetCapturedStderr() {
return GetCapturedStream(&g_captured_stderr);
}
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
...@@ -702,8 +706,8 @@ void Abort() { ...@@ -702,8 +706,8 @@ void Abort() {
// Returns the name of the environment variable corresponding to the // Returns the name of the environment variable corresponding to the
// given flag. For example, FlagToEnvVar("foo") will return // given flag. For example, FlagToEnvVar("foo") will return
// "GTEST_FOO" in the open-source version. // "GTEST_FOO" in the open-source version.
static String FlagToEnvVar(const char* flag) { static std::string FlagToEnvVar(const char* flag) {
const String full_flag = const std::string full_flag =
(Message() << GTEST_FLAG_PREFIX_ << flag).GetString(); (Message() << GTEST_FLAG_PREFIX_ << flag).GetString();
Message env_var; Message env_var;
...@@ -760,7 +764,7 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) { ...@@ -760,7 +764,7 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
// //
// The value is considered true iff it's not "0". // The value is considered true iff it's not "0".
bool BoolFromGTestEnv(const char* flag, bool default_value) { bool BoolFromGTestEnv(const char* flag, bool default_value) {
const 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 == NULL ?
default_value : strcmp(string_value, "0") != 0; default_value : strcmp(string_value, "0") != 0;
...@@ -770,7 +774,7 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) { ...@@ -770,7 +774,7 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
// variable corresponding to the given flag; if it isn't set or // variable corresponding to the given flag; if it isn't set or
// doesn't represent a valid 32-bit integer, returns default_value. // doesn't represent a valid 32-bit integer, returns default_value.
Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
const 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 == NULL) {
// The environment variable is not set. // The environment variable is not set.
...@@ -792,7 +796,7 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { ...@@ -792,7 +796,7 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
// Reads and returns the string environment variable corresponding to // Reads and returns the string environment variable corresponding to
// the given flag; if it's not set, returns default_value. // the given flag; if it's not set, returns default_value.
const char* StringFromGTestEnv(const char* flag, const char* default_value) { const char* StringFromGTestEnv(const char* flag, const char* default_value) {
const 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 == NULL ? default_value : value;
} }
......
...@@ -48,10 +48,10 @@ using internal::GetUnitTestImpl; ...@@ -48,10 +48,10 @@ using internal::GetUnitTestImpl;
// Gets the summary of the failure message by omitting the stack trace // Gets the summary of the failure message by omitting the stack trace
// in it. // in it.
internal::String TestPartResult::ExtractSummary(const char* message) { std::string TestPartResult::ExtractSummary(const char* message) {
const char* const stack_trace = strstr(message, internal::kStackTraceMarker); const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
return stack_trace == NULL ? internal::String(message) : return stack_trace == NULL ? message :
internal::String(message, stack_trace - message); std::string(message, stack_trace);
} }
// Prints a TestPartResult object. // Prints a TestPartResult object.
......
...@@ -58,10 +58,10 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames( ...@@ -58,10 +58,10 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
registered_tests = SkipSpaces(registered_tests); registered_tests = SkipSpaces(registered_tests);
Message errors; Message errors;
::std::set<String> tests; ::std::set<std::string> tests;
for (const char* names = registered_tests; names != NULL; for (const char* names = registered_tests; names != NULL;
names = SkipComma(names)) { names = SkipComma(names)) {
const String name = GetPrefixUntilComma(names); const std::string name = GetPrefixUntilComma(names);
if (tests.count(name) != 0) { if (tests.count(name) != 0) {
errors << "Test " << name << " is listed more than once.\n"; errors << "Test " << name << " is listed more than once.\n";
continue; continue;
...@@ -93,7 +93,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames( ...@@ -93,7 +93,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
} }
} }
const String& errors_str = errors.GetString(); const std::string& errors_str = errors.GetString();
if (errors_str != "") { if (errors_str != "") {
fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
errors_str.c_str()); errors_str.c_str());
......
This diff is collapsed.
...@@ -77,7 +77,6 @@ using testing::internal::GetLastErrnoDescription; ...@@ -77,7 +77,6 @@ using testing::internal::GetLastErrnoDescription;
using testing::internal::GetUnitTestImpl; using testing::internal::GetUnitTestImpl;
using testing::internal::InDeathTestChild; using testing::internal::InDeathTestChild;
using testing::internal::ParseNaturalNumber; using testing::internal::ParseNaturalNumber;
using testing::internal::String;
namespace testing { namespace testing {
namespace internal { namespace internal {
...@@ -1139,26 +1138,26 @@ TEST(ParseNaturalNumberTest, RejectsInvalidFormat) { ...@@ -1139,26 +1138,26 @@ TEST(ParseNaturalNumberTest, RejectsInvalidFormat) {
BiggestParsable result = 0; BiggestParsable result = 0;
// Rejects non-numbers. // Rejects non-numbers.
EXPECT_FALSE(ParseNaturalNumber(String("non-number string"), &result)); EXPECT_FALSE(ParseNaturalNumber("non-number string", &result));
// Rejects numbers with whitespace prefix. // Rejects numbers with whitespace prefix.
EXPECT_FALSE(ParseNaturalNumber(String(" 123"), &result)); EXPECT_FALSE(ParseNaturalNumber(" 123", &result));
// Rejects negative numbers. // Rejects negative numbers.
EXPECT_FALSE(ParseNaturalNumber(String("-123"), &result)); EXPECT_FALSE(ParseNaturalNumber("-123", &result));
// Rejects numbers starting with a plus sign. // Rejects numbers starting with a plus sign.
EXPECT_FALSE(ParseNaturalNumber(String("+123"), &result)); EXPECT_FALSE(ParseNaturalNumber("+123", &result));
errno = 0; errno = 0;
} }
TEST(ParseNaturalNumberTest, RejectsOverflownNumbers) { TEST(ParseNaturalNumberTest, RejectsOverflownNumbers) {
BiggestParsable result = 0; BiggestParsable result = 0;
EXPECT_FALSE(ParseNaturalNumber(String("99999999999999999999999"), &result)); EXPECT_FALSE(ParseNaturalNumber("99999999999999999999999", &result));
signed char char_result = 0; signed char char_result = 0;
EXPECT_FALSE(ParseNaturalNumber(String("200"), &char_result)); EXPECT_FALSE(ParseNaturalNumber("200", &char_result));
errno = 0; errno = 0;
} }
...@@ -1166,16 +1165,16 @@ TEST(ParseNaturalNumberTest, AcceptsValidNumbers) { ...@@ -1166,16 +1165,16 @@ TEST(ParseNaturalNumberTest, AcceptsValidNumbers) {
BiggestParsable result = 0; BiggestParsable result = 0;
result = 0; result = 0;
ASSERT_TRUE(ParseNaturalNumber(String("123"), &result)); ASSERT_TRUE(ParseNaturalNumber("123", &result));
EXPECT_EQ(123U, result); EXPECT_EQ(123U, result);
// Check 0 as an edge case. // Check 0 as an edge case.
result = 1; result = 1;
ASSERT_TRUE(ParseNaturalNumber(String("0"), &result)); ASSERT_TRUE(ParseNaturalNumber("0", &result));
EXPECT_EQ(0U, result); EXPECT_EQ(0U, result);
result = 1; result = 1;
ASSERT_TRUE(ParseNaturalNumber(String("00000"), &result)); ASSERT_TRUE(ParseNaturalNumber("00000", &result));
EXPECT_EQ(0U, result); EXPECT_EQ(0U, result);
} }
...@@ -1211,11 +1210,11 @@ TEST(ParseNaturalNumberTest, AcceptsTypeLimits) { ...@@ -1211,11 +1210,11 @@ TEST(ParseNaturalNumberTest, AcceptsTypeLimits) {
TEST(ParseNaturalNumberTest, WorksForShorterIntegers) { TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
short short_result = 0; short short_result = 0;
ASSERT_TRUE(ParseNaturalNumber(String("123"), &short_result)); ASSERT_TRUE(ParseNaturalNumber("123", &short_result));
EXPECT_EQ(123, short_result); EXPECT_EQ(123, short_result);
signed char char_result = 0; signed char char_result = 0;
ASSERT_TRUE(ParseNaturalNumber(String("123"), &char_result)); ASSERT_TRUE(ParseNaturalNumber("123", &char_result));
EXPECT_EQ(123, char_result); EXPECT_EQ(123, char_result);
} }
...@@ -1245,7 +1244,6 @@ TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) { ...@@ -1245,7 +1244,6 @@ TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
using testing::internal::CaptureStderr; using testing::internal::CaptureStderr;
using testing::internal::GetCapturedStderr; using testing::internal::GetCapturedStderr;
using testing::internal::String;
// Tests that EXPECT_DEATH_IF_SUPPORTED/ASSERT_DEATH_IF_SUPPORTED are still // Tests that EXPECT_DEATH_IF_SUPPORTED/ASSERT_DEATH_IF_SUPPORTED are still
// defined but do not trigger failures when death tests are not available on // defined but do not trigger failures when death tests are not available on
...@@ -1255,7 +1253,7 @@ TEST(ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable) { ...@@ -1255,7 +1253,7 @@ TEST(ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable) {
// when death tests are not supported. // when death tests are not supported.
CaptureStderr(); CaptureStderr();
EXPECT_DEATH_IF_SUPPORTED(;, ""); EXPECT_DEATH_IF_SUPPORTED(;, "");
String output = GetCapturedStderr(); std::string output = GetCapturedStderr();
ASSERT_TRUE(NULL != strstr(output.c_str(), ASSERT_TRUE(NULL != strstr(output.c_str(),
"Death tests are not supported on this platform")); "Death tests are not supported on this platform"));
ASSERT_TRUE(NULL != strstr(output.c_str(), ";")); ASSERT_TRUE(NULL != strstr(output.c_str(), ";"));
......
This diff is collapsed.
...@@ -45,10 +45,9 @@ using ::testing::TestEventListener; ...@@ -45,10 +45,9 @@ using ::testing::TestEventListener;
using ::testing::TestInfo; using ::testing::TestInfo;
using ::testing::TestPartResult; using ::testing::TestPartResult;
using ::testing::UnitTest; using ::testing::UnitTest;
using ::testing::internal::String;
// Used by tests to register their events. // Used by tests to register their events.
std::vector<String>* g_events = NULL; std::vector<std::string>* g_events = NULL;
namespace testing { namespace testing {
namespace internal { namespace internal {
...@@ -119,54 +118,52 @@ class EventRecordingListener : public TestEventListener { ...@@ -119,54 +118,52 @@ class EventRecordingListener : public TestEventListener {
} }
private: private:
String GetFullMethodName(const char* name) { std::string GetFullMethodName(const char* name) {
Message message; return name_ + "." + name;
message << name_ << "." << name;
return message.GetString();
} }
String name_; std::string name_;
}; };
class EnvironmentInvocationCatcher : public Environment { class EnvironmentInvocationCatcher : public Environment {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
g_events->push_back(String("Environment::SetUp")); g_events->push_back("Environment::SetUp");
} }
virtual void TearDown() { virtual void TearDown() {
g_events->push_back(String("Environment::TearDown")); g_events->push_back("Environment::TearDown");
} }
}; };
class ListenerTest : public Test { class ListenerTest : public Test {
protected: protected:
static void SetUpTestCase() { static void SetUpTestCase() {
g_events->push_back(String("ListenerTest::SetUpTestCase")); g_events->push_back("ListenerTest::SetUpTestCase");
} }
static void TearDownTestCase() { static void TearDownTestCase() {
g_events->push_back(String("ListenerTest::TearDownTestCase")); g_events->push_back("ListenerTest::TearDownTestCase");
} }
virtual void SetUp() { virtual void SetUp() {
g_events->push_back(String("ListenerTest::SetUp")); g_events->push_back("ListenerTest::SetUp");
} }
virtual void TearDown() { virtual void TearDown() {
g_events->push_back(String("ListenerTest::TearDown")); g_events->push_back("ListenerTest::TearDown");
} }
}; };
TEST_F(ListenerTest, DoesFoo) { TEST_F(ListenerTest, DoesFoo) {
// Test execution order within a test case is not guaranteed so we are not // Test execution order within a test case is not guaranteed so we are not
// recording the test name. // recording the test name.
g_events->push_back(String("ListenerTest::* Test Body")); g_events->push_back("ListenerTest::* Test Body");
SUCCEED(); // Triggers OnTestPartResult. SUCCEED(); // Triggers OnTestPartResult.
} }
TEST_F(ListenerTest, DoesBar) { TEST_F(ListenerTest, DoesBar) {
g_events->push_back(String("ListenerTest::* Test Body")); g_events->push_back("ListenerTest::* Test Body");
SUCCEED(); // Triggers OnTestPartResult. SUCCEED(); // Triggers OnTestPartResult.
} }
...@@ -177,7 +174,7 @@ TEST_F(ListenerTest, DoesBar) { ...@@ -177,7 +174,7 @@ TEST_F(ListenerTest, DoesBar) {
using ::testing::internal::EnvironmentInvocationCatcher; using ::testing::internal::EnvironmentInvocationCatcher;
using ::testing::internal::EventRecordingListener; using ::testing::internal::EventRecordingListener;
void VerifyResults(const std::vector<String>& data, void VerifyResults(const std::vector<std::string>& data,
const char* const* expected_data, const char* const* expected_data,
int expected_data_size) { int expected_data_size) {
const int actual_size = data.size(); const int actual_size = data.size();
...@@ -201,7 +198,7 @@ void VerifyResults(const std::vector<String>& data, ...@@ -201,7 +198,7 @@ void VerifyResults(const std::vector<String>& data,
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
std::vector<String> events; std::vector<std::string> events;
g_events = &events; g_events = &events;
InitGoogleTest(&argc, argv); InitGoogleTest(&argc, argv);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment