gmock-matchers.cc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. // 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. // Google Mock - a framework for writing C++ mock classes.
  30. //
  31. // This file implements Matcher<const string&>, Matcher<string>, and
  32. // utilities for defining matchers.
  33. #include "gmock/gmock-matchers.h"
  34. #include "gmock/gmock-generated-matchers.h"
  35. #include <string.h>
  36. #include <iostream>
  37. #include <sstream>
  38. #include <string>
  39. namespace testing {
  40. // Constructs a matcher that matches a const std::string& whose value is
  41. // equal to s.
  42. Matcher<const std::string&>::Matcher(const std::string& s) { *this = Eq(s); }
  43. #if GTEST_HAS_GLOBAL_STRING
  44. // Constructs a matcher that matches a const std::string& whose value is
  45. // equal to s.
  46. Matcher<const std::string&>::Matcher(const ::string& s) {
  47. *this = Eq(static_cast<std::string>(s));
  48. }
  49. #endif // GTEST_HAS_GLOBAL_STRING
  50. // Constructs a matcher that matches a const std::string& whose value is
  51. // equal to s.
  52. Matcher<const std::string&>::Matcher(const char* s) {
  53. *this = Eq(std::string(s));
  54. }
  55. // Constructs a matcher that matches a std::string whose value is equal to
  56. // s.
  57. Matcher<std::string>::Matcher(const std::string& s) { *this = Eq(s); }
  58. #if GTEST_HAS_GLOBAL_STRING
  59. // Constructs a matcher that matches a std::string whose value is equal to
  60. // s.
  61. Matcher<std::string>::Matcher(const ::string& s) {
  62. *this = Eq(static_cast<std::string>(s));
  63. }
  64. #endif // GTEST_HAS_GLOBAL_STRING
  65. // Constructs a matcher that matches a std::string whose value is equal to
  66. // s.
  67. Matcher<std::string>::Matcher(const char* s) { *this = Eq(std::string(s)); }
  68. #if GTEST_HAS_GLOBAL_STRING
  69. // Constructs a matcher that matches a const ::string& whose value is
  70. // equal to s.
  71. Matcher<const ::string&>::Matcher(const std::string& s) {
  72. *this = Eq(static_cast<::string>(s));
  73. }
  74. // Constructs a matcher that matches a const ::string& whose value is
  75. // equal to s.
  76. Matcher<const ::string&>::Matcher(const ::string& s) { *this = Eq(s); }
  77. // Constructs a matcher that matches a const ::string& whose value is
  78. // equal to s.
  79. Matcher<const ::string&>::Matcher(const char* s) { *this = Eq(::string(s)); }
  80. // Constructs a matcher that matches a ::string whose value is equal to s.
  81. Matcher<::string>::Matcher(const std::string& s) {
  82. *this = Eq(static_cast<::string>(s));
  83. }
  84. // Constructs a matcher that matches a ::string whose value is equal to s.
  85. Matcher<::string>::Matcher(const ::string& s) { *this = Eq(s); }
  86. // Constructs a matcher that matches a string whose value is equal to s.
  87. Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); }
  88. #endif // GTEST_HAS_GLOBAL_STRING
  89. #if GTEST_HAS_ABSL
  90. // Constructs a matcher that matches a const absl::string_view& whose value is
  91. // equal to s.
  92. Matcher<const absl::string_view&>::Matcher(const std::string& s) {
  93. *this = Eq(s);
  94. }
  95. #if GTEST_HAS_GLOBAL_STRING
  96. // Constructs a matcher that matches a const absl::string_view& whose value is
  97. // equal to s.
  98. Matcher<const absl::string_view&>::Matcher(const ::string& s) { *this = Eq(s); }
  99. #endif // GTEST_HAS_GLOBAL_STRING
  100. // Constructs a matcher that matches a const absl::string_view& whose value is
  101. // equal to s.
  102. Matcher<const absl::string_view&>::Matcher(const char* s) {
  103. *this = Eq(std::string(s));
  104. }
  105. // Constructs a matcher that matches a const absl::string_view& whose value is
  106. // equal to s.
  107. Matcher<const absl::string_view&>::Matcher(absl::string_view s) {
  108. *this = Eq(std::string(s));
  109. }
  110. // Constructs a matcher that matches a absl::string_view whose value is equal to
  111. // s.
  112. Matcher<absl::string_view>::Matcher(const std::string& s) { *this = Eq(s); }
  113. #if GTEST_HAS_GLOBAL_STRING
  114. // Constructs a matcher that matches a absl::string_view whose value is equal to
  115. // s.
  116. Matcher<absl::string_view>::Matcher(const ::string& s) { *this = Eq(s); }
  117. #endif // GTEST_HAS_GLOBAL_STRING
  118. // Constructs a matcher that matches a absl::string_view whose value is equal to
  119. // s.
  120. Matcher<absl::string_view>::Matcher(const char* s) {
  121. *this = Eq(std::string(s));
  122. }
  123. // Constructs a matcher that matches a absl::string_view whose value is equal to
  124. // s.
  125. Matcher<absl::string_view>::Matcher(absl::string_view s) {
  126. *this = Eq(std::string(s));
  127. }
  128. #endif // GTEST_HAS_ABSL
  129. namespace internal {
  130. // Returns the description for a matcher defined using the MATCHER*()
  131. // macro where the user-supplied description string is "", if
  132. // 'negation' is false; otherwise returns the description of the
  133. // negation of the matcher. 'param_values' contains a list of strings
  134. // that are the print-out of the matcher's parameters.
  135. GTEST_API_ std::string FormatMatcherDescription(bool negation,
  136. const char* matcher_name,
  137. const Strings& param_values) {
  138. std::string result = ConvertIdentifierNameToWords(matcher_name);
  139. if (param_values.size() >= 1) result += " " + JoinAsTuple(param_values);
  140. return negation ? "not (" + result + ")" : result;
  141. }
  142. // FindMaxBipartiteMatching and its helper class.
  143. //
  144. // Uses the well-known Ford-Fulkerson max flow method to find a maximum
  145. // bipartite matching. Flow is considered to be from left to right.
  146. // There is an implicit source node that is connected to all of the left
  147. // nodes, and an implicit sink node that is connected to all of the
  148. // right nodes. All edges have unit capacity.
  149. //
  150. // Neither the flow graph nor the residual flow graph are represented
  151. // explicitly. Instead, they are implied by the information in 'graph' and
  152. // a vector<int> called 'left_' whose elements are initialized to the
  153. // value kUnused. This represents the initial state of the algorithm,
  154. // where the flow graph is empty, and the residual flow graph has the
  155. // following edges:
  156. // - An edge from source to each left_ node
  157. // - An edge from each right_ node to sink
  158. // - An edge from each left_ node to each right_ node, if the
  159. // corresponding edge exists in 'graph'.
  160. //
  161. // When the TryAugment() method adds a flow, it sets left_[l] = r for some
  162. // nodes l and r. This induces the following changes:
  163. // - The edges (source, l), (l, r), and (r, sink) are added to the
  164. // flow graph.
  165. // - The same three edges are removed from the residual flow graph.
  166. // - The reverse edges (l, source), (r, l), and (sink, r) are added
  167. // to the residual flow graph, which is a directional graph
  168. // representing unused flow capacity.
  169. //
  170. // When the method augments a flow (moving left_[l] from some r1 to some
  171. // other r2), this can be thought of as "undoing" the above steps with
  172. // respect to r1 and "redoing" them with respect to r2.
  173. //
  174. // It bears repeating that the flow graph and residual flow graph are
  175. // never represented explicitly, but can be derived by looking at the
  176. // information in 'graph' and in left_.
  177. //
  178. // As an optimization, there is a second vector<int> called right_ which
  179. // does not provide any new information. Instead, it enables more
  180. // efficient queries about edges entering or leaving the right-side nodes
  181. // of the flow or residual flow graphs. The following invariants are
  182. // maintained:
  183. //
  184. // left[l] == kUnused or right[left[l]] == l
  185. // right[r] == kUnused or left[right[r]] == r
  186. //
  187. // . [ source ] .
  188. // . ||| .
  189. // . ||| .
  190. // . ||\--> left[0]=1 ---\ right[0]=-1 ----\ .
  191. // . || | | .
  192. // . |\---> left[1]=-1 \--> right[1]=0 ---\| .
  193. // . | || .
  194. // . \----> left[2]=2 ------> right[2]=2 --\|| .
  195. // . ||| .
  196. // . elements matchers vvv .
  197. // . [ sink ] .
  198. //
  199. // See Also:
  200. // [1] Cormen, et al (2001). "Section 26.2: The Ford-Fulkerson method".
  201. // "Introduction to Algorithms (Second ed.)", pp. 651-664.
  202. // [2] "Ford-Fulkerson algorithm", Wikipedia,
  203. // 'http://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm'
  204. class MaxBipartiteMatchState {
  205. public:
  206. explicit MaxBipartiteMatchState(const MatchMatrix& graph)
  207. : graph_(&graph),
  208. left_(graph_->LhsSize(), kUnused),
  209. right_(graph_->RhsSize(), kUnused) {}
  210. // Returns the edges of a maximal match, each in the form {left, right}.
  211. ElementMatcherPairs Compute() {
  212. // 'seen' is used for path finding { 0: unseen, 1: seen }.
  213. ::std::vector<char> seen;
  214. // Searches the residual flow graph for a path from each left node to
  215. // the sink in the residual flow graph, and if one is found, add flow
  216. // to the graph. It's okay to search through the left nodes once. The
  217. // edge from the implicit source node to each previously-visited left
  218. // node will have flow if that left node has any path to the sink
  219. // whatsoever. Subsequent augmentations can only add flow to the
  220. // network, and cannot take away that previous flow unit from the source.
  221. // Since the source-to-left edge can only carry one flow unit (or,
  222. // each element can be matched to only one matcher), there is no need
  223. // to visit the left nodes more than once looking for augmented paths.
  224. // The flow is known to be possible or impossible by looking at the
  225. // node once.
  226. for (size_t ilhs = 0; ilhs < graph_->LhsSize(); ++ilhs) {
  227. // Reset the path-marking vector and try to find a path from
  228. // source to sink starting at the left_[ilhs] node.
  229. GTEST_CHECK_(left_[ilhs] == kUnused)
  230. << "ilhs: " << ilhs << ", left_[ilhs]: " << left_[ilhs];
  231. // 'seen' initialized to 'graph_->RhsSize()' copies of 0.
  232. seen.assign(graph_->RhsSize(), 0);
  233. TryAugment(ilhs, &seen);
  234. }
  235. ElementMatcherPairs result;
  236. for (size_t ilhs = 0; ilhs < left_.size(); ++ilhs) {
  237. size_t irhs = left_[ilhs];
  238. if (irhs == kUnused) continue;
  239. result.push_back(ElementMatcherPair(ilhs, irhs));
  240. }
  241. return result;
  242. }
  243. private:
  244. static const size_t kUnused = static_cast<size_t>(-1);
  245. // Perform a depth-first search from left node ilhs to the sink. If a
  246. // path is found, flow is added to the network by linking the left and
  247. // right vector elements corresponding each segment of the path.
  248. // Returns true if a path to sink was found, which means that a unit of
  249. // flow was added to the network. The 'seen' vector elements correspond
  250. // to right nodes and are marked to eliminate cycles from the search.
  251. //
  252. // Left nodes will only be explored at most once because they
  253. // are accessible from at most one right node in the residual flow
  254. // graph.
  255. //
  256. // Note that left_[ilhs] is the only element of left_ that TryAugment will
  257. // potentially transition from kUnused to another value. Any other
  258. // left_ element holding kUnused before TryAugment will be holding it
  259. // when TryAugment returns.
  260. //
  261. bool TryAugment(size_t ilhs, ::std::vector<char>* seen) {
  262. for (size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) {
  263. if ((*seen)[irhs]) continue;
  264. if (!graph_->HasEdge(ilhs, irhs)) continue;
  265. // There's an available edge from ilhs to irhs.
  266. (*seen)[irhs] = 1;
  267. // Next a search is performed to determine whether
  268. // this edge is a dead end or leads to the sink.
  269. //
  270. // right_[irhs] == kUnused means that there is residual flow from
  271. // right node irhs to the sink, so we can use that to finish this
  272. // flow path and return success.
  273. //
  274. // Otherwise there is residual flow to some ilhs. We push flow
  275. // along that path and call ourselves recursively to see if this
  276. // ultimately leads to sink.
  277. if (right_[irhs] == kUnused || TryAugment(right_[irhs], seen)) {
  278. // Add flow from left_[ilhs] to right_[irhs].
  279. left_[ilhs] = irhs;
  280. right_[irhs] = ilhs;
  281. return true;
  282. }
  283. }
  284. return false;
  285. }
  286. const MatchMatrix* graph_; // not owned
  287. // Each element of the left_ vector represents a left hand side node
  288. // (i.e. an element) and each element of right_ is a right hand side
  289. // node (i.e. a matcher). The values in the left_ vector indicate
  290. // outflow from that node to a node on the right_ side. The values
  291. // in the right_ indicate inflow, and specify which left_ node is
  292. // feeding that right_ node, if any. For example, left_[3] == 1 means
  293. // there's a flow from element #3 to matcher #1. Such a flow would also
  294. // be redundantly represented in the right_ vector as right_[1] == 3.
  295. // Elements of left_ and right_ are either kUnused or mutually
  296. // referent. Mutually referent means that left_[right_[i]] = i and
  297. // right_[left_[i]] = i.
  298. ::std::vector<size_t> left_;
  299. ::std::vector<size_t> right_;
  300. GTEST_DISALLOW_ASSIGN_(MaxBipartiteMatchState);
  301. };
  302. const size_t MaxBipartiteMatchState::kUnused;
  303. GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix& g) {
  304. return MaxBipartiteMatchState(g).Compute();
  305. }
  306. static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
  307. ::std::ostream* stream) {
  308. typedef ElementMatcherPairs::const_iterator Iter;
  309. ::std::ostream& os = *stream;
  310. os << "{";
  311. const char* sep = "";
  312. for (Iter it = pairs.begin(); it != pairs.end(); ++it) {
  313. os << sep << "\n ("
  314. << "element #" << it->first << ", "
  315. << "matcher #" << it->second << ")";
  316. sep = ",";
  317. }
  318. os << "\n}";
  319. }
  320. bool MatchMatrix::NextGraph() {
  321. for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
  322. for (size_t irhs = 0; irhs < RhsSize(); ++irhs) {
  323. char& b = matched_[SpaceIndex(ilhs, irhs)];
  324. if (!b) {
  325. b = 1;
  326. return true;
  327. }
  328. b = 0;
  329. }
  330. }
  331. return false;
  332. }
  333. void MatchMatrix::Randomize() {
  334. for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
  335. for (size_t irhs = 0; irhs < RhsSize(); ++irhs) {
  336. char& b = matched_[SpaceIndex(ilhs, irhs)];
  337. b = static_cast<char>(rand() & 1); // NOLINT
  338. }
  339. }
  340. }
  341. std::string MatchMatrix::DebugString() const {
  342. ::std::stringstream ss;
  343. const char* sep = "";
  344. for (size_t i = 0; i < LhsSize(); ++i) {
  345. ss << sep;
  346. for (size_t j = 0; j < RhsSize(); ++j) {
  347. ss << HasEdge(i, j);
  348. }
  349. sep = ";";
  350. }
  351. return ss.str();
  352. }
  353. void UnorderedElementsAreMatcherImplBase::DescribeToImpl(
  354. ::std::ostream* os) const {
  355. switch (match_flags()) {
  356. case UnorderedMatcherRequire::ExactMatch:
  357. if (matcher_describers_.empty()) {
  358. *os << "is empty";
  359. return;
  360. }
  361. if (matcher_describers_.size() == 1) {
  362. *os << "has " << Elements(1) << " and that element ";
  363. matcher_describers_[0]->DescribeTo(os);
  364. return;
  365. }
  366. *os << "has " << Elements(matcher_describers_.size())
  367. << " and there exists some permutation of elements such that:\n";
  368. break;
  369. case UnorderedMatcherRequire::Superset:
  370. *os << "a surjection from elements to requirements exists such that:\n";
  371. break;
  372. case UnorderedMatcherRequire::Subset:
  373. *os << "an injection from elements to requirements exists such that:\n";
  374. break;
  375. }
  376. const char* sep = "";
  377. for (size_t i = 0; i != matcher_describers_.size(); ++i) {
  378. *os << sep;
  379. if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
  380. *os << " - element #" << i << " ";
  381. } else {
  382. *os << " - an element ";
  383. }
  384. matcher_describers_[i]->DescribeTo(os);
  385. if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
  386. sep = ", and\n";
  387. } else {
  388. sep = "\n";
  389. }
  390. }
  391. }
  392. void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
  393. ::std::ostream* os) const {
  394. switch (match_flags()) {
  395. case UnorderedMatcherRequire::ExactMatch:
  396. if (matcher_describers_.empty()) {
  397. *os << "isn't empty";
  398. return;
  399. }
  400. if (matcher_describers_.size() == 1) {
  401. *os << "doesn't have " << Elements(1) << ", or has " << Elements(1)
  402. << " that ";
  403. matcher_describers_[0]->DescribeNegationTo(os);
  404. return;
  405. }
  406. *os << "doesn't have " << Elements(matcher_describers_.size())
  407. << ", or there exists no permutation of elements such that:\n";
  408. break;
  409. case UnorderedMatcherRequire::Superset:
  410. *os << "no surjection from elements to requirements exists such that:\n";
  411. break;
  412. case UnorderedMatcherRequire::Subset:
  413. *os << "no injection from elements to requirements exists such that:\n";
  414. break;
  415. }
  416. const char* sep = "";
  417. for (size_t i = 0; i != matcher_describers_.size(); ++i) {
  418. *os << sep;
  419. if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
  420. *os << " - element #" << i << " ";
  421. } else {
  422. *os << " - an element ";
  423. }
  424. matcher_describers_[i]->DescribeTo(os);
  425. if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
  426. sep = ", and\n";
  427. } else {
  428. sep = "\n";
  429. }
  430. }
  431. }
  432. // Checks that all matchers match at least one element, and that all
  433. // elements match at least one matcher. This enables faster matching
  434. // and better error reporting.
  435. // Returns false, writing an explanation to 'listener', if and only
  436. // if the success criteria are not met.
  437. bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
  438. const ::std::vector<std::string>& element_printouts,
  439. const MatchMatrix& matrix, MatchResultListener* listener) const {
  440. bool result = true;
  441. ::std::vector<char> element_matched(matrix.LhsSize(), 0);
  442. ::std::vector<char> matcher_matched(matrix.RhsSize(), 0);
  443. for (size_t ilhs = 0; ilhs < matrix.LhsSize(); ilhs++) {
  444. for (size_t irhs = 0; irhs < matrix.RhsSize(); irhs++) {
  445. char matched = matrix.HasEdge(ilhs, irhs);
  446. element_matched[ilhs] |= matched;
  447. matcher_matched[irhs] |= matched;
  448. }
  449. }
  450. if (match_flags() & UnorderedMatcherRequire::Superset) {
  451. 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) {
  454. if (matcher_matched[mi]) continue;
  455. 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. if (match_flags() & UnorderedMatcherRequire::Subset) {
  464. const char* sep =
  465. "where the following elements don't match any matchers:\n";
  466. const char* outer_sep = "";
  467. if (!result) {
  468. outer_sep = "\nand ";
  469. }
  470. for (size_t ei = 0; ei < element_matched.size(); ++ei) {
  471. if (element_matched[ei]) continue;
  472. result = false;
  473. if (listener->IsInterested()) {
  474. *listener << outer_sep << sep << "element #" << ei << ": "
  475. << element_printouts[ei];
  476. sep = ",\n";
  477. outer_sep = "";
  478. }
  479. }
  480. }
  481. return result;
  482. }
  483. bool UnorderedElementsAreMatcherImplBase::FindPairing(
  484. const MatchMatrix& matrix, MatchResultListener* listener) const {
  485. ElementMatcherPairs matches = FindMaxBipartiteMatching(matrix);
  486. size_t max_flow = matches.size();
  487. if ((match_flags() & UnorderedMatcherRequire::Superset) &&
  488. max_flow < matrix.RhsSize()) {
  489. if (listener->IsInterested()) {
  490. *listener << "where no permutation of the elements can satisfy all "
  491. "matchers, and the closest match is "
  492. << max_flow << " of " << matrix.RhsSize()
  493. << " matchers with the pairings:\n";
  494. LogElementMatcherPairVec(matches, listener->stream());
  495. }
  496. return false;
  497. }
  498. if ((match_flags() & UnorderedMatcherRequire::Subset) &&
  499. max_flow < matrix.LhsSize()) {
  500. if (listener->IsInterested()) {
  501. *listener
  502. << "where not all elements can be matched, and the closest match is "
  503. << max_flow << " of " << matrix.RhsSize()
  504. << " matchers with the pairings:\n";
  505. LogElementMatcherPairVec(matches, listener->stream());
  506. }
  507. return false;
  508. }
  509. if (matches.size() > 1) {
  510. if (listener->IsInterested()) {
  511. const char* sep = "where:\n";
  512. for (size_t mi = 0; mi < matches.size(); ++mi) {
  513. *listener << sep << " - element #" << matches[mi].first
  514. << " is matched by matcher #" << matches[mi].second;
  515. sep = ",\n";
  516. }
  517. }
  518. }
  519. return true;
  520. }
  521. } // namespace internal
  522. } // namespace testing