Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
9e712372
Unverified
Commit
9e712372
authored
Mar 18, 2022
by
Brad Messer
Committed by
GitHub
Mar 18, 2022
Browse files
Merge branch 'main' into promote-inclusive-behavior
parents
794da715
b007c54f
Changes
135
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1038 additions
and
1300 deletions
+1038
-1300
googlemock/test/gmock-internal-utils_test.cc
googlemock/test/gmock-internal-utils_test.cc
+71
-72
googlemock/test/gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+374
-434
googlemock/test/gmock-more-actions_test.cc
googlemock/test/gmock-more-actions_test.cc
+15
-18
googlemock/test/gmock-nice-strict_test.cc
googlemock/test/gmock-nice-strict_test.cc
+10
-10
googlemock/test/gmock-port_test.cc
googlemock/test/gmock-port_test.cc
+1
-1
googlemock/test/gmock-pp-string_test.cc
googlemock/test/gmock-pp-string_test.cc
+1
-2
googlemock/test/gmock-spec-builders_test.cc
googlemock/test/gmock-spec-builders_test.cc
+371
-538
googlemock/test/gmock_ex_test.cc
googlemock/test/gmock_ex_test.cc
+0
-2
googlemock/test/gmock_leak_test_.cc
googlemock/test/gmock_leak_test_.cc
+0
-1
googlemock/test/gmock_link2_test.cc
googlemock/test/gmock_link2_test.cc
+0
-1
googlemock/test/gmock_link_test.cc
googlemock/test/gmock_link_test.cc
+0
-1
googlemock/test/gmock_link_test.h
googlemock/test/gmock_link_test.h
+16
-18
googlemock/test/gmock_output_test_.cc
googlemock/test/gmock_output_test_.cc
+22
-41
googlemock/test/gmock_stress_test.cc
googlemock/test/gmock_stress_test.cc
+20
-33
googlemock/test/gmock_test.cc
googlemock/test/gmock_test.cc
+1
-1
googletest/include/gtest/gtest-death-test.h
googletest/include/gtest/gtest-death-test.h
+38
-39
googletest/include/gtest/gtest-matchers.h
googletest/include/gtest/gtest-matchers.h
+36
-19
googletest/include/gtest/gtest-message.h
googletest/include/gtest/gtest-message.h
+10
-12
googletest/include/gtest/gtest-param-test.h
googletest/include/gtest/gtest-param-test.h
+34
-37
googletest/include/gtest/gtest-printers.h
googletest/include/gtest/gtest-printers.h
+18
-20
No files found.
googlemock/test/gmock-internal-utils_test.cc
View file @
9e712372
...
...
@@ -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 tests the internal utilities.
...
...
@@ -58,7 +57,7 @@
#undef GTEST_IMPLEMENTATION_
#if GTEST_OS_CYGWIN
#
include <sys/types.h> // For ssize_t. NOLINT
#include <sys/types.h> // For ssize_t. NOLINT
#endif
namespace
proto2
{
...
...
@@ -155,19 +154,19 @@ TEST(KindOfTest, Bool) {
}
TEST
(
KindOfTest
,
Integer
)
{
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
char
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
signed
char
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
unsigned
char
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
short
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
unsigned
short
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
int
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
unsigned
int
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
long
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
unsigned
long
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
long
long
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
char
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
signed
char
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
unsigned
char
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
short
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
unsigned
short
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
int
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
unsigned
int
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
long
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
unsigned
long
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
long
long
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
unsigned
long
long
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
wchar_t
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
size_t
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
wchar_t
));
// NOLINT
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
size_t
));
// NOLINT
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
// ssize_t is not defined on Windows and possibly some other OSes.
EXPECT_EQ
(
kInteger
,
GMOCK_KIND_OF_
(
ssize_t
));
// NOLINT
...
...
@@ -175,15 +174,15 @@ TEST(KindOfTest, Integer) {
}
TEST
(
KindOfTest
,
FloatingPoint
)
{
EXPECT_EQ
(
kFloatingPoint
,
GMOCK_KIND_OF_
(
float
));
// NOLINT
EXPECT_EQ
(
kFloatingPoint
,
GMOCK_KIND_OF_
(
double
));
// NOLINT
EXPECT_EQ
(
kFloatingPoint
,
GMOCK_KIND_OF_
(
float
));
// NOLINT
EXPECT_EQ
(
kFloatingPoint
,
GMOCK_KIND_OF_
(
double
));
// NOLINT
EXPECT_EQ
(
kFloatingPoint
,
GMOCK_KIND_OF_
(
long
double
));
// NOLINT
}
TEST
(
KindOfTest
,
Other
)
{
EXPECT_EQ
(
kOther
,
GMOCK_KIND_OF_
(
void
*
));
// NOLINT
EXPECT_EQ
(
kOther
,
GMOCK_KIND_OF_
(
void
*
));
// NOLINT
EXPECT_EQ
(
kOther
,
GMOCK_KIND_OF_
(
char
**
));
// NOLINT
EXPECT_EQ
(
kOther
,
GMOCK_KIND_OF_
(
Base
));
// NOLINT
EXPECT_EQ
(
kOther
,
GMOCK_KIND_OF_
(
Base
));
// NOLINT
}
// Tests LosslessArithmeticConvertible<T, U>.
...
...
@@ -214,26 +213,26 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
EXPECT_TRUE
((
LosslessArithmeticConvertible
<
unsigned
char
,
int
>::
value
));
// Unsigned => larger unsigned is fine.
EXPECT_TRUE
((
LosslessArithmeticConvertible
<
unsigned
short
,
uint64_t
>::
value
));
// NOLINT
EXPECT_TRUE
((
LosslessArithmeticConvertible
<
unsigned
short
,
uint64_t
>::
value
));
// NOLINT
// Signed => unsigned is not fine.
EXPECT_FALSE
(
(
LosslessArithmeticConvertible
<
short
,
uint64_t
>::
value
));
// NOLINT
EXPECT_FALSE
((
LosslessArithmeticConvertible
<
signed
char
,
unsigned
int
>::
value
));
// NOLINT
EXPECT_FALSE
(
(
LosslessArithmeticConvertible
<
short
,
uint64_t
>::
value
));
// NOLINT
EXPECT_FALSE
((
LosslessArithmeticConvertible
<
signed
char
,
unsigned
int
>::
value
));
// NOLINT
// Same size and same signedness: fine too.
EXPECT_TRUE
(
(
LosslessArithmeticConvertible
<
unsigned
char
,
unsigned
char
>::
value
));
EXPECT_TRUE
(
(
LosslessArithmeticConvertible
<
unsigned
char
,
unsigned
char
>::
value
));
EXPECT_TRUE
((
LosslessArithmeticConvertible
<
int
,
int
>::
value
));
EXPECT_TRUE
((
LosslessArithmeticConvertible
<
wchar_t
,
wchar_t
>::
value
));
EXPECT_TRUE
((
LosslessArithmeticConvertible
<
unsigned
long
,
unsigned
long
>::
value
));
// NOLINT
EXPECT_TRUE
((
LosslessArithmeticConvertible
<
unsigned
long
,
unsigned
long
>::
value
));
// NOLINT
// Same size, different signedness: not fine.
EXPECT_FALSE
(
(
LosslessArithmeticConvertible
<
unsigned
char
,
signed
char
>::
value
));
EXPECT_FALSE
(
(
LosslessArithmeticConvertible
<
unsigned
char
,
signed
char
>::
value
));
EXPECT_FALSE
((
LosslessArithmeticConvertible
<
int
,
unsigned
int
>::
value
));
EXPECT_FALSE
((
LosslessArithmeticConvertible
<
uint64_t
,
int64_t
>::
value
));
...
...
@@ -248,8 +247,8 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
// the format of the latter is implementation-defined.
EXPECT_FALSE
((
LosslessArithmeticConvertible
<
char
,
float
>::
value
));
EXPECT_FALSE
((
LosslessArithmeticConvertible
<
int
,
double
>::
value
));
EXPECT_FALSE
(
(
LosslessArithmeticConvertible
<
short
,
long
double
>::
value
));
// NOLINT
EXPECT_FALSE
(
(
LosslessArithmeticConvertible
<
short
,
long
double
>::
value
));
// NOLINT
}
TEST
(
LosslessArithmeticConvertibleTest
,
FloatingPointToBool
)
{
...
...
@@ -277,7 +276,7 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
EXPECT_FALSE
((
LosslessArithmeticConvertible
<
double
,
float
>::
value
));
GTEST_INTENTIONAL_CONST_COND_PUSH_
()
if
(
sizeof
(
double
)
==
sizeof
(
long
double
))
{
// NOLINT
GTEST_INTENTIONAL_CONST_COND_POP_
()
GTEST_INTENTIONAL_CONST_COND_POP_
()
// In some implementations (e.g. MSVC), double and long double
// have the same size.
EXPECT_TRUE
((
LosslessArithmeticConvertible
<
long
double
,
double
>::
value
));
...
...
@@ -296,7 +295,7 @@ TEST(TupleMatchesTest, WorksForSize0) {
}
TEST
(
TupleMatchesTest
,
WorksForSize1
)
{
std
::
tuple
<
Matcher
<
int
>
>
matchers
(
Eq
(
1
));
std
::
tuple
<
Matcher
<
int
>>
matchers
(
Eq
(
1
));
std
::
tuple
<
int
>
values1
(
1
),
values2
(
2
);
EXPECT_TRUE
(
TupleMatches
(
matchers
,
values1
));
...
...
@@ -304,7 +303,7 @@ TEST(TupleMatchesTest, WorksForSize1) {
}
TEST
(
TupleMatchesTest
,
WorksForSize2
)
{
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
>
matchers
(
Eq
(
1
),
Eq
(
'a'
));
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>>
matchers
(
Eq
(
1
),
Eq
(
'a'
));
std
::
tuple
<
int
,
char
>
values1
(
1
,
'a'
),
values2
(
1
,
'b'
),
values3
(
2
,
'a'
),
values4
(
2
,
'b'
);
...
...
@@ -317,7 +316,7 @@ TEST(TupleMatchesTest, WorksForSize2) {
TEST
(
TupleMatchesTest
,
WorksForSize5
)
{
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
long
>
,
// NOLINT
Matcher
<
std
::
string
>
>
Matcher
<
std
::
string
>>
matchers
(
Eq
(
1
),
Eq
(
'a'
),
Eq
(
true
),
Eq
(
2L
),
Eq
(
"hi"
));
std
::
tuple
<
int
,
char
,
bool
,
long
,
std
::
string
>
// NOLINT
values1
(
1
,
'a'
,
true
,
2L
,
"hi"
),
values2
(
1
,
'a'
,
true
,
2L
,
"hello"
),
...
...
@@ -336,13 +335,10 @@ TEST(AssertTest, SucceedsOnTrue) {
// Tests that Assert(false, ...) generates a fatal failure.
TEST
(
AssertTest
,
FailsFatallyOnFalse
)
{
EXPECT_DEATH_IF_SUPPORTED
({
Assert
(
false
,
__FILE__
,
__LINE__
,
"This should fail."
);
},
""
);
EXPECT_DEATH_IF_SUPPORTED
(
{
Assert
(
false
,
__FILE__
,
__LINE__
,
"This should fail."
);
},
""
);
EXPECT_DEATH_IF_SUPPORTED
({
Assert
(
false
,
__FILE__
,
__LINE__
);
},
""
);
EXPECT_DEATH_IF_SUPPORTED
({
Assert
(
false
,
__FILE__
,
__LINE__
);
},
""
);
}
// Tests that Expect(true, ...) succeeds.
...
...
@@ -353,13 +349,17 @@ TEST(ExpectTest, SucceedsOnTrue) {
// Tests that Expect(false, ...) generates a non-fatal failure.
TEST
(
ExpectTest
,
FailsNonfatallyOnFalse
)
{
EXPECT_NONFATAL_FAILURE
({
// NOLINT
Expect
(
false
,
__FILE__
,
__LINE__
,
"This should fail."
);
},
"This should fail"
);
EXPECT_NONFATAL_FAILURE
(
{
// NOLINT
Expect
(
false
,
__FILE__
,
__LINE__
,
"This should fail."
);
},
"This should fail"
);
EXPECT_NONFATAL_FAILURE
({
// NOLINT
Expect
(
false
,
__FILE__
,
__LINE__
);
},
"Expectation failed"
);
EXPECT_NONFATAL_FAILURE
(
{
// NOLINT
Expect
(
false
,
__FILE__
,
__LINE__
);
},
"Expectation failed"
);
}
// Tests LogIsVisible().
...
...
@@ -404,11 +404,11 @@ void TestLogWithSeverity(const std::string& verbosity, LogSeverity severity,
CaptureStdout
();
Log
(
severity
,
"Test log.
\n
"
,
0
);
if
(
should_print
)
{
EXPECT_THAT
(
GetCapturedStdout
().
c_str
(),
ContainsRegex
(
severity
==
kWarning
?
"^
\n
GMOCK WARNING:
\n
Test log
\\
.
\n
Stack trace:
\n
"
:
"^
\n
Test log
\\
.
\n
Stack trace:
\n
"
));
EXPECT_THAT
(
GetCapturedStdout
().
c_str
(),
ContainsRegex
(
severity
==
kWarning
?
"^
\n
GMOCK WARNING:
\n
Test log
\\
.
\n
Stack trace:
\n
"
:
"^
\n
Test log
\\
.
\n
Stack trace:
\n
"
));
}
else
{
EXPECT_STREQ
(
""
,
GetCapturedStdout
().
c_str
());
}
...
...
@@ -455,13 +455,13 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
EXPECT_THAT
(
log
,
HasSubstr
(
expected_message
));
int
skip_count
=
atoi
(
log
.
substr
(
expected_message
.
size
()).
c_str
());
#
if defined(NDEBUG)
#if defined(NDEBUG)
// In opt mode, no stack frame should be skipped.
const
int
expected_skip_count
=
0
;
#
else
#else
// In dbg mode, the stack frames should be skipped.
const
int
expected_skip_count
=
100
;
#
endif
#endif
// Note that each inner implementation layer will +1 the number to remove
// itself from the trace. This means that the value is a little higher than
...
...
@@ -503,7 +503,7 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
// Verifies that Log() behaves correctly for the given verbosity level
// and log severity.
std
::
string
GrabOutput
(
void
(
*
logger
)(),
const
char
*
verbosity
)
{
std
::
string
GrabOutput
(
void
(
*
logger
)(),
const
char
*
verbosity
)
{
const
std
::
string
saved_flag
=
GMOCK_FLAG_GET
(
verbose
);
GMOCK_FLAG_SET
(
verbose
,
verbosity
);
CaptureStdout
();
...
...
@@ -538,7 +538,7 @@ TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
// Verifies that EXPECT_CALL doesn't log
// if the --gmock_verbose flag is set to "error".
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
EXPECT_STREQ
(
""
,
GrabOutput
(
ExpectCallLogger
,
kErrorVerbosity
).
c_str
());
}
...
...
@@ -582,9 +582,9 @@ TEST(OnCallTest, LogsAnythingArgument) {
TEST
(
StlContainerViewTest
,
WorksForStlContainer
)
{
StaticAssertTypeEq
<
std
::
vector
<
int
>
,
StlContainerView
<
std
::
vector
<
int
>
>::
type
>
();
StlContainerView
<
std
::
vector
<
int
>>::
type
>
();
StaticAssertTypeEq
<
const
std
::
vector
<
double
>&
,
StlContainerView
<
std
::
vector
<
double
>
>::
const_reference
>
();
StlContainerView
<
std
::
vector
<
double
>>::
const_reference
>
();
typedef
std
::
vector
<
char
>
Chars
;
Chars
v1
;
...
...
@@ -597,17 +597,16 @@ TEST(StlContainerViewTest, WorksForStlContainer) {
}
TEST
(
StlContainerViewTest
,
WorksForStaticNativeArray
)
{
StaticAssertTypeEq
<
NativeArray
<
int
>
,
StlContainerView
<
int
[
3
]
>::
type
>
();
StaticAssertTypeEq
<
NativeArray
<
int
>
,
StlContainerView
<
int
[
3
]
>::
type
>
();
StaticAssertTypeEq
<
NativeArray
<
double
>
,
StlContainerView
<
const
double
[
4
]
>::
type
>
();
StlContainerView
<
const
double
[
4
]
>::
type
>
();
StaticAssertTypeEq
<
NativeArray
<
char
[
3
]
>
,
StlContainerView
<
const
char
[
2
][
3
]
>::
type
>
();
StlContainerView
<
const
char
[
2
][
3
]
>::
type
>
();
StaticAssertTypeEq
<
const
NativeArray
<
int
>
,
StlContainerView
<
int
[
2
]
>::
const_reference
>
();
StlContainerView
<
int
[
2
]
>::
const_reference
>
();
int
a1
[
3
]
=
{
0
,
1
,
2
};
int
a1
[
3
]
=
{
0
,
1
,
2
};
NativeArray
<
int
>
a2
=
StlContainerView
<
int
[
3
]
>::
ConstReference
(
a1
);
EXPECT_EQ
(
3U
,
a2
.
size
());
EXPECT_EQ
(
a1
,
a2
.
begin
());
...
...
@@ -625,24 +624,24 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) {
TEST
(
StlContainerViewTest
,
WorksForDynamicNativeArray
)
{
StaticAssertTypeEq
<
NativeArray
<
int
>
,
StlContainerView
<
std
::
tuple
<
const
int
*
,
size_t
>
>::
type
>
();
StlContainerView
<
std
::
tuple
<
const
int
*
,
size_t
>>::
type
>
();
StaticAssertTypeEq
<
NativeArray
<
double
>
,
StlContainerView
<
std
::
tuple
<
std
::
shared_ptr
<
double
>
,
int
>
>::
type
>
();
StlContainerView
<
std
::
tuple
<
std
::
shared_ptr
<
double
>
,
int
>>::
type
>
();
StaticAssertTypeEq
<
const
NativeArray
<
int
>
,
StlContainerView
<
std
::
tuple
<
const
int
*
,
int
>
>::
const_reference
>
();
StlContainerView
<
std
::
tuple
<
const
int
*
,
int
>>::
const_reference
>
();
int
a1
[
3
]
=
{
0
,
1
,
2
};
int
a1
[
3
]
=
{
0
,
1
,
2
};
const
int
*
const
p1
=
a1
;
NativeArray
<
int
>
a2
=
StlContainerView
<
std
::
tuple
<
const
int
*
,
int
>
>::
ConstReference
(
StlContainerView
<
std
::
tuple
<
const
int
*
,
int
>>::
ConstReference
(
std
::
make_tuple
(
p1
,
3
));
EXPECT_EQ
(
3U
,
a2
.
size
());
EXPECT_EQ
(
a1
,
a2
.
begin
());
const
NativeArray
<
int
>
a3
=
StlContainerView
<
std
::
tuple
<
int
*
,
size_t
>
>::
Copy
(
const
NativeArray
<
int
>
a3
=
StlContainerView
<
std
::
tuple
<
int
*
,
size_t
>>::
Copy
(
std
::
make_tuple
(
static_cast
<
int
*>
(
a1
),
3
));
ASSERT_EQ
(
3U
,
a3
.
size
());
EXPECT_EQ
(
0
,
a3
.
begin
()[
0
]);
...
...
googlemock/test/gmock-matchers_test.cc
View file @
9e712372
This diff is collapsed.
Click to expand it.
googlemock/test/gmock-more-actions_test.cc
View file @
9e712372
...
...
@@ -145,7 +145,7 @@ class Foo {
std
::
string
Binary
(
const
std
::
string
&
str
,
char
c
)
const
{
return
str
+
c
;
}
int
Ternary
(
int
x
,
bool
y
,
char
z
)
{
return
value_
+
x
+
y
*
z
;
}
int
Ternary
(
int
x
,
bool
y
,
char
z
)
{
return
value_
+
x
+
y
*
z
;
}
int
SumOf4
(
int
a
,
int
b
,
int
c
,
int
d
)
const
{
return
a
+
b
+
c
+
d
+
value_
;
...
...
@@ -291,8 +291,7 @@ TEST(InvokeTest, FunctionWithUnusedParameters) {
std
::
make_tuple
(
10
,
2
,
5.6
,
std
::
string
(
"hi"
));
EXPECT_EQ
(
12
,
a1
.
Perform
(
dummy
));
Action
<
int
(
int
,
int
,
bool
,
int
*
)
>
a2
=
Invoke
(
SumOfFirst2
);
Action
<
int
(
int
,
int
,
bool
,
int
*
)
>
a2
=
Invoke
(
SumOfFirst2
);
EXPECT_EQ
(
23
,
a2
.
Perform
(
std
::
make_tuple
(
20
,
3
,
true
,
static_cast
<
int
*>
(
nullptr
))));
}
...
...
@@ -303,8 +302,7 @@ TEST(InvokeTest, MethodWithUnusedParameters) {
Action
<
int
(
std
::
string
,
bool
,
int
,
int
)
>
a1
=
Invoke
(
&
foo
,
&
Foo
::
SumOfLast2
);
EXPECT_EQ
(
12
,
a1
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"hi"
),
true
,
10
,
2
)));
Action
<
int
(
char
,
double
,
int
,
int
)
>
a2
=
Invoke
(
&
foo
,
&
Foo
::
SumOfLast2
);
Action
<
int
(
char
,
double
,
int
,
int
)
>
a2
=
Invoke
(
&
foo
,
&
Foo
::
SumOfLast2
);
EXPECT_EQ
(
23
,
a2
.
Perform
(
std
::
make_tuple
(
'a'
,
2.5
,
20
,
3
)));
}
...
...
@@ -362,7 +360,8 @@ TEST(InvokeMethodTest, MethodThatTakes4Arguments) {
// Tests using Invoke() with a 5-argument method.
TEST
(
InvokeMethodTest
,
MethodThatTakes5Arguments
)
{
Foo
foo
;
Action
<
int
(
int
,
int
,
int
,
int
,
int
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
SumOf5
);
// NOLINT
Action
<
int
(
int
,
int
,
int
,
int
,
int
)
>
a
=
Invoke
(
&
foo
,
&
Foo
::
SumOf5
);
// NOLINT
EXPECT_EQ
(
12345
,
a
.
Perform
(
std
::
make_tuple
(
10000
,
2000
,
300
,
40
,
5
)));
}
...
...
@@ -523,15 +522,12 @@ TEST(SetArgRefereeActionTest, WorksWithExtraArguments) {
// the bool provided to the constructor to true when destroyed.
class
DeletionTester
{
public:
explicit
DeletionTester
(
bool
*
is_deleted
)
:
is_deleted_
(
is_deleted
)
{
explicit
DeletionTester
(
bool
*
is_deleted
)
:
is_deleted_
(
is_deleted
)
{
// Make sure the bit is set to false.
*
is_deleted_
=
false
;
}
~
DeletionTester
()
{
*
is_deleted_
=
true
;
}
~
DeletionTester
()
{
*
is_deleted_
=
true
;
}
private:
bool
*
is_deleted_
;
...
...
@@ -540,7 +536,7 @@ class DeletionTester {
TEST
(
DeleteArgActionTest
,
OneArg
)
{
bool
is_deleted
=
false
;
DeletionTester
*
t
=
new
DeletionTester
(
&
is_deleted
);
const
Action
<
void
(
DeletionTester
*
)
>
a1
=
DeleteArg
<
0
>
();
// NOLINT
const
Action
<
void
(
DeletionTester
*
)
>
a1
=
DeleteArg
<
0
>
();
// NOLINT
EXPECT_FALSE
(
is_deleted
);
a1
.
Perform
(
std
::
make_tuple
(
t
));
EXPECT_TRUE
(
is_deleted
);
...
...
@@ -549,8 +545,9 @@ TEST(DeleteArgActionTest, OneArg) {
TEST
(
DeleteArgActionTest
,
TenArgs
)
{
bool
is_deleted
=
false
;
DeletionTester
*
t
=
new
DeletionTester
(
&
is_deleted
);
const
Action
<
void
(
bool
,
int
,
int
,
const
char
*
,
bool
,
int
,
int
,
int
,
int
,
DeletionTester
*
)
>
a1
=
DeleteArg
<
9
>
();
const
Action
<
void
(
bool
,
int
,
int
,
const
char
*
,
bool
,
int
,
int
,
int
,
int
,
DeletionTester
*
)
>
a1
=
DeleteArg
<
9
>
();
EXPECT_FALSE
(
is_deleted
);
a1
.
Perform
(
std
::
make_tuple
(
true
,
5
,
6
,
CharPtr
(
"hi"
),
false
,
7
,
8
,
9
,
10
,
t
));
EXPECT_TRUE
(
is_deleted
);
...
...
@@ -608,7 +605,7 @@ TEST(ThrowActionTest, Times0) {
// pointed to by the N-th (0-based) argument to values in range [first, last).
TEST
(
SetArrayArgumentTest
,
SetsTheNthArray
)
{
using
MyFunction
=
void
(
bool
,
int
*
,
char
*
);
int
numbers
[]
=
{
1
,
2
,
3
};
int
numbers
[]
=
{
1
,
2
,
3
};
Action
<
MyFunction
>
a
=
SetArrayArgument
<
1
>
(
numbers
,
numbers
+
3
);
int
n
[
4
]
=
{};
...
...
@@ -644,7 +641,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArray) {
// Tests SetArrayArgument<N>(first, last) where first == last.
TEST
(
SetArrayArgumentTest
,
SetsTheNthArrayWithEmptyRange
)
{
using
MyFunction
=
void
(
bool
,
int
*
);
int
numbers
[]
=
{
1
,
2
,
3
};
int
numbers
[]
=
{
1
,
2
,
3
};
Action
<
MyFunction
>
a
=
SetArrayArgument
<
1
>
(
numbers
,
numbers
);
int
n
[
4
]
=
{};
...
...
@@ -660,10 +657,10 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) {
// (but not equal) to the argument type.
TEST
(
SetArrayArgumentTest
,
SetsTheNthArrayWithConvertibleType
)
{
using
MyFunction
=
void
(
bool
,
int
*
);
char
chars
[]
=
{
97
,
98
,
99
};
char
chars
[]
=
{
97
,
98
,
99
};
Action
<
MyFunction
>
a
=
SetArrayArgument
<
1
>
(
chars
,
chars
+
3
);
int
codes
[
4
]
=
{
111
,
222
,
333
,
444
};
int
codes
[
4
]
=
{
111
,
222
,
333
,
444
};
int
*
pcodes
=
codes
;
a
.
Perform
(
std
::
make_tuple
(
true
,
pcodes
));
EXPECT_EQ
(
97
,
codes
[
0
]);
...
...
googlemock/test/gmock-nice-strict_test.cc
View file @
9e712372
...
...
@@ -31,6 +31,7 @@
#include <string>
#include <utility>
#include "gmock/gmock.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
...
...
@@ -102,7 +103,8 @@ class MockBar {
MockBar
(
char
a1
,
char
a2
,
std
::
string
a3
,
std
::
string
a4
,
int
a5
,
int
a6
,
const
std
::
string
&
a7
,
const
std
::
string
&
a8
,
bool
a9
,
bool
a10
)
{
str_
=
std
::
string
()
+
a1
+
a2
+
a3
+
a4
+
static_cast
<
char
>
(
a5
)
+
static_cast
<
char
>
(
a6
)
+
a7
+
a8
+
(
a9
?
'T'
:
'F'
)
+
(
a10
?
'T'
:
'F'
);
static_cast
<
char
>
(
a6
)
+
a7
+
a8
+
(
a9
?
'T'
:
'F'
)
+
(
a10
?
'T'
:
'F'
);
}
virtual
~
MockBar
()
{}
...
...
@@ -118,7 +120,6 @@ class MockBar {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
};
class
MockBaz
{
public:
class
MoveOnly
{
...
...
@@ -161,8 +162,7 @@ TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
MockFoo
*
const
raw_foo
=
new
MockFoo
;
ON_CALL
(
*
raw_foo
,
DoThis
())
.
WillByDefault
(
Invoke
(
raw_foo
,
&
MockFoo
::
Delete
));
ON_CALL
(
*
raw_foo
,
DoThis
()).
WillByDefault
(
Invoke
(
raw_foo
,
&
MockFoo
::
Delete
));
CaptureStdout
();
raw_foo
->
DoThis
();
...
...
@@ -280,8 +280,8 @@ TEST(NiceMockTest, NonDefaultConstructor) {
// Tests that NiceMock works with a mock class that has a 10-ary
// non-default constructor.
TEST
(
NiceMockTest
,
NonDefaultConstructor10
)
{
NiceMock
<
MockBar
>
nice_bar
(
'a'
,
'b'
,
"c"
,
"d"
,
'e'
,
'f'
,
"g"
,
"h"
,
true
,
false
);
NiceMock
<
MockBar
>
nice_bar
(
'a'
,
'b'
,
"c"
,
"d"
,
'e'
,
'f'
,
"g"
,
"h"
,
true
,
false
);
EXPECT_EQ
(
"abcdefghTF"
,
nice_bar
.
str
());
nice_bar
.
This
();
...
...
@@ -390,8 +390,8 @@ TEST(NaggyMockTest, NonDefaultConstructor) {
// Tests that NaggyMock works with a mock class that has a 10-ary
// non-default constructor.
TEST
(
NaggyMockTest
,
NonDefaultConstructor10
)
{
NaggyMock
<
MockBar
>
naggy_bar
(
'0'
,
'1'
,
"2"
,
"3"
,
'4'
,
'5'
,
"6"
,
"7"
,
true
,
false
);
NaggyMock
<
MockBar
>
naggy_bar
(
'0'
,
'1'
,
"2"
,
"3"
,
'4'
,
'5'
,
"6"
,
"7"
,
true
,
false
);
EXPECT_EQ
(
"01234567TF"
,
naggy_bar
.
str
());
naggy_bar
.
This
();
...
...
@@ -490,8 +490,8 @@ TEST(StrictMockTest, NonDefaultConstructor) {
// Tests that StrictMock works with a mock class that has a 10-ary
// non-default constructor.
TEST
(
StrictMockTest
,
NonDefaultConstructor10
)
{
StrictMock
<
MockBar
>
strict_bar
(
'a'
,
'b'
,
"c"
,
"d"
,
'e'
,
'f'
,
"g"
,
"h"
,
true
,
false
);
StrictMock
<
MockBar
>
strict_bar
(
'a'
,
'b'
,
"c"
,
"d"
,
'e'
,
'f'
,
"g"
,
"h"
,
true
,
false
);
EXPECT_EQ
(
"abcdefghTF"
,
strict_bar
.
str
());
EXPECT_NONFATAL_FAILURE
(
strict_bar
.
That
(
5
,
true
),
...
...
googlemock/test/gmock-port_test.cc
View file @
9e712372
...
...
@@ -27,12 +27,12 @@
// (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 tests the internal cross-platform support utilities.
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
// NOTE: if this file is left without tests for some reason, put a dummy
...
...
googlemock/test/gmock-pp-string_test.cc
View file @
9e712372
...
...
@@ -30,11 +30,10 @@
// Google Mock - a framework for writing C++ mock classes.
//
// This file tests the internal preprocessor macro library.
#include "gmock/internal/gmock-pp.h"
#include <string>
#include "gmock/gmock.h"
#include "gmock/internal/gmock-pp.h"
namespace
testing
{
namespace
{
...
...
googlemock/test/gmock-spec-builders_test.cc
View file @
9e712372
This diff is collapsed.
Click to expand it.
googlemock/test/gmock_ex_test.cc
View file @
9e712372
...
...
@@ -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.
// Tests Google Mock's functionality that depends on exceptions.
#include "gmock/gmock.h"
...
...
@@ -75,6 +74,5 @@ TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) {
}
}
}
// unnamed namespace
#endif
googlemock/test/gmock_leak_test_.cc
View file @
9e712372
...
...
@@ -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 program is for verifying that a leaked mock object can be
...
...
googlemock/test/gmock_link2_test.cc
View file @
9e712372
...
...
@@ -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 is for verifying that various Google Mock constructs do not
...
...
googlemock/test/gmock_link_test.cc
View file @
9e712372
...
...
@@ -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 is for verifying that various Google Mock constructs do not
...
...
googlemock/test/gmock_link_test.h
View file @
9e712372
...
...
@@ -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 tests that:
...
...
@@ -118,7 +117,7 @@
#include "gmock/gmock.h"
#if !GTEST_OS_WINDOWS_MOBILE
#
include <errno.h>
#include <errno.h>
#endif
#include <iostream>
...
...
@@ -200,14 +199,14 @@ class Interface {
virtual
char
*
StringFromString
(
char
*
str
)
=
0
;
virtual
int
IntFromString
(
char
*
str
)
=
0
;
virtual
int
&
IntRefFromString
(
char
*
str
)
=
0
;
virtual
void
VoidFromFunc
(
void
(
*
func
)(
char
*
str
))
=
0
;
virtual
void
VoidFromFunc
(
void
(
*
func
)(
char
*
str
))
=
0
;
virtual
void
VoidFromIntRef
(
int
&
n
)
=
0
;
// NOLINT
virtual
void
VoidFromFloat
(
float
n
)
=
0
;
virtual
void
VoidFromDouble
(
double
n
)
=
0
;
virtual
void
VoidFromVector
(
const
std
::
vector
<
int
>&
v
)
=
0
;
};
class
Mock
:
public
Interface
{
class
Mock
:
public
Interface
{
public:
Mock
()
{}
...
...
@@ -215,7 +214,7 @@ class Mock: public Interface {
MOCK_METHOD1
(
StringFromString
,
char
*
(
char
*
str
));
MOCK_METHOD1
(
IntFromString
,
int
(
char
*
str
));
MOCK_METHOD1
(
IntRefFromString
,
int
&
(
char
*
str
));
MOCK_METHOD1
(
VoidFromFunc
,
void
(
void
(
*
func
)(
char
*
str
)));
MOCK_METHOD1
(
VoidFromFunc
,
void
(
void
(
*
func
)(
char
*
str
)));
MOCK_METHOD1
(
VoidFromIntRef
,
void
(
int
&
n
));
// NOLINT
MOCK_METHOD1
(
VoidFromFloat
,
void
(
float
n
));
MOCK_METHOD1
(
VoidFromDouble
,
void
(
double
n
));
...
...
@@ -301,8 +300,8 @@ TEST(LinkTest, TestSetArrayArgument) {
char
ch
=
'x'
;
char
ch2
=
'y'
;
EXPECT_CALL
(
mock
,
VoidFromString
(
_
))
.
WillOnce
(
SetArrayArgument
<
0
>
(
&
ch2
,
&
ch2
+
1
));
EXPECT_CALL
(
mock
,
VoidFromString
(
_
))
.
WillOnce
(
SetArrayArgument
<
0
>
(
&
ch2
,
&
ch2
+
1
));
mock
.
VoidFromString
(
&
ch
);
}
...
...
@@ -339,8 +338,8 @@ TEST(LinkTest, TestInvokeWithoutArgs) {
EXPECT_CALL
(
mock
,
VoidFromString
(
_
))
.
WillOnce
(
InvokeWithoutArgs
(
&
InvokeHelper
::
StaticVoidFromVoid
))
.
WillOnce
(
InvokeWithoutArgs
(
&
test_invoke_helper
,
&
InvokeHelper
::
VoidFromVoid
));
.
WillOnce
(
InvokeWithoutArgs
(
&
test_invoke_helper
,
&
InvokeHelper
::
VoidFromVoid
));
mock
.
VoidFromString
(
nullptr
);
mock
.
VoidFromString
(
nullptr
);
}
...
...
@@ -424,14 +423,14 @@ TEST(LinkTest, TestThrow) {
// is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here.
#ifdef _MSC_VER
#
pragma warning(push)
#
pragma warning(disable
:
4100)
#pragma warning(push)
#pragma warning(disable
:
4100)
#endif
// Tests the linkage of actions created using ACTION macro.
namespace
{
ACTION
(
Return1
)
{
return
1
;
}
}
}
// namespace
TEST
(
LinkTest
,
TestActionMacro
)
{
Mock
mock
;
...
...
@@ -443,7 +442,7 @@ TEST(LinkTest, TestActionMacro) {
// Tests the linkage of actions created using ACTION_P macro.
namespace
{
ACTION_P
(
ReturnArgument
,
ret_value
)
{
return
ret_value
;
}
}
}
// namespace
TEST
(
LinkTest
,
TestActionPMacro
)
{
Mock
mock
;
...
...
@@ -457,10 +456,10 @@ namespace {
ACTION_P2
(
ReturnEqualsEitherOf
,
first
,
second
)
{
return
arg0
==
first
||
arg0
==
second
;
}
}
}
// namespace
#ifdef _MSC_VER
#
pragma warning(pop)
#pragma warning(pop)
#endif
TEST
(
LinkTest
,
TestActionP2Macro
)
{
...
...
@@ -492,8 +491,7 @@ TEST(LinkTest, TestMatchersEq) {
const
char
*
p
=
"x"
;
ON_CALL
(
mock
,
VoidFromString
(
Eq
(
p
))).
WillByDefault
(
Return
());
ON_CALL
(
mock
,
VoidFromString
(
const_cast
<
char
*>
(
"y"
)))
.
WillByDefault
(
Return
());
ON_CALL
(
mock
,
VoidFromString
(
const_cast
<
char
*>
(
"y"
))).
WillByDefault
(
Return
());
}
// Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
...
...
@@ -592,7 +590,7 @@ TEST(LinkTest, TestMatcherElementsAre) {
// Tests the linkage of the ElementsAreArray matcher.
TEST
(
LinkTest
,
TestMatcherElementsAreArray
)
{
Mock
mock
;
char
arr
[]
=
{
'a'
,
'b'
};
char
arr
[]
=
{
'a'
,
'b'
};
ON_CALL
(
mock
,
VoidFromVector
(
ElementsAreArray
(
arr
))).
WillByDefault
(
Return
());
}
...
...
googlemock/test/gmock_output_test_.cc
View file @
9e712372
...
...
@@ -27,21 +27,20 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Tests Google Mock's output in various scenarios. This ensures that
// Google Mock's messages are readable and useful.
#include "gmock/gmock.h"
#include <stdio.h>
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
// Silence C4100 (unreferenced formal parameter)
#ifdef _MSC_VER
#
pragma warning(push)
#
pragma warning(disable
:
4100)
#pragma warning(push)
#pragma warning(disable
:
4100)
#endif
using
testing
::
_
;
...
...
@@ -90,9 +89,7 @@ TEST_F(GMockOutputTest, ExpectedCallToVoidFunction) {
}
TEST_F
(
GMockOutputTest
,
ExplicitActionsRunOut
)
{
EXPECT_CALL
(
foo_
,
Bar2
(
_
,
_
))
.
Times
(
2
)
.
WillOnce
(
Return
(
false
));
EXPECT_CALL
(
foo_
,
Bar2
(
_
,
_
)).
Times
(
2
).
WillOnce
(
Return
(
false
));
foo_
.
Bar2
(
2
,
2
);
foo_
.
Bar2
(
1
,
1
);
// Explicit actions in EXPECT_CALL run out.
}
...
...
@@ -134,8 +131,7 @@ TEST_F(GMockOutputTest, UninterestingCallToVoidFunction) {
}
TEST_F
(
GMockOutputTest
,
RetiredExpectation
)
{
EXPECT_CALL
(
foo_
,
Bar2
(
_
,
_
))
.
RetiresOnSaturation
();
EXPECT_CALL
(
foo_
,
Bar2
(
_
,
_
)).
RetiresOnSaturation
();
EXPECT_CALL
(
foo_
,
Bar2
(
0
,
0
));
foo_
.
Bar2
(
1
,
1
);
...
...
@@ -160,12 +156,9 @@ TEST_F(GMockOutputTest, UnsatisfiedPrerequisite) {
TEST_F
(
GMockOutputTest
,
UnsatisfiedPrerequisites
)
{
Sequence
s1
,
s2
;
EXPECT_CALL
(
foo_
,
Bar
(
_
,
0
,
_
))
.
InSequence
(
s1
);
EXPECT_CALL
(
foo_
,
Bar2
(
0
,
0
))
.
InSequence
(
s2
);
EXPECT_CALL
(
foo_
,
Bar2
(
1
,
_
))
.
InSequence
(
s1
,
s2
);
EXPECT_CALL
(
foo_
,
Bar
(
_
,
0
,
_
)).
InSequence
(
s1
);
EXPECT_CALL
(
foo_
,
Bar2
(
0
,
0
)).
InSequence
(
s2
);
EXPECT_CALL
(
foo_
,
Bar2
(
1
,
_
)).
InSequence
(
s1
,
s2
);
foo_
.
Bar2
(
1
,
0
);
// Has two immediate unsatisfied pre-requisites
foo_
.
Bar
(
"Hi"
,
0
,
0
);
...
...
@@ -179,8 +172,7 @@ TEST_F(GMockOutputTest, UnsatisfiedWith) {
TEST_F
(
GMockOutputTest
,
UnsatisfiedExpectation
)
{
EXPECT_CALL
(
foo_
,
Bar
(
_
,
_
,
_
));
EXPECT_CALL
(
foo_
,
Bar2
(
0
,
_
))
.
Times
(
2
);
EXPECT_CALL
(
foo_
,
Bar2
(
0
,
_
)).
Times
(
2
);
foo_
.
Bar2
(
0
,
1
);
}
...
...
@@ -194,26 +186,22 @@ TEST_F(GMockOutputTest, MismatchArguments) {
}
TEST_F
(
GMockOutputTest
,
MismatchWith
)
{
EXPECT_CALL
(
foo_
,
Bar2
(
Ge
(
2
),
Ge
(
1
)))
.
With
(
Ge
());
EXPECT_CALL
(
foo_
,
Bar2
(
Ge
(
2
),
Ge
(
1
))).
With
(
Ge
());
foo_
.
Bar2
(
2
,
3
);
// Mismatch With()
foo_
.
Bar2
(
2
,
1
);
}
TEST_F
(
GMockOutputTest
,
MismatchArgumentsAndWith
)
{
EXPECT_CALL
(
foo_
,
Bar2
(
Ge
(
2
),
Ge
(
1
)))
.
With
(
Ge
());
EXPECT_CALL
(
foo_
,
Bar2
(
Ge
(
2
),
Ge
(
1
))).
With
(
Ge
());
foo_
.
Bar2
(
1
,
3
);
// Mismatch arguments and mismatch With()
foo_
.
Bar2
(
2
,
1
);
}
TEST_F
(
GMockOutputTest
,
UnexpectedCallWithDefaultAction
)
{
ON_CALL
(
foo_
,
Bar2
(
_
,
_
))
.
WillByDefault
(
Return
(
true
));
// Default action #1
ON_CALL
(
foo_
,
Bar2
(
1
,
_
))
.
WillByDefault
(
Return
(
false
));
// Default action #2
ON_CALL
(
foo_
,
Bar2
(
_
,
_
)).
WillByDefault
(
Return
(
true
));
// Default action #1
ON_CALL
(
foo_
,
Bar2
(
1
,
_
)).
WillByDefault
(
Return
(
false
));
// Default action #2
EXPECT_CALL
(
foo_
,
Bar2
(
2
,
2
));
foo_
.
Bar2
(
1
,
0
);
// Unexpected call, takes default action #2.
...
...
@@ -222,10 +210,8 @@ TEST_F(GMockOutputTest, UnexpectedCallWithDefaultAction) {
}
TEST_F
(
GMockOutputTest
,
ExcessiveCallWithDefaultAction
)
{
ON_CALL
(
foo_
,
Bar2
(
_
,
_
))
.
WillByDefault
(
Return
(
true
));
// Default action #1
ON_CALL
(
foo_
,
Bar2
(
1
,
_
))
.
WillByDefault
(
Return
(
false
));
// Default action #2
ON_CALL
(
foo_
,
Bar2
(
_
,
_
)).
WillByDefault
(
Return
(
true
));
// Default action #1
ON_CALL
(
foo_
,
Bar2
(
1
,
_
)).
WillByDefault
(
Return
(
false
));
// Default action #2
EXPECT_CALL
(
foo_
,
Bar2
(
2
,
2
));
EXPECT_CALL
(
foo_
,
Bar2
(
1
,
1
));
...
...
@@ -237,22 +223,17 @@ TEST_F(GMockOutputTest, ExcessiveCallWithDefaultAction) {
}
TEST_F
(
GMockOutputTest
,
UninterestingCallWithDefaultAction
)
{
ON_CALL
(
foo_
,
Bar2
(
_
,
_
))
.
WillByDefault
(
Return
(
true
));
// Default action #1
ON_CALL
(
foo_
,
Bar2
(
1
,
_
))
.
WillByDefault
(
Return
(
false
));
// Default action #2
ON_CALL
(
foo_
,
Bar2
(
_
,
_
)).
WillByDefault
(
Return
(
true
));
// Default action #1
ON_CALL
(
foo_
,
Bar2
(
1
,
_
)).
WillByDefault
(
Return
(
false
));
// Default action #2
foo_
.
Bar2
(
2
,
2
);
// Uninteresting call, takes default action #1.
foo_
.
Bar2
(
1
,
1
);
// Uninteresting call, takes default action #2.
}
TEST_F
(
GMockOutputTest
,
ExplicitActionsRunOutWithDefaultAction
)
{
ON_CALL
(
foo_
,
Bar2
(
_
,
_
))
.
WillByDefault
(
Return
(
true
));
// Default action #1
ON_CALL
(
foo_
,
Bar2
(
_
,
_
)).
WillByDefault
(
Return
(
true
));
// Default action #1
EXPECT_CALL
(
foo_
,
Bar2
(
_
,
_
))
.
Times
(
2
)
.
WillOnce
(
Return
(
false
));
EXPECT_CALL
(
foo_
,
Bar2
(
_
,
_
)).
Times
(
2
).
WillOnce
(
Return
(
false
));
foo_
.
Bar2
(
2
,
2
);
foo_
.
Bar2
(
1
,
1
);
// Explicit actions in EXPECT_CALL run out.
}
...
...
@@ -293,7 +274,7 @@ void TestCatchesLeakedMocksInAdHocTests() {
// foo is deliberately leaked.
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleMock
(
&
argc
,
argv
);
// Ensures that the tests pass no matter what value of
// --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.
...
...
@@ -305,5 +286,5 @@ int main(int argc, char **argv) {
}
#ifdef _MSC_VER
#
pragma warning(pop)
#pragma warning(pop)
#endif
googlemock/test/gmock_stress_test.cc
View file @
9e712372
...
...
@@ -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.
// Tests that Google Mock constructs can be used in a large number of
// threads concurrently.
...
...
@@ -49,7 +48,7 @@ const int kRepeat = 50;
class
MockFoo
{
public:
MOCK_METHOD1
(
Bar
,
int
(
int
n
));
// NOLINT
MOCK_METHOD1
(
Bar
,
int
(
int
n
));
// NOLINT
MOCK_METHOD2
(
Baz
,
char
(
const
char
*
s1
,
const
std
::
string
&
s2
));
// NOLINT
};
...
...
@@ -62,21 +61,16 @@ void JoinAndDelete(ThreadWithParam<T>* t) {
struct
Dummy
{};
// Tests that different mock objects can be used in their respective
// threads. This should generate no Google Test failure.
void
TestConcurrentMockObjects
(
Dummy
/* dummy */
)
{
// Creates a mock and does some typical operations on it.
MockFoo
foo
;
ON_CALL
(
foo
,
Bar
(
_
))
.
WillByDefault
(
Return
(
1
));
ON_CALL
(
foo
,
Baz
(
_
,
_
))
.
WillByDefault
(
Return
(
'b'
));
ON_CALL
(
foo
,
Baz
(
_
,
"you"
))
.
WillByDefault
(
Return
(
'a'
));
EXPECT_CALL
(
foo
,
Bar
(
0
))
.
Times
(
AtMost
(
3
));
ON_CALL
(
foo
,
Bar
(
_
)).
WillByDefault
(
Return
(
1
));
ON_CALL
(
foo
,
Baz
(
_
,
_
)).
WillByDefault
(
Return
(
'b'
));
ON_CALL
(
foo
,
Baz
(
_
,
"you"
)).
WillByDefault
(
Return
(
'a'
));
EXPECT_CALL
(
foo
,
Bar
(
0
)).
Times
(
AtMost
(
3
));
EXPECT_CALL
(
foo
,
Baz
(
_
,
_
));
EXPECT_CALL
(
foo
,
Baz
(
"hi"
,
"you"
))
.
WillOnce
(
Return
(
'z'
))
...
...
@@ -119,22 +113,19 @@ void Helper1(Helper1Param param) {
void
TestConcurrentCallsOnSameObject
(
Dummy
/* dummy */
)
{
MockFoo
foo
;
ON_CALL
(
foo
,
Bar
(
_
))
.
WillByDefault
(
Return
(
1
));
EXPECT_CALL
(
foo
,
Baz
(
_
,
"b"
))
.
Times
(
kRepeat
)
.
WillRepeatedly
(
Return
(
'a'
));
ON_CALL
(
foo
,
Bar
(
_
)).
WillByDefault
(
Return
(
1
));
EXPECT_CALL
(
foo
,
Baz
(
_
,
"b"
)).
Times
(
kRepeat
).
WillRepeatedly
(
Return
(
'a'
));
EXPECT_CALL
(
foo
,
Baz
(
_
,
"c"
));
// Expected to be unsatisfied.
// This chunk of code should generate kRepeat failures about
// excessive calls, and 2*kRepeat failures about unexpected calls.
int
count1
=
0
;
const
Helper1Param
param
=
{
&
foo
,
&
count1
};
const
Helper1Param
param
=
{
&
foo
,
&
count1
};
ThreadWithParam
<
Helper1Param
>*
const
t
=
new
ThreadWithParam
<
Helper1Param
>
(
Helper1
,
param
,
nullptr
);
int
count2
=
0
;
const
Helper1Param
param2
=
{
&
foo
,
&
count2
};
const
Helper1Param
param2
=
{
&
foo
,
&
count2
};
Helper1
(
param2
);
JoinAndDelete
(
t
);
...
...
@@ -162,22 +153,18 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) {
{
InSequence
dummy
;
EXPECT_CALL
(
foo
,
Bar
(
0
));
EXPECT_CALL
(
foo
,
Bar
(
1
))
.
InSequence
(
s1
,
s2
);
EXPECT_CALL
(
foo
,
Bar
(
1
)).
InSequence
(
s1
,
s2
);
}
EXPECT_CALL
(
foo
,
Bar
(
2
))
.
Times
(
2
*
kRepeat
)
.
Times
(
2
*
kRepeat
)
.
InSequence
(
s1
)
.
RetiresOnSaturation
();
EXPECT_CALL
(
foo
,
Bar
(
3
))
.
Times
(
2
*
kRepeat
)
.
InSequence
(
s2
);
EXPECT_CALL
(
foo
,
Bar
(
3
)).
Times
(
2
*
kRepeat
).
InSequence
(
s2
);
{
InSequence
dummy
;
EXPECT_CALL
(
foo
,
Bar
(
2
))
.
InSequence
(
s1
,
s2
);
EXPECT_CALL
(
foo
,
Bar
(
2
)).
InSequence
(
s1
,
s2
);
EXPECT_CALL
(
foo
,
Bar
(
4
));
}
...
...
@@ -196,12 +183,12 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) {
// Tests using Google Mock constructs in many threads concurrently.
TEST
(
StressTest
,
CanUseGMockWithThreads
)
{
void
(
*
test_routines
[])(
Dummy
dummy
)
=
{
&
TestConcurrentMockObjects
,
&
TestConcurrentCallsOnSameObject
,
&
TestPartiallyOrderedExpectationsWithThreads
,
&
TestConcurrentMockObjects
,
&
TestConcurrentCallsOnSameObject
,
&
TestPartiallyOrderedExpectationsWithThreads
,
};
const
int
kRoutines
=
sizeof
(
test_routines
)
/
sizeof
(
test_routines
[
0
]);
const
int
kRoutines
=
sizeof
(
test_routines
)
/
sizeof
(
test_routines
[
0
]);
const
int
kCopiesOfEachRoutine
=
kMaxTestThreads
/
kRoutines
;
const
int
kTestThreads
=
kCopiesOfEachRoutine
*
kRoutines
;
ThreadWithParam
<
Dummy
>*
threads
[
kTestThreads
]
=
{};
...
...
@@ -220,7 +207,7 @@ TEST(StressTest, CanUseGMockWithThreads) {
// Ensures that the correct number of failures have been reported.
const
TestInfo
*
const
info
=
UnitTest
::
GetInstance
()
->
current_test_info
();
const
TestResult
&
result
=
*
info
->
result
();
const
int
kExpectedFailures
=
(
3
*
kRepeat
+
1
)
*
kCopiesOfEachRoutine
;
const
int
kExpectedFailures
=
(
3
*
kRepeat
+
1
)
*
kCopiesOfEachRoutine
;
GTEST_CHECK_
(
kExpectedFailures
==
result
.
total_part_count
())
<<
"Expected "
<<
kExpectedFailures
<<
" failures, but got "
<<
result
.
total_part_count
();
...
...
@@ -229,7 +216,7 @@ TEST(StressTest, CanUseGMockWithThreads) {
}
// namespace
}
// namespace testing
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleMock
(
&
argc
,
argv
);
const
int
exit_code
=
RUN_ALL_TESTS
();
// Expected to fail.
...
...
googlemock/test/gmock_test.cc
View file @
9e712372
...
...
@@ -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 tests code in gmock.cc.
...
...
@@ -35,6 +34,7 @@
#include "gmock/gmock.h"
#include <string>
#include "gtest/gtest.h"
#include "gtest/internal/custom/gtest.h"
...
...
googletest/include/gtest/gtest-death-test.h
View file @
9e712372
...
...
@@ -170,24 +170,24 @@ GTEST_API_ bool InDeathTestChild();
// Asserts that a given `statement` causes the program to exit, with an
// integer exit status that satisfies `predicate`, and emitting error output
// that matches `matcher`.
#
define ASSERT_EXIT(statement, predicate, matcher) \
GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_FATAL_FAILURE_)
#define ASSERT_EXIT(statement, predicate, matcher) \
GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_FATAL_FAILURE_)
// Like `ASSERT_EXIT`, but continues on to successive tests in the
// test suite, if any:
#
define EXPECT_EXIT(statement, predicate, matcher) \
GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_NONFATAL_FAILURE_)
#define EXPECT_EXIT(statement, predicate, matcher) \
GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_NONFATAL_FAILURE_)
// Asserts that a given `statement` causes the program to exit, either by
// explicitly exiting with a nonzero exit code or being killed by a
// signal, and emitting error output that matches `matcher`.
#
define ASSERT_DEATH(statement, matcher) \
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher)
#define ASSERT_DEATH(statement, matcher) \
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher)
// Like `ASSERT_DEATH`, but continues on to successive tests in the
// test suite, if any:
#
define EXPECT_DEATH(statement, matcher) \
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher)
#define EXPECT_DEATH(statement, matcher) \
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher)
// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
...
...
@@ -198,21 +198,23 @@ class GTEST_API_ ExitedWithCode {
ExitedWithCode
(
const
ExitedWithCode
&
)
=
default
;
void
operator
=
(
const
ExitedWithCode
&
other
)
=
delete
;
bool
operator
()(
int
exit_status
)
const
;
private:
const
int
exit_code_
;
};
#
if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
// Tests that an exit code describes an exit due to termination by a
// given signal.
class
GTEST_API_
KilledBySignal
{
public:
explicit
KilledBySignal
(
int
signum
);
bool
operator
()(
int
exit_status
)
const
;
private:
const
int
signum_
;
};
#
endif // !GTEST_OS_WINDOWS
#endif // !GTEST_OS_WINDOWS
// EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.
// The death testing framework causes this to have interesting semantics,
...
...
@@ -257,23 +259,21 @@ class GTEST_API_ KilledBySignal {
// EXPECT_EQ(12, DieInDebugOr12(&sideeffect));
// }, "death");
//
#
ifdef NDEBUG
#ifdef NDEBUG
#
define EXPECT_DEBUG_DEATH(statement, regex) \
#define EXPECT_DEBUG_DEATH(statement, regex) \
GTEST_EXECUTE_STATEMENT_(statement, regex)
#
define ASSERT_DEBUG_DEATH(statement, regex) \
#define ASSERT_DEBUG_DEATH(statement, regex) \
GTEST_EXECUTE_STATEMENT_(statement, regex)
#
else
#else
# define EXPECT_DEBUG_DEATH(statement, regex) \
EXPECT_DEATH(statement, regex)
#define EXPECT_DEBUG_DEATH(statement, regex) EXPECT_DEATH(statement, regex)
# define ASSERT_DEBUG_DEATH(statement, regex) \
ASSERT_DEATH(statement, regex)
#define ASSERT_DEBUG_DEATH(statement, regex) ASSERT_DEATH(statement, regex)
#
endif // NDEBUG for EXPECT_DEBUG_DEATH
#endif // NDEBUG for EXPECT_DEBUG_DEATH
#endif // GTEST_HAS_DEATH_TEST
// This macro is used for implementing macros such as
...
...
@@ -311,18 +311,17 @@ class GTEST_API_ KilledBySignal {
// statement unconditionally returns or throws. The Message constructor at
// the end allows the syntax of streaming additional messages into the
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
# define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::AlwaysTrue()) { \
GTEST_LOG_(WARNING) \
<< "Death tests are not supported on this platform.\n" \
<< "Statement '" #statement "' cannot be verified."; \
} else if (::testing::internal::AlwaysFalse()) { \
::testing::internal::RE::PartialMatch(".*", (regex)); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
terminator; \
} else \
::testing::Message()
#define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::AlwaysTrue()) { \
GTEST_LOG_(WARNING) << "Death tests are not supported on this platform.\n" \
<< "Statement '" #statement "' cannot be verified."; \
} else if (::testing::internal::AlwaysFalse()) { \
::testing::internal::RE::PartialMatch(".*", (regex)); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
terminator; \
} else \
::testing::Message()
// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
// ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if
...
...
@@ -330,15 +329,15 @@ class GTEST_API_ KilledBySignal {
// useful when you are combining death test assertions with normal test
// assertions in one test.
#if GTEST_HAS_DEATH_TEST
#
define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
EXPECT_DEATH(statement, regex)
#
define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
ASSERT_DEATH(statement, regex)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
EXPECT_DEATH(statement, regex)
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
ASSERT_DEATH(statement, regex)
#else
#
define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, )
#
define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, )
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return)
#endif
}
// namespace testing
...
...
googletest/include/gtest/gtest-matchers.h
View file @
9e712372
...
...
@@ -105,8 +105,7 @@ class MatchResultListener {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MatchResultListener
);
};
inline
MatchResultListener
::~
MatchResultListener
()
{
}
inline
MatchResultListener
::~
MatchResultListener
()
{}
// An instance of a subclass of this knows how to describe itself as a
// matcher.
...
...
@@ -180,27 +179,39 @@ namespace internal {
struct
AnyEq
{
template
<
typename
A
,
typename
B
>
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
==
b
;
}
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
==
b
;
}
};
struct
AnyNe
{
template
<
typename
A
,
typename
B
>
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
!=
b
;
}
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
!=
b
;
}
};
struct
AnyLt
{
template
<
typename
A
,
typename
B
>
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
<
b
;
}
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
<
b
;
}
};
struct
AnyGt
{
template
<
typename
A
,
typename
B
>
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
>
b
;
}
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
>
b
;
}
};
struct
AnyLe
{
template
<
typename
A
,
typename
B
>
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
<=
b
;
}
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
<=
b
;
}
};
struct
AnyGe
{
template
<
typename
A
,
typename
B
>
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
>=
b
;
}
bool
operator
()(
const
A
&
a
,
const
B
&
b
)
const
{
return
a
>=
b
;
}
};
// A match result listener that ignores the explanation.
...
...
@@ -424,8 +435,8 @@ class MatcherBase : private MatcherDescriberInterface {
static
const
M
&
Get
(
const
MatcherBase
&
m
)
{
// When inlined along with Init, need to be explicit to avoid violating
// strict aliasing rules.
const
M
*
ptr
=
static_cast
<
const
M
*>
(
static_cast
<
const
void
*>
(
&
m
.
buffer_
));
const
M
*
ptr
=
static_cast
<
const
M
*>
(
static_cast
<
const
void
*>
(
&
m
.
buffer_
));
return
*
ptr
;
}
static
void
Init
(
MatcherBase
&
m
,
M
impl
)
{
...
...
@@ -745,7 +756,7 @@ template <typename Rhs>
class
EqMatcher
:
public
ComparisonBase
<
EqMatcher
<
Rhs
>
,
Rhs
,
AnyEq
>
{
public:
explicit
EqMatcher
(
const
Rhs
&
rhs
)
:
ComparisonBase
<
EqMatcher
<
Rhs
>
,
Rhs
,
AnyEq
>
(
rhs
)
{
}
:
ComparisonBase
<
EqMatcher
<
Rhs
>
,
Rhs
,
AnyEq
>
(
rhs
)
{}
static
const
char
*
Desc
()
{
return
"is equal to"
;
}
static
const
char
*
NegatedDesc
()
{
return
"isn't equal to"
;
}
};
...
...
@@ -753,7 +764,7 @@ template <typename Rhs>
class
NeMatcher
:
public
ComparisonBase
<
NeMatcher
<
Rhs
>
,
Rhs
,
AnyNe
>
{
public:
explicit
NeMatcher
(
const
Rhs
&
rhs
)
:
ComparisonBase
<
NeMatcher
<
Rhs
>
,
Rhs
,
AnyNe
>
(
rhs
)
{
}
:
ComparisonBase
<
NeMatcher
<
Rhs
>
,
Rhs
,
AnyNe
>
(
rhs
)
{}
static
const
char
*
Desc
()
{
return
"isn't equal to"
;
}
static
const
char
*
NegatedDesc
()
{
return
"is equal to"
;
}
};
...
...
@@ -761,7 +772,7 @@ template <typename Rhs>
class
LtMatcher
:
public
ComparisonBase
<
LtMatcher
<
Rhs
>
,
Rhs
,
AnyLt
>
{
public:
explicit
LtMatcher
(
const
Rhs
&
rhs
)
:
ComparisonBase
<
LtMatcher
<
Rhs
>
,
Rhs
,
AnyLt
>
(
rhs
)
{
}
:
ComparisonBase
<
LtMatcher
<
Rhs
>
,
Rhs
,
AnyLt
>
(
rhs
)
{}
static
const
char
*
Desc
()
{
return
"is <"
;
}
static
const
char
*
NegatedDesc
()
{
return
"isn't <"
;
}
};
...
...
@@ -769,7 +780,7 @@ template <typename Rhs>
class
GtMatcher
:
public
ComparisonBase
<
GtMatcher
<
Rhs
>
,
Rhs
,
AnyGt
>
{
public:
explicit
GtMatcher
(
const
Rhs
&
rhs
)
:
ComparisonBase
<
GtMatcher
<
Rhs
>
,
Rhs
,
AnyGt
>
(
rhs
)
{
}
:
ComparisonBase
<
GtMatcher
<
Rhs
>
,
Rhs
,
AnyGt
>
(
rhs
)
{}
static
const
char
*
Desc
()
{
return
"is >"
;
}
static
const
char
*
NegatedDesc
()
{
return
"isn't >"
;
}
};
...
...
@@ -777,7 +788,7 @@ template <typename Rhs>
class
LeMatcher
:
public
ComparisonBase
<
LeMatcher
<
Rhs
>
,
Rhs
,
AnyLe
>
{
public:
explicit
LeMatcher
(
const
Rhs
&
rhs
)
:
ComparisonBase
<
LeMatcher
<
Rhs
>
,
Rhs
,
AnyLe
>
(
rhs
)
{
}
:
ComparisonBase
<
LeMatcher
<
Rhs
>
,
Rhs
,
AnyLe
>
(
rhs
)
{}
static
const
char
*
Desc
()
{
return
"is <="
;
}
static
const
char
*
NegatedDesc
()
{
return
"isn't <="
;
}
};
...
...
@@ -785,7 +796,7 @@ template <typename Rhs>
class
GeMatcher
:
public
ComparisonBase
<
GeMatcher
<
Rhs
>
,
Rhs
,
AnyGe
>
{
public:
explicit
GeMatcher
(
const
Rhs
&
rhs
)
:
ComparisonBase
<
GeMatcher
<
Rhs
>
,
Rhs
,
AnyGe
>
(
rhs
)
{
}
:
ComparisonBase
<
GeMatcher
<
Rhs
>
,
Rhs
,
AnyGe
>
(
rhs
)
{}
static
const
char
*
Desc
()
{
return
"is >="
;
}
static
const
char
*
NegatedDesc
()
{
return
"isn't >="
;
}
};
...
...
@@ -876,12 +887,16 @@ PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
// Note: if the parameter of Eq() were declared as const T&, Eq("foo")
// wouldn't compile.
template
<
typename
T
>
inline
internal
::
EqMatcher
<
T
>
Eq
(
T
x
)
{
return
internal
::
EqMatcher
<
T
>
(
x
);
}
inline
internal
::
EqMatcher
<
T
>
Eq
(
T
x
)
{
return
internal
::
EqMatcher
<
T
>
(
x
);
}
// Constructs a Matcher<T> from a 'value' of type T. The constructed
// matcher matches any value that's equal to 'value'.
template
<
typename
T
>
Matcher
<
T
>::
Matcher
(
T
value
)
{
*
this
=
Eq
(
value
);
}
Matcher
<
T
>::
Matcher
(
T
value
)
{
*
this
=
Eq
(
value
);
}
// Creates a monomorphic matcher that matches anything with type Lhs
// and equal to rhs. A user may need to use this instead of Eq(...)
...
...
@@ -896,7 +911,9 @@ Matcher<T>::Matcher(T value) { *this = Eq(value); }
// can always write Matcher<T>(Lt(5)) to be explicit about the type,
// for example.
template
<
typename
Lhs
,
typename
Rhs
>
inline
Matcher
<
Lhs
>
TypedEq
(
const
Rhs
&
rhs
)
{
return
Eq
(
rhs
);
}
inline
Matcher
<
Lhs
>
TypedEq
(
const
Rhs
&
rhs
)
{
return
Eq
(
rhs
);
}
// Creates a polymorphic matcher that matches anything >= x.
template
<
typename
Rhs
>
...
...
googletest/include/gtest/gtest-message.h
View file @
9e712372
...
...
@@ -111,8 +111,8 @@ class GTEST_API_ Message {
// Streams a non-pointer value to this object.
template
<
typename
T
>
inline
Message
&
operator
<<
(
const
T
&
val
)
{
// Some libraries overload << for STL containers. These
inline
Message
&
operator
<<
(
const
T
&
val
)
{
// Some libraries overload << for STL containers. These
// overloads are defined in the global namespace instead of ::std.
//
// C++'s symbol lookup rule (i.e. Koenig lookup) says that these
...
...
@@ -126,7 +126,7 @@ class GTEST_API_ Message {
// from the global namespace. With this using declaration,
// overloads of << defined in the global namespace and those
// visible via Koenig lookup are both exposed in this function.
using
::
operator
<<
;
using
::
operator
<<
;
*
ss_
<<
val
;
return
*
this
;
}
...
...
@@ -145,7 +145,7 @@ class GTEST_API_ Message {
// ensure consistent result across compilers, we always treat NULL
// as "(null)".
template
<
typename
T
>
inline
Message
&
operator
<<
(
T
*
const
&
pointer
)
{
// NOLINT
inline
Message
&
operator
<<
(
T
*
const
&
pointer
)
{
// NOLINT
if
(
pointer
==
nullptr
)
{
*
ss_
<<
"(null)"
;
}
else
{
...
...
@@ -160,25 +160,23 @@ class GTEST_API_ Message {
// templatized version above. Without this definition, streaming
// endl or other basic IO manipulators to Message will confuse the
// compiler.
Message
&
operator
<<
(
BasicNarrowIoManip
val
)
{
Message
&
operator
<<
(
BasicNarrowIoManip
val
)
{
*
ss_
<<
val
;
return
*
this
;
}
// Instead of 1/0, we want to see true/false for bool values.
Message
&
operator
<<
(
bool
b
)
{
return
*
this
<<
(
b
?
"true"
:
"false"
);
}
Message
&
operator
<<
(
bool
b
)
{
return
*
this
<<
(
b
?
"true"
:
"false"
);
}
// These two overloads allow streaming a wide C string to a Message
// using the UTF-8 encoding.
Message
&
operator
<<
(
const
wchar_t
*
wide_c_str
);
Message
&
operator
<<
(
wchar_t
*
wide_c_str
);
Message
&
operator
<<
(
const
wchar_t
*
wide_c_str
);
Message
&
operator
<<
(
wchar_t
*
wide_c_str
);
#if GTEST_HAS_STD_WSTRING
// Converts the given wide string to a narrow string using the UTF-8
// encoding, and streams the result to this Message object.
Message
&
operator
<<
(
const
::
std
::
wstring
&
wstr
);
Message
&
operator
<<
(
const
::
std
::
wstring
&
wstr
);
#endif // GTEST_HAS_STD_WSTRING
// Gets the text streamed to this object so far as an std::string.
...
...
@@ -197,7 +195,7 @@ class GTEST_API_ Message {
};
// Streams a Message to an ostream.
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Message
&
sb
)
{
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Message
&
sb
)
{
return
os
<<
sb
.
GetString
();
}
...
...
googletest/include/gtest/gtest-param-test.h
View file @
9e712372
...
...
@@ -356,9 +356,7 @@ internal::ValueArray<T...> Values(T... v) {
// }
// INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool());
//
inline
internal
::
ParamGenerator
<
bool
>
Bool
()
{
return
Values
(
false
,
true
);
}
inline
internal
::
ParamGenerator
<
bool
>
Bool
()
{
return
Values
(
false
,
true
);
}
// Combine() allows the user to combine two or more sequences to produce
// values of a Cartesian product of those sequences' elements.
...
...
@@ -456,43 +454,42 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) {
#define GTEST_GET_FIRST_(first, ...) first
#define GTEST_GET_SECOND_(first, second, ...) second
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...)
\
static ::testing::internal::ParamGenerator<test_suite_name::ParamType>
\
gtest_##prefix##test_suite_name##_EvalGenerator_() {
\
return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_));
\
}
\
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_(
\
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) {
\
if (::testing::internal::AlwaysFalse()) {
\
::testing::internal::TestNotEmpty(GTEST_EXPAND_(GTEST_GET_SECOND_(
\
__VA_ARGS__,
\
::testing::internal::DefaultParamName<test_suite_name::ParamType>,
\
DUMMY_PARAM_)));
\
auto t = std::make_tuple(__VA_ARGS__);
\
static_assert(std::tuple_size<decltype(t)>::value <= 2,
\
"Too Many Args!");
\
}
\
return ((GTEST_EXPAND_(GTEST_GET_SECOND_(
\
__VA_ARGS__,
\
::testing::internal::DefaultParamName<test_suite_name::ParamType>,
\
DUMMY_PARAM_))))(info);
\
}
\
static int gtest_##prefix##test_suite_name##_dummy_
\
GTEST_ATTRIBUTE_UNUSED_ =
\
::testing::UnitTest::GetInstance()
\
->parameterized_test_registry()
\
.GetTestSuitePatternHolder<test_suite_name>(
\
GTEST_STRINGIFY_(test_suite_name),
\
::testing::internal::CodeLocation(__FILE__, __LINE__))
\
->AddTestSuiteInstantiation(
\
GTEST_STRINGIFY_(prefix),
\
>est_##prefix##test_suite_name##_EvalGenerator_,
\
>est_##prefix##test_suite_name##_EvalGenerateName_,
\
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
gtest_##prefix##test_suite_name##_EvalGenerator_() { \
return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \
} \
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
if (::testing::internal::AlwaysFalse()) { \
::testing::internal::TestNotEmpty(GTEST_EXPAND_(GTEST_GET_SECOND_( \
__VA_ARGS__, \
::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
DUMMY_PARAM_))); \
auto t = std::make_tuple(__VA_ARGS__); \
static_assert(std::tuple_size<decltype(t)>::value <= 2, \
"Too Many Args!"); \
} \
return ((GTEST_EXPAND_(GTEST_GET_SECOND_( \
__VA_ARGS__, \
::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
DUMMY_PARAM_))))(info); \
} \
static int gtest_##prefix##test_suite_name##_dummy_ \
GTEST_ATTRIBUTE_UNUSED_ = \
::testing::UnitTest::GetInstance() \
->parameterized_test_registry() \
.GetTestSuitePatternHolder<test_suite_name>( \
GTEST_STRINGIFY_(test_suite_name), \
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
->AddTestSuiteInstantiation( \
GTEST_STRINGIFY_(prefix), \
>est_##prefix##test_suite_name##_EvalGenerator_, \
>est_##prefix##test_suite_name##_EvalGenerateName_, \
__FILE__, __LINE__)
// Allow Marking a Parameterized test class as not needing to be instantiated.
#define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T)
\
#define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T) \
namespace gtest_do_not_use_outside_namespace_scope {} \
static const ::testing::internal::MarkAsIgnored gtest_allow_ignore_##T( \
GTEST_STRINGIFY_(T))
...
...
googletest/include/gtest/gtest-printers.h
View file @
9e712372
...
...
@@ -258,12 +258,10 @@ struct ConvertibleToStringViewPrinter {
#endif
};
// Prints the given number of bytes in the given object to the given
// ostream.
GTEST_API_
void
PrintBytesInObjectTo
(
const
unsigned
char
*
obj_bytes
,
size_t
count
,
::
std
::
ostream
*
os
);
size_t
count
,
::
std
::
ostream
*
os
);
struct
RawBytesPrinter
{
// SFINAE on `sizeof` to make sure we have a complete type.
template
<
typename
T
,
size_t
=
sizeof
(
T
)
>
...
...
@@ -376,12 +374,12 @@ GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char32_t);
// to point to a NUL-terminated string, and thus can print it as a string.
#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
template <> \
class FormatForComparison<CharType*, OtherStringType> { \
public: \
static ::std::string Format(CharType* value) { \
return ::testing::PrintToString(value); \
} \
template <>
\
class FormatForComparison<CharType*, OtherStringType> {
\
public:
\
static ::std::string Format(CharType* value) {
\
return ::testing::PrintToString(value);
\
}
\
}
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
(
char
,
::
std
::
string
);
...
...
@@ -411,8 +409,8 @@ GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
//
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
template
<
typename
T1
,
typename
T2
>
std
::
string
FormatForComparisonFailureMessage
(
const
T1
&
value
,
const
T2
&
/* other_operand */
)
{
std
::
string
FormatForComparisonFailureMessage
(
const
T1
&
value
,
const
T2
&
/* other_operand */
)
{
return
FormatForComparison
<
T1
,
T2
>::
Format
(
value
);
}
...
...
@@ -552,7 +550,7 @@ void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {
}
// Overloads for ::std::string.
GTEST_API_
void
PrintStringTo
(
const
::
std
::
string
&
s
,
::
std
::
ostream
*
os
);
GTEST_API_
void
PrintStringTo
(
const
::
std
::
string
&
s
,
::
std
::
ostream
*
os
);
inline
void
PrintTo
(
const
::
std
::
string
&
s
,
::
std
::
ostream
*
os
)
{
PrintStringTo
(
s
,
os
);
}
...
...
@@ -579,7 +577,7 @@ inline void PrintTo(const ::std::u32string& s, ::std::ostream* os) {
// Overloads for ::std::wstring.
#if GTEST_HAS_STD_WSTRING
GTEST_API_
void
PrintWideStringTo
(
const
::
std
::
wstring
&
s
,
::
std
::
ostream
*
os
);
GTEST_API_
void
PrintWideStringTo
(
const
::
std
::
wstring
&
s
,
::
std
::
ostream
*
os
);
inline
void
PrintTo
(
const
::
std
::
wstring
&
s
,
::
std
::
ostream
*
os
)
{
PrintWideStringTo
(
s
,
os
);
}
...
...
@@ -823,8 +821,8 @@ void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
}
}
// This overload prints a (const) char array compactly.
GTEST_API_
void
UniversalPrintArray
(
const
char
*
begin
,
size_t
len
,
::
std
::
ostream
*
os
);
GTEST_API_
void
UniversalPrintArray
(
const
char
*
begin
,
size_t
len
,
::
std
::
ostream
*
os
);
#ifdef __cpp_char8_t
// This overload prints a (const) char8_t array compactly.
...
...
@@ -841,8 +839,8 @@ GTEST_API_ void UniversalPrintArray(const char32_t* begin, size_t len,
::
std
::
ostream
*
os
);
// This overload prints a (const) wchar_t array compactly.
GTEST_API_
void
UniversalPrintArray
(
const
wchar_t
*
begin
,
size_t
len
,
::
std
::
ostream
*
os
);
GTEST_API_
void
UniversalPrintArray
(
const
wchar_t
*
begin
,
size_t
len
,
::
std
::
ostream
*
os
);
// Implements printing an array type T[N].
template
<
typename
T
,
size_t
N
>
...
...
@@ -1001,10 +999,10 @@ void UniversalPrint(const T& value, ::std::ostream* os) {
UniversalPrinter
<
T1
>::
Print
(
value
,
os
);
}
typedef
::
std
::
vector
<
::
std
::
string
>
Strings
;
typedef
::
std
::
vector
<::
std
::
string
>
Strings
;
// Tersely prints the first N fields of a tuple to a string vector,
// one element for each field.
// Tersely prints the first N fields of a tuple to a string vector,
// one element for each field.
template
<
typename
Tuple
>
void
TersePrintPrefixToStrings
(
const
Tuple
&
,
std
::
integral_constant
<
size_t
,
0
>
,
Strings
*
)
{}
...
...
Prev
1
2
3
4
5
6
7
Next
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