summaryrefslogtreecommitdiff
path: root/src/gtest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gtest.cc')
-rw-r--r--src/gtest.cc312
1 files changed, 120 insertions, 192 deletions
diff --git a/src/gtest.cc b/src/gtest.cc
index 3b5a28b..0567e83 100644
--- a/src/gtest.cc
+++ b/src/gtest.cc
@@ -364,7 +364,7 @@ void AssertHelper::operator=(const Message& message) const {
GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex);
// Application pathname gotten in InitGoogleTest.
-String g_executable_path;
+std::string g_executable_path;
// Returns the current application's name, removing directory path if that
// is present.
@@ -383,29 +383,29 @@ FilePath GetCurrentExecutableName() {
// Functions for processing the gtest_output flag.
// Returns the output format, or "" for normal printed output.
-String UnitTestOptions::GetOutputFormat() {
+std::string UnitTestOptions::GetOutputFormat() {
const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
- if (gtest_output_flag == NULL) return String("");
+ if (gtest_output_flag == NULL) return std::string("");
const char* const colon = strchr(gtest_output_flag, ':');
return (colon == NULL) ?
- String(gtest_output_flag) :
- String(gtest_output_flag, colon - gtest_output_flag);
+ std::string(gtest_output_flag) :
+ std::string(gtest_output_flag, colon - gtest_output_flag);
}
// Returns the name of the requested output file, or the default if none
// was explicitly specified.
-String UnitTestOptions::GetAbsolutePathToOutputFile() {
+std::string UnitTestOptions::GetAbsolutePathToOutputFile() {
const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
if (gtest_output_flag == NULL)
- return String("");
+ return "";
const char* const colon = strchr(gtest_output_flag, ':');
if (colon == NULL)
- return String(internal::FilePath::ConcatPaths(
- internal::FilePath(
- UnitTest::GetInstance()->original_working_dir()),
- internal::FilePath(kDefaultOutputFile)).ToString() );
+ return internal::FilePath::ConcatPaths(
+ internal::FilePath(
+ UnitTest::GetInstance()->original_working_dir()),
+ internal::FilePath(kDefaultOutputFile)).string();
internal::FilePath output_name(colon + 1);
if (!output_name.IsAbsolutePath())
@@ -418,12 +418,12 @@ String UnitTestOptions::GetAbsolutePathToOutputFile() {
internal::FilePath(colon + 1));
if (!output_name.IsDirectory())
- return output_name.ToString();
+ return output_name.string();
internal::FilePath result(internal::FilePath::GenerateUniqueFileName(
output_name, internal::GetCurrentExecutableName(),
GetOutputFormat().c_str()));
- return result.ToString();
+ return result.string();
}
// Returns true iff the wildcard pattern matches the string. The
@@ -448,7 +448,8 @@ bool UnitTestOptions::PatternMatchesString(const char *pattern,
}
}
-bool UnitTestOptions::MatchesFilter(const String& name, const char* filter) {
+bool UnitTestOptions::MatchesFilter(
+ const std::string& name, const char* filter) {
const char *cur_pattern = filter;
for (;;) {
if (PatternMatchesString(cur_pattern, name.c_str())) {
@@ -468,28 +469,24 @@ bool UnitTestOptions::MatchesFilter(const String& name, const char* filter) {
}
}
-// TODO(keithray): move String function implementations to gtest-string.cc.
-
// Returns true iff the user-specified filter matches the test case
// name and the test name.
-bool UnitTestOptions::FilterMatchesTest(const String &test_case_name,
- const String &test_name) {
- const String& full_name = String::Format("%s.%s",
- test_case_name.c_str(),
- test_name.c_str());
+bool UnitTestOptions::FilterMatchesTest(const std::string &test_case_name,
+ const std::string &test_name) {
+ const std::string& full_name = test_case_name + "." + test_name.c_str();
// Split --gtest_filter at '-', if there is one, to separate into
// positive filter and negative filter portions
const char* const p = GTEST_FLAG(filter).c_str();
const char* const dash = strchr(p, '-');
- String positive;
- String negative;
+ std::string positive;
+ std::string negative;
if (dash == NULL) {
positive = GTEST_FLAG(filter).c_str(); // Whole string is a positive filter
- negative = String("");
+ negative = "";
} else {
- positive = String(p, dash - p); // Everything up to the dash
- negative = String(dash+1); // Everything after the dash
+ positive = std::string(p, dash); // Everything up to the dash
+ negative = std::string(dash + 1); // Everything after the dash
if (positive.empty()) {
// Treat '-test1' as the same as '*-test1'
positive = kUniversalFilter;
@@ -609,7 +606,7 @@ AssertionResult HasOneFailure(const char* /* results_expr */,
const TestPartResultArray& results,
TestPartResult::Type type,
const string& substr) {
- const String expected(type == TestPartResult::kFatalFailure ?
+ const std::string expected(type == TestPartResult::kFatalFailure ?
"1 fatal failure" :
"1 non-fatal failure");
Message msg;
@@ -747,7 +744,7 @@ int UnitTestImpl::test_to_run_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::test_to_run_count);
}
-// 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 gtest_stack_trace_depth flag. The skip_count parameter
@@ -757,9 +754,9 @@ int UnitTestImpl::test_to_run_count() const {
// For example, if Foo() calls Bar(), which in turn calls
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
-String UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
+std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
(void)skip_count;
- return String("");
+ return "";
}
// Returns the current time in milliseconds.
@@ -816,30 +813,7 @@ TimeInMillis GetTimeInMillis() {
// Utilities
-// class String
-
-// Copies at most length characters from str into a newly-allocated
-// piece of memory of size length+1. The memory is allocated with new[].
-// A terminating null byte is written to the memory, and a pointer to it
-// is returned. If str is NULL, NULL is returned.
-static char* CloneString(const char* str, size_t length) {
- if (str == NULL) {
- return NULL;
- } else {
- char* const clone = new char[length + 1];
- posix::StrNCpy(clone, str, length);
- clone[length] = '\0';
- return clone;
- }
-}
-
-// Clones a 0-terminated C string, allocating memory using new. The
-// caller is responsible for deleting[] the return value. Returns the
-// cloned string, or NULL if the input is NULL.
-const char * String::CloneCString(const char* c_str) {
- return (c_str == NULL) ?
- NULL : CloneString(c_str, strlen(c_str));
-}
+// class String.
#if GTEST_OS_WINDOWS_MOBILE
// Creates a UTF-16 wide string from the given ANSI string, allocating
@@ -896,11 +870,6 @@ bool String::CStringEquals(const char * lhs, const char * rhs) {
// encoding, and streams the result to the given Message object.
static void StreamWideCharsToMessage(const wchar_t* wstr, size_t length,
Message* msg) {
- // TODO(wan): consider allowing a testing::String object to
- // contain '\0'. This will make it behave more like std::string,
- // and will allow ToUtf8String() to return the correct encoding
- // for '\0' s.t. we can get rid of the conditional here (and in
- // several other places).
for (size_t i = 0; i != length; ) { // NOLINT
if (wstr[i] != L'\0') {
*msg << WideStringToUtf8(wstr + i, static_cast<int>(length - i));
@@ -987,8 +956,8 @@ namespace internal {
// be inserted into the message.
AssertionResult EqFailure(const char* expected_expression,
const char* actual_expression,
- const String& expected_value,
- const String& actual_value,
+ const std::string& expected_value,
+ const std::string& actual_value,
bool ignoring_case) {
Message msg;
msg << "Value of: " << actual_expression;
@@ -1008,10 +977,11 @@ AssertionResult EqFailure(const char* expected_expression,
}
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
-String GetBoolAssertionFailureMessage(const AssertionResult& assertion_result,
- const char* expression_text,
- const char* actual_predicate_value,
- const char* expected_predicate_value) {
+std::string GetBoolAssertionFailureMessage(
+ const AssertionResult& assertion_result,
+ const char* expression_text,
+ const char* actual_predicate_value,
+ const char* expected_predicate_value) {
const char* actual_message = assertion_result.message();
Message msg;
msg << "Value of: " << expression_text
@@ -1357,7 +1327,7 @@ AssertionResult HRESULTFailureHelper(const char* expr,
# endif // GTEST_OS_WINDOWS_MOBILE
- const String error_hex(String::Format("0x%08X ", hr));
+ const std::string error_hex(String::Format("0x%08X ", hr));
return ::testing::AssertionFailure()
<< "Expected: " << expr << " " << expected << ".\n"
<< " Actual: " << error_hex << error_text << "\n";
@@ -1491,7 +1461,7 @@ inline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first,
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
// and contains invalid UTF-16 surrogate pairs, values in those pairs
// will be encoded as individual Unicode characters from Basic Normal Plane.
-String WideStringToUtf8(const wchar_t* str, int num_chars) {
+std::string WideStringToUtf8(const wchar_t* str, int num_chars) {
if (num_chars == -1)
num_chars = static_cast<int>(wcslen(str));
@@ -1515,12 +1485,12 @@ String WideStringToUtf8(const wchar_t* str, int num_chars) {
return StringStreamToString(&stream);
}
-// Converts a wide C string to a String using the UTF-8 encoding.
+// Converts a wide C string to an std::string using the UTF-8 encoding.
// NULL will be converted to "(null)".
-String String::ShowWideCString(const wchar_t * wide_c_str) {
- if (wide_c_str == NULL) return String("(null)");
+std::string String::ShowWideCString(const wchar_t * wide_c_str) {
+ if (wide_c_str == NULL) return "(null)";
- return String(internal::WideStringToUtf8(wide_c_str, -1).c_str());
+ return internal::WideStringToUtf8(wide_c_str, -1);
}
// Compares two wide C strings. Returns true iff they have the same
@@ -1616,59 +1586,18 @@ bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
#endif // OS selector
}
-// 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 String::Compare(const String & rhs) const {
- const char* const lhs_c_str = c_str();
- const char* const rhs_c_str = rhs.c_str();
-
- if (lhs_c_str == NULL) {
- return rhs_c_str == NULL ? 0 : -1; // NULL < anything except NULL
- } else if (rhs_c_str == NULL) {
- return 1;
- }
-
- const size_t shorter_str_len =
- length() <= rhs.length() ? length() : rhs.length();
- for (size_t i = 0; i != shorter_str_len; i++) {
- if (lhs_c_str[i] < rhs_c_str[i]) {
- return -1;
- } else if (lhs_c_str[i] > rhs_c_str[i]) {
- return 1;
- }
- }
- return (length() < rhs.length()) ? -1 :
- (length() > rhs.length()) ? 1 : 0;
-}
-
-// Returns true iff this String ends with the given suffix. *Any*
-// String is considered to end with a NULL or empty suffix.
-bool String::EndsWith(const char* suffix) const {
- if (suffix == NULL || CStringEquals(suffix, "")) return true;
-
- if (c_str() == NULL) return false;
-
- const size_t this_len = strlen(c_str());
- const size_t suffix_len = strlen(suffix);
- return (this_len >= suffix_len) &&
- CStringEquals(c_str() + this_len - suffix_len, suffix);
+// Returns true iff str ends with the given suffix, ignoring case.
+// Any string is considered to end with an empty suffix.
+bool String::EndsWithCaseInsensitive(
+ const std::string& str, const std::string& suffix) {
+ const size_t str_len = str.length();
+ const size_t suffix_len = suffix.length();
+ return (str_len >= suffix_len) &&
+ CaseInsensitiveCStringEquals(str.c_str() + str_len - suffix_len,
+ suffix.c_str());
}
-// Returns true iff this String ends with the given suffix, ignoring case.
-// Any String is considered to end with a NULL or empty suffix.
-bool String::EndsWithCaseInsensitive(const char* suffix) const {
- if (suffix == NULL || CStringEquals(suffix, "")) return true;
-
- if (c_str() == NULL) return false;
-
- const size_t this_len = strlen(c_str());
- const size_t suffix_len = strlen(suffix);
- return (this_len >= suffix_len) &&
- CaseInsensitiveCStringEquals(c_str() + this_len - suffix_len, suffix);
-}
-
-// Formats a list of arguments to a String, using the same format
+// Formats a list of arguments to an std::string, using the same format
// spec string as for printf.
//
// We do not use the StringPrintf class as it is not universally
@@ -1678,7 +1607,7 @@ bool String::EndsWithCaseInsensitive(const char* suffix) const {
// If 4096 characters are not enough to format the input, or if
// there's an error, "<formatting error or buffer exceeded>" is
// returned.
-String String::Format(const char * format, ...) {
+std::string String::Format(const char * format, ...) {
va_list args;
va_start(args, format);
@@ -1705,46 +1634,42 @@ String String::Format(const char * format, ...) {
// always returns a negative value. For simplicity, we lump the two
// error cases together.
if (size < 0 || size >= kBufferSize) {
- return String("<formatting error or buffer exceeded>");
+ return "<formatting error or buffer exceeded>";
} else {
- return String(buffer, size);
+ return std::string(buffer, size);
}
}
-// Converts the buffer in a stringstream to a String, converting NUL
+// Converts the buffer in a stringstream to an std::string, converting NUL
// bytes to "\\0" along the way.
-String StringStreamToString(::std::stringstream* ss) {
+std::string StringStreamToString(::std::stringstream* ss) {
const ::std::string& str = ss->str();
const char* const start = str.c_str();
const char* const end = start + str.length();
- // We need to use a helper stringstream to do this transformation
- // because String doesn't support push_back().
- ::std::stringstream helper;
+ std::string result;
+ result.reserve(2 * (end - start));
for (const char* ch = start; ch != end; ++ch) {
if (*ch == '\0') {
- helper << "\\0"; // Replaces NUL with "\\0";
+ result += "\\0"; // Replaces NUL with "\\0";
} else {
- helper.put(*ch);
+ result += *ch;
}
}
- return String(helper.str().c_str());
+ return result;
}
// Appends the user-supplied message to the Google-Test-generated message.
-String AppendUserMessage(const String& gtest_msg,
- const Message& user_msg) {
+std::string AppendUserMessage(const std::string& gtest_msg,
+ const Message& user_msg) {
// Appends the user message if it's non-empty.
- const String user_msg_string = user_msg.GetString();
+ const std::string user_msg_string = user_msg.GetString();
if (user_msg_string.empty()) {
return gtest_msg;
}
- Message msg;
- msg << gtest_msg << "\n" << user_msg_string;
-
- return msg.GetString();
+ return gtest_msg + "\n" + user_msg_string;
}
} // namespace internal
@@ -1810,7 +1735,7 @@ void TestResult::RecordProperty(const TestProperty& test_property) {
// Adds a failure if the key is a reserved attribute of Google Test
// testcase tags. Returns true if the property is valid.
bool TestResult::ValidateTestProperty(const TestProperty& test_property) {
- internal::String key(test_property.key());
+ const std::string& key = test_property.key();
if (key == "name" || key == "status" || key == "time" || key == "classname") {
ADD_FAILURE()
<< "Reserved key used in RecordProperty(): "
@@ -1911,7 +1836,7 @@ void Test::RecordProperty(const char* key, int value) {
namespace internal {
void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
- const String& message) {
+ const std::string& message) {
// This function is a friend of UnitTest and as such has access to
// AddTestPartResult.
UnitTest::GetInstance()->AddTestPartResult(
@@ -1919,7 +1844,7 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
NULL, // No info about the source file where the exception occurred.
-1, // We have no info on which line caused the exception.
message,
- String()); // No stack trace, either.
+ ""); // No stack trace, either.
}
} // namespace internal
@@ -1996,13 +1921,13 @@ bool Test::HasSameFixtureClass() {
// function returns its result via an output parameter pointer because VC++
// prohibits creation of objects with destructors on stack in functions
// using __try (see error C2712).
-static internal::String* FormatSehExceptionMessage(DWORD exception_code,
- const char* location) {
+static std::string* FormatSehExceptionMessage(DWORD exception_code,
+ const char* location) {
Message message;
message << "SEH exception with code 0x" << std::setbase(16) <<
exception_code << std::setbase(10) << " thrown in " << location << ".";
- return new internal::String(message.GetString());
+ return new std::string(message.GetString());
}
#endif // GTEST_HAS_SEH
@@ -2010,8 +1935,8 @@ static internal::String* FormatSehExceptionMessage(DWORD exception_code,
#if GTEST_HAS_EXCEPTIONS
// Adds an "exception thrown" fatal failure to the current test.
-static internal::String FormatCxxExceptionMessage(const char* description,
- const char* location) {
+static std::string FormatCxxExceptionMessage(const char* description,
+ const char* location) {
Message message;
if (description != NULL) {
message << "C++ exception with description \"" << description << "\"";
@@ -2023,7 +1948,7 @@ static internal::String FormatCxxExceptionMessage(const char* description,
return message.GetString();
}
-static internal::String PrintTestPartResultToString(
+static std::string PrintTestPartResultToString(
const TestPartResult& test_part_result);
// A failed Google Test assertion will throw an exception of this type when
@@ -2059,7 +1984,7 @@ Result HandleSehExceptionsInMethodIfSupported(
// We create the exception message on the heap because VC++ prohibits
// creation of objects with destructors on stack in functions using __try
// (see error C2712).
- internal::String* exception_message = FormatSehExceptionMessage(
+ std::string* exception_message = FormatSehExceptionMessage(
GetExceptionCode(), location);
internal::ReportFailureInUnknownLocation(TestPartResult::kFatalFailure,
*exception_message);
@@ -2263,11 +2188,11 @@ class TestNameIs {
// Returns true iff the test name of test_info matches name_.
bool operator()(const TestInfo * test_info) const {
- return test_info && internal::String(test_info->name()).Compare(name_) == 0;
+ return test_info && test_info->name() == name_;
}
private:
- internal::String name_;
+ std::string name_;
};
} // namespace
@@ -2457,20 +2382,20 @@ void TestCase::UnshuffleTests() {
//
// FormatCountableNoun(1, "formula", "formuli") returns "1 formula".
// FormatCountableNoun(5, "book", "books") returns "5 books".
-static internal::String FormatCountableNoun(int count,
- const char * singular_form,
- const char * plural_form) {
+static std::string FormatCountableNoun(int count,
+ const char * singular_form,
+ const char * plural_form) {
return internal::String::Format("%d %s", count,
count == 1 ? singular_form : plural_form);
}
// Formats the count of tests.
-static internal::String FormatTestCount(int test_count) {
+static std::string FormatTestCount(int test_count) {
return FormatCountableNoun(test_count, "test", "tests");
}
// Formats the count of test cases.
-static internal::String FormatTestCaseCount(int test_case_count) {
+static std::string FormatTestCaseCount(int test_case_count) {
return FormatCountableNoun(test_case_count, "test case", "test cases");
}
@@ -2495,8 +2420,8 @@ static const char * TestPartResultTypeToString(TestPartResult::Type type) {
}
}
-// Prints a TestPartResult to a String.
-static internal::String PrintTestPartResultToString(
+// Prints a TestPartResult to an std::string.
+static std::string PrintTestPartResultToString(
const TestPartResult& test_part_result) {
return (Message()
<< internal::FormatFileLocation(test_part_result.file_name(),
@@ -2507,7 +2432,7 @@ static internal::String PrintTestPartResultToString(
// Prints a TestPartResult.
static void PrintTestPartResult(const TestPartResult& test_part_result) {
- const internal::String& result =
+ const std::string& result =
PrintTestPartResultToString(test_part_result);
printf("%s\n", result.c_str());
fflush(stdout);
@@ -2700,7 +2625,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart(
// Prints the filter if it's not *. This reminds the user that some
// tests may be skipped.
- if (!internal::String::CStringEquals(filter, kUniversalFilter)) {
+ if (!String::CStringEquals(filter, kUniversalFilter)) {
ColoredPrintf(COLOR_YELLOW,
"Note: %s filter = %s\n", GTEST_NAME_, filter);
}
@@ -2734,7 +2659,7 @@ void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(
}
void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) {
- const internal::String counts =
+ const std::string counts =
FormatCountableNoun(test_case.test_to_run_count(), "test", "tests");
ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("%s from %s", counts.c_str(), test_case.name());
@@ -2787,7 +2712,7 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) {
if (!GTEST_FLAG(print_time)) return;
- const internal::String counts =
+ const std::string counts =
FormatCountableNoun(test_case.test_to_run_count(), "test", "tests");
ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("%s from %s (%s ms total)\n\n",
@@ -3006,18 +2931,20 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
// is_attribute is true, the text is meant to appear as an attribute
// value, and normalizable whitespace is preserved by replacing it
// with character references.
- static String EscapeXml(const char* str, bool is_attribute);
+ static std::string EscapeXml(const char* str, bool is_attribute);
// Returns the given string with all characters invalid in XML removed.
static string RemoveInvalidXmlCharacters(const string& str);
// Convenience wrapper around EscapeXml when str is an attribute value.
- static String EscapeXmlAttribute(const char* str) {
+ static std::string EscapeXmlAttribute(const char* str) {
return EscapeXml(str, true);
}
// Convenience wrapper around EscapeXml when str is not an attribute value.
- static String EscapeXmlText(const char* str) { return EscapeXml(str, false); }
+ static std::string EscapeXmlText(const char* str) {
+ return EscapeXml(str, false);
+ }
// Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
static void OutputXmlCDataSection(::std::ostream* stream, const char* data);
@@ -3035,12 +2962,12 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
// Produces a string representing the test properties in a result as space
// delimited XML attributes based on the property key="value" pairs.
- // When the String is not empty, it includes a space at the beginning,
+ // When the std::string is not empty, it includes a space at the beginning,
// to delimit this attribute from prior attributes.
- static String TestPropertiesAsXmlAttributes(const TestResult& result);
+ static std::string TestPropertiesAsXmlAttributes(const TestResult& result);
// The output file.
- const String output_file_;
+ const std::string output_file_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter);
};
@@ -3098,7 +3025,8 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
// most invalid characters can be retained using character references.
// TODO(wan): It might be nice to have a minimally invasive, human-readable
// escaping scheme for invalid characters, rather than dropping them.
-String XmlUnitTestResultPrinter::EscapeXml(const char* str, bool is_attribute) {
+std::string XmlUnitTestResultPrinter::EscapeXml(
+ const char* str, bool is_attribute) {
Message m;
if (str != NULL) {
@@ -3316,7 +3244,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,
// Produces a string representing the test properties in a result as space
// delimited XML attributes based on the property key="value" pairs.
-String XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
+std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
const TestResult& result) {
Message attributes;
for (int i = 0; i < result.test_property_count(); ++i) {
@@ -3528,17 +3456,17 @@ ScopedTrace::~ScopedTrace()
// class OsStackTraceGetter
-// 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
// in the trace.
// skip_count - the number of top frames to be skipped; doesn't count
// against max_depth.
//
-String OsStackTraceGetter::CurrentStackTrace(int /* max_depth */,
+string OsStackTraceGetter::CurrentStackTrace(int /* max_depth */,
int /* skip_count */)
GTEST_LOCK_EXCLUDED_(mutex_) {
- return String("");
+ return "";
}
void OsStackTraceGetter::UponLeavingGTest()
@@ -3759,8 +3687,8 @@ void UnitTest::AddTestPartResult(
TestPartResult::Type result_type,
const char* file_name,
int line_number,
- const internal::String& message,
- const internal::String& os_stack_trace)
+ const std::string& message,
+ const std::string& os_stack_trace)
GTEST_LOCK_EXCLUDED_(mutex_) {
Message msg;
msg << message;
@@ -4008,7 +3936,7 @@ void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
// Initializes event listeners performing XML output as specified by
// UnitTestOptions. Must not be called before InitGoogleTest.
void UnitTestImpl::ConfigureXmlOutput() {
- const String& output_format = UnitTestOptions::GetOutputFormat();
+ const std::string& output_format = UnitTestOptions::GetOutputFormat();
if (output_format == "xml") {
listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter(
UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
@@ -4020,13 +3948,13 @@ void UnitTestImpl::ConfigureXmlOutput() {
}
#if GTEST_CAN_STREAM_RESULTS_
-// Initializes event listeners for streaming test results in String form.
+// Initializes event listeners for streaming test results in string form.
// Must not be called before InitGoogleTest.
void UnitTestImpl::ConfigureStreamingOutput() {
- const string& target = GTEST_FLAG(stream_result_to);
+ const std::string& target = GTEST_FLAG(stream_result_to);
if (!target.empty()) {
const size_t pos = target.find(':');
- if (pos != string::npos) {
+ if (pos != std::string::npos) {
listeners()->Append(new StreamingListener(target.substr(0, pos),
target.substr(pos+1)));
} else {
@@ -4080,7 +4008,7 @@ void UnitTestImpl::PostFlagParsingInit() {
class TestCaseNameIs {
public:
// Constructor.
- explicit TestCaseNameIs(const String& name)
+ explicit TestCaseNameIs(const std::string& name)
: name_(name) {}
// Returns true iff the name of test_case matches name_.
@@ -4089,7 +4017,7 @@ class TestCaseNameIs {
}
private:
- String name_;
+ std::string name_;
};
// Finds and returns a TestCase with the given name. If one doesn't
@@ -4121,7 +4049,7 @@ TestCase* UnitTestImpl::GetTestCase(const char* test_case_name,
new TestCase(test_case_name, type_param, set_up_tc, tear_down_tc);
// Is this a death test case?
- if (internal::UnitTestOptions::MatchesFilter(String(test_case_name),
+ if (internal::UnitTestOptions::MatchesFilter(test_case_name,
kDeathTestCaseFilter)) {
// Yes. Inserts the test case after the last death test case
// defined so far. This only works when the test cases haven't
@@ -4400,12 +4328,12 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
int num_selected_tests = 0;
for (size_t i = 0; i < test_cases_.size(); i++) {
TestCase* const test_case = test_cases_[i];
- const String &test_case_name = test_case->name();
+ const std::string &test_case_name = test_case->name();
test_case->set_should_run(false);
for (size_t j = 0; j < test_case->test_info_list().size(); j++) {
TestInfo* const test_info = test_case->test_info_list()[j];
- const String test_name(test_info->name());
+ const std::string test_name(test_info->name());
// A test is disabled if test case name or test name matches
// kDisableTestFilter.
const bool is_disabled =
@@ -4517,7 +4445,7 @@ void UnitTestImpl::UnshuffleTests() {
}
}
-// 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 gtest_stack_trace_depth flag. The skip_count parameter
@@ -4527,8 +4455,8 @@ void UnitTestImpl::UnshuffleTests() {
// For example, if Foo() calls Bar(), which in turn calls
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
-String GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/,
- int skip_count) {
+std::string GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/,
+ int skip_count) {
// We pass skip_count + 1 to skip this wrapper function in addition
// to what the user really wants to skip.
return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1);
@@ -4576,7 +4504,7 @@ const char* ParseFlagValue(const char* str,
if (str == NULL || flag == NULL) return NULL;
// The flag must start with "--" followed by GTEST_FLAG_PREFIX_.
- const String flag_str = String::Format("--%s%s", GTEST_FLAG_PREFIX_, flag);
+ const std::string flag_str = std::string("--") + GTEST_FLAG_PREFIX_ + flag;
const size_t flag_len = flag_str.length();
if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL;
@@ -4641,7 +4569,7 @@ bool ParseInt32Flag(const char* str, const char* flag, Int32* value) {
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
-bool ParseStringFlag(const char* str, const char* flag, String* value) {
+bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
// Gets the value of the flag as a string.
const char* const value_str = ParseFlagValue(str, flag, false);
@@ -4693,7 +4621,7 @@ static void PrintColorEncoded(const char* str) {
return;
}
- ColoredPrintf(color, "%s", String(str, p - str).c_str());
+ ColoredPrintf(color, "%s", std::string(str, p).c_str());
const char ch = p[1];
str = p + 2;
@@ -4783,7 +4711,7 @@ static const char kColorEncodedHelpMessage[] =
template <typename CharType>
void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
for (int i = 1; i < *argc; i++) {
- const String arg_string = StreamableToString(argv[i]);
+ const std::string arg_string = StreamableToString(argv[i]);
const char* const arg = arg_string.c_str();
using internal::ParseBoolFlag;