Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
2bd1750b
Commit
2bd1750b
authored
Feb 27, 2018
by
Gennadiy Civil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gmock merging -2
parent
7d15497f
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
56 deletions
+118
-56
gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+0
-0
gmock-matchers.cc
googlemock/src/gmock-matchers.cc
+96
-54
gmock_link_test.h
googlemock/test/gmock_link_test.h
+22
-2
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
2bd1750b
This diff is collapsed.
Click to expand it.
googlemock/src/gmock-matchers.cc
View file @
2bd1750b
...
@@ -38,6 +38,7 @@
...
@@ -38,6 +38,7 @@
#include "gmock/gmock-generated-matchers.h"
#include "gmock/gmock-generated-matchers.h"
#include <string.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <sstream>
#include <string>
#include <string>
...
@@ -181,8 +182,7 @@ class MaxBipartiteMatchState {
...
@@ -181,8 +182,7 @@ class MaxBipartiteMatchState {
explicit
MaxBipartiteMatchState
(
const
MatchMatrix
&
graph
)
explicit
MaxBipartiteMatchState
(
const
MatchMatrix
&
graph
)
:
graph_
(
&
graph
),
:
graph_
(
&
graph
),
left_
(
graph_
->
LhsSize
(),
kUnused
),
left_
(
graph_
->
LhsSize
(),
kUnused
),
right_
(
graph_
->
RhsSize
(),
kUnused
)
{
right_
(
graph_
->
RhsSize
(),
kUnused
)
{}
}
// Returns the edges of a maximal match, each in the form {left, right}.
// Returns the edges of a maximal match, each in the form {left, right}.
ElementMatcherPairs
Compute
()
{
ElementMatcherPairs
Compute
()
{
...
@@ -239,10 +239,8 @@ class MaxBipartiteMatchState {
...
@@ -239,10 +239,8 @@ class MaxBipartiteMatchState {
//
//
bool
TryAugment
(
size_t
ilhs
,
::
std
::
vector
<
char
>*
seen
)
{
bool
TryAugment
(
size_t
ilhs
,
::
std
::
vector
<
char
>*
seen
)
{
for
(
size_t
irhs
=
0
;
irhs
<
graph_
->
RhsSize
();
++
irhs
)
{
for
(
size_t
irhs
=
0
;
irhs
<
graph_
->
RhsSize
();
++
irhs
)
{
if
((
*
seen
)[
irhs
])
if
((
*
seen
)[
irhs
])
continue
;
continue
;
if
(
!
graph_
->
HasEdge
(
ilhs
,
irhs
))
continue
;
if
(
!
graph_
->
HasEdge
(
ilhs
,
irhs
))
continue
;
// There's an available edge from ilhs to irhs.
// There's an available edge from ilhs to irhs.
(
*
seen
)[
irhs
]
=
1
;
(
*
seen
)[
irhs
]
=
1
;
// Next a search is performed to determine whether
// Next a search is performed to determine whether
...
@@ -285,8 +283,7 @@ class MaxBipartiteMatchState {
...
@@ -285,8 +283,7 @@ class MaxBipartiteMatchState {
const
size_t
MaxBipartiteMatchState
::
kUnused
;
const
size_t
MaxBipartiteMatchState
::
kUnused
;
GTEST_API_
ElementMatcherPairs
GTEST_API_
ElementMatcherPairs
FindMaxBipartiteMatching
(
const
MatchMatrix
&
g
)
{
FindMaxBipartiteMatching
(
const
MatchMatrix
&
g
)
{
return
MaxBipartiteMatchState
(
g
).
Compute
();
return
MaxBipartiteMatchState
(
g
).
Compute
();
}
}
...
@@ -295,7 +292,7 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
...
@@ -295,7 +292,7 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
typedef
ElementMatcherPairs
::
const_iterator
Iter
;
typedef
ElementMatcherPairs
::
const_iterator
Iter
;
::
std
::
ostream
&
os
=
*
stream
;
::
std
::
ostream
&
os
=
*
stream
;
os
<<
"{"
;
os
<<
"{"
;
const
char
*
sep
=
""
;
const
char
*
sep
=
""
;
for
(
Iter
it
=
pairs
.
begin
();
it
!=
pairs
.
end
();
++
it
)
{
for
(
Iter
it
=
pairs
.
begin
();
it
!=
pairs
.
end
();
++
it
)
{
os
<<
sep
<<
"
\n
("
os
<<
sep
<<
"
\n
("
<<
"element #"
<<
it
->
first
<<
", "
<<
"element #"
<<
it
->
first
<<
", "
...
@@ -305,38 +302,6 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
...
@@ -305,38 +302,6 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
os
<<
"
\n
}"
;
os
<<
"
\n
}"
;
}
}
// Tries to find a pairing, and explains the result.
GTEST_API_
bool
FindPairing
(
const
MatchMatrix
&
matrix
,
MatchResultListener
*
listener
)
{
ElementMatcherPairs
matches
=
FindMaxBipartiteMatching
(
matrix
);
size_t
max_flow
=
matches
.
size
();
bool
result
=
(
max_flow
==
matrix
.
RhsSize
());
if
(
!
result
)
{
if
(
listener
->
IsInterested
())
{
*
listener
<<
"where no permutation of the elements can "
"satisfy all matchers, and the closest match is "
<<
max_flow
<<
" of "
<<
matrix
.
RhsSize
()
<<
" matchers with the pairings:
\n
"
;
LogElementMatcherPairVec
(
matches
,
listener
->
stream
());
}
return
false
;
}
if
(
matches
.
size
()
>
1
)
{
if
(
listener
->
IsInterested
())
{
const
char
*
sep
=
"where:
\n
"
;
for
(
size_t
mi
=
0
;
mi
<
matches
.
size
();
++
mi
)
{
*
listener
<<
sep
<<
" - element #"
<<
matches
[
mi
].
first
<<
" is matched by matcher #"
<<
matches
[
mi
].
second
;
sep
=
",
\n
"
;
}
}
}
return
true
;
}
bool
MatchMatrix
::
NextGraph
()
{
bool
MatchMatrix
::
NextGraph
()
{
for
(
size_t
ilhs
=
0
;
ilhs
<
LhsSize
();
++
ilhs
)
{
for
(
size_t
ilhs
=
0
;
ilhs
<
LhsSize
();
++
ilhs
)
{
for
(
size_t
irhs
=
0
;
irhs
<
RhsSize
();
++
irhs
)
{
for
(
size_t
irhs
=
0
;
irhs
<
RhsSize
();
++
irhs
)
{
...
@@ -362,7 +327,7 @@ void MatchMatrix::Randomize() {
...
@@ -362,7 +327,7 @@ void MatchMatrix::Randomize() {
std
::
string
MatchMatrix
::
DebugString
()
const
{
std
::
string
MatchMatrix
::
DebugString
()
const
{
::
std
::
stringstream
ss
;
::
std
::
stringstream
ss
;
const
char
*
sep
=
""
;
const
char
*
sep
=
""
;
for
(
size_t
i
=
0
;
i
<
LhsSize
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
LhsSize
();
++
i
)
{
ss
<<
sep
;
ss
<<
sep
;
for
(
size_t
j
=
0
;
j
<
RhsSize
();
++
j
)
{
for
(
size_t
j
=
0
;
j
<
RhsSize
();
++
j
)
{
...
@@ -375,6 +340,8 @@ std::string MatchMatrix::DebugString() const {
...
@@ -375,6 +340,8 @@ std::string MatchMatrix::DebugString() const {
void
UnorderedElementsAreMatcherImplBase
::
DescribeToImpl
(
void
UnorderedElementsAreMatcherImplBase
::
DescribeToImpl
(
::
std
::
ostream
*
os
)
const
{
::
std
::
ostream
*
os
)
const
{
switch
(
match_flags
())
{
case
UnorderedMatcherRequire
:
:
ExactMatch
:
if
(
matcher_describers_
.
empty
())
{
if
(
matcher_describers_
.
empty
())
{
*
os
<<
"is empty"
;
*
os
<<
"is empty"
;
return
;
return
;
...
@@ -386,33 +353,70 @@ void UnorderedElementsAreMatcherImplBase::DescribeToImpl(
...
@@ -386,33 +353,70 @@ void UnorderedElementsAreMatcherImplBase::DescribeToImpl(
}
}
*
os
<<
"has "
<<
Elements
(
matcher_describers_
.
size
())
*
os
<<
"has "
<<
Elements
(
matcher_describers_
.
size
())
<<
" and there exists some permutation of elements such that:
\n
"
;
<<
" and there exists some permutation of elements such that:
\n
"
;
break
;
case
UnorderedMatcherRequire
:
:
Superset
:
*
os
<<
"a surjection from elements to requirements exists such that:
\n
"
;
break
;
case
UnorderedMatcherRequire
:
:
Subset
:
*
os
<<
"an injection from elements to requirements exists such that:
\n
"
;
break
;
}
const
char
*
sep
=
""
;
const
char
*
sep
=
""
;
for
(
size_t
i
=
0
;
i
!=
matcher_describers_
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
matcher_describers_
.
size
();
++
i
)
{
*
os
<<
sep
<<
" - element #"
<<
i
<<
" "
;
*
os
<<
sep
;
if
(
match_flags
()
==
UnorderedMatcherRequire
::
ExactMatch
)
{
*
os
<<
" - element #"
<<
i
<<
" "
;
}
else
{
*
os
<<
" - an element "
;
}
matcher_describers_
[
i
]
->
DescribeTo
(
os
);
matcher_describers_
[
i
]
->
DescribeTo
(
os
);
if
(
match_flags
()
==
UnorderedMatcherRequire
::
ExactMatch
)
{
sep
=
", and
\n
"
;
sep
=
", and
\n
"
;
}
else
{
sep
=
"
\n
"
;
}
}
}
}
}
void
UnorderedElementsAreMatcherImplBase
::
DescribeNegationToImpl
(
void
UnorderedElementsAreMatcherImplBase
::
DescribeNegationToImpl
(
::
std
::
ostream
*
os
)
const
{
::
std
::
ostream
*
os
)
const
{
switch
(
match_flags
())
{
case
UnorderedMatcherRequire
:
:
ExactMatch
:
if
(
matcher_describers_
.
empty
())
{
if
(
matcher_describers_
.
empty
())
{
*
os
<<
"isn't empty"
;
*
os
<<
"isn't empty"
;
return
;
return
;
}
}
if
(
matcher_describers_
.
size
()
==
1
)
{
if
(
matcher_describers_
.
size
()
==
1
)
{
*
os
<<
"doesn't have
"
<<
Elements
(
1
)
*
os
<<
"doesn't have "
<<
Elements
(
1
)
<<
", or has
"
<<
Elements
(
1
)
<<
", or has "
<<
Elements
(
1
)
<<
" that "
;
<<
" that "
;
matcher_describers_
[
0
]
->
DescribeNegationTo
(
os
);
matcher_describers_
[
0
]
->
DescribeNegationTo
(
os
);
return
;
return
;
}
}
*
os
<<
"doesn't have "
<<
Elements
(
matcher_describers_
.
size
())
*
os
<<
"doesn't have "
<<
Elements
(
matcher_describers_
.
size
())
<<
", or there exists no permutation of elements such that:
\n
"
;
<<
", or there exists no permutation of elements such that:
\n
"
;
break
;
case
UnorderedMatcherRequire
:
:
Superset
:
*
os
<<
"no surjection from elements to requirements exists such that:
\n
"
;
break
;
case
UnorderedMatcherRequire
:
:
Subset
:
*
os
<<
"no injection from elements to requirements exists such that:
\n
"
;
break
;
}
const
char
*
sep
=
""
;
const
char
*
sep
=
""
;
for
(
size_t
i
=
0
;
i
!=
matcher_describers_
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
!=
matcher_describers_
.
size
();
++
i
)
{
*
os
<<
sep
<<
" - element #"
<<
i
<<
" "
;
*
os
<<
sep
;
if
(
match_flags
()
==
UnorderedMatcherRequire
::
ExactMatch
)
{
*
os
<<
" - element #"
<<
i
<<
" "
;
}
else
{
*
os
<<
" - an element "
;
}
matcher_describers_
[
i
]
->
DescribeTo
(
os
);
matcher_describers_
[
i
]
->
DescribeTo
(
os
);
if
(
match_flags
()
==
UnorderedMatcherRequire
::
ExactMatch
)
{
sep
=
", and
\n
"
;
sep
=
", and
\n
"
;
}
else
{
sep
=
"
\n
"
;
}
}
}
}
}
...
@@ -421,8 +425,7 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
...
@@ -421,8 +425,7 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
// and better error reporting.
// and better error reporting.
// Returns false, writing an explanation to 'listener', if and only
// Returns false, writing an explanation to 'listener', if and only
// if the success criteria are not met.
// if the success criteria are not met.
bool
UnorderedElementsAreMatcherImplBase
::
bool
UnorderedElementsAreMatcherImplBase
::
VerifyMatchMatrix
(
VerifyAllElementsAndMatchersAreMatched
(
const
::
std
::
vector
<
std
::
string
>&
element_printouts
,
const
::
std
::
vector
<
std
::
string
>&
element_printouts
,
const
MatchMatrix
&
matrix
,
MatchResultListener
*
listener
)
const
{
const
MatchMatrix
&
matrix
,
MatchResultListener
*
listener
)
const
{
bool
result
=
true
;
bool
result
=
true
;
...
@@ -437,12 +440,11 @@ bool UnorderedElementsAreMatcherImplBase::
...
@@ -437,12 +440,11 @@ bool UnorderedElementsAreMatcherImplBase::
}
}
}
}
{
if
(
match_flags
()
&
UnorderedMatcherRequire
::
Superset
)
{
const
char
*
sep
=
const
char
*
sep
=
"where the following matchers don't match any elements:
\n
"
;
"where the following matchers don't match any elements:
\n
"
;
for
(
size_t
mi
=
0
;
mi
<
matcher_matched
.
size
();
++
mi
)
{
for
(
size_t
mi
=
0
;
mi
<
matcher_matched
.
size
();
++
mi
)
{
if
(
matcher_matched
[
mi
])
if
(
matcher_matched
[
mi
])
continue
;
continue
;
result
=
false
;
result
=
false
;
if
(
listener
->
IsInterested
())
{
if
(
listener
->
IsInterested
())
{
*
listener
<<
sep
<<
"matcher #"
<<
mi
<<
": "
;
*
listener
<<
sep
<<
"matcher #"
<<
mi
<<
": "
;
...
@@ -452,7 +454,7 @@ bool UnorderedElementsAreMatcherImplBase::
...
@@ -452,7 +454,7 @@ bool UnorderedElementsAreMatcherImplBase::
}
}
}
}
{
if
(
match_flags
()
&
UnorderedMatcherRequire
::
Subset
)
{
const
char
*
sep
=
const
char
*
sep
=
"where the following elements don't match any matchers:
\n
"
;
"where the following elements don't match any matchers:
\n
"
;
const
char
*
outer_sep
=
""
;
const
char
*
outer_sep
=
""
;
...
@@ -460,8 +462,7 @@ bool UnorderedElementsAreMatcherImplBase::
...
@@ -460,8 +462,7 @@ bool UnorderedElementsAreMatcherImplBase::
outer_sep
=
"
\n
and "
;
outer_sep
=
"
\n
and "
;
}
}
for
(
size_t
ei
=
0
;
ei
<
element_matched
.
size
();
++
ei
)
{
for
(
size_t
ei
=
0
;
ei
<
element_matched
.
size
();
++
ei
)
{
if
(
element_matched
[
ei
])
if
(
element_matched
[
ei
])
continue
;
continue
;
result
=
false
;
result
=
false
;
if
(
listener
->
IsInterested
())
{
if
(
listener
->
IsInterested
())
{
*
listener
<<
outer_sep
<<
sep
<<
"element #"
<<
ei
<<
": "
*
listener
<<
outer_sep
<<
sep
<<
"element #"
<<
ei
<<
": "
...
@@ -474,5 +475,46 @@ bool UnorderedElementsAreMatcherImplBase::
...
@@ -474,5 +475,46 @@ bool UnorderedElementsAreMatcherImplBase::
return
result
;
return
result
;
}
}
bool
UnorderedElementsAreMatcherImplBase
::
FindPairing
(
const
MatchMatrix
&
matrix
,
MatchResultListener
*
listener
)
const
{
ElementMatcherPairs
matches
=
FindMaxBipartiteMatching
(
matrix
);
size_t
max_flow
=
matches
.
size
();
if
((
match_flags
()
&
UnorderedMatcherRequire
::
Superset
)
&&
max_flow
<
matrix
.
RhsSize
())
{
if
(
listener
->
IsInterested
())
{
*
listener
<<
"where no permutation of the elements can satisfy all "
"matchers, and the closest match is "
<<
max_flow
<<
" of "
<<
matrix
.
RhsSize
()
<<
" matchers with the pairings:
\n
"
;
LogElementMatcherPairVec
(
matches
,
listener
->
stream
());
}
return
false
;
}
if
((
match_flags
()
&
UnorderedMatcherRequire
::
Subset
)
&&
max_flow
<
matrix
.
LhsSize
())
{
if
(
listener
->
IsInterested
())
{
*
listener
<<
"where not all elements can be matched, and the closest match is "
<<
max_flow
<<
" of "
<<
matrix
.
RhsSize
()
<<
" matchers with the pairings:
\n
"
;
LogElementMatcherPairVec
(
matches
,
listener
->
stream
());
}
return
false
;
}
if
(
matches
.
size
()
>
1
)
{
if
(
listener
->
IsInterested
())
{
const
char
*
sep
=
"where:
\n
"
;
for
(
size_t
mi
=
0
;
mi
<
matches
.
size
();
++
mi
)
{
*
listener
<<
sep
<<
" - element #"
<<
matches
[
mi
].
first
<<
" is matched by matcher #"
<<
matches
[
mi
].
second
;
sep
=
",
\n
"
;
}
}
}
return
true
;
}
}
// namespace internal
}
// namespace internal
}
// namespace testing
}
// namespace testing
googlemock/test/gmock_link_test.h
View file @
2bd1750b
...
@@ -120,13 +120,15 @@
...
@@ -120,13 +120,15 @@
# include <errno.h>
# include <errno.h>
#endif
#endif
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
#include "gtest/gtest.h"
#include "gtest/internal/gtest-port.h"
using
testing
::
_
;
using
testing
::
_
;
using
testing
::
A
;
using
testing
::
A
;
using
testing
::
Action
;
using
testing
::
AllOf
;
using
testing
::
AllOf
;
using
testing
::
AnyOf
;
using
testing
::
AnyOf
;
using
testing
::
Assign
;
using
testing
::
Assign
;
...
@@ -148,6 +150,8 @@ using testing::Invoke;
...
@@ -148,6 +150,8 @@ using testing::Invoke;
using
testing
::
InvokeArgument
;
using
testing
::
InvokeArgument
;
using
testing
::
InvokeWithoutArgs
;
using
testing
::
InvokeWithoutArgs
;
using
testing
::
IsNull
;
using
testing
::
IsNull
;
using
testing
::
IsSubsetOf
;
using
testing
::
IsSupersetOf
;
using
testing
::
Le
;
using
testing
::
Le
;
using
testing
::
Lt
;
using
testing
::
Lt
;
using
testing
::
Matcher
;
using
testing
::
Matcher
;
...
@@ -592,6 +596,22 @@ TEST(LinkTest, TestMatcherElementsAreArray) {
...
@@ -592,6 +596,22 @@ TEST(LinkTest, TestMatcherElementsAreArray) {
ON_CALL
(
mock
,
VoidFromVector
(
ElementsAreArray
(
arr
))).
WillByDefault
(
Return
());
ON_CALL
(
mock
,
VoidFromVector
(
ElementsAreArray
(
arr
))).
WillByDefault
(
Return
());
}
}
// Tests the linkage of the IsSubsetOf matcher.
TEST
(
LinkTest
,
TestMatcherIsSubsetOf
)
{
Mock
mock
;
char
arr
[]
=
{
'a'
,
'b'
};
ON_CALL
(
mock
,
VoidFromVector
(
IsSubsetOf
(
arr
))).
WillByDefault
(
Return
());
}
// Tests the linkage of the IsSupersetOf matcher.
TEST
(
LinkTest
,
TestMatcherIsSupersetOf
)
{
Mock
mock
;
char
arr
[]
=
{
'a'
,
'b'
};
ON_CALL
(
mock
,
VoidFromVector
(
IsSupersetOf
(
arr
))).
WillByDefault
(
Return
());
}
// Tests the linkage of the ContainerEq matcher.
// Tests the linkage of the ContainerEq matcher.
TEST
(
LinkTest
,
TestMatcherContainerEq
)
{
TEST
(
LinkTest
,
TestMatcherContainerEq
)
{
Mock
mock
;
Mock
mock
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment