X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=googlemock%2Finclude%2Fgmock%2Fgmock-more-matchers.h;h=54ea68be969d6845208a407f3725f2fb0b00e212;hb=35012fd0964a1a5455ccd93dd34531ce90728a08;hp=1c9a399a341e79ee0102c674a75a269bd2552ec2;hpb=e7b4c00007893a03bd18ec50f004b1031e3d635b;p=platform%2Fupstream%2Fgtest.git diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index 1c9a399..54ea68b 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -27,43 +27,71 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - // Google Mock - a framework for writing C++ mock classes. // -// This file implements some matchers that depend on gmock-generated-matchers.h. +// This file implements some matchers that depend on gmock-matchers.h. // // Note that tests are implemented in gmock-matchers_test.cc rather than // gmock-more-matchers-test.cc. -// GOOGLETEST_CM0002 DO NOT DELETE +// IWYU pragma: private, include "gmock/gmock.h" +// IWYU pragma: friend gmock/.* + +#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ +#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_ -#ifndef GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_ -#define GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_ +#include +#include -#include "gmock/gmock-generated-matchers.h" +#include "gmock/gmock-matchers.h" namespace testing { // Silence C4100 (unreferenced formal // parameter) for MSVC -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) -#if (_MSC_VER == 1900) +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100) +#if defined(_MSC_VER) && (_MSC_VER == 1900) // and silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 14 -# pragma warning(disable:4800) - #endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800) #endif -// Defines a matcher that matches an empty container. The container must -// support both size() and empty(), which all STL-like containers provide. -MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { - if (arg.empty()) { - return true; +namespace internal { + +// Implements the polymorphic IsEmpty matcher, which +// can be used as a Matcher as long as T is either a container that defines +// empty() and size() (e.g. std::vector or std::string), or a C-style string. +class IsEmptyMatcher { + public: + // Matches anything that defines empty() and size(). + template + bool MatchAndExplain(const MatcheeContainerType& c, + MatchResultListener* listener) const { + if (c.empty()) { + return true; + } + *listener << "whose size is " << c.size(); + return false; + } + + // Matches C-style strings. + bool MatchAndExplain(const char* s, MatchResultListener* listener) const { + return MatchAndExplain(std::string(s), listener); } - *result_listener << "whose size is " << arg.size(); - return false; + + // Describes what this matcher matches. + void DescribeTo(std::ostream* os) const { *os << "is empty"; } + + void DescribeNegationTo(std::ostream* os) const { *os << "isn't empty"; } +}; + +} // namespace internal + +// Creates a polymorphic matcher that matches an empty container or C-style +// string. The container must support both size() and empty(), which all +// STL-like containers provide. +inline PolymorphicMatcher IsEmpty() { + return MakePolymorphicMatcher(internal::IsEmptyMatcher()); } // Define a matcher that matches a value that evaluates in boolean @@ -82,11 +110,11 @@ MATCHER(IsFalse, negation ? "is true" : "is false") { return !static_cast(arg); } -#ifdef _MSC_VER -# pragma warning(pop) +#if defined(_MSC_VER) && (_MSC_VER == 1900) +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800 #endif - +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 } // namespace testing -#endif // GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_ +#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_MATCHERS_H_