aboutsummaryrefslogtreecommitdiff
path: root/googlemock/src/gmock-matchers.cc
diff options
context:
space:
mode:
authorKrzysztof Kosiński <krzysio@google.com>2023-09-28 00:37:09 +0000
committerKrzysztof Kosiński <krzysio@google.com>2023-09-28 09:44:10 +0000
commita00801a508bed52885e961b08058af6af7206bf9 (patch)
treee568063ca5d9e9e557d71e24304156a62534b94a /googlemock/src/gmock-matchers.cc
parent817e9f6edc2fc8301b92403962478d2df0024924 (diff)
parente47544ad31cb3ceecd04cc13e8fe556f8df9fe0b (diff)
downloadgoogletest-a00801a508bed52885e961b08058af6af7206bf9.tar.gz
Upgrade googletest to most recent upstream version.
Changes needed to complete the upgrade: - Bump GMock C++ version to C++14. - Set gmock_tests to C++14 to work around an issue with ExpectCallTest.NonMoveableType, which fails to compile with the current AOSP compiler. - Disable -Wthread-safety-negative for the Notification type (breaks code that enables -Werror). - Disable -Wfloat-equal in AppropriateResolution (ditto). - Disable -Wuser-defined-warnings for the pointer printer to avoid errors in mock methods from the std namespace manipulation in android-base/logging.h. - Temporarily add an inclusion of <iomanip> to gtest/internal/custom/gtest-port.h. This header was previously included by gtest/internal/gtest-internal.h and many tests do not include it explicitly. - Remove the newline added in AddTestPartResult so that the golden output tests in gtest_isolated_tests do not break. Bug: 271622675 Test: presubmit Change-Id: Ic34a9add234dbbc5fc5162d0408c78844f2ae1e6
Diffstat (limited to 'googlemock/src/gmock-matchers.cc')
-rw-r--r--googlemock/src/gmock-matchers.cc32
1 files changed, 26 insertions, 6 deletions
diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc
index dded437a..81a5b7ea 100644
--- a/googlemock/src/gmock-matchers.cc
+++ b/googlemock/src/gmock-matchers.cc
@@ -27,7 +27,6 @@
// (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 Matcher<const string&>, Matcher<string>, and
@@ -36,9 +35,11 @@
#include "gmock/gmock-matchers.h"
#include <string.h>
+
#include <iostream>
#include <sstream>
#include <string>
+#include <vector>
namespace testing {
namespace internal {
@@ -48,11 +49,13 @@ namespace internal {
// '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_ std::string FormatMatcherDescription(bool negation,
- const char* matcher_name,
- const Strings& param_values) {
+GTEST_API_ std::string FormatMatcherDescription(
+ bool negation, const char* matcher_name,
+ const std::vector<const char*>& param_names, const Strings& param_values) {
std::string result = ConvertIdentifierNameToWords(matcher_name);
- if (param_values.size() >= 1) result += " " + JoinAsTuple(param_values);
+ if (!param_values.empty()) {
+ result += " " + JoinAsKeyValueTuple(param_names, param_values);
+ }
return negation ? "not (" + result + ")" : result;
}
@@ -117,7 +120,7 @@ GTEST_API_ std::string FormatMatcherDescription(bool negation,
// [1] Cormen, et al (2001). "Section 26.2: The Ford-Fulkerson method".
// "Introduction to Algorithms (Second ed.)", pp. 651-664.
// [2] "Ford-Fulkerson algorithm", Wikipedia,
-// 'http://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm'
+// 'https://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm'
class MaxBipartiteMatchState {
public:
explicit MaxBipartiteMatchState(const MatchMatrix& graph)
@@ -367,6 +370,23 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
const ::std::vector<std::string>& element_printouts,
const MatchMatrix& matrix, MatchResultListener* listener) const {
+ if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
+ return true;
+ }
+
+ if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
+ if (matrix.LhsSize() != matrix.RhsSize()) {
+ // The element count doesn't match. If the container is empty,
+ // there's no need to explain anything as Google Mock already
+ // prints the empty container. Otherwise we just need to show
+ // how many elements there actually are.
+ if (matrix.LhsSize() != 0 && listener->IsInterested()) {
+ *listener << "which has " << Elements(matrix.LhsSize());
+ }
+ return false;
+ }
+ }
+
bool result = true;
::std::vector<char> element_matched(matrix.LhsSize(), 0);
::std::vector<char> matcher_matched(matrix.RhsSize(), 0);