blob: a5ed686e8b9f31918a75c3ee56c1209ff1fc7f88 [file] [log] [blame]
shiqiane35fdd92008-12-10 05:08:54 +00001// Copyright 2007, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// Author: wan@google.com (Zhanyong Wan)
31
32// Google Mock - a framework for writing C++ mock classes.
33//
zhanyong.wan4a5330d2009-02-19 00:36:44 +000034// This file implements Matcher<const string&>, Matcher<string>, and
35// utilities for defining matchers.
shiqiane35fdd92008-12-10 05:08:54 +000036
zhanyong.wan53e08c42010-09-14 05:38:21 +000037#include "gmock/gmock-matchers.h"
38#include "gmock/gmock-generated-matchers.h"
zhanyong.wan4a5330d2009-02-19 00:36:44 +000039
40#include <string.h>
Gennadiy Civil2bd17502018-02-27 13:51:09 -050041#include <iostream>
zhanyong.wan4a5330d2009-02-19 00:36:44 +000042#include <sstream>
43#include <string>
shiqiane35fdd92008-12-10 05:08:54 +000044
45namespace testing {
46
Gennadiy Civilb7c56832018-03-22 15:35:37 -040047// Constructs a matcher that matches a const std::string& whose value is
shiqiane35fdd92008-12-10 05:08:54 +000048// equal to s.
Gennadiy Civilb7c56832018-03-22 15:35:37 -040049Matcher<const std::string&>::Matcher(const std::string& s) { *this = Eq(s); }
50
51#if GTEST_HAS_GLOBAL_STRING
52// Constructs a matcher that matches a const std::string& whose value is
53// equal to s.
54Matcher<const std::string&>::Matcher(const ::string& s) {
55 *this = Eq(static_cast<std::string>(s));
56}
57#endif // GTEST_HAS_GLOBAL_STRING
58
59// Constructs a matcher that matches a const std::string& whose value is
60// equal to s.
61Matcher<const std::string&>::Matcher(const char* s) {
62 *this = Eq(std::string(s));
shiqiane35fdd92008-12-10 05:08:54 +000063}
64
Gennadiy Civilb7c56832018-03-22 15:35:37 -040065// Constructs a matcher that matches a std::string whose value is equal to
66// s.
67Matcher<std::string>::Matcher(const std::string& s) { *this = Eq(s); }
68
69#if GTEST_HAS_GLOBAL_STRING
70// Constructs a matcher that matches a std::string whose value is equal to
71// s.
72Matcher<std::string>::Matcher(const ::string& s) {
73 *this = Eq(static_cast<std::string>(s));
shiqiane35fdd92008-12-10 05:08:54 +000074}
Gennadiy Civilb7c56832018-03-22 15:35:37 -040075#endif // GTEST_HAS_GLOBAL_STRING
76
77// Constructs a matcher that matches a std::string whose value is equal to
78// s.
79Matcher<std::string>::Matcher(const char* s) { *this = Eq(std::string(s)); }
80
81#if GTEST_HAS_GLOBAL_STRING
82// Constructs a matcher that matches a const ::string& whose value is
83// equal to s.
84Matcher<const ::string&>::Matcher(const std::string& s) {
85 *this = Eq(static_cast<::string>(s));
86}
87
88// Constructs a matcher that matches a const ::string& whose value is
89// equal to s.
90Matcher<const ::string&>::Matcher(const ::string& s) { *this = Eq(s); }
91
92// Constructs a matcher that matches a const ::string& whose value is
93// equal to s.
94Matcher<const ::string&>::Matcher(const char* s) { *this = Eq(::string(s)); }
95
96// Constructs a matcher that matches a ::string whose value is equal to s.
97Matcher<::string>::Matcher(const std::string& s) {
98 *this = Eq(static_cast<::string>(s));
99}
100
101// Constructs a matcher that matches a ::string whose value is equal to s.
102Matcher<::string>::Matcher(const ::string& s) { *this = Eq(s); }
shiqiane35fdd92008-12-10 05:08:54 +0000103
104// Constructs a matcher that matches a string whose value is equal to s.
Gennadiy Civilb7c56832018-03-22 15:35:37 -0400105Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); }
106#endif // GTEST_HAS_GLOBAL_STRING
shiqiane35fdd92008-12-10 05:08:54 +0000107
zhanyong.wan1f122a02013-03-25 16:27:03 +0000108
zhanyong.wan4a5330d2009-02-19 00:36:44 +0000109namespace internal {
110
zhanyong.wanb4140802010-06-08 22:53:57 +0000111// Returns the description for a matcher defined using the MATCHER*()
112// macro where the user-supplied description string is "", if
113// 'negation' is false; otherwise returns the description of the
114// negation of the matcher. 'param_values' contains a list of strings
115// that are the print-out of the matcher's parameters.
vladlosev587c1b32011-05-20 00:42:22 +0000116GTEST_API_ string FormatMatcherDescription(bool negation,
117 const char* matcher_name,
118 const Strings& param_values) {
zhanyong.wanb4140802010-06-08 22:53:57 +0000119 string result = ConvertIdentifierNameToWords(matcher_name);
120 if (param_values.size() >= 1)
121 result += " " + JoinAsTuple(param_values);
122 return negation ? "not (" + result + ")" : result;
zhanyong.wan4a5330d2009-02-19 00:36:44 +0000123}
124
zhanyong.wanfb25d532013-07-28 08:24:00 +0000125// FindMaxBipartiteMatching and its helper class.
126//
127// Uses the well-known Ford-Fulkerson max flow method to find a maximum
128// bipartite matching. Flow is considered to be from left to right.
129// There is an implicit source node that is connected to all of the left
130// nodes, and an implicit sink node that is connected to all of the
131// right nodes. All edges have unit capacity.
132//
133// Neither the flow graph nor the residual flow graph are represented
134// explicitly. Instead, they are implied by the information in 'graph' and
135// a vector<int> called 'left_' whose elements are initialized to the
136// value kUnused. This represents the initial state of the algorithm,
137// where the flow graph is empty, and the residual flow graph has the
138// following edges:
139// - An edge from source to each left_ node
140// - An edge from each right_ node to sink
141// - An edge from each left_ node to each right_ node, if the
142// corresponding edge exists in 'graph'.
143//
144// When the TryAugment() method adds a flow, it sets left_[l] = r for some
145// nodes l and r. This induces the following changes:
146// - The edges (source, l), (l, r), and (r, sink) are added to the
147// flow graph.
148// - The same three edges are removed from the residual flow graph.
149// - The reverse edges (l, source), (r, l), and (sink, r) are added
150// to the residual flow graph, which is a directional graph
151// representing unused flow capacity.
152//
153// When the method augments a flow (moving left_[l] from some r1 to some
154// other r2), this can be thought of as "undoing" the above steps with
155// respect to r1 and "redoing" them with respect to r2.
156//
157// It bears repeating that the flow graph and residual flow graph are
158// never represented explicitly, but can be derived by looking at the
159// information in 'graph' and in left_.
160//
161// As an optimization, there is a second vector<int> called right_ which
162// does not provide any new information. Instead, it enables more
163// efficient queries about edges entering or leaving the right-side nodes
164// of the flow or residual flow graphs. The following invariants are
165// maintained:
166//
167// left[l] == kUnused or right[left[l]] == l
168// right[r] == kUnused or left[right[r]] == r
169//
170// . [ source ] .
171// . ||| .
172// . ||| .
173// . ||\--> left[0]=1 ---\ right[0]=-1 ----\ .
174// . || | | .
175// . |\---> left[1]=-1 \--> right[1]=0 ---\| .
176// . | || .
177// . \----> left[2]=2 ------> right[2]=2 --\|| .
178// . ||| .
179// . elements matchers vvv .
180// . [ sink ] .
181//
182// See Also:
kosak15d61e42014-03-24 22:08:24 +0000183// [1] Cormen, et al (2001). "Section 26.2: The Ford-Fulkerson method".
184// "Introduction to Algorithms (Second ed.)", pp. 651-664.
185// [2] "Ford-Fulkerson algorithm", Wikipedia,
zhanyong.wanfb25d532013-07-28 08:24:00 +0000186// 'http://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm'
187class MaxBipartiteMatchState {
188 public:
189 explicit MaxBipartiteMatchState(const MatchMatrix& graph)
190 : graph_(&graph),
191 left_(graph_->LhsSize(), kUnused),
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500192 right_(graph_->RhsSize(), kUnused) {}
zhanyong.wanfb25d532013-07-28 08:24:00 +0000193
194 // Returns the edges of a maximal match, each in the form {left, right}.
195 ElementMatcherPairs Compute() {
196 // 'seen' is used for path finding { 0: unseen, 1: seen }.
197 ::std::vector<char> seen;
198 // Searches the residual flow graph for a path from each left node to
199 // the sink in the residual flow graph, and if one is found, add flow
200 // to the graph. It's okay to search through the left nodes once. The
201 // edge from the implicit source node to each previously-visited left
202 // node will have flow if that left node has any path to the sink
203 // whatsoever. Subsequent augmentations can only add flow to the
204 // network, and cannot take away that previous flow unit from the source.
205 // Since the source-to-left edge can only carry one flow unit (or,
206 // each element can be matched to only one matcher), there is no need
207 // to visit the left nodes more than once looking for augmented paths.
208 // The flow is known to be possible or impossible by looking at the
209 // node once.
210 for (size_t ilhs = 0; ilhs < graph_->LhsSize(); ++ilhs) {
211 // Reset the path-marking vector and try to find a path from
212 // source to sink starting at the left_[ilhs] node.
213 GTEST_CHECK_(left_[ilhs] == kUnused)
214 << "ilhs: " << ilhs << ", left_[ilhs]: " << left_[ilhs];
215 // 'seen' initialized to 'graph_->RhsSize()' copies of 0.
216 seen.assign(graph_->RhsSize(), 0);
217 TryAugment(ilhs, &seen);
218 }
219 ElementMatcherPairs result;
220 for (size_t ilhs = 0; ilhs < left_.size(); ++ilhs) {
221 size_t irhs = left_[ilhs];
222 if (irhs == kUnused) continue;
223 result.push_back(ElementMatcherPair(ilhs, irhs));
224 }
225 return result;
226 }
227
228 private:
229 static const size_t kUnused = static_cast<size_t>(-1);
230
231 // Perform a depth-first search from left node ilhs to the sink. If a
232 // path is found, flow is added to the network by linking the left and
233 // right vector elements corresponding each segment of the path.
234 // Returns true if a path to sink was found, which means that a unit of
235 // flow was added to the network. The 'seen' vector elements correspond
236 // to right nodes and are marked to eliminate cycles from the search.
237 //
238 // Left nodes will only be explored at most once because they
239 // are accessible from at most one right node in the residual flow
240 // graph.
241 //
242 // Note that left_[ilhs] is the only element of left_ that TryAugment will
243 // potentially transition from kUnused to another value. Any other
244 // left_ element holding kUnused before TryAugment will be holding it
245 // when TryAugment returns.
246 //
247 bool TryAugment(size_t ilhs, ::std::vector<char>* seen) {
248 for (size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) {
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500249 if ((*seen)[irhs]) continue;
250 if (!graph_->HasEdge(ilhs, irhs)) continue;
zhanyong.wanfb25d532013-07-28 08:24:00 +0000251 // There's an available edge from ilhs to irhs.
252 (*seen)[irhs] = 1;
253 // Next a search is performed to determine whether
254 // this edge is a dead end or leads to the sink.
255 //
256 // right_[irhs] == kUnused means that there is residual flow from
257 // right node irhs to the sink, so we can use that to finish this
258 // flow path and return success.
259 //
260 // Otherwise there is residual flow to some ilhs. We push flow
261 // along that path and call ourselves recursively to see if this
262 // ultimately leads to sink.
263 if (right_[irhs] == kUnused || TryAugment(right_[irhs], seen)) {
264 // Add flow from left_[ilhs] to right_[irhs].
265 left_[ilhs] = irhs;
266 right_[irhs] = ilhs;
267 return true;
268 }
269 }
270 return false;
271 }
272
273 const MatchMatrix* graph_; // not owned
274 // Each element of the left_ vector represents a left hand side node
275 // (i.e. an element) and each element of right_ is a right hand side
276 // node (i.e. a matcher). The values in the left_ vector indicate
Li Peng266a1852016-04-27 16:41:27 +0800277 // outflow from that node to a node on the right_ side. The values
zhanyong.wanfb25d532013-07-28 08:24:00 +0000278 // in the right_ indicate inflow, and specify which left_ node is
279 // feeding that right_ node, if any. For example, left_[3] == 1 means
280 // there's a flow from element #3 to matcher #1. Such a flow would also
281 // be redundantly represented in the right_ vector as right_[1] == 3.
282 // Elements of left_ and right_ are either kUnused or mutually
283 // referent. Mutually referent means that left_[right_[i]] = i and
284 // right_[left_[i]] = i.
285 ::std::vector<size_t> left_;
286 ::std::vector<size_t> right_;
287
288 GTEST_DISALLOW_ASSIGN_(MaxBipartiteMatchState);
289};
290
291const size_t MaxBipartiteMatchState::kUnused;
292
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500293GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix& g) {
zhanyong.wanfb25d532013-07-28 08:24:00 +0000294 return MaxBipartiteMatchState(g).Compute();
295}
296
297static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
298 ::std::ostream* stream) {
299 typedef ElementMatcherPairs::const_iterator Iter;
300 ::std::ostream& os = *stream;
301 os << "{";
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500302 const char* sep = "";
zhanyong.wanfb25d532013-07-28 08:24:00 +0000303 for (Iter it = pairs.begin(); it != pairs.end(); ++it) {
304 os << sep << "\n ("
305 << "element #" << it->first << ", "
306 << "matcher #" << it->second << ")";
307 sep = ",";
308 }
309 os << "\n}";
310}
311
zhanyong.wanfb25d532013-07-28 08:24:00 +0000312bool MatchMatrix::NextGraph() {
313 for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
314 for (size_t irhs = 0; irhs < RhsSize(); ++irhs) {
315 char& b = matched_[SpaceIndex(ilhs, irhs)];
316 if (!b) {
317 b = 1;
318 return true;
319 }
320 b = 0;
321 }
322 }
323 return false;
324}
325
326void MatchMatrix::Randomize() {
327 for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
328 for (size_t irhs = 0; irhs < RhsSize(); ++irhs) {
329 char& b = matched_[SpaceIndex(ilhs, irhs)];
330 b = static_cast<char>(rand() & 1); // NOLINT
331 }
332 }
333}
334
Nico Weber09fd5b32017-05-15 17:07:03 -0400335std::string MatchMatrix::DebugString() const {
zhanyong.wanfb25d532013-07-28 08:24:00 +0000336 ::std::stringstream ss;
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500337 const char* sep = "";
zhanyong.wanfb25d532013-07-28 08:24:00 +0000338 for (size_t i = 0; i < LhsSize(); ++i) {
339 ss << sep;
340 for (size_t j = 0; j < RhsSize(); ++j) {
341 ss << HasEdge(i, j);
342 }
343 sep = ";";
344 }
345 return ss.str();
346}
347
348void UnorderedElementsAreMatcherImplBase::DescribeToImpl(
349 ::std::ostream* os) const {
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500350 switch (match_flags()) {
351 case UnorderedMatcherRequire::ExactMatch:
352 if (matcher_describers_.empty()) {
353 *os << "is empty";
354 return;
355 }
356 if (matcher_describers_.size() == 1) {
357 *os << "has " << Elements(1) << " and that element ";
358 matcher_describers_[0]->DescribeTo(os);
359 return;
360 }
361 *os << "has " << Elements(matcher_describers_.size())
362 << " and there exists some permutation of elements such that:\n";
363 break;
364 case UnorderedMatcherRequire::Superset:
365 *os << "a surjection from elements to requirements exists such that:\n";
366 break;
367 case UnorderedMatcherRequire::Subset:
368 *os << "an injection from elements to requirements exists such that:\n";
369 break;
zhanyong.wanfb25d532013-07-28 08:24:00 +0000370 }
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500371
zhanyong.wanfb25d532013-07-28 08:24:00 +0000372 const char* sep = "";
373 for (size_t i = 0; i != matcher_describers_.size(); ++i) {
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500374 *os << sep;
375 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
376 *os << " - element #" << i << " ";
377 } else {
378 *os << " - an element ";
379 }
zhanyong.wanfb25d532013-07-28 08:24:00 +0000380 matcher_describers_[i]->DescribeTo(os);
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500381 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
382 sep = ", and\n";
383 } else {
384 sep = "\n";
385 }
zhanyong.wanfb25d532013-07-28 08:24:00 +0000386 }
387}
388
389void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
390 ::std::ostream* os) const {
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500391 switch (match_flags()) {
392 case UnorderedMatcherRequire::ExactMatch:
393 if (matcher_describers_.empty()) {
394 *os << "isn't empty";
395 return;
396 }
397 if (matcher_describers_.size() == 1) {
398 *os << "doesn't have " << Elements(1) << ", or has " << Elements(1)
399 << " that ";
400 matcher_describers_[0]->DescribeNegationTo(os);
401 return;
402 }
403 *os << "doesn't have " << Elements(matcher_describers_.size())
404 << ", or there exists no permutation of elements such that:\n";
405 break;
406 case UnorderedMatcherRequire::Superset:
407 *os << "no surjection from elements to requirements exists such that:\n";
408 break;
409 case UnorderedMatcherRequire::Subset:
410 *os << "no injection from elements to requirements exists such that:\n";
411 break;
zhanyong.wanfb25d532013-07-28 08:24:00 +0000412 }
zhanyong.wanfb25d532013-07-28 08:24:00 +0000413 const char* sep = "";
414 for (size_t i = 0; i != matcher_describers_.size(); ++i) {
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500415 *os << sep;
416 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
417 *os << " - element #" << i << " ";
418 } else {
419 *os << " - an element ";
420 }
zhanyong.wanfb25d532013-07-28 08:24:00 +0000421 matcher_describers_[i]->DescribeTo(os);
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500422 if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
423 sep = ", and\n";
424 } else {
425 sep = "\n";
426 }
zhanyong.wanfb25d532013-07-28 08:24:00 +0000427 }
428}
429
430// Checks that all matchers match at least one element, and that all
431// elements match at least one matcher. This enables faster matching
432// and better error reporting.
433// Returns false, writing an explanation to 'listener', if and only
434// if the success criteria are not met.
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500435bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
436 const ::std::vector<std::string>& element_printouts,
437 const MatchMatrix& matrix, MatchResultListener* listener) const {
zhanyong.wanfb25d532013-07-28 08:24:00 +0000438 bool result = true;
439 ::std::vector<char> element_matched(matrix.LhsSize(), 0);
440 ::std::vector<char> matcher_matched(matrix.RhsSize(), 0);
441
442 for (size_t ilhs = 0; ilhs < matrix.LhsSize(); ilhs++) {
443 for (size_t irhs = 0; irhs < matrix.RhsSize(); irhs++) {
444 char matched = matrix.HasEdge(ilhs, irhs);
445 element_matched[ilhs] |= matched;
446 matcher_matched[irhs] |= matched;
447 }
448 }
449
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500450 if (match_flags() & UnorderedMatcherRequire::Superset) {
zhanyong.wanfb25d532013-07-28 08:24:00 +0000451 const char* sep =
452 "where the following matchers don't match any elements:\n";
453 for (size_t mi = 0; mi < matcher_matched.size(); ++mi) {
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500454 if (matcher_matched[mi]) continue;
zhanyong.wanfb25d532013-07-28 08:24:00 +0000455 result = false;
456 if (listener->IsInterested()) {
457 *listener << sep << "matcher #" << mi << ": ";
458 matcher_describers_[mi]->DescribeTo(listener->stream());
459 sep = ",\n";
460 }
461 }
462 }
463
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500464 if (match_flags() & UnorderedMatcherRequire::Subset) {
zhanyong.wanfb25d532013-07-28 08:24:00 +0000465 const char* sep =
466 "where the following elements don't match any matchers:\n";
467 const char* outer_sep = "";
468 if (!result) {
469 outer_sep = "\nand ";
470 }
471 for (size_t ei = 0; ei < element_matched.size(); ++ei) {
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500472 if (element_matched[ei]) continue;
zhanyong.wanfb25d532013-07-28 08:24:00 +0000473 result = false;
474 if (listener->IsInterested()) {
475 *listener << outer_sep << sep << "element #" << ei << ": "
476 << element_printouts[ei];
477 sep = ",\n";
478 outer_sep = "";
479 }
480 }
481 }
482 return result;
483}
484
Gennadiy Civil2bd17502018-02-27 13:51:09 -0500485bool UnorderedElementsAreMatcherImplBase::FindPairing(
486 const MatchMatrix& matrix, MatchResultListener* listener) const {
487 ElementMatcherPairs matches = FindMaxBipartiteMatching(matrix);
488
489 size_t max_flow = matches.size();
490 if ((match_flags() & UnorderedMatcherRequire::Superset) &&
491 max_flow < matrix.RhsSize()) {
492 if (listener->IsInterested()) {
493 *listener << "where no permutation of the elements can satisfy all "
494 "matchers, and the closest match is "
495 << max_flow << " of " << matrix.RhsSize()
496 << " matchers with the pairings:\n";
497 LogElementMatcherPairVec(matches, listener->stream());
498 }
499 return false;
500 }
501 if ((match_flags() & UnorderedMatcherRequire::Subset) &&
502 max_flow < matrix.LhsSize()) {
503 if (listener->IsInterested()) {
504 *listener
505 << "where not all elements can be matched, and the closest match is "
506 << max_flow << " of " << matrix.RhsSize()
507 << " matchers with the pairings:\n";
508 LogElementMatcherPairVec(matches, listener->stream());
509 }
510 return false;
511 }
512
513 if (matches.size() > 1) {
514 if (listener->IsInterested()) {
515 const char* sep = "where:\n";
516 for (size_t mi = 0; mi < matches.size(); ++mi) {
517 *listener << sep << " - element #" << matches[mi].first
518 << " is matched by matcher #" << matches[mi].second;
519 sep = ",\n";
520 }
521 }
522 }
523 return true;
524}
525
zhanyong.wan4a5330d2009-02-19 00:36:44 +0000526} // namespace internal
shiqiane35fdd92008-12-10 05:08:54 +0000527} // namespace testing