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
8c82ba48
Unverified
Commit
8c82ba48
authored
Oct 16, 2018
by
BrukerJWD
Committed by
GitHub
Oct 16, 2018
Browse files
Merge branch 'master' into isnice
parents
6bbf911a
a651a4d4
Changes
145
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1222 additions
and
769 deletions
+1222
-769
googlemock/msvc/2015/gmock_main.vcxproj
googlemock/msvc/2015/gmock_main.vcxproj
+63
-2
googlemock/msvc/2015/gmock_test.vcxproj
googlemock/msvc/2015/gmock_test.vcxproj
+76
-3
googlemock/scripts/fuse_gmock_files.py
googlemock/scripts/fuse_gmock_files.py
+1
-1
googlemock/scripts/generator/README
googlemock/scripts/generator/README
+4
-5
googlemock/scripts/generator/cpp/ast.py
googlemock/scripts/generator/cpp/ast.py
+6
-3
googlemock/scripts/generator/cpp/gmock_class_test.py
googlemock/scripts/generator/cpp/gmock_class_test.py
+18
-0
googlemock/scripts/upload.py
googlemock/scripts/upload.py
+4
-4
googlemock/src/gmock-all.cc
googlemock/src/gmock-all.cc
+1
-2
googlemock/src/gmock-cardinalities.cc
googlemock/src/gmock-cardinalities.cc
+2
-3
googlemock/src/gmock-internal-utils.cc
googlemock/src/gmock-internal-utils.cc
+37
-8
googlemock/src/gmock-matchers.cc
googlemock/src/gmock-matchers.cc
+211
-137
googlemock/src/gmock-spec-builders.cc
googlemock/src/gmock-spec-builders.cc
+130
-74
googlemock/src/gmock.cc
googlemock/src/gmock.cc
+30
-9
googlemock/src/gmock_main.cc
googlemock/src/gmock_main.cc
+3
-3
googlemock/test/BUILD.bazel
googlemock/test/BUILD.bazel
+123
-0
googlemock/test/gmock-actions_test.cc
googlemock/test/gmock-actions_test.cc
+255
-294
googlemock/test/gmock-cardinalities_test.cc
googlemock/test/gmock-cardinalities_test.cc
+2
-3
googlemock/test/gmock-generated-actions_test.cc
googlemock/test/gmock-generated-actions_test.cc
+173
-173
googlemock/test/gmock-generated-function-mockers_test.cc
googlemock/test/gmock-generated-function-mockers_test.cc
+56
-21
googlemock/test/gmock-generated-internal-utils_test.cc
googlemock/test/gmock-generated-internal-utils_test.cc
+27
-24
No files found.
Too many changes to show.
To preserve performance only
145 of 145+
files are displayed.
Plain diff
Email patch
googlemock/msvc/2015/gmock_main.vcxproj
View file @
8c82ba48
...
...
@@ -5,10 +5,18 @@
<Configuration>
Debug
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Debug|x64"
>
<Configuration>
Debug
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|Win32"
>
<Configuration>
Release
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|x64"
>
<Configuration>
Release
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup
Label=
"Globals"
>
<ProjectGuid>
{E4EF614B-30DF-4954-8C53-580A0BF6B589}
</ProjectGuid>
...
...
@@ -22,11 +30,22 @@
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"Configuration"
>
<ConfigurationType>
StaticLibrary
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
StaticLibrary
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"Configuration"
>
<ConfigurationType>
StaticLibrary
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.props"
/>
<ImportGroup
Label=
"ExtensionSettings"
>
</ImportGroup>
...
...
@@ -34,18 +53,34 @@
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<PropertyGroup
Label=
"UserMacros"
/>
<PropertyGroup>
<_ProjectFileVersion>
10.0.30319.1
</_ProjectFileVersion>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(SolutionDir)$(Configuration)\
</OutDir>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(SolutionDir)$(
Platform)-$(
Configuration)\
</OutDir>
<IntDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(OutDir)$(ProjectName)\
</IntDir>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(SolutionDir)$(Configuration)\
</OutDir>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(SolutionDir)$(
Platform)-$(
Configuration)\
</OutDir>
<IntDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<OutDir>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<OutDir>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ClCompile>
<Optimization>
Disabled
</Optimization>
...
...
@@ -60,6 +95,19 @@
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<ClCompile>
<Optimization>
Disabled
</Optimization>
<AdditionalIncludeDirectories>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<BasicRuntimeChecks>
EnableFastChecks
</BasicRuntimeChecks>
<RuntimeLibrary>
MultiThreadedDebug
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<ClCompile>
<AdditionalIncludeDirectories>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
...
...
@@ -71,6 +119,17 @@
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<ClCompile>
<AdditionalIncludeDirectories>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<RuntimeLibrary>
MultiThreaded
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference
Include=
"gmock.vcxproj"
>
<Project>
{34681f0d-ce45-415d-b5f2-5c662dfe3bd5}
</Project>
...
...
@@ -81,7 +140,9 @@
<ItemGroup>
<ClCompile
Include=
"..\..\src\gmock_main.cc"
>
<AdditionalIncludeDirectories
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
...
...
googlemock/msvc/2015/gmock_test.vcxproj
View file @
8c82ba48
...
...
@@ -5,10 +5,18 @@
<Configuration>
Debug
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Debug|x64"
>
<Configuration>
Debug
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|Win32"
>
<Configuration>
Release
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|x64"
>
<Configuration>
Release
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup
Label=
"Globals"
>
<ProjectGuid>
{F10D22F8-AC7B-4213-8720-608E7D878CD2}
</ProjectGuid>
...
...
@@ -22,11 +30,22 @@
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.props"
/>
<ImportGroup
Label=
"ExtensionSettings"
>
</ImportGroup>
...
...
@@ -34,19 +53,37 @@
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<PropertyGroup
Label=
"UserMacros"
/>
<PropertyGroup>
<_ProjectFileVersion>
10.0.30319.1
</_ProjectFileVersion>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(SolutionDir)$(Configuration)\
</OutDir>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(SolutionDir)$(
Platform)-$(
Configuration)\
</OutDir>
<IntDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(OutDir)$(ProjectName)\
</IntDir>
<LinkIncremental
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</LinkIncremental>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(SolutionDir)$(Configuration)\
</OutDir>
<LinkIncremental
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
true
</LinkIncremental>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(OutDir)$(ProjectName)\
</IntDir>
<LinkIncremental
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
false
</LinkIncremental>
<LinkIncremental
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
false
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<OutDir>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<OutDir>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ClCompile>
...
...
@@ -68,10 +105,28 @@
<TargetMachine>
MachineX86
</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<ClCompile>
<AdditionalOptions>
/bigobj %(AdditionalOptions)
</AdditionalOptions>
<Optimization>
Disabled
</Optimization>
<AdditionalIncludeDirectories>
..\..\include;..\..;$(GTestDir);%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<BasicRuntimeChecks>
EnableFastChecks
</BasicRuntimeChecks>
<RuntimeLibrary>
MultiThreadedDebug
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<SubSystem>
Console
</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<ClCompile>
<AdditionalOptions>
/bigobj %(AdditionalOptions)
</AdditionalOptions>
<AdditionalIncludeDirectories>
..\..\include;..\..;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>
..\..\include;..\..;
$(GTestDir);
%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<RuntimeLibrary>
MultiThreaded
</RuntimeLibrary>
<PrecompiledHeader>
...
...
@@ -87,6 +142,24 @@
<TargetMachine>
MachineX86
</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<ClCompile>
<AdditionalOptions>
/bigobj %(AdditionalOptions)
</AdditionalOptions>
<AdditionalIncludeDirectories>
..\..\include;..\..;$(GTestDir);%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<RuntimeLibrary>
MultiThreaded
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<SubSystem>
Console
</SubSystem>
<OptimizeReferences>
true
</OptimizeReferences>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference
Include=
"gmock_main.vcxproj"
>
<Project>
{e4ef614b-30df-4954-8c53-580a0bf6b589}
</Project>
...
...
googlemock/scripts/fuse_gmock_files.py
View file @
8c82ba48
...
...
@@ -55,7 +55,7 @@ EXAMPLES
This tool is experimental. In particular, it assumes that there is no
conditional inclusion of Google Mock or Google Test headers. Please
report any problems to googlemock@googlegroups.com. You can read
http://
code.google.com/p
/googlemock/
wiki
/CookBook for more
http
s
://
github.com/google/googletest/blob/master
/googlemock/
docs
/CookBook
.md
for more
information.
"""
...
...
googlemock/scripts/generator/README
View file @
8c82ba48
The Google Mock class generator is an application that is part of cppclean.
For more information about cppclean, see the README.cppclean file or
visit http://code.google.com/p/cppclean/
For more information about cppclean, visit http://code.google.com/p/cppclean/
cppclean
requires Python 2.3.5 or later. If you don't have Python
installed
on your system, you will also need to install it. You can download
Python
from: http://www.python.org/download/releases/
The mock generator
requires Python 2.3.5 or later. If you don't have Python
installed
on your system, you will also need to install it. You can download
Python
from: http://www.python.org/download/releases/
To use the Google Mock class generator, you need to call it
on the command line passing the header file and class for which you want
...
...
googlemock/scripts/generator/cpp/ast.py
View file @
8c82ba48
...
...
@@ -338,7 +338,7 @@ class Class(_GenericDeclaration):
# TODO(nnorwitz): handle namespaces, etc.
if
self
.
bases
:
for
token_list
in
self
.
bases
:
# TODO(nnorwitz): bases are tokens, do name comparis
i
on.
# TODO(nnorwitz): bases are tokens, do name comparison.
for
token
in
token_list
:
if
token
.
name
==
node
.
name
:
return
True
...
...
@@ -381,7 +381,7 @@ class Function(_GenericDeclaration):
def
Requires
(
self
,
node
):
if
self
.
parameters
:
# TODO(nnorwitz): parameters are tokens, do name comparis
i
on.
# TODO(nnorwitz): parameters are tokens, do name comparison.
for
p
in
self
.
parameters
:
if
p
.
name
==
node
.
name
:
return
True
...
...
@@ -858,7 +858,7 @@ class AstBuilder(object):
last_token
=
self
.
_GetNextToken
()
return
tokens
,
last_token
# TODO(nnorwitz): remove _IgnoreUpTo() it shouldn't be necesary.
# TODO(nnorwitz): remove _IgnoreUpTo() it shouldn't be neces
s
ary.
def
_IgnoreUpTo
(
self
,
token_type
,
token
):
unused_tokens
=
self
.
_GetTokensUpTo
(
token_type
,
token
)
...
...
@@ -1264,6 +1264,9 @@ class AstBuilder(object):
return
self
.
_GetNestedType
(
Union
)
def
handle_enum
(
self
):
token
=
self
.
_GetNextToken
()
if
not
(
token
.
token_type
==
tokenize
.
NAME
and
token
.
name
==
'class'
):
self
.
_AddBackToken
(
token
)
return
self
.
_GetNestedType
(
Enum
)
def
handle_auto
(
self
):
...
...
googlemock/scripts/generator/cpp/gmock_class_test.py
View file @
8c82ba48
...
...
@@ -440,6 +440,24 @@ public:
MOCK_METHOD1(Bar,
void(const FooType& test_arg));
};
"""
self
.
assertEqualIgnoreLeadingWhitespace
(
expected
,
self
.
GenerateMocks
(
source
))
def
testEnumClass
(
self
):
source
=
"""
class Test {
public:
enum class Baz { BAZINGA };
virtual void Bar(const FooType& test_arg);
};
"""
expected
=
"""
\
class MockTest : public Test {
public:
MOCK_METHOD1(Bar,
void(const FooType& test_arg));
};
"""
self
.
assertEqualIgnoreLeadingWhitespace
(
expected
,
self
.
GenerateMocks
(
source
))
...
...
googlemock/scripts/upload.py
View file @
8c82ba48
...
...
@@ -242,7 +242,7 @@ class AbstractRpcServer(object):
The authentication process works as follows:
1) We get a username and password from the user
2) We use ClientLogin to obtain an AUTH token for the user
(see http://
co
de.google.com/
apis/account
s/AuthForInstalledApps
.html
).
(see http
s
://de
velopers
.google.com/
identity/protocol
s/AuthForInstalledApps).
3) We pass the auth token to /_ah/login on the server to obtain an
authentication cookie. If login was successful, it tries to redirect
us to the URL we provided.
...
...
@@ -506,7 +506,7 @@ def EncodeMultipartFormData(fields, files):
(content_type, body) ready for httplib.HTTP instance.
Source:
http://
aspn.activestate.com/ASPN/Cookbook/Python/R
ecipe/146306
http
s
://
web.archive.org/web/20160116052001/code.activestate.com/r
ecipe
s
/146306
"""
BOUNDARY
=
'-M-A-G-I-C---B-O-U-N-D-A-R-Y-'
CRLF
=
'
\r\n
'
...
...
@@ -807,7 +807,7 @@ class SubversionVCS(VersionControlSystem):
# svn cat translates keywords but svn diff doesn't. As a result of this
# behavior patching.PatchChunks() fails with a chunk mismatch error.
# This part was originally written by the Review Board development team
# who had the same problem (http://reviews.review
-
board.org/r/276/).
# who had the same problem (http
s
://reviews.reviewboard.org/r/276/).
# Mapping of keywords to known aliases
svn_keywords
=
{
# Standard keywords
...
...
@@ -860,7 +860,7 @@ class SubversionVCS(VersionControlSystem):
status_lines
=
status
.
splitlines
()
# If file is in a cl, the output will begin with
# "\n--- Changelist 'cl_name':\n". See
# http://svn.collab.net/repos/svn/trunk/notes/changelist-design.txt
# http
s
://
web.archive.org/web/20090918234815/
svn.collab.net/repos/svn/trunk/notes/changelist-design.txt
if
(
len
(
status_lines
)
==
3
and
not
status_lines
[
0
]
and
status_lines
[
1
].
startswith
(
"--- Changelist"
)):
...
...
googlemock/src/gmock-all.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
//
// Google C++ Mocking Framework (Google Mock)
//
...
...
googlemock/src/gmock-cardinalities.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -92,7 +91,7 @@ class BetweenCardinalityImpl : public CardinalityInterface {
};
// Formats "n times" in a human-friendly way.
inline
internal
::
string
FormatTimes
(
int
n
)
{
inline
std
::
string
FormatTimes
(
int
n
)
{
if
(
n
==
1
)
{
return
"once"
;
}
else
if
(
n
==
2
)
{
...
...
googlemock/src/gmock-internal-utils.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -47,12 +46,31 @@
namespace
testing
{
namespace
internal
{
// Joins a vector of strings as if they are fields of a tuple; returns
// the joined string.
GTEST_API_
std
::
string
JoinAsTuple
(
const
Strings
&
fields
)
{
switch
(
fields
.
size
())
{
case
0
:
return
""
;
case
1
:
return
fields
[
0
];
default:
std
::
string
result
=
"("
+
fields
[
0
];
for
(
size_t
i
=
1
;
i
<
fields
.
size
();
i
++
)
{
result
+=
", "
;
result
+=
fields
[
i
];
}
result
+=
")"
;
return
result
;
}
}
// Converts an identifier name to a space-separated list of lower-case
// words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
// treated as one word. For example, both "FooBar123" and
// "foo_bar_123" are converted to "foo bar 123".
GTEST_API_
string
ConvertIdentifierNameToWords
(
const
char
*
id_name
)
{
string
result
;
GTEST_API_
std
::
string
ConvertIdentifierNameToWords
(
const
char
*
id_name
)
{
std
::
string
result
;
char
prev_char
=
'\0'
;
for
(
const
char
*
p
=
id_name
;
*
p
!=
'\0'
;
prev_char
=
*
(
p
++
))
{
// We don't care about the current locale as the input is
...
...
@@ -71,12 +89,12 @@ GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name) {
}
// This class reports Google Mock failures as Google Test failures. A
// user can define another class in a similar fashion if he intend
s
to
// user can define another class in a similar fashion if
t
he
y
intend to
// use Google Mock with a testing framework other than Google Test.
class
GoogleTestFailureReporter
:
public
FailureReporterInterface
{
public:
virtual
void
ReportFailure
(
FailureType
type
,
const
char
*
file
,
int
line
,
const
string
&
message
)
{
const
std
::
string
&
message
)
{
AssertHelper
(
type
==
kFatal
?
TestPartResult
::
kFatalFailure
:
TestPartResult
::
kNonFatalFailure
,
...
...
@@ -128,8 +146,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) {
// stack_frames_to_skip is treated as 0, since we don't know which
// function calls will be inlined by the compiler and need to be
// conservative.
GTEST_API_
void
Log
(
LogSeverity
severity
,
const
string
&
message
,
GTEST_API_
void
Log
(
LogSeverity
severity
,
const
std
::
string
&
message
,
int
stack_frames_to_skip
)
{
if
(
!
LogIsVisible
(
severity
))
return
;
...
...
@@ -170,5 +187,17 @@ GTEST_API_ void Log(LogSeverity severity,
std
::
cout
<<
::
std
::
flush
;
}
GTEST_API_
WithoutMatchers
GetWithoutMatchers
()
{
return
WithoutMatchers
();
}
GTEST_API_
void
IllegalDoDefault
(
const
char
*
file
,
int
line
)
{
internal
::
Assert
(
false
,
file
,
line
,
"You are using DoDefault() inside a composite action like "
"DoAll() or WithArgs(). This is not supported for technical "
"reasons. Please instead spell out the default action, or "
"assign the default action to an Action variable and use "
"the variable in various places."
);
}
}
// namespace internal
}
// namespace testing
googlemock/src/gmock-matchers.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -38,98 +37,133 @@
#include "gmock/gmock-generated-matchers.h"
#include <string.h>
#include <iostream>
#include <sstream>
#include <string>
namespace
testing
{
// Constructs a matcher that matches a const string& whose value is
// Constructs a matcher that matches a const
std::
string& whose value is
// equal to s.
Matcher
<
const
internal
::
string
&>::
Matcher
(
const
internal
::
string
&
s
)
{
*
this
=
Eq
(
s
);
Matcher
<
const
std
::
string
&>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
#if GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a const std::string& whose value is
// equal to s.
Matcher
<
const
std
::
string
&>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
static_cast
<
std
::
string
>
(
s
));
}
#endif // GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a const string& whose value is
// Constructs a matcher that matches a const
std::
string& whose value is
// equal to s.
Matcher
<
const
internal
::
string
&>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
internal
::
string
(
s
));
Matcher
<
const
std
::
string
&>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
}
// Constructs a matcher that matches a string whose value is equal to s.
Matcher
<
internal
::
string
>::
Matcher
(
const
internal
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
// Constructs a matcher that matches a std::string whose value is equal to
// s.
Matcher
<
std
::
string
>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
// Constructs a matcher that matches a string whose value is equal to s.
Matcher
<
internal
::
string
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
internal
::
string
(
s
));
#if GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a std::string whose value is equal to
// s.
Matcher
<
std
::
string
>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
static_cast
<
std
::
string
>
(
s
));
}
#endif // GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a std::string whose value is equal to
// s.
Matcher
<
std
::
string
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
}
#if GTEST_HAS_
STRING_PIECE_
// Constructs a matcher that matches a const
S
tring
Piece
& whose value is
#if GTEST_HAS_
GLOBAL_STRING
// Constructs a matcher that matches a const
::s
tring& whose value is
// equal to s.
Matcher
<
const
S
tring
Piece
&>::
Matcher
(
const
internal
::
string
&
s
)
{
*
this
=
Eq
(
s
);
Matcher
<
const
::
s
tring
&>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
tatic_cast
<::
string
>
(
s
)
);
}
// Constructs a matcher that matches a const
S
tring
Piece
& whose value is
// Constructs a matcher that matches a const
::s
tring& whose value is
// equal to s.
Matcher
<
const
StringPiece
&>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
internal
::
string
(
s
));
}
Matcher
<
const
::
string
&>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
// Constructs a matcher that matches a const
S
tring
Piece
& whose value is
// Constructs a matcher that matches a const
::s
tring& whose value is
// equal to s.
Matcher
<
const
StringPiece
&>::
Matcher
(
StringPiece
s
)
{
*
this
=
Eq
(
s
.
ToString
());
Matcher
<
const
::
string
&>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
::
string
(
s
));
}
// Constructs a matcher that matches a ::string whose value is equal to s.
Matcher
<::
string
>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
static_cast
<::
string
>
(
s
));
}
// Constructs a matcher that matches a StringPiece whose value is equal to s.
Matcher
<
StringPiece
>::
Matcher
(
const
internal
::
string
&
s
)
{
// Constructs a matcher that matches a ::string whose value is equal to s.
Matcher
<::
string
>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
// Constructs a matcher that matches a string whose value is equal to s.
Matcher
<::
string
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
::
string
(
s
));
}
#endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_ABSL
// Constructs a matcher that matches a const absl::string_view& whose value is
// equal to s.
Matcher
<
const
absl
::
string_view
&>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
// Constructs a matcher that matches a StringPiece whose value is equal to s.
Matcher
<
StringPiece
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
internal
::
string
(
s
));
#if GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a const absl::string_view& whose value is
// equal to s.
Matcher
<
const
absl
::
string_view
&>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
#endif // GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a const absl::string_view& whose value is
// equal to s.
Matcher
<
const
absl
::
string_view
&>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
}
// Constructs a matcher that matches a StringPiece whose value is equal to s.
Matcher
<
StringPiece
>::
Matcher
(
StringPiece
s
)
{
*
this
=
Eq
(
s
.
ToString
());
// Constructs a matcher that matches a const absl::string_view& whose value is
// equal to s.
Matcher
<
const
absl
::
string_view
&>::
Matcher
(
absl
::
string_view
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
}
#endif // GTEST_HAS_STRING_PIECE_
namespace
internal
{
// Constructs a matcher that matches a absl::string_view whose value is equal to
// s.
Matcher
<
absl
::
string_view
>::
Matcher
(
const
std
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
// Joins a vector of strings as if they are fields of a tuple; returns
// the joined string.
GTEST_API_
string
JoinAsTuple
(
const
Strings
&
fields
)
{
switch
(
fields
.
size
())
{
case
0
:
return
""
;
case
1
:
return
fields
[
0
];
default:
string
result
=
"("
+
fields
[
0
];
for
(
size_t
i
=
1
;
i
<
fields
.
size
();
i
++
)
{
result
+=
", "
;
result
+=
fields
[
i
];
}
result
+=
")"
;
return
result
;
}
#if GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a absl::string_view whose value is equal to
// s.
Matcher
<
absl
::
string_view
>::
Matcher
(
const
::
string
&
s
)
{
*
this
=
Eq
(
s
);
}
#endif // GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a absl::string_view whose value is equal to
// s.
Matcher
<
absl
::
string_view
>::
Matcher
(
const
char
*
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
}
// Constructs a matcher that matches a absl::string_view whose value is equal to
// s.
Matcher
<
absl
::
string_view
>::
Matcher
(
absl
::
string_view
s
)
{
*
this
=
Eq
(
std
::
string
(
s
));
}
#endif // GTEST_HAS_ABSL
namespace
internal
{
// Returns the description for a matcher defined using the MATCHER*()
// macro where the user-supplied description string is "", if
// 'negation' is false; otherwise returns the description of the
// negation of the matcher. 'param_values' contains a list of strings
// that are the print-out of the matcher's parameters.
GTEST_API_
string
FormatMatcherDescription
(
bool
negation
,
const
char
*
matcher_name
,
const
Strings
&
param_values
)
{
string
result
=
ConvertIdentifierNameToWords
(
matcher_name
);
if
(
param_values
.
size
()
>=
1
)
result
+=
" "
+
JoinAsTuple
(
param_values
);
GTEST_API_
std
::
string
FormatMatcherDescription
(
bool
negation
,
const
char
*
matcher_name
,
const
Strings
&
param_values
)
{
std
::
string
result
=
ConvertIdentifierNameToWords
(
matcher_name
);
if
(
param_values
.
size
()
>=
1
)
result
+=
" "
+
JoinAsTuple
(
param_values
);
return
negation
?
"not ("
+
result
+
")"
:
result
;
}
...
...
@@ -200,8 +234,7 @@ class MaxBipartiteMatchState {
explicit
MaxBipartiteMatchState
(
const
MatchMatrix
&
graph
)
:
graph_
(
&
graph
),
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}.
ElementMatcherPairs
Compute
()
{
...
...
@@ -258,10 +291,8 @@ class MaxBipartiteMatchState {
//
bool
TryAugment
(
size_t
ilhs
,
::
std
::
vector
<
char
>*
seen
)
{
for
(
size_t
irhs
=
0
;
irhs
<
graph_
->
RhsSize
();
++
irhs
)
{
if
((
*
seen
)[
irhs
])
continue
;
if
(
!
graph_
->
HasEdge
(
ilhs
,
irhs
))
continue
;
if
((
*
seen
)[
irhs
])
continue
;
if
(
!
graph_
->
HasEdge
(
ilhs
,
irhs
))
continue
;
// There's an available edge from ilhs to irhs.
(
*
seen
)[
irhs
]
=
1
;
// Next a search is performed to determine whether
...
...
@@ -288,7 +319,7 @@ class MaxBipartiteMatchState {
// Each element of the left_ vector represents a left hand side node
// (i.e. an element) and each element of right_ is a right hand side
// node (i.e. a matcher). The values in the left_ vector indicate
// outflow from that node to a node on the
the
right_ side. The values
// outflow from that node to a node on the right_ side. The values
// in the right_ indicate inflow, and specify which left_ node is
// feeding that right_ node, if any. For example, left_[3] == 1 means
// there's a flow from element #3 to matcher #1. Such a flow would also
...
...
@@ -304,8 +335,7 @@ class MaxBipartiteMatchState {
const
size_t
MaxBipartiteMatchState
::
kUnused
;
GTEST_API_
ElementMatcherPairs
FindMaxBipartiteMatching
(
const
MatchMatrix
&
g
)
{
GTEST_API_
ElementMatcherPairs
FindMaxBipartiteMatching
(
const
MatchMatrix
&
g
)
{
return
MaxBipartiteMatchState
(
g
).
Compute
();
}
...
...
@@ -314,7 +344,7 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
typedef
ElementMatcherPairs
::
const_iterator
Iter
;
::
std
::
ostream
&
os
=
*
stream
;
os
<<
"{"
;
const
char
*
sep
=
""
;
const
char
*
sep
=
""
;
for
(
Iter
it
=
pairs
.
begin
();
it
!=
pairs
.
end
();
++
it
)
{
os
<<
sep
<<
"
\n
("
<<
"element #"
<<
it
->
first
<<
", "
...
...
@@ -324,38 +354,6 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
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
()
{
for
(
size_t
ilhs
=
0
;
ilhs
<
LhsSize
();
++
ilhs
)
{
for
(
size_t
irhs
=
0
;
irhs
<
RhsSize
();
++
irhs
)
{
...
...
@@ -379,9 +377,9 @@ void MatchMatrix::Randomize() {
}
}
string
MatchMatrix
::
DebugString
()
const
{
std
::
string
MatchMatrix
::
DebugString
()
const
{
::
std
::
stringstream
ss
;
const
char
*
sep
=
""
;
const
char
*
sep
=
""
;
for
(
size_t
i
=
0
;
i
<
LhsSize
();
++
i
)
{
ss
<<
sep
;
for
(
size_t
j
=
0
;
j
<
RhsSize
();
++
j
)
{
...
...
@@ -394,44 +392,83 @@ string MatchMatrix::DebugString() const {
void
UnorderedElementsAreMatcherImplBase
::
DescribeToImpl
(
::
std
::
ostream
*
os
)
const
{
if
(
matcher_describers_
.
empty
())
{
*
os
<<
"is empty"
;
return
;
}
if
(
matcher_describers_
.
size
()
==
1
)
{
*
os
<<
"has "
<<
Elements
(
1
)
<<
" and that element "
;
matcher_describers_
[
0
]
->
DescribeTo
(
os
);
return
;
switch
(
match_flags
())
{
case
UnorderedMatcherRequire
::
ExactMatch
:
if
(
matcher_describers_
.
empty
())
{
*
os
<<
"is empty"
;
return
;
}
if
(
matcher_describers_
.
size
()
==
1
)
{
*
os
<<
"has "
<<
Elements
(
1
)
<<
" and that element "
;
matcher_describers_
[
0
]
->
DescribeTo
(
os
);
return
;
}
*
os
<<
"has "
<<
Elements
(
matcher_describers_
.
size
())
<<
" 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
;
}
*
os
<<
"has "
<<
Elements
(
matcher_describers_
.
size
())
<<
" and there exists some permutation of elements such that:
\n
"
;
const
char
*
sep
=
""
;
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
);
sep
=
", and
\n
"
;
if
(
match_flags
()
==
UnorderedMatcherRequire
::
ExactMatch
)
{
sep
=
", and
\n
"
;
}
else
{
sep
=
"
\n
"
;
}
}
}
void
UnorderedElementsAreMatcherImplBase
::
DescribeNegationToImpl
(
::
std
::
ostream
*
os
)
const
{
if
(
matcher_describers_
.
empty
())
{
*
os
<<
"isn't empty"
;
return
;
}
if
(
matcher_describers_
.
size
()
==
1
)
{
*
os
<<
"doesn't have "
<<
Elements
(
1
)
<<
", or has "
<<
Elements
(
1
)
<<
" that "
;
matcher_describers_
[
0
]
->
DescribeNegationTo
(
os
);
return
;
switch
(
match_flags
())
{
case
UnorderedMatcherRequire
::
ExactMatch
:
if
(
matcher_describers_
.
empty
())
{
*
os
<<
"isn't empty"
;
return
;
}
if
(
matcher_describers_
.
size
()
==
1
)
{
*
os
<<
"doesn't have "
<<
Elements
(
1
)
<<
", or has "
<<
Elements
(
1
)
<<
" that "
;
matcher_describers_
[
0
]
->
DescribeNegationTo
(
os
);
return
;
}
*
os
<<
"doesn't have "
<<
Elements
(
matcher_describers_
.
size
())
<<
", 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
;
}
*
os
<<
"doesn't have "
<<
Elements
(
matcher_describers_
.
size
())
<<
", or there exists no permutation of elements such that:
\n
"
;
const
char
*
sep
=
""
;
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
);
sep
=
", and
\n
"
;
if
(
match_flags
()
==
UnorderedMatcherRequire
::
ExactMatch
)
{
sep
=
", and
\n
"
;
}
else
{
sep
=
"
\n
"
;
}
}
}
...
...
@@ -440,11 +477,9 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
// and better error reporting.
// Returns false, writing an explanation to 'listener', if and only
// if the success criteria are not met.
bool
UnorderedElementsAreMatcherImplBase
::
VerifyAllElementsAndMatchersAreMatched
(
const
::
std
::
vector
<
string
>&
element_printouts
,
const
MatchMatrix
&
matrix
,
MatchResultListener
*
listener
)
const
{
bool
UnorderedElementsAreMatcherImplBase
::
VerifyMatchMatrix
(
const
::
std
::
vector
<
std
::
string
>&
element_printouts
,
const
MatchMatrix
&
matrix
,
MatchResultListener
*
listener
)
const
{
bool
result
=
true
;
::
std
::
vector
<
char
>
element_matched
(
matrix
.
LhsSize
(),
0
);
::
std
::
vector
<
char
>
matcher_matched
(
matrix
.
RhsSize
(),
0
);
...
...
@@ -457,12 +492,11 @@ VerifyAllElementsAndMatchersAreMatched(
}
}
{
if
(
match_flags
()
&
UnorderedMatcherRequire
::
Superset
)
{
const
char
*
sep
=
"where the following matchers don't match any elements:
\n
"
;
for
(
size_t
mi
=
0
;
mi
<
matcher_matched
.
size
();
++
mi
)
{
if
(
matcher_matched
[
mi
])
continue
;
if
(
matcher_matched
[
mi
])
continue
;
result
=
false
;
if
(
listener
->
IsInterested
())
{
*
listener
<<
sep
<<
"matcher #"
<<
mi
<<
": "
;
...
...
@@ -472,7 +506,7 @@ VerifyAllElementsAndMatchersAreMatched(
}
}
{
if
(
match_flags
()
&
UnorderedMatcherRequire
::
Subset
)
{
const
char
*
sep
=
"where the following elements don't match any matchers:
\n
"
;
const
char
*
outer_sep
=
""
;
...
...
@@ -480,8 +514,7 @@ VerifyAllElementsAndMatchersAreMatched(
outer_sep
=
"
\n
and "
;
}
for
(
size_t
ei
=
0
;
ei
<
element_matched
.
size
();
++
ei
)
{
if
(
element_matched
[
ei
])
continue
;
if
(
element_matched
[
ei
])
continue
;
result
=
false
;
if
(
listener
->
IsInterested
())
{
*
listener
<<
outer_sep
<<
sep
<<
"element #"
<<
ei
<<
": "
...
...
@@ -494,5 +527,46 @@ VerifyAllElementsAndMatchersAreMatched(
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 testing
googlemock/src/gmock-spec-builders.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -41,6 +40,7 @@
#include <map>
#include <set>
#include <string>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
...
...
@@ -48,6 +48,15 @@
# include <unistd.h> // NOLINT
#endif
// Silence C4800 (C4800: 'int *const ': forcing value
// to bool 'true' or 'false') for MSVC 14,15
#ifdef _MSC_VER
#if _MSC_VER <= 1900
# pragma warning(push)
# pragma warning(disable:4800)
#endif
#endif
namespace
testing
{
namespace
internal
{
...
...
@@ -58,16 +67,15 @@ GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_gmock_mutex);
// Logs a message including file and line number information.
GTEST_API_
void
LogWithLocation
(
testing
::
internal
::
LogSeverity
severity
,
const
char
*
file
,
int
line
,
const
string
&
message
)
{
const
std
::
string
&
message
)
{
::
std
::
ostringstream
s
;
s
<<
file
<<
":"
<<
line
<<
": "
<<
message
<<
::
std
::
endl
;
Log
(
severity
,
s
.
str
(),
0
);
}
// Constructs an ExpectationBase object.
ExpectationBase
::
ExpectationBase
(
const
char
*
a_file
,
int
a_line
,
const
string
&
a_source_text
)
ExpectationBase
::
ExpectationBase
(
const
char
*
a_file
,
int
a_line
,
const
std
::
string
&
a_source_text
)
:
file_
(
a_file
),
line_
(
a_line
),
source_text_
(
a_source_text
),
...
...
@@ -100,12 +108,19 @@ void ExpectationBase::RetireAllPreRequisites()
return
;
}
for
(
ExpectationSet
::
const_iterator
it
=
immediate_prerequisites_
.
begin
();
it
!=
immediate_prerequisites_
.
end
();
++
it
)
{
ExpectationBase
*
const
prerequisite
=
it
->
expectation_base
().
get
();
if
(
!
prerequisite
->
is_retired
())
{
prerequisite
->
RetireAllPreRequisites
();
prerequisite
->
Retire
();
::
std
::
vector
<
ExpectationBase
*>
expectations
(
1
,
this
);
while
(
!
expectations
.
empty
())
{
ExpectationBase
*
exp
=
expectations
.
back
();
expectations
.
pop_back
();
for
(
ExpectationSet
::
const_iterator
it
=
exp
->
immediate_prerequisites_
.
begin
();
it
!=
exp
->
immediate_prerequisites_
.
end
();
++
it
)
{
ExpectationBase
*
next
=
it
->
expectation_base
().
get
();
if
(
!
next
->
is_retired
())
{
next
->
Retire
();
expectations
.
push_back
(
next
);
}
}
}
}
...
...
@@ -115,11 +130,18 @@ void ExpectationBase::RetireAllPreRequisites()
bool
ExpectationBase
::
AllPrerequisitesAreSatisfied
()
const
GTEST_EXCLUSIVE_LOCK_REQUIRED_
(
g_gmock_mutex
)
{
g_gmock_mutex
.
AssertHeld
();
for
(
ExpectationSet
::
const_iterator
it
=
immediate_prerequisites_
.
begin
();
it
!=
immediate_prerequisites_
.
end
();
++
it
)
{
if
(
!
(
it
->
expectation_base
()
->
IsSatisfied
())
||
!
(
it
->
expectation_base
()
->
AllPrerequisitesAreSatisfied
()))
return
false
;
::
std
::
vector
<
const
ExpectationBase
*>
expectations
(
1
,
this
);
while
(
!
expectations
.
empty
())
{
const
ExpectationBase
*
exp
=
expectations
.
back
();
expectations
.
pop_back
();
for
(
ExpectationSet
::
const_iterator
it
=
exp
->
immediate_prerequisites_
.
begin
();
it
!=
exp
->
immediate_prerequisites_
.
end
();
++
it
)
{
const
ExpectationBase
*
next
=
it
->
expectation_base
().
get
();
if
(
!
next
->
IsSatisfied
())
return
false
;
expectations
.
push_back
(
next
);
}
}
return
true
;
}
...
...
@@ -128,19 +150,28 @@ bool ExpectationBase::AllPrerequisitesAreSatisfied() const
void
ExpectationBase
::
FindUnsatisfiedPrerequisites
(
ExpectationSet
*
result
)
const
GTEST_EXCLUSIVE_LOCK_REQUIRED_
(
g_gmock_mutex
)
{
g_gmock_mutex
.
AssertHeld
();
for
(
ExpectationSet
::
const_iterator
it
=
immediate_prerequisites_
.
begin
();
it
!=
immediate_prerequisites_
.
end
();
++
it
)
{
if
(
it
->
expectation_base
()
->
IsSatisfied
())
{
// If *it is satisfied and has a call count of 0, some of its
// pre-requisites may not be satisfied yet.
if
(
it
->
expectation_base
()
->
call_count_
==
0
)
{
it
->
expectation_base
()
->
FindUnsatisfiedPrerequisites
(
result
);
::
std
::
vector
<
const
ExpectationBase
*>
expectations
(
1
,
this
);
while
(
!
expectations
.
empty
())
{
const
ExpectationBase
*
exp
=
expectations
.
back
();
expectations
.
pop_back
();
for
(
ExpectationSet
::
const_iterator
it
=
exp
->
immediate_prerequisites_
.
begin
();
it
!=
exp
->
immediate_prerequisites_
.
end
();
++
it
)
{
const
ExpectationBase
*
next
=
it
->
expectation_base
().
get
();
if
(
next
->
IsSatisfied
())
{
// If *it is satisfied and has a call count of 0, some of its
// pre-requisites may not be satisfied yet.
if
(
next
->
call_count_
==
0
)
{
expectations
.
push_back
(
next
);
}
}
else
{
// Now that we know next is unsatisfied, we are not so interested
// in whether its pre-requisites are satisfied. Therefore we
// don't iterate into it here.
*
result
+=
*
it
;
}
}
else
{
// Now that we know *it is unsatisfied, we are not so interested
// in whether its pre-requisites are satisfied. Therefore we
// don't recursively call FindUnsatisfiedPrerequisites() here.
*
result
+=
*
it
;
}
}
}
...
...
@@ -244,7 +275,7 @@ GTEST_API_ ThreadLocal<Sequence*> g_gmock_implicit_sequence;
// Reports an uninteresting call (whose description is in msg) in the
// manner specified by 'reaction'.
void
ReportUninterestingCall
(
CallReaction
reaction
,
const
string
&
msg
)
{
void
ReportUninterestingCall
(
CallReaction
reaction
,
const
std
::
string
&
msg
)
{
// Include a stack trace only if --gmock_verbose=info is specified.
const
int
stack_frames_to_skip
=
GMOCK_FLAG
(
verbose
)
==
kInfoVerbosity
?
3
:
-
1
;
...
...
@@ -255,20 +286,22 @@ void ReportUninterestingCall(CallReaction reaction, const string& msg) {
case
kWarn
:
Log
(
kWarning
,
msg
+
"
\n
NOTE: You can safely ignore the above warning unless this "
"call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. "
"See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#"
"knowing-when-to-expect for details.
\n
"
,
"
\n
NOTE: You can safely ignore the above warning unless this "
"call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. "
"See "
"https://github.com/google/googletest/blob/master/googlemock/"
"docs/CookBook.md#"
"knowing-when-to-expect for details.
\n
"
,
stack_frames_to_skip
);
break
;
default:
// FAIL
Expect
(
false
,
NULL
,
-
1
,
msg
);
Expect
(
false
,
nullptr
,
-
1
,
msg
);
}
}
UntypedFunctionMockerBase
::
UntypedFunctionMockerBase
()
:
mock_obj_
(
NULL
),
name_
(
""
)
{}
:
mock_obj_
(
nullptr
),
name_
(
""
)
{}
UntypedFunctionMockerBase
::~
UntypedFunctionMockerBase
()
{}
...
...
@@ -307,7 +340,7 @@ const void* UntypedFunctionMockerBase::MockObject() const
// We protect mock_obj_ under g_gmock_mutex in case this mock
// function is called from two threads concurrently.
MutexLock
l
(
&
g_gmock_mutex
);
Assert
(
mock_obj_
!=
NULL
,
__FILE__
,
__LINE__
,
Assert
(
mock_obj_
!=
nullptr
,
__FILE__
,
__LINE__
,
"MockObject() must not be called before RegisterOwner() or "
"SetOwnerAndName() has been called."
);
mock_obj
=
mock_obj_
;
...
...
@@ -324,7 +357,7 @@ const char* UntypedFunctionMockerBase::Name() const
// We protect name_ under g_gmock_mutex in case this mock
// function is called from two threads concurrently.
MutexLock
l
(
&
g_gmock_mutex
);
Assert
(
name_
!=
NULL
,
__FILE__
,
__LINE__
,
Assert
(
name_
!=
nullptr
,
__FILE__
,
__LINE__
,
"Name() must not be called before SetOwnerAndName() has "
"been called."
);
name
=
name_
;
...
...
@@ -335,9 +368,10 @@ const char* UntypedFunctionMockerBase::Name() const
// Calculates the result of invoking this mock function with the given
// arguments, prints it, and returns it. The caller is responsible
// for deleting the result.
UntypedActionResultHolderBase
*
UntypedFunctionMockerBase
::
UntypedInvokeWith
(
const
void
*
const
untyped_args
)
GTEST_LOCK_EXCLUDED_
(
g_gmock_mutex
)
{
UntypedActionResultHolderBase
*
UntypedFunctionMockerBase
::
UntypedInvokeWith
(
void
*
const
untyped_args
)
GTEST_LOCK_EXCLUDED_
(
g_gmock_mutex
)
{
// See the definition of untyped_expectations_ for why access to it
// is unprotected here.
if
(
untyped_expectations_
.
size
()
==
0
)
{
// No expectation is set on this mock method - we have an
// uninteresting call.
...
...
@@ -354,18 +388,21 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
// the behavior of ReportUninterestingCall().
const
bool
need_to_report_uninteresting_call
=
// If the user allows this uninteresting call, we print it
// only when he want
s
informational messages.
// only when
t
he
y
want informational messages.
reaction
==
kAllow
?
LogIsVisible
(
kInfo
)
:
// If the user wants this to be a warning, we print it only
// when he wants to see warnings.
reaction
==
kWarn
?
LogIsVisible
(
kWarning
)
:
// Otherwise, the user wants this to be an error, and we
// should always print detailed information in the error.
true
;
// If the user wants this to be a warning, we print
// it only when they want to see warnings.
reaction
==
kWarn
?
LogIsVisible
(
kWarning
)
:
// Otherwise, the user wants this to be an error, and we
// should always print detailed information in the error.
true
;
if
(
!
need_to_report_uninteresting_call
)
{
// Perform the action without printing the call information.
return
this
->
UntypedPerformDefaultAction
(
untyped_args
,
""
);
return
this
->
UntypedPerformDefaultAction
(
untyped_args
,
"Function call: "
+
std
::
string
(
Name
()));
}
// Warns about the uninteresting call.
...
...
@@ -377,8 +414,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
this
->
UntypedPerformDefaultAction
(
untyped_args
,
ss
.
str
());
// Prints the function result.
if
(
result
!=
NULL
)
result
->
PrintAsActionResult
(
&
ss
);
if
(
result
!=
nullptr
)
result
->
PrintAsActionResult
(
&
ss
);
ReportUninterestingCall
(
reaction
,
ss
.
str
());
return
result
;
...
...
@@ -388,7 +424,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
::
std
::
stringstream
ss
;
::
std
::
stringstream
why
;
::
std
::
stringstream
loc
;
const
void
*
untyped_action
=
NULL
;
const
void
*
untyped_action
=
nullptr
;
// The UntypedFindMatchingExpectation() function acquires and
// releases g_gmock_mutex.
...
...
@@ -396,7 +432,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
this
->
UntypedFindMatchingExpectation
(
untyped_args
,
&
untyped_action
,
&
is_excessive
,
&
ss
,
&
why
);
const
bool
found
=
untyped_expectation
!=
NULL
;
const
bool
found
=
untyped_expectation
!=
nullptr
;
// True iff we need to print the call's arguments and return value.
// This definition must be kept in sync with the uses of Expect()
...
...
@@ -405,10 +441,9 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
!
found
||
is_excessive
||
LogIsVisible
(
kInfo
);
if
(
!
need_to_report_call
)
{
// Perform the action without printing the call information.
return
untyped_action
==
NULL
?
this
->
UntypedPerformDefaultAction
(
untyped_args
,
""
)
:
this
->
UntypedPerformAction
(
untyped_action
,
untyped_args
);
return
untyped_action
==
nullptr
?
this
->
UntypedPerformDefaultAction
(
untyped_args
,
""
)
:
this
->
UntypedPerformAction
(
untyped_action
,
untyped_args
);
}
ss
<<
" Function call: "
<<
Name
();
...
...
@@ -421,16 +456,15 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
}
UntypedActionResultHolderBase
*
const
result
=
untyped_action
==
NULL
?
this
->
UntypedPerformDefaultAction
(
untyped_args
,
ss
.
str
())
:
this
->
UntypedPerformAction
(
untyped_action
,
untyped_args
);
if
(
result
!=
NULL
)
result
->
PrintAsActionResult
(
&
ss
);
untyped_action
==
nullptr
?
this
->
UntypedPerformDefaultAction
(
untyped_args
,
ss
.
str
())
:
this
->
UntypedPerformAction
(
untyped_action
,
untyped_args
);
if
(
result
!=
nullptr
)
result
->
PrintAsActionResult
(
&
ss
);
ss
<<
"
\n
"
<<
why
.
str
();
if
(
!
found
)
{
// No expectation matches this call - reports a failure.
Expect
(
false
,
NULL
,
-
1
,
ss
.
str
());
Expect
(
false
,
nullptr
,
-
1
,
ss
.
str
());
}
else
if
(
is_excessive
)
{
// We had an upper-bound violation and the failure message is in ss.
Expect
(
false
,
untyped_expectation
->
file
(),
...
...
@@ -447,6 +481,8 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
// Returns an Expectation object that references and co-owns exp,
// which must be an expectation on this mock function.
Expectation
UntypedFunctionMockerBase
::
GetHandleOf
(
ExpectationBase
*
exp
)
{
// See the definition of untyped_expectations_ for why access to it
// is unprotected here.
for
(
UntypedExpectations
::
const_iterator
it
=
untyped_expectations_
.
begin
();
it
!=
untyped_expectations_
.
end
();
++
it
)
{
...
...
@@ -509,6 +545,13 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
return
expectations_met
;
}
CallReaction
intToCallReaction
(
int
mock_behavior
)
{
if
(
mock_behavior
>=
kAllow
&&
mock_behavior
<=
kFail
)
{
return
static_cast
<
internal
::
CallReaction
>
(
mock_behavior
);
}
return
kWarn
;
}
}
// namespace internal
// Class Mock.
...
...
@@ -522,7 +565,7 @@ typedef std::set<internal::UntypedFunctionMockerBase*> FunctionMockers;
// expectations.
struct
MockObjectState
{
MockObjectState
()
:
first_used_file
(
NULL
),
first_used_line
(
-
1
),
leakable
(
false
)
{}
:
first_used_file
(
nullptr
),
first_used_line
(
-
1
),
leakable
(
false
)
{}
// Where in the source file an ON_CALL or EXPECT_CALL is first
// invoked on this mock object.
...
...
@@ -560,7 +603,7 @@ class MockObjectRegistry {
if
(
it
->
second
.
leakable
)
// The user said it's fine to leak this object.
continue
;
//
TODO(wan@google.com)
: Print the type of the leaked object.
//
FIXME
: Print the type of the leaked object.
// This can help the user identify the leaked object.
std
::
cout
<<
"
\n
"
;
const
MockObjectState
&
state
=
it
->
second
;
...
...
@@ -576,9 +619,15 @@ class MockObjectRegistry {
leaked_count
++
;
}
if
(
leaked_count
>
0
)
{
std
::
cout
<<
"
\n
ERROR: "
<<
leaked_count
<<
" leaked mock "
<<
(
leaked_count
==
1
?
"object"
:
"objects"
)
<<
" found at program exit.
\n
"
;
std
::
cout
<<
"
\n
ERROR: "
<<
leaked_count
<<
" leaked mock "
<<
(
leaked_count
==
1
?
"object"
:
"objects"
)
<<
" found at program exit. Expectations on a mock object is "
"verified when the object is destructed. Leaking a mock "
"means that its expectations aren't verified, which is "
"usually a test bug. If you really intend to leak a mock, "
"you can suppress this error using "
"testing::Mock::AllowLeak(mock_object), or you may use a "
"fake or stub instead of a mock.
\n
"
;
std
::
cout
.
flush
();
::
std
::
cerr
.
flush
();
// RUN_ALL_TESTS() has already returned when this destructor is
...
...
@@ -649,7 +698,8 @@ internal::CallReaction Mock::GetReactionOnUninterestingCalls(
GTEST_LOCK_EXCLUDED_
(
internal
::
g_gmock_mutex
)
{
internal
::
MutexLock
l
(
&
internal
::
g_gmock_mutex
);
return
(
g_uninteresting_call_reaction
.
count
(
mock_obj
)
==
0
)
?
internal
::
kDefault
:
g_uninteresting_call_reaction
[
mock_obj
];
internal
::
intToCallReaction
(
GMOCK_FLAG
(
default_mock_behavior
))
:
g_uninteresting_call_reaction
[
mock_obj
];
}
// Tells Google Mock to ignore mock_obj when checking for leaked mock
...
...
@@ -750,13 +800,13 @@ void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj,
GTEST_LOCK_EXCLUDED_
(
internal
::
g_gmock_mutex
)
{
internal
::
MutexLock
l
(
&
internal
::
g_gmock_mutex
);
MockObjectState
&
state
=
g_mock_object_registry
.
states
()[
mock_obj
];
if
(
state
.
first_used_file
==
NULL
)
{
if
(
state
.
first_used_file
==
nullptr
)
{
state
.
first_used_file
=
file
;
state
.
first_used_line
=
line
;
const
TestInfo
*
const
test_info
=
UnitTest
::
GetInstance
()
->
current_test_info
();
if
(
test_info
!=
NULL
)
{
//
TODO(wan@google.com)
: record the test case name when the
if
(
test_info
!=
nullptr
)
{
//
FIXME
: record the test case name when the
// ON_CALL or EXPECT_CALL is invoked from SetUpTestCase() or
// TearDownTestCase().
state
.
first_used_test_case
=
test_info
->
test_case_name
();
...
...
@@ -820,7 +870,7 @@ Expectation::~Expectation() {}
// Adds an expectation to a sequence.
void
Sequence
::
AddExpectation
(
const
Expectation
&
expectation
)
const
{
if
(
*
last_expectation_
!=
expectation
)
{
if
(
last_expectation_
->
expectation_base
()
!=
NULL
)
{
if
(
last_expectation_
->
expectation_base
()
!=
nullptr
)
{
expectation
.
expectation_base
()
->
immediate_prerequisites_
+=
*
last_expectation_
;
}
...
...
@@ -848,3 +898,9 @@ InSequence::~InSequence() {
}
}
// namespace testing
#ifdef _MSC_VER
#if _MSC_VER <= 1900
# pragma warning(pop)
#endif
#endif
googlemock/src/gmock.cc
View file @
8c82ba48
...
...
@@ -26,15 +26,14 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
#include "gmock/gmock.h"
#include "gmock/internal/gmock-port.h"
namespace
testing
{
//
TODO(wan@google.com)
: support using environment variables to
//
FIXME
: support using environment variables to
// control the flag values, like what Google Test does.
GMOCK_DEFINE_bool_
(
catch_leaked_mocks
,
true
,
...
...
@@ -48,6 +47,13 @@ GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
" warning - prints warnings and errors.
\n
"
" error - prints errors only."
);
GMOCK_DEFINE_int32_
(
default_mock_behavior
,
1
,
"Controls the default behavior of mocks."
" Valid values:
\n
"
" 0 - by default, mocks act as NiceMocks.
\n
"
" 1 - by default, mocks act as NaggyMocks.
\n
"
" 2 - by default, mocks act as StrictMocks."
);
namespace
internal
{
// Parses a string as a command line flag. The string should have the
...
...
@@ -59,12 +65,12 @@ static const char* ParseGoogleMockFlagValue(const char* str,
const
char
*
flag
,
bool
def_optional
)
{
// str and flag must not be NULL.
if
(
str
==
NULL
||
flag
==
NULL
)
return
NULL
;
if
(
str
==
nullptr
||
flag
==
nullptr
)
return
nullptr
;
// The flag must start with "--gmock_".
const
std
::
string
flag_str
=
std
::
string
(
"--gmock_"
)
+
flag
;
const
size_t
flag_len
=
flag_str
.
length
();
if
(
strncmp
(
str
,
flag_str
.
c_str
(),
flag_len
)
!=
0
)
return
NULL
;
if
(
strncmp
(
str
,
flag_str
.
c_str
(),
flag_len
)
!=
0
)
return
nullptr
;
// Skips the flag name.
const
char
*
flag_end
=
str
+
flag_len
;
...
...
@@ -77,7 +83,7 @@ static const char* ParseGoogleMockFlagValue(const char* str,
// If def_optional is true and there are more characters after the
// flag name, or if def_optional is false, there must be a '=' after
// the flag name.
if
(
flag_end
[
0
]
!=
'='
)
return
NULL
;
if
(
flag_end
[
0
]
!=
'='
)
return
nullptr
;
// Returns the string after "=".
return
flag_end
+
1
;
...
...
@@ -94,7 +100,7 @@ static bool ParseGoogleMockBoolFlag(const char* str, const char* flag,
const
char
*
const
value_str
=
ParseGoogleMockFlagValue
(
str
,
flag
,
true
);
// Aborts if the parsing failed.
if
(
value_str
==
NULL
)
return
false
;
if
(
value_str
==
nullptr
)
return
false
;
// Converts the string value to a bool.
*
value
=
!
(
*
value_str
==
'0'
||
*
value_str
==
'f'
||
*
value_str
==
'F'
);
...
...
@@ -113,13 +119,26 @@ static bool ParseGoogleMockStringFlag(const char* str, const char* flag,
const
char
*
const
value_str
=
ParseGoogleMockFlagValue
(
str
,
flag
,
false
);
// Aborts if the parsing failed.
if
(
value_str
==
NULL
)
return
false
;
if
(
value_str
==
nullptr
)
return
false
;
// Sets *value to the value of the flag.
*
value
=
value_str
;
return
true
;
}
static
bool
ParseGoogleMockIntFlag
(
const
char
*
str
,
const
char
*
flag
,
int
*
value
)
{
// Gets the value of the flag as a string.
const
char
*
const
value_str
=
ParseGoogleMockFlagValue
(
str
,
flag
,
true
);
// Aborts if the parsing failed.
if
(
value_str
==
nullptr
)
return
false
;
// Sets *value to the value of the flag.
return
ParseInt32
(
Message
()
<<
"The value of flag --"
<<
flag
,
value_str
,
value
);
}
// The internal implementation of InitGoogleMock().
//
// The type parameter CharType can be instantiated to either char or
...
...
@@ -138,7 +157,9 @@ void InitGoogleMockImpl(int* argc, CharType** argv) {
// Do we see a Google Mock flag?
if
(
ParseGoogleMockBoolFlag
(
arg
,
"catch_leaked_mocks"
,
&
GMOCK_FLAG
(
catch_leaked_mocks
))
||
ParseGoogleMockStringFlag
(
arg
,
"verbose"
,
&
GMOCK_FLAG
(
verbose
)))
{
ParseGoogleMockStringFlag
(
arg
,
"verbose"
,
&
GMOCK_FLAG
(
verbose
))
||
ParseGoogleMockIntFlag
(
arg
,
"default_mock_behavior"
,
&
GMOCK_FLAG
(
default_mock_behavior
)))
{
// Yes. Shift the remainder of the argv list left by one. Note
// that argv has (*argc + 1) elements, the last one always being
// NULL. The following loop moves the trailing NULL element as
...
...
googlemock/src/gmock_main.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
#include <iostream>
#include "gmock/gmock.h"
...
...
@@ -37,7 +36,8 @@
// causes a link error when _tmain is defined in a static library and UNICODE
// is enabled. For this reason instead of _tmain, main function is used on
// Windows. See the following link to track the current status of this bug:
// http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=394464 // NOLINT
// https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library
// // NOLINT
#if GTEST_OS_WINDOWS_MOBILE
# include <tchar.h> // NOLINT
...
...
googlemock/test/BUILD.bazel
0 → 100644
View file @
8c82ba48
# Copyright 2017 Google Inc.
# All Rights Reserved.
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Author: misterg@google.com (Gennadiy Civil)
#
# Bazel Build for Google C++ Testing Framework(Google Test)-googlemock
licenses
([
"notice"
])
""" gmock own tests """
cc_test
(
name
=
"gmock_all_test"
,
size
=
"small"
,
srcs
=
glob
(
include
=
[
"gmock-*.cc"
,
],
),
linkopts
=
select
({
"//:windows"
:
[],
"//:windows_msvc"
:
[],
"//conditions:default"
:
[
"-pthread"
,
],
}),
deps
=
[
"//:gtest"
],
)
# Py tests
py_library
(
name
=
"gmock_test_utils"
,
testonly
=
1
,
srcs
=
[
"gmock_test_utils.py"
],
)
cc_binary
(
name
=
"gmock_leak_test_"
,
testonly
=
1
,
srcs
=
[
"gmock_leak_test_.cc"
],
deps
=
[
"//:gtest_main"
,
],
)
py_test
(
name
=
"gmock_leak_test"
,
size
=
"medium"
,
srcs
=
[
"gmock_leak_test.py"
],
data
=
[
":gmock_leak_test_"
,
":gmock_test_utils"
,
],
)
cc_test
(
name
=
"gmock_link_test"
,
size
=
"small"
,
srcs
=
[
"gmock_link2_test.cc"
,
"gmock_link_test.cc"
,
"gmock_link_test.h"
,
],
deps
=
[
"//:gtest_main"
,
],
)
cc_binary
(
name
=
"gmock_output_test_"
,
srcs
=
[
"gmock_output_test_.cc"
],
deps
=
[
"//:gtest"
,
],
)
py_test
(
name
=
"gmock_output_test"
,
size
=
"medium"
,
srcs
=
[
"gmock_output_test.py"
],
data
=
[
":gmock_output_test_"
,
":gmock_output_test_golden.txt"
,
],
deps
=
[
":gmock_test_utils"
],
)
cc_test
(
name
=
"gmock_test"
,
size
=
"small"
,
srcs
=
[
"gmock_test.cc"
],
deps
=
[
"//:gtest_main"
,
],
)
googlemock/test/gmock-actions_test.cc
View file @
8c82ba48
...
...
@@ -26,13 +26,21 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
// This file tests the built-in actions.
// Silence C4800 (C4800: 'int *const ': forcing value
// to bool 'true' or 'false') for MSVC 14,15
#ifdef _MSC_VER
#if _MSC_VER <= 1900
# pragma warning(push)
# pragma warning(disable:4800)
#endif
#endif
#include "gmock/gmock-actions.h"
#include <algorithm>
#include <iterator>
...
...
@@ -65,28 +73,21 @@ using testing::ReturnRef;
using
testing
::
ReturnRefOfCopy
;
using
testing
::
SetArgPointee
;
using
testing
::
SetArgumentPointee
;
using
testing
::
Unused
;
using
testing
::
_
;
using
testing
::
get
;
using
testing
::
internal
::
BuiltInDefaultValue
;
using
testing
::
internal
::
Int64
;
using
testing
::
internal
::
UInt64
;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
tuple_element
;
#if !GTEST_OS_WINDOWS_MOBILE
using
testing
::
SetErrnoAndReturn
;
#endif
#if GTEST_HAS_PROTOBUF_
using
testing
::
internal
::
TestMessage
;
#endif // GTEST_HAS_PROTOBUF_
// Tests that BuiltInDefaultValue<T*>::Get() returns NULL.
TEST
(
BuiltInDefaultValueTest
,
IsNullForPointerTypes
)
{
EXPECT_TRUE
(
BuiltInDefaultValue
<
int
*>::
Get
()
==
NULL
);
EXPECT_TRUE
(
BuiltInDefaultValue
<
const
char
*>::
Get
()
==
NULL
);
EXPECT_TRUE
(
BuiltInDefaultValue
<
void
*>::
Get
()
==
NULL
);
EXPECT_TRUE
(
BuiltInDefaultValue
<
int
*>::
Get
()
==
nullptr
);
EXPECT_TRUE
(
BuiltInDefaultValue
<
const
char
*>::
Get
()
==
nullptr
);
EXPECT_TRUE
(
BuiltInDefaultValue
<
void
*>::
Get
()
==
nullptr
);
}
// Tests that BuiltInDefaultValue<T*>::Exists() return true.
...
...
@@ -107,7 +108,11 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
wchar_t
>::
Get
());
#endif
#if GMOCK_WCHAR_T_IS_NATIVE_
#if !defined(__WCHAR_UNSIGNED__)
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
wchar_t
>::
Get
());
#else
EXPECT_EQ
(
0U
,
BuiltInDefaultValue
<
wchar_t
>::
Get
());
#endif
#endif
EXPECT_EQ
(
0U
,
BuiltInDefaultValue
<
unsigned
short
>::
Get
());
// NOLINT
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
short
>::
Get
());
// NOLINT
...
...
@@ -187,7 +192,7 @@ TEST(BuiltInDefaultValueTest, ExistsForString) {
TEST
(
BuiltInDefaultValueTest
,
WorksForConstTypes
)
{
EXPECT_EQ
(
""
,
BuiltInDefaultValue
<
const
std
::
string
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
const
int
>::
Get
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
char
*
const
>::
Get
()
==
NULL
);
EXPECT_TRUE
(
BuiltInDefaultValue
<
char
*
const
>::
Get
()
==
nullptr
);
EXPECT_FALSE
(
BuiltInDefaultValue
<
const
bool
>::
Get
());
}
...
...
@@ -214,7 +219,7 @@ class MyNonDefaultConstructible {
int
value_
;
};
#if GTEST_
HAS_STD_TYPE_TRAITS_
#if GTEST_
LANG_CXX11
TEST
(
BuiltInDefaultValueTest
,
ExistsForDefaultConstructibleType
)
{
EXPECT_TRUE
(
BuiltInDefaultValue
<
MyDefaultConstructible
>::
Exists
());
...
...
@@ -224,7 +229,7 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) {
EXPECT_EQ
(
42
,
BuiltInDefaultValue
<
MyDefaultConstructible
>::
Get
().
value
());
}
#endif // GTEST_
HAS_STD_TYPE_TRAITS_
#endif // GTEST_
LANG_CXX11
TEST
(
BuiltInDefaultValueTest
,
DoesNotExistForNonDefaultConstructibleType
)
{
EXPECT_FALSE
(
BuiltInDefaultValue
<
MyNonDefaultConstructible
>::
Exists
());
...
...
@@ -297,7 +302,7 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
#if GTEST_HAS_STD_UNIQUE_PTR_
TEST
(
DefaultValueTest
,
GetWorksForMoveOnlyIfSet
)
{
EXPECT_TRUE
(
DefaultValue
<
std
::
unique_ptr
<
int
>>::
Exists
());
EXPECT_TRUE
(
DefaultValue
<
std
::
unique_ptr
<
int
>>::
Get
()
==
NULL
);
EXPECT_TRUE
(
DefaultValue
<
std
::
unique_ptr
<
int
>>::
Get
()
==
nullptr
);
DefaultValue
<
std
::
unique_ptr
<
int
>>::
SetFactory
([]
{
return
std
::
unique_ptr
<
int
>
(
new
int
(
42
));
});
...
...
@@ -373,8 +378,8 @@ typedef int MyGlobalFunction(bool, int);
class
MyActionImpl
:
public
ActionInterface
<
MyGlobalFunction
>
{
public:
virtual
int
Perform
(
const
tuple
<
bool
,
int
>&
args
)
{
return
get
<
0
>
(
args
)
?
get
<
1
>
(
args
)
:
0
;
virtual
int
Perform
(
const
std
::
tuple
<
bool
,
int
>&
args
)
{
return
std
::
get
<
0
>
(
args
)
?
std
::
get
<
1
>
(
args
)
:
0
;
}
};
...
...
@@ -390,8 +395,8 @@ TEST(ActionInterfaceTest, MakeAction) {
// it a tuple whose size and type are compatible with F's argument
// types. For example, if F is int(), then Perform() takes a
// 0-tuple; if F is void(bool, int), then Perform() takes a
// tuple<bool, int>, and so on.
EXPECT_EQ
(
5
,
action
.
Perform
(
make_tuple
(
true
,
5
)));
//
std::
tuple<bool, int>, and so on.
EXPECT_EQ
(
5
,
action
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
}
// Tests that Action<F> can be contructed from a pointer to
...
...
@@ -404,8 +409,8 @@ TEST(ActionTest, CanBeConstructedFromActionInterface) {
TEST
(
ActionTest
,
DelegatesWorkToActionInterface
)
{
const
Action
<
MyGlobalFunction
>
action
(
new
MyActionImpl
);
EXPECT_EQ
(
5
,
action
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
action
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
action
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
action
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
}
// Tests that Action<F> can be copied.
...
...
@@ -414,22 +419,22 @@ TEST(ActionTest, IsCopyable) {
Action
<
MyGlobalFunction
>
a2
(
a1
);
// Tests the copy constructor.
// a1 should continue to work after being copied from.
EXPECT_EQ
(
5
,
a1
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
// a2 should work like the action it was copied from.
EXPECT_EQ
(
5
,
a2
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
a2
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
a2
=
a1
;
// Tests the assignment operator.
// a1 should continue to work after being copied from.
EXPECT_EQ
(
5
,
a1
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
// a2 should work like the action it was copied from.
EXPECT_EQ
(
5
,
a2
.
Perform
(
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
make_tuple
(
false
,
1
)));
EXPECT_EQ
(
5
,
a2
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
std
::
make_tuple
(
false
,
1
)));
}
// Tests that an Action<From> object can be converted to a
...
...
@@ -437,8 +442,8 @@ TEST(ActionTest, IsCopyable) {
class
IsNotZero
:
public
ActionInterface
<
bool
(
int
)
>
{
// NOLINT
public:
virtual
bool
Perform
(
const
tuple
<
int
>&
arg
)
{
return
get
<
0
>
(
arg
)
!=
0
;
virtual
bool
Perform
(
const
std
::
tuple
<
int
>&
arg
)
{
return
std
::
get
<
0
>
(
arg
)
!=
0
;
}
};
...
...
@@ -451,8 +456,8 @@ class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
TEST
(
ActionTest
,
CanBeConvertedToOtherActionType
)
{
const
Action
<
bool
(
int
)
>
a1
(
new
IsNotZero
);
// NOLINT
const
Action
<
int
(
char
)
>
a2
=
Action
<
int
(
char
)
>
(
a1
);
// NOLINT
EXPECT_EQ
(
1
,
a2
.
Perform
(
make_tuple
(
'a'
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
make_tuple
(
'\0'
)));
EXPECT_EQ
(
1
,
a2
.
Perform
(
std
::
make_tuple
(
'a'
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
std
::
make_tuple
(
'\0'
)));
}
#endif // !GTEST_OS_SYMBIAN
...
...
@@ -466,7 +471,9 @@ class ReturnSecondArgumentAction {
// polymorphic action whose Perform() method template is either
// const or not. This lets us verify the non-const case.
template
<
typename
Result
,
typename
ArgumentTuple
>
Result
Perform
(
const
ArgumentTuple
&
args
)
{
return
get
<
1
>
(
args
);
}
Result
Perform
(
const
ArgumentTuple
&
args
)
{
return
std
::
get
<
1
>
(
args
);
}
};
// Implements a polymorphic action that can be used in a nullary
...
...
@@ -481,7 +488,9 @@ class ReturnZeroFromNullaryFunctionAction {
// polymorphic action whose Perform() method template is either
// const or not. This lets us verify the const case.
template
<
typename
Result
>
Result
Perform
(
const
tuple
<>&
)
const
{
return
0
;
}
Result
Perform
(
const
std
::
tuple
<>&
)
const
{
return
0
;
}
};
// These functions verify that MakePolymorphicAction() returns a
...
...
@@ -500,42 +509,42 @@ ReturnZeroFromNullaryFunction() {
// implementation class into a polymorphic action.
TEST
(
MakePolymorphicActionTest
,
ConstructsActionFromImpl
)
{
Action
<
int
(
bool
,
int
,
double
)
>
a1
=
ReturnSecondArgument
();
// NOLINT
EXPECT_EQ
(
5
,
a1
.
Perform
(
make_tuple
(
false
,
5
,
2.0
)));
EXPECT_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
5
,
2.0
)));
}
// Tests that MakePolymorphicAction() works when the implementation
// class' Perform() method template has only one template parameter.
TEST
(
MakePolymorphicActionTest
,
WorksWhenPerformHasOneTemplateParameter
)
{
Action
<
int
()
>
a1
=
ReturnZeroFromNullaryFunction
();
EXPECT_EQ
(
0
,
a1
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
0
,
a1
.
Perform
(
std
::
make_tuple
()));
Action
<
void
*
()
>
a2
=
ReturnZeroFromNullaryFunction
();
EXPECT_TRUE
(
a2
.
Perform
(
make_tuple
())
==
NULL
);
EXPECT_TRUE
(
a2
.
Perform
(
std
::
make_tuple
())
==
nullptr
);
}
// Tests that Return() works as an action for void-returning
// functions.
TEST
(
ReturnTest
,
WorksForVoid
)
{
const
Action
<
void
(
int
)
>
ret
=
Return
();
// NOLINT
return
ret
.
Perform
(
make_tuple
(
1
));
return
ret
.
Perform
(
std
::
make_tuple
(
1
));
}
// Tests that Return(v) returns v.
TEST
(
ReturnTest
,
ReturnsGivenValue
)
{
Action
<
int
()
>
ret
=
Return
(
1
);
// NOLINT
EXPECT_EQ
(
1
,
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
1
,
ret
.
Perform
(
std
::
make_tuple
()));
ret
=
Return
(
-
5
);
EXPECT_EQ
(
-
5
,
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
-
5
,
ret
.
Perform
(
std
::
make_tuple
()));
}
// Tests that Return("string literal") works.
TEST
(
ReturnTest
,
AcceptsStringLiteral
)
{
Action
<
const
char
*
()
>
a1
=
Return
(
"Hello"
);
EXPECT_STREQ
(
"Hello"
,
a1
.
Perform
(
make_tuple
()));
EXPECT_STREQ
(
"Hello"
,
a1
.
Perform
(
std
::
make_tuple
()));
Action
<
std
::
string
()
>
a2
=
Return
(
"world"
);
EXPECT_EQ
(
"world"
,
a2
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
"world"
,
a2
.
Perform
(
std
::
make_tuple
()));
}
// Test struct which wraps a vector of integers. Used in
...
...
@@ -554,7 +563,7 @@ TEST(ReturnTest, SupportsWrapperReturnType) {
// Return() called with 'v' as argument. The Action will return the same data
// as 'v' (copy) but it will be wrapped in an IntegerVectorWrapper.
Action
<
IntegerVectorWrapper
()
>
a
=
Return
(
v
);
const
std
::
vector
<
int
>&
result
=
*
(
a
.
Perform
(
make_tuple
()).
v
);
const
std
::
vector
<
int
>&
result
=
*
(
a
.
Perform
(
std
::
make_tuple
()).
v
);
EXPECT_THAT
(
result
,
::
testing
::
ElementsAre
(
0
,
1
,
2
,
3
,
4
));
}
...
...
@@ -572,10 +581,10 @@ TEST(ReturnTest, IsCovariant) {
Base
base
;
Derived
derived
;
Action
<
Base
*
()
>
ret
=
Return
(
&
base
);
EXPECT_EQ
(
&
base
,
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
base
,
ret
.
Perform
(
std
::
make_tuple
()));
ret
=
Return
(
&
derived
);
EXPECT_EQ
(
&
derived
,
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
derived
,
ret
.
Perform
(
std
::
make_tuple
()));
}
// Tests that the type of the value passed into Return is converted into T
...
...
@@ -606,7 +615,7 @@ TEST(ReturnTest, ConvertsArgumentWhenConverted) {
EXPECT_TRUE
(
converted
)
<<
"Return must convert its argument in its own "
<<
"conversion operator."
;
converted
=
false
;
action
.
Perform
(
tuple
<>
());
action
.
Perform
(
std
::
tuple
<>
());
EXPECT_FALSE
(
converted
)
<<
"Action must NOT convert its argument "
<<
"when performed."
;
}
...
...
@@ -627,10 +636,10 @@ TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) {
// Tests that ReturnNull() returns NULL in a pointer-returning function.
TEST
(
ReturnNullTest
,
WorksInPointerReturningFunction
)
{
const
Action
<
int
*
()
>
a1
=
ReturnNull
();
EXPECT_TRUE
(
a1
.
Perform
(
make_tuple
())
==
NULL
);
EXPECT_TRUE
(
a1
.
Perform
(
std
::
make_tuple
())
==
nullptr
);
const
Action
<
const
char
*
(
bool
)
>
a2
=
ReturnNull
();
// NOLINT
EXPECT_TRUE
(
a2
.
Perform
(
make_tuple
(
true
))
==
NULL
);
EXPECT_TRUE
(
a2
.
Perform
(
std
::
make_tuple
(
true
))
==
nullptr
);
}
#if GTEST_HAS_STD_UNIQUE_PTR_
...
...
@@ -638,10 +647,10 @@ TEST(ReturnNullTest, WorksInPointerReturningFunction) {
// functions.
TEST
(
ReturnNullTest
,
WorksInSmartPointerReturningFunction
)
{
const
Action
<
std
::
unique_ptr
<
const
int
>
()
>
a1
=
ReturnNull
();
EXPECT_TRUE
(
a1
.
Perform
(
make_tuple
())
==
nullptr
);
EXPECT_TRUE
(
a1
.
Perform
(
std
::
make_tuple
())
==
nullptr
);
const
Action
<
std
::
shared_ptr
<
int
>
(
std
::
string
)
>
a2
=
ReturnNull
();
EXPECT_TRUE
(
a2
.
Perform
(
make_tuple
(
"foo"
))
==
nullptr
);
EXPECT_TRUE
(
a2
.
Perform
(
std
::
make_tuple
(
"foo"
))
==
nullptr
);
}
#endif // GTEST_HAS_STD_UNIQUE_PTR_
...
...
@@ -650,7 +659,7 @@ TEST(ReturnRefTest, WorksForReference) {
const
int
n
=
0
;
const
Action
<
const
int
&
(
bool
)
>
ret
=
ReturnRef
(
n
);
// NOLINT
EXPECT_EQ
(
&
n
,
&
ret
.
Perform
(
make_tuple
(
true
)));
EXPECT_EQ
(
&
n
,
&
ret
.
Perform
(
std
::
make_tuple
(
true
)));
}
// Tests that ReturnRef(v) is covariant.
...
...
@@ -658,10 +667,10 @@ TEST(ReturnRefTest, IsCovariant) {
Base
base
;
Derived
derived
;
Action
<
Base
&
()
>
a
=
ReturnRef
(
base
);
EXPECT_EQ
(
&
base
,
&
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
base
,
&
a
.
Perform
(
std
::
make_tuple
()));
a
=
ReturnRef
(
derived
);
EXPECT_EQ
(
&
derived
,
&
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
derived
,
&
a
.
Perform
(
std
::
make_tuple
()));
}
// Tests that ReturnRefOfCopy(v) works for reference types.
...
...
@@ -669,12 +678,12 @@ TEST(ReturnRefOfCopyTest, WorksForReference) {
int
n
=
42
;
const
Action
<
const
int
&
()
>
ret
=
ReturnRefOfCopy
(
n
);
EXPECT_NE
(
&
n
,
&
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
42
,
ret
.
Perform
(
make_tuple
()));
EXPECT_NE
(
&
n
,
&
ret
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
42
,
ret
.
Perform
(
std
::
make_tuple
()));
n
=
43
;
EXPECT_NE
(
&
n
,
&
ret
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
42
,
ret
.
Perform
(
make_tuple
()));
EXPECT_NE
(
&
n
,
&
ret
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
42
,
ret
.
Perform
(
std
::
make_tuple
()));
}
// Tests that ReturnRefOfCopy(v) is covariant.
...
...
@@ -682,10 +691,10 @@ TEST(ReturnRefOfCopyTest, IsCovariant) {
Base
base
;
Derived
derived
;
Action
<
Base
&
()
>
a
=
ReturnRefOfCopy
(
base
);
EXPECT_NE
(
&
base
,
&
a
.
Perform
(
make_tuple
()));
EXPECT_NE
(
&
base
,
&
a
.
Perform
(
std
::
make_tuple
()));
a
=
ReturnRefOfCopy
(
derived
);
EXPECT_NE
(
&
derived
,
&
a
.
Perform
(
make_tuple
()));
EXPECT_NE
(
&
derived
,
&
a
.
Perform
(
std
::
make_tuple
()));
}
// Tests that DoDefault() does the default action for the mock method.
...
...
@@ -700,6 +709,9 @@ class MockClass {
MOCK_METHOD0
(
MakeUnique
,
std
::
unique_ptr
<
int
>
());
MOCK_METHOD0
(
MakeUniqueBase
,
std
::
unique_ptr
<
Base
>
());
MOCK_METHOD0
(
MakeVectorUnique
,
std
::
vector
<
std
::
unique_ptr
<
int
>>
());
MOCK_METHOD1
(
TakeUnique
,
int
(
std
::
unique_ptr
<
int
>
));
MOCK_METHOD2
(
TakeUnique
,
int
(
const
std
::
unique_ptr
<
int
>&
,
std
::
unique_ptr
<
int
>
));
#endif
private:
...
...
@@ -788,14 +800,14 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) {
int
n
=
0
;
char
ch
=
'\0'
;
a
.
Perform
(
make_tuple
(
true
,
&
n
,
&
ch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
n
,
&
ch
));
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'\0'
,
ch
);
a
=
SetArgPointee
<
2
>
(
'a'
);
n
=
0
;
ch
=
'\0'
;
a
.
Perform
(
make_tuple
(
true
,
&
n
,
&
ch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
n
,
&
ch
));
EXPECT_EQ
(
0
,
n
);
EXPECT_EQ
(
'a'
,
ch
);
}
...
...
@@ -807,14 +819,14 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) {
typedef
void
MyFunction
(
std
::
string
*
,
const
char
**
);
Action
<
MyFunction
>
a
=
SetArgPointee
<
0
>
(
"hi"
);
std
::
string
str
;
const
char
*
ptr
=
NULL
;
a
.
Perform
(
make_tuple
(
&
str
,
&
ptr
));
const
char
*
ptr
=
nullptr
;
a
.
Perform
(
std
::
make_tuple
(
&
str
,
&
ptr
));
EXPECT_EQ
(
"hi"
,
str
);
EXPECT_TRUE
(
ptr
==
NULL
);
EXPECT_TRUE
(
ptr
==
nullptr
);
a
=
SetArgPointee
<
1
>
(
"world"
);
str
=
""
;
a
.
Perform
(
make_tuple
(
&
str
,
&
ptr
));
a
.
Perform
(
std
::
make_tuple
(
&
str
,
&
ptr
));
EXPECT_EQ
(
""
,
str
);
EXPECT_STREQ
(
"world"
,
ptr
);
}
...
...
@@ -822,8 +834,8 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) {
TEST
(
SetArgPointeeTest
,
AcceptsWideStringLiteral
)
{
typedef
void
MyFunction
(
const
wchar_t
**
);
Action
<
MyFunction
>
a
=
SetArgPointee
<
0
>
(
L"world"
);
const
wchar_t
*
ptr
=
NULL
;
a
.
Perform
(
make_tuple
(
&
ptr
));
const
wchar_t
*
ptr
=
nullptr
;
a
.
Perform
(
std
::
make_tuple
(
&
ptr
));
EXPECT_STREQ
(
L"world"
,
ptr
);
# if GTEST_HAS_STD_WSTRING
...
...
@@ -831,7 +843,7 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
typedef
void
MyStringFunction
(
std
::
wstring
*
);
Action
<
MyStringFunction
>
a2
=
SetArgPointee
<
0
>
(
L"world"
);
std
::
wstring
str
=
L""
;
a2
.
Perform
(
make_tuple
(
&
str
));
a2
.
Perform
(
std
::
make_tuple
(
&
str
));
EXPECT_EQ
(
L"world"
,
str
);
# endif
...
...
@@ -844,16 +856,16 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) {
const
char
*
const
hi
=
"hi"
;
Action
<
MyFunction
>
a
=
SetArgPointee
<
1
>
(
hi
);
std
::
string
str
;
const
char
*
ptr
=
NULL
;
a
.
Perform
(
make_tuple
(
true
,
&
str
,
&
ptr
));
const
char
*
ptr
=
nullptr
;
a
.
Perform
(
std
::
make_tuple
(
true
,
&
str
,
&
ptr
));
EXPECT_EQ
(
"hi"
,
str
);
EXPECT_TRUE
(
ptr
==
NULL
);
EXPECT_TRUE
(
ptr
==
nullptr
);
char
world_array
[]
=
"world"
;
char
*
const
world
=
world_array
;
a
=
SetArgPointee
<
2
>
(
world
);
str
=
""
;
a
.
Perform
(
make_tuple
(
true
,
&
str
,
&
ptr
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
str
,
&
ptr
));
EXPECT_EQ
(
""
,
str
);
EXPECT_EQ
(
world
,
ptr
);
}
...
...
@@ -862,8 +874,8 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
typedef
void
MyFunction
(
bool
,
const
wchar_t
**
);
const
wchar_t
*
const
hi
=
L"hi"
;
Action
<
MyFunction
>
a
=
SetArgPointee
<
1
>
(
hi
);
const
wchar_t
*
ptr
=
NULL
;
a
.
Perform
(
make_tuple
(
true
,
&
ptr
));
const
wchar_t
*
ptr
=
nullptr
;
a
.
Perform
(
std
::
make_tuple
(
true
,
&
ptr
));
EXPECT_EQ
(
hi
,
ptr
);
# if GTEST_HAS_STD_WSTRING
...
...
@@ -873,110 +885,11 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
wchar_t
*
const
world
=
world_array
;
Action
<
MyStringFunction
>
a2
=
SetArgPointee
<
1
>
(
world
);
std
::
wstring
str
;
a2
.
Perform
(
make_tuple
(
true
,
&
str
));
a2
.
Perform
(
std
::
make_tuple
(
true
,
&
str
));
EXPECT_EQ
(
world_array
,
str
);
# endif
}
#if GTEST_HAS_PROTOBUF_
// Tests that SetArgPointee<N>(proto_buffer) sets the v1 protobuf
// variable pointed to by the N-th (0-based) argument to proto_buffer.
TEST
(
SetArgPointeeTest
,
SetsTheNthPointeeOfProtoBufferType
)
{
TestMessage
*
const
msg
=
new
TestMessage
;
msg
->
set_member
(
"yes"
);
TestMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
TestMessage
*
)
>
a
=
SetArgPointee
<
1
>
(
*
msg
);
// SetArgPointee<N>(proto_buffer) makes a copy of proto_buffer
// s.t. the action works even when the original proto_buffer has
// died. We ensure this behavior by deleting msg before using the
// action.
delete
msg
;
TestMessage
dest
;
EXPECT_FALSE
(
orig_msg
.
Equals
(
dest
));
a
.
Perform
(
make_tuple
(
true
,
&
dest
));
EXPECT_TRUE
(
orig_msg
.
Equals
(
dest
));
}
// Tests that SetArgPointee<N>(proto_buffer) sets the
// ::ProtocolMessage variable pointed to by the N-th (0-based)
// argument to proto_buffer.
TEST
(
SetArgPointeeTest
,
SetsTheNthPointeeOfProtoBufferBaseType
)
{
TestMessage
*
const
msg
=
new
TestMessage
;
msg
->
set_member
(
"yes"
);
TestMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
::
ProtocolMessage
*
)
>
a
=
SetArgPointee
<
1
>
(
*
msg
);
// SetArgPointee<N>(proto_buffer) makes a copy of proto_buffer
// s.t. the action works even when the original proto_buffer has
// died. We ensure this behavior by deleting msg before using the
// action.
delete
msg
;
TestMessage
dest
;
::
ProtocolMessage
*
const
dest_base
=
&
dest
;
EXPECT_FALSE
(
orig_msg
.
Equals
(
dest
));
a
.
Perform
(
make_tuple
(
true
,
dest_base
));
EXPECT_TRUE
(
orig_msg
.
Equals
(
dest
));
}
// Tests that SetArgPointee<N>(proto2_buffer) sets the v2
// protobuf variable pointed to by the N-th (0-based) argument to
// proto2_buffer.
TEST
(
SetArgPointeeTest
,
SetsTheNthPointeeOfProto2BufferType
)
{
using
testing
::
internal
::
FooMessage
;
FooMessage
*
const
msg
=
new
FooMessage
;
msg
->
set_int_field
(
2
);
msg
->
set_string_field
(
"hi"
);
FooMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
FooMessage
*
)
>
a
=
SetArgPointee
<
1
>
(
*
msg
);
// SetArgPointee<N>(proto2_buffer) makes a copy of
// proto2_buffer s.t. the action works even when the original
// proto2_buffer has died. We ensure this behavior by deleting msg
// before using the action.
delete
msg
;
FooMessage
dest
;
dest
.
set_int_field
(
0
);
a
.
Perform
(
make_tuple
(
true
,
&
dest
));
EXPECT_EQ
(
2
,
dest
.
int_field
());
EXPECT_EQ
(
"hi"
,
dest
.
string_field
());
}
// Tests that SetArgPointee<N>(proto2_buffer) sets the
// proto2::Message variable pointed to by the N-th (0-based) argument
// to proto2_buffer.
TEST
(
SetArgPointeeTest
,
SetsTheNthPointeeOfProto2BufferBaseType
)
{
using
testing
::
internal
::
FooMessage
;
FooMessage
*
const
msg
=
new
FooMessage
;
msg
->
set_int_field
(
2
);
msg
->
set_string_field
(
"hi"
);
FooMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
::
proto2
::
Message
*
)
>
a
=
SetArgPointee
<
1
>
(
*
msg
);
// SetArgPointee<N>(proto2_buffer) makes a copy of
// proto2_buffer s.t. the action works even when the original
// proto2_buffer has died. We ensure this behavior by deleting msg
// before using the action.
delete
msg
;
FooMessage
dest
;
dest
.
set_int_field
(
0
);
::
proto2
::
Message
*
const
dest_base
=
&
dest
;
a
.
Perform
(
make_tuple
(
true
,
dest_base
));
EXPECT_EQ
(
2
,
dest
.
int_field
());
EXPECT_EQ
(
"hi"
,
dest
.
string_field
());
}
#endif // GTEST_HAS_PROTOBUF_
// Tests that SetArgumentPointee<N>(v) sets the variable pointed to by
// the N-th (0-based) argument to v.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointee
)
{
...
...
@@ -985,117 +898,18 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
int
n
=
0
;
char
ch
=
'\0'
;
a
.
Perform
(
make_tuple
(
true
,
&
n
,
&
ch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
n
,
&
ch
));
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'\0'
,
ch
);
a
=
SetArgumentPointee
<
2
>
(
'a'
);
n
=
0
;
ch
=
'\0'
;
a
.
Perform
(
make_tuple
(
true
,
&
n
,
&
ch
));
a
.
Perform
(
std
::
make_tuple
(
true
,
&
n
,
&
ch
));
EXPECT_EQ
(
0
,
n
);
EXPECT_EQ
(
'a'
,
ch
);
}
#if GTEST_HAS_PROTOBUF_
// Tests that SetArgumentPointee<N>(proto_buffer) sets the v1 protobuf
// variable pointed to by the N-th (0-based) argument to proto_buffer.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointeeOfProtoBufferType
)
{
TestMessage
*
const
msg
=
new
TestMessage
;
msg
->
set_member
(
"yes"
);
TestMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
TestMessage
*
)
>
a
=
SetArgumentPointee
<
1
>
(
*
msg
);
// SetArgumentPointee<N>(proto_buffer) makes a copy of proto_buffer
// s.t. the action works even when the original proto_buffer has
// died. We ensure this behavior by deleting msg before using the
// action.
delete
msg
;
TestMessage
dest
;
EXPECT_FALSE
(
orig_msg
.
Equals
(
dest
));
a
.
Perform
(
make_tuple
(
true
,
&
dest
));
EXPECT_TRUE
(
orig_msg
.
Equals
(
dest
));
}
// Tests that SetArgumentPointee<N>(proto_buffer) sets the
// ::ProtocolMessage variable pointed to by the N-th (0-based)
// argument to proto_buffer.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointeeOfProtoBufferBaseType
)
{
TestMessage
*
const
msg
=
new
TestMessage
;
msg
->
set_member
(
"yes"
);
TestMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
::
ProtocolMessage
*
)
>
a
=
SetArgumentPointee
<
1
>
(
*
msg
);
// SetArgumentPointee<N>(proto_buffer) makes a copy of proto_buffer
// s.t. the action works even when the original proto_buffer has
// died. We ensure this behavior by deleting msg before using the
// action.
delete
msg
;
TestMessage
dest
;
::
ProtocolMessage
*
const
dest_base
=
&
dest
;
EXPECT_FALSE
(
orig_msg
.
Equals
(
dest
));
a
.
Perform
(
make_tuple
(
true
,
dest_base
));
EXPECT_TRUE
(
orig_msg
.
Equals
(
dest
));
}
// Tests that SetArgumentPointee<N>(proto2_buffer) sets the v2
// protobuf variable pointed to by the N-th (0-based) argument to
// proto2_buffer.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointeeOfProto2BufferType
)
{
using
testing
::
internal
::
FooMessage
;
FooMessage
*
const
msg
=
new
FooMessage
;
msg
->
set_int_field
(
2
);
msg
->
set_string_field
(
"hi"
);
FooMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
FooMessage
*
)
>
a
=
SetArgumentPointee
<
1
>
(
*
msg
);
// SetArgumentPointee<N>(proto2_buffer) makes a copy of
// proto2_buffer s.t. the action works even when the original
// proto2_buffer has died. We ensure this behavior by deleting msg
// before using the action.
delete
msg
;
FooMessage
dest
;
dest
.
set_int_field
(
0
);
a
.
Perform
(
make_tuple
(
true
,
&
dest
));
EXPECT_EQ
(
2
,
dest
.
int_field
());
EXPECT_EQ
(
"hi"
,
dest
.
string_field
());
}
// Tests that SetArgumentPointee<N>(proto2_buffer) sets the
// proto2::Message variable pointed to by the N-th (0-based) argument
// to proto2_buffer.
TEST
(
SetArgumentPointeeTest
,
SetsTheNthPointeeOfProto2BufferBaseType
)
{
using
testing
::
internal
::
FooMessage
;
FooMessage
*
const
msg
=
new
FooMessage
;
msg
->
set_int_field
(
2
);
msg
->
set_string_field
(
"hi"
);
FooMessage
orig_msg
;
orig_msg
.
CopyFrom
(
*
msg
);
Action
<
void
(
bool
,
::
proto2
::
Message
*
)
>
a
=
SetArgumentPointee
<
1
>
(
*
msg
);
// SetArgumentPointee<N>(proto2_buffer) makes a copy of
// proto2_buffer s.t. the action works even when the original
// proto2_buffer has died. We ensure this behavior by deleting msg
// before using the action.
delete
msg
;
FooMessage
dest
;
dest
.
set_int_field
(
0
);
::
proto2
::
Message
*
const
dest_base
=
&
dest
;
a
.
Perform
(
make_tuple
(
true
,
dest_base
));
EXPECT_EQ
(
2
,
dest
.
int_field
());
EXPECT_EQ
(
"hi"
,
dest
.
string_field
());
}
#endif // GTEST_HAS_PROTOBUF_
// Sample functions and functors for testing Invoke() and etc.
int
Nullary
()
{
return
1
;
}
...
...
@@ -1126,16 +940,16 @@ class Foo {
TEST
(
InvokeWithoutArgsTest
,
Function
)
{
// As an action that takes one argument.
Action
<
int
(
int
)
>
a
=
InvokeWithoutArgs
(
Nullary
);
// NOLINT
EXPECT_EQ
(
1
,
a
.
Perform
(
make_tuple
(
2
)));
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
(
2
)));
// As an action that takes two arguments.
Action
<
int
(
int
,
double
)
>
a2
=
InvokeWithoutArgs
(
Nullary
);
// NOLINT
EXPECT_EQ
(
1
,
a2
.
Perform
(
make_tuple
(
2
,
3.5
)));
EXPECT_EQ
(
1
,
a2
.
Perform
(
std
::
make_tuple
(
2
,
3.5
)));
// As an action that returns void.
Action
<
void
(
int
)
>
a3
=
InvokeWithoutArgs
(
VoidNullary
);
// NOLINT
g_done
=
false
;
a3
.
Perform
(
make_tuple
(
1
));
a3
.
Perform
(
std
::
make_tuple
(
1
));
EXPECT_TRUE
(
g_done
);
}
...
...
@@ -1143,17 +957,17 @@ TEST(InvokeWithoutArgsTest, Function) {
TEST
(
InvokeWithoutArgsTest
,
Functor
)
{
// As an action that takes no argument.
Action
<
int
()
>
a
=
InvokeWithoutArgs
(
NullaryFunctor
());
// NOLINT
EXPECT_EQ
(
2
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
2
,
a
.
Perform
(
std
::
make_tuple
()));
// As an action that takes three arguments.
Action
<
int
(
int
,
double
,
char
)
>
a2
=
// NOLINT
InvokeWithoutArgs
(
NullaryFunctor
());
EXPECT_EQ
(
2
,
a2
.
Perform
(
make_tuple
(
3
,
3.5
,
'a'
)));
EXPECT_EQ
(
2
,
a2
.
Perform
(
std
::
make_tuple
(
3
,
3.5
,
'a'
)));
// As an action that returns void.
Action
<
void
()
>
a3
=
InvokeWithoutArgs
(
VoidNullaryFunctor
());
g_done
=
false
;
a3
.
Perform
(
make_tuple
());
a3
.
Perform
(
std
::
make_tuple
());
EXPECT_TRUE
(
g_done
);
}
...
...
@@ -1162,13 +976,13 @@ TEST(InvokeWithoutArgsTest, Method) {
Foo
foo
;
Action
<
int
(
bool
,
char
)
>
a
=
// NOLINT
InvokeWithoutArgs
(
&
foo
,
&
Foo
::
Nullary
);
EXPECT_EQ
(
123
,
a
.
Perform
(
make_tuple
(
true
,
'a'
)));
EXPECT_EQ
(
123
,
a
.
Perform
(
std
::
make_tuple
(
true
,
'a'
)));
}
// Tests using IgnoreResult() on a polymorphic action.
TEST
(
IgnoreResultTest
,
PolymorphicAction
)
{
Action
<
void
(
int
)
>
a
=
IgnoreResult
(
Return
(
5
));
// NOLINT
a
.
Perform
(
make_tuple
(
1
));
a
.
Perform
(
std
::
make_tuple
(
1
));
}
// Tests using IgnoreResult() on a monomorphic action.
...
...
@@ -1181,7 +995,7 @@ int ReturnOne() {
TEST
(
IgnoreResultTest
,
MonomorphicAction
)
{
g_done
=
false
;
Action
<
void
()
>
a
=
IgnoreResult
(
Invoke
(
ReturnOne
));
a
.
Perform
(
make_tuple
());
a
.
Perform
(
std
::
make_tuple
());
EXPECT_TRUE
(
g_done
);
}
...
...
@@ -1196,28 +1010,28 @@ TEST(IgnoreResultTest, ActionReturningClass) {
g_done
=
false
;
Action
<
void
(
int
)
>
a
=
IgnoreResult
(
Invoke
(
ReturnMyNonDefaultConstructible
));
// NOLINT
a
.
Perform
(
make_tuple
(
2
));
a
.
Perform
(
std
::
make_tuple
(
2
));
EXPECT_TRUE
(
g_done
);
}
TEST
(
AssignTest
,
Int
)
{
int
x
=
0
;
Action
<
void
(
int
)
>
a
=
Assign
(
&
x
,
5
);
a
.
Perform
(
make_tuple
(
0
));
a
.
Perform
(
std
::
make_tuple
(
0
));
EXPECT_EQ
(
5
,
x
);
}
TEST
(
AssignTest
,
String
)
{
::
std
::
string
x
;
Action
<
void
(
void
)
>
a
=
Assign
(
&
x
,
"Hello, world"
);
a
.
Perform
(
make_tuple
());
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
"Hello, world"
,
x
);
}
TEST
(
AssignTest
,
CompatibleTypes
)
{
double
x
=
0
;
Action
<
void
(
int
)
>
a
=
Assign
(
&
x
,
5
);
a
.
Perform
(
make_tuple
(
0
));
a
.
Perform
(
std
::
make_tuple
(
0
));
EXPECT_DOUBLE_EQ
(
5
,
x
);
}
...
...
@@ -1231,20 +1045,20 @@ class SetErrnoAndReturnTest : public testing::Test {
TEST_F
(
SetErrnoAndReturnTest
,
Int
)
{
Action
<
int
(
void
)
>
a
=
SetErrnoAndReturn
(
ENOTTY
,
-
5
);
EXPECT_EQ
(
-
5
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
-
5
,
a
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
ENOTTY
,
errno
);
}
TEST_F
(
SetErrnoAndReturnTest
,
Ptr
)
{
int
x
;
Action
<
int
*
(
void
)
>
a
=
SetErrnoAndReturn
(
ENOTTY
,
&
x
);
EXPECT_EQ
(
&
x
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
&
x
,
a
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
ENOTTY
,
errno
);
}
TEST_F
(
SetErrnoAndReturnTest
,
CompatibleTypes
)
{
Action
<
double
()
>
a
=
SetErrnoAndReturn
(
EINVAL
,
5
);
EXPECT_DOUBLE_EQ
(
5.0
,
a
.
Perform
(
make_tuple
()));
EXPECT_DOUBLE_EQ
(
5.0
,
a
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
EINVAL
,
errno
);
}
...
...
@@ -1406,6 +1220,153 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) {
EXPECT_EQ
(
7
,
*
vresult
[
0
]);
}
TEST
(
MockMethodTest
,
CanTakeMoveOnlyValue
)
{
MockClass
mock
;
auto
make
=
[](
int
i
)
{
return
std
::
unique_ptr
<
int
>
(
new
int
(
i
));
};
EXPECT_CALL
(
mock
,
TakeUnique
(
_
)).
WillRepeatedly
([](
std
::
unique_ptr
<
int
>
i
)
{
return
*
i
;
});
// DoAll() does not compile, since it would move from its arguments twice.
// EXPECT_CALL(mock, TakeUnique(_, _))
// .WillRepeatedly(DoAll(Invoke([](std::unique_ptr<int> j) {}),
// Return(1)));
EXPECT_CALL
(
mock
,
TakeUnique
(
testing
::
Pointee
(
7
)))
.
WillOnce
(
Return
(
-
7
))
.
RetiresOnSaturation
();
EXPECT_CALL
(
mock
,
TakeUnique
(
testing
::
IsNull
()))
.
WillOnce
(
Return
(
-
1
))
.
RetiresOnSaturation
();
EXPECT_EQ
(
5
,
mock
.
TakeUnique
(
make
(
5
)));
EXPECT_EQ
(
-
7
,
mock
.
TakeUnique
(
make
(
7
)));
EXPECT_EQ
(
7
,
mock
.
TakeUnique
(
make
(
7
)));
EXPECT_EQ
(
7
,
mock
.
TakeUnique
(
make
(
7
)));
EXPECT_EQ
(
-
1
,
mock
.
TakeUnique
({}));
// Some arguments are moved, some passed by reference.
auto
lvalue
=
make
(
6
);
EXPECT_CALL
(
mock
,
TakeUnique
(
_
,
_
))
.
WillOnce
([](
const
std
::
unique_ptr
<
int
>&
i
,
std
::
unique_ptr
<
int
>
j
)
{
return
*
i
*
*
j
;
});
EXPECT_EQ
(
42
,
mock
.
TakeUnique
(
lvalue
,
make
(
7
)));
// The unique_ptr can be saved by the action.
std
::
unique_ptr
<
int
>
saved
;
EXPECT_CALL
(
mock
,
TakeUnique
(
_
)).
WillOnce
([
&
saved
](
std
::
unique_ptr
<
int
>
i
)
{
saved
=
std
::
move
(
i
);
return
0
;
});
EXPECT_EQ
(
0
,
mock
.
TakeUnique
(
make
(
42
)));
EXPECT_EQ
(
42
,
*
saved
);
}
#endif // GTEST_HAS_STD_UNIQUE_PTR_
#if GTEST_LANG_CXX11
// Tests for std::function based action.
int
Add
(
int
val
,
int
&
ref
,
int
*
ptr
)
{
// NOLINT
int
result
=
val
+
ref
+
*
ptr
;
ref
=
42
;
*
ptr
=
43
;
return
result
;
}
int
Deref
(
std
::
unique_ptr
<
int
>
ptr
)
{
return
*
ptr
;
}
struct
Double
{
template
<
typename
T
>
T
operator
()(
T
t
)
{
return
2
*
t
;
}
};
std
::
unique_ptr
<
int
>
UniqueInt
(
int
i
)
{
return
std
::
unique_ptr
<
int
>
(
new
int
(
i
));
}
TEST
(
FunctorActionTest
,
ActionFromFunction
)
{
Action
<
int
(
int
,
int
&
,
int
*
)
>
a
=
&
Add
;
int
x
=
1
,
y
=
2
,
z
=
3
;
EXPECT_EQ
(
6
,
a
.
Perform
(
std
::
forward_as_tuple
(
x
,
y
,
&
z
)));
EXPECT_EQ
(
42
,
y
);
EXPECT_EQ
(
43
,
z
);
Action
<
int
(
std
::
unique_ptr
<
int
>
)
>
a1
=
&
Deref
;
EXPECT_EQ
(
7
,
a1
.
Perform
(
std
::
make_tuple
(
UniqueInt
(
7
))));
}
TEST
(
FunctorActionTest
,
ActionFromLambda
)
{
Action
<
int
(
bool
,
int
)
>
a1
=
[](
bool
b
,
int
i
)
{
return
b
?
i
:
0
;
};
EXPECT_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
(
true
,
5
)));
EXPECT_EQ
(
0
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
5
)));
std
::
unique_ptr
<
int
>
saved
;
Action
<
void
(
std
::
unique_ptr
<
int
>
)
>
a2
=
[
&
saved
](
std
::
unique_ptr
<
int
>
p
)
{
saved
=
std
::
move
(
p
);
};
a2
.
Perform
(
std
::
make_tuple
(
UniqueInt
(
5
)));
EXPECT_EQ
(
5
,
*
saved
);
}
TEST
(
FunctorActionTest
,
PolymorphicFunctor
)
{
Action
<
int
(
int
)
>
ai
=
Double
();
EXPECT_EQ
(
2
,
ai
.
Perform
(
std
::
make_tuple
(
1
)));
Action
<
double
(
double
)
>
ad
=
Double
();
// Double? Double double!
EXPECT_EQ
(
3.0
,
ad
.
Perform
(
std
::
make_tuple
(
1.5
)));
}
TEST
(
FunctorActionTest
,
TypeConversion
)
{
// Numeric promotions are allowed.
const
Action
<
bool
(
int
)
>
a1
=
[](
int
i
)
{
return
i
>
1
;
};
const
Action
<
int
(
bool
)
>
a2
=
Action
<
int
(
bool
)
>
(
a1
);
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
42
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
std
::
make_tuple
(
42
)));
// Implicit constructors are allowed.
const
Action
<
bool
(
std
::
string
)
>
s1
=
[](
std
::
string
s
)
{
return
!
s
.
empty
();
};
const
Action
<
int
(
const
char
*
)
>
s2
=
Action
<
int
(
const
char
*
)
>
(
s1
);
EXPECT_EQ
(
0
,
s2
.
Perform
(
std
::
make_tuple
(
""
)));
EXPECT_EQ
(
1
,
s2
.
Perform
(
std
::
make_tuple
(
"hello"
)));
// Also between the lambda and the action itself.
const
Action
<
bool
(
std
::
string
)
>
x
=
[](
Unused
)
{
return
42
;
};
EXPECT_TRUE
(
x
.
Perform
(
std
::
make_tuple
(
"hello"
)));
}
TEST
(
FunctorActionTest
,
UnusedArguments
)
{
// Verify that users can ignore uninteresting arguments.
Action
<
int
(
int
,
double
y
,
double
z
)
>
a
=
[](
int
i
,
Unused
,
Unused
)
{
return
2
*
i
;
};
std
::
tuple
<
int
,
double
,
double
>
dummy
=
std
::
make_tuple
(
3
,
7.3
,
9.44
);
EXPECT_EQ
(
6
,
a
.
Perform
(
dummy
));
}
// Test that basic built-in actions work with move-only arguments.
// FIXME: Currently, almost all ActionInterface-based actions will not
// work, even if they only try to use other, copyable arguments. Implement them
// if necessary (but note that DoAll cannot work on non-copyable types anyway -
// so maybe it's better to make users use lambdas instead.
TEST
(
MoveOnlyArgumentsTest
,
ReturningActions
)
{
Action
<
int
(
std
::
unique_ptr
<
int
>
)
>
a
=
Return
(
1
);
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
(
nullptr
)));
a
=
testing
::
WithoutArgs
([]()
{
return
7
;
});
EXPECT_EQ
(
7
,
a
.
Perform
(
std
::
make_tuple
(
nullptr
)));
Action
<
void
(
std
::
unique_ptr
<
int
>
,
int
*
)
>
a2
=
testing
::
SetArgPointee
<
1
>
(
3
);
int
x
=
0
;
a2
.
Perform
(
std
::
make_tuple
(
nullptr
,
&
x
));
EXPECT_EQ
(
x
,
3
);
}
#endif // GTEST_LANG_CXX11
}
// Unnamed namespace
#ifdef _MSC_VER
#if _MSC_VER == 1900
# pragma warning(pop)
#endif
#endif
googlemock/test/gmock-cardinalities_test.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -391,7 +390,7 @@ TEST(ExactlyTest, HasCorrectBounds) {
EXPECT_EQ
(
3
,
c
.
ConservativeUpperBound
());
}
// Tests that a user can make
his
own cardinality by implementing
// Tests that a user can make
their
own cardinality by implementing
// CardinalityInterface and calling MakeCardinality().
class
EvenCardinality
:
public
CardinalityInterface
{
...
...
googlemock/test/gmock-generated-actions_test.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -46,10 +45,6 @@ namespace gmock_generated_actions_test {
using
::
std
::
plus
;
using
::
std
::
string
;
using
testing
::
get
;
using
testing
::
make_tuple
;
using
testing
::
tuple
;
using
testing
::
tuple_element
;
using
testing
::
_
;
using
testing
::
Action
;
using
testing
::
ActionInterface
;
...
...
@@ -81,12 +76,12 @@ bool Unary(int x) { return x < 0; }
const
char
*
Plus1
(
const
char
*
s
)
{
return
s
+
1
;
}
bool
ByConstRef
(
const
string
&
s
)
{
return
s
==
"Hi"
;
}
bool
ByConstRef
(
const
std
::
string
&
s
)
{
return
s
==
"Hi"
;
}
const
double
g_double
=
0
;
bool
ReferencesGlobalDouble
(
const
double
&
x
)
{
return
&
x
==
&
g_double
;
}
string
ByNonConstRef
(
string
&
s
)
{
return
s
+=
"+"
;
}
// NOLINT
std
::
string
ByNonConstRef
(
std
::
string
&
s
)
{
return
s
+=
"+"
;
}
// NOLINT
struct
UnaryFunctor
{
int
operator
()(
bool
x
)
{
return
x
?
1
:
-
1
;
}
...
...
@@ -102,9 +97,9 @@ void VoidTernary(int, char, bool) { g_done = true; }
int
SumOf4
(
int
a
,
int
b
,
int
c
,
int
d
)
{
return
a
+
b
+
c
+
d
;
}
string
Concat4
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
;
std
::
string
Concat4
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
)
{
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
;
}
int
SumOf5
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
)
{
return
a
+
b
+
c
+
d
+
e
;
}
...
...
@@ -115,9 +110,9 @@ struct SumOf5Functor {
}
};
string
Concat5
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
;
std
::
string
Concat5
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
)
{
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
;
}
int
SumOf6
(
int
a
,
int
b
,
int
c
,
int
d
,
int
e
,
int
f
)
{
...
...
@@ -130,34 +125,34 @@ struct SumOf6Functor {
}
};
string
Concat6
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
;
std
::
string
Concat6
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
)
{
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
;
}
string
Concat7
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
;
std
::
string
Concat7
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
)
{
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
;
}
string
Concat8
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
;
std
::
string
Concat8
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
)
{
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
;
}
string
Concat9
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
;
std
::
string
Concat9
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
)
{
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
;
}
string
Concat10
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
,
const
char
*
s10
)
{
return
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
+
s10
;
std
::
string
Concat10
(
const
char
*
s1
,
const
char
*
s2
,
const
char
*
s3
,
const
char
*
s4
,
const
char
*
s5
,
const
char
*
s6
,
const
char
*
s7
,
const
char
*
s8
,
const
char
*
s9
,
const
char
*
s10
)
{
return
std
::
string
(
s1
)
+
s2
+
s3
+
s4
+
s5
+
s6
+
s7
+
s8
+
s9
+
s10
;
}
// A helper that turns the type of a C-string literal from const
...
...
@@ -169,85 +164,84 @@ inline const char* CharPtr(const char* s) { return s; }
// Tests using InvokeArgument with a nullary function.
TEST
(
InvokeArgumentTest
,
Function0
)
{
Action
<
int
(
int
,
int
(
*
)())
>
a
=
InvokeArgument
<
1
>
();
// NOLINT
EXPECT_EQ
(
1
,
a
.
Perform
(
make_tuple
(
2
,
&
Nullary
)));
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
(
2
,
&
Nullary
)));
}
// Tests using InvokeArgument with a unary function.
TEST
(
InvokeArgumentTest
,
Functor1
)
{
Action
<
int
(
UnaryFunctor
)
>
a
=
InvokeArgument
<
0
>
(
true
);
// NOLINT
EXPECT_EQ
(
1
,
a
.
Perform
(
make_tuple
(
UnaryFunctor
())));
EXPECT_EQ
(
1
,
a
.
Perform
(
std
::
make_tuple
(
UnaryFunctor
())));
}
// Tests using InvokeArgument with a 5-ary function.
TEST
(
InvokeArgumentTest
,
Function5
)
{
Action
<
int
(
int
(
*
)(
int
,
int
,
int
,
int
,
int
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
10000
,
2000
,
300
,
40
,
5
);
EXPECT_EQ
(
12345
,
a
.
Perform
(
make_tuple
(
&
SumOf5
)));
EXPECT_EQ
(
12345
,
a
.
Perform
(
std
::
make_tuple
(
&
SumOf5
)));
}
// Tests using InvokeArgument with a 5-ary functor.
TEST
(
InvokeArgumentTest
,
Functor5
)
{
Action
<
int
(
SumOf5Functor
)
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
10000
,
2000
,
300
,
40
,
5
);
EXPECT_EQ
(
12345
,
a
.
Perform
(
make_tuple
(
SumOf5Functor
())));
EXPECT_EQ
(
12345
,
a
.
Perform
(
std
::
make_tuple
(
SumOf5Functor
())));
}
// Tests using InvokeArgument with a 6-ary function.
TEST
(
InvokeArgumentTest
,
Function6
)
{
Action
<
int
(
int
(
*
)(
int
,
int
,
int
,
int
,
int
,
int
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
100000
,
20000
,
3000
,
400
,
50
,
6
);
EXPECT_EQ
(
123456
,
a
.
Perform
(
make_tuple
(
&
SumOf6
)));
EXPECT_EQ
(
123456
,
a
.
Perform
(
std
::
make_tuple
(
&
SumOf6
)));
}
// Tests using InvokeArgument with a 6-ary functor.
TEST
(
InvokeArgumentTest
,
Functor6
)
{
Action
<
int
(
SumOf6Functor
)
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
100000
,
20000
,
3000
,
400
,
50
,
6
);
EXPECT_EQ
(
123456
,
a
.
Perform
(
make_tuple
(
SumOf6Functor
())));
EXPECT_EQ
(
123456
,
a
.
Perform
(
std
::
make_tuple
(
SumOf6Functor
())));
}
// Tests using InvokeArgument with a 7-ary function.
TEST
(
InvokeArgumentTest
,
Function7
)
{
Action
<
st
ring
(
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
);
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
make_tuple
(
&
Concat7
)));
Action
<
st
d
::
string
(
std
::
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
);
EXPECT_EQ
(
"1234567"
,
a
.
Perform
(
std
::
make_tuple
(
&
Concat7
)));
}
// Tests using InvokeArgument with a 8-ary function.
TEST
(
InvokeArgumentTest
,
Function8
)
{
Action
<
st
ring
(
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
);
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
make_tuple
(
&
Concat8
)));
Action
<
st
d
::
string
(
std
::
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
);
EXPECT_EQ
(
"12345678"
,
a
.
Perform
(
std
::
make_tuple
(
&
Concat8
)));
}
// Tests using InvokeArgument with a 9-ary function.
TEST
(
InvokeArgumentTest
,
Function9
)
{
Action
<
st
ring
(
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
);
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
make_tuple
(
&
Concat9
)));
Action
<
st
d
::
string
(
std
::
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
);
EXPECT_EQ
(
"123456789"
,
a
.
Perform
(
std
::
make_tuple
(
&
Concat9
)));
}
// Tests using InvokeArgument with a 10-ary function.
TEST
(
InvokeArgumentTest
,
Function10
)
{
Action
<
string
(
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"0"
);
EXPECT_EQ
(
"1234567890"
,
a
.
Perform
(
make_tuple
(
&
Concat10
)));
Action
<
std
::
string
(
std
::
string
(
*
)(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
))
>
a
=
InvokeArgument
<
0
>
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"0"
);
EXPECT_EQ
(
"1234567890"
,
a
.
Perform
(
std
::
make_tuple
(
&
Concat10
)));
}
// Tests using InvokeArgument with a function that takes a pointer argument.
TEST
(
InvokeArgumentTest
,
ByPointerFunction
)
{
Action
<
const
char
*
(
const
char
*
(
*
)(
const
char
*
input
,
short
n
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
static_cast
<
const
char
*>
(
"Hi"
),
Short
(
1
));
EXPECT_STREQ
(
"i"
,
a
.
Perform
(
make_tuple
(
&
Binary
)));
EXPECT_STREQ
(
"i"
,
a
.
Perform
(
std
::
make_tuple
(
&
Binary
)));
}
// Tests using InvokeArgument with a function that takes a const char*
...
...
@@ -255,17 +249,17 @@ TEST(InvokeArgumentTest, ByPointerFunction) {
TEST
(
InvokeArgumentTest
,
FunctionWithCStringLiteral
)
{
Action
<
const
char
*
(
const
char
*
(
*
)(
const
char
*
input
,
short
n
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
"Hi"
,
Short
(
1
));
EXPECT_STREQ
(
"i"
,
a
.
Perform
(
make_tuple
(
&
Binary
)));
EXPECT_STREQ
(
"i"
,
a
.
Perform
(
std
::
make_tuple
(
&
Binary
)));
}
// Tests using InvokeArgument with a function that takes a const reference.
TEST
(
InvokeArgumentTest
,
ByConstReferenceFunction
)
{
Action
<
bool
(
bool
(
*
function
)(
const
string
&
s
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
string
(
"Hi"
));
Action
<
bool
(
bool
(
*
function
)(
const
std
::
string
&
s
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
std
::
string
(
"Hi"
));
// When action 'a' is constructed, it makes a copy of the temporary
// string object passed to it, so it's OK to use 'a' later, when the
// temporary object has already died.
EXPECT_TRUE
(
a
.
Perform
(
make_tuple
(
&
ByConstRef
)));
EXPECT_TRUE
(
a
.
Perform
(
std
::
make_tuple
(
&
ByConstRef
)));
}
// Tests using InvokeArgument with ByRef() and a function that takes a
...
...
@@ -274,18 +268,18 @@ TEST(InvokeArgumentTest, ByExplicitConstReferenceFunction) {
Action
<
bool
(
bool
(
*
)(
const
double
&
x
))
>
a
=
// NOLINT
InvokeArgument
<
0
>
(
ByRef
(
g_double
));
// The above line calls ByRef() on a const value.
EXPECT_TRUE
(
a
.
Perform
(
make_tuple
(
&
ReferencesGlobalDouble
)));
EXPECT_TRUE
(
a
.
Perform
(
std
::
make_tuple
(
&
ReferencesGlobalDouble
)));
double
x
=
0
;
a
=
InvokeArgument
<
0
>
(
ByRef
(
x
));
// This calls ByRef() on a non-const.
EXPECT_FALSE
(
a
.
Perform
(
make_tuple
(
&
ReferencesGlobalDouble
)));
EXPECT_FALSE
(
a
.
Perform
(
std
::
make_tuple
(
&
ReferencesGlobalDouble
)));
}
// Tests using WithArgs and with an action that takes 1 argument.
TEST
(
WithArgsTest
,
OneArg
)
{
Action
<
bool
(
double
x
,
int
n
)
>
a
=
WithArgs
<
1
>
(
Invoke
(
Unary
));
// NOLINT
EXPECT_TRUE
(
a
.
Perform
(
make_tuple
(
1.5
,
-
1
)));
EXPECT_FALSE
(
a
.
Perform
(
make_tuple
(
1.5
,
1
)));
EXPECT_TRUE
(
a
.
Perform
(
std
::
make_tuple
(
1.5
,
-
1
)));
EXPECT_FALSE
(
a
.
Perform
(
std
::
make_tuple
(
1.5
,
1
)));
}
// Tests using WithArgs with an action that takes 2 arguments.
...
...
@@ -293,105 +287,105 @@ TEST(WithArgsTest, TwoArgs) {
Action
<
const
char
*
(
const
char
*
s
,
double
x
,
short
n
)
>
a
=
WithArgs
<
0
,
2
>
(
Invoke
(
Binary
));
const
char
s
[]
=
"Hello"
;
EXPECT_EQ
(
s
+
2
,
a
.
Perform
(
make_tuple
(
CharPtr
(
s
),
0.5
,
Short
(
2
))));
EXPECT_EQ
(
s
+
2
,
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
s
),
0.5
,
Short
(
2
))));
}
// Tests using WithArgs with an action that takes 3 arguments.
TEST
(
WithArgsTest
,
ThreeArgs
)
{
Action
<
int
(
int
,
double
,
char
,
short
)
>
a
=
// NOLINT
WithArgs
<
0
,
2
,
3
>
(
Invoke
(
Ternary
));
EXPECT_EQ
(
123
,
a
.
Perform
(
make_tuple
(
100
,
6.5
,
Char
(
20
),
Short
(
3
))));
EXPECT_EQ
(
123
,
a
.
Perform
(
std
::
make_tuple
(
100
,
6.5
,
Char
(
20
),
Short
(
3
))));
}
// Tests using WithArgs with an action that takes 4 arguments.
TEST
(
WithArgsTest
,
FourArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
double
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
4
,
3
,
1
,
0
>
(
Invoke
(
Concat4
));
EXPECT_EQ
(
"4310"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
2.5
,
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
double
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
4
,
3
,
1
,
0
>
(
Invoke
(
Concat4
));
EXPECT_EQ
(
"4310"
,
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
2.5
,
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
}
// Tests using WithArgs with an action that takes 5 arguments.
TEST
(
WithArgsTest
,
FiveArgs
)
{
Action
<
st
ring
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
4
,
3
,
2
,
1
,
0
>
(
Invoke
(
Concat5
));
Action
<
st
d
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
4
,
3
,
2
,
1
,
0
>
(
Invoke
(
Concat5
));
EXPECT_EQ
(
"43210"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
),
CharPtr
(
"4"
))));
}
// Tests using WithArgs with an action that takes 6 arguments.
TEST
(
WithArgsTest
,
SixArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
2
,
1
,
0
>
(
Invoke
(
Concat6
));
EXPECT_EQ
(
"012210"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
))));
EXPECT_EQ
(
"012210"
,
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
))));
}
// Tests using WithArgs with an action that takes 7 arguments.
TEST
(
WithArgsTest
,
SevenArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
2
,
1
,
0
>
(
Invoke
(
Concat7
));
EXPECT_EQ
(
"0123210"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
EXPECT_EQ
(
"0123210"
,
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
}
// Tests using WithArgs with an action that takes 8 arguments.
TEST
(
WithArgsTest
,
EightArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
0
,
1
,
2
,
3
>
(
Invoke
(
Concat8
));
EXPECT_EQ
(
"01230123"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
EXPECT_EQ
(
"01230123"
,
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
}
// Tests using WithArgs with an action that takes 9 arguments.
TEST
(
WithArgsTest
,
NineArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
1
,
2
,
3
,
2
,
3
>
(
Invoke
(
Concat9
));
EXPECT_EQ
(
"012312323"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
}
// Tests using WithArgs with an action that takes 10 arguments.
TEST
(
WithArgsTest
,
TenArgs
)
{
Action
<
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
Action
<
std
::
string
(
const
char
*
,
const
char
*
,
const
char
*
,
const
char
*
)
>
a
=
WithArgs
<
0
,
1
,
2
,
3
,
2
,
1
,
0
,
1
,
2
,
3
>
(
Invoke
(
Concat10
));
EXPECT_EQ
(
"0123210123"
,
a
.
Perform
(
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
a
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"0"
),
CharPtr
(
"1"
),
CharPtr
(
"2"
),
CharPtr
(
"3"
))));
}
// Tests using WithArgs with an action that is not Invoke().
class
SubstractAction
:
public
ActionInterface
<
int
(
int
,
int
)
>
{
// NOLINT
public:
virtual
int
Perform
(
const
tuple
<
int
,
int
>&
args
)
{
return
get
<
0
>
(
args
)
-
get
<
1
>
(
args
);
virtual
int
Perform
(
const
std
::
tuple
<
int
,
int
>&
args
)
{
return
std
::
get
<
0
>
(
args
)
-
std
::
get
<
1
>
(
args
);
}
};
TEST
(
WithArgsTest
,
NonInvokeAction
)
{
Action
<
int
(
const
string
&
,
int
,
int
)
>
a
=
// NOLINT
Action
<
int
(
const
std
::
string
&
,
int
,
int
)
>
a
=
// NOLINT
WithArgs
<
2
,
1
>
(
MakeAction
(
new
SubstractAction
));
string
s
(
"hello"
);
EXPECT_EQ
(
8
,
a
.
Perform
(
tuple
<
const
string
&
,
int
,
int
>
(
s
,
2
,
10
)));
std
::
tuple
<
std
::
string
,
int
,
int
>
dummy
=
std
::
make_tuple
(
std
::
string
(
"hi"
),
2
,
10
);
EXPECT_EQ
(
8
,
a
.
Perform
(
dummy
));
}
// Tests using WithArgs to pass all original arguments in the original order.
TEST
(
WithArgsTest
,
Identity
)
{
Action
<
int
(
int
x
,
char
y
,
short
z
)
>
a
=
// NOLINT
WithArgs
<
0
,
1
,
2
>
(
Invoke
(
Ternary
));
EXPECT_EQ
(
123
,
a
.
Perform
(
make_tuple
(
100
,
Char
(
20
),
Short
(
3
))));
EXPECT_EQ
(
123
,
a
.
Perform
(
std
::
make_tuple
(
100
,
Char
(
20
),
Short
(
3
))));
}
// Tests using WithArgs with repeated arguments.
TEST
(
WithArgsTest
,
RepeatedArguments
)
{
Action
<
int
(
bool
,
int
m
,
int
n
)
>
a
=
// NOLINT
WithArgs
<
1
,
1
,
1
,
1
>
(
Invoke
(
SumOf4
));
EXPECT_EQ
(
4
,
a
.
Perform
(
make_tuple
(
false
,
1
,
10
)));
EXPECT_EQ
(
4
,
a
.
Perform
(
std
::
make_tuple
(
false
,
1
,
10
)));
}
// Tests using WithArgs with reversed argument order.
...
...
@@ -399,21 +393,22 @@ TEST(WithArgsTest, ReversedArgumentOrder) {
Action
<
const
char
*
(
short
n
,
const
char
*
input
)
>
a
=
// NOLINT
WithArgs
<
1
,
0
>
(
Invoke
(
Binary
));
const
char
s
[]
=
"Hello"
;
EXPECT_EQ
(
s
+
2
,
a
.
Perform
(
make_tuple
(
Short
(
2
),
CharPtr
(
s
))));
EXPECT_EQ
(
s
+
2
,
a
.
Perform
(
std
::
make_tuple
(
Short
(
2
),
CharPtr
(
s
))));
}
// Tests using WithArgs with compatible, but not identical, argument types.
TEST
(
WithArgsTest
,
ArgsOfCompatibleTypes
)
{
Action
<
long
(
short
x
,
char
y
,
double
z
,
char
c
)
>
a
=
// NOLINT
WithArgs
<
0
,
1
,
3
>
(
Invoke
(
Ternary
));
EXPECT_EQ
(
123
,
a
.
Perform
(
make_tuple
(
Short
(
100
),
Char
(
20
),
5.6
,
Char
(
3
))));
EXPECT_EQ
(
123
,
a
.
Perform
(
std
::
make_tuple
(
Short
(
100
),
Char
(
20
),
5.6
,
Char
(
3
))));
}
// Tests using WithArgs with an action that returns void.
TEST
(
WithArgsTest
,
VoidAction
)
{
Action
<
void
(
double
x
,
char
c
,
int
n
)
>
a
=
WithArgs
<
2
,
1
>
(
Invoke
(
VoidBinary
));
g_done
=
false
;
a
.
Perform
(
make_tuple
(
1.5
,
'a'
,
3
));
a
.
Perform
(
std
::
make_tuple
(
1.5
,
'a'
,
3
));
EXPECT_TRUE
(
g_done
);
}
...
...
@@ -422,7 +417,7 @@ TEST(DoAllTest, TwoActions) {
int
n
=
0
;
Action
<
int
(
int
*
)
>
a
=
DoAll
(
SetArgPointee
<
0
>
(
1
),
// NOLINT
Return
(
2
));
EXPECT_EQ
(
2
,
a
.
Perform
(
make_tuple
(
&
n
)));
EXPECT_EQ
(
2
,
a
.
Perform
(
std
::
make_tuple
(
&
n
)));
EXPECT_EQ
(
1
,
n
);
}
...
...
@@ -432,7 +427,7 @@ TEST(DoAllTest, ThreeActions) {
Action
<
int
(
int
*
,
int
*
)
>
a
=
DoAll
(
SetArgPointee
<
0
>
(
1
),
// NOLINT
SetArgPointee
<
1
>
(
2
),
Return
(
3
));
EXPECT_EQ
(
3
,
a
.
Perform
(
make_tuple
(
&
m
,
&
n
)));
EXPECT_EQ
(
3
,
a
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
}
...
...
@@ -446,7 +441,7 @@ TEST(DoAllTest, FourActions) {
SetArgPointee
<
1
>
(
2
),
SetArgPointee
<
2
>
(
'a'
),
Return
(
3
));
EXPECT_EQ
(
3
,
a
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
ch
)));
EXPECT_EQ
(
3
,
a
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
ch
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
ch
);
...
...
@@ -462,7 +457,7 @@ TEST(DoAllTest, FiveActions) {
SetArgPointee
<
2
>
(
'a'
),
SetArgPointee
<
3
>
(
'b'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -480,7 +475,7 @@ TEST(DoAllTest, SixActions) {
SetArgPointee
<
3
>
(
'b'
),
SetArgPointee
<
4
>
(
'c'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -500,7 +495,7 @@ TEST(DoAllTest, SevenActions) {
SetArgPointee
<
4
>
(
'c'
),
SetArgPointee
<
5
>
(
'd'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -523,7 +518,7 @@ TEST(DoAllTest, EightActions) {
SetArgPointee
<
5
>
(
'd'
),
SetArgPointee
<
6
>
(
'e'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -548,7 +543,7 @@ TEST(DoAllTest, NineActions) {
SetArgPointee
<
6
>
(
'e'
),
SetArgPointee
<
7
>
(
'f'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
,
&
f
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
,
&
f
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -576,7 +571,8 @@ TEST(DoAllTest, TenActions) {
SetArgPointee
<
7
>
(
'f'
),
SetArgPointee
<
8
>
(
'g'
),
Return
(
3
));
EXPECT_EQ
(
3
,
action
.
Perform
(
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
,
&
f
,
&
g
)));
EXPECT_EQ
(
3
,
action
.
Perform
(
std
::
make_tuple
(
&
m
,
&
n
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
,
&
f
,
&
g
)));
EXPECT_EQ
(
1
,
m
);
EXPECT_EQ
(
2
,
n
);
EXPECT_EQ
(
'a'
,
a
);
...
...
@@ -606,10 +602,10 @@ ACTION(Return5) { return 5; }
TEST
(
ActionMacroTest
,
WorksWhenNotReferencingArguments
)
{
Action
<
double
()
>
a1
=
Return5
();
EXPECT_DOUBLE_EQ
(
5
,
a1
.
Perform
(
make_tuple
()));
EXPECT_DOUBLE_EQ
(
5
,
a1
.
Perform
(
std
::
make_tuple
()));
Action
<
int
(
double
,
bool
)
>
a2
=
Return5
();
EXPECT_EQ
(
5
,
a2
.
Perform
(
make_tuple
(
1
,
true
)));
EXPECT_EQ
(
5
,
a2
.
Perform
(
std
::
make_tuple
(
1
,
true
)));
}
// Tests that ACTION() can define an action that returns void.
...
...
@@ -618,7 +614,7 @@ ACTION(IncrementArg1) { (*arg1)++; }
TEST
(
ActionMacroTest
,
WorksWhenReturningVoid
)
{
Action
<
void
(
int
,
int
*
)
>
a1
=
IncrementArg1
();
int
n
=
0
;
a1
.
Perform
(
make_tuple
(
5
,
&
n
));
a1
.
Perform
(
std
::
make_tuple
(
5
,
&
n
));
EXPECT_EQ
(
1
,
n
);
}
...
...
@@ -633,22 +629,22 @@ ACTION(IncrementArg2) {
TEST
(
ActionMacroTest
,
CanReferenceArgumentType
)
{
Action
<
void
(
int
,
bool
,
int
*
)
>
a1
=
IncrementArg2
();
int
n
=
0
;
a1
.
Perform
(
make_tuple
(
5
,
false
,
&
n
));
a1
.
Perform
(
std
::
make_tuple
(
5
,
false
,
&
n
));
EXPECT_EQ
(
1
,
n
);
}
// Tests that the body of ACTION() can reference the argument tuple
// via args_type and args.
ACTION
(
Sum2
)
{
StaticAssertTypeEq
<
tuple
<
int
,
char
,
int
*>
,
args_type
>
();
StaticAssertTypeEq
<
std
::
tuple
<
int
,
char
,
int
*>
,
args_type
>
();
args_type
args_copy
=
args
;
return
get
<
0
>
(
args_copy
)
+
get
<
1
>
(
args_copy
);
return
std
::
get
<
0
>
(
args_copy
)
+
std
::
get
<
1
>
(
args_copy
);
}
TEST
(
ActionMacroTest
,
CanReferenceArgumentTuple
)
{
Action
<
int
(
int
,
char
,
int
*
)
>
a1
=
Sum2
();
int
dummy
=
0
;
EXPECT_EQ
(
11
,
a1
.
Perform
(
make_tuple
(
5
,
Char
(
6
),
&
dummy
)));
EXPECT_EQ
(
11
,
a1
.
Perform
(
std
::
make_tuple
(
5
,
Char
(
6
),
&
dummy
)));
}
// Tests that the body of ACTION() can reference the mock function
...
...
@@ -663,8 +659,8 @@ ACTION(InvokeDummy) {
TEST
(
ActionMacroTest
,
CanReferenceMockFunctionType
)
{
Action
<
int
(
bool
)
>
a1
=
InvokeDummy
();
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
(
true
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
(
false
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
true
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
false
)));
}
// Tests that the body of ACTION() can reference the mock function's
...
...
@@ -677,8 +673,8 @@ ACTION(InvokeDummy2) {
TEST
(
ActionMacroTest
,
CanReferenceMockFunctionReturnType
)
{
Action
<
int
(
bool
)
>
a1
=
InvokeDummy2
();
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
(
true
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
(
false
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
true
)));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
(
false
)));
}
// Tests that ACTION() works for arguments passed by const reference.
...
...
@@ -690,7 +686,7 @@ ACTION(ReturnAddrOfConstBoolReferenceArg) {
TEST
(
ActionMacroTest
,
WorksForConstReferenceArg
)
{
Action
<
const
bool
*
(
int
,
const
bool
&
)
>
a
=
ReturnAddrOfConstBoolReferenceArg
();
const
bool
b
=
false
;
EXPECT_EQ
(
&
b
,
a
.
Perform
(
tuple
<
int
,
const
bool
&>
(
0
,
b
)));
EXPECT_EQ
(
&
b
,
a
.
Perform
(
std
::
tuple
<
int
,
const
bool
&>
(
0
,
b
)));
}
// Tests that ACTION() works for arguments passed by non-const reference.
...
...
@@ -702,7 +698,7 @@ ACTION(ReturnAddrOfIntReferenceArg) {
TEST
(
ActionMacroTest
,
WorksForNonConstReferenceArg
)
{
Action
<
int
*
(
int
&
,
bool
,
int
)
>
a
=
ReturnAddrOfIntReferenceArg
();
int
n
=
0
;
EXPECT_EQ
(
&
n
,
a
.
Perform
(
tuple
<
int
&
,
bool
,
int
>
(
n
,
true
,
1
)));
EXPECT_EQ
(
&
n
,
a
.
Perform
(
std
::
tuple
<
int
&
,
bool
,
int
>
(
n
,
true
,
1
)));
}
// Tests that ACTION() can be used in a namespace.
...
...
@@ -712,7 +708,7 @@ ACTION(Sum) { return arg0 + arg1; }
TEST
(
ActionMacroTest
,
WorksInNamespace
)
{
Action
<
int
(
int
,
int
)
>
a1
=
action_test
::
Sum
();
EXPECT_EQ
(
3
,
a1
.
Perform
(
make_tuple
(
1
,
2
)));
EXPECT_EQ
(
3
,
a1
.
Perform
(
std
::
make_tuple
(
1
,
2
)));
}
// Tests that the same ACTION definition works for mock functions with
...
...
@@ -721,11 +717,11 @@ ACTION(PlusTwo) { return arg0 + 2; }
TEST
(
ActionMacroTest
,
WorksForDifferentArgumentNumbers
)
{
Action
<
int
(
int
)
>
a1
=
PlusTwo
();
EXPECT_EQ
(
4
,
a1
.
Perform
(
make_tuple
(
2
)));
EXPECT_EQ
(
4
,
a1
.
Perform
(
std
::
make_tuple
(
2
)));
Action
<
double
(
float
,
void
*
)
>
a2
=
PlusTwo
();
int
dummy
;
EXPECT_DOUBLE_EQ
(
6
,
a2
.
Perform
(
make_tuple
(
4.0
f
,
&
dummy
)));
EXPECT_DOUBLE_EQ
(
6
,
a2
.
Perform
(
std
::
make_tuple
(
4.0
f
,
&
dummy
)));
}
// Tests that ACTION_P can define a parameterized action.
...
...
@@ -733,7 +729,7 @@ ACTION_P(Plus, n) { return arg0 + n; }
TEST
(
ActionPMacroTest
,
DefinesParameterizedAction
)
{
Action
<
int
(
int
m
,
bool
t
)
>
a1
=
Plus
(
9
);
EXPECT_EQ
(
10
,
a1
.
Perform
(
make_tuple
(
1
,
true
)));
EXPECT_EQ
(
10
,
a1
.
Perform
(
std
::
make_tuple
(
1
,
true
)));
}
// Tests that the body of ACTION_P can reference the argument types
...
...
@@ -746,7 +742,7 @@ ACTION_P(TypedPlus, n) {
TEST
(
ActionPMacroTest
,
CanReferenceArgumentAndParameterTypes
)
{
Action
<
int
(
char
m
,
bool
t
)
>
a1
=
TypedPlus
(
9
);
EXPECT_EQ
(
10
,
a1
.
Perform
(
make_tuple
(
Char
(
1
),
true
)));
EXPECT_EQ
(
10
,
a1
.
Perform
(
std
::
make_tuple
(
Char
(
1
),
true
)));
}
// Tests that a parameterized action can be used in any mock function
...
...
@@ -754,7 +750,8 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
TEST
(
ActionPMacroTest
,
WorksInCompatibleMockFunction
)
{
Action
<
std
::
string
(
const
std
::
string
&
s
)
>
a1
=
Plus
(
"tail"
);
const
std
::
string
re
=
"re"
;
EXPECT_EQ
(
"retail"
,
a1
.
Perform
(
tuple
<
const
std
::
string
&>
(
re
)));
std
::
tuple
<
const
std
::
string
>
dummy
=
std
::
make_tuple
(
re
);
EXPECT_EQ
(
"retail"
,
a1
.
Perform
(
dummy
));
}
// Tests that we can use ACTION*() to define actions overloaded on the
...
...
@@ -774,16 +771,16 @@ TEST(ActionMacroTest, CanDefineOverloadedActions) {
typedef
Action
<
const
char
*
(
bool
,
const
char
*
)
>
MyAction
;
const
MyAction
a1
=
OverloadedAction
();
EXPECT_STREQ
(
"hello"
,
a1
.
Perform
(
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"world"
,
a1
.
Perform
(
make_tuple
(
true
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"hello"
,
a1
.
Perform
(
std
::
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"world"
,
a1
.
Perform
(
std
::
make_tuple
(
true
,
CharPtr
(
"world"
))));
const
MyAction
a2
=
OverloadedAction
(
"hi"
);
EXPECT_STREQ
(
"hi"
,
a2
.
Perform
(
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"world"
,
a2
.
Perform
(
make_tuple
(
true
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"hi"
,
a2
.
Perform
(
std
::
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"world"
,
a2
.
Perform
(
std
::
make_tuple
(
true
,
CharPtr
(
"world"
))));
const
MyAction
a3
=
OverloadedAction
(
"hi"
,
"you"
);
EXPECT_STREQ
(
"hi"
,
a3
.
Perform
(
make_tuple
(
true
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"you"
,
a3
.
Perform
(
make_tuple
(
false
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"hi"
,
a3
.
Perform
(
std
::
make_tuple
(
true
,
CharPtr
(
"world"
))));
EXPECT_STREQ
(
"you"
,
a3
.
Perform
(
std
::
make_tuple
(
false
,
CharPtr
(
"world"
))));
}
// Tests ACTION_Pn where n >= 3.
...
...
@@ -792,25 +789,26 @@ ACTION_P3(Plus, m, n, k) { return arg0 + m + n + k; }
TEST
(
ActionPnMacroTest
,
WorksFor3Parameters
)
{
Action
<
double
(
int
m
,
bool
t
)
>
a1
=
Plus
(
100
,
20
,
3.4
);
EXPECT_DOUBLE_EQ
(
3123.4
,
a1
.
Perform
(
make_tuple
(
3000
,
true
)));
EXPECT_DOUBLE_EQ
(
3123.4
,
a1
.
Perform
(
std
::
make_tuple
(
3000
,
true
)));
Action
<
std
::
string
(
const
std
::
string
&
s
)
>
a2
=
Plus
(
"tail"
,
"-"
,
">"
);
const
std
::
string
re
=
"re"
;
EXPECT_EQ
(
"retail->"
,
a2
.
Perform
(
tuple
<
const
std
::
string
&>
(
re
)));
std
::
tuple
<
const
std
::
string
>
dummy
=
std
::
make_tuple
(
re
);
EXPECT_EQ
(
"retail->"
,
a2
.
Perform
(
dummy
));
}
ACTION_P4
(
Plus
,
p0
,
p1
,
p2
,
p3
)
{
return
arg0
+
p0
+
p1
+
p2
+
p3
;
}
TEST
(
ActionPnMacroTest
,
WorksFor4Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P5
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
)
{
return
arg0
+
p0
+
p1
+
p2
+
p3
+
p4
;
}
TEST
(
ActionPnMacroTest
,
WorksFor5Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P6
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
)
{
...
...
@@ -819,7 +817,7 @@ ACTION_P6(Plus, p0, p1, p2, p3, p4, p5) {
TEST
(
ActionPnMacroTest
,
WorksFor6Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P7
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
)
{
...
...
@@ -828,7 +826,7 @@ ACTION_P7(Plus, p0, p1, p2, p3, p4, p5, p6) {
TEST
(
ActionPnMacroTest
,
WorksFor7Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
,
7
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P8
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
)
{
...
...
@@ -837,7 +835,8 @@ ACTION_P8(Plus, p0, p1, p2, p3, p4, p5, p6, p7) {
TEST
(
ActionPnMacroTest
,
WorksFor8Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P9
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
)
{
...
...
@@ -846,7 +845,8 @@ ACTION_P9(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8) {
TEST
(
ActionPnMacroTest
,
WorksFor9Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
,
a1
.
Perform
(
make_tuple
(
10
)));
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
,
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
ACTION_P10
(
Plus
,
p0
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
,
last_param
)
{
...
...
@@ -858,7 +858,7 @@ ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param) {
TEST
(
ActionPnMacroTest
,
WorksFor10Parameters
)
{
Action
<
int
(
int
)
>
a1
=
Plus
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
);
EXPECT_EQ
(
10
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
,
a1
.
Perform
(
make_tuple
(
10
)));
a1
.
Perform
(
std
::
make_tuple
(
10
)));
}
// Tests that the action body can promote the parameter types.
...
...
@@ -875,8 +875,8 @@ TEST(ActionPnMacroTest, SimpleTypePromotion) {
PadArgument
(
std
::
string
(
"foo"
),
'r'
);
Action
<
std
::
string
(
const
char
*
)
>
promo
=
PadArgument
(
"foo"
,
static_cast
<
int
>
(
'r'
));
EXPECT_EQ
(
"foobar"
,
no_promo
.
Perform
(
make_tuple
(
CharPtr
(
"ba"
))));
EXPECT_EQ
(
"foobar"
,
promo
.
Perform
(
make_tuple
(
CharPtr
(
"ba"
))));
EXPECT_EQ
(
"foobar"
,
no_promo
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"ba"
))));
EXPECT_EQ
(
"foobar"
,
promo
.
Perform
(
std
::
make_tuple
(
CharPtr
(
"ba"
))));
}
// Tests that we can partially restrict parameter types using a
...
...
@@ -925,10 +925,10 @@ Concat(T1 a, int b, T2 c) {
TEST
(
ActionPnMacroTest
,
CanPartiallyRestrictParameterTypes
)
{
Action
<
const
std
::
string
()
>
a1
=
Concat
(
"Hello"
,
"1"
,
2
);
EXPECT_EQ
(
"Hello12"
,
a1
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
"Hello12"
,
a1
.
Perform
(
std
::
make_tuple
()));
a1
=
Concat
(
1
,
2
,
3
);
EXPECT_EQ
(
"123"
,
a1
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
"123"
,
a1
.
Perform
(
std
::
make_tuple
()));
}
// Verifies the type of an ACTION*.
...
...
@@ -986,7 +986,7 @@ ACTION_P10(Plus10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
TEST
(
ActionPnMacroTest
,
CanExplicitlyInstantiateWithReferenceTypes
)
{
int
x
=
1
,
y
=
2
,
z
=
3
;
const
tuple
<>
empty
=
make_tuple
();
const
std
::
tuple
<>
empty
=
std
::
make_tuple
();
Action
<
int
()
>
a
=
Plus1
<
int
&>
(
x
);
EXPECT_EQ
(
1
,
a
.
Perform
(
empty
));
...
...
@@ -1013,7 +1013,7 @@ class NullaryConstructorClass {
// Tests using ReturnNew() with a nullary constructor.
TEST
(
ReturnNewTest
,
NoArgs
)
{
Action
<
NullaryConstructorClass
*
()
>
a
=
ReturnNew
<
NullaryConstructorClass
>
();
NullaryConstructorClass
*
c
=
a
.
Perform
(
make_tuple
());
NullaryConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
123
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1027,7 +1027,7 @@ class UnaryConstructorClass {
// Tests using ReturnNew() with a unary constructor.
TEST
(
ReturnNewTest
,
Unary
)
{
Action
<
UnaryConstructorClass
*
()
>
a
=
ReturnNew
<
UnaryConstructorClass
>
(
4000
);
UnaryConstructorClass
*
c
=
a
.
Perform
(
make_tuple
());
UnaryConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
4000
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1035,7 +1035,7 @@ TEST(ReturnNewTest, Unary) {
TEST
(
ReturnNewTest
,
UnaryWorksWhenMockMethodHasArgs
)
{
Action
<
UnaryConstructorClass
*
(
bool
,
int
)
>
a
=
ReturnNew
<
UnaryConstructorClass
>
(
4000
);
UnaryConstructorClass
*
c
=
a
.
Perform
(
make_tuple
(
false
,
5
));
UnaryConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
(
false
,
5
));
EXPECT_EQ
(
4000
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1043,7 +1043,7 @@ TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) {
TEST
(
ReturnNewTest
,
UnaryWorksWhenMockMethodReturnsPointerToConst
)
{
Action
<
const
UnaryConstructorClass
*
()
>
a
=
ReturnNew
<
UnaryConstructorClass
>
(
4000
);
const
UnaryConstructorClass
*
c
=
a
.
Perform
(
make_tuple
());
const
UnaryConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
4000
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1063,7 +1063,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) {
ReturnNew
<
TenArgConstructorClass
>
(
1000000000
,
200000000
,
30000000
,
4000000
,
500000
,
60000
,
7000
,
800
,
90
,
0
);
TenArgConstructorClass
*
c
=
a
.
Perform
(
make_tuple
());
TenArgConstructorClass
*
c
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
1234567890
,
c
->
value_
);
delete
c
;
}
...
...
@@ -1077,7 +1077,7 @@ ACTION_TEMPLATE(CreateNew,
TEST
(
ActionTemplateTest
,
WorksWithoutValueParam
)
{
const
Action
<
int
*
()
>
a
=
CreateNew
<
int
>
();
int
*
p
=
a
.
Perform
(
make_tuple
());
int
*
p
=
a
.
Perform
(
std
::
make_tuple
());
delete
p
;
}
...
...
@@ -1090,7 +1090,7 @@ ACTION_TEMPLATE(CreateNew,
TEST
(
ActionTemplateTest
,
WorksWithValueParams
)
{
const
Action
<
int
*
()
>
a
=
CreateNew
<
int
>
(
42
);
int
*
p
=
a
.
Perform
(
make_tuple
());
int
*
p
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
42
,
*
p
);
delete
p
;
}
...
...
@@ -1099,7 +1099,7 @@ TEST(ActionTemplateTest, WorksWithValueParams) {
ACTION_TEMPLATE
(
MyDeleteArg
,
HAS_1_TEMPLATE_PARAMS
(
int
,
k
),
AND_0_VALUE_PARAMS
())
{
delete
get
<
k
>
(
args
);
delete
std
::
get
<
k
>
(
args
);
}
// Resets a bool variable in the destructor.
...
...
@@ -1116,7 +1116,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) {
int
n
=
0
;
bool
b
=
true
;
BoolResetter
*
resetter
=
new
BoolResetter
(
&
b
);
a
.
Perform
(
make_tuple
(
&
n
,
resetter
));
a
.
Perform
(
std
::
make_tuple
(
&
n
,
resetter
));
EXPECT_FALSE
(
b
);
// Verifies that resetter is deleted.
}
...
...
@@ -1131,7 +1131,7 @@ ACTION_TEMPLATE(ReturnSmartPointer,
TEST
(
ActionTemplateTest
,
WorksForTemplateTemplateParameters
)
{
using
::
testing
::
internal
::
linked_ptr
;
const
Action
<
linked_ptr
<
int
>
()
>
a
=
ReturnSmartPointer
<
linked_ptr
>
(
42
);
linked_ptr
<
int
>
p
=
a
.
Perform
(
make_tuple
());
linked_ptr
<
int
>
p
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
42
,
*
p
);
}
...
...
@@ -1166,7 +1166,7 @@ TEST(ActionTemplateTest, WorksFor10TemplateParameters) {
true
,
6
,
char
,
unsigned
,
int
>
Giant
;
const
Action
<
Giant
()
>
a
=
ReturnGiant
<
int
,
bool
,
double
,
5
,
true
,
6
,
char
,
unsigned
,
int
,
linked_ptr
>
(
42
);
Giant
giant
=
a
.
Perform
(
make_tuple
());
Giant
giant
=
a
.
Perform
(
std
::
make_tuple
());
EXPECT_EQ
(
42
,
giant
.
value
);
}
...
...
@@ -1179,7 +1179,7 @@ ACTION_TEMPLATE(ReturnSum,
TEST
(
ActionTemplateTest
,
WorksFor10ValueParameters
)
{
const
Action
<
int
()
>
a
=
ReturnSum
<
int
>
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
);
EXPECT_EQ
(
55
,
a
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
55
,
a
.
Perform
(
std
::
make_tuple
()));
}
// Tests that ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded
...
...
@@ -1213,11 +1213,11 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) {
const
Action
<
int
()
>
a2
=
ReturnSum
<
int
>
(
1
,
2
);
const
Action
<
int
()
>
a3
=
ReturnSum
<
int
>
(
1
,
2
,
3
);
const
Action
<
int
()
>
a4
=
ReturnSum
<
int
,
10000
>
(
2000
,
300
,
40
,
5
);
EXPECT_EQ
(
0
,
a0
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
1
,
a1
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
3
,
a2
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
6
,
a3
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
12345
,
a4
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
0
,
a0
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
1
,
a1
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
3
,
a2
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
6
,
a3
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
12345
,
a4
.
Perform
(
std
::
make_tuple
()));
}
#ifdef _MSC_VER
...
...
googlemock/test/gmock-generated-function-mockers_test.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -57,7 +56,6 @@
namespace
testing
{
namespace
gmock_generated_function_mockers_test
{
using
testing
::
internal
::
string
;
using
testing
::
_
;
using
testing
::
A
;
using
testing
::
An
;
...
...
@@ -82,11 +80,11 @@ class FooInterface {
virtual
bool
Unary
(
int
x
)
=
0
;
virtual
long
Binary
(
short
x
,
int
y
)
=
0
;
// NOLINT
virtual
int
Decimal
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
// NOLINT
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
string
&
k
)
=
0
;
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
std
::
string
&
k
)
=
0
;
virtual
bool
TakesNonConstReference
(
int
&
n
)
=
0
;
// NOLINT
virtual
string
TakesConstReference
(
const
int
&
n
)
=
0
;
virtual
std
::
string
TakesConstReference
(
const
int
&
n
)
=
0
;
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual
bool
TakesConst
(
const
int
x
)
=
0
;
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
...
...
@@ -101,13 +99,14 @@ class FooInterface {
virtual
char
OverloadedOnConstness
()
const
=
0
;
virtual
int
TypeWithHole
(
int
(
*
func
)())
=
0
;
virtual
int
TypeWithComma
(
const
std
::
map
<
int
,
string
>&
a_map
)
=
0
;
virtual
int
TypeWithComma
(
const
std
::
map
<
int
,
std
::
string
>&
a_map
)
=
0
;
#if GTEST_OS_WINDOWS
STDMETHOD_
(
int
,
CTNullary
)()
=
0
;
STDMETHOD_
(
bool
,
CTUnary
)(
int
x
)
=
0
;
STDMETHOD_
(
int
,
CTDecimal
)(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
// NOLINT
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
string
&
k
)
=
0
;
STDMETHOD_
(
int
,
CTDecimal
)
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
// NOLINT
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
std
::
string
&
k
)
=
0
;
STDMETHOD_
(
char
,
CTConst
)(
int
x
)
const
=
0
;
#endif // GTEST_OS_WINDOWS
};
...
...
@@ -133,19 +132,19 @@ class MockFoo : public FooInterface {
MOCK_METHOD1
(
Unary
,
bool
(
int
));
// NOLINT
MOCK_METHOD2
(
Binary
,
long
(
short
,
int
));
// NOLINT
MOCK_METHOD10
(
Decimal
,
int
(
bool
,
char
,
short
,
int
,
long
,
float
,
// NOLINT
double
,
unsigned
,
char
*
,
const
string
&
str
));
double
,
unsigned
,
char
*
,
const
std
::
string
&
str
));
MOCK_METHOD1
(
TakesNonConstReference
,
bool
(
int
&
));
// NOLINT
MOCK_METHOD1
(
TakesConstReference
,
string
(
const
int
&
));
MOCK_METHOD1
(
TakesConstReference
,
std
::
string
(
const
int
&
));
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
MOCK_METHOD1
(
TakesConst
,
bool
(
const
int
));
// NOLINT
#endif
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD0
(
ReturnTypeWithComma
,
std
::
map
<
int
,
string
>
());
MOCK_METHOD0
(
ReturnTypeWithComma
,
std
::
map
<
int
,
std
::
string
>
());
MOCK_CONST_METHOD1
(
ReturnTypeWithComma
,
std
::
map
<
int
,
string
>
(
int
));
// NOLINT
std
::
map
<
int
,
std
::
string
>
(
int
));
// NOLINT
MOCK_METHOD0
(
OverloadedOnArgumentNumber
,
int
());
// NOLINT
MOCK_METHOD1
(
OverloadedOnArgumentNumber
,
int
(
int
));
// NOLINT
...
...
@@ -157,19 +156,21 @@ class MockFoo : public FooInterface {
MOCK_CONST_METHOD0
(
OverloadedOnConstness
,
char
());
// NOLINT
MOCK_METHOD1
(
TypeWithHole
,
int
(
int
(
*
)()));
// NOLINT
MOCK_METHOD1
(
TypeWithComma
,
int
(
const
std
::
map
<
int
,
string
>&
));
// NOLINT
MOCK_METHOD1
(
TypeWithComma
,
int
(
const
std
::
map
<
int
,
std
::
string
>&
));
// NOLINT
#if GTEST_OS_WINDOWS
MOCK_METHOD0_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTNullary
,
int
());
MOCK_METHOD1_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTUnary
,
bool
(
int
));
MOCK_METHOD10_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTDecimal
,
int
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
string
&
k
));
MOCK_METHOD10_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTDecimal
,
int
(
bool
b
,
char
c
,
short
d
,
int
e
,
long
f
,
float
g
,
double
h
,
unsigned
i
,
char
*
j
,
const
std
::
string
&
k
));
MOCK_CONST_METHOD1_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTConst
,
char
(
int
));
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD0_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTReturnTypeWithComma
,
std
::
map
<
int
,
string
>
());
std
::
map
<
int
,
std
::
string
>
());
#endif // GTEST_OS_WINDOWS
private:
...
...
@@ -227,7 +228,7 @@ TEST_F(FunctionMockerTest, MocksDecimalFunction) {
Lt
(
100
),
5U
,
NULL
,
"hi"
))
.
WillOnce
(
Return
(
5
));
EXPECT_EQ
(
5
,
foo_
->
Decimal
(
true
,
'a'
,
0
,
0
,
1
,
0
,
0
,
5
,
NULL
,
"hi"
));
EXPECT_EQ
(
5
,
foo_
->
Decimal
(
true
,
'a'
,
0
,
0
,
1
,
0
,
0
,
5
,
nullptr
,
"hi"
));
}
// Tests mocking a function that takes a non-const reference.
...
...
@@ -291,7 +292,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) {
}
TEST_F
(
FunctionMockerTest
,
MocksReturnTypeWithComma
)
{
const
std
::
map
<
int
,
string
>
a_map
;
const
std
::
map
<
int
,
std
::
string
>
a_map
;
EXPECT_CALL
(
mock_foo_
,
ReturnTypeWithComma
())
.
WillOnce
(
Return
(
a_map
));
EXPECT_CALL
(
mock_foo_
,
ReturnTypeWithComma
(
42
))
...
...
@@ -341,7 +342,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
}
TEST_F
(
FunctionMockerTest
,
MocksReturnTypeWithCommaAndCallType
)
{
const
std
::
map
<
int
,
string
>
a_map
;
const
std
::
map
<
int
,
std
::
string
>
a_map
;
EXPECT_CALL
(
mock_foo_
,
CTReturnTypeWithComma
())
.
WillOnce
(
Return
(
a_map
));
...
...
@@ -616,7 +617,41 @@ TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
value
=
2
;
EXPECT_EQ
(
2
,
ref
);
}
TEST
(
MockFunctionTest
,
AsStdFunctionWithReferenceParameter
)
{
MockFunction
<
int
(
int
&
)
>
foo
;
auto
call
=
[](
const
std
::
function
<
int
(
int
&
)
>
&
f
,
int
&
i
)
{
return
f
(
i
);
};
int
i
=
42
;
EXPECT_CALL
(
foo
,
Call
(
i
)).
WillOnce
(
Return
(
-
1
));
EXPECT_EQ
(
-
1
,
call
(
foo
.
AsStdFunction
(),
i
));
}
#endif // GTEST_HAS_STD_FUNCTION_
struct
MockMethodSizes0
{
MOCK_METHOD0
(
func
,
void
());
};
struct
MockMethodSizes1
{
MOCK_METHOD1
(
func
,
void
(
int
));
};
struct
MockMethodSizes2
{
MOCK_METHOD2
(
func
,
void
(
int
,
int
));
};
struct
MockMethodSizes3
{
MOCK_METHOD3
(
func
,
void
(
int
,
int
,
int
));
};
struct
MockMethodSizes4
{
MOCK_METHOD4
(
func
,
void
(
int
,
int
,
int
,
int
));
};
TEST
(
MockFunctionTest
,
MockMethodSizeOverhead
)
{
EXPECT_EQ
(
sizeof
(
MockMethodSizes0
),
sizeof
(
MockMethodSizes1
));
EXPECT_EQ
(
sizeof
(
MockMethodSizes0
),
sizeof
(
MockMethodSizes2
));
EXPECT_EQ
(
sizeof
(
MockMethodSizes0
),
sizeof
(
MockMethodSizes3
));
EXPECT_EQ
(
sizeof
(
MockMethodSizes0
),
sizeof
(
MockMethodSizes4
));
}
}
// namespace gmock_generated_function_mockers_test
}
// namespace testing
googlemock/test/gmock-generated-internal-utils_test.cc
View file @
8c82ba48
...
...
@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes.
//
...
...
@@ -39,7 +38,6 @@
namespace
{
using
::
testing
::
tuple
;
using
::
testing
::
Matcher
;
using
::
testing
::
internal
::
CompileAssertTypesEqual
;
using
::
testing
::
internal
::
MatcherTuple
;
...
...
@@ -49,24 +47,24 @@ using ::testing::internal::IgnoredValue;
// Tests the MatcherTuple template struct.
TEST
(
MatcherTupleTest
,
ForSize0
)
{
CompileAssertTypesEqual
<
tuple
<>
,
MatcherTuple
<
tuple
<>
>::
type
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
MatcherTuple
<
std
::
tuple
<>
>::
type
>
();
}
TEST
(
MatcherTupleTest
,
ForSize1
)
{
CompileAssertTypesEqual
<
tuple
<
Matcher
<
int
>
>
,
MatcherTuple
<
tuple
<
int
>
>::
type
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
int
>
>
,
MatcherTuple
<
std
::
tuple
<
int
>
>::
type
>
();
}
TEST
(
MatcherTupleTest
,
ForSize2
)
{
CompileAssertTypesEqual
<
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
>
,
MatcherTuple
<
tuple
<
int
,
char
>
>::
type
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
>
,
MatcherTuple
<
std
::
tuple
<
int
,
char
>
>::
type
>
();
}
TEST
(
MatcherTupleTest
,
ForSize5
)
{
CompileAssertTypesEqual
<
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
double
>
,
Matcher
<
char
*>
>
,
MatcherTuple
<
tuple
<
int
,
char
,
bool
,
double
,
char
*>
>::
type
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
double
>
,
Matcher
<
char
*>
>
,
MatcherTuple
<
std
::
tuple
<
int
,
char
,
bool
,
double
,
char
*>
>::
type
>
();
}
// Tests the Function template struct.
...
...
@@ -74,8 +72,8 @@ TEST(MatcherTupleTest, ForSize5) {
TEST
(
FunctionTest
,
Nullary
)
{
typedef
Function
<
int
()
>
F
;
// NOLINT
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
tuple
<>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
tuple
<>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(),
F
::
MakeResultVoid
>
();
CompileAssertTypesEqual
<
IgnoredValue
(),
F
::
MakeResultIgnoredValue
>
();
}
...
...
@@ -84,8 +82,9 @@ TEST(FunctionTest, Unary) {
typedef
Function
<
int
(
bool
)
>
F
;
// NOLINT
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Argument1
>
();
CompileAssertTypesEqual
<
tuple
<
bool
>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
bool
>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
),
F
::
MakeResultVoid
>
();
// NOLINT
CompileAssertTypesEqual
<
IgnoredValue
(
bool
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
...
...
@@ -96,9 +95,11 @@ TEST(FunctionTest, Binary) {
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Argument1
>
();
CompileAssertTypesEqual
<
const
long
&
,
F
::
Argument2
>
();
// NOLINT
CompileAssertTypesEqual
<
tuple
<
bool
,
const
long
&>
,
F
::
ArgumentTuple
>
();
// NOLINT
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
bool
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
const
long
&
),
F
::
MakeResultVoid
>
();
// NOLINT
CompileAssertTypesEqual
<
IgnoredValue
(
bool
,
const
long
&
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
...
...
@@ -112,11 +113,13 @@ TEST(FunctionTest, LongArgumentList) {
CompileAssertTypesEqual
<
char
*
,
F
::
Argument3
>
();
CompileAssertTypesEqual
<
int
&
,
F
::
Argument4
>
();
CompileAssertTypesEqual
<
const
long
&
,
F
::
Argument5
>
();
// NOLINT
CompileAssertTypesEqual
<
tuple
<
bool
,
int
,
char
*
,
int
&
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
tuple
<
Matcher
<
bool
>
,
Matcher
<
int
>
,
Matcher
<
char
*>
,
Matcher
<
int
&>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
bool
,
int
,
char
*
,
int
&
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
,
Matcher
<
int
>
,
Matcher
<
char
*>
,
Matcher
<
int
&>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
int
,
char
*
,
int
&
,
const
long
&
),
// NOLINT
F
::
MakeResultVoid
>
();
CompileAssertTypesEqual
<
...
...
Prev
1
2
3
4
5
6
7
8
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