Unverified Commit 96d16157 authored by Jonathan Wendeborn's avatar Jonathan Wendeborn
Browse files

Merge branch 'isnice' of https://github.com/BrukerJWD/googletest into isnice

parents 386391b0 8c82ba48
...@@ -5,10 +5,18 @@ ...@@ -5,10 +5,18 @@
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32"> <ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{E4EF614B-30DF-4954-8C53-580A0BF6B589}</ProjectGuid> <ProjectGuid>{E4EF614B-30DF-4954-8C53-580A0BF6B589}</ProjectGuid>
...@@ -22,11 +30,22 @@ ...@@ -22,11 +30,22 @@
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </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"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </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" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
</ImportGroup> </ImportGroup>
...@@ -34,18 +53,34 @@ ...@@ -34,18 +53,34 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="gmock_config.props" /> <Import Project="gmock_config.props" />
</ImportGroup> </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"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="gmock_config.props" /> <Import Project="gmock_config.props" />
</ImportGroup> </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 Label="UserMacros" />
<PropertyGroup> <PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion> <_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> <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> <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)$(ProjectName)\</IntDir>
</PropertyGroup> </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'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
...@@ -60,6 +95,19 @@ ...@@ -60,6 +95,19 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </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'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
...@@ -71,6 +119,17 @@ ...@@ -71,6 +119,17 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </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> <ItemGroup>
<ProjectReference Include="gmock.vcxproj"> <ProjectReference Include="gmock.vcxproj">
<Project>{34681f0d-ce45-415d-b5f2-5c662dfe3bd5}</Project> <Project>{34681f0d-ce45-415d-b5f2-5c662dfe3bd5}</Project>
...@@ -81,7 +140,9 @@ ...@@ -81,7 +140,9 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\src\gmock_main.cc"> <ClCompile Include="..\..\src\gmock_main.cc">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <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|Win32'">../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
...@@ -5,10 +5,18 @@ ...@@ -5,10 +5,18 @@
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32"> <ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{F10D22F8-AC7B-4213-8720-608E7D878CD2}</ProjectGuid> <ProjectGuid>{F10D22F8-AC7B-4213-8720-608E7D878CD2}</ProjectGuid>
...@@ -22,11 +30,22 @@ ...@@ -22,11 +30,22 @@
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </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"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
</PropertyGroup> </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" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
</ImportGroup> </ImportGroup>
...@@ -34,19 +53,37 @@ ...@@ -34,19 +53,37 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="gmock_config.props" /> <Import Project="gmock_config.props" />
</ImportGroup> </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"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="gmock_config.props" /> <Import Project="gmock_config.props" />
</ImportGroup> </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 Label="UserMacros" />
<PropertyGroup> <PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion> <_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> <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)$(ProjectName)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental> <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> <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)$(ProjectName)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental> <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> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
...@@ -68,10 +105,28 @@ ...@@ -68,10 +105,28 @@
<TargetMachine>MachineX86</TargetMachine> <TargetMachine>MachineX86</TargetMachine>
</Link> </Link>
</ItemDefinitionGroup> </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'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\..\include;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\..\include;..\..;$(GTestDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader> <PrecompiledHeader>
...@@ -87,6 +142,24 @@ ...@@ -87,6 +142,24 @@
<TargetMachine>MachineX86</TargetMachine> <TargetMachine>MachineX86</TargetMachine>
</Link> </Link>
</ItemDefinitionGroup> </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> <ItemGroup>
<ProjectReference Include="gmock_main.vcxproj"> <ProjectReference Include="gmock_main.vcxproj">
<Project>{e4ef614b-30df-4954-8c53-580a0bf6b589}</Project> <Project>{e4ef614b-30df-4954-8c53-580a0bf6b589}</Project>
......
...@@ -55,7 +55,7 @@ EXAMPLES ...@@ -55,7 +55,7 @@ EXAMPLES
This tool is experimental. In particular, it assumes that there is no This tool is experimental. In particular, it assumes that there is no
conditional inclusion of Google Mock or Google Test headers. Please conditional inclusion of Google Mock or Google Test headers. Please
report any problems to googlemock@googlegroups.com. You can read report any problems to googlemock@googlegroups.com. You can read
http://code.google.com/p/googlemock/wiki/CookBook for more https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md for more
information. information.
""" """
......
The Google Mock class generator is an application that is part of cppclean. The Google Mock class generator is an application that is part of cppclean.
For more information about cppclean, see the README.cppclean file or For more information about cppclean, visit http://code.google.com/p/cppclean/
visit http://code.google.com/p/cppclean/
cppclean requires Python 2.3.5 or later. If you don't have Python installed The mock generator requires Python 2.3.5 or later. If you don't have Python
on your system, you will also need to install it. You can download Python installed on your system, you will also need to install it. You can download
from: http://www.python.org/download/releases/ Python from: http://www.python.org/download/releases/
To use the Google Mock class generator, you need to call it 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 on the command line passing the header file and class for which you want
......
...@@ -338,7 +338,7 @@ class Class(_GenericDeclaration): ...@@ -338,7 +338,7 @@ class Class(_GenericDeclaration):
# TODO(nnorwitz): handle namespaces, etc. # TODO(nnorwitz): handle namespaces, etc.
if self.bases: if self.bases:
for token_list in self.bases: for token_list in self.bases:
# TODO(nnorwitz): bases are tokens, do name comparision. # TODO(nnorwitz): bases are tokens, do name comparison.
for token in token_list: for token in token_list:
if token.name == node.name: if token.name == node.name:
return True return True
...@@ -381,7 +381,7 @@ class Function(_GenericDeclaration): ...@@ -381,7 +381,7 @@ class Function(_GenericDeclaration):
def Requires(self, node): def Requires(self, node):
if self.parameters: if self.parameters:
# TODO(nnorwitz): parameters are tokens, do name comparision. # TODO(nnorwitz): parameters are tokens, do name comparison.
for p in self.parameters: for p in self.parameters:
if p.name == node.name: if p.name == node.name:
return True return True
...@@ -858,7 +858,7 @@ class AstBuilder(object): ...@@ -858,7 +858,7 @@ class AstBuilder(object):
last_token = self._GetNextToken() last_token = self._GetNextToken()
return tokens, last_token return tokens, last_token
# TODO(nnorwitz): remove _IgnoreUpTo() it shouldn't be necesary. # TODO(nnorwitz): remove _IgnoreUpTo() it shouldn't be necessary.
def _IgnoreUpTo(self, token_type, token): def _IgnoreUpTo(self, token_type, token):
unused_tokens = self._GetTokensUpTo(token_type, token) unused_tokens = self._GetTokensUpTo(token_type, token)
...@@ -1264,6 +1264,9 @@ class AstBuilder(object): ...@@ -1264,6 +1264,9 @@ class AstBuilder(object):
return self._GetNestedType(Union) return self._GetNestedType(Union)
def handle_enum(self): 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) return self._GetNestedType(Enum)
def handle_auto(self): def handle_auto(self):
......
...@@ -440,6 +440,24 @@ public: ...@@ -440,6 +440,24 @@ public:
MOCK_METHOD1(Bar, MOCK_METHOD1(Bar,
void(const FooType& test_arg)); 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( self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source)) expected, self.GenerateMocks(source))
......
...@@ -242,7 +242,7 @@ class AbstractRpcServer(object): ...@@ -242,7 +242,7 @@ class AbstractRpcServer(object):
The authentication process works as follows: The authentication process works as follows:
1) We get a username and password from the user 1) We get a username and password from the user
2) We use ClientLogin to obtain an AUTH token for the user 2) We use ClientLogin to obtain an AUTH token for the user
(see http://code.google.com/apis/accounts/AuthForInstalledApps.html). (see https://developers.google.com/identity/protocols/AuthForInstalledApps).
3) We pass the auth token to /_ah/login on the server to obtain an 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 authentication cookie. If login was successful, it tries to redirect
us to the URL we provided. us to the URL we provided.
...@@ -506,7 +506,7 @@ def EncodeMultipartFormData(fields, files): ...@@ -506,7 +506,7 @@ def EncodeMultipartFormData(fields, files):
(content_type, body) ready for httplib.HTTP instance. (content_type, body) ready for httplib.HTTP instance.
Source: Source:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 https://web.archive.org/web/20160116052001/code.activestate.com/recipes/146306
""" """
BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-' BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-'
CRLF = '\r\n' CRLF = '\r\n'
...@@ -807,7 +807,7 @@ class SubversionVCS(VersionControlSystem): ...@@ -807,7 +807,7 @@ class SubversionVCS(VersionControlSystem):
# svn cat translates keywords but svn diff doesn't. As a result of this # svn cat translates keywords but svn diff doesn't. As a result of this
# behavior patching.PatchChunks() fails with a chunk mismatch error. # behavior patching.PatchChunks() fails with a chunk mismatch error.
# This part was originally written by the Review Board development team # 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 (https://reviews.reviewboard.org/r/276/).
# Mapping of keywords to known aliases # Mapping of keywords to known aliases
svn_keywords = { svn_keywords = {
# Standard keywords # Standard keywords
...@@ -860,7 +860,7 @@ class SubversionVCS(VersionControlSystem): ...@@ -860,7 +860,7 @@ class SubversionVCS(VersionControlSystem):
status_lines = status.splitlines() status_lines = status.splitlines()
# If file is in a cl, the output will begin with # If file is in a cl, the output will begin with
# "\n--- Changelist 'cl_name':\n". See # "\n--- Changelist 'cl_name':\n". See
# http://svn.collab.net/repos/svn/trunk/notes/changelist-design.txt # https://web.archive.org/web/20090918234815/svn.collab.net/repos/svn/trunk/notes/changelist-design.txt
if (len(status_lines) == 3 and if (len(status_lines) == 3 and
not status_lines[0] and not status_lines[0] and
status_lines[1].startswith("--- Changelist")): status_lines[1].startswith("--- Changelist")):
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// //
// Google C++ Mocking Framework (Google Mock) // Google C++ Mocking Framework (Google Mock)
// //
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -92,7 +91,7 @@ class BetweenCardinalityImpl : public CardinalityInterface { ...@@ -92,7 +91,7 @@ class BetweenCardinalityImpl : public CardinalityInterface {
}; };
// Formats "n times" in a human-friendly way. // Formats "n times" in a human-friendly way.
inline internal::string FormatTimes(int n) { inline std::string FormatTimes(int n) {
if (n == 1) { if (n == 1) {
return "once"; return "once";
} else if (n == 2) { } else if (n == 2) {
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -47,12 +46,31 @@ ...@@ -47,12 +46,31 @@
namespace testing { namespace testing {
namespace internal { 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 // 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 // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
// treated as one word. For example, both "FooBar123" and // treated as one word. For example, both "FooBar123" and
// "foo_bar_123" are converted to "foo bar 123". // "foo_bar_123" are converted to "foo bar 123".
GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name) { GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name) {
string result; std::string result;
char prev_char = '\0'; char prev_char = '\0';
for (const char* p = id_name; *p != '\0'; prev_char = *(p++)) { for (const char* p = id_name; *p != '\0'; prev_char = *(p++)) {
// We don't care about the current locale as the input is // We don't care about the current locale as the input is
...@@ -71,12 +89,12 @@ GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name) { ...@@ -71,12 +89,12 @@ GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name) {
} }
// This class reports Google Mock failures as Google Test failures. A // This class reports Google Mock failures as Google Test failures. A
// user can define another class in a similar fashion if he intends to // user can define another class in a similar fashion if they intend to
// use Google Mock with a testing framework other than Google Test. // use Google Mock with a testing framework other than Google Test.
class GoogleTestFailureReporter : public FailureReporterInterface { class GoogleTestFailureReporter : public FailureReporterInterface {
public: public:
virtual void ReportFailure(FailureType type, const char* file, int line, virtual void ReportFailure(FailureType type, const char* file, int line,
const string& message) { const std::string& message) {
AssertHelper(type == kFatal ? AssertHelper(type == kFatal ?
TestPartResult::kFatalFailure : TestPartResult::kFatalFailure :
TestPartResult::kNonFatalFailure, TestPartResult::kNonFatalFailure,
...@@ -128,8 +146,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) { ...@@ -128,8 +146,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) {
// stack_frames_to_skip is treated as 0, since we don't know which // 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 // function calls will be inlined by the compiler and need to be
// conservative. // conservative.
GTEST_API_ void Log(LogSeverity severity, GTEST_API_ void Log(LogSeverity severity, const std::string& message,
const string& message,
int stack_frames_to_skip) { int stack_frames_to_skip) {
if (!LogIsVisible(severity)) if (!LogIsVisible(severity))
return; return;
...@@ -170,5 +187,17 @@ GTEST_API_ void Log(LogSeverity severity, ...@@ -170,5 +187,17 @@ GTEST_API_ void Log(LogSeverity severity,
std::cout << ::std::flush; 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 internal
} // namespace testing } // namespace testing
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -38,98 +37,133 @@ ...@@ -38,98 +37,133 @@
#include "gmock/gmock-generated-matchers.h" #include "gmock/gmock-generated-matchers.h"
#include <string.h> #include <string.h>
#include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
namespace testing { 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. // equal to s.
Matcher<const internal::string&>::Matcher(const internal::string& s) { Matcher<const std::string&>::Matcher(const std::string& s) { *this = Eq(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. // equal to s.
Matcher<const internal::string&>::Matcher(const char* s) { Matcher<const std::string&>::Matcher(const char* s) {
*this = Eq(internal::string(s)); *this = Eq(std::string(s));
} }
// Constructs a matcher that matches a string whose value is equal to s. // Constructs a matcher that matches a std::string whose value is equal to
Matcher<internal::string>::Matcher(const internal::string& s) { *this = Eq(s); } // 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. #if GTEST_HAS_GLOBAL_STRING
Matcher<internal::string>::Matcher(const char* s) { // Constructs a matcher that matches a std::string whose value is equal to
*this = Eq(internal::string(s)); // 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_ #if GTEST_HAS_GLOBAL_STRING
// Constructs a matcher that matches a const StringPiece& whose value is // Constructs a matcher that matches a const ::string& whose value is
// equal to s. // equal to s.
Matcher<const StringPiece&>::Matcher(const internal::string& s) { Matcher<const ::string&>::Matcher(const std::string& s) {
*this = Eq(s); *this = Eq(static_cast<::string>(s));
} }
// Constructs a matcher that matches a const StringPiece& whose value is // Constructs a matcher that matches a const ::string& whose value is
// equal to s. // equal to s.
Matcher<const StringPiece&>::Matcher(const char* s) { Matcher<const ::string&>::Matcher(const ::string& s) { *this = Eq(s); }
*this = Eq(internal::string(s));
}
// Constructs a matcher that matches a const StringPiece& whose value is // Constructs a matcher that matches a const ::string& whose value is
// equal to s. // equal to s.
Matcher<const StringPiece&>::Matcher(StringPiece s) { Matcher<const ::string&>::Matcher(const char* s) { *this = Eq(::string(s)); }
*this = Eq(s.ToString());
// 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. // Constructs a matcher that matches a ::string whose value is equal to s.
Matcher<StringPiece>::Matcher(const internal::string& 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); *this = Eq(s);
} }
// Constructs a matcher that matches a StringPiece whose value is equal to s. #if GTEST_HAS_GLOBAL_STRING
Matcher<StringPiece>::Matcher(const char* s) { // Constructs a matcher that matches a const absl::string_view& whose value is
*this = Eq(internal::string(s)); // 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. // Constructs a matcher that matches a const absl::string_view& whose value is
Matcher<StringPiece>::Matcher(StringPiece s) { // equal to s.
*this = Eq(s.ToString()); 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 #if GTEST_HAS_GLOBAL_STRING
// the joined string. // Constructs a matcher that matches a absl::string_view whose value is equal to
GTEST_API_ string JoinAsTuple(const Strings& fields) { // s.
switch (fields.size()) { Matcher<absl::string_view>::Matcher(const ::string& s) { *this = Eq(s); }
case 0: #endif // GTEST_HAS_GLOBAL_STRING
return "";
case 1: // Constructs a matcher that matches a absl::string_view whose value is equal to
return fields[0]; // s.
default: Matcher<absl::string_view>::Matcher(const char* s) {
string result = "(" + fields[0]; *this = Eq(std::string(s));
for (size_t i = 1; i < fields.size(); i++) {
result += ", ";
result += fields[i];
}
result += ")";
return result;
}
} }
// 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*() // Returns the description for a matcher defined using the MATCHER*()
// macro where the user-supplied description string is "", if // macro where the user-supplied description string is "", if
// 'negation' is false; otherwise returns the description of the // 'negation' is false; otherwise returns the description of the
// negation of the matcher. 'param_values' contains a list of strings // negation of the matcher. 'param_values' contains a list of strings
// that are the print-out of the matcher's parameters. // that are the print-out of the matcher's parameters.
GTEST_API_ string FormatMatcherDescription(bool negation, GTEST_API_ std::string FormatMatcherDescription(bool negation,
const char* matcher_name, const char* matcher_name,
const Strings& param_values) { const Strings& param_values) {
string result = ConvertIdentifierNameToWords(matcher_name); std::string result = ConvertIdentifierNameToWords(matcher_name);
if (param_values.size() >= 1) if (param_values.size() >= 1) result += " " + JoinAsTuple(param_values);
result += " " + JoinAsTuple(param_values);
return negation ? "not (" + result + ")" : result; return negation ? "not (" + result + ")" : result;
} }
...@@ -200,8 +234,7 @@ class MaxBipartiteMatchState { ...@@ -200,8 +234,7 @@ class MaxBipartiteMatchState {
explicit MaxBipartiteMatchState(const MatchMatrix& graph) explicit MaxBipartiteMatchState(const MatchMatrix& graph)
: graph_(&graph), : graph_(&graph),
left_(graph_->LhsSize(), kUnused), left_(graph_->LhsSize(), kUnused),
right_(graph_->RhsSize(), kUnused) { right_(graph_->RhsSize(), kUnused) {}
}
// Returns the edges of a maximal match, each in the form {left, right}. // Returns the edges of a maximal match, each in the form {left, right}.
ElementMatcherPairs Compute() { ElementMatcherPairs Compute() {
...@@ -258,10 +291,8 @@ class MaxBipartiteMatchState { ...@@ -258,10 +291,8 @@ class MaxBipartiteMatchState {
// //
bool TryAugment(size_t ilhs, ::std::vector<char>* seen) { bool TryAugment(size_t ilhs, ::std::vector<char>* seen) {
for (size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) { for (size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) {
if ((*seen)[irhs]) if ((*seen)[irhs]) continue;
continue; if (!graph_->HasEdge(ilhs, irhs)) continue;
if (!graph_->HasEdge(ilhs, irhs))
continue;
// There's an available edge from ilhs to irhs. // There's an available edge from ilhs to irhs.
(*seen)[irhs] = 1; (*seen)[irhs] = 1;
// Next a search is performed to determine whether // Next a search is performed to determine whether
...@@ -288,7 +319,7 @@ class MaxBipartiteMatchState { ...@@ -288,7 +319,7 @@ class MaxBipartiteMatchState {
// Each element of the left_ vector represents a left hand side node // 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 // (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 // 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 // in the right_ indicate inflow, and specify which left_ node is
// feeding that right_ node, if any. For example, left_[3] == 1 means // 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 // there's a flow from element #3 to matcher #1. Such a flow would also
...@@ -304,8 +335,7 @@ class MaxBipartiteMatchState { ...@@ -304,8 +335,7 @@ class MaxBipartiteMatchState {
const size_t MaxBipartiteMatchState::kUnused; const size_t MaxBipartiteMatchState::kUnused;
GTEST_API_ ElementMatcherPairs GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix& g) {
FindMaxBipartiteMatching(const MatchMatrix& g) {
return MaxBipartiteMatchState(g).Compute(); return MaxBipartiteMatchState(g).Compute();
} }
...@@ -314,7 +344,7 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs, ...@@ -314,7 +344,7 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
typedef ElementMatcherPairs::const_iterator Iter; typedef ElementMatcherPairs::const_iterator Iter;
::std::ostream& os = *stream; ::std::ostream& os = *stream;
os << "{"; os << "{";
const char *sep = ""; const char* sep = "";
for (Iter it = pairs.begin(); it != pairs.end(); ++it) { for (Iter it = pairs.begin(); it != pairs.end(); ++it) {
os << sep << "\n (" os << sep << "\n ("
<< "element #" << it->first << ", " << "element #" << it->first << ", "
...@@ -324,38 +354,6 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs, ...@@ -324,38 +354,6 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs,
os << "\n}"; os << "\n}";
} }
// Tries to find a pairing, and explains the result.
GTEST_API_ bool FindPairing(const MatchMatrix& matrix,
MatchResultListener* listener) {
ElementMatcherPairs matches = FindMaxBipartiteMatching(matrix);
size_t max_flow = matches.size();
bool result = (max_flow == matrix.RhsSize());
if (!result) {
if (listener->IsInterested()) {
*listener << "where no permutation of the elements can "
"satisfy all matchers, and the closest match is "
<< max_flow << " of " << matrix.RhsSize()
<< " matchers with the pairings:\n";
LogElementMatcherPairVec(matches, listener->stream());
}
return false;
}
if (matches.size() > 1) {
if (listener->IsInterested()) {
const char *sep = "where:\n";
for (size_t mi = 0; mi < matches.size(); ++mi) {
*listener << sep << " - element #" << matches[mi].first
<< " is matched by matcher #" << matches[mi].second;
sep = ",\n";
}
}
}
return true;
}
bool MatchMatrix::NextGraph() { bool MatchMatrix::NextGraph() {
for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) { for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) {
for (size_t irhs = 0; irhs < RhsSize(); ++irhs) { for (size_t irhs = 0; irhs < RhsSize(); ++irhs) {
...@@ -379,9 +377,9 @@ void MatchMatrix::Randomize() { ...@@ -379,9 +377,9 @@ void MatchMatrix::Randomize() {
} }
} }
string MatchMatrix::DebugString() const { std::string MatchMatrix::DebugString() const {
::std::stringstream ss; ::std::stringstream ss;
const char *sep = ""; const char* sep = "";
for (size_t i = 0; i < LhsSize(); ++i) { for (size_t i = 0; i < LhsSize(); ++i) {
ss << sep; ss << sep;
for (size_t j = 0; j < RhsSize(); ++j) { for (size_t j = 0; j < RhsSize(); ++j) {
...@@ -394,44 +392,83 @@ string MatchMatrix::DebugString() const { ...@@ -394,44 +392,83 @@ string MatchMatrix::DebugString() const {
void UnorderedElementsAreMatcherImplBase::DescribeToImpl( void UnorderedElementsAreMatcherImplBase::DescribeToImpl(
::std::ostream* os) const { ::std::ostream* os) const {
if (matcher_describers_.empty()) { switch (match_flags()) {
*os << "is empty"; case UnorderedMatcherRequire::ExactMatch:
return; if (matcher_describers_.empty()) {
} *os << "is empty";
if (matcher_describers_.size() == 1) { return;
*os << "has " << Elements(1) << " and that element "; }
matcher_describers_[0]->DescribeTo(os); if (matcher_describers_.size() == 1) {
return; *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 = ""; const char* sep = "";
for (size_t i = 0; i != matcher_describers_.size(); ++i) { for (size_t i = 0; i != matcher_describers_.size(); ++i) {
*os << sep << " - element #" << i << " "; *os << sep;
if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
*os << " - element #" << i << " ";
} else {
*os << " - an element ";
}
matcher_describers_[i]->DescribeTo(os); matcher_describers_[i]->DescribeTo(os);
sep = ", and\n"; if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
sep = ", and\n";
} else {
sep = "\n";
}
} }
} }
void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl( void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
::std::ostream* os) const { ::std::ostream* os) const {
if (matcher_describers_.empty()) { switch (match_flags()) {
*os << "isn't empty"; case UnorderedMatcherRequire::ExactMatch:
return; if (matcher_describers_.empty()) {
} *os << "isn't empty";
if (matcher_describers_.size() == 1) { return;
*os << "doesn't have " << Elements(1) }
<< ", or has " << Elements(1) << " that "; if (matcher_describers_.size() == 1) {
matcher_describers_[0]->DescribeNegationTo(os); *os << "doesn't have " << Elements(1) << ", or has " << Elements(1)
return; << " 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 = ""; const char* sep = "";
for (size_t i = 0; i != matcher_describers_.size(); ++i) { for (size_t i = 0; i != matcher_describers_.size(); ++i) {
*os << sep << " - element #" << i << " "; *os << sep;
if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
*os << " - element #" << i << " ";
} else {
*os << " - an element ";
}
matcher_describers_[i]->DescribeTo(os); matcher_describers_[i]->DescribeTo(os);
sep = ", and\n"; if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
sep = ", and\n";
} else {
sep = "\n";
}
} }
} }
...@@ -440,11 +477,9 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl( ...@@ -440,11 +477,9 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
// and better error reporting. // and better error reporting.
// Returns false, writing an explanation to 'listener', if and only // Returns false, writing an explanation to 'listener', if and only
// if the success criteria are not met. // if the success criteria are not met.
bool UnorderedElementsAreMatcherImplBase:: bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
VerifyAllElementsAndMatchersAreMatched( const ::std::vector<std::string>& element_printouts,
const ::std::vector<string>& element_printouts, const MatchMatrix& matrix, MatchResultListener* listener) const {
const MatchMatrix& matrix,
MatchResultListener* listener) const {
bool result = true; bool result = true;
::std::vector<char> element_matched(matrix.LhsSize(), 0); ::std::vector<char> element_matched(matrix.LhsSize(), 0);
::std::vector<char> matcher_matched(matrix.RhsSize(), 0); ::std::vector<char> matcher_matched(matrix.RhsSize(), 0);
...@@ -457,12 +492,11 @@ VerifyAllElementsAndMatchersAreMatched( ...@@ -457,12 +492,11 @@ VerifyAllElementsAndMatchersAreMatched(
} }
} }
{ if (match_flags() & UnorderedMatcherRequire::Superset) {
const char* sep = const char* sep =
"where the following matchers don't match any elements:\n"; "where the following matchers don't match any elements:\n";
for (size_t mi = 0; mi < matcher_matched.size(); ++mi) { for (size_t mi = 0; mi < matcher_matched.size(); ++mi) {
if (matcher_matched[mi]) if (matcher_matched[mi]) continue;
continue;
result = false; result = false;
if (listener->IsInterested()) { if (listener->IsInterested()) {
*listener << sep << "matcher #" << mi << ": "; *listener << sep << "matcher #" << mi << ": ";
...@@ -472,7 +506,7 @@ VerifyAllElementsAndMatchersAreMatched( ...@@ -472,7 +506,7 @@ VerifyAllElementsAndMatchersAreMatched(
} }
} }
{ if (match_flags() & UnorderedMatcherRequire::Subset) {
const char* sep = const char* sep =
"where the following elements don't match any matchers:\n"; "where the following elements don't match any matchers:\n";
const char* outer_sep = ""; const char* outer_sep = "";
...@@ -480,8 +514,7 @@ VerifyAllElementsAndMatchersAreMatched( ...@@ -480,8 +514,7 @@ VerifyAllElementsAndMatchersAreMatched(
outer_sep = "\nand "; outer_sep = "\nand ";
} }
for (size_t ei = 0; ei < element_matched.size(); ++ei) { for (size_t ei = 0; ei < element_matched.size(); ++ei) {
if (element_matched[ei]) if (element_matched[ei]) continue;
continue;
result = false; result = false;
if (listener->IsInterested()) { if (listener->IsInterested()) {
*listener << outer_sep << sep << "element #" << ei << ": " *listener << outer_sep << sep << "element #" << ei << ": "
...@@ -494,5 +527,46 @@ VerifyAllElementsAndMatchersAreMatched( ...@@ -494,5 +527,46 @@ VerifyAllElementsAndMatchersAreMatched(
return result; return result;
} }
bool UnorderedElementsAreMatcherImplBase::FindPairing(
const MatchMatrix& matrix, MatchResultListener* listener) const {
ElementMatcherPairs matches = FindMaxBipartiteMatching(matrix);
size_t max_flow = matches.size();
if ((match_flags() & UnorderedMatcherRequire::Superset) &&
max_flow < matrix.RhsSize()) {
if (listener->IsInterested()) {
*listener << "where no permutation of the elements can satisfy all "
"matchers, and the closest match is "
<< max_flow << " of " << matrix.RhsSize()
<< " matchers with the pairings:\n";
LogElementMatcherPairVec(matches, listener->stream());
}
return false;
}
if ((match_flags() & UnorderedMatcherRequire::Subset) &&
max_flow < matrix.LhsSize()) {
if (listener->IsInterested()) {
*listener
<< "where not all elements can be matched, and the closest match is "
<< max_flow << " of " << matrix.RhsSize()
<< " matchers with the pairings:\n";
LogElementMatcherPairVec(matches, listener->stream());
}
return false;
}
if (matches.size() > 1) {
if (listener->IsInterested()) {
const char* sep = "where:\n";
for (size_t mi = 0; mi < matches.size(); ++mi) {
*listener << sep << " - element #" << matches[mi].first
<< " is matched by matcher #" << matches[mi].second;
sep = ",\n";
}
}
}
return true;
}
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -41,6 +40,7 @@ ...@@ -41,6 +40,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include <string> #include <string>
#include <vector>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -48,6 +48,15 @@ ...@@ -48,6 +48,15 @@
# include <unistd.h> // NOLINT # include <unistd.h> // NOLINT
#endif #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 testing {
namespace internal { namespace internal {
...@@ -58,16 +67,15 @@ GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_gmock_mutex); ...@@ -58,16 +67,15 @@ GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_gmock_mutex);
// Logs a message including file and line number information. // Logs a message including file and line number information.
GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity, GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
const char* file, int line, const char* file, int line,
const string& message) { const std::string& message) {
::std::ostringstream s; ::std::ostringstream s;
s << file << ":" << line << ": " << message << ::std::endl; s << file << ":" << line << ": " << message << ::std::endl;
Log(severity, s.str(), 0); Log(severity, s.str(), 0);
} }
// Constructs an ExpectationBase object. // Constructs an ExpectationBase object.
ExpectationBase::ExpectationBase(const char* a_file, ExpectationBase::ExpectationBase(const char* a_file, int a_line,
int a_line, const std::string& a_source_text)
const string& a_source_text)
: file_(a_file), : file_(a_file),
line_(a_line), line_(a_line),
source_text_(a_source_text), source_text_(a_source_text),
...@@ -100,12 +108,19 @@ void ExpectationBase::RetireAllPreRequisites() ...@@ -100,12 +108,19 @@ void ExpectationBase::RetireAllPreRequisites()
return; return;
} }
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); ::std::vector<ExpectationBase*> expectations(1, this);
it != immediate_prerequisites_.end(); ++it) { while (!expectations.empty()) {
ExpectationBase* const prerequisite = it->expectation_base().get(); ExpectationBase* exp = expectations.back();
if (!prerequisite->is_retired()) { expectations.pop_back();
prerequisite->RetireAllPreRequisites();
prerequisite->Retire(); 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() ...@@ -115,11 +130,18 @@ void ExpectationBase::RetireAllPreRequisites()
bool ExpectationBase::AllPrerequisitesAreSatisfied() const bool ExpectationBase::AllPrerequisitesAreSatisfied() const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); ::std::vector<const ExpectationBase*> expectations(1, this);
it != immediate_prerequisites_.end(); ++it) { while (!expectations.empty()) {
if (!(it->expectation_base()->IsSatisfied()) || const ExpectationBase* exp = expectations.back();
!(it->expectation_base()->AllPrerequisitesAreSatisfied())) expectations.pop_back();
return false;
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; return true;
} }
...@@ -128,19 +150,28 @@ bool ExpectationBase::AllPrerequisitesAreSatisfied() const ...@@ -128,19 +150,28 @@ bool ExpectationBase::AllPrerequisitesAreSatisfied() const
void ExpectationBase::FindUnsatisfiedPrerequisites(ExpectationSet* result) const void ExpectationBase::FindUnsatisfiedPrerequisites(ExpectationSet* result) const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); ::std::vector<const ExpectationBase*> expectations(1, this);
it != immediate_prerequisites_.end(); ++it) { while (!expectations.empty()) {
if (it->expectation_base()->IsSatisfied()) { const ExpectationBase* exp = expectations.back();
// If *it is satisfied and has a call count of 0, some of its expectations.pop_back();
// pre-requisites may not be satisfied yet.
if (it->expectation_base()->call_count_ == 0) { for (ExpectationSet::const_iterator it =
it->expectation_base()->FindUnsatisfiedPrerequisites(result); 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; ...@@ -244,7 +275,7 @@ GTEST_API_ ThreadLocal<Sequence*> g_gmock_implicit_sequence;
// Reports an uninteresting call (whose description is in msg) in the // Reports an uninteresting call (whose description is in msg) in the
// manner specified by 'reaction'. // 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. // Include a stack trace only if --gmock_verbose=info is specified.
const int stack_frames_to_skip = const int stack_frames_to_skip =
GMOCK_FLAG(verbose) == kInfoVerbosity ? 3 : -1; GMOCK_FLAG(verbose) == kInfoVerbosity ? 3 : -1;
...@@ -255,20 +286,22 @@ void ReportUninterestingCall(CallReaction reaction, const string& msg) { ...@@ -255,20 +286,22 @@ void ReportUninterestingCall(CallReaction reaction, const string& msg) {
case kWarn: case kWarn:
Log(kWarning, Log(kWarning,
msg + msg +
"\nNOTE: You can safely ignore the above warning unless this " "\nNOTE: You can safely ignore the above warning unless this "
"call should not happen. Do not suppress it by blindly adding " "call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. " "an EXPECT_CALL() if you don't mean to enforce the call. "
"See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#" "See "
"knowing-when-to-expect for details.\n", "https://github.com/google/googletest/blob/master/googlemock/"
"docs/CookBook.md#"
"knowing-when-to-expect for details.\n",
stack_frames_to_skip); stack_frames_to_skip);
break; break;
default: // FAIL default: // FAIL
Expect(false, NULL, -1, msg); Expect(false, nullptr, -1, msg);
} }
} }
UntypedFunctionMockerBase::UntypedFunctionMockerBase() UntypedFunctionMockerBase::UntypedFunctionMockerBase()
: mock_obj_(NULL), name_("") {} : mock_obj_(nullptr), name_("") {}
UntypedFunctionMockerBase::~UntypedFunctionMockerBase() {} UntypedFunctionMockerBase::~UntypedFunctionMockerBase() {}
...@@ -307,7 +340,7 @@ const void* UntypedFunctionMockerBase::MockObject() const ...@@ -307,7 +340,7 @@ const void* UntypedFunctionMockerBase::MockObject() const
// We protect mock_obj_ under g_gmock_mutex in case this mock // We protect mock_obj_ under g_gmock_mutex in case this mock
// function is called from two threads concurrently. // function is called from two threads concurrently.
MutexLock l(&g_gmock_mutex); 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 " "MockObject() must not be called before RegisterOwner() or "
"SetOwnerAndName() has been called."); "SetOwnerAndName() has been called.");
mock_obj = mock_obj_; mock_obj = mock_obj_;
...@@ -324,7 +357,7 @@ const char* UntypedFunctionMockerBase::Name() const ...@@ -324,7 +357,7 @@ const char* UntypedFunctionMockerBase::Name() const
// We protect name_ under g_gmock_mutex in case this mock // We protect name_ under g_gmock_mutex in case this mock
// function is called from two threads concurrently. // function is called from two threads concurrently.
MutexLock l(&g_gmock_mutex); MutexLock l(&g_gmock_mutex);
Assert(name_ != NULL, __FILE__, __LINE__, Assert(name_ != nullptr, __FILE__, __LINE__,
"Name() must not be called before SetOwnerAndName() has " "Name() must not be called before SetOwnerAndName() has "
"been called."); "been called.");
name = name_; name = name_;
...@@ -335,9 +368,10 @@ const char* UntypedFunctionMockerBase::Name() const ...@@ -335,9 +368,10 @@ const char* UntypedFunctionMockerBase::Name() const
// Calculates the result of invoking this mock function with the given // Calculates the result of invoking this mock function with the given
// arguments, prints it, and returns it. The caller is responsible // arguments, prints it, and returns it. The caller is responsible
// for deleting the result. // for deleting the result.
UntypedActionResultHolderBase* UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith(
UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) void* const untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
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) { if (untyped_expectations_.size() == 0) {
// No expectation is set on this mock method - we have an // No expectation is set on this mock method - we have an
// uninteresting call. // uninteresting call.
...@@ -354,18 +388,21 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) ...@@ -354,18 +388,21 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
// the behavior of ReportUninterestingCall(). // the behavior of ReportUninterestingCall().
const bool need_to_report_uninteresting_call = const bool need_to_report_uninteresting_call =
// If the user allows this uninteresting call, we print it // If the user allows this uninteresting call, we print it
// only when he wants informational messages. // only when they want informational messages.
reaction == kAllow ? LogIsVisible(kInfo) : reaction == kAllow ? LogIsVisible(kInfo) :
// If the user wants this to be a warning, we print it only // If the user wants this to be a warning, we print
// when he wants to see warnings. // it only when they want to see warnings.
reaction == kWarn ? LogIsVisible(kWarning) : reaction == kWarn
// Otherwise, the user wants this to be an error, and we ? LogIsVisible(kWarning)
// should always print detailed information in the error. :
true; // 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) { if (!need_to_report_uninteresting_call) {
// Perform the action without printing the call information. // 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. // Warns about the uninteresting call.
...@@ -377,8 +414,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) ...@@ -377,8 +414,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
this->UntypedPerformDefaultAction(untyped_args, ss.str()); this->UntypedPerformDefaultAction(untyped_args, ss.str());
// Prints the function result. // Prints the function result.
if (result != NULL) if (result != nullptr) result->PrintAsActionResult(&ss);
result->PrintAsActionResult(&ss);
ReportUninterestingCall(reaction, ss.str()); ReportUninterestingCall(reaction, ss.str());
return result; return result;
...@@ -388,7 +424,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) ...@@ -388,7 +424,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
::std::stringstream ss; ::std::stringstream ss;
::std::stringstream why; ::std::stringstream why;
::std::stringstream loc; ::std::stringstream loc;
const void* untyped_action = NULL; const void* untyped_action = nullptr;
// The UntypedFindMatchingExpectation() function acquires and // The UntypedFindMatchingExpectation() function acquires and
// releases g_gmock_mutex. // releases g_gmock_mutex.
...@@ -396,7 +432,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) ...@@ -396,7 +432,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
this->UntypedFindMatchingExpectation( this->UntypedFindMatchingExpectation(
untyped_args, &untyped_action, &is_excessive, untyped_args, &untyped_action, &is_excessive,
&ss, &why); &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. // 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() // This definition must be kept in sync with the uses of Expect()
...@@ -405,10 +441,9 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) ...@@ -405,10 +441,9 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
!found || is_excessive || LogIsVisible(kInfo); !found || is_excessive || LogIsVisible(kInfo);
if (!need_to_report_call) { if (!need_to_report_call) {
// Perform the action without printing the call information. // Perform the action without printing the call information.
return return untyped_action == nullptr
untyped_action == NULL ? ? this->UntypedPerformDefaultAction(untyped_args, "")
this->UntypedPerformDefaultAction(untyped_args, "") : : this->UntypedPerformAction(untyped_action, untyped_args);
this->UntypedPerformAction(untyped_action, untyped_args);
} }
ss << " Function call: " << Name(); ss << " Function call: " << Name();
...@@ -421,16 +456,15 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) ...@@ -421,16 +456,15 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
} }
UntypedActionResultHolderBase* const result = UntypedActionResultHolderBase* const result =
untyped_action == NULL ? untyped_action == nullptr
this->UntypedPerformDefaultAction(untyped_args, ss.str()) : ? this->UntypedPerformDefaultAction(untyped_args, ss.str())
this->UntypedPerformAction(untyped_action, untyped_args); : this->UntypedPerformAction(untyped_action, untyped_args);
if (result != NULL) if (result != nullptr) result->PrintAsActionResult(&ss);
result->PrintAsActionResult(&ss);
ss << "\n" << why.str(); ss << "\n" << why.str();
if (!found) { if (!found) {
// No expectation matches this call - reports a failure. // No expectation matches this call - reports a failure.
Expect(false, NULL, -1, ss.str()); Expect(false, nullptr, -1, ss.str());
} else if (is_excessive) { } else if (is_excessive) {
// We had an upper-bound violation and the failure message is in ss. // We had an upper-bound violation and the failure message is in ss.
Expect(false, untyped_expectation->file(), Expect(false, untyped_expectation->file(),
...@@ -447,6 +481,8 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) ...@@ -447,6 +481,8 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
// Returns an Expectation object that references and co-owns exp, // Returns an Expectation object that references and co-owns exp,
// which must be an expectation on this mock function. // which must be an expectation on this mock function.
Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) { Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) {
// See the definition of untyped_expectations_ for why access to it
// is unprotected here.
for (UntypedExpectations::const_iterator it = for (UntypedExpectations::const_iterator it =
untyped_expectations_.begin(); untyped_expectations_.begin();
it != untyped_expectations_.end(); ++it) { it != untyped_expectations_.end(); ++it) {
...@@ -509,6 +545,13 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() ...@@ -509,6 +545,13 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
return expectations_met; 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 } // namespace internal
// Class Mock. // Class Mock.
...@@ -522,7 +565,7 @@ typedef std::set<internal::UntypedFunctionMockerBase*> FunctionMockers; ...@@ -522,7 +565,7 @@ typedef std::set<internal::UntypedFunctionMockerBase*> FunctionMockers;
// expectations. // expectations.
struct MockObjectState { struct MockObjectState {
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 // Where in the source file an ON_CALL or EXPECT_CALL is first
// invoked on this mock object. // invoked on this mock object.
...@@ -560,7 +603,7 @@ class MockObjectRegistry { ...@@ -560,7 +603,7 @@ class MockObjectRegistry {
if (it->second.leakable) // The user said it's fine to leak this object. if (it->second.leakable) // The user said it's fine to leak this object.
continue; 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. // This can help the user identify the leaked object.
std::cout << "\n"; std::cout << "\n";
const MockObjectState& state = it->second; const MockObjectState& state = it->second;
...@@ -576,9 +619,15 @@ class MockObjectRegistry { ...@@ -576,9 +619,15 @@ class MockObjectRegistry {
leaked_count++; leaked_count++;
} }
if (leaked_count > 0) { if (leaked_count > 0) {
std::cout << "\nERROR: " << leaked_count std::cout << "\nERROR: " << leaked_count << " leaked mock "
<< " leaked mock " << (leaked_count == 1 ? "object" : "objects") << (leaked_count == 1 ? "object" : "objects")
<< " found at program exit.\n"; << " 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::cout.flush();
::std::cerr.flush(); ::std::cerr.flush();
// RUN_ALL_TESTS() has already returned when this destructor is // RUN_ALL_TESTS() has already returned when this destructor is
...@@ -649,7 +698,8 @@ internal::CallReaction Mock::GetReactionOnUninterestingCalls( ...@@ -649,7 +698,8 @@ internal::CallReaction Mock::GetReactionOnUninterestingCalls(
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
internal::MutexLock l(&internal::g_gmock_mutex); internal::MutexLock l(&internal::g_gmock_mutex);
return (g_uninteresting_call_reaction.count(mock_obj) == 0) ? 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 // Tells Google Mock to ignore mock_obj when checking for leaked mock
...@@ -736,13 +786,13 @@ void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj, ...@@ -736,13 +786,13 @@ void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj,
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
internal::MutexLock l(&internal::g_gmock_mutex); internal::MutexLock l(&internal::g_gmock_mutex);
MockObjectState& state = g_mock_object_registry.states()[mock_obj]; 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_file = file;
state.first_used_line = line; state.first_used_line = line;
const TestInfo* const test_info = const TestInfo* const test_info =
UnitTest::GetInstance()->current_test_info(); UnitTest::GetInstance()->current_test_info();
if (test_info != NULL) { if (test_info != nullptr) {
// TODO(wan@google.com): record the test case name when the // FIXME: record the test case name when the
// ON_CALL or EXPECT_CALL is invoked from SetUpTestCase() or // ON_CALL or EXPECT_CALL is invoked from SetUpTestCase() or
// TearDownTestCase(). // TearDownTestCase().
state.first_used_test_case = test_info->test_case_name(); state.first_used_test_case = test_info->test_case_name();
...@@ -806,7 +856,7 @@ Expectation::~Expectation() {} ...@@ -806,7 +856,7 @@ Expectation::~Expectation() {}
// Adds an expectation to a sequence. // Adds an expectation to a sequence.
void Sequence::AddExpectation(const Expectation& expectation) const { void Sequence::AddExpectation(const Expectation& expectation) const {
if (*last_expectation_ != expectation) { if (*last_expectation_ != expectation) {
if (last_expectation_->expectation_base() != NULL) { if (last_expectation_->expectation_base() != nullptr) {
expectation.expectation_base()->immediate_prerequisites_ expectation.expectation_base()->immediate_prerequisites_
+= *last_expectation_; += *last_expectation_;
} }
...@@ -834,3 +884,9 @@ InSequence::~InSequence() { ...@@ -834,3 +884,9 @@ InSequence::~InSequence() {
} }
} // namespace testing } // namespace testing
#ifdef _MSC_VER
#if _MSC_VER <= 1900
# pragma warning(pop)
#endif
#endif
...@@ -26,15 +26,14 @@ ...@@ -26,15 +26,14 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
namespace testing { 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. // control the flag values, like what Google Test does.
GMOCK_DEFINE_bool_(catch_leaked_mocks, true, GMOCK_DEFINE_bool_(catch_leaked_mocks, true,
...@@ -48,6 +47,13 @@ GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity, ...@@ -48,6 +47,13 @@ GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
" warning - prints warnings and errors.\n" " warning - prints warnings and errors.\n"
" error - prints errors only."); " 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 { namespace internal {
// Parses a string as a command line flag. The string should have the // Parses a string as a command line flag. The string should have the
...@@ -59,12 +65,12 @@ static const char* ParseGoogleMockFlagValue(const char* str, ...@@ -59,12 +65,12 @@ static const char* ParseGoogleMockFlagValue(const char* str,
const char* flag, const char* flag,
bool def_optional) { bool def_optional) {
// str and flag must not be NULL. // 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_". // The flag must start with "--gmock_".
const std::string flag_str = std::string("--gmock_") + flag; const std::string flag_str = std::string("--gmock_") + flag;
const size_t flag_len = flag_str.length(); 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. // Skips the flag name.
const char* flag_end = str + flag_len; const char* flag_end = str + flag_len;
...@@ -77,7 +83,7 @@ static const char* ParseGoogleMockFlagValue(const char* str, ...@@ -77,7 +83,7 @@ static const char* ParseGoogleMockFlagValue(const char* str,
// If def_optional is true and there are more characters after the // 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 // flag name, or if def_optional is false, there must be a '=' after
// the flag name. // the flag name.
if (flag_end[0] != '=') return NULL; if (flag_end[0] != '=') return nullptr;
// Returns the string after "=". // Returns the string after "=".
return flag_end + 1; return flag_end + 1;
...@@ -94,7 +100,7 @@ static bool ParseGoogleMockBoolFlag(const char* str, const char* flag, ...@@ -94,7 +100,7 @@ static bool ParseGoogleMockBoolFlag(const char* str, const char* flag,
const char* const value_str = ParseGoogleMockFlagValue(str, flag, true); const char* const value_str = ParseGoogleMockFlagValue(str, flag, true);
// Aborts if the parsing failed. // Aborts if the parsing failed.
if (value_str == NULL) return false; if (value_str == nullptr) return false;
// Converts the string value to a bool. // Converts the string value to a bool.
*value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F'); *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F');
...@@ -113,13 +119,26 @@ static bool ParseGoogleMockStringFlag(const char* str, const char* flag, ...@@ -113,13 +119,26 @@ static bool ParseGoogleMockStringFlag(const char* str, const char* flag,
const char* const value_str = ParseGoogleMockFlagValue(str, flag, false); const char* const value_str = ParseGoogleMockFlagValue(str, flag, false);
// Aborts if the parsing failed. // 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. // Sets *value to the value of the flag.
*value = value_str; *value = value_str;
return true; 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 internal implementation of InitGoogleMock().
// //
// The type parameter CharType can be instantiated to either char or // The type parameter CharType can be instantiated to either char or
...@@ -138,7 +157,9 @@ void InitGoogleMockImpl(int* argc, CharType** argv) { ...@@ -138,7 +157,9 @@ void InitGoogleMockImpl(int* argc, CharType** argv) {
// Do we see a Google Mock flag? // Do we see a Google Mock flag?
if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks", if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks",
&GMOCK_FLAG(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 // Yes. Shift the remainder of the argv list left by one. Note
// that argv has (*argc + 1) elements, the last one always being // that argv has (*argc + 1) elements, the last one always being
// NULL. The following loop moves the trailing NULL element as // NULL. The following loop moves the trailing NULL element as
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
#include <iostream> #include <iostream>
#include "gmock/gmock.h" #include "gmock/gmock.h"
...@@ -37,7 +36,8 @@ ...@@ -37,7 +36,8 @@
// causes a link error when _tmain is defined in a static library and UNICODE // 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 // 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: // 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 #if GTEST_OS_WINDOWS_MOBILE
# include <tchar.h> // NOLINT # include <tchar.h> // NOLINT
......
# 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",
],
)
...@@ -26,13 +26,21 @@ ...@@ -26,13 +26,21 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
// This file tests the built-in actions. // 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 "gmock/gmock-actions.h"
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
...@@ -65,28 +73,21 @@ using testing::ReturnRef; ...@@ -65,28 +73,21 @@ using testing::ReturnRef;
using testing::ReturnRefOfCopy; using testing::ReturnRefOfCopy;
using testing::SetArgPointee; using testing::SetArgPointee;
using testing::SetArgumentPointee; using testing::SetArgumentPointee;
using testing::Unused;
using testing::_; using testing::_;
using testing::get;
using testing::internal::BuiltInDefaultValue; using testing::internal::BuiltInDefaultValue;
using testing::internal::Int64; using testing::internal::Int64;
using testing::internal::UInt64; using testing::internal::UInt64;
using testing::make_tuple;
using testing::tuple;
using testing::tuple_element;
#if !GTEST_OS_WINDOWS_MOBILE #if !GTEST_OS_WINDOWS_MOBILE
using testing::SetErrnoAndReturn; using testing::SetErrnoAndReturn;
#endif #endif
#if GTEST_HAS_PROTOBUF_
using testing::internal::TestMessage;
#endif // GTEST_HAS_PROTOBUF_
// Tests that BuiltInDefaultValue<T*>::Get() returns NULL. // Tests that BuiltInDefaultValue<T*>::Get() returns NULL.
TEST(BuiltInDefaultValueTest, IsNullForPointerTypes) { TEST(BuiltInDefaultValueTest, IsNullForPointerTypes) {
EXPECT_TRUE(BuiltInDefaultValue<int*>::Get() == NULL); EXPECT_TRUE(BuiltInDefaultValue<int*>::Get() == nullptr);
EXPECT_TRUE(BuiltInDefaultValue<const char*>::Get() == NULL); EXPECT_TRUE(BuiltInDefaultValue<const char*>::Get() == nullptr);
EXPECT_TRUE(BuiltInDefaultValue<void*>::Get() == NULL); EXPECT_TRUE(BuiltInDefaultValue<void*>::Get() == nullptr);
} }
// Tests that BuiltInDefaultValue<T*>::Exists() return true. // Tests that BuiltInDefaultValue<T*>::Exists() return true.
...@@ -107,7 +108,11 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) { ...@@ -107,7 +108,11 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
EXPECT_EQ(0, BuiltInDefaultValue<signed wchar_t>::Get()); EXPECT_EQ(0, BuiltInDefaultValue<signed wchar_t>::Get());
#endif #endif
#if GMOCK_WCHAR_T_IS_NATIVE_ #if GMOCK_WCHAR_T_IS_NATIVE_
#if !defined(__WCHAR_UNSIGNED__)
EXPECT_EQ(0, BuiltInDefaultValue<wchar_t>::Get()); EXPECT_EQ(0, BuiltInDefaultValue<wchar_t>::Get());
#else
EXPECT_EQ(0U, BuiltInDefaultValue<wchar_t>::Get());
#endif
#endif #endif
EXPECT_EQ(0U, BuiltInDefaultValue<unsigned short>::Get()); // NOLINT EXPECT_EQ(0U, BuiltInDefaultValue<unsigned short>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<signed short>::Get()); // NOLINT EXPECT_EQ(0, BuiltInDefaultValue<signed short>::Get()); // NOLINT
...@@ -187,7 +192,7 @@ TEST(BuiltInDefaultValueTest, ExistsForString) { ...@@ -187,7 +192,7 @@ TEST(BuiltInDefaultValueTest, ExistsForString) {
TEST(BuiltInDefaultValueTest, WorksForConstTypes) { TEST(BuiltInDefaultValueTest, WorksForConstTypes) {
EXPECT_EQ("", BuiltInDefaultValue<const std::string>::Get()); EXPECT_EQ("", BuiltInDefaultValue<const std::string>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<const int>::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()); EXPECT_FALSE(BuiltInDefaultValue<const bool>::Get());
} }
...@@ -214,7 +219,7 @@ class MyNonDefaultConstructible { ...@@ -214,7 +219,7 @@ class MyNonDefaultConstructible {
int value_; int value_;
}; };
#if GTEST_HAS_STD_TYPE_TRAITS_ #if GTEST_LANG_CXX11
TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) { TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) {
EXPECT_TRUE(BuiltInDefaultValue<MyDefaultConstructible>::Exists()); EXPECT_TRUE(BuiltInDefaultValue<MyDefaultConstructible>::Exists());
...@@ -224,7 +229,7 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) { ...@@ -224,7 +229,7 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) {
EXPECT_EQ(42, BuiltInDefaultValue<MyDefaultConstructible>::Get().value()); EXPECT_EQ(42, BuiltInDefaultValue<MyDefaultConstructible>::Get().value());
} }
#endif // GTEST_HAS_STD_TYPE_TRAITS_ #endif // GTEST_LANG_CXX11
TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) { TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) {
EXPECT_FALSE(BuiltInDefaultValue<MyNonDefaultConstructible>::Exists()); EXPECT_FALSE(BuiltInDefaultValue<MyNonDefaultConstructible>::Exists());
...@@ -297,7 +302,7 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) { ...@@ -297,7 +302,7 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
#if GTEST_HAS_STD_UNIQUE_PTR_ #if GTEST_HAS_STD_UNIQUE_PTR_
TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) { TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists()); 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([] { DefaultValue<std::unique_ptr<int>>::SetFactory([] {
return std::unique_ptr<int>(new int(42)); return std::unique_ptr<int>(new int(42));
}); });
...@@ -373,8 +378,8 @@ typedef int MyGlobalFunction(bool, int); ...@@ -373,8 +378,8 @@ typedef int MyGlobalFunction(bool, int);
class MyActionImpl : public ActionInterface<MyGlobalFunction> { class MyActionImpl : public ActionInterface<MyGlobalFunction> {
public: public:
virtual int Perform(const tuple<bool, int>& args) { virtual int Perform(const std::tuple<bool, int>& args) {
return get<0>(args) ? get<1>(args) : 0; return std::get<0>(args) ? std::get<1>(args) : 0;
} }
}; };
...@@ -390,8 +395,8 @@ TEST(ActionInterfaceTest, MakeAction) { ...@@ -390,8 +395,8 @@ TEST(ActionInterfaceTest, MakeAction) {
// it a tuple whose size and type are compatible with F's argument // it a tuple whose size and type are compatible with F's argument
// types. For example, if F is int(), then Perform() takes a // types. For example, if F is int(), then Perform() takes a
// 0-tuple; if F is void(bool, int), then Perform() takes a // 0-tuple; if F is void(bool, int), then Perform() takes a
// tuple<bool, int>, and so on. // std::tuple<bool, int>, and so on.
EXPECT_EQ(5, action.Perform(make_tuple(true, 5))); EXPECT_EQ(5, action.Perform(std::make_tuple(true, 5)));
} }
// Tests that Action<F> can be contructed from a pointer to // Tests that Action<F> can be contructed from a pointer to
...@@ -404,8 +409,8 @@ TEST(ActionTest, CanBeConstructedFromActionInterface) { ...@@ -404,8 +409,8 @@ TEST(ActionTest, CanBeConstructedFromActionInterface) {
TEST(ActionTest, DelegatesWorkToActionInterface) { TEST(ActionTest, DelegatesWorkToActionInterface) {
const Action<MyGlobalFunction> action(new MyActionImpl); const Action<MyGlobalFunction> action(new MyActionImpl);
EXPECT_EQ(5, action.Perform(make_tuple(true, 5))); EXPECT_EQ(5, action.Perform(std::make_tuple(true, 5)));
EXPECT_EQ(0, action.Perform(make_tuple(false, 1))); EXPECT_EQ(0, action.Perform(std::make_tuple(false, 1)));
} }
// Tests that Action<F> can be copied. // Tests that Action<F> can be copied.
...@@ -414,22 +419,22 @@ TEST(ActionTest, IsCopyable) { ...@@ -414,22 +419,22 @@ TEST(ActionTest, IsCopyable) {
Action<MyGlobalFunction> a2(a1); // Tests the copy constructor. Action<MyGlobalFunction> a2(a1); // Tests the copy constructor.
// a1 should continue to work after being copied from. // a1 should continue to work after being copied from.
EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); EXPECT_EQ(5, a1.Perform(std::make_tuple(true, 5)));
EXPECT_EQ(0, a1.Perform(make_tuple(false, 1))); EXPECT_EQ(0, a1.Perform(std::make_tuple(false, 1)));
// a2 should work like the action it was copied from. // a2 should work like the action it was copied from.
EXPECT_EQ(5, a2.Perform(make_tuple(true, 5))); EXPECT_EQ(5, a2.Perform(std::make_tuple(true, 5)));
EXPECT_EQ(0, a2.Perform(make_tuple(false, 1))); EXPECT_EQ(0, a2.Perform(std::make_tuple(false, 1)));
a2 = a1; // Tests the assignment operator. a2 = a1; // Tests the assignment operator.
// a1 should continue to work after being copied from. // a1 should continue to work after being copied from.
EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); EXPECT_EQ(5, a1.Perform(std::make_tuple(true, 5)));
EXPECT_EQ(0, a1.Perform(make_tuple(false, 1))); EXPECT_EQ(0, a1.Perform(std::make_tuple(false, 1)));
// a2 should work like the action it was copied from. // a2 should work like the action it was copied from.
EXPECT_EQ(5, a2.Perform(make_tuple(true, 5))); EXPECT_EQ(5, a2.Perform(std::make_tuple(true, 5)));
EXPECT_EQ(0, a2.Perform(make_tuple(false, 1))); EXPECT_EQ(0, a2.Perform(std::make_tuple(false, 1)));
} }
// Tests that an Action<From> object can be converted to a // Tests that an Action<From> object can be converted to a
...@@ -437,8 +442,8 @@ TEST(ActionTest, IsCopyable) { ...@@ -437,8 +442,8 @@ TEST(ActionTest, IsCopyable) {
class IsNotZero : public ActionInterface<bool(int)> { // NOLINT class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
public: public:
virtual bool Perform(const tuple<int>& arg) { virtual bool Perform(const std::tuple<int>& arg) {
return get<0>(arg) != 0; return std::get<0>(arg) != 0;
} }
}; };
...@@ -451,8 +456,8 @@ class IsNotZero : public ActionInterface<bool(int)> { // NOLINT ...@@ -451,8 +456,8 @@ class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
TEST(ActionTest, CanBeConvertedToOtherActionType) { TEST(ActionTest, CanBeConvertedToOtherActionType) {
const Action<bool(int)> a1(new IsNotZero); // NOLINT const Action<bool(int)> a1(new IsNotZero); // NOLINT
const Action<int(char)> a2 = Action<int(char)>(a1); // NOLINT const Action<int(char)> a2 = Action<int(char)>(a1); // NOLINT
EXPECT_EQ(1, a2.Perform(make_tuple('a'))); EXPECT_EQ(1, a2.Perform(std::make_tuple('a')));
EXPECT_EQ(0, a2.Perform(make_tuple('\0'))); EXPECT_EQ(0, a2.Perform(std::make_tuple('\0')));
} }
#endif // !GTEST_OS_SYMBIAN #endif // !GTEST_OS_SYMBIAN
...@@ -466,7 +471,9 @@ class ReturnSecondArgumentAction { ...@@ -466,7 +471,9 @@ class ReturnSecondArgumentAction {
// polymorphic action whose Perform() method template is either // polymorphic action whose Perform() method template is either
// const or not. This lets us verify the non-const case. // const or not. This lets us verify the non-const case.
template <typename Result, typename ArgumentTuple> 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 // Implements a polymorphic action that can be used in a nullary
...@@ -481,7 +488,9 @@ class ReturnZeroFromNullaryFunctionAction { ...@@ -481,7 +488,9 @@ class ReturnZeroFromNullaryFunctionAction {
// polymorphic action whose Perform() method template is either // polymorphic action whose Perform() method template is either
// const or not. This lets us verify the const case. // const or not. This lets us verify the const case.
template <typename Result> 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 // These functions verify that MakePolymorphicAction() returns a
...@@ -500,42 +509,42 @@ ReturnZeroFromNullaryFunction() { ...@@ -500,42 +509,42 @@ ReturnZeroFromNullaryFunction() {
// implementation class into a polymorphic action. // implementation class into a polymorphic action.
TEST(MakePolymorphicActionTest, ConstructsActionFromImpl) { TEST(MakePolymorphicActionTest, ConstructsActionFromImpl) {
Action<int(bool, int, double)> a1 = ReturnSecondArgument(); // NOLINT 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 // Tests that MakePolymorphicAction() works when the implementation
// class' Perform() method template has only one template parameter. // class' Perform() method template has only one template parameter.
TEST(MakePolymorphicActionTest, WorksWhenPerformHasOneTemplateParameter) { TEST(MakePolymorphicActionTest, WorksWhenPerformHasOneTemplateParameter) {
Action<int()> a1 = ReturnZeroFromNullaryFunction(); Action<int()> a1 = ReturnZeroFromNullaryFunction();
EXPECT_EQ(0, a1.Perform(make_tuple())); EXPECT_EQ(0, a1.Perform(std::make_tuple()));
Action<void*()> a2 = ReturnZeroFromNullaryFunction(); 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 // Tests that Return() works as an action for void-returning
// functions. // functions.
TEST(ReturnTest, WorksForVoid) { TEST(ReturnTest, WorksForVoid) {
const Action<void(int)> ret = Return(); // NOLINT 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. // Tests that Return(v) returns v.
TEST(ReturnTest, ReturnsGivenValue) { TEST(ReturnTest, ReturnsGivenValue) {
Action<int()> ret = Return(1); // NOLINT Action<int()> ret = Return(1); // NOLINT
EXPECT_EQ(1, ret.Perform(make_tuple())); EXPECT_EQ(1, ret.Perform(std::make_tuple()));
ret = Return(-5); ret = Return(-5);
EXPECT_EQ(-5, ret.Perform(make_tuple())); EXPECT_EQ(-5, ret.Perform(std::make_tuple()));
} }
// Tests that Return("string literal") works. // Tests that Return("string literal") works.
TEST(ReturnTest, AcceptsStringLiteral) { TEST(ReturnTest, AcceptsStringLiteral) {
Action<const char*()> a1 = Return("Hello"); 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"); 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 // Test struct which wraps a vector of integers. Used in
...@@ -554,7 +563,7 @@ TEST(ReturnTest, SupportsWrapperReturnType) { ...@@ -554,7 +563,7 @@ TEST(ReturnTest, SupportsWrapperReturnType) {
// Return() called with 'v' as argument. The Action will return the same data // Return() called with 'v' as argument. The Action will return the same data
// as 'v' (copy) but it will be wrapped in an IntegerVectorWrapper. // as 'v' (copy) but it will be wrapped in an IntegerVectorWrapper.
Action<IntegerVectorWrapper()> a = Return(v); 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)); EXPECT_THAT(result, ::testing::ElementsAre(0, 1, 2, 3, 4));
} }
...@@ -572,10 +581,10 @@ TEST(ReturnTest, IsCovariant) { ...@@ -572,10 +581,10 @@ TEST(ReturnTest, IsCovariant) {
Base base; Base base;
Derived derived; Derived derived;
Action<Base*()> ret = Return(&base); Action<Base*()> ret = Return(&base);
EXPECT_EQ(&base, ret.Perform(make_tuple())); EXPECT_EQ(&base, ret.Perform(std::make_tuple()));
ret = Return(&derived); 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 // Tests that the type of the value passed into Return is converted into T
...@@ -606,7 +615,7 @@ TEST(ReturnTest, ConvertsArgumentWhenConverted) { ...@@ -606,7 +615,7 @@ TEST(ReturnTest, ConvertsArgumentWhenConverted) {
EXPECT_TRUE(converted) << "Return must convert its argument in its own " EXPECT_TRUE(converted) << "Return must convert its argument in its own "
<< "conversion operator."; << "conversion operator.";
converted = false; converted = false;
action.Perform(tuple<>()); action.Perform(std::tuple<>());
EXPECT_FALSE(converted) << "Action must NOT convert its argument " EXPECT_FALSE(converted) << "Action must NOT convert its argument "
<< "when performed."; << "when performed.";
} }
...@@ -627,10 +636,10 @@ TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) { ...@@ -627,10 +636,10 @@ TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) {
// Tests that ReturnNull() returns NULL in a pointer-returning function. // Tests that ReturnNull() returns NULL in a pointer-returning function.
TEST(ReturnNullTest, WorksInPointerReturningFunction) { TEST(ReturnNullTest, WorksInPointerReturningFunction) {
const Action<int*()> a1 = ReturnNull(); 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 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_ #if GTEST_HAS_STD_UNIQUE_PTR_
...@@ -638,10 +647,10 @@ TEST(ReturnNullTest, WorksInPointerReturningFunction) { ...@@ -638,10 +647,10 @@ TEST(ReturnNullTest, WorksInPointerReturningFunction) {
// functions. // functions.
TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) { TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) {
const Action<std::unique_ptr<const int>()> a1 = ReturnNull(); 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(); 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_ #endif // GTEST_HAS_STD_UNIQUE_PTR_
...@@ -650,7 +659,7 @@ TEST(ReturnRefTest, WorksForReference) { ...@@ -650,7 +659,7 @@ TEST(ReturnRefTest, WorksForReference) {
const int n = 0; const int n = 0;
const Action<const int&(bool)> ret = ReturnRef(n); // NOLINT 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. // Tests that ReturnRef(v) is covariant.
...@@ -658,10 +667,10 @@ TEST(ReturnRefTest, IsCovariant) { ...@@ -658,10 +667,10 @@ TEST(ReturnRefTest, IsCovariant) {
Base base; Base base;
Derived derived; Derived derived;
Action<Base&()> a = ReturnRef(base); Action<Base&()> a = ReturnRef(base);
EXPECT_EQ(&base, &a.Perform(make_tuple())); EXPECT_EQ(&base, &a.Perform(std::make_tuple()));
a = ReturnRef(derived); 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. // Tests that ReturnRefOfCopy(v) works for reference types.
...@@ -669,12 +678,12 @@ TEST(ReturnRefOfCopyTest, WorksForReference) { ...@@ -669,12 +678,12 @@ TEST(ReturnRefOfCopyTest, WorksForReference) {
int n = 42; int n = 42;
const Action<const int&()> ret = ReturnRefOfCopy(n); const Action<const int&()> ret = ReturnRefOfCopy(n);
EXPECT_NE(&n, &ret.Perform(make_tuple())); EXPECT_NE(&n, &ret.Perform(std::make_tuple()));
EXPECT_EQ(42, ret.Perform(make_tuple())); EXPECT_EQ(42, ret.Perform(std::make_tuple()));
n = 43; n = 43;
EXPECT_NE(&n, &ret.Perform(make_tuple())); EXPECT_NE(&n, &ret.Perform(std::make_tuple()));
EXPECT_EQ(42, ret.Perform(make_tuple())); EXPECT_EQ(42, ret.Perform(std::make_tuple()));
} }
// Tests that ReturnRefOfCopy(v) is covariant. // Tests that ReturnRefOfCopy(v) is covariant.
...@@ -682,10 +691,10 @@ TEST(ReturnRefOfCopyTest, IsCovariant) { ...@@ -682,10 +691,10 @@ TEST(ReturnRefOfCopyTest, IsCovariant) {
Base base; Base base;
Derived derived; Derived derived;
Action<Base&()> a = ReturnRefOfCopy(base); Action<Base&()> a = ReturnRefOfCopy(base);
EXPECT_NE(&base, &a.Perform(make_tuple())); EXPECT_NE(&base, &a.Perform(std::make_tuple()));
a = ReturnRefOfCopy(derived); 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. // Tests that DoDefault() does the default action for the mock method.
...@@ -700,6 +709,9 @@ class MockClass { ...@@ -700,6 +709,9 @@ class MockClass {
MOCK_METHOD0(MakeUnique, std::unique_ptr<int>()); MOCK_METHOD0(MakeUnique, std::unique_ptr<int>());
MOCK_METHOD0(MakeUniqueBase, std::unique_ptr<Base>()); MOCK_METHOD0(MakeUniqueBase, std::unique_ptr<Base>());
MOCK_METHOD0(MakeVectorUnique, std::vector<std::unique_ptr<int>>()); 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 #endif
private: private:
...@@ -788,14 +800,14 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) { ...@@ -788,14 +800,14 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) {
int n = 0; int n = 0;
char ch = '\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(2, n);
EXPECT_EQ('\0', ch); EXPECT_EQ('\0', ch);
a = SetArgPointee<2>('a'); a = SetArgPointee<2>('a');
n = 0; n = 0;
ch = '\0'; ch = '\0';
a.Perform(make_tuple(true, &n, &ch)); a.Perform(std::make_tuple(true, &n, &ch));
EXPECT_EQ(0, n); EXPECT_EQ(0, n);
EXPECT_EQ('a', ch); EXPECT_EQ('a', ch);
} }
...@@ -807,14 +819,14 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) { ...@@ -807,14 +819,14 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) {
typedef void MyFunction(std::string*, const char**); typedef void MyFunction(std::string*, const char**);
Action<MyFunction> a = SetArgPointee<0>("hi"); Action<MyFunction> a = SetArgPointee<0>("hi");
std::string str; std::string str;
const char* ptr = NULL; const char* ptr = nullptr;
a.Perform(make_tuple(&str, &ptr)); a.Perform(std::make_tuple(&str, &ptr));
EXPECT_EQ("hi", str); EXPECT_EQ("hi", str);
EXPECT_TRUE(ptr == NULL); EXPECT_TRUE(ptr == nullptr);
a = SetArgPointee<1>("world"); a = SetArgPointee<1>("world");
str = ""; str = "";
a.Perform(make_tuple(&str, &ptr)); a.Perform(std::make_tuple(&str, &ptr));
EXPECT_EQ("", str); EXPECT_EQ("", str);
EXPECT_STREQ("world", ptr); EXPECT_STREQ("world", ptr);
} }
...@@ -822,8 +834,8 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) { ...@@ -822,8 +834,8 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) {
TEST(SetArgPointeeTest, AcceptsWideStringLiteral) { TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
typedef void MyFunction(const wchar_t**); typedef void MyFunction(const wchar_t**);
Action<MyFunction> a = SetArgPointee<0>(L"world"); Action<MyFunction> a = SetArgPointee<0>(L"world");
const wchar_t* ptr = NULL; const wchar_t* ptr = nullptr;
a.Perform(make_tuple(&ptr)); a.Perform(std::make_tuple(&ptr));
EXPECT_STREQ(L"world", ptr); EXPECT_STREQ(L"world", ptr);
# if GTEST_HAS_STD_WSTRING # if GTEST_HAS_STD_WSTRING
...@@ -831,7 +843,7 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) { ...@@ -831,7 +843,7 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
typedef void MyStringFunction(std::wstring*); typedef void MyStringFunction(std::wstring*);
Action<MyStringFunction> a2 = SetArgPointee<0>(L"world"); Action<MyStringFunction> a2 = SetArgPointee<0>(L"world");
std::wstring str = L""; std::wstring str = L"";
a2.Perform(make_tuple(&str)); a2.Perform(std::make_tuple(&str));
EXPECT_EQ(L"world", str); EXPECT_EQ(L"world", str);
# endif # endif
...@@ -844,16 +856,16 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) { ...@@ -844,16 +856,16 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) {
const char* const hi = "hi"; const char* const hi = "hi";
Action<MyFunction> a = SetArgPointee<1>(hi); Action<MyFunction> a = SetArgPointee<1>(hi);
std::string str; std::string str;
const char* ptr = NULL; const char* ptr = nullptr;
a.Perform(make_tuple(true, &str, &ptr)); a.Perform(std::make_tuple(true, &str, &ptr));
EXPECT_EQ("hi", str); EXPECT_EQ("hi", str);
EXPECT_TRUE(ptr == NULL); EXPECT_TRUE(ptr == nullptr);
char world_array[] = "world"; char world_array[] = "world";
char* const world = world_array; char* const world = world_array;
a = SetArgPointee<2>(world); a = SetArgPointee<2>(world);
str = ""; str = "";
a.Perform(make_tuple(true, &str, &ptr)); a.Perform(std::make_tuple(true, &str, &ptr));
EXPECT_EQ("", str); EXPECT_EQ("", str);
EXPECT_EQ(world, ptr); EXPECT_EQ(world, ptr);
} }
...@@ -862,8 +874,8 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) { ...@@ -862,8 +874,8 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
typedef void MyFunction(bool, const wchar_t**); typedef void MyFunction(bool, const wchar_t**);
const wchar_t* const hi = L"hi"; const wchar_t* const hi = L"hi";
Action<MyFunction> a = SetArgPointee<1>(hi); Action<MyFunction> a = SetArgPointee<1>(hi);
const wchar_t* ptr = NULL; const wchar_t* ptr = nullptr;
a.Perform(make_tuple(true, &ptr)); a.Perform(std::make_tuple(true, &ptr));
EXPECT_EQ(hi, ptr); EXPECT_EQ(hi, ptr);
# if GTEST_HAS_STD_WSTRING # if GTEST_HAS_STD_WSTRING
...@@ -873,110 +885,11 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) { ...@@ -873,110 +885,11 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
wchar_t* const world = world_array; wchar_t* const world = world_array;
Action<MyStringFunction> a2 = SetArgPointee<1>(world); Action<MyStringFunction> a2 = SetArgPointee<1>(world);
std::wstring str; std::wstring str;
a2.Perform(make_tuple(true, &str)); a2.Perform(std::make_tuple(true, &str));
EXPECT_EQ(world_array, str); EXPECT_EQ(world_array, str);
# endif # 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 // Tests that SetArgumentPointee<N>(v) sets the variable pointed to by
// the N-th (0-based) argument to v. // the N-th (0-based) argument to v.
TEST(SetArgumentPointeeTest, SetsTheNthPointee) { TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
...@@ -985,117 +898,18 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) { ...@@ -985,117 +898,18 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
int n = 0; int n = 0;
char ch = '\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(2, n);
EXPECT_EQ('\0', ch); EXPECT_EQ('\0', ch);
a = SetArgumentPointee<2>('a'); a = SetArgumentPointee<2>('a');
n = 0; n = 0;
ch = '\0'; ch = '\0';
a.Perform(make_tuple(true, &n, &ch)); a.Perform(std::make_tuple(true, &n, &ch));
EXPECT_EQ(0, n); EXPECT_EQ(0, n);
EXPECT_EQ('a', ch); 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. // Sample functions and functors for testing Invoke() and etc.
int Nullary() { return 1; } int Nullary() { return 1; }
...@@ -1126,16 +940,16 @@ class Foo { ...@@ -1126,16 +940,16 @@ class Foo {
TEST(InvokeWithoutArgsTest, Function) { TEST(InvokeWithoutArgsTest, Function) {
// As an action that takes one argument. // As an action that takes one argument.
Action<int(int)> a = InvokeWithoutArgs(Nullary); // NOLINT 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. // As an action that takes two arguments.
Action<int(int, double)> a2 = InvokeWithoutArgs(Nullary); // NOLINT 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. // As an action that returns void.
Action<void(int)> a3 = InvokeWithoutArgs(VoidNullary); // NOLINT Action<void(int)> a3 = InvokeWithoutArgs(VoidNullary); // NOLINT
g_done = false; g_done = false;
a3.Perform(make_tuple(1)); a3.Perform(std::make_tuple(1));
EXPECT_TRUE(g_done); EXPECT_TRUE(g_done);
} }
...@@ -1143,17 +957,17 @@ TEST(InvokeWithoutArgsTest, Function) { ...@@ -1143,17 +957,17 @@ TEST(InvokeWithoutArgsTest, Function) {
TEST(InvokeWithoutArgsTest, Functor) { TEST(InvokeWithoutArgsTest, Functor) {
// As an action that takes no argument. // As an action that takes no argument.
Action<int()> a = InvokeWithoutArgs(NullaryFunctor()); // NOLINT 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. // As an action that takes three arguments.
Action<int(int, double, char)> a2 = // NOLINT Action<int(int, double, char)> a2 = // NOLINT
InvokeWithoutArgs(NullaryFunctor()); 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. // As an action that returns void.
Action<void()> a3 = InvokeWithoutArgs(VoidNullaryFunctor()); Action<void()> a3 = InvokeWithoutArgs(VoidNullaryFunctor());
g_done = false; g_done = false;
a3.Perform(make_tuple()); a3.Perform(std::make_tuple());
EXPECT_TRUE(g_done); EXPECT_TRUE(g_done);
} }
...@@ -1162,13 +976,13 @@ TEST(InvokeWithoutArgsTest, Method) { ...@@ -1162,13 +976,13 @@ TEST(InvokeWithoutArgsTest, Method) {
Foo foo; Foo foo;
Action<int(bool, char)> a = // NOLINT Action<int(bool, char)> a = // NOLINT
InvokeWithoutArgs(&foo, &Foo::Nullary); 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. // Tests using IgnoreResult() on a polymorphic action.
TEST(IgnoreResultTest, PolymorphicAction) { TEST(IgnoreResultTest, PolymorphicAction) {
Action<void(int)> a = IgnoreResult(Return(5)); // NOLINT 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. // Tests using IgnoreResult() on a monomorphic action.
...@@ -1181,7 +995,7 @@ int ReturnOne() { ...@@ -1181,7 +995,7 @@ int ReturnOne() {
TEST(IgnoreResultTest, MonomorphicAction) { TEST(IgnoreResultTest, MonomorphicAction) {
g_done = false; g_done = false;
Action<void()> a = IgnoreResult(Invoke(ReturnOne)); Action<void()> a = IgnoreResult(Invoke(ReturnOne));
a.Perform(make_tuple()); a.Perform(std::make_tuple());
EXPECT_TRUE(g_done); EXPECT_TRUE(g_done);
} }
...@@ -1196,28 +1010,28 @@ TEST(IgnoreResultTest, ActionReturningClass) { ...@@ -1196,28 +1010,28 @@ TEST(IgnoreResultTest, ActionReturningClass) {
g_done = false; g_done = false;
Action<void(int)> a = Action<void(int)> a =
IgnoreResult(Invoke(ReturnMyNonDefaultConstructible)); // NOLINT IgnoreResult(Invoke(ReturnMyNonDefaultConstructible)); // NOLINT
a.Perform(make_tuple(2)); a.Perform(std::make_tuple(2));
EXPECT_TRUE(g_done); EXPECT_TRUE(g_done);
} }
TEST(AssignTest, Int) { TEST(AssignTest, Int) {
int x = 0; int x = 0;
Action<void(int)> a = Assign(&x, 5); Action<void(int)> a = Assign(&x, 5);
a.Perform(make_tuple(0)); a.Perform(std::make_tuple(0));
EXPECT_EQ(5, x); EXPECT_EQ(5, x);
} }
TEST(AssignTest, String) { TEST(AssignTest, String) {
::std::string x; ::std::string x;
Action<void(void)> a = Assign(&x, "Hello, world"); Action<void(void)> a = Assign(&x, "Hello, world");
a.Perform(make_tuple()); a.Perform(std::make_tuple());
EXPECT_EQ("Hello, world", x); EXPECT_EQ("Hello, world", x);
} }
TEST(AssignTest, CompatibleTypes) { TEST(AssignTest, CompatibleTypes) {
double x = 0; double x = 0;
Action<void(int)> a = Assign(&x, 5); Action<void(int)> a = Assign(&x, 5);
a.Perform(make_tuple(0)); a.Perform(std::make_tuple(0));
EXPECT_DOUBLE_EQ(5, x); EXPECT_DOUBLE_EQ(5, x);
} }
...@@ -1231,20 +1045,20 @@ class SetErrnoAndReturnTest : public testing::Test { ...@@ -1231,20 +1045,20 @@ class SetErrnoAndReturnTest : public testing::Test {
TEST_F(SetErrnoAndReturnTest, Int) { TEST_F(SetErrnoAndReturnTest, Int) {
Action<int(void)> a = SetErrnoAndReturn(ENOTTY, -5); 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); EXPECT_EQ(ENOTTY, errno);
} }
TEST_F(SetErrnoAndReturnTest, Ptr) { TEST_F(SetErrnoAndReturnTest, Ptr) {
int x; int x;
Action<int*(void)> a = SetErrnoAndReturn(ENOTTY, &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); EXPECT_EQ(ENOTTY, errno);
} }
TEST_F(SetErrnoAndReturnTest, CompatibleTypes) { TEST_F(SetErrnoAndReturnTest, CompatibleTypes) {
Action<double()> a = SetErrnoAndReturn(EINVAL, 5); 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); EXPECT_EQ(EINVAL, errno);
} }
...@@ -1406,6 +1220,153 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { ...@@ -1406,6 +1220,153 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) {
EXPECT_EQ(7, *vresult[0]); 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_ #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 } // Unnamed namespace
#ifdef _MSC_VER
#if _MSC_VER == 1900
# pragma warning(pop)
#endif
#endif
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -391,7 +390,7 @@ TEST(ExactlyTest, HasCorrectBounds) { ...@@ -391,7 +390,7 @@ TEST(ExactlyTest, HasCorrectBounds) {
EXPECT_EQ(3, c.ConservativeUpperBound()); 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(). // CardinalityInterface and calling MakeCardinality().
class EvenCardinality : public CardinalityInterface { class EvenCardinality : public CardinalityInterface {
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -46,10 +45,6 @@ namespace gmock_generated_actions_test { ...@@ -46,10 +45,6 @@ namespace gmock_generated_actions_test {
using ::std::plus; using ::std::plus;
using ::std::string; using ::std::string;
using testing::get;
using testing::make_tuple;
using testing::tuple;
using testing::tuple_element;
using testing::_; using testing::_;
using testing::Action; using testing::Action;
using testing::ActionInterface; using testing::ActionInterface;
...@@ -81,12 +76,12 @@ bool Unary(int x) { return x < 0; } ...@@ -81,12 +76,12 @@ bool Unary(int x) { return x < 0; }
const char* Plus1(const char* s) { return s + 1; } 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; const double g_double = 0;
bool ReferencesGlobalDouble(const double& x) { return &x == &g_double; } 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 { struct UnaryFunctor {
int operator()(bool x) { return x ? 1 : -1; } int operator()(bool x) { return x ? 1 : -1; }
...@@ -102,9 +97,9 @@ void VoidTernary(int, char, bool) { g_done = true; } ...@@ -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; } 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, std::string Concat4(const char* s1, const char* s2, const char* s3,
const char* s4) { const char* s4) {
return string(s1) + s2 + s3 + 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; } int SumOf5(int a, int b, int c, int d, int e) { return a + b + c + d + e; }
...@@ -115,9 +110,9 @@ struct SumOf5Functor { ...@@ -115,9 +110,9 @@ struct SumOf5Functor {
} }
}; };
string Concat5(const char* s1, const char* s2, const char* s3, std::string Concat5(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5) { const char* s4, const char* s5) {
return string(s1) + s2 + s3 + s4 + s5; return std::string(s1) + s2 + s3 + s4 + s5;
} }
int SumOf6(int a, int b, int c, int d, int e, int f) { int SumOf6(int a, int b, int c, int d, int e, int f) {
...@@ -130,34 +125,34 @@ struct SumOf6Functor { ...@@ -130,34 +125,34 @@ struct SumOf6Functor {
} }
}; };
string Concat6(const char* s1, const char* s2, const char* s3, std::string Concat6(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6) { const char* s4, const char* s5, const char* s6) {
return string(s1) + s2 + s3 + s4 + s5 + s6; return std::string(s1) + s2 + s3 + s4 + s5 + s6;
} }
string Concat7(const char* s1, const char* s2, const char* s3, std::string Concat7(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6, const char* s4, const char* s5, const char* s6,
const char* s7) { const char* s7) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7; return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7;
} }
string Concat8(const char* s1, const char* s2, const char* s3, std::string Concat8(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6, const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8) { const char* s7, const char* s8) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8; return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8;
} }
string Concat9(const char* s1, const char* s2, const char* s3, std::string Concat9(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6, const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9) { const char* s7, const char* s8, const char* s9) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9; return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9;
} }
string Concat10(const char* s1, const char* s2, const char* s3, std::string Concat10(const char* s1, const char* s2, const char* s3,
const char* s4, const char* s5, const char* s6, const char* s4, const char* s5, const char* s6,
const char* s7, const char* s8, const char* s9, const char* s7, const char* s8, const char* s9,
const char* s10) { const char* s10) {
return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + 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 // 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; } ...@@ -169,85 +164,84 @@ inline const char* CharPtr(const char* s) { return s; }
// Tests using InvokeArgument with a nullary function. // Tests using InvokeArgument with a nullary function.
TEST(InvokeArgumentTest, Function0) { TEST(InvokeArgumentTest, Function0) {
Action<int(int, int(*)())> a = InvokeArgument<1>(); // NOLINT 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. // Tests using InvokeArgument with a unary function.
TEST(InvokeArgumentTest, Functor1) { TEST(InvokeArgumentTest, Functor1) {
Action<int(UnaryFunctor)> a = InvokeArgument<0>(true); // NOLINT 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. // Tests using InvokeArgument with a 5-ary function.
TEST(InvokeArgumentTest, Function5) { TEST(InvokeArgumentTest, Function5) {
Action<int(int(*)(int, int, int, int, int))> a = // NOLINT Action<int(int(*)(int, int, int, int, int))> a = // NOLINT
InvokeArgument<0>(10000, 2000, 300, 40, 5); 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. // Tests using InvokeArgument with a 5-ary functor.
TEST(InvokeArgumentTest, Functor5) { TEST(InvokeArgumentTest, Functor5) {
Action<int(SumOf5Functor)> a = // NOLINT Action<int(SumOf5Functor)> a = // NOLINT
InvokeArgument<0>(10000, 2000, 300, 40, 5); 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. // Tests using InvokeArgument with a 6-ary function.
TEST(InvokeArgumentTest, Function6) { TEST(InvokeArgumentTest, Function6) {
Action<int(int(*)(int, int, int, int, int, int))> a = // NOLINT Action<int(int(*)(int, int, int, int, int, int))> a = // NOLINT
InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6); 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. // Tests using InvokeArgument with a 6-ary functor.
TEST(InvokeArgumentTest, Functor6) { TEST(InvokeArgumentTest, Functor6) {
Action<int(SumOf6Functor)> a = // NOLINT Action<int(SumOf6Functor)> a = // NOLINT
InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6); 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. // Tests using InvokeArgument with a 7-ary function.
TEST(InvokeArgumentTest, Function7) { TEST(InvokeArgumentTest, Function7) {
Action<string(string(*)(const char*, const char*, const char*, 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 = const char*))>
InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7"); a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7");
EXPECT_EQ("1234567", a.Perform(make_tuple(&Concat7))); EXPECT_EQ("1234567", a.Perform(std::make_tuple(&Concat7)));
} }
// Tests using InvokeArgument with a 8-ary function. // Tests using InvokeArgument with a 8-ary function.
TEST(InvokeArgumentTest, Function8) { TEST(InvokeArgumentTest, Function8) {
Action<string(string(*)(const char*, const char*, const char*, 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*, const char*))> a = const char*, const char*))>
InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8"); a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8");
EXPECT_EQ("12345678", a.Perform(make_tuple(&Concat8))); EXPECT_EQ("12345678", a.Perform(std::make_tuple(&Concat8)));
} }
// Tests using InvokeArgument with a 9-ary function. // Tests using InvokeArgument with a 9-ary function.
TEST(InvokeArgumentTest, Function9) { TEST(InvokeArgumentTest, Function9) {
Action<string(string(*)(const char*, const char*, const char*, 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*, const char*, const char*))> a = const char*, const char*, const char*))>
InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9"); a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9");
EXPECT_EQ("123456789", a.Perform(make_tuple(&Concat9))); EXPECT_EQ("123456789", a.Perform(std::make_tuple(&Concat9)));
} }
// Tests using InvokeArgument with a 10-ary function. // Tests using InvokeArgument with a 10-ary function.
TEST(InvokeArgumentTest, Function10) { TEST(InvokeArgumentTest, Function10) {
Action<string(string(*)(const char*, const char*, const char*, 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*, const char*, const char*, const char*, const char*, const char*, const char*))>
const char*))> a = a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"); EXPECT_EQ("1234567890", a.Perform(std::make_tuple(&Concat10)));
EXPECT_EQ("1234567890", a.Perform(make_tuple(&Concat10)));
} }
// Tests using InvokeArgument with a function that takes a pointer argument. // Tests using InvokeArgument with a function that takes a pointer argument.
TEST(InvokeArgumentTest, ByPointerFunction) { TEST(InvokeArgumentTest, ByPointerFunction) {
Action<const char*(const char*(*)(const char* input, short n))> a = // NOLINT Action<const char*(const char*(*)(const char* input, short n))> a = // NOLINT
InvokeArgument<0>(static_cast<const char*>("Hi"), Short(1)); 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* // Tests using InvokeArgument with a function that takes a const char*
...@@ -255,17 +249,17 @@ TEST(InvokeArgumentTest, ByPointerFunction) { ...@@ -255,17 +249,17 @@ TEST(InvokeArgumentTest, ByPointerFunction) {
TEST(InvokeArgumentTest, FunctionWithCStringLiteral) { TEST(InvokeArgumentTest, FunctionWithCStringLiteral) {
Action<const char*(const char*(*)(const char* input, short n))> a = // NOLINT Action<const char*(const char*(*)(const char* input, short n))> a = // NOLINT
InvokeArgument<0>("Hi", Short(1)); 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. // Tests using InvokeArgument with a function that takes a const reference.
TEST(InvokeArgumentTest, ByConstReferenceFunction) { TEST(InvokeArgumentTest, ByConstReferenceFunction) {
Action<bool(bool(*function)(const string& s))> a = // NOLINT Action<bool(bool (*function)(const std::string& s))> a = // NOLINT
InvokeArgument<0>(string("Hi")); InvokeArgument<0>(std::string("Hi"));
// When action 'a' is constructed, it makes a copy of the temporary // 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 // string object passed to it, so it's OK to use 'a' later, when the
// temporary object has already died. // 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 // Tests using InvokeArgument with ByRef() and a function that takes a
...@@ -274,18 +268,18 @@ TEST(InvokeArgumentTest, ByExplicitConstReferenceFunction) { ...@@ -274,18 +268,18 @@ TEST(InvokeArgumentTest, ByExplicitConstReferenceFunction) {
Action<bool(bool(*)(const double& x))> a = // NOLINT Action<bool(bool(*)(const double& x))> a = // NOLINT
InvokeArgument<0>(ByRef(g_double)); InvokeArgument<0>(ByRef(g_double));
// The above line calls ByRef() on a const value. // 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; double x = 0;
a = InvokeArgument<0>(ByRef(x)); // This calls ByRef() on a non-const. 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. // Tests using WithArgs and with an action that takes 1 argument.
TEST(WithArgsTest, OneArg) { TEST(WithArgsTest, OneArg) {
Action<bool(double x, int n)> a = WithArgs<1>(Invoke(Unary)); // NOLINT Action<bool(double x, int n)> a = WithArgs<1>(Invoke(Unary)); // NOLINT
EXPECT_TRUE(a.Perform(make_tuple(1.5, -1))); EXPECT_TRUE(a.Perform(std::make_tuple(1.5, -1)));
EXPECT_FALSE(a.Perform(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. // Tests using WithArgs with an action that takes 2 arguments.
...@@ -293,105 +287,105 @@ TEST(WithArgsTest, TwoArgs) { ...@@ -293,105 +287,105 @@ TEST(WithArgsTest, TwoArgs) {
Action<const char*(const char* s, double x, short n)> a = Action<const char*(const char* s, double x, short n)> a =
WithArgs<0, 2>(Invoke(Binary)); WithArgs<0, 2>(Invoke(Binary));
const char s[] = "Hello"; 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. // Tests using WithArgs with an action that takes 3 arguments.
TEST(WithArgsTest, ThreeArgs) { TEST(WithArgsTest, ThreeArgs) {
Action<int(int, double, char, short)> a = // NOLINT Action<int(int, double, char, short)> a = // NOLINT
WithArgs<0, 2, 3>(Invoke(Ternary)); 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. // Tests using WithArgs with an action that takes 4 arguments.
TEST(WithArgsTest, FourArgs) { TEST(WithArgsTest, FourArgs) {
Action<string(const char*, const char*, double, const char*, const char*)> a = Action<std::string(const char*, const char*, double, const char*,
WithArgs<4, 3, 1, 0>(Invoke(Concat4)); const char*)>
EXPECT_EQ("4310", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), 2.5, a = WithArgs<4, 3, 1, 0>(Invoke(Concat4));
CharPtr("3"), CharPtr("4")))); 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. // Tests using WithArgs with an action that takes 5 arguments.
TEST(WithArgsTest, FiveArgs) { TEST(WithArgsTest, FiveArgs) {
Action<string(const char*, const char*, const char*, Action<std::string(const char*, const char*, const char*, const char*,
const char*, const char*)> a = const char*)>
WithArgs<4, 3, 2, 1, 0>(Invoke(Concat5)); a = WithArgs<4, 3, 2, 1, 0>(Invoke(Concat5));
EXPECT_EQ("43210", EXPECT_EQ("43210",
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"),
CharPtr("3"), CharPtr("4")))); CharPtr("3"), CharPtr("4"))));
} }
// Tests using WithArgs with an action that takes 6 arguments. // Tests using WithArgs with an action that takes 6 arguments.
TEST(WithArgsTest, SixArgs) { 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)); WithArgs<0, 1, 2, 2, 1, 0>(Invoke(Concat6));
EXPECT_EQ("012210", EXPECT_EQ("012210", a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"),
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2")))); CharPtr("2"))));
} }
// Tests using WithArgs with an action that takes 7 arguments. // Tests using WithArgs with an action that takes 7 arguments.
TEST(WithArgsTest, SevenArgs) { 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)); WithArgs<0, 1, 2, 3, 2, 1, 0>(Invoke(Concat7));
EXPECT_EQ("0123210", EXPECT_EQ("0123210", a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"),
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), CharPtr("2"), CharPtr("3"))));
CharPtr("3"))));
} }
// Tests using WithArgs with an action that takes 8 arguments. // Tests using WithArgs with an action that takes 8 arguments.
TEST(WithArgsTest, EightArgs) { 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)); WithArgs<0, 1, 2, 3, 0, 1, 2, 3>(Invoke(Concat8));
EXPECT_EQ("01230123", EXPECT_EQ("01230123", a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"),
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), CharPtr("2"), CharPtr("3"))));
CharPtr("3"))));
} }
// Tests using WithArgs with an action that takes 9 arguments. // Tests using WithArgs with an action that takes 9 arguments.
TEST(WithArgsTest, NineArgs) { 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)); WithArgs<0, 1, 2, 3, 1, 2, 3, 2, 3>(Invoke(Concat9));
EXPECT_EQ("012312323", EXPECT_EQ("012312323",
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"),
CharPtr("3")))); CharPtr("3"))));
} }
// Tests using WithArgs with an action that takes 10 arguments. // Tests using WithArgs with an action that takes 10 arguments.
TEST(WithArgsTest, TenArgs) { 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)); WithArgs<0, 1, 2, 3, 2, 1, 0, 1, 2, 3>(Invoke(Concat10));
EXPECT_EQ("0123210123", EXPECT_EQ("0123210123",
a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"),
CharPtr("3")))); CharPtr("3"))));
} }
// Tests using WithArgs with an action that is not Invoke(). // Tests using WithArgs with an action that is not Invoke().
class SubstractAction : public ActionInterface<int(int, int)> { // NOLINT class SubstractAction : public ActionInterface<int(int, int)> { // NOLINT
public: public:
virtual int Perform(const tuple<int, int>& args) { virtual int Perform(const std::tuple<int, int>& args) {
return get<0>(args) - get<1>(args); return std::get<0>(args) - std::get<1>(args);
} }
}; };
TEST(WithArgsTest, NonInvokeAction) { 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)); WithArgs<2, 1>(MakeAction(new SubstractAction));
string s("hello"); std::tuple<std::string, int, int> dummy =
EXPECT_EQ(8, a.Perform(tuple<const string&, int, int>(s, 2, 10))); 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. // Tests using WithArgs to pass all original arguments in the original order.
TEST(WithArgsTest, Identity) { TEST(WithArgsTest, Identity) {
Action<int(int x, char y, short z)> a = // NOLINT Action<int(int x, char y, short z)> a = // NOLINT
WithArgs<0, 1, 2>(Invoke(Ternary)); 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. // Tests using WithArgs with repeated arguments.
TEST(WithArgsTest, RepeatedArguments) { TEST(WithArgsTest, RepeatedArguments) {
Action<int(bool, int m, int n)> a = // NOLINT Action<int(bool, int m, int n)> a = // NOLINT
WithArgs<1, 1, 1, 1>(Invoke(SumOf4)); 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. // Tests using WithArgs with reversed argument order.
...@@ -399,21 +393,22 @@ TEST(WithArgsTest, ReversedArgumentOrder) { ...@@ -399,21 +393,22 @@ TEST(WithArgsTest, ReversedArgumentOrder) {
Action<const char*(short n, const char* input)> a = // NOLINT Action<const char*(short n, const char* input)> a = // NOLINT
WithArgs<1, 0>(Invoke(Binary)); WithArgs<1, 0>(Invoke(Binary));
const char s[] = "Hello"; 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. // Tests using WithArgs with compatible, but not identical, argument types.
TEST(WithArgsTest, ArgsOfCompatibleTypes) { TEST(WithArgsTest, ArgsOfCompatibleTypes) {
Action<long(short x, char y, double z, char c)> a = // NOLINT Action<long(short x, char y, double z, char c)> a = // NOLINT
WithArgs<0, 1, 3>(Invoke(Ternary)); 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. // Tests using WithArgs with an action that returns void.
TEST(WithArgsTest, VoidAction) { TEST(WithArgsTest, VoidAction) {
Action<void(double x, char c, int n)> a = WithArgs<2, 1>(Invoke(VoidBinary)); Action<void(double x, char c, int n)> a = WithArgs<2, 1>(Invoke(VoidBinary));
g_done = false; g_done = false;
a.Perform(make_tuple(1.5, 'a', 3)); a.Perform(std::make_tuple(1.5, 'a', 3));
EXPECT_TRUE(g_done); EXPECT_TRUE(g_done);
} }
...@@ -422,7 +417,7 @@ TEST(DoAllTest, TwoActions) { ...@@ -422,7 +417,7 @@ TEST(DoAllTest, TwoActions) {
int n = 0; int n = 0;
Action<int(int*)> a = DoAll(SetArgPointee<0>(1), // NOLINT Action<int(int*)> a = DoAll(SetArgPointee<0>(1), // NOLINT
Return(2)); Return(2));
EXPECT_EQ(2, a.Perform(make_tuple(&n))); EXPECT_EQ(2, a.Perform(std::make_tuple(&n)));
EXPECT_EQ(1, n); EXPECT_EQ(1, n);
} }
...@@ -432,7 +427,7 @@ TEST(DoAllTest, ThreeActions) { ...@@ -432,7 +427,7 @@ TEST(DoAllTest, ThreeActions) {
Action<int(int*, int*)> a = DoAll(SetArgPointee<0>(1), // NOLINT Action<int(int*, int*)> a = DoAll(SetArgPointee<0>(1), // NOLINT
SetArgPointee<1>(2), SetArgPointee<1>(2),
Return(3)); 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(1, m);
EXPECT_EQ(2, n); EXPECT_EQ(2, n);
} }
...@@ -446,7 +441,7 @@ TEST(DoAllTest, FourActions) { ...@@ -446,7 +441,7 @@ TEST(DoAllTest, FourActions) {
SetArgPointee<1>(2), SetArgPointee<1>(2),
SetArgPointee<2>('a'), SetArgPointee<2>('a'),
Return(3)); 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(1, m);
EXPECT_EQ(2, n); EXPECT_EQ(2, n);
EXPECT_EQ('a', ch); EXPECT_EQ('a', ch);
...@@ -462,7 +457,7 @@ TEST(DoAllTest, FiveActions) { ...@@ -462,7 +457,7 @@ TEST(DoAllTest, FiveActions) {
SetArgPointee<2>('a'), SetArgPointee<2>('a'),
SetArgPointee<3>('b'), SetArgPointee<3>('b'),
Return(3)); 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(1, m);
EXPECT_EQ(2, n); EXPECT_EQ(2, n);
EXPECT_EQ('a', a); EXPECT_EQ('a', a);
...@@ -480,7 +475,7 @@ TEST(DoAllTest, SixActions) { ...@@ -480,7 +475,7 @@ TEST(DoAllTest, SixActions) {
SetArgPointee<3>('b'), SetArgPointee<3>('b'),
SetArgPointee<4>('c'), SetArgPointee<4>('c'),
Return(3)); 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(1, m);
EXPECT_EQ(2, n); EXPECT_EQ(2, n);
EXPECT_EQ('a', a); EXPECT_EQ('a', a);
...@@ -500,7 +495,7 @@ TEST(DoAllTest, SevenActions) { ...@@ -500,7 +495,7 @@ TEST(DoAllTest, SevenActions) {
SetArgPointee<4>('c'), SetArgPointee<4>('c'),
SetArgPointee<5>('d'), SetArgPointee<5>('d'),
Return(3)); 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(1, m);
EXPECT_EQ(2, n); EXPECT_EQ(2, n);
EXPECT_EQ('a', a); EXPECT_EQ('a', a);
...@@ -523,7 +518,7 @@ TEST(DoAllTest, EightActions) { ...@@ -523,7 +518,7 @@ TEST(DoAllTest, EightActions) {
SetArgPointee<5>('d'), SetArgPointee<5>('d'),
SetArgPointee<6>('e'), SetArgPointee<6>('e'),
Return(3)); 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(1, m);
EXPECT_EQ(2, n); EXPECT_EQ(2, n);
EXPECT_EQ('a', a); EXPECT_EQ('a', a);
...@@ -548,7 +543,7 @@ TEST(DoAllTest, NineActions) { ...@@ -548,7 +543,7 @@ TEST(DoAllTest, NineActions) {
SetArgPointee<6>('e'), SetArgPointee<6>('e'),
SetArgPointee<7>('f'), SetArgPointee<7>('f'),
Return(3)); 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(1, m);
EXPECT_EQ(2, n); EXPECT_EQ(2, n);
EXPECT_EQ('a', a); EXPECT_EQ('a', a);
...@@ -576,7 +571,8 @@ TEST(DoAllTest, TenActions) { ...@@ -576,7 +571,8 @@ TEST(DoAllTest, TenActions) {
SetArgPointee<7>('f'), SetArgPointee<7>('f'),
SetArgPointee<8>('g'), SetArgPointee<8>('g'),
Return(3)); 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(1, m);
EXPECT_EQ(2, n); EXPECT_EQ(2, n);
EXPECT_EQ('a', a); EXPECT_EQ('a', a);
...@@ -606,10 +602,10 @@ ACTION(Return5) { return 5; } ...@@ -606,10 +602,10 @@ ACTION(Return5) { return 5; }
TEST(ActionMacroTest, WorksWhenNotReferencingArguments) { TEST(ActionMacroTest, WorksWhenNotReferencingArguments) {
Action<double()> a1 = Return5(); 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(); 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. // Tests that ACTION() can define an action that returns void.
...@@ -618,7 +614,7 @@ ACTION(IncrementArg1) { (*arg1)++; } ...@@ -618,7 +614,7 @@ ACTION(IncrementArg1) { (*arg1)++; }
TEST(ActionMacroTest, WorksWhenReturningVoid) { TEST(ActionMacroTest, WorksWhenReturningVoid) {
Action<void(int, int*)> a1 = IncrementArg1(); Action<void(int, int*)> a1 = IncrementArg1();
int n = 0; int n = 0;
a1.Perform(make_tuple(5, &n)); a1.Perform(std::make_tuple(5, &n));
EXPECT_EQ(1, n); EXPECT_EQ(1, n);
} }
...@@ -633,22 +629,22 @@ ACTION(IncrementArg2) { ...@@ -633,22 +629,22 @@ ACTION(IncrementArg2) {
TEST(ActionMacroTest, CanReferenceArgumentType) { TEST(ActionMacroTest, CanReferenceArgumentType) {
Action<void(int, bool, int*)> a1 = IncrementArg2(); Action<void(int, bool, int*)> a1 = IncrementArg2();
int n = 0; int n = 0;
a1.Perform(make_tuple(5, false, &n)); a1.Perform(std::make_tuple(5, false, &n));
EXPECT_EQ(1, n); EXPECT_EQ(1, n);
} }
// Tests that the body of ACTION() can reference the argument tuple // Tests that the body of ACTION() can reference the argument tuple
// via args_type and args. // via args_type and args.
ACTION(Sum2) { ACTION(Sum2) {
StaticAssertTypeEq<tuple<int, char, int*>, args_type>(); StaticAssertTypeEq<std::tuple<int, char, int*>, args_type>();
args_type args_copy = args; 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) { TEST(ActionMacroTest, CanReferenceArgumentTuple) {
Action<int(int, char, int*)> a1 = Sum2(); Action<int(int, char, int*)> a1 = Sum2();
int dummy = 0; 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 // Tests that the body of ACTION() can reference the mock function
...@@ -663,8 +659,8 @@ ACTION(InvokeDummy) { ...@@ -663,8 +659,8 @@ ACTION(InvokeDummy) {
TEST(ActionMacroTest, CanReferenceMockFunctionType) { TEST(ActionMacroTest, CanReferenceMockFunctionType) {
Action<int(bool)> a1 = InvokeDummy(); Action<int(bool)> a1 = InvokeDummy();
EXPECT_EQ(1, a1.Perform(make_tuple(true))); EXPECT_EQ(1, a1.Perform(std::make_tuple(true)));
EXPECT_EQ(1, a1.Perform(make_tuple(false))); EXPECT_EQ(1, a1.Perform(std::make_tuple(false)));
} }
// Tests that the body of ACTION() can reference the mock function's // Tests that the body of ACTION() can reference the mock function's
...@@ -677,8 +673,8 @@ ACTION(InvokeDummy2) { ...@@ -677,8 +673,8 @@ ACTION(InvokeDummy2) {
TEST(ActionMacroTest, CanReferenceMockFunctionReturnType) { TEST(ActionMacroTest, CanReferenceMockFunctionReturnType) {
Action<int(bool)> a1 = InvokeDummy2(); Action<int(bool)> a1 = InvokeDummy2();
EXPECT_EQ(1, a1.Perform(make_tuple(true))); EXPECT_EQ(1, a1.Perform(std::make_tuple(true)));
EXPECT_EQ(1, a1.Perform(make_tuple(false))); EXPECT_EQ(1, a1.Perform(std::make_tuple(false)));
} }
// Tests that ACTION() works for arguments passed by const reference. // Tests that ACTION() works for arguments passed by const reference.
...@@ -690,7 +686,7 @@ ACTION(ReturnAddrOfConstBoolReferenceArg) { ...@@ -690,7 +686,7 @@ ACTION(ReturnAddrOfConstBoolReferenceArg) {
TEST(ActionMacroTest, WorksForConstReferenceArg) { TEST(ActionMacroTest, WorksForConstReferenceArg) {
Action<const bool*(int, const bool&)> a = ReturnAddrOfConstBoolReferenceArg(); Action<const bool*(int, const bool&)> a = ReturnAddrOfConstBoolReferenceArg();
const bool b = false; 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. // Tests that ACTION() works for arguments passed by non-const reference.
...@@ -702,7 +698,7 @@ ACTION(ReturnAddrOfIntReferenceArg) { ...@@ -702,7 +698,7 @@ ACTION(ReturnAddrOfIntReferenceArg) {
TEST(ActionMacroTest, WorksForNonConstReferenceArg) { TEST(ActionMacroTest, WorksForNonConstReferenceArg) {
Action<int*(int&, bool, int)> a = ReturnAddrOfIntReferenceArg(); Action<int*(int&, bool, int)> a = ReturnAddrOfIntReferenceArg();
int n = 0; 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. // Tests that ACTION() can be used in a namespace.
...@@ -712,7 +708,7 @@ ACTION(Sum) { return arg0 + arg1; } ...@@ -712,7 +708,7 @@ ACTION(Sum) { return arg0 + arg1; }
TEST(ActionMacroTest, WorksInNamespace) { TEST(ActionMacroTest, WorksInNamespace) {
Action<int(int, int)> a1 = action_test::Sum(); 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 // Tests that the same ACTION definition works for mock functions with
...@@ -721,11 +717,11 @@ ACTION(PlusTwo) { return arg0 + 2; } ...@@ -721,11 +717,11 @@ ACTION(PlusTwo) { return arg0 + 2; }
TEST(ActionMacroTest, WorksForDifferentArgumentNumbers) { TEST(ActionMacroTest, WorksForDifferentArgumentNumbers) {
Action<int(int)> a1 = PlusTwo(); 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(); Action<double(float, void*)> a2 = PlusTwo();
int dummy; int dummy;
EXPECT_DOUBLE_EQ(6, a2.Perform(make_tuple(4.0f, &dummy))); EXPECT_DOUBLE_EQ(6, a2.Perform(std::make_tuple(4.0f, &dummy)));
} }
// Tests that ACTION_P can define a parameterized action. // Tests that ACTION_P can define a parameterized action.
...@@ -733,7 +729,7 @@ ACTION_P(Plus, n) { return arg0 + n; } ...@@ -733,7 +729,7 @@ ACTION_P(Plus, n) { return arg0 + n; }
TEST(ActionPMacroTest, DefinesParameterizedAction) { TEST(ActionPMacroTest, DefinesParameterizedAction) {
Action<int(int m, bool t)> a1 = Plus(9); 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 // Tests that the body of ACTION_P can reference the argument types
...@@ -746,7 +742,7 @@ ACTION_P(TypedPlus, n) { ...@@ -746,7 +742,7 @@ ACTION_P(TypedPlus, n) {
TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) { TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
Action<int(char m, bool t)> a1 = TypedPlus(9); 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 // Tests that a parameterized action can be used in any mock function
...@@ -754,7 +750,8 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) { ...@@ -754,7 +750,8 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
TEST(ActionPMacroTest, WorksInCompatibleMockFunction) { TEST(ActionPMacroTest, WorksInCompatibleMockFunction) {
Action<std::string(const std::string& s)> a1 = Plus("tail"); Action<std::string(const std::string& s)> a1 = Plus("tail");
const std::string re = "re"; 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 // Tests that we can use ACTION*() to define actions overloaded on the
...@@ -774,16 +771,16 @@ TEST(ActionMacroTest, CanDefineOverloadedActions) { ...@@ -774,16 +771,16 @@ TEST(ActionMacroTest, CanDefineOverloadedActions) {
typedef Action<const char*(bool, const char*)> MyAction; typedef Action<const char*(bool, const char*)> MyAction;
const MyAction a1 = OverloadedAction(); const MyAction a1 = OverloadedAction();
EXPECT_STREQ("hello", a1.Perform(make_tuple(false, CharPtr("world")))); EXPECT_STREQ("hello", a1.Perform(std::make_tuple(false, CharPtr("world"))));
EXPECT_STREQ("world", a1.Perform(make_tuple(true, CharPtr("world")))); EXPECT_STREQ("world", a1.Perform(std::make_tuple(true, CharPtr("world"))));
const MyAction a2 = OverloadedAction("hi"); const MyAction a2 = OverloadedAction("hi");
EXPECT_STREQ("hi", a2.Perform(make_tuple(false, CharPtr("world")))); EXPECT_STREQ("hi", a2.Perform(std::make_tuple(false, CharPtr("world"))));
EXPECT_STREQ("world", a2.Perform(make_tuple(true, CharPtr("world")))); EXPECT_STREQ("world", a2.Perform(std::make_tuple(true, CharPtr("world"))));
const MyAction a3 = OverloadedAction("hi", "you"); const MyAction a3 = OverloadedAction("hi", "you");
EXPECT_STREQ("hi", a3.Perform(make_tuple(true, CharPtr("world")))); EXPECT_STREQ("hi", a3.Perform(std::make_tuple(true, CharPtr("world"))));
EXPECT_STREQ("you", a3.Perform(make_tuple(false, CharPtr("world")))); EXPECT_STREQ("you", a3.Perform(std::make_tuple(false, CharPtr("world"))));
} }
// Tests ACTION_Pn where n >= 3. // Tests ACTION_Pn where n >= 3.
...@@ -792,25 +789,26 @@ ACTION_P3(Plus, m, n, k) { return arg0 + m + n + k; } ...@@ -792,25 +789,26 @@ ACTION_P3(Plus, m, n, k) { return arg0 + m + n + k; }
TEST(ActionPnMacroTest, WorksFor3Parameters) { TEST(ActionPnMacroTest, WorksFor3Parameters) {
Action<double(int m, bool t)> a1 = Plus(100, 20, 3.4); 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", "-", ">"); Action<std::string(const std::string& s)> a2 = Plus("tail", "-", ">");
const std::string re = "re"; 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; } ACTION_P4(Plus, p0, p1, p2, p3) { return arg0 + p0 + p1 + p2 + p3; }
TEST(ActionPnMacroTest, WorksFor4Parameters) { TEST(ActionPnMacroTest, WorksFor4Parameters) {
Action<int(int)> a1 = Plus(1, 2, 3, 4); 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; } ACTION_P5(Plus, p0, p1, p2, p3, p4) { return arg0 + p0 + p1 + p2 + p3 + p4; }
TEST(ActionPnMacroTest, WorksFor5Parameters) { TEST(ActionPnMacroTest, WorksFor5Parameters) {
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5); 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) { ACTION_P6(Plus, p0, p1, p2, p3, p4, p5) {
...@@ -819,7 +817,7 @@ 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) { TEST(ActionPnMacroTest, WorksFor6Parameters) {
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6); 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) { ACTION_P7(Plus, p0, p1, p2, p3, p4, p5, p6) {
...@@ -828,7 +826,7 @@ 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) { TEST(ActionPnMacroTest, WorksFor7Parameters) {
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7); 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) { 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) { ...@@ -837,7 +835,8 @@ ACTION_P8(Plus, p0, p1, p2, p3, p4, p5, p6, p7) {
TEST(ActionPnMacroTest, WorksFor8Parameters) { TEST(ActionPnMacroTest, WorksFor8Parameters) {
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8); 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) { 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) { ...@@ -846,7 +845,8 @@ ACTION_P9(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8) {
TEST(ActionPnMacroTest, WorksFor9Parameters) { TEST(ActionPnMacroTest, WorksFor9Parameters) {
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8, 9); 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) { 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) { ...@@ -858,7 +858,7 @@ ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param) {
TEST(ActionPnMacroTest, WorksFor10Parameters) { TEST(ActionPnMacroTest, WorksFor10Parameters) {
Action<int(int)> a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 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, 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. // Tests that the action body can promote the parameter types.
...@@ -875,8 +875,8 @@ TEST(ActionPnMacroTest, SimpleTypePromotion) { ...@@ -875,8 +875,8 @@ TEST(ActionPnMacroTest, SimpleTypePromotion) {
PadArgument(std::string("foo"), 'r'); PadArgument(std::string("foo"), 'r');
Action<std::string(const char*)> promo = Action<std::string(const char*)> promo =
PadArgument("foo", static_cast<int>('r')); PadArgument("foo", static_cast<int>('r'));
EXPECT_EQ("foobar", no_promo.Perform(make_tuple(CharPtr("ba")))); EXPECT_EQ("foobar", no_promo.Perform(std::make_tuple(CharPtr("ba"))));
EXPECT_EQ("foobar", promo.Perform(make_tuple(CharPtr("ba")))); EXPECT_EQ("foobar", promo.Perform(std::make_tuple(CharPtr("ba"))));
} }
// Tests that we can partially restrict parameter types using a // Tests that we can partially restrict parameter types using a
...@@ -925,10 +925,10 @@ Concat(T1 a, int b, T2 c) { ...@@ -925,10 +925,10 @@ Concat(T1 a, int b, T2 c) {
TEST(ActionPnMacroTest, CanPartiallyRestrictParameterTypes) { TEST(ActionPnMacroTest, CanPartiallyRestrictParameterTypes) {
Action<const std::string()> a1 = Concat("Hello", "1", 2); 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); 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*. // Verifies the type of an ACTION*.
...@@ -986,7 +986,7 @@ ACTION_P10(Plus10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { ...@@ -986,7 +986,7 @@ ACTION_P10(Plus10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
TEST(ActionPnMacroTest, CanExplicitlyInstantiateWithReferenceTypes) { TEST(ActionPnMacroTest, CanExplicitlyInstantiateWithReferenceTypes) {
int x = 1, y = 2, z = 3; 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); Action<int()> a = Plus1<int&>(x);
EXPECT_EQ(1, a.Perform(empty)); EXPECT_EQ(1, a.Perform(empty));
...@@ -1013,7 +1013,7 @@ class NullaryConstructorClass { ...@@ -1013,7 +1013,7 @@ class NullaryConstructorClass {
// Tests using ReturnNew() with a nullary constructor. // Tests using ReturnNew() with a nullary constructor.
TEST(ReturnNewTest, NoArgs) { TEST(ReturnNewTest, NoArgs) {
Action<NullaryConstructorClass*()> a = ReturnNew<NullaryConstructorClass>(); Action<NullaryConstructorClass*()> a = ReturnNew<NullaryConstructorClass>();
NullaryConstructorClass* c = a.Perform(make_tuple()); NullaryConstructorClass* c = a.Perform(std::make_tuple());
EXPECT_EQ(123, c->value_); EXPECT_EQ(123, c->value_);
delete c; delete c;
} }
...@@ -1027,7 +1027,7 @@ class UnaryConstructorClass { ...@@ -1027,7 +1027,7 @@ class UnaryConstructorClass {
// Tests using ReturnNew() with a unary constructor. // Tests using ReturnNew() with a unary constructor.
TEST(ReturnNewTest, Unary) { TEST(ReturnNewTest, Unary) {
Action<UnaryConstructorClass*()> a = ReturnNew<UnaryConstructorClass>(4000); Action<UnaryConstructorClass*()> a = ReturnNew<UnaryConstructorClass>(4000);
UnaryConstructorClass* c = a.Perform(make_tuple()); UnaryConstructorClass* c = a.Perform(std::make_tuple());
EXPECT_EQ(4000, c->value_); EXPECT_EQ(4000, c->value_);
delete c; delete c;
} }
...@@ -1035,7 +1035,7 @@ TEST(ReturnNewTest, Unary) { ...@@ -1035,7 +1035,7 @@ TEST(ReturnNewTest, Unary) {
TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) { TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) {
Action<UnaryConstructorClass*(bool, int)> a = Action<UnaryConstructorClass*(bool, int)> a =
ReturnNew<UnaryConstructorClass>(4000); 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_); EXPECT_EQ(4000, c->value_);
delete c; delete c;
} }
...@@ -1043,7 +1043,7 @@ TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) { ...@@ -1043,7 +1043,7 @@ TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) {
TEST(ReturnNewTest, UnaryWorksWhenMockMethodReturnsPointerToConst) { TEST(ReturnNewTest, UnaryWorksWhenMockMethodReturnsPointerToConst) {
Action<const UnaryConstructorClass*()> a = Action<const UnaryConstructorClass*()> a =
ReturnNew<UnaryConstructorClass>(4000); ReturnNew<UnaryConstructorClass>(4000);
const UnaryConstructorClass* c = a.Perform(make_tuple()); const UnaryConstructorClass* c = a.Perform(std::make_tuple());
EXPECT_EQ(4000, c->value_); EXPECT_EQ(4000, c->value_);
delete c; delete c;
} }
...@@ -1063,7 +1063,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) { ...@@ -1063,7 +1063,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) {
ReturnNew<TenArgConstructorClass>(1000000000, 200000000, 30000000, ReturnNew<TenArgConstructorClass>(1000000000, 200000000, 30000000,
4000000, 500000, 60000, 4000000, 500000, 60000,
7000, 800, 90, 0); 7000, 800, 90, 0);
TenArgConstructorClass* c = a.Perform(make_tuple()); TenArgConstructorClass* c = a.Perform(std::make_tuple());
EXPECT_EQ(1234567890, c->value_); EXPECT_EQ(1234567890, c->value_);
delete c; delete c;
} }
...@@ -1077,7 +1077,7 @@ ACTION_TEMPLATE(CreateNew, ...@@ -1077,7 +1077,7 @@ ACTION_TEMPLATE(CreateNew,
TEST(ActionTemplateTest, WorksWithoutValueParam) { TEST(ActionTemplateTest, WorksWithoutValueParam) {
const Action<int*()> a = CreateNew<int>(); const Action<int*()> a = CreateNew<int>();
int* p = a.Perform(make_tuple()); int* p = a.Perform(std::make_tuple());
delete p; delete p;
} }
...@@ -1090,7 +1090,7 @@ ACTION_TEMPLATE(CreateNew, ...@@ -1090,7 +1090,7 @@ ACTION_TEMPLATE(CreateNew,
TEST(ActionTemplateTest, WorksWithValueParams) { TEST(ActionTemplateTest, WorksWithValueParams) {
const Action<int*()> a = CreateNew<int>(42); const Action<int*()> a = CreateNew<int>(42);
int* p = a.Perform(make_tuple()); int* p = a.Perform(std::make_tuple());
EXPECT_EQ(42, *p); EXPECT_EQ(42, *p);
delete p; delete p;
} }
...@@ -1099,7 +1099,7 @@ TEST(ActionTemplateTest, WorksWithValueParams) { ...@@ -1099,7 +1099,7 @@ TEST(ActionTemplateTest, WorksWithValueParams) {
ACTION_TEMPLATE(MyDeleteArg, ACTION_TEMPLATE(MyDeleteArg,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_0_VALUE_PARAMS()) { AND_0_VALUE_PARAMS()) {
delete get<k>(args); delete std::get<k>(args);
} }
// Resets a bool variable in the destructor. // Resets a bool variable in the destructor.
...@@ -1116,7 +1116,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) { ...@@ -1116,7 +1116,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) {
int n = 0; int n = 0;
bool b = true; bool b = true;
BoolResetter* resetter = new BoolResetter(&b); 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. EXPECT_FALSE(b); // Verifies that resetter is deleted.
} }
...@@ -1131,7 +1131,7 @@ ACTION_TEMPLATE(ReturnSmartPointer, ...@@ -1131,7 +1131,7 @@ ACTION_TEMPLATE(ReturnSmartPointer,
TEST(ActionTemplateTest, WorksForTemplateTemplateParameters) { TEST(ActionTemplateTest, WorksForTemplateTemplateParameters) {
using ::testing::internal::linked_ptr; using ::testing::internal::linked_ptr;
const Action<linked_ptr<int>()> a = ReturnSmartPointer<linked_ptr>(42); 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); EXPECT_EQ(42, *p);
} }
...@@ -1166,7 +1166,7 @@ TEST(ActionTemplateTest, WorksFor10TemplateParameters) { ...@@ -1166,7 +1166,7 @@ TEST(ActionTemplateTest, WorksFor10TemplateParameters) {
true, 6, char, unsigned, int> Giant; true, 6, char, unsigned, int> Giant;
const Action<Giant()> a = ReturnGiant< const Action<Giant()> a = ReturnGiant<
int, bool, double, 5, true, 6, char, unsigned, int, linked_ptr>(42); 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); EXPECT_EQ(42, giant.value);
} }
...@@ -1179,7 +1179,7 @@ ACTION_TEMPLATE(ReturnSum, ...@@ -1179,7 +1179,7 @@ ACTION_TEMPLATE(ReturnSum,
TEST(ActionTemplateTest, WorksFor10ValueParameters) { TEST(ActionTemplateTest, WorksFor10ValueParameters) {
const Action<int()> a = ReturnSum<int>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 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 // Tests that ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded
...@@ -1213,11 +1213,11 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) { ...@@ -1213,11 +1213,11 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) {
const Action<int()> a2 = ReturnSum<int>(1, 2); const Action<int()> a2 = ReturnSum<int>(1, 2);
const Action<int()> a3 = ReturnSum<int>(1, 2, 3); const Action<int()> a3 = ReturnSum<int>(1, 2, 3);
const Action<int()> a4 = ReturnSum<int, 10000>(2000, 300, 40, 5); const Action<int()> a4 = ReturnSum<int, 10000>(2000, 300, 40, 5);
EXPECT_EQ(0, a0.Perform(make_tuple())); EXPECT_EQ(0, a0.Perform(std::make_tuple()));
EXPECT_EQ(1, a1.Perform(make_tuple())); EXPECT_EQ(1, a1.Perform(std::make_tuple()));
EXPECT_EQ(3, a2.Perform(make_tuple())); EXPECT_EQ(3, a2.Perform(std::make_tuple()));
EXPECT_EQ(6, a3.Perform(make_tuple())); EXPECT_EQ(6, a3.Perform(std::make_tuple()));
EXPECT_EQ(12345, a4.Perform(make_tuple())); EXPECT_EQ(12345, a4.Perform(std::make_tuple()));
} }
#ifdef _MSC_VER #ifdef _MSC_VER
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -57,7 +56,6 @@ ...@@ -57,7 +56,6 @@
namespace testing { namespace testing {
namespace gmock_generated_function_mockers_test { namespace gmock_generated_function_mockers_test {
using testing::internal::string;
using testing::_; using testing::_;
using testing::A; using testing::A;
using testing::An; using testing::An;
...@@ -82,11 +80,11 @@ class FooInterface { ...@@ -82,11 +80,11 @@ class FooInterface {
virtual bool Unary(int x) = 0; virtual bool Unary(int x) = 0;
virtual long Binary(short x, int y) = 0; // NOLINT virtual long Binary(short x, int y) = 0; // NOLINT
virtual int Decimal(bool b, char c, short d, int e, long f, // 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) float g, double h, unsigned i, char* j,
= 0; const std::string& k) = 0;
virtual bool TakesNonConstReference(int& n) = 0; // NOLINT 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 #ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual bool TakesConst(const int x) = 0; virtual bool TakesConst(const int x) = 0;
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS #endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
...@@ -101,13 +99,14 @@ class FooInterface { ...@@ -101,13 +99,14 @@ class FooInterface {
virtual char OverloadedOnConstness() const = 0; virtual char OverloadedOnConstness() const = 0;
virtual int TypeWithHole(int (*func)()) = 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 #if GTEST_OS_WINDOWS
STDMETHOD_(int, CTNullary)() = 0; STDMETHOD_(int, CTNullary)() = 0;
STDMETHOD_(bool, CTUnary)(int x) = 0; STDMETHOD_(bool, CTUnary)(int x) = 0;
STDMETHOD_(int, CTDecimal)(bool b, char c, short d, int e, long f, // NOLINT STDMETHOD_(int, CTDecimal)
float g, double h, unsigned i, char* j, const string& k) = 0; (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; STDMETHOD_(char, CTConst)(int x) const = 0;
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
}; };
...@@ -133,19 +132,19 @@ class MockFoo : public FooInterface { ...@@ -133,19 +132,19 @@ class MockFoo : public FooInterface {
MOCK_METHOD1(Unary, bool(int)); // NOLINT MOCK_METHOD1(Unary, bool(int)); // NOLINT
MOCK_METHOD2(Binary, long(short, int)); // NOLINT MOCK_METHOD2(Binary, long(short, int)); // NOLINT
MOCK_METHOD10(Decimal, int(bool, char, short, int, long, float, // 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(TakesNonConstReference, bool(int&)); // NOLINT
MOCK_METHOD1(TakesConstReference, string(const int&)); MOCK_METHOD1(TakesConstReference, std::string(const int&));
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS #ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT
#endif #endif
// Tests that the function return type can contain unprotected comma. // 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, MOCK_CONST_METHOD1(ReturnTypeWithComma,
std::map<int, string>(int)); // NOLINT std::map<int, std::string>(int)); // NOLINT
MOCK_METHOD0(OverloadedOnArgumentNumber, int()); // NOLINT MOCK_METHOD0(OverloadedOnArgumentNumber, int()); // NOLINT
MOCK_METHOD1(OverloadedOnArgumentNumber, int(int)); // NOLINT MOCK_METHOD1(OverloadedOnArgumentNumber, int(int)); // NOLINT
...@@ -157,19 +156,21 @@ class MockFoo : public FooInterface { ...@@ -157,19 +156,21 @@ class MockFoo : public FooInterface {
MOCK_CONST_METHOD0(OverloadedOnConstness, char()); // NOLINT MOCK_CONST_METHOD0(OverloadedOnConstness, char()); // NOLINT
MOCK_METHOD1(TypeWithHole, int(int (*)())); // 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 #if GTEST_OS_WINDOWS
MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int()); MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int());
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int)); MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int));
MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal, int(bool b, char c, MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal,
short d, int e, long f, float g, double h, unsigned i, char* j, int(bool b, char c, short d, int e, long f,
const string& k)); float g, double h, unsigned i, char* j,
const std::string& k));
MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst, char(int)); MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst, char(int));
// Tests that the function return type can contain unprotected comma. // Tests that the function return type can contain unprotected comma.
MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTReturnTypeWithComma, MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTReturnTypeWithComma,
std::map<int, string>()); std::map<int, std::string>());
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
private: private:
...@@ -227,7 +228,7 @@ TEST_F(FunctionMockerTest, MocksDecimalFunction) { ...@@ -227,7 +228,7 @@ TEST_F(FunctionMockerTest, MocksDecimalFunction) {
Lt(100), 5U, NULL, "hi")) Lt(100), 5U, NULL, "hi"))
.WillOnce(Return(5)); .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. // Tests mocking a function that takes a non-const reference.
...@@ -291,7 +292,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) { ...@@ -291,7 +292,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) {
} }
TEST_F(FunctionMockerTest, MocksReturnTypeWithComma) { TEST_F(FunctionMockerTest, MocksReturnTypeWithComma) {
const std::map<int, string> a_map; const std::map<int, std::string> a_map;
EXPECT_CALL(mock_foo_, ReturnTypeWithComma()) EXPECT_CALL(mock_foo_, ReturnTypeWithComma())
.WillOnce(Return(a_map)); .WillOnce(Return(a_map));
EXPECT_CALL(mock_foo_, ReturnTypeWithComma(42)) EXPECT_CALL(mock_foo_, ReturnTypeWithComma(42))
...@@ -341,7 +342,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) { ...@@ -341,7 +342,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
} }
TEST_F(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) { TEST_F(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) {
const std::map<int, string> a_map; const std::map<int, std::string> a_map;
EXPECT_CALL(mock_foo_, CTReturnTypeWithComma()) EXPECT_CALL(mock_foo_, CTReturnTypeWithComma())
.WillOnce(Return(a_map)); .WillOnce(Return(a_map));
...@@ -616,7 +617,41 @@ TEST(MockFunctionTest, AsStdFunctionReturnsReference) { ...@@ -616,7 +617,41 @@ TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
value = 2; value = 2;
EXPECT_EQ(2, ref); 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_ #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 gmock_generated_function_mockers_test
} // namespace testing } // namespace testing
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -39,7 +38,6 @@ ...@@ -39,7 +38,6 @@
namespace { namespace {
using ::testing::tuple;
using ::testing::Matcher; using ::testing::Matcher;
using ::testing::internal::CompileAssertTypesEqual; using ::testing::internal::CompileAssertTypesEqual;
using ::testing::internal::MatcherTuple; using ::testing::internal::MatcherTuple;
...@@ -49,24 +47,24 @@ using ::testing::internal::IgnoredValue; ...@@ -49,24 +47,24 @@ using ::testing::internal::IgnoredValue;
// Tests the MatcherTuple template struct. // Tests the MatcherTuple template struct.
TEST(MatcherTupleTest, ForSize0) { TEST(MatcherTupleTest, ForSize0) {
CompileAssertTypesEqual<tuple<>, MatcherTuple<tuple<> >::type>(); CompileAssertTypesEqual<std::tuple<>, MatcherTuple<std::tuple<> >::type>();
} }
TEST(MatcherTupleTest, ForSize1) { TEST(MatcherTupleTest, ForSize1) {
CompileAssertTypesEqual<tuple<Matcher<int> >, CompileAssertTypesEqual<std::tuple<Matcher<int> >,
MatcherTuple<tuple<int> >::type>(); MatcherTuple<std::tuple<int> >::type>();
} }
TEST(MatcherTupleTest, ForSize2) { TEST(MatcherTupleTest, ForSize2) {
CompileAssertTypesEqual<tuple<Matcher<int>, Matcher<char> >, CompileAssertTypesEqual<std::tuple<Matcher<int>, Matcher<char> >,
MatcherTuple<tuple<int, char> >::type>(); MatcherTuple<std::tuple<int, char> >::type>();
} }
TEST(MatcherTupleTest, ForSize5) { TEST(MatcherTupleTest, ForSize5) {
CompileAssertTypesEqual<tuple<Matcher<int>, Matcher<char>, Matcher<bool>, CompileAssertTypesEqual<
Matcher<double>, Matcher<char*> >, std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<double>,
MatcherTuple<tuple<int, char, bool, double, char*> Matcher<char*> >,
>::type>(); MatcherTuple<std::tuple<int, char, bool, double, char*> >::type>();
} }
// Tests the Function template struct. // Tests the Function template struct.
...@@ -74,8 +72,8 @@ TEST(MatcherTupleTest, ForSize5) { ...@@ -74,8 +72,8 @@ TEST(MatcherTupleTest, ForSize5) {
TEST(FunctionTest, Nullary) { TEST(FunctionTest, Nullary) {
typedef Function<int()> F; // NOLINT typedef Function<int()> F; // NOLINT
CompileAssertTypesEqual<int, F::Result>(); CompileAssertTypesEqual<int, F::Result>();
CompileAssertTypesEqual<tuple<>, F::ArgumentTuple>(); CompileAssertTypesEqual<std::tuple<>, F::ArgumentTuple>();
CompileAssertTypesEqual<tuple<>, F::ArgumentMatcherTuple>(); CompileAssertTypesEqual<std::tuple<>, F::ArgumentMatcherTuple>();
CompileAssertTypesEqual<void(), F::MakeResultVoid>(); CompileAssertTypesEqual<void(), F::MakeResultVoid>();
CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>(); CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>();
} }
...@@ -84,8 +82,9 @@ TEST(FunctionTest, Unary) { ...@@ -84,8 +82,9 @@ TEST(FunctionTest, Unary) {
typedef Function<int(bool)> F; // NOLINT typedef Function<int(bool)> F; // NOLINT
CompileAssertTypesEqual<int, F::Result>(); CompileAssertTypesEqual<int, F::Result>();
CompileAssertTypesEqual<bool, F::Argument1>(); CompileAssertTypesEqual<bool, F::Argument1>();
CompileAssertTypesEqual<tuple<bool>, F::ArgumentTuple>(); CompileAssertTypesEqual<std::tuple<bool>, F::ArgumentTuple>();
CompileAssertTypesEqual<tuple<Matcher<bool> >, F::ArgumentMatcherTuple>(); CompileAssertTypesEqual<std::tuple<Matcher<bool> >,
F::ArgumentMatcherTuple>();
CompileAssertTypesEqual<void(bool), F::MakeResultVoid>(); // NOLINT CompileAssertTypesEqual<void(bool), F::MakeResultVoid>(); // NOLINT
CompileAssertTypesEqual<IgnoredValue(bool), // NOLINT CompileAssertTypesEqual<IgnoredValue(bool), // NOLINT
F::MakeResultIgnoredValue>(); F::MakeResultIgnoredValue>();
...@@ -96,9 +95,11 @@ TEST(FunctionTest, Binary) { ...@@ -96,9 +95,11 @@ TEST(FunctionTest, Binary) {
CompileAssertTypesEqual<int, F::Result>(); CompileAssertTypesEqual<int, F::Result>();
CompileAssertTypesEqual<bool, F::Argument1>(); CompileAssertTypesEqual<bool, F::Argument1>();
CompileAssertTypesEqual<const long&, F::Argument2>(); // NOLINT CompileAssertTypesEqual<const long&, F::Argument2>(); // NOLINT
CompileAssertTypesEqual<tuple<bool, const long&>, F::ArgumentTuple>(); // NOLINT CompileAssertTypesEqual<std::tuple<bool, const long&>, // NOLINT
CompileAssertTypesEqual<tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT F::ArgumentTuple>();
F::ArgumentMatcherTuple>(); CompileAssertTypesEqual<
std::tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT
F::ArgumentMatcherTuple>();
CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>(); // NOLINT CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>(); // NOLINT
CompileAssertTypesEqual<IgnoredValue(bool, const long&), // NOLINT CompileAssertTypesEqual<IgnoredValue(bool, const long&), // NOLINT
F::MakeResultIgnoredValue>(); F::MakeResultIgnoredValue>();
...@@ -112,11 +113,13 @@ TEST(FunctionTest, LongArgumentList) { ...@@ -112,11 +113,13 @@ TEST(FunctionTest, LongArgumentList) {
CompileAssertTypesEqual<char*, F::Argument3>(); CompileAssertTypesEqual<char*, F::Argument3>();
CompileAssertTypesEqual<int&, F::Argument4>(); CompileAssertTypesEqual<int&, F::Argument4>();
CompileAssertTypesEqual<const long&, F::Argument5>(); // NOLINT CompileAssertTypesEqual<const long&, F::Argument5>(); // NOLINT
CompileAssertTypesEqual<tuple<bool, int, char*, int&, const long&>, // NOLINT CompileAssertTypesEqual<
F::ArgumentTuple>(); std::tuple<bool, int, char*, int&, const long&>, // NOLINT
CompileAssertTypesEqual<tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, F::ArgumentTuple>();
Matcher<int&>, Matcher<const long&> >, // NOLINT CompileAssertTypesEqual<
F::ArgumentMatcherTuple>(); 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 CompileAssertTypesEqual<void(bool, int, char*, int&, const long&), // NOLINT
F::MakeResultVoid>(); F::MakeResultVoid>();
CompileAssertTypesEqual< CompileAssertTypesEqual<
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment