Skip to content

Commit 03c3149

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. git-svn-id: http://googletest.googlecode.com/svn/trunk@628 861a406c-534a-0410-8894-cb66d6ee9925
1 parent 5d9f11f commit 03c3149

28 files changed

+533
-1090
lines changed

include/gtest/gtest-message.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ class GTEST_API_ Message {
183183
Message& operator <<(const ::wstring& wstr);
184184
#endif // GTEST_HAS_GLOBAL_WSTRING
185185

186-
// Gets the text streamed to this object so far as a String.
186+
// Gets the text streamed to this object so far as an std::string.
187187
// Each '\0' character in the buffer is replaced with "\\0".
188188
//
189189
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
190-
internal::String GetString() const {
190+
std::string GetString() const {
191191
return internal::StringStreamToString(ss_.get());
192192
}
193193

include/gtest/gtest-test-part.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class GTEST_API_ TestPartResult {
6262
int a_line_number,
6363
const char* a_message)
6464
: type_(a_type),
65-
file_name_(a_file_name),
65+
file_name_(a_file_name == NULL ? "" : a_file_name),
6666
line_number_(a_line_number),
6767
summary_(ExtractSummary(a_message)),
6868
message_(a_message) {
@@ -73,7 +73,9 @@ class GTEST_API_ TestPartResult {
7373

7474
// Gets the name of the source file where the test part took place, or
7575
// NULL if it's unknown.
76-
const char* file_name() const { return file_name_.c_str(); }
76+
const char* file_name() const {
77+
return file_name_.empty() ? NULL : file_name_.c_str();
78+
}
7779

7880
// Gets the line in the source file where the test part took place,
7981
// or -1 if it's unknown.
@@ -102,16 +104,16 @@ class GTEST_API_ TestPartResult {
102104

103105
// Gets the summary of the failure message by omitting the stack
104106
// trace in it.
105-
static internal::String ExtractSummary(const char* message);
107+
static std::string ExtractSummary(const char* message);
106108

107109
// The name of the source file where the test part took place, or
108-
// NULL if the source file is unknown.
109-
internal::String file_name_;
110+
// "" if the source file is unknown.
111+
std::string file_name_;
110112
// The line in the source file where the test part took place, or -1
111113
// if the line number is unknown.
112114
int line_number_;
113-
internal::String summary_; // The test failure summary.
114-
internal::String message_; // The test failure message.
115+
std::string summary_; // The test failure summary.
116+
std::string message_; // The test failure message.
115117
};
116118

117119
// Prints a TestPartResult object.

include/gtest/gtest.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ class TestEventRepeater;
160160
class WindowsDeathTest;
161161
class UnitTestImpl* GetUnitTestImpl();
162162
void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
163-
const String& message);
163+
const std::string& message);
164164

165-
// Converts a streamable value to a String. A NULL pointer is
165+
// Converts a streamable value to an std::string. A NULL pointer is
166166
// converted to "(null)". When the input value is a ::string,
167167
// ::std::string, ::wstring, or ::std::wstring object, each NUL
168168
// character in it is replaced with "\\0".
169169
// Declared in gtest-internal.h but defined here, so that it has access
170170
// to the definition of the Message class, required by the ARM
171171
// compiler.
172172
template <typename T>
173-
String StreamableToString(const T& streamable) {
173+
std::string StreamableToString(const T& streamable) {
174174
return (Message() << streamable).GetString();
175175
}
176176

@@ -495,9 +495,9 @@ class TestProperty {
495495

496496
private:
497497
// The key supplied by the user.
498-
internal::String key_;
498+
std::string key_;
499499
// The value supplied by the user.
500-
internal::String value_;
500+
std::string value_;
501501
};
502502

503503
// The result of a single Test. This includes a list of
@@ -869,7 +869,7 @@ class GTEST_API_ TestCase {
869869
void UnshuffleTests();
870870

871871
// Name of the test case.
872-
internal::String name_;
872+
std::string name_;
873873
// Name of the parameter type, or NULL if this is not a typed or a
874874
// type-parameterized test.
875875
const internal::scoped_ptr<const ::std::string> type_param_;
@@ -1196,8 +1196,8 @@ class GTEST_API_ UnitTest {
11961196
void AddTestPartResult(TestPartResult::Type result_type,
11971197
const char* file_name,
11981198
int line_number,
1199-
const internal::String& message,
1200-
const internal::String& os_stack_trace)
1199+
const std::string& message,
1200+
const std::string& os_stack_trace)
12011201
GTEST_LOCK_EXCLUDED_(mutex_);
12021202

12031203
// Adds a TestProperty to the current TestResult object. If the result already
@@ -1221,7 +1221,7 @@ class GTEST_API_ UnitTest {
12211221
friend internal::UnitTestImpl* internal::GetUnitTestImpl();
12221222
friend void internal::ReportFailureInUnknownLocation(
12231223
TestPartResult::Type result_type,
1224-
const internal::String& message);
1224+
const std::string& message);
12251225

12261226
// Creates an empty UnitTest.
12271227
UnitTest();
@@ -1383,8 +1383,8 @@ GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
13831383
//
13841384
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
13851385
template <typename T1, typename T2>
1386-
String FormatForComparisonFailureMessage(const T1& value,
1387-
const T2& /* other_operand */) {
1386+
std::string FormatForComparisonFailureMessage(
1387+
const T1& value, const T2& /* other_operand */) {
13881388
return FormatForComparison<T1, T2>::Format(value);
13891389
}
13901390

@@ -1701,9 +1701,9 @@ class GTEST_API_ AssertHelper {
17011701
: type(t), file(srcfile), line(line_num), message(msg) { }
17021702

17031703
TestPartResult::Type const type;
1704-
const char* const file;
1705-
int const line;
1706-
String const message;
1704+
const char* const file;
1705+
int const line;
1706+
std::string const message;
17071707

17081708
private:
17091709
GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
@@ -1981,7 +1981,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {
19811981
# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
19821982
#endif
19831983

1984-
// C String Comparisons. All tests treat NULL and any non-NULL string
1984+
// C-string Comparisons. All tests treat NULL and any non-NULL string
19851985
// as different. Two NULLs are equal.
19861986
//
19871987
// * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2

include/gtest/internal/gtest-death-test-internal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ class GTEST_API_ DeathTest {
127127
// the last death test.
128128
static const char* LastMessage();
129129

130-
static void set_last_death_test_message(const String& message);
130+
static void set_last_death_test_message(const std::string& message);
131131

132132
private:
133133
// A string containing a description of the outcome of the last death test.
134-
static String last_death_test_message_;
134+
static std::string last_death_test_message_;
135135

136136
GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
137137
};
@@ -233,7 +233,7 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
233233
// RUN_ALL_TESTS was called.
234234
class InternalRunDeathTestFlag {
235235
public:
236-
InternalRunDeathTestFlag(const String& a_file,
236+
InternalRunDeathTestFlag(const std::string& a_file,
237237
int a_line,
238238
int an_index,
239239
int a_write_fd)
@@ -245,13 +245,13 @@ class InternalRunDeathTestFlag {
245245
posix::Close(write_fd_);
246246
}
247247

248-
String file() const { return file_; }
248+
const std::string& file() const { return file_; }
249249
int line() const { return line_; }
250250
int index() const { return index_; }
251251
int write_fd() const { return write_fd_; }
252252

253253
private:
254-
String file_;
254+
std::string file_;
255255
int line_;
256256
int index_;
257257
int write_fd_;

include/gtest/internal/gtest-filepath.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ class GTEST_API_ FilePath {
6161
FilePath() : pathname_("") { }
6262
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
6363

64-
explicit FilePath(const char* pathname) : pathname_(pathname) {
65-
Normalize();
66-
}
67-
68-
explicit FilePath(const String& pathname) : pathname_(pathname) {
64+
explicit FilePath(const std::string& pathname) : pathname_(pathname) {
6965
Normalize();
7066
}
7167

@@ -78,7 +74,7 @@ class GTEST_API_ FilePath {
7874
pathname_ = rhs.pathname_;
7975
}
8076

81-
String ToString() const { return pathname_; }
77+
const std::string& string() const { return pathname_; }
8278
const char* c_str() const { return pathname_.c_str(); }
8379

8480
// Returns the current working directory, or "" if unsuccessful.
@@ -111,8 +107,8 @@ class GTEST_API_ FilePath {
111107
const FilePath& base_name,
112108
const char* extension);
113109

114-
// Returns true iff the path is NULL or "".
115-
bool IsEmpty() const { return c_str() == NULL || *c_str() == '\0'; }
110+
// Returns true iff the path is "".
111+
bool IsEmpty() const { return pathname_.empty(); }
116112

117113
// If input name has a trailing separator character, removes it and returns
118114
// the name, otherwise return the name string unmodified.
@@ -201,7 +197,7 @@ class GTEST_API_ FilePath {
201197
// separators. Returns NULL if no path separator was found.
202198
const char* FindLastPathSeparator() const;
203199

204-
String pathname_;
200+
std::string pathname_;
205201
}; // class FilePath
206202

207203
} // namespace internal

include/gtest/internal/gtest-internal.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT
163163
#endif // GTEST_ELLIPSIS_NEEDS_POD_
164164

165165
// Appends the user-supplied message to the Google-Test-generated message.
166-
GTEST_API_ String AppendUserMessage(const String& gtest_msg,
167-
const Message& user_msg);
166+
GTEST_API_ std::string AppendUserMessage(
167+
const std::string& gtest_msg, const Message& user_msg);
168168

169169
// A helper class for creating scoped traces in user programs.
170170
class GTEST_API_ ScopedTrace {
@@ -185,15 +185,15 @@ class GTEST_API_ ScopedTrace {
185185
// c'tor and d'tor. Therefore it doesn't
186186
// need to be used otherwise.
187187

188-
// Converts a streamable value to a String. A NULL pointer is
188+
// Converts a streamable value to an std::string. A NULL pointer is
189189
// converted to "(null)". When the input value is a ::string,
190190
// ::std::string, ::wstring, or ::std::wstring object, each NUL
191191
// character in it is replaced with "\\0".
192192
// Declared here but defined in gtest.h, so that it has access
193193
// to the definition of the Message class, required by the ARM
194194
// compiler.
195195
template <typename T>
196-
String StreamableToString(const T& streamable);
196+
std::string StreamableToString(const T& streamable);
197197

198198
// Constructs and returns the message for an equality assertion
199199
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
@@ -212,12 +212,12 @@ String StreamableToString(const T& streamable);
212212
// be inserted into the message.
213213
GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
214214
const char* actual_expression,
215-
const String& expected_value,
216-
const String& actual_value,
215+
const std::string& expected_value,
216+
const std::string& actual_value,
217217
bool ignoring_case);
218218

219219
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
220-
GTEST_API_ String GetBoolAssertionFailureMessage(
220+
GTEST_API_ std::string GetBoolAssertionFailureMessage(
221221
const AssertionResult& assertion_result,
222222
const char* expression_text,
223223
const char* actual_predicate_value,
@@ -563,9 +563,9 @@ inline const char* SkipComma(const char* str) {
563563

564564
// Returns the prefix of 'str' before the first comma in it; returns
565565
// the entire string if it contains no comma.
566-
inline String GetPrefixUntilComma(const char* str) {
566+
inline std::string GetPrefixUntilComma(const char* str) {
567567
const char* comma = strchr(str, ',');
568-
return comma == NULL ? String(str) : String(str, comma - str);
568+
return comma == NULL ? str : std::string(str, comma);
569569
}
570570

571571
// TypeParameterizedTest<Fixture, TestSel, Types>::Register()
@@ -650,7 +650,7 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> {
650650

651651
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
652652

653-
// Returns the current OS stack trace as a String.
653+
// Returns the current OS stack trace as an std::string.
654654
//
655655
// The maximum number of stack frames to be included is specified by
656656
// the gtest_stack_trace_depth flag. The skip_count parameter
@@ -660,8 +660,8 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> {
660660
// For example, if Foo() calls Bar(), which in turn calls
661661
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
662662
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
663-
GTEST_API_ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test,
664-
int skip_count);
663+
GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(
664+
UnitTest* unit_test, int skip_count);
665665

666666
// Helpers for suppressing warnings on unreachable code or constant
667667
// condition.

include/gtest/internal/gtest-port.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@
239239
# define GTEST_OS_MAC 1
240240
# if TARGET_OS_IPHONE
241241
# define GTEST_OS_IOS 1
242+
# if TARGET_IPHONE_SIMULATOR
243+
# define GEST_OS_IOS_SIMULATOR 1
244+
# endif
242245
# endif
243246
#elif defined __linux__
244247
# define GTEST_OS_LINUX 1
@@ -635,7 +638,7 @@ using ::std::tuple_size;
635638
// abort() in a VC 7.1 application compiled as GUI in debug config
636639
// pops up a dialog window that cannot be suppressed programmatically.
637640
#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
638-
(GTEST_OS_MAC && !GTEST_OS_IOS) || \
641+
(GTEST_OS_MAC && (!GTEST_OS_IOS || GEST_OS_IOS_SIMULATOR)) || \
639642
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
640643
GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
641644
GTEST_OS_OPENBSD || GTEST_OS_QNX)
@@ -780,8 +783,6 @@ class Message;
780783

781784
namespace internal {
782785

783-
class String;
784-
785786
// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
786787
// expression is true. For example, you could use it to verify the
787788
// size of a static array:
@@ -964,10 +965,9 @@ class GTEST_API_ RE {
964965
private:
965966
void Init(const char* regex);
966967

967-
// We use a const char* instead of a string, as Google Test may be used
968-
// where string is not available. We also do not use Google Test's own
969-
// String type here, in order to simplify dependencies between the
970-
// files.
968+
// We use a const char* instead of an std::string, as Google Test used to be
969+
// used where std::string is not available. TODO([email protected]): change to
970+
// std::string.
971971
const char* pattern_;
972972
bool is_valid_;
973973

@@ -1150,9 +1150,9 @@ Derived* CheckedDowncastToActualType(Base* base) {
11501150
// GetCapturedStderr - stops capturing stderr and returns the captured string.
11511151
//
11521152
GTEST_API_ void CaptureStdout();
1153-
GTEST_API_ String GetCapturedStdout();
1153+
GTEST_API_ std::string GetCapturedStdout();
11541154
GTEST_API_ void CaptureStderr();
1155-
GTEST_API_ String GetCapturedStderr();
1155+
GTEST_API_ std::string GetCapturedStderr();
11561156

11571157
#endif // GTEST_HAS_STREAM_REDIRECTION
11581158

@@ -1903,15 +1903,15 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
19031903
#define GTEST_DECLARE_int32_(name) \
19041904
GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
19051905
#define GTEST_DECLARE_string_(name) \
1906-
GTEST_API_ extern ::testing::internal::String GTEST_FLAG(name)
1906+
GTEST_API_ extern ::std::string GTEST_FLAG(name)
19071907

19081908
// Macros for defining flags.
19091909
#define GTEST_DEFINE_bool_(name, default_val, doc) \
19101910
GTEST_API_ bool GTEST_FLAG(name) = (default_val)
19111911
#define GTEST_DEFINE_int32_(name, default_val, doc) \
19121912
GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
19131913
#define GTEST_DEFINE_string_(name, default_val, doc) \
1914-
GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val)
1914+
GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
19151915

19161916
// Thread annotations
19171917
#define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)

0 commit comments

Comments
 (0)