Imported Upstream version 1.14.0
[platform/upstream/gtest.git] / googlemock / include / gmock / gmock-more-matchers.h
index 1c9a399..54ea68b 100644 (file)
 // (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 <ostream>
+#include <string>
 
-#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<T> 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 <typename MatcheeContainerType>
+  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<internal::IsEmptyMatcher> 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<bool>(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_