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
844fa949
Commit
844fa949
authored
Mar 01, 2013
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implements NaggyMock.
parent
a31d9ce2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
302 additions
and
81 deletions
+302
-81
gmock-generated-nice-strict.h
include/gmock/gmock-generated-nice-strict.h
+140
-17
gmock-generated-nice-strict.h.pump
include/gmock/gmock-generated-nice-strict.h.pump
+59
-58
gmock-spec-builders.h
include/gmock/gmock-spec-builders.h
+3
-0
gmock-nice-strict_test.cc
test/gmock-nice-strict_test.cc
+100
-6
No files found.
include/gmock/gmock-generated-nice-strict.h
View file @
844fa949
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
// This file was GENERATED by command:
// pump.py gmock-generated-nice-strict.h.pump
// DO NOT EDIT BY HAND!!!
// Copyright 2008, Google Inc.
// Copyright 2008, Google Inc.
// All rights reserved.
// All rights reserved.
...
@@ -31,26 +33,36 @@
...
@@ -31,26 +33,36 @@
//
//
// Author: wan@google.com (Zhanyong Wan)
// Author: wan@google.com (Zhanyong Wan)
// Implements class templates NiceMock and StrictMock.
// Implements class templates NiceMock
, NaggyMock,
and StrictMock.
//
//
// Given a mock class MockFoo that is created using Google Mock,
// Given a mock class MockFoo that is created using Google Mock,
// NiceMock<MockFoo> is a subclass of MockFoo that allows
// NiceMock<MockFoo> is a subclass of MockFoo that allows
// uninteresting calls (i.e. calls to mock methods that have no
// uninteresting calls (i.e. calls to mock methods that have no
// EXPECT_CALL specs), and StrictMock<MockFoo> is a subclass of
// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
// MockFoo that treats all uninteresting calls as errors.
// that prints a warning when an uninteresting call occurs, and
// StrictMock<MockFoo> is a subclass of MockFoo that treats all
// uninteresting calls as errors.
//
//
// NiceMock and StrictMock "inherits" the constructors of their
// Currently a mock is naggy by default, so MockFoo and
// respective base class, with up-to 10 arguments. Therefore you can
// NaggyMock<MockFoo> behave like the same. However, we will soon
// write NiceMock<MockFoo>(5, "a") to construct a nice mock where
// switch the default behavior of mocks to be nice, as that in general
// MockFoo has a constructor that accepts (int, const char*), for
// leads to more maintainable tests. When that happens, MockFoo will
// example.
// stop behaving like NaggyMock<MockFoo> and start behaving like
// NiceMock<MockFoo>.
//
//
// A known limitation is that NiceMock<MockFoo> and
// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
// StrictMock<MockFoo> only works for mock methods defined using the
// their respective base class, with up-to 10 arguments. Therefore
// MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. If a
// you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
// mock method is defined in a base class of MockFoo, the "nice" or
// where MockFoo has a constructor that accepts (int, const char*),
// "strict" modifier may not affect it, depending on the compiler. In
// for example.
// particular, nesting NiceMock and StrictMock is NOT supported.
//
// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
// and StrictMock<MockFoo> only works for mock methods defined using
// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
// If a mock method is defined in a base class of MockFoo, the "nice"
// or "strict" modifier may not affect it, depending on the compiler.
// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
// supported.
//
//
// Another known limitation is that the constructors of the base mock
// Another known limitation is that the constructors of the base mock
// cannot have arguments passed by non-const reference, which are
// cannot have arguments passed by non-const reference, which are
...
@@ -161,6 +173,102 @@ class NiceMock : public MockClass {
...
@@ -161,6 +173,102 @@ class NiceMock : public MockClass {
};
};
template
<
class
MockClass
>
template
<
class
MockClass
>
class
NaggyMock
:
public
MockClass
{
public
:
// We don't factor out the constructor body to a common method, as
// we have to avoid a possible clash with members of MockClass.
NaggyMock
()
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
// C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it for each arity.
template
<
typename
A1
>
explicit
NaggyMock
(
const
A1
&
a1
)
:
MockClass
(
a1
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
,
typename
A2
>
NaggyMock
(
const
A1
&
a1
,
const
A2
&
a2
)
:
MockClass
(
a1
,
a2
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
,
typename
A2
,
typename
A3
>
NaggyMock
(
const
A1
&
a1
,
const
A2
&
a2
,
const
A3
&
a3
)
:
MockClass
(
a1
,
a2
,
a3
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
,
typename
A2
,
typename
A3
,
typename
A4
>
NaggyMock
(
const
A1
&
a1
,
const
A2
&
a2
,
const
A3
&
a3
,
const
A4
&
a4
)
:
MockClass
(
a1
,
a2
,
a3
,
a4
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
,
typename
A2
,
typename
A3
,
typename
A4
,
typename
A5
>
NaggyMock
(
const
A1
&
a1
,
const
A2
&
a2
,
const
A3
&
a3
,
const
A4
&
a4
,
const
A5
&
a5
)
:
MockClass
(
a1
,
a2
,
a3
,
a4
,
a5
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
,
typename
A2
,
typename
A3
,
typename
A4
,
typename
A5
,
typename
A6
>
NaggyMock
(
const
A1
&
a1
,
const
A2
&
a2
,
const
A3
&
a3
,
const
A4
&
a4
,
const
A5
&
a5
,
const
A6
&
a6
)
:
MockClass
(
a1
,
a2
,
a3
,
a4
,
a5
,
a6
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
,
typename
A2
,
typename
A3
,
typename
A4
,
typename
A5
,
typename
A6
,
typename
A7
>
NaggyMock
(
const
A1
&
a1
,
const
A2
&
a2
,
const
A3
&
a3
,
const
A4
&
a4
,
const
A5
&
a5
,
const
A6
&
a6
,
const
A7
&
a7
)
:
MockClass
(
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
a7
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
,
typename
A2
,
typename
A3
,
typename
A4
,
typename
A5
,
typename
A6
,
typename
A7
,
typename
A8
>
NaggyMock
(
const
A1
&
a1
,
const
A2
&
a2
,
const
A3
&
a3
,
const
A4
&
a4
,
const
A5
&
a5
,
const
A6
&
a6
,
const
A7
&
a7
,
const
A8
&
a8
)
:
MockClass
(
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
a7
,
a8
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
,
typename
A2
,
typename
A3
,
typename
A4
,
typename
A5
,
typename
A6
,
typename
A7
,
typename
A8
,
typename
A9
>
NaggyMock
(
const
A1
&
a1
,
const
A2
&
a2
,
const
A3
&
a3
,
const
A4
&
a4
,
const
A5
&
a5
,
const
A6
&
a6
,
const
A7
&
a7
,
const
A8
&
a8
,
const
A9
&
a9
)
:
MockClass
(
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
a7
,
a8
,
a9
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
,
typename
A2
,
typename
A3
,
typename
A4
,
typename
A5
,
typename
A6
,
typename
A7
,
typename
A8
,
typename
A9
,
typename
A10
>
NaggyMock
(
const
A1
&
a1
,
const
A2
&
a2
,
const
A3
&
a3
,
const
A4
&
a4
,
const
A5
&
a5
,
const
A6
&
a6
,
const
A7
&
a7
,
const
A8
&
a8
,
const
A9
&
a9
,
const
A10
&
a10
)
:
MockClass
(
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
a7
,
a8
,
a9
,
a10
)
{
::
testing
::
Mock
::
WarnUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
virtual
~
NaggyMock
()
{
::
testing
::
Mock
::
UnregisterCallReaction
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
private
:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
NaggyMock
);
};
template
<
class
MockClass
>
class
StrictMock
:
public
MockClass
{
class
StrictMock
:
public
MockClass
{
public
:
public
:
// We don't factor out the constructor body to a common method, as
// We don't factor out the constructor body to a common method, as
...
@@ -170,6 +278,8 @@ class StrictMock : public MockClass {
...
@@ -170,6 +278,8 @@ class StrictMock : public MockClass {
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
}
// C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it for each arity.
template
<
typename
A1
>
template
<
typename
A1
>
explicit
StrictMock
(
const
A1
&
a1
)
:
MockClass
(
a1
)
{
explicit
StrictMock
(
const
A1
&
a1
)
:
MockClass
(
a1
)
{
::
testing
::
Mock
::
FailUninterestingCalls
(
::
testing
::
Mock
::
FailUninterestingCalls
(
...
@@ -258,15 +368,28 @@ class StrictMock : public MockClass {
...
@@ -258,15 +368,28 @@ class StrictMock : public MockClass {
// user errors of nesting nice and strict mocks. They do NOT catch
// user errors of nesting nice and strict mocks. They do NOT catch
// all possible errors.
// all possible errors.
// These specializations are declared but not defined, as NiceMock and
// These specializations are declared but not defined, as NiceMock,
// StrictMock cannot be nested.
// NaggyMock, and StrictMock cannot be nested.
template
<
typename
MockClass
>
template
<
typename
MockClass
>
class
NiceMock
<
NiceMock
<
MockClass
>
>
;
class
NiceMock
<
NiceMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
template
<
typename
MockClass
>
class
NiceMock
<
NaggyMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
NiceMock
<
StrictMock
<
MockClass
>
>
;
class
NiceMock
<
StrictMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
NaggyMock
<
NiceMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
NaggyMock
<
NaggyMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
NaggyMock
<
StrictMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
template
<
typename
MockClass
>
class
StrictMock
<
NiceMock
<
MockClass
>
>
;
class
StrictMock
<
NiceMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
template
<
typename
MockClass
>
class
StrictMock
<
NaggyMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
StrictMock
<
StrictMock
<
MockClass
>
>
;
class
StrictMock
<
StrictMock
<
MockClass
>
>
;
}
// namespace testing
}
// namespace testing
...
...
include/gmock/gmock-generated-nice-strict.h.pump
View file @
844fa949
...
@@ -34,26 +34,36 @@ $var n = 10 $$ The maximum arity we support.
...
@@ -34,26 +34,36 @@ $var n = 10 $$ The maximum arity we support.
//
//
// Author: wan@google.com (Zhanyong Wan)
// Author: wan@google.com (Zhanyong Wan)
// Implements class templates NiceMock and StrictMock.
// Implements class templates NiceMock
, NaggyMock,
and StrictMock.
//
//
// Given a mock class MockFoo that is created using Google Mock,
// Given a mock class MockFoo that is created using Google Mock,
// NiceMock<MockFoo> is a subclass of MockFoo that allows
// NiceMock<MockFoo> is a subclass of MockFoo that allows
// uninteresting calls (i.e. calls to mock methods that have no
// uninteresting calls (i.e. calls to mock methods that have no
// EXPECT_CALL specs), and StrictMock<MockFoo> is a subclass of
// EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
// MockFoo that treats all uninteresting calls as errors.
// that prints a warning when an uninteresting call occurs, and
// StrictMock<MockFoo> is a subclass of MockFoo that treats all
// uninteresting calls as errors.
//
//
// NiceMock and StrictMock "inherits" the constructors of their
// Currently a mock is naggy by default, so MockFoo and
// respective base class, with up-to $n arguments. Therefore you can
// NaggyMock<MockFoo> behave like the same. However, we will soon
// write NiceMock<MockFoo>(5, "a") to construct a nice mock where
// switch the default behavior of mocks to be nice, as that in general
// MockFoo has a constructor that accepts (int, const char*), for
// leads to more maintainable tests. When that happens, MockFoo will
// example.
// stop behaving like NaggyMock<MockFoo> and start behaving like
// NiceMock<MockFoo>.
//
//
// A known limitation is that NiceMock<MockFoo> and
// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
// StrictMock<MockFoo> only works for mock methods defined using the
// their respective base class, with up-to $n arguments. Therefore
// MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. If a
// you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
// mock method is defined in a base class of MockFoo, the "nice" or
// where MockFoo has a constructor that accepts (int, const char*),
// "strict" modifier may not affect it, depending on the compiler. In
// for example.
// particular, nesting NiceMock and StrictMock is NOT supported.
//
// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
// and StrictMock<MockFoo> only works for mock methods defined using
// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
// If a mock method is defined in a base class of MockFoo, the "nice"
// or "strict" modifier may not affect it, depending on the compiler.
// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
// supported.
//
//
// Another known limitation is that the constructors of the base mock
// Another known limitation is that the constructors of the base mock
// cannot have arguments passed by non-const reference, which are
// cannot have arguments passed by non-const reference, which are
...
@@ -67,21 +77,32 @@ $var n = 10 $$ The maximum arity we support.
...
@@ -67,21 +77,32 @@ $var n = 10 $$ The maximum arity we support.
namespace
testing
{
namespace
testing
{
$
range
kind
0..2
$
for
kind
[[
$
var
clazz
=
[[
$
if
kind
==
0
[[
NiceMock
]]
$
elif
kind
==
1
[[
NaggyMock
]]
$
else
[[
StrictMock
]]]]
$
var
method
=
[[
$
if
kind
==
0
[[
AllowUninterestingCalls
]]
$
elif
kind
==
1
[[
WarnUninterestingCalls
]]
$
else
[[
FailUninterestingCalls
]]]]
template
<
class
MockClass
>
template
<
class
MockClass
>
class
NiceMock
:
public
MockClass
{
class
$
clazz
:
public
MockClass
{
public
:
public
:
// We don't factor out the constructor body to a common method, as
// We don't factor out the constructor body to a common method, as
// we have to avoid a possible clash with members of MockClass.
// we have to avoid a possible clash with members of MockClass.
NiceMock
()
{
$
clazz
()
{
::
testing
::
Mock
::
AllowUninterestingCalls
(
::
testing
::
Mock
::
$
method
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
}
// C++ doesn't (yet) allow inheritance of constructors, so we have
// C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it for each arity.
// to define it for each arity.
template
<
typename
A1
>
template
<
typename
A1
>
explicit
NiceMock
(
const
A1
&
a1
)
:
MockClass
(
a1
)
{
explicit
$
clazz
(
const
A1
&
a1
)
:
MockClass
(
a1
)
{
::
testing
::
Mock
::
AllowUninterestingCalls
(
::
testing
::
Mock
::
$
method
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
}
...
@@ -89,70 +110,50 @@ $range i 2..n
...
@@ -89,70 +110,50 @@ $range i 2..n
$
for
i
[[
$
for
i
[[
$
range
j
1.
.
i
$
range
j
1.
.
i
template
<
$
for
j
,
[[
typename
A
$
j
]]
>
template
<
$
for
j
,
[[
typename
A
$
j
]]
>
NiceMock
(
$
for
j
,
[[
const
A
$
j
&
a
$
j
]])
:
MockClass
(
$
for
j
,
[[
a
$
j
]])
{
$
clazz
(
$
for
j
,
[[
const
A
$
j
&
a
$
j
]])
:
MockClass
(
$
for
j
,
[[
a
$
j
]])
{
::
testing
::
Mock
::
AllowUninterestingCalls
(
::
testing
::
Mock
::
$
method
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
}
]]
]]
virtual
~
NiceMock
()
{
virtual
~
$
clazz
()
{
::
testing
::
Mock
::
UnregisterCallReaction
(
::
testing
::
Mock
::
UnregisterCallReaction
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
}
private
:
private
:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
NiceMock
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
$
clazz
);
};
};
template
<
class
MockClass
>
class
StrictMock
:
public
MockClass
{
public
:
// We don't factor out the constructor body to a common method, as
// we have to avoid a possible clash with members of MockClass.
StrictMock
()
{
::
testing
::
Mock
::
FailUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
template
<
typename
A1
>
explicit
StrictMock
(
const
A1
&
a1
)
:
MockClass
(
a1
)
{
::
testing
::
Mock
::
FailUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
$
for
i
[[
$
range
j
1.
.
i
template
<
$
for
j
,
[[
typename
A
$
j
]]
>
StrictMock
(
$
for
j
,
[[
const
A
$
j
&
a
$
j
]])
:
MockClass
(
$
for
j
,
[[
a
$
j
]])
{
::
testing
::
Mock
::
FailUninterestingCalls
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
]]
]]
virtual
~
StrictMock
()
{
::
testing
::
Mock
::
UnregisterCallReaction
(
internal
::
ImplicitCast_
<
MockClass
*>
(
this
));
}
private
:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
StrictMock
);
};
// The following specializations catch some (relatively more common)
// The following specializations catch some (relatively more common)
// user errors of nesting nice and strict mocks. They do NOT catch
// user errors of nesting nice and strict mocks. They do NOT catch
// all possible errors.
// all possible errors.
// These specializations are declared but not defined, as NiceMock and
// These specializations are declared but not defined, as NiceMock,
// StrictMock cannot be nested.
// NaggyMock, and StrictMock cannot be nested.
template
<
typename
MockClass
>
template
<
typename
MockClass
>
class
NiceMock
<
NiceMock
<
MockClass
>
>
;
class
NiceMock
<
NiceMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
template
<
typename
MockClass
>
class
NiceMock
<
NaggyMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
NiceMock
<
StrictMock
<
MockClass
>
>
;
class
NiceMock
<
StrictMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
NaggyMock
<
NiceMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
NaggyMock
<
NaggyMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
NaggyMock
<
StrictMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
template
<
typename
MockClass
>
class
StrictMock
<
NiceMock
<
MockClass
>
>
;
class
StrictMock
<
NiceMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
template
<
typename
MockClass
>
class
StrictMock
<
NaggyMock
<
MockClass
>
>
;
template
<
typename
MockClass
>
class
StrictMock
<
StrictMock
<
MockClass
>
>
;
class
StrictMock
<
StrictMock
<
MockClass
>
>
;
}
// namespace testing
}
// namespace testing
...
...
include/gmock/gmock-spec-builders.h
View file @
844fa949
...
@@ -400,6 +400,9 @@ class GTEST_API_ Mock {
...
@@ -400,6 +400,9 @@ class GTEST_API_ Mock {
friend
class
NiceMock
;
friend
class
NiceMock
;
template
<
typename
M
>
template
<
typename
M
>
friend
class
NaggyMock
;
template
<
typename
M
>
friend
class
StrictMock
;
friend
class
StrictMock
;
// Tells Google Mock to allow uninteresting calls on the given mock
// Tells Google Mock to allow uninteresting calls on the given mock
...
...
test/gmock-nice-strict_test.cc
View file @
844fa949
...
@@ -54,6 +54,7 @@ namespace gmock_nice_strict_test {
...
@@ -54,6 +54,7 @@ namespace gmock_nice_strict_test {
using
testing
::
internal
::
string
;
using
testing
::
internal
::
string
;
using
testing
::
GMOCK_FLAG
(
verbose
);
using
testing
::
GMOCK_FLAG
(
verbose
);
using
testing
::
HasSubstr
;
using
testing
::
HasSubstr
;
using
testing
::
NaggyMock
;
using
testing
::
NiceMock
;
using
testing
::
NiceMock
;
using
testing
::
StrictMock
;
using
testing
::
StrictMock
;
...
@@ -116,7 +117,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCall) {
...
@@ -116,7 +117,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCall) {
CaptureStdout
();
CaptureStdout
();
nice_foo
.
DoThis
();
nice_foo
.
DoThis
();
nice_foo
.
DoThat
(
true
);
nice_foo
.
DoThat
(
true
);
EXPECT_
STREQ
(
""
,
GetCapturedStdout
().
c_str
());
EXPECT_
EQ
(
""
,
GetCapturedStdout
());
}
}
// Tests that a nice mock generates no warning for uninteresting calls
// Tests that a nice mock generates no warning for uninteresting calls
...
@@ -129,7 +130,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
...
@@ -129,7 +130,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
CaptureStdout
();
CaptureStdout
();
nice_foo
->
DoThis
();
nice_foo
->
DoThis
();
EXPECT_
STREQ
(
""
,
GetCapturedStdout
().
c_str
());
EXPECT_
EQ
(
""
,
GetCapturedStdout
());
}
}
// Tests that a nice mock generates informational logs for
// Tests that a nice mock generates informational logs for
...
@@ -141,12 +142,12 @@ TEST(NiceMockTest, InfoForUninterestingCall) {
...
@@ -141,12 +142,12 @@ TEST(NiceMockTest, InfoForUninterestingCall) {
GMOCK_FLAG
(
verbose
)
=
"info"
;
GMOCK_FLAG
(
verbose
)
=
"info"
;
CaptureStdout
();
CaptureStdout
();
nice_foo
.
DoThis
();
nice_foo
.
DoThis
();
EXPECT_THAT
(
std
::
string
(
GetCapturedStdout
()
),
EXPECT_THAT
(
GetCapturedStdout
(
),
HasSubstr
(
"Uninteresting mock function call"
));
HasSubstr
(
"Uninteresting mock function call"
));
CaptureStdout
();
CaptureStdout
();
nice_foo
.
DoThat
(
true
);
nice_foo
.
DoThat
(
true
);
EXPECT_THAT
(
std
::
string
(
GetCapturedStdout
()
),
EXPECT_THAT
(
GetCapturedStdout
(
),
HasSubstr
(
"Uninteresting mock function call"
));
HasSubstr
(
"Uninteresting mock function call"
));
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
}
}
...
@@ -192,7 +193,7 @@ TEST(NiceMockTest, NonDefaultConstructor10) {
...
@@ -192,7 +193,7 @@ TEST(NiceMockTest, NonDefaultConstructor10) {
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that NiceMock<Mock> compiles where Mock is a user-defined
// Tests that NiceMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to workaround an
// class (as opposed to ::testing::Mock). We had to work
around an
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// NiceMock to be looked up in the wrong context, and this test
// NiceMock to be looked up in the wrong context, and this test
// ensures that our fix works.
// ensures that our fix works.
...
@@ -206,6 +207,99 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
...
@@ -206,6 +207,99 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
}
}
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
#if GTEST_HAS_STREAM_REDIRECTION
// Tests that a naggy mock generates warnings for uninteresting calls.
TEST
(
NaggyMockTest
,
WarningForUninterestingCall
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
"warning"
;
NaggyMock
<
MockFoo
>
naggy_foo
;
CaptureStdout
();
naggy_foo
.
DoThis
();
naggy_foo
.
DoThat
(
true
);
EXPECT_THAT
(
GetCapturedStdout
(),
HasSubstr
(
"Uninteresting mock function call"
));
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
}
// Tests that a naggy mock generates a warning for an uninteresting call
// that deletes the mock object.
TEST
(
NaggyMockTest
,
WarningForUninterestingCallAfterDeath
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
"warning"
;
NaggyMock
<
MockFoo
>*
const
naggy_foo
=
new
NaggyMock
<
MockFoo
>
;
ON_CALL
(
*
naggy_foo
,
DoThis
())
.
WillByDefault
(
Invoke
(
naggy_foo
,
&
MockFoo
::
Delete
));
CaptureStdout
();
naggy_foo
->
DoThis
();
EXPECT_THAT
(
GetCapturedStdout
(),
HasSubstr
(
"Uninteresting mock function call"
));
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
}
#endif // GTEST_HAS_STREAM_REDIRECTION
// Tests that a naggy mock allows expected calls.
TEST
(
NaggyMockTest
,
AllowsExpectedCall
)
{
NaggyMock
<
MockFoo
>
naggy_foo
;
EXPECT_CALL
(
naggy_foo
,
DoThis
());
naggy_foo
.
DoThis
();
}
// Tests that an unexpected call on a naggy mock fails.
TEST
(
NaggyMockTest
,
UnexpectedCallFails
)
{
NaggyMock
<
MockFoo
>
naggy_foo
;
EXPECT_CALL
(
naggy_foo
,
DoThis
()).
Times
(
0
);
EXPECT_NONFATAL_FAILURE
(
naggy_foo
.
DoThis
(),
"called more times than expected"
);
}
// Tests that NaggyMock works with a mock class that has a non-default
// constructor.
TEST
(
NaggyMockTest
,
NonDefaultConstructor
)
{
NaggyMock
<
MockBar
>
naggy_bar
(
"hi"
);
EXPECT_EQ
(
"hi"
,
naggy_bar
.
str
());
naggy_bar
.
This
();
naggy_bar
.
That
(
5
,
true
);
}
// 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
);
EXPECT_EQ
(
"01234567TF"
,
naggy_bar
.
str
());
naggy_bar
.
This
();
naggy_bar
.
That
(
5
,
true
);
}
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that NaggyMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// NaggyMock to be looked up in the wrong context, and this test
// ensures that our fix works.
//
// We have to skip this test on Symbian and Windows Mobile, as it
// causes the program to crash there, for reasons unclear to us yet.
TEST
(
NaggyMockTest
,
AcceptsClassNamedMock
)
{
NaggyMock
<
::
Mock
>
naggy
;
EXPECT_CALL
(
naggy
,
DoThis
());
naggy
.
DoThis
();
}
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that a strict mock allows expected calls.
// Tests that a strict mock allows expected calls.
TEST
(
StrictMockTest
,
AllowsExpectedCall
)
{
TEST
(
StrictMockTest
,
AllowsExpectedCall
)
{
StrictMock
<
MockFoo
>
strict_foo
;
StrictMock
<
MockFoo
>
strict_foo
;
...
@@ -266,7 +360,7 @@ TEST(StrictMockTest, NonDefaultConstructor10) {
...
@@ -266,7 +360,7 @@ TEST(StrictMockTest, NonDefaultConstructor10) {
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that StrictMock<Mock> compiles where Mock is a user-defined
// Tests that StrictMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to workaround an
// class (as opposed to ::testing::Mock). We had to work
around an
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// StrictMock to be looked up in the wrong context, and this test
// StrictMock to be looked up in the wrong context, and this test
// ensures that our fix works.
// ensures that our fix works.
...
...
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