diff options
author | Billy Donahue <BillyDonahue@users.noreply.github.com> | 2017-05-16 21:00:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-16 21:00:03 (GMT) |
commit | 7cc548dcbf266d48c9b3fe8ec30c2f2ba8acb1d9 (patch) | |
tree | 8f92a22eb8633766fc7d2e689593bd100dc17824 /googlemock/include | |
parent | 078d5d930ad8b25b3c61556dc6de7ad13fa9a179 (diff) | |
parent | 09fd5b3ebfaac10b78bda664ec7f57fac74ef214 (diff) | |
download | googletest-7cc548dcbf266d48c9b3fe8ec30c2f2ba8acb1d9.zip googletest-7cc548dcbf266d48c9b3fe8ec30c2f2ba8acb1d9.tar.gz googletest-7cc548dcbf266d48c9b3fe8ec30c2f2ba8acb1d9.tar.bz2 |
Merge pull request #1089 from nico/stdstring
Use std::string and ::string explicitly in gtest and gmock code.
Diffstat (limited to 'googlemock/include')
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 118 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-spec-builders.h | 53 | ||||
-rw-r--r-- | googlemock/include/gmock/internal/gmock-internal-utils.h | 9 |
3 files changed, 90 insertions, 90 deletions
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 33b37a7..9ade5b6 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -186,7 +186,7 @@ class StringMatchResultListener : public MatchResultListener { StringMatchResultListener() : MatchResultListener(&ss_) {} // Returns the explanation accumulated so far. - internal::string str() const { return ss_.str(); } + std::string str() const { return ss_.str(); } // Clears the explanation accumulated so far. void Clear() { ss_.str(""); } @@ -675,7 +675,7 @@ Matcher<T> A(); namespace internal { // If the explanation is not empty, prints it to the ostream. -inline void PrintIfNotEmpty(const internal::string& explanation, +inline void PrintIfNotEmpty(const std::string& explanation, ::std::ostream* os) { if (explanation != "" && os != NULL) { *os << ", " << explanation; @@ -685,11 +685,11 @@ inline void PrintIfNotEmpty(const internal::string& explanation, // Returns true if the given type name is easy to read by a human. // This is used to decide whether printing the type of a value might // be helpful. -inline bool IsReadableTypeName(const string& type_name) { +inline bool IsReadableTypeName(const std::string& type_name) { // We consider a type name readable if it's short or doesn't contain // a template or function type. return (type_name.length() <= 20 || - type_name.find_first_of("<(") == string::npos); + type_name.find_first_of("<(") == std::string::npos); } // Matches the value against the given matcher, prints the value and explains @@ -711,7 +711,7 @@ bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher, UniversalPrint(value, listener->stream()); #if GTEST_HAS_RTTI - const string& type_name = GetTypeName<Value>(); + const std::string& type_name = GetTypeName<Value>(); if (IsReadableTypeName(type_name)) *listener->stream() << " (of type " << type_name << ")"; #endif @@ -1335,17 +1335,17 @@ class MatchesRegexMatcher { // wchar_t* template <typename CharType> bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(internal::string(s), listener); + return s != NULL && MatchAndExplain(std::string(s), listener); } - // Matches anything that can convert to internal::string. + // Matches anything that can convert to std::string. // - // This is a template, not just a plain function with const internal::string&, + // This is a template, not just a plain function with const std::string&, // because StringPiece has some interfering non-explicit constructors. template <class MatcheeStringType> bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const internal::string& s2(s); + const std::string& s2(s); return full_match_ ? RE::FullMatch(s2, *regex_) : RE::PartialMatch(s2, *regex_); } @@ -1353,13 +1353,13 @@ class MatchesRegexMatcher { void DescribeTo(::std::ostream* os) const { *os << (full_match_ ? "matches" : "contains") << " regular expression "; - UniversalPrinter<internal::string>::Print(regex_->pattern(), os); + UniversalPrinter<std::string>::Print(regex_->pattern(), os); } void DescribeNegationTo(::std::ostream* os) const { *os << "doesn't " << (full_match_ ? "match" : "contain") << " regular expression "; - UniversalPrinter<internal::string>::Print(regex_->pattern(), os); + UniversalPrinter<std::string>::Print(regex_->pattern(), os); } private: @@ -1526,8 +1526,8 @@ class BothOfMatcherImpl : public MatcherInterface<T> { } // Otherwise we need to explain why *both* of them match. - const internal::string s1 = listener1.str(); - const internal::string s2 = listener2.str(); + const std::string s1 = listener1.str(); + const std::string s2 = listener2.str(); if (s1 == "") { *listener << s2; @@ -1698,8 +1698,8 @@ class EitherOfMatcherImpl : public MatcherInterface<T> { } // Otherwise we need to explain why *both* of them fail. - const internal::string s1 = listener1.str(); - const internal::string s2 = listener2.str(); + const std::string s1 = listener1.str(); + const std::string s2 = listener2.str(); if (s1 == "") { *listener << s2; @@ -2123,7 +2123,7 @@ class WhenDynamicCastToMatcherBase { protected: const Matcher<To> matcher_; - static string GetToName() { + static std::string GetToName() { #if GTEST_HAS_RTTI return GetTypeName<To>(); #else // GTEST_HAS_RTTI @@ -2953,7 +2953,7 @@ class KeyMatcherImpl : public MatcherInterface<PairType> { StringMatchResultListener inner_listener; const bool match = inner_matcher_.MatchAndExplain(key_value.first, &inner_listener); - const internal::string explanation = inner_listener.str(); + const std::string explanation = inner_listener.str(); if (explanation != "") { *listener << "whose first field is a value " << explanation; } @@ -3058,8 +3058,8 @@ class PairMatcherImpl : public MatcherInterface<PairType> { } private: - void ExplainSuccess(const internal::string& first_explanation, - const internal::string& second_explanation, + void ExplainSuccess(const std::string& first_explanation, + const std::string& second_explanation, MatchResultListener* listener) const { *listener << "whose both fields match"; if (first_explanation != "") { @@ -3166,7 +3166,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> { const bool listener_interested = listener->IsInterested(); // explanations[i] is the explanation of the element at index i. - ::std::vector<internal::string> explanations(count()); + ::std::vector<std::string> explanations(count()); StlContainerReference stl_container = View::ConstReference(container); typename StlContainer::const_iterator it = stl_container.begin(); size_t exam_pos = 0; @@ -3225,7 +3225,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> { if (listener_interested) { bool reason_printed = false; for (size_t i = 0; i != count(); ++i) { - const internal::string& s = explanations[i]; + const std::string& s = explanations[i]; if (!s.empty()) { if (reason_printed) { *listener << ",\nand "; @@ -3278,7 +3278,7 @@ class GTEST_API_ MatchMatrix { void Randomize(); - string DebugString() const; + std::string DebugString() const; private: size_t SpaceIndex(size_t ilhs, size_t irhs) const { @@ -3322,9 +3322,8 @@ class GTEST_API_ UnorderedElementsAreMatcherImplBase { void DescribeNegationToImpl(::std::ostream* os) const; bool VerifyAllElementsAndMatchersAreMatched( - const ::std::vector<string>& element_printouts, - const MatchMatrix& matrix, - MatchResultListener* listener) const; + const ::std::vector<std::string>& element_printouts, + const MatchMatrix& matrix, MatchResultListener* listener) const; MatcherDescriberVec& matcher_describers() { return matcher_describers_; @@ -3376,7 +3375,7 @@ class UnorderedElementsAreMatcherImpl virtual bool MatchAndExplain(Container container, MatchResultListener* listener) const { StlContainerReference stl_container = View::ConstReference(container); - ::std::vector<string> element_printouts; + ::std::vector<std::string> element_printouts; MatchMatrix matrix = AnalyzeElements(stl_container.begin(), stl_container.end(), &element_printouts, @@ -3407,7 +3406,7 @@ class UnorderedElementsAreMatcherImpl template <typename ElementIter> MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last, - ::std::vector<string>* element_printouts, + ::std::vector<std::string>* element_printouts, MatchResultListener* listener) const { element_printouts->clear(); ::std::vector<char> did_match; @@ -3619,9 +3618,9 @@ BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond( // 'negation' is false; otherwise returns the description of the // negation of the matcher. 'param_values' contains a list of strings // that are the print-out of the matcher's parameters. -GTEST_API_ string FormatMatcherDescription(bool negation, - const char* matcher_name, - const Strings& param_values); +GTEST_API_ std::string FormatMatcherDescription(bool negation, + const char* matcher_name, + const Strings& param_values); } // namespace internal @@ -3951,53 +3950,52 @@ internal::ResultOfMatcher<Callable> ResultOf( // String matchers. // Matches a string equal to str. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > - StrEq(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( - str, true, true)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrEq( + const std::string& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::string>(str, true, true)); } // Matches a string not equal to str. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > - StrNe(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( - str, false, true)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrNe( + const std::string& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::string>(str, false, true)); } // Matches a string equal to str, ignoring case. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > - StrCaseEq(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( - str, true, false)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseEq( + const std::string& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::string>(str, true, false)); } // Matches a string not equal to str, ignoring case. -inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> > - StrCaseNe(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>( - str, false, false)); +inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseNe( + const std::string& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher<std::string>(str, false, false)); } // Creates a matcher that matches any string, std::string, or C string // that contains the given substring. -inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> > - HasSubstr(const internal::string& substring) { - return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>( - substring)); +inline PolymorphicMatcher<internal::HasSubstrMatcher<std::string> > HasSubstr( + const std::string& substring) { + return MakePolymorphicMatcher( + internal::HasSubstrMatcher<std::string>(substring)); } // Matches a string that starts with 'prefix' (case-sensitive). -inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> > - StartsWith(const internal::string& prefix) { - return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>( - prefix)); +inline PolymorphicMatcher<internal::StartsWithMatcher<std::string> > StartsWith( + const std::string& prefix) { + return MakePolymorphicMatcher( + internal::StartsWithMatcher<std::string>(prefix)); } // Matches a string that ends with 'suffix' (case-sensitive). -inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> > - EndsWith(const internal::string& suffix) { - return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>( - suffix)); +inline PolymorphicMatcher<internal::EndsWithMatcher<std::string> > EndsWith( + const std::string& suffix) { + return MakePolymorphicMatcher(internal::EndsWithMatcher<std::string>(suffix)); } // Matches a string that fully matches regular expression 'regex'. @@ -4007,7 +4005,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true)); } inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( - const internal::string& regex) { + const std::string& regex) { return MatchesRegex(new internal::RE(regex)); } @@ -4018,7 +4016,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false)); } inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( - const internal::string& regex) { + const std::string& regex) { return ContainsRegex(new internal::RE(regex)); } diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index fed7de6..39f7212 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -148,8 +148,7 @@ class GTEST_API_ UntypedFunctionMockerBase { // action fails. // L = * virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( - const void* untyped_args, - const string& call_description) const = 0; + const void* untyped_args, const std::string& call_description) const = 0; // Performs the given action with the given arguments and returns // the action's result. @@ -263,12 +262,14 @@ class UntypedOnCallSpecBase { }; // Asserts that the ON_CALL() statement has a certain property. - void AssertSpecProperty(bool property, const string& failure_message) const { + void AssertSpecProperty(bool property, + const std::string& failure_message) const { Assert(property, file_, line_, failure_message); } // Expects that the ON_CALL() statement has a certain property. - void ExpectSpecProperty(bool property, const string& failure_message) const { + void ExpectSpecProperty(bool property, + const std::string& failure_message) const { Expect(property, file_, line_, failure_message); } @@ -690,7 +691,7 @@ GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence; class GTEST_API_ ExpectationBase { public: // source_text is the EXPECT_CALL(...) source that created this Expectation. - ExpectationBase(const char* file, int line, const string& source_text); + ExpectationBase(const char* file, int line, const std::string& source_text); virtual ~ExpectationBase(); @@ -738,12 +739,14 @@ class GTEST_API_ ExpectationBase { virtual Expectation GetHandle() = 0; // Asserts that the EXPECT_CALL() statement has the given property. - void AssertSpecProperty(bool property, const string& failure_message) const { + void AssertSpecProperty(bool property, + const std::string& failure_message) const { Assert(property, file_, line_, failure_message); } // Expects that the EXPECT_CALL() statement has the given property. - void ExpectSpecProperty(bool property, const string& failure_message) const { + void ExpectSpecProperty(bool property, + const std::string& failure_message) const { Expect(property, file_, line_, failure_message); } @@ -845,7 +848,7 @@ class GTEST_API_ ExpectationBase { // an EXPECT_CALL() statement finishes. const char* file_; // The file that contains the expectation. int line_; // The line number of the expectation. - const string source_text_; // The EXPECT_CALL(...) source text. + const std::string source_text_; // The EXPECT_CALL(...) source text. // True iff the cardinality is specified explicitly. bool cardinality_specified_; Cardinality cardinality_; // The cardinality of the expectation. @@ -880,8 +883,8 @@ class TypedExpectation : public ExpectationBase { typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; typedef typename Function<F>::Result Result; - TypedExpectation(FunctionMockerBase<F>* owner, - const char* a_file, int a_line, const string& a_source_text, + TypedExpectation(FunctionMockerBase<F>* owner, const char* a_file, int a_line, + const std::string& a_source_text, const ArgumentMatcherTuple& m) : ExpectationBase(a_file, a_line, a_source_text), owner_(owner), @@ -1240,7 +1243,7 @@ class TypedExpectation : public ExpectationBase { // Logs a message including file and line number information. GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity, const char* file, int line, - const string& message); + const std::string& message); template <typename F> class MockSpec { @@ -1259,7 +1262,7 @@ class MockSpec { internal::OnCallSpec<F>& InternalDefaultActionSetAt( const char* file, int line, const char* obj, const char* call) { LogWithLocation(internal::kInfo, file, line, - string("ON_CALL(") + obj + ", " + call + ") invoked"); + std::string("ON_CALL(") + obj + ", " + call + ") invoked"); return function_mocker_->AddNewOnCallSpec(file, line, matchers_); } @@ -1267,7 +1270,8 @@ class MockSpec { // the newly created spec. internal::TypedExpectation<F>& InternalExpectedAt( const char* file, int line, const char* obj, const char* call) { - const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")"); + const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " + + call + ")"); LogWithLocation(internal::kInfo, file, line, source_text + " invoked"); return function_mocker_->AddNewExpectation( file, line, source_text, matchers_); @@ -1389,7 +1393,7 @@ class ActionResultHolder : public UntypedActionResultHolderBase { static ActionResultHolder* PerformDefaultAction( const FunctionMockerBase<F>* func_mocker, const typename Function<F>::ArgumentTuple& args, - const string& call_description) { + const std::string& call_description) { return new ActionResultHolder(Wrapper( func_mocker->PerformDefaultAction(args, call_description))); } @@ -1429,7 +1433,7 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase { static ActionResultHolder* PerformDefaultAction( const FunctionMockerBase<F>* func_mocker, const typename Function<F>::ArgumentTuple& args, - const string& call_description) { + const std::string& call_description) { func_mocker->PerformDefaultAction(args, call_description); return new ActionResultHolder; } @@ -1496,13 +1500,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // without locking. // L = * Result PerformDefaultAction(const ArgumentTuple& args, - const string& call_description) const { + const std::string& call_description) const { const OnCallSpec<F>* const spec = this->FindOnCallSpec(args); if (spec != NULL) { return spec->GetAction().Perform(args); } - const string message = call_description + + const std::string message = + call_description + "\n The mock function has no default action " "set, and its return type has no default value set."; #if GTEST_HAS_EXCEPTIONS @@ -1522,7 +1527,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // L = * virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( const void* untyped_args, // must point to an ArgumentTuple - const string& call_description) const { + const std::string& call_description) const { const ArgumentTuple& args = *static_cast<const ArgumentTuple*>(untyped_args); return ResultHolder::PerformDefaultAction(this, args, call_description); @@ -1598,12 +1603,10 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { } // Adds and returns an expectation spec for this mock function. - TypedExpectation<F>& AddNewExpectation( - const char* file, - int line, - const string& source_text, - const ArgumentMatcherTuple& m) - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + TypedExpectation<F>& AddNewExpectation(const char* file, int line, + const std::string& source_text, + const ArgumentMatcherTuple& m) + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); TypedExpectation<F>* const expectation = new TypedExpectation<F>(this, file, line, source_text, m); @@ -1796,7 +1799,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // Reports an uninteresting call (whose description is in msg) in the // manner specified by 'reaction'. -void ReportUninterestingCall(CallReaction reaction, const string& msg); +void ReportUninterestingCall(CallReaction reaction, const std::string& msg); } // namespace internal diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index e2ddb05..7e65cea 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -267,7 +267,7 @@ class FailureReporterInterface { // Reports a failure that occurred at the given source file location. virtual void ReportFailure(FailureType type, const char* file, int line, - const string& message) = 0; + const std::string& message) = 0; }; // Returns the failure reporter used by Google Mock. @@ -279,7 +279,7 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter(); // inline this function to prevent it from showing up in the stack // trace. inline void Assert(bool condition, const char* file, int line, - const string& msg) { + const std::string& msg) { if (!condition) { GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, file, line, msg); @@ -292,7 +292,7 @@ inline void Assert(bool condition, const char* file, int line) { // Verifies that condition is true; generates a non-fatal failure if // condition is false. inline void Expect(bool condition, const char* file, int line, - const string& msg) { + const std::string& msg) { if (!condition) { GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal, file, line, msg); @@ -328,8 +328,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity); // stack_frames_to_skip is treated as 0, since we don't know which // function calls will be inlined by the compiler and need to be // conservative. -GTEST_API_ void Log(LogSeverity severity, - const string& message, +GTEST_API_ void Log(LogSeverity severity, const std::string& message, int stack_frames_to_skip); // TODO(wan@google.com): group all type utilities together. |