Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
85f059f0
Unverified
Commit
85f059f0
authored
Aug 27, 2019
by
Chris Johnson
Committed by
GitHub
Aug 27, 2019
Browse files
Merge pull request #3 from google/master
Update master
parents
130e5aa8
fdd6a1dc
Changes
218
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
549 additions
and
1115 deletions
+549
-1115
googlemock/msvc/2015/gmock_main.vcxproj
googlemock/msvc/2015/gmock_main.vcxproj
+0
-151
googlemock/msvc/2015/gmock_test.vcxproj
googlemock/msvc/2015/gmock_test.vcxproj
+0
-176
googlemock/scripts/fuse_gmock_files.py
googlemock/scripts/fuse_gmock_files.py
+1
-1
googlemock/src/gmock-internal-utils.cc
googlemock/src/gmock-internal-utils.cc
+2
-5
googlemock/src/gmock-spec-builders.cc
googlemock/src/gmock-spec-builders.cc
+10
-16
googlemock/src/gmock.cc
googlemock/src/gmock.cc
+13
-4
googlemock/src/gmock_main.cc
googlemock/src/gmock_main.cc
+1
-7
googlemock/test/BUILD.bazel
googlemock/test/BUILD.bazel
+4
-0
googlemock/test/gmock-actions_test.cc
googlemock/test/gmock-actions_test.cc
+5
-48
googlemock/test/gmock-cardinalities_test.cc
googlemock/test/gmock-cardinalities_test.cc
+2
-2
googlemock/test/gmock-function-mocker_test.cc
googlemock/test/gmock-function-mocker_test.cc
+18
-17
googlemock/test/gmock-generated-actions_test.cc
googlemock/test/gmock-generated-actions_test.cc
+2
-4
googlemock/test/gmock-generated-function-mockers_test.cc
googlemock/test/gmock-generated-function-mockers_test.cc
+19
-3
googlemock/test/gmock-generated-internal-utils_test.cc
googlemock/test/gmock-generated-internal-utils_test.cc
+0
-130
googlemock/test/gmock-generated-matchers_test.cc
googlemock/test/gmock-generated-matchers_test.cc
+143
-5
googlemock/test/gmock-internal-utils_test.cc
googlemock/test/gmock-internal-utils_test.cc
+77
-47
googlemock/test/gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+237
-446
googlemock/test/gmock-nice-strict_test.cc
googlemock/test/gmock-nice-strict_test.cc
+11
-49
googlemock/test/gmock-spec-builders_test.cc
googlemock/test/gmock-spec-builders_test.cc
+4
-3
googlemock/test/gmock_all_test.cc
googlemock/test/gmock_all_test.cc
+0
-1
No files found.
googlemock/msvc/2015/gmock_main.vcxproj
deleted
100644 → 0
View file @
130e5aa8
<?xml version="1.0" encoding="utf-8"?>
<Project
DefaultTargets=
"Build"
ToolsVersion=
"14.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup
Label=
"ProjectConfigurations"
>
<ProjectConfiguration
Include=
"Debug|Win32"
>
<Configuration>
Debug
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Debug|x64"
>
<Configuration>
Debug
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|Win32"
>
<Configuration>
Release
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|x64"
>
<Configuration>
Release
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup
Label=
"Globals"
>
<ProjectGuid>
{E4EF614B-30DF-4954-8C53-580A0BF6B589}
</ProjectGuid>
<RootNamespace>
gmock_main
</RootNamespace>
<Keyword>
Win32Proj
</Keyword>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.Default.props"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
StaticLibrary
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"Configuration"
>
<ConfigurationType>
StaticLibrary
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
StaticLibrary
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"Configuration"
>
<ConfigurationType>
StaticLibrary
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.props"
/>
<ImportGroup
Label=
"ExtensionSettings"
>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<PropertyGroup
Label=
"UserMacros"
/>
<PropertyGroup>
<_ProjectFileVersion>
10.0.30319.1
</_ProjectFileVersion>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(OutDir)$(ProjectName)\
</IntDir>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<OutDir>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<OutDir>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ClCompile>
<Optimization>
Disabled
</Optimization>
<AdditionalIncludeDirectories>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<MinimalRebuild>
true
</MinimalRebuild>
<BasicRuntimeChecks>
EnableFastChecks
</BasicRuntimeChecks>
<RuntimeLibrary>
MultiThreadedDebug
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<ClCompile>
<Optimization>
Disabled
</Optimization>
<AdditionalIncludeDirectories>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<BasicRuntimeChecks>
EnableFastChecks
</BasicRuntimeChecks>
<RuntimeLibrary>
MultiThreadedDebug
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<ClCompile>
<AdditionalIncludeDirectories>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<RuntimeLibrary>
MultiThreaded
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<ClCompile>
<AdditionalIncludeDirectories>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<RuntimeLibrary>
MultiThreaded
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference
Include=
"gmock.vcxproj"
>
<Project>
{34681f0d-ce45-415d-b5f2-5c662dfe3bd5}
</Project>
<CopyLocalSatelliteAssemblies>
true
</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>
true
</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"..\..\src\gmock_main.cc"
>
<AdditionalIncludeDirectories
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
../../include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
</ImportGroup>
</Project>
\ No newline at end of file
googlemock/msvc/2015/gmock_test.vcxproj
deleted
100644 → 0
View file @
130e5aa8
<?xml version="1.0" encoding="utf-8"?>
<Project
DefaultTargets=
"Build"
ToolsVersion=
"14.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup
Label=
"ProjectConfigurations"
>
<ProjectConfiguration
Include=
"Debug|Win32"
>
<Configuration>
Debug
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Debug|x64"
>
<Configuration>
Debug
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|Win32"
>
<Configuration>
Release
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|x64"
>
<Configuration>
Release
</Configuration>
<Platform>
x64
</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup
Label=
"Globals"
>
<ProjectGuid>
{F10D22F8-AC7B-4213-8720-608E7D878CD2}
</ProjectGuid>
<RootNamespace>
gmock_test
</RootNamespace>
<Keyword>
Win32Proj
</Keyword>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.Default.props"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<CharacterSet>
Unicode
</CharacterSet>
<PlatformToolset>
v140
</PlatformToolset>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.props"
/>
<ImportGroup
Label=
"ExtensionSettings"
>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<ImportGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
Label=
"PropertySheets"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
<Import
Project=
"gmock_config.props"
/>
</ImportGroup>
<PropertyGroup
Label=
"UserMacros"
/>
<PropertyGroup>
<_ProjectFileVersion>
10.0.30319.1
</_ProjectFileVersion>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
$(OutDir)$(ProjectName)\
</IntDir>
<LinkIncremental
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</LinkIncremental>
<LinkIncremental
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
true
</LinkIncremental>
<OutDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
$(OutDir)$(ProjectName)\
</IntDir>
<LinkIncremental
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
false
</LinkIncremental>
<LinkIncremental
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
false
</LinkIncremental>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<OutDir>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<OutDir>
$(SolutionDir)$(Platform)-$(Configuration)\
</OutDir>
<IntDir>
$(OutDir)$(ProjectName)\
</IntDir>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ClCompile>
<AdditionalOptions>
/bigobj %(AdditionalOptions)
</AdditionalOptions>
<Optimization>
Disabled
</Optimization>
<AdditionalIncludeDirectories>
..\..\include;..\..;$(GTestDir);%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<MinimalRebuild>
true
</MinimalRebuild>
<BasicRuntimeChecks>
EnableFastChecks
</BasicRuntimeChecks>
<RuntimeLibrary>
MultiThreadedDebug
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<SubSystem>
Console
</SubSystem>
<TargetMachine>
MachineX86
</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<ClCompile>
<AdditionalOptions>
/bigobj %(AdditionalOptions)
</AdditionalOptions>
<Optimization>
Disabled
</Optimization>
<AdditionalIncludeDirectories>
..\..\include;..\..;$(GTestDir);%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<BasicRuntimeChecks>
EnableFastChecks
</BasicRuntimeChecks>
<RuntimeLibrary>
MultiThreadedDebug
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<SubSystem>
Console
</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<ClCompile>
<AdditionalOptions>
/bigobj %(AdditionalOptions)
</AdditionalOptions>
<AdditionalIncludeDirectories>
..\..\include;..\..;$(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>
<TargetMachine>
MachineX86
</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<ClCompile>
<AdditionalOptions>
/bigobj %(AdditionalOptions)
</AdditionalOptions>
<AdditionalIncludeDirectories>
..\..\include;..\..;$(GTestDir);%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<RuntimeLibrary>
MultiThreaded
</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<SubSystem>
Console
</SubSystem>
<OptimizeReferences>
true
</OptimizeReferences>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference
Include=
"gmock_main.vcxproj"
>
<Project>
{e4ef614b-30df-4954-8c53-580a0bf6b589}
</Project>
<CopyLocalSatelliteAssemblies>
true
</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>
true
</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"..\..\test\gmock_all_test.cc"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
</ImportGroup>
</Project>
\ No newline at end of file
googlemock/scripts/fuse_gmock_files.py
View file @
85f059f0
...
...
@@ -55,7 +55,7 @@ EXAMPLES
This tool is experimental. In particular, it assumes that there is no
conditional inclusion of Google Mock or Google Test headers. Please
report any problems to googlemock@googlegroups.com. You can read
https://github.com/google/googletest/blob/master/googlemock/docs/
C
ook
B
ook.md for more
https://github.com/google/googletest/blob/master/googlemock/docs/
c
ook
_b
ook.md for more
information.
"""
...
...
googlemock/src/gmock-internal-utils.cc
View file @
85f059f0
...
...
@@ -123,7 +123,7 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter() {
// Protects global resources (stdout in particular) used by Log().
static
GTEST_DEFINE_STATIC_MUTEX_
(
g_log_mutex
);
// Returns true if
f
a log with the given severity is visible according
// Returns true if a log with the given severity is visible according
// to the --gmock_verbose flag.
GTEST_API_
bool
LogIsVisible
(
LogSeverity
severity
)
{
if
(
GMOCK_FLAG
(
verbose
)
==
kInfoVerbosity
)
{
...
...
@@ -139,7 +139,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) {
}
}
// Prints the given message to stdout if
f
'severity' >= the level
// Prints the given message to stdout if 'severity' >= the level
// specified by the --gmock_verbose flag. If stack_frames_to_skip >=
// 0, also prints the stack trace excluding the top
// stack_frames_to_skip frames. In opt mode, any positive
...
...
@@ -154,9 +154,6 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message,
// Ensures that logs from different threads don't interleave.
MutexLock
l
(
&
g_log_mutex
);
// "using ::std::cout;" doesn't work with Symbian's STLport, where cout is a
// macro.
if
(
severity
==
kWarning
)
{
// Prints a GMOCK WARNING marker to make the warnings easily searchable.
std
::
cout
<<
"
\n
GMOCK WARNING:"
;
...
...
googlemock/src/gmock-spec-builders.cc
View file @
85f059f0
...
...
@@ -126,7 +126,7 @@ void ExpectationBase::RetireAllPreRequisites()
}
}
// Returns true if
f
all pre-requisites of this expectation have been
// Returns true if all pre-requisites of this expectation have been
// satisfied.
bool
ExpectationBase
::
AllPrerequisitesAreSatisfied
()
const
GTEST_EXCLUSIVE_LOCK_REQUIRED_
(
g_gmock_mutex
)
{
...
...
@@ -292,7 +292,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
"an EXPECT_CALL() if you don't mean to enforce the call. "
"See "
"https://github.com/google/googletest/blob/master/googlemock/"
"docs/
C
ook
B
ook.md#"
"docs/
c
ook
_b
ook.md#"
"knowing-when-to-expect for details.
\n
"
,
stack_frames_to_skip
);
break
;
...
...
@@ -384,7 +384,7 @@ UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith(
const
CallReaction
reaction
=
Mock
::
GetReactionOnUninterestingCalls
(
MockObject
());
// True if
f
we need to print this call's arguments and return
// True if we need to print this call's arguments and return
// value. This definition must be kept in sync with
// the behavior of ReportUninterestingCall().
const
bool
need_to_report_uninteresting_call
=
...
...
@@ -435,7 +435,7 @@ UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith(
&
ss
,
&
why
);
const
bool
found
=
untyped_expectation
!=
nullptr
;
// True if
f
we need to print the call's arguments and return value.
// True if we need to print the call's arguments and return value.
// This definition must be kept in sync with the uses of Expect()
// and Log() in this function.
const
bool
need_to_report_call
=
...
...
@@ -572,9 +572,9 @@ struct MockObjectState {
// invoked on this mock object.
const
char
*
first_used_file
;
int
first_used_line
;
::
std
::
string
first_used_test_
cas
e
;
::
std
::
string
first_used_test_
suit
e
;
::
std
::
string
first_used_test
;
bool
leakable
;
// true if
f
it's OK to leak the object.
bool
leakable
;
// true if it's OK to leak the object.
FunctionMockers
function_mockers
;
// All registered methods of the object.
};
...
...
@@ -592,9 +592,6 @@ class MockObjectRegistry {
// object alive. Therefore we report any living object as test
// failure, unless the user explicitly asked us to ignore it.
~
MockObjectRegistry
()
{
// "using ::std::cout;" doesn't work with Symbian's STLport, where cout is
// a macro.
if
(
!
GMOCK_FLAG
(
catch_leaked_mocks
))
return
;
...
...
@@ -612,7 +609,7 @@ class MockObjectRegistry {
state
.
first_used_line
);
std
::
cout
<<
" ERROR: this mock object"
;
if
(
state
.
first_used_test
!=
""
)
{
std
::
cout
<<
" (used in test "
<<
state
.
first_used_test_
cas
e
<<
"."
std
::
cout
<<
" (used in test "
<<
state
.
first_used_test_
suit
e
<<
"."
<<
state
.
first_used_test
<<
")"
;
}
std
::
cout
<<
" should be deleted but never is. Its address is @"
...
...
@@ -721,7 +718,7 @@ bool Mock::VerifyAndClearExpectations(void* mock_obj)
}
// Verifies all expectations on the given mock object and clears its
// default actions and expectations. Returns true if
f
the
// default actions and expectations. Returns true if the
// verification was successful.
bool
Mock
::
VerifyAndClear
(
void
*
mock_obj
)
GTEST_LOCK_EXCLUDED_
(
internal
::
g_gmock_mutex
)
{
...
...
@@ -793,10 +790,7 @@ void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj,
const
TestInfo
*
const
test_info
=
UnitTest
::
GetInstance
()
->
current_test_info
();
if
(
test_info
!=
nullptr
)
{
// FIXME: record the test case name when the
// ON_CALL or EXPECT_CALL is invoked from SetUpTestCase() or
// TearDownTestCase().
state
.
first_used_test_case
=
test_info
->
test_case_name
();
state
.
first_used_test_suite
=
test_info
->
test_suite_name
();
state
.
first_used_test
=
test_info
->
name
();
}
}
...
...
googlemock/src/gmock.cc
View file @
85f059f0
...
...
@@ -33,11 +33,8 @@
namespace
testing
{
// FIXME: support using environment variables to
// control the flag values, like what Google Test does.
GMOCK_DEFINE_bool_
(
catch_leaked_mocks
,
true
,
"true if
f
Google Mock should report leaked mock objects "
"true if Google Mock should report leaked mock objects "
"as failures."
);
GMOCK_DEFINE_string_
(
verbose
,
internal
::
kWarningVerbosity
,
...
...
@@ -201,4 +198,16 @@ GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv) {
internal
::
InitGoogleMockImpl
(
argc
,
argv
);
}
// This overloaded version can be used on Arduino/embedded platforms where
// there is no argc/argv.
GTEST_API_
void
InitGoogleMock
()
{
// Since Arduino doesn't have a command line, fake out the argc/argv arguments
int
argc
=
1
;
const
auto
arg0
=
"dummy"
;
char
*
argv0
=
const_cast
<
char
*>
(
arg0
);
char
**
argv
=
&
argv0
;
internal
::
InitGoogleMockImpl
(
&
argc
,
argv
);
}
}
// namespace testing
googlemock/src/gmock_main.cc
View file @
85f059f0
...
...
@@ -34,16 +34,10 @@
#ifdef ARDUINO
void
setup
()
{
// Since Arduino doesn't have a command line, fake out the argc/argv arguments
int
argc
=
1
;
const
auto
arg0
=
"PlatformIO"
;
char
*
argv0
=
const_cast
<
char
*>
(
arg0
);
char
**
argv
=
&
argv0
;
// Since Google Mock depends on Google Test, InitGoogleMock() is
// also responsible for initializing Google Test. Therefore there's
// no need for calling testing::InitGoogleTest() separately.
testing
::
InitGoogleMock
(
&
argc
,
argv
);
testing
::
InitGoogleMock
();
}
void
loop
()
{
RUN_ALL_TESTS
();
}
#else
...
...
googlemock/test/BUILD.bazel
View file @
85f059f0
...
...
@@ -32,6 +32,9 @@
#
# Bazel Build for Google C++ Testing Framework(Google Test)-googlemock
load
(
"@rules_cc//cc:defs.bzl"
,
"cc_binary"
,
"cc_test"
)
load
(
"@rules_python//python:defs.bzl"
,
"py_library"
,
"py_test"
)
licenses
([
"notice"
])
# Tests for GMock itself
...
...
@@ -95,6 +98,7 @@ py_test(
":gmock_output_test_"
,
":gmock_output_test_golden.txt"
,
],
python_version
=
"PY2"
,
deps
=
[
":gmock_test_utils"
],
)
...
...
googlemock/test/gmock-actions_test.cc
View file @
85f059f0
...
...
@@ -54,12 +54,14 @@
namespace
{
// This list should be kept sorted.
using
testing
::
_
;
using
testing
::
Action
;
using
testing
::
ActionInterface
;
using
testing
::
Assign
;
using
testing
::
ByMove
;
using
testing
::
ByRef
;
using
testing
::
DefaultValue
;
using
testing
::
DoAll
;
using
testing
::
DoDefault
;
using
testing
::
IgnoreResult
;
using
testing
::
Invoke
;
...
...
@@ -75,7 +77,6 @@ using testing::SetArgPointee;
using
testing
::
SetArgumentPointee
;
using
testing
::
Unused
;
using
testing
::
WithArgs
;
using
testing
::
_
;
using
testing
::
internal
::
BuiltInDefaultValue
;
using
testing
::
internal
::
Int64
;
using
testing
::
internal
::
UInt64
;
...
...
@@ -104,10 +105,6 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
EXPECT_EQ
(
0U
,
BuiltInDefaultValue
<
unsigned
char
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
char
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
char
>::
Get
());
#if GMOCK_HAS_SIGNED_WCHAR_T_
EXPECT_EQ
(
0U
,
BuiltInDefaultValue
<
unsigned
wchar_t
>::
Get
());
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
signed
wchar_t
>::
Get
());
#endif
#if GMOCK_WCHAR_T_IS_NATIVE_
#if !defined(__WCHAR_UNSIGNED__)
EXPECT_EQ
(
0
,
BuiltInDefaultValue
<
wchar_t
>::
Get
());
...
...
@@ -136,10 +133,6 @@ TEST(BuiltInDefaultValueTest, ExistsForNumericTypes) {
EXPECT_TRUE
(
BuiltInDefaultValue
<
unsigned
char
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
signed
char
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
char
>::
Exists
());
#if GMOCK_HAS_SIGNED_WCHAR_T_
EXPECT_TRUE
(
BuiltInDefaultValue
<
unsigned
wchar_t
>::
Exists
());
EXPECT_TRUE
(
BuiltInDefaultValue
<
signed
wchar_t
>::
Exists
());
#endif
#if GMOCK_WCHAR_T_IS_NATIVE_
EXPECT_TRUE
(
BuiltInDefaultValue
<
wchar_t
>::
Exists
());
#endif
...
...
@@ -171,20 +164,12 @@ TEST(BuiltInDefaultValueTest, BoolExists) {
// Tests that BuiltInDefaultValue<T>::Get() returns "" when T is a
// string type.
TEST
(
BuiltInDefaultValueTest
,
IsEmptyStringForString
)
{
#if GTEST_HAS_GLOBAL_STRING
EXPECT_EQ
(
""
,
BuiltInDefaultValue
<
::
string
>::
Get
());
#endif // GTEST_HAS_GLOBAL_STRING
EXPECT_EQ
(
""
,
BuiltInDefaultValue
<
::
std
::
string
>::
Get
());
}
// Tests that BuiltInDefaultValue<T>::Exists() returns true when T is a
// string type.
TEST
(
BuiltInDefaultValueTest
,
ExistsForString
)
{
#if GTEST_HAS_GLOBAL_STRING
EXPECT_TRUE
(
BuiltInDefaultValue
<
::
string
>::
Exists
());
#endif // GTEST_HAS_GLOBAL_STRING
EXPECT_TRUE
(
BuiltInDefaultValue
<
::
std
::
string
>::
Exists
());
}
...
...
@@ -220,7 +205,6 @@ class MyNonDefaultConstructible {
int
value_
;
};
#if GTEST_LANG_CXX11
TEST
(
BuiltInDefaultValueTest
,
ExistsForDefaultConstructibleType
)
{
EXPECT_TRUE
(
BuiltInDefaultValue
<
MyDefaultConstructible
>::
Exists
());
...
...
@@ -230,7 +214,6 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) {
EXPECT_EQ
(
42
,
BuiltInDefaultValue
<
MyDefaultConstructible
>::
Get
().
value
());
}
#endif // GTEST_LANG_CXX11
TEST
(
BuiltInDefaultValueTest
,
DoesNotExistForNonDefaultConstructibleType
)
{
EXPECT_FALSE
(
BuiltInDefaultValue
<
MyNonDefaultConstructible
>::
Exists
());
...
...
@@ -300,7 +283,6 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
},
""
);
}
#if GTEST_HAS_STD_UNIQUE_PTR_
TEST
(
DefaultValueTest
,
GetWorksForMoveOnlyIfSet
)
{
EXPECT_TRUE
(
DefaultValue
<
std
::
unique_ptr
<
int
>>::
Exists
());
EXPECT_TRUE
(
DefaultValue
<
std
::
unique_ptr
<
int
>>::
Get
()
==
nullptr
);
...
...
@@ -311,7 +293,6 @@ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
std
::
unique_ptr
<
int
>
i
=
DefaultValue
<
std
::
unique_ptr
<
int
>>::
Get
();
EXPECT_EQ
(
42
,
*
i
);
}
#endif // GTEST_HAS_STD_UNIQUE_PTR_
// Tests that DefaultValue<void>::Get() returns void.
TEST
(
DefaultValueTest
,
GetWorksForVoid
)
{
...
...
@@ -448,19 +429,12 @@ class IsNotZero : public ActionInterface<bool(int)> { // NOLINT
}
};
#if !GTEST_OS_SYMBIAN
// Compiling this test on Nokia's Symbian compiler fails with:
// 'Result' is not a member of class 'testing::internal::Function<int>'
// (point of instantiation: '@unnamed@gmock_actions_test_cc@::
// ActionTest_CanBeConvertedToOtherActionType_Test::TestBody()')
// with no obvious fix.
TEST
(
ActionTest
,
CanBeConvertedToOtherActionType
)
{
const
Action
<
bool
(
int
)
>
a1
(
new
IsNotZero
);
// NOLINT
const
Action
<
int
(
char
)
>
a2
=
Action
<
int
(
char
)
>
(
a1
);
// NOLINT
EXPECT_EQ
(
1
,
a2
.
Perform
(
std
::
make_tuple
(
'a'
)));
EXPECT_EQ
(
0
,
a2
.
Perform
(
std
::
make_tuple
(
'\0'
)));
}
#endif // !GTEST_OS_SYMBIAN
// The following two classes are for testing MakePolymorphicAction().
...
...
@@ -643,7 +617,6 @@ TEST(ReturnNullTest, WorksInPointerReturningFunction) {
EXPECT_TRUE
(
a2
.
Perform
(
std
::
make_tuple
(
true
))
==
nullptr
);
}
#if GTEST_HAS_STD_UNIQUE_PTR_
// Tests that ReturnNull() returns NULL for shared_ptr and unique_ptr returning
// functions.
TEST
(
ReturnNullTest
,
WorksInSmartPointerReturningFunction
)
{
...
...
@@ -653,7 +626,6 @@ TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) {
const
Action
<
std
::
shared_ptr
<
int
>
(
std
::
string
)
>
a2
=
ReturnNull
();
EXPECT_TRUE
(
a2
.
Perform
(
std
::
make_tuple
(
"foo"
))
==
nullptr
);
}
#endif // GTEST_HAS_STD_UNIQUE_PTR_
// Tests that ReturnRef(v) works for reference types.
TEST
(
ReturnRefTest
,
WorksForReference
)
{
...
...
@@ -706,14 +678,12 @@ class MockClass {
MOCK_METHOD1
(
IntFunc
,
int
(
bool
flag
));
// NOLINT
MOCK_METHOD0
(
Foo
,
MyNonDefaultConstructible
());
#if GTEST_HAS_STD_UNIQUE_PTR_
MOCK_METHOD0
(
MakeUnique
,
std
::
unique_ptr
<
int
>
());
MOCK_METHOD0
(
MakeUniqueBase
,
std
::
unique_ptr
<
Base
>
());
MOCK_METHOD0
(
MakeVectorUnique
,
std
::
vector
<
std
::
unique_ptr
<
int
>>
());
MOCK_METHOD1
(
TakeUnique
,
int
(
std
::
unique_ptr
<
int
>
));
MOCK_METHOD2
(
TakeUnique
,
int
(
const
std
::
unique_ptr
<
int
>&
,
std
::
unique_ptr
<
int
>
));
#endif
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockClass
);
...
...
@@ -813,9 +783,7 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) {
EXPECT_EQ
(
'a'
,
ch
);
}
#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
// Tests that SetArgPointee<N>() accepts a string literal.
// GCC prior to v4.0 and the Symbian compiler do not support this.
TEST
(
SetArgPointeeTest
,
AcceptsStringLiteral
)
{
typedef
void
MyFunction
(
std
::
string
*
,
const
char
**
);
Action
<
MyFunction
>
a
=
SetArgPointee
<
0
>
(
"hi"
);
...
...
@@ -849,7 +817,6 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
# endif
}
#endif
// Tests that SetArgPointee<N>() accepts a char pointer.
TEST
(
SetArgPointeeTest
,
AcceptsCharPointer
)
{
...
...
@@ -1182,13 +1149,12 @@ TEST_F(SetErrnoAndReturnTest, CompatibleTypes) {
// Tests ByRef().
// Tests that
ReferenceWrapper<T>
is copyable.
// Tests that
the result of ByRef()
is copyable.
TEST
(
ByRefTest
,
IsCopyable
)
{
const
std
::
string
s1
=
"Hi"
;
const
std
::
string
s2
=
"Hello"
;
::
testing
::
internal
::
ReferenceWrapper
<
const
std
::
string
>
ref_wrapper
=
ByRef
(
s1
);
auto
ref_wrapper
=
ByRef
(
s1
);
const
std
::
string
&
r1
=
ref_wrapper
;
EXPECT_EQ
(
&
s1
,
&
r1
);
...
...
@@ -1197,8 +1163,7 @@ TEST(ByRefTest, IsCopyable) {
const
std
::
string
&
r2
=
ref_wrapper
;
EXPECT_EQ
(
&
s2
,
&
r2
);
::
testing
::
internal
::
ReferenceWrapper
<
const
std
::
string
>
ref_wrapper1
=
ByRef
(
s1
);
auto
ref_wrapper1
=
ByRef
(
s1
);
// Copies ref_wrapper1 to ref_wrapper.
ref_wrapper
=
ref_wrapper1
;
const
std
::
string
&
r3
=
ref_wrapper
;
...
...
@@ -1265,7 +1230,6 @@ TEST(ByRefTest, PrintsCorrectly) {
EXPECT_EQ
(
expected
.
str
(),
actual
.
str
());
}
#if GTEST_HAS_STD_UNIQUE_PTR_
std
::
unique_ptr
<
int
>
UniquePtrSource
()
{
return
std
::
unique_ptr
<
int
>
(
new
int
(
19
));
...
...
@@ -1378,9 +1342,7 @@ TEST(MockMethodTest, CanTakeMoveOnlyValue) {
EXPECT_EQ
(
42
,
*
saved
);
}
#endif // GTEST_HAS_STD_UNIQUE_PTR_
#if GTEST_LANG_CXX11
// Tests for std::function based action.
int
Add
(
int
val
,
int
&
ref
,
int
*
ptr
)
{
// NOLINT
...
...
@@ -1459,10 +1421,6 @@ TEST(FunctorActionTest, UnusedArguments) {
}
// 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
)));
...
...
@@ -1476,7 +1434,6 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) {
EXPECT_EQ
(
x
,
3
);
}
#endif // GTEST_LANG_CXX11
}
// Unnamed namespace
...
...
googlemock/test/gmock-cardinalities_test.cc
View file @
85f059f0
...
...
@@ -395,12 +395,12 @@ TEST(ExactlyTest, HasCorrectBounds) {
class
EvenCardinality
:
public
CardinalityInterface
{
public:
// Returns true if
f
call_count calls will satisfy this cardinality.
// Returns true if call_count calls will satisfy this cardinality.
bool
IsSatisfiedByCallCount
(
int
call_count
)
const
override
{
return
(
call_count
%
2
==
0
);
}
// Returns true if
f
call_count calls will saturate this cardinality.
// Returns true if call_count calls will saturate this cardinality.
bool
IsSaturatedByCallCount
(
int
/* call_count */
)
const
override
{
return
false
;
}
...
...
googlemock/test/gmock-function-mocker_test.cc
View file @
85f059f0
...
...
@@ -45,13 +45,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
// There is a bug in MSVC (fixed in VS 2008) that prevents creating a
// mock for a function with const arguments, so we don't test such
// cases for MSVC versions older than 2008.
#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
#endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
namespace
testing
{
namespace
gmock_function_mocker_test
{
...
...
@@ -69,6 +62,15 @@ using testing::Return;
using
testing
::
ReturnRef
;
using
testing
::
TypedEq
;
template
<
typename
T
>
class
TemplatedCopyable
{
public:
TemplatedCopyable
()
{}
template
<
typename
U
>
TemplatedCopyable
(
const
U
&
other
)
{}
// NOLINT
};
class
FooInterface
{
public:
virtual
~
FooInterface
()
{}
...
...
@@ -84,9 +86,7 @@ class FooInterface {
virtual
bool
TakesNonConstReference
(
int
&
n
)
=
0
;
// NOLINT
virtual
std
::
string
TakesConstReference
(
const
int
&
n
)
=
0
;
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual
bool
TakesConst
(
const
int
x
)
=
0
;
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
virtual
int
OverloadedOnArgumentNumber
()
=
0
;
virtual
int
OverloadedOnArgumentNumber
(
int
n
)
=
0
;
...
...
@@ -99,6 +99,7 @@ class FooInterface {
virtual
int
TypeWithHole
(
int
(
*
func
)())
=
0
;
virtual
int
TypeWithComma
(
const
std
::
map
<
int
,
std
::
string
>&
a_map
)
=
0
;
virtual
int
TypeWithTemplatedCopyCtor
(
const
TemplatedCopyable
<
int
>&
)
=
0
;
#if GTEST_OS_WINDOWS
STDMETHOD_
(
int
,
CTNullary
)()
=
0
;
...
...
@@ -137,10 +138,7 @@ class MockFoo : public FooInterface {
MOCK_METHOD
(
bool
,
TakesNonConstReference
,
(
int
&
));
// NOLINT
MOCK_METHOD
(
std
::
string
,
TakesConstReference
,
(
const
int
&
));
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
MOCK_METHOD
(
bool
,
TakesConst
,
(
const
int
));
// NOLINT
#endif
// Tests that the function return type can contain unprotected comma.
MOCK_METHOD
((
std
::
map
<
int
,
std
::
string
>
),
ReturnTypeWithComma
,
(),
());
...
...
@@ -158,6 +156,8 @@ class MockFoo : public FooInterface {
MOCK_METHOD
(
int
,
TypeWithHole
,
(
int
(
*
)()),
());
// NOLINT
MOCK_METHOD
(
int
,
TypeWithComma
,
((
const
std
::
map
<
int
,
std
::
string
>&
)));
MOCK_METHOD
(
int
,
TypeWithTemplatedCopyCtor
,
(
const
TemplatedCopyable
<
int
>&
));
// NOLINT
#if GTEST_OS_WINDOWS
MOCK_METHOD
(
int
,
CTNullary
,
(),
(
Calltype
(
STDMETHODCALLTYPE
)));
...
...
@@ -248,7 +248,6 @@ TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
EXPECT_EQ
(
"Hello"
,
foo_
->
TakesConstReference
(
a
));
}
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
// Tests mocking a function that takes a const variable.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksFunctionWithConstArgument
)
{
EXPECT_CALL
(
mock_foo_
,
TakesConst
(
Lt
(
10
)))
...
...
@@ -256,7 +255,6 @@ TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstArgument) {
EXPECT_FALSE
(
foo_
->
TakesConst
(
5
));
}
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
// Tests mocking functions overloaded on the number of arguments.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksFunctionsOverloadedOnArgumentNumber
)
{
...
...
@@ -302,6 +300,11 @@ TEST_F(MockMethodFunctionMockerTest, MocksReturnTypeWithComma) {
EXPECT_EQ
(
a_map
,
mock_foo_
.
ReturnTypeWithComma
(
42
));
}
TEST_F
(
MockMethodFunctionMockerTest
,
MocksTypeWithTemplatedCopyCtor
)
{
EXPECT_CALL
(
mock_foo_
,
TypeWithTemplatedCopyCtor
(
_
)).
WillOnce
(
Return
(
true
));
EXPECT_TRUE
(
foo_
->
TypeWithTemplatedCopyCtor
(
TemplatedCopyable
<
int
>
()));
}
#if GTEST_OS_WINDOWS
// Tests mocking a nullary function with calltype.
TEST_F
(
MockMethodFunctionMockerTest
,
MocksNullaryFunctionWithCallType
)
{
...
...
@@ -533,7 +536,7 @@ TEST(MockMethodOverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
#define MY_MOCK_METHODS2_ \
MOCK_CONST_METHOD1(Overloaded, int(int n)); \
MOCK_METHOD1(Overloaded, int(int n))
;
MOCK_METHOD1(Overloaded, int(int n))
class
MockOverloadedOnConstness
{
public:
...
...
@@ -598,7 +601,6 @@ TEST(MockMethodMockFunctionTest, WorksFor10Arguments) {
EXPECT_EQ
(
2
,
foo
.
Call
(
true
,
'a'
,
0
,
0
,
0
,
0
,
0
,
'b'
,
1
,
false
));
}
#if GTEST_HAS_STD_FUNCTION_
TEST
(
MockMethodMockFunctionTest
,
AsStdFunction
)
{
MockFunction
<
int
(
int
)
>
foo
;
auto
call
=
[](
const
std
::
function
<
int
(
int
)
>
&
f
,
int
i
)
{
...
...
@@ -630,7 +632,6 @@ TEST(MockMethodMockFunctionTest, AsStdFunctionWithReferenceParameter) {
EXPECT_EQ
(
-
1
,
call
(
foo
.
AsStdFunction
(),
i
));
}
#endif // GTEST_HAS_STD_FUNCTION_
struct
MockMethodSizes0
{
MOCK_METHOD
(
void
,
func
,
());
...
...
googlemock/test/gmock-generated-actions_test.cc
View file @
85f059f0
...
...
@@ -428,11 +428,12 @@ TEST(DoAllTest, TenActions) {
// the macro definition, as the warnings are generated when the macro
// is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here.
// Also suppress C4503 decorated name length exceeded, name was truncated
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4100)
# pragma warning(disable:4503)
#endif
// Tests the ACTION*() macro family.
// Tests that ACTION() can define an action that doesn't reference the
...
...
@@ -1058,9 +1059,6 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) {
EXPECT_EQ
(
12345
,
a4
.
Perform
(
std
::
make_tuple
()));
}
#ifdef _MSC_VER
# pragma warning(pop)
#endif
}
// namespace gmock_generated_actions_test
}
// namespace testing
googlemock/test/gmock-generated-function-mockers_test.cc
View file @
85f059f0
...
...
@@ -63,6 +63,15 @@ using testing::Return;
using
testing
::
ReturnRef
;
using
testing
::
TypedEq
;
template
<
typename
T
>
class
TemplatedCopyable
{
public:
TemplatedCopyable
()
{}
template
<
typename
U
>
TemplatedCopyable
(
const
U
&
other
)
{}
// NOLINT
};
class
FooInterface
{
public:
virtual
~
FooInterface
()
{}
...
...
@@ -91,6 +100,8 @@ class FooInterface {
virtual
int
TypeWithHole
(
int
(
*
func
)())
=
0
;
virtual
int
TypeWithComma
(
const
std
::
map
<
int
,
std
::
string
>&
a_map
)
=
0
;
virtual
int
TypeWithTemplatedCopyCtor
(
const
TemplatedCopyable
<
int
>&
a_vector
)
=
0
;
#if GTEST_OS_WINDOWS
STDMETHOD_
(
int
,
CTNullary
)()
=
0
;
...
...
@@ -146,6 +157,8 @@ class MockFoo : public FooInterface {
MOCK_METHOD1
(
TypeWithHole
,
int
(
int
(
*
)()));
// NOLINT
MOCK_METHOD1
(
TypeWithComma
,
int
(
const
std
::
map
<
int
,
std
::
string
>&
));
// NOLINT
MOCK_METHOD1
(
TypeWithTemplatedCopyCtor
,
int
(
const
TemplatedCopyable
<
int
>&
));
// NOLINT
#if GTEST_OS_WINDOWS
MOCK_METHOD0_WITH_CALLTYPE
(
STDMETHODCALLTYPE
,
CTNullary
,
int
());
...
...
@@ -288,6 +301,11 @@ TEST_F(FunctionMockerTest, MocksReturnTypeWithComma) {
EXPECT_EQ
(
a_map
,
mock_foo_
.
ReturnTypeWithComma
(
42
));
}
TEST_F
(
FunctionMockerTest
,
MocksTypeWithTemplatedCopyCtor
)
{
EXPECT_CALL
(
mock_foo_
,
TypeWithTemplatedCopyCtor
(
_
)).
WillOnce
(
Return
(
true
));
EXPECT_TRUE
(
foo_
->
TypeWithTemplatedCopyCtor
(
TemplatedCopyable
<
int
>
()));
}
#if GTEST_OS_WINDOWS
// Tests mocking a nullary function with calltype.
TEST_F
(
FunctionMockerTest
,
MocksNullaryFunctionWithCallType
)
{
...
...
@@ -517,7 +535,7 @@ TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
#define MY_MOCK_METHODS2_ \
MOCK_CONST_METHOD1(Overloaded, int(int n)); \
MOCK_METHOD1(Overloaded, int(int n))
;
MOCK_METHOD1(Overloaded, int(int n))
class
MockOverloadedOnConstness
{
public:
...
...
@@ -582,7 +600,6 @@ TEST(MockFunctionTest, WorksFor10Arguments) {
EXPECT_EQ
(
2
,
foo
.
Call
(
true
,
'a'
,
0
,
0
,
0
,
0
,
0
,
'b'
,
1
,
false
));
}
#if GTEST_HAS_STD_FUNCTION_
TEST
(
MockFunctionTest
,
AsStdFunction
)
{
MockFunction
<
int
(
int
)
>
foo
;
auto
call
=
[](
const
std
::
function
<
int
(
int
)
>
&
f
,
int
i
)
{
...
...
@@ -614,7 +631,6 @@ TEST(MockFunctionTest, AsStdFunctionWithReferenceParameter) {
EXPECT_EQ
(
-
1
,
call
(
foo
.
AsStdFunction
(),
i
));
}
#endif // GTEST_HAS_STD_FUNCTION_
struct
MockMethodSizes0
{
MOCK_METHOD0
(
func
,
void
());
...
...
googlemock/test/gmock-generated-internal-utils_test.cc
deleted
100644 → 0
View file @
130e5aa8
// Copyright 2007, 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.
// Google Mock - a framework for writing C++ mock classes.
//
// This file tests the internal utilities.
#include "gmock/internal/gmock-generated-internal-utils.h"
#include "gmock/internal/gmock-internal-utils.h"
#include "gtest/gtest.h"
namespace
{
using
::
testing
::
Matcher
;
using
::
testing
::
internal
::
CompileAssertTypesEqual
;
using
::
testing
::
internal
::
MatcherTuple
;
using
::
testing
::
internal
::
Function
;
using
::
testing
::
internal
::
IgnoredValue
;
// Tests the MatcherTuple template struct.
TEST
(
MatcherTupleTest
,
ForSize0
)
{
CompileAssertTypesEqual
<
std
::
tuple
<>
,
MatcherTuple
<
std
::
tuple
<>
>::
type
>
();
}
TEST
(
MatcherTupleTest
,
ForSize1
)
{
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
int
>
>
,
MatcherTuple
<
std
::
tuple
<
int
>
>::
type
>
();
}
TEST
(
MatcherTupleTest
,
ForSize2
)
{
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
>
,
MatcherTuple
<
std
::
tuple
<
int
,
char
>
>::
type
>
();
}
TEST
(
MatcherTupleTest
,
ForSize5
)
{
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
int
>
,
Matcher
<
char
>
,
Matcher
<
bool
>
,
Matcher
<
double
>
,
Matcher
<
char
*>
>
,
MatcherTuple
<
std
::
tuple
<
int
,
char
,
bool
,
double
,
char
*>
>::
type
>
();
}
// Tests the Function template struct.
TEST
(
FunctionTest
,
Nullary
)
{
typedef
Function
<
int
()
>
F
;
// NOLINT
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(),
F
::
MakeResultVoid
>
();
CompileAssertTypesEqual
<
IgnoredValue
(),
F
::
MakeResultIgnoredValue
>
();
}
TEST
(
FunctionTest
,
Unary
)
{
typedef
Function
<
int
(
bool
)
>
F
;
// NOLINT
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Argument1
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
bool
>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
),
F
::
MakeResultVoid
>
();
// NOLINT
CompileAssertTypesEqual
<
IgnoredValue
(
bool
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
}
TEST
(
FunctionTest
,
Binary
)
{
typedef
Function
<
int
(
bool
,
const
long
&
)
>
F
;
// NOLINT
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Argument1
>
();
CompileAssertTypesEqual
<
const
long
&
,
F
::
Argument2
>
();
// NOLINT
CompileAssertTypesEqual
<
std
::
tuple
<
bool
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
const
long
&
),
F
::
MakeResultVoid
>
();
// NOLINT
CompileAssertTypesEqual
<
IgnoredValue
(
bool
,
const
long
&
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
}
TEST
(
FunctionTest
,
LongArgumentList
)
{
typedef
Function
<
char
(
bool
,
int
,
char
*
,
int
&
,
const
long
&
)
>
F
;
// NOLINT
CompileAssertTypesEqual
<
char
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Argument1
>
();
CompileAssertTypesEqual
<
int
,
F
::
Argument2
>
();
CompileAssertTypesEqual
<
char
*
,
F
::
Argument3
>
();
CompileAssertTypesEqual
<
int
&
,
F
::
Argument4
>
();
CompileAssertTypesEqual
<
const
long
&
,
F
::
Argument5
>
();
// NOLINT
CompileAssertTypesEqual
<
std
::
tuple
<
bool
,
int
,
char
*
,
int
&
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
,
Matcher
<
int
>
,
Matcher
<
char
*>
,
Matcher
<
int
&>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
int
,
char
*
,
int
&
,
const
long
&
),
// NOLINT
F
::
MakeResultVoid
>
();
CompileAssertTypesEqual
<
IgnoredValue
(
bool
,
int
,
char
*
,
int
&
,
const
long
&
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
}
}
// Unnamed namespace
googlemock/test/gmock-generated-matchers_test.cc
View file @
85f059f0
...
...
@@ -64,7 +64,9 @@ using std::stringstream;
using
std
::
vector
;
using
testing
::
_
;
using
testing
::
AllOf
;
using
testing
::
AllOfArray
;
using
testing
::
AnyOf
;
using
testing
::
AnyOfArray
;
using
testing
::
Args
;
using
testing
::
Contains
;
using
testing
::
ElementsAre
;
...
...
@@ -489,7 +491,6 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithVector) {
EXPECT_THAT
(
test_vector
,
Not
(
ElementsAreArray
(
expected
)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
ElementsAreArrayTest
,
TakesInitializerList
)
{
const
int
a
[
5
]
=
{
1
,
2
,
3
,
4
,
5
};
...
...
@@ -525,7 +526,6 @@ TEST(ElementsAreArrayTest,
{
Eq
(
1
),
Ne
(
-
2
),
Ge
(
3
),
Le
(
4
),
Eq
(
6
)
})));
}
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
ElementsAreArrayTest
,
CanBeCreatedWithMatcherVector
)
{
const
int
a
[]
=
{
1
,
2
,
3
};
...
...
@@ -1096,6 +1096,146 @@ TEST(ContainsTest, WorksForTwoDimensionalNativeArray) {
EXPECT_THAT
(
a
,
Contains
(
Not
(
Contains
(
5
))));
}
TEST
(
AllOfArrayTest
,
BasicForms
)
{
// Iterator
std
::
vector
<
int
>
v0
{};
std
::
vector
<
int
>
v1
{
1
};
std
::
vector
<
int
>
v2
{
2
,
3
};
std
::
vector
<
int
>
v3
{
4
,
4
,
4
};
EXPECT_THAT
(
0
,
AllOfArray
(
v0
.
begin
(),
v0
.
end
()));
EXPECT_THAT
(
1
,
AllOfArray
(
v1
.
begin
(),
v1
.
end
()));
EXPECT_THAT
(
2
,
Not
(
AllOfArray
(
v1
.
begin
(),
v1
.
end
())));
EXPECT_THAT
(
3
,
Not
(
AllOfArray
(
v2
.
begin
(),
v2
.
end
())));
EXPECT_THAT
(
4
,
AllOfArray
(
v3
.
begin
(),
v3
.
end
()));
// Pointer + size
int
ar
[
6
]
=
{
1
,
2
,
3
,
4
,
4
,
4
};
EXPECT_THAT
(
0
,
AllOfArray
(
ar
,
0
));
EXPECT_THAT
(
1
,
AllOfArray
(
ar
,
1
));
EXPECT_THAT
(
2
,
Not
(
AllOfArray
(
ar
,
1
)));
EXPECT_THAT
(
3
,
Not
(
AllOfArray
(
ar
+
1
,
3
)));
EXPECT_THAT
(
4
,
AllOfArray
(
ar
+
3
,
3
));
// Array
// int ar0[0]; Not usable
int
ar1
[
1
]
=
{
1
};
int
ar2
[
2
]
=
{
2
,
3
};
int
ar3
[
3
]
=
{
4
,
4
,
4
};
// EXPECT_THAT(0, Not(AllOfArray(ar0))); // Cannot work
EXPECT_THAT
(
1
,
AllOfArray
(
ar1
));
EXPECT_THAT
(
2
,
Not
(
AllOfArray
(
ar1
)));
EXPECT_THAT
(
3
,
Not
(
AllOfArray
(
ar2
)));
EXPECT_THAT
(
4
,
AllOfArray
(
ar3
));
// Container
EXPECT_THAT
(
0
,
AllOfArray
(
v0
));
EXPECT_THAT
(
1
,
AllOfArray
(
v1
));
EXPECT_THAT
(
2
,
Not
(
AllOfArray
(
v1
)));
EXPECT_THAT
(
3
,
Not
(
AllOfArray
(
v2
)));
EXPECT_THAT
(
4
,
AllOfArray
(
v3
));
// Initializer
EXPECT_THAT
(
0
,
AllOfArray
<
int
>
({}));
// Requires template arg.
EXPECT_THAT
(
1
,
AllOfArray
({
1
}));
EXPECT_THAT
(
2
,
Not
(
AllOfArray
({
1
})));
EXPECT_THAT
(
3
,
Not
(
AllOfArray
({
2
,
3
})));
EXPECT_THAT
(
4
,
AllOfArray
({
4
,
4
,
4
}));
}
TEST
(
AllOfArrayTest
,
Matchers
)
{
// vector
std
::
vector
<
Matcher
<
int
>>
matchers
{
Ge
(
1
),
Lt
(
2
)};
EXPECT_THAT
(
0
,
Not
(
AllOfArray
(
matchers
)));
EXPECT_THAT
(
1
,
AllOfArray
(
matchers
));
EXPECT_THAT
(
2
,
Not
(
AllOfArray
(
matchers
)));
// initializer_list
EXPECT_THAT
(
0
,
Not
(
AllOfArray
({
Ge
(
0
),
Ge
(
1
)})));
EXPECT_THAT
(
1
,
AllOfArray
({
Ge
(
0
),
Ge
(
1
)}));
}
TEST
(
AnyOfArrayTest
,
BasicForms
)
{
// Iterator
std
::
vector
<
int
>
v0
{};
std
::
vector
<
int
>
v1
{
1
};
std
::
vector
<
int
>
v2
{
2
,
3
};
EXPECT_THAT
(
0
,
Not
(
AnyOfArray
(
v0
.
begin
(),
v0
.
end
())));
EXPECT_THAT
(
1
,
AnyOfArray
(
v1
.
begin
(),
v1
.
end
()));
EXPECT_THAT
(
2
,
Not
(
AnyOfArray
(
v1
.
begin
(),
v1
.
end
())));
EXPECT_THAT
(
3
,
AnyOfArray
(
v2
.
begin
(),
v2
.
end
()));
EXPECT_THAT
(
4
,
Not
(
AnyOfArray
(
v2
.
begin
(),
v2
.
end
())));
// Pointer + size
int
ar
[
3
]
=
{
1
,
2
,
3
};
EXPECT_THAT
(
0
,
Not
(
AnyOfArray
(
ar
,
0
)));
EXPECT_THAT
(
1
,
AnyOfArray
(
ar
,
1
));
EXPECT_THAT
(
2
,
Not
(
AnyOfArray
(
ar
,
1
)));
EXPECT_THAT
(
3
,
AnyOfArray
(
ar
+
1
,
2
));
EXPECT_THAT
(
4
,
Not
(
AnyOfArray
(
ar
+
1
,
2
)));
// Array
// int ar0[0]; Not usable
int
ar1
[
1
]
=
{
1
};
int
ar2
[
2
]
=
{
2
,
3
};
// EXPECT_THAT(0, Not(AnyOfArray(ar0))); // Cannot work
EXPECT_THAT
(
1
,
AnyOfArray
(
ar1
));
EXPECT_THAT
(
2
,
Not
(
AnyOfArray
(
ar1
)));
EXPECT_THAT
(
3
,
AnyOfArray
(
ar2
));
EXPECT_THAT
(
4
,
Not
(
AnyOfArray
(
ar2
)));
// Container
EXPECT_THAT
(
0
,
Not
(
AnyOfArray
(
v0
)));
EXPECT_THAT
(
1
,
AnyOfArray
(
v1
));
EXPECT_THAT
(
2
,
Not
(
AnyOfArray
(
v1
)));
EXPECT_THAT
(
3
,
AnyOfArray
(
v2
));
EXPECT_THAT
(
4
,
Not
(
AnyOfArray
(
v2
)));
// Initializer
EXPECT_THAT
(
0
,
Not
(
AnyOfArray
<
int
>
({})));
// Requires template arg.
EXPECT_THAT
(
1
,
AnyOfArray
({
1
}));
EXPECT_THAT
(
2
,
Not
(
AnyOfArray
({
1
})));
EXPECT_THAT
(
3
,
AnyOfArray
({
2
,
3
}));
EXPECT_THAT
(
4
,
Not
(
AnyOfArray
({
2
,
3
})));
}
TEST
(
AnyOfArrayTest
,
Matchers
)
{
// We negate test AllOfArrayTest.Matchers.
// vector
std
::
vector
<
Matcher
<
int
>>
matchers
{
Lt
(
1
),
Ge
(
2
)};
EXPECT_THAT
(
0
,
AnyOfArray
(
matchers
));
EXPECT_THAT
(
1
,
Not
(
AnyOfArray
(
matchers
)));
EXPECT_THAT
(
2
,
AnyOfArray
(
matchers
));
// initializer_list
EXPECT_THAT
(
0
,
AnyOfArray
({
Lt
(
0
),
Lt
(
1
)}));
EXPECT_THAT
(
1
,
Not
(
AllOfArray
({
Lt
(
0
),
Lt
(
1
)})));
}
TEST
(
AnyOfArrayTest
,
ExplainsMatchResultCorrectly
)
{
// AnyOfArray and AllOfArry use the same underlying template-template,
// thus it is sufficient to test one here.
const
std
::
vector
<
int
>
v0
{};
const
std
::
vector
<
int
>
v1
{
1
};
const
std
::
vector
<
int
>
v2
{
2
,
3
};
const
Matcher
<
int
>
m0
=
AnyOfArray
(
v0
);
const
Matcher
<
int
>
m1
=
AnyOfArray
(
v1
);
const
Matcher
<
int
>
m2
=
AnyOfArray
(
v2
);
EXPECT_EQ
(
""
,
Explain
(
m0
,
0
));
EXPECT_EQ
(
""
,
Explain
(
m1
,
1
));
EXPECT_EQ
(
""
,
Explain
(
m1
,
2
));
EXPECT_EQ
(
""
,
Explain
(
m2
,
3
));
EXPECT_EQ
(
""
,
Explain
(
m2
,
4
));
EXPECT_EQ
(
"()"
,
Describe
(
m0
));
EXPECT_EQ
(
"(is equal to 1)"
,
Describe
(
m1
));
EXPECT_EQ
(
"(is equal to 2) or (is equal to 3)"
,
Describe
(
m2
));
EXPECT_EQ
(
"()"
,
DescribeNegation
(
m0
));
EXPECT_EQ
(
"(isn't equal to 1)"
,
DescribeNegation
(
m1
));
EXPECT_EQ
(
"(isn't equal to 2) and (isn't equal to 3)"
,
DescribeNegation
(
m2
));
// Explain with matchers
const
Matcher
<
int
>
g1
=
AnyOfArray
({
GreaterThan
(
1
)});
const
Matcher
<
int
>
g2
=
AnyOfArray
({
GreaterThan
(
1
),
GreaterThan
(
2
)});
// Explains the first positiv match and all prior negative matches...
EXPECT_EQ
(
"which is 1 less than 1"
,
Explain
(
g1
,
0
));
EXPECT_EQ
(
"which is the same as 1"
,
Explain
(
g1
,
1
));
EXPECT_EQ
(
"which is 1 more than 1"
,
Explain
(
g1
,
2
));
EXPECT_EQ
(
"which is 1 less than 1, and which is 2 less than 2"
,
Explain
(
g2
,
0
));
EXPECT_EQ
(
"which is the same as 1, and which is 1 less than 2"
,
Explain
(
g2
,
1
));
EXPECT_EQ
(
"which is 1 more than 1"
,
// Only the first
Explain
(
g2
,
2
));
}
TEST
(
AllOfTest
,
HugeMatcher
)
{
// Verify that using AllOf with many arguments doesn't cause
// the compiler to exceed template instantiation depth limit.
...
...
@@ -1122,7 +1262,7 @@ namespace adl_test {
MATCHER
(
M
,
""
)
{
return
true
;
}
template
<
typename
T1
,
typename
T2
>
bool
AllOf
(
const
T1
&
t1
,
const
T2
&
t2
)
{
return
true
;
}
bool
AllOf
(
const
T1
&
/*t1*/
,
const
T2
&
/*t2*/
)
{
return
true
;
}
TEST
(
AllOfTest
,
DoesNotCallAllOfUnqualified
)
{
EXPECT_THAT
(
42
,
testing
::
AllOf
(
...
...
@@ -1139,7 +1279,6 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
}
// namespace adl_test
#if GTEST_LANG_CXX11
TEST
(
AllOfTest
,
WorksOnMoveOnlyType
)
{
std
::
unique_ptr
<
int
>
p
(
new
int
(
3
));
...
...
@@ -1177,7 +1316,6 @@ TEST(MatcherPMacroTest, WorksOnMoveOnlyType) {
EXPECT_THAT
(
p
,
Not
(
UniquePointee
(
2
)));
}
#endif // GTEST_LASNG_CXX11
}
// namespace
...
...
googlemock/test/gmock-internal-utils_test.cc
View file @
85f059f0
...
...
@@ -33,16 +33,20 @@
// This file tests the internal utilities.
#include "gmock/internal/gmock-internal-utils.h"
#include <stdlib.h>
#include <map>
#include <memory>
#include <string>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>
#include "gmock/gmock.h"
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
...
...
@@ -57,8 +61,6 @@
# include <sys/types.h> // For ssize_t. NOLINT
#endif
class
ProtocolMessage
;
namespace
proto2
{
class
Message
;
}
// namespace proto2
...
...
@@ -123,13 +125,9 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
}
TEST
(
PointeeOfTest
,
WorksForSmartPointers
)
{
#if GTEST_HAS_STD_UNIQUE_PTR_
CompileAssertTypesEqual
<
int
,
PointeeOf
<
std
::
unique_ptr
<
int
>
>::
type
>
();
#endif // GTEST_HAS_STD_UNIQUE_PTR_
#if GTEST_HAS_STD_SHARED_PTR_
CompileAssertTypesEqual
<
std
::
string
,
PointeeOf
<
std
::
shared_ptr
<
std
::
string
>
>::
type
>
();
#endif // GTEST_HAS_STD_SHARED_PTR_
}
TEST
(
PointeeOfTest
,
WorksForRawPointers
)
{
...
...
@@ -139,21 +137,16 @@ TEST(PointeeOfTest, WorksForRawPointers) {
}
TEST
(
GetRawPointerTest
,
WorksForSmartPointers
)
{
#if GTEST_HAS_STD_UNIQUE_PTR_
const
char
*
const
raw_p1
=
new
const
char
(
'a'
);
// NOLINT
const
std
::
unique_ptr
<
const
char
>
p1
(
raw_p1
);
EXPECT_EQ
(
raw_p1
,
GetRawPointer
(
p1
));
#endif // GTEST_HAS_STD_UNIQUE_PTR_
#if GTEST_HAS_STD_SHARED_PTR_
double
*
const
raw_p2
=
new
double
(
2.5
);
// NOLINT
const
std
::
shared_ptr
<
double
>
p2
(
raw_p2
);
EXPECT_EQ
(
raw_p2
,
GetRawPointer
(
p2
));
#endif // GTEST_HAS_STD_SHARED_PTR_
}
TEST
(
GetRawPointerTest
,
WorksForRawPointers
)
{
int
*
p
=
nullptr
;
// Don't use EXPECT_EQ as no NULL-testing magic on Symbian.
EXPECT_TRUE
(
nullptr
==
GetRawPointer
(
p
));
int
n
=
1
;
EXPECT_EQ
(
&
n
,
GetRawPointer
(
&
n
));
...
...
@@ -515,39 +508,12 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
#endif // GTEST_HAS_STREAM_REDIRECTION
TEST
(
TypeTraitsTest
,
true_type
)
{
EXPECT_TRUE
(
true_type
::
value
);
}
TEST
(
TypeTraitsTest
,
false_type
)
{
EXPECT_FALSE
(
false_type
::
value
);
}
TEST
(
TypeTraitsTest
,
is_reference
)
{
EXPECT_FALSE
(
is_reference
<
int
>::
value
);
EXPECT_FALSE
(
is_reference
<
char
*>::
value
);
EXPECT_TRUE
(
is_reference
<
const
int
&>::
value
);
}
TEST
(
TypeTraitsTest
,
is_pointer
)
{
EXPECT_FALSE
(
is_pointer
<
int
>::
value
);
EXPECT_FALSE
(
is_pointer
<
char
&>::
value
);
EXPECT_TRUE
(
is_pointer
<
const
int
*>::
value
);
}
TEST
(
TypeTraitsTest
,
type_equals
)
{
EXPECT_FALSE
((
type_equals
<
int
,
const
int
>::
value
));
EXPECT_FALSE
((
type_equals
<
int
,
int
&>::
value
));
EXPECT_FALSE
((
type_equals
<
int
,
double
>::
value
));
EXPECT_TRUE
((
type_equals
<
char
,
char
>::
value
));
}
TEST
(
TypeTraitsTest
,
remove_reference
)
{
EXPECT_TRUE
((
type_equals
<
char
,
remove_reference
<
char
&>::
type
>::
value
));
EXPECT_TRUE
(
(
type_equals
<
const
int
,
remove_reference
<
const
int
&>::
type
>::
value
));
EXPECT_TRUE
((
type_equals
<
int
,
remove_reference
<
int
>::
type
>::
value
));
EXPECT_TRUE
((
type_equals
<
double
*
,
remove_reference
<
double
*>::
type
>::
value
));
EXPECT_TRUE
((
std
::
is_same
<
char
,
remove_reference
<
char
&>::
type
>::
value
));
EXPECT_TRUE
(
(
std
::
is_same
<
const
int
,
remove_reference
<
const
int
&>::
type
>::
value
));
EXPECT_TRUE
((
std
::
is_same
<
int
,
remove_reference
<
int
>::
type
>::
value
));
EXPECT_TRUE
((
std
::
is_same
<
double
*
,
remove_reference
<
double
*>::
type
>::
value
));
}
#if GTEST_HAS_STREAM_REDIRECTION
...
...
@@ -573,7 +539,7 @@ void ExpectCallLogger() {
DummyMock
mock
;
EXPECT_CALL
(
mock
,
TestMethod
());
mock
.
TestMethod
();
}
;
}
// Verifies that EXPECT_CALL logs if the --gmock_verbose flag is set to "info".
TEST
(
ExpectCallTest
,
LogsWhenVerbosityIsInfo
)
{
...
...
@@ -596,7 +562,7 @@ TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
void
OnCallLogger
()
{
DummyMock
mock
;
ON_CALL
(
mock
,
TestMethod
());
}
;
}
// Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info".
TEST
(
OnCallTest
,
LogsWhenVerbosityIsInfo
)
{
...
...
@@ -705,6 +671,70 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
EXPECT_EQ
(
0
,
a3
.
begin
()[
0
]);
}
// Tests the Function template struct.
TEST
(
FunctionTest
,
Nullary
)
{
typedef
Function
<
int
()
>
F
;
// NOLINT
EXPECT_EQ
(
0u
,
F
::
ArgumentCount
);
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(),
F
::
MakeResultVoid
>
();
CompileAssertTypesEqual
<
IgnoredValue
(),
F
::
MakeResultIgnoredValue
>
();
}
TEST
(
FunctionTest
,
Unary
)
{
typedef
Function
<
int
(
bool
)
>
F
;
// NOLINT
EXPECT_EQ
(
1u
,
F
::
ArgumentCount
);
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Arg
<
0
>::
type
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
bool
>
,
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
>
,
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
),
F
::
MakeResultVoid
>
();
// NOLINT
CompileAssertTypesEqual
<
IgnoredValue
(
bool
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
}
TEST
(
FunctionTest
,
Binary
)
{
typedef
Function
<
int
(
bool
,
const
long
&
)
>
F
;
// NOLINT
EXPECT_EQ
(
2u
,
F
::
ArgumentCount
);
CompileAssertTypesEqual
<
int
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Arg
<
0
>::
type
>
();
CompileAssertTypesEqual
<
const
long
&
,
F
::
Arg
<
1
>::
type
>
();
// NOLINT
CompileAssertTypesEqual
<
std
::
tuple
<
bool
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
const
long
&
),
F
::
MakeResultVoid
>
();
// NOLINT
CompileAssertTypesEqual
<
IgnoredValue
(
bool
,
const
long
&
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
}
TEST
(
FunctionTest
,
LongArgumentList
)
{
typedef
Function
<
char
(
bool
,
int
,
char
*
,
int
&
,
const
long
&
)
>
F
;
// NOLINT
EXPECT_EQ
(
5u
,
F
::
ArgumentCount
);
CompileAssertTypesEqual
<
char
,
F
::
Result
>
();
CompileAssertTypesEqual
<
bool
,
F
::
Arg
<
0
>::
type
>
();
CompileAssertTypesEqual
<
int
,
F
::
Arg
<
1
>::
type
>
();
CompileAssertTypesEqual
<
char
*
,
F
::
Arg
<
2
>::
type
>
();
CompileAssertTypesEqual
<
int
&
,
F
::
Arg
<
3
>::
type
>
();
CompileAssertTypesEqual
<
const
long
&
,
F
::
Arg
<
4
>::
type
>
();
// NOLINT
CompileAssertTypesEqual
<
std
::
tuple
<
bool
,
int
,
char
*
,
int
&
,
const
long
&>
,
// NOLINT
F
::
ArgumentTuple
>
();
CompileAssertTypesEqual
<
std
::
tuple
<
Matcher
<
bool
>
,
Matcher
<
int
>
,
Matcher
<
char
*>
,
Matcher
<
int
&>
,
Matcher
<
const
long
&>
>
,
// NOLINT
F
::
ArgumentMatcherTuple
>
();
CompileAssertTypesEqual
<
void
(
bool
,
int
,
char
*
,
int
&
,
const
long
&
),
// NOLINT
F
::
MakeResultVoid
>
();
CompileAssertTypesEqual
<
IgnoredValue
(
bool
,
int
,
char
*
,
int
&
,
const
long
&
),
// NOLINT
F
::
MakeResultIgnoredValue
>
();
}
}
// namespace
}
// namespace internal
}
// namespace testing
googlemock/test/gmock-matchers_test.cc
View file @
85f059f0
...
...
@@ -46,6 +46,7 @@
#include <string.h>
#include <time.h>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <iterator>
...
...
@@ -56,22 +57,16 @@
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
#if GTEST_HAS_STD_FORWARD_LIST_
# include <forward_list> // NOLINT
#endif
#if GTEST_LANG_CXX11
# include <type_traits>
#endif
namespace
testing
{
namespace
gmock_matchers_test
{
namespace
{
using
std
::
greater
;
using
std
::
less
;
...
...
@@ -85,65 +80,6 @@ using std::pair;
using
std
::
set
;
using
std
::
stringstream
;
using
std
::
vector
;
using
testing
::
_
;
using
testing
::
A
;
using
testing
::
AllArgs
;
using
testing
::
AllOf
;
using
testing
::
An
;
using
testing
::
AnyOf
;
using
testing
::
ByRef
;
using
testing
::
ContainsRegex
;
using
testing
::
DoubleEq
;
using
testing
::
DoubleNear
;
using
testing
::
EndsWith
;
using
testing
::
Eq
;
using
testing
::
ExplainMatchResult
;
using
testing
::
Field
;
using
testing
::
FloatEq
;
using
testing
::
FloatNear
;
using
testing
::
Ge
;
using
testing
::
Gt
;
using
testing
::
HasSubstr
;
using
testing
::
IsEmpty
;
using
testing
::
IsNull
;
using
testing
::
Key
;
using
testing
::
Le
;
using
testing
::
Lt
;
using
testing
::
MakeMatcher
;
using
testing
::
MakePolymorphicMatcher
;
using
testing
::
Matcher
;
using
testing
::
MatcherCast
;
using
testing
::
MatcherInterface
;
using
testing
::
Matches
;
using
testing
::
MatchesRegex
;
using
testing
::
MatchResultListener
;
using
testing
::
NanSensitiveDoubleEq
;
using
testing
::
NanSensitiveDoubleNear
;
using
testing
::
NanSensitiveFloatEq
;
using
testing
::
NanSensitiveFloatNear
;
using
testing
::
Ne
;
using
testing
::
Not
;
using
testing
::
NotNull
;
using
testing
::
Pair
;
using
testing
::
Pointee
;
using
testing
::
Pointwise
;
using
testing
::
PolymorphicMatcher
;
using
testing
::
Property
;
using
testing
::
Ref
;
using
testing
::
ResultOf
;
using
testing
::
SizeIs
;
using
testing
::
StartsWith
;
using
testing
::
StrCaseEq
;
using
testing
::
StrCaseNe
;
using
testing
::
StrEq
;
using
testing
::
StringMatchResultListener
;
using
testing
::
StrNe
;
using
testing
::
Truly
;
using
testing
::
TypedEq
;
using
testing
::
UnorderedPointwise
;
using
testing
::
Value
;
using
testing
::
WhenSorted
;
using
testing
::
WhenSortedBy
;
using
testing
::
internal
::
DummyMatchResultListener
;
using
testing
::
internal
::
ElementMatcherPair
;
using
testing
::
internal
::
ElementMatcherPairs
;
...
...
@@ -155,9 +91,21 @@ using testing::internal::MatchMatrix;
using
testing
::
internal
::
PredicateFormatterFromMatcher
;
using
testing
::
internal
::
RE
;
using
testing
::
internal
::
StreamMatchResultListener
;
using
testing
::
internal
::
string
;
using
testing
::
internal
::
Strings
;
// Helper for testing container-valued matchers in mock method context. It is
// important to test matchers in this context, since it requires additional type
// deduction beyond what EXPECT_THAT does, thus making it more restrictive.
struct
ContainerHelper
{
MOCK_METHOD1
(
Call
,
void
(
std
::
vector
<
std
::
unique_ptr
<
int
>>
));
};
std
::
vector
<
std
::
unique_ptr
<
int
>>
MakeUniquePtrs
(
const
std
::
vector
<
int
>&
ints
)
{
std
::
vector
<
std
::
unique_ptr
<
int
>>
pointers
;
for
(
int
i
:
ints
)
pointers
.
emplace_back
(
new
int
(
i
));
return
pointers
;
}
// For testing ExplainMatchResultTo().
class
GreaterThanMatcher
:
public
MatcherInterface
<
int
>
{
public:
...
...
@@ -399,58 +347,6 @@ TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) {
EXPECT_FALSE
(
m2
.
Matches
(
"hello"
));
}
#if GTEST_HAS_GLOBAL_STRING
// Tests that a ::string object can be implicitly converted to a
// Matcher<std::string> or Matcher<const std::string&>.
TEST
(
StringMatcherTest
,
CanBeImplicitlyConstructedFromGlobalString
)
{
Matcher
<
std
::
string
>
m1
=
::
string
(
"hi"
);
EXPECT_TRUE
(
m1
.
Matches
(
"hi"
));
EXPECT_FALSE
(
m1
.
Matches
(
"hello"
));
Matcher
<
const
std
::
string
&>
m2
=
::
string
(
"hi"
);
EXPECT_TRUE
(
m2
.
Matches
(
"hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
"hello"
));
}
#endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_GLOBAL_STRING
// Tests that a C-string literal can be implicitly converted to a
// Matcher<::string> or Matcher<const ::string&>.
TEST
(
GlobalStringMatcherTest
,
CanBeImplicitlyConstructedFromCStringLiteral
)
{
Matcher
<
::
string
>
m1
=
"hi"
;
EXPECT_TRUE
(
m1
.
Matches
(
"hi"
));
EXPECT_FALSE
(
m1
.
Matches
(
"hello"
));
Matcher
<
const
::
string
&>
m2
=
"hi"
;
EXPECT_TRUE
(
m2
.
Matches
(
"hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
"hello"
));
}
// Tests that a std::string object can be implicitly converted to a
// Matcher<::string> or Matcher<const ::string&>.
TEST
(
GlobalStringMatcherTest
,
CanBeImplicitlyConstructedFromString
)
{
Matcher
<
::
string
>
m1
=
std
::
string
(
"hi"
);
EXPECT_TRUE
(
m1
.
Matches
(
"hi"
));
EXPECT_FALSE
(
m1
.
Matches
(
"hello"
));
Matcher
<
const
::
string
&>
m2
=
std
::
string
(
"hi"
);
EXPECT_TRUE
(
m2
.
Matches
(
"hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
"hello"
));
}
// Tests that a ::string object can be implicitly converted to a
// Matcher<::string> or Matcher<const ::string&>.
TEST
(
GlobalStringMatcherTest
,
CanBeImplicitlyConstructedFromGlobalString
)
{
Matcher
<
::
string
>
m1
=
::
string
(
"hi"
);
EXPECT_TRUE
(
m1
.
Matches
(
"hi"
));
EXPECT_FALSE
(
m1
.
Matches
(
"hello"
));
Matcher
<
const
::
string
&>
m2
=
::
string
(
"hi"
);
EXPECT_TRUE
(
m2
.
Matches
(
"hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
"hello"
));
}
#endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_ABSL
// Tests that a C-string literal can be implicitly converted to a
// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
...
...
@@ -476,32 +372,32 @@ TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromString) {
EXPECT_FALSE
(
m2
.
Matches
(
"dogs"
));
}
#if GTEST_HAS_GLOBAL_STRING
// Tests that a ::string object can be implicitly converted to a
// Tests that a absl::string_view object can be implicitly converted to a
// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
TEST
(
StringViewMatcherTest
,
CanBeImplicitlyConstructedFrom
Global
String
)
{
Matcher
<
absl
::
string_view
>
m1
=
::
string
(
"cats"
);
TEST
(
StringViewMatcherTest
,
CanBeImplicitlyConstructedFromString
View
)
{
Matcher
<
absl
::
string_view
>
m1
=
absl
::
string
_view
(
"cats"
);
EXPECT_TRUE
(
m1
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m1
.
Matches
(
"dogs"
));
Matcher
<
const
absl
::
string_view
&>
m2
=
::
string
(
"cats"
);
Matcher
<
const
absl
::
string_view
&>
m2
=
absl
::
string
_view
(
"cats"
);
EXPECT_TRUE
(
m2
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m2
.
Matches
(
"dogs"
));
}
#endif // GTEST_HAS_
GLOBAL_STRING
#endif // GTEST_HAS_
ABSL
// Tests that a absl::string_view object can be implicitly converted to a
// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
TEST
(
StringViewMatcherTest
,
CanBeImplicitlyConstructedFromStringView
)
{
Matcher
<
absl
::
string_view
>
m1
=
absl
::
string_view
(
"cats"
);
// Tests that a std::reference_wrapper<std::string> object can be implicitly
// converted to a Matcher<std::string> or Matcher<const std::string&> via Eq().
TEST
(
StringMatcherTest
,
CanBeImplicitlyConstructedFromEqReferenceWrapperString
)
{
std
::
string
value
=
"cats"
;
Matcher
<
std
::
string
>
m1
=
Eq
(
std
::
ref
(
value
));
EXPECT_TRUE
(
m1
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m1
.
Matches
(
"dogs"
));
Matcher
<
const
absl
::
string
_view
&>
m2
=
absl
::
string_view
(
"cats"
);
Matcher
<
const
std
::
string
&>
m2
=
Eq
(
std
::
ref
(
value
)
);
EXPECT_TRUE
(
m2
.
Matches
(
"cats"
));
EXPECT_FALSE
(
m2
.
Matches
(
"dogs"
));
}
#endif // GTEST_HAS_ABSL
// Tests that MakeMatcher() constructs a Matcher<T> from a
// MatcherInterface* without requiring the user to explicitly
...
...
@@ -1019,6 +915,8 @@ class Unprintable {
Unprintable
()
:
c_
(
'a'
)
{}
bool
operator
==
(
const
Unprintable
&
/* rhs */
)
const
{
return
true
;
}
// -Wunused-private-field: dummy accessor for `c_`.
char
dummy_c
()
{
return
c_
;
}
private:
char
c_
;
};
...
...
@@ -1058,7 +956,7 @@ TEST(TypedEqTest, CanDescribeSelf) {
// Tests that TypedEq<T>(v) has type Matcher<T>.
// Type<T>::IsTypeOf(v) compiles if
f
the type of value v is T, where T
// Type<T>::IsTypeOf(v) compiles if the type of value v is T, where T
// is a "bare" type (i.e. not in the form of const U or U&). If v's
// type is not T, the compiler will generate a message about
// "undefined reference".
...
...
@@ -1146,6 +1044,47 @@ TEST(NeTest, CanDescribeSelf) {
EXPECT_EQ
(
"isn't equal to 5"
,
Describe
(
m
));
}
class
MoveOnly
{
public:
explicit
MoveOnly
(
int
i
)
:
i_
(
i
)
{}
MoveOnly
(
const
MoveOnly
&
)
=
delete
;
MoveOnly
(
MoveOnly
&&
)
=
default
;
MoveOnly
&
operator
=
(
const
MoveOnly
&
)
=
delete
;
MoveOnly
&
operator
=
(
MoveOnly
&&
)
=
default
;
bool
operator
==
(
const
MoveOnly
&
other
)
const
{
return
i_
==
other
.
i_
;
}
bool
operator
!=
(
const
MoveOnly
&
other
)
const
{
return
i_
!=
other
.
i_
;
}
bool
operator
<
(
const
MoveOnly
&
other
)
const
{
return
i_
<
other
.
i_
;
}
bool
operator
<=
(
const
MoveOnly
&
other
)
const
{
return
i_
<=
other
.
i_
;
}
bool
operator
>
(
const
MoveOnly
&
other
)
const
{
return
i_
>
other
.
i_
;
}
bool
operator
>=
(
const
MoveOnly
&
other
)
const
{
return
i_
>=
other
.
i_
;
}
private:
int
i_
;
};
struct
MoveHelper
{
MOCK_METHOD1
(
Call
,
void
(
MoveOnly
));
};
TEST
(
ComparisonBaseTest
,
WorksWithMoveOnly
)
{
MoveOnly
m
{
0
};
MoveHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
Eq
(
ByRef
(
m
))));
helper
.
Call
(
MoveOnly
(
0
));
EXPECT_CALL
(
helper
,
Call
(
Ne
(
ByRef
(
m
))));
helper
.
Call
(
MoveOnly
(
1
));
EXPECT_CALL
(
helper
,
Call
(
Le
(
ByRef
(
m
))));
helper
.
Call
(
MoveOnly
(
0
));
EXPECT_CALL
(
helper
,
Call
(
Lt
(
ByRef
(
m
))));
helper
.
Call
(
MoveOnly
(
-
1
));
EXPECT_CALL
(
helper
,
Call
(
Ge
(
ByRef
(
m
))));
helper
.
Call
(
MoveOnly
(
0
));
EXPECT_CALL
(
helper
,
Call
(
Gt
(
ByRef
(
m
))));
helper
.
Call
(
MoveOnly
(
1
));
}
// Tests that IsNull() matches any NULL pointer of any type.
TEST
(
IsNullTest
,
MatchesNullPointer
)
{
Matcher
<
int
*>
m1
=
IsNull
();
...
...
@@ -1159,30 +1098,18 @@ TEST(IsNullTest, MatchesNullPointer) {
EXPECT_TRUE
(
m2
.
Matches
(
p2
));
EXPECT_FALSE
(
m2
.
Matches
(
"hi"
));
#if !GTEST_OS_SYMBIAN
// Nokia's Symbian compiler generates:
// gmock-matchers.h: ambiguous access to overloaded function
// gmock-matchers.h: 'testing::Matcher<void *>::Matcher(void *)'
// gmock-matchers.h: 'testing::Matcher<void *>::Matcher(const testing::
// MatcherInterface<void *> *)'
// gmock-matchers.h: (point of instantiation: 'testing::
// gmock_matchers_test::IsNullTest_MatchesNullPointer_Test::TestBody()')
// gmock-matchers.h: (instantiating: 'testing::PolymorphicMatc
Matcher
<
void
*>
m3
=
IsNull
();
void
*
p3
=
nullptr
;
EXPECT_TRUE
(
m3
.
Matches
(
p3
));
EXPECT_FALSE
(
m3
.
Matches
(
reinterpret_cast
<
void
*>
(
0xbeef
)));
#endif
}
#if GTEST_LANG_CXX11
TEST
(
IsNullTest
,
StdFunction
)
{
const
Matcher
<
std
::
function
<
void
()
>>
m
=
IsNull
();
EXPECT_TRUE
(
m
.
Matches
(
std
::
function
<
void
()
>
()));
EXPECT_FALSE
(
m
.
Matches
([]{}));
}
#endif // GTEST_LANG_CXX11
// Tests that IsNull() describes itself properly.
TEST
(
IsNullTest
,
CanDescribeSelf
)
{
...
...
@@ -1223,14 +1150,12 @@ TEST(NotNullTest, ReferenceToConstLinkedPtr) {
EXPECT_TRUE
(
m
.
Matches
(
non_null_p
));
}
#if GTEST_LANG_CXX11
TEST
(
NotNullTest
,
StdFunction
)
{
const
Matcher
<
std
::
function
<
void
()
>>
m
=
NotNull
();
EXPECT_TRUE
(
m
.
Matches
([]{}));
EXPECT_FALSE
(
m
.
Matches
(
std
::
function
<
void
()
>
()));
}
#endif // GTEST_LANG_CXX11
// Tests that NotNull() describes itself properly.
TEST
(
NotNullTest
,
CanDescribeSelf
)
{
...
...
@@ -1513,18 +1438,22 @@ TEST(KeyTest, MatchesCorrectly) {
EXPECT_THAT
(
p
,
Not
(
Key
(
Lt
(
25
))));
}
#if GTEST_LANG_CXX11
TEST
(
KeyTest
,
WorksWithMoveOnly
)
{
pair
<
std
::
unique_ptr
<
int
>
,
std
::
unique_ptr
<
int
>>
p
;
EXPECT_THAT
(
p
,
Key
(
Eq
(
nullptr
)));
}
template
<
size_t
I
>
struct
Tag
{};
struct
PairWithGet
{
int
member_1
;
string
member_2
;
std
::
string
member_2
;
using
first_type
=
int
;
using
second_type
=
string
;
using
second_type
=
std
::
string
;
const
int
&
GetImpl
(
Tag
<
0
>
)
const
{
return
member_1
;
}
const
string
&
GetImpl
(
Tag
<
1
>
)
const
{
return
member_2
;
}
const
std
::
string
&
GetImpl
(
Tag
<
1
>
)
const
{
return
member_2
;
}
};
template
<
size_t
I
>
auto
get
(
const
PairWithGet
&
value
)
->
decltype
(
value
.
GetImpl
(
Tag
<
I
>
()))
{
...
...
@@ -1540,7 +1469,6 @@ TEST(PairTest, MatchesPairWithGetCorrectly) {
std
::
vector
<
PairWithGet
>
v
=
{{
11
,
"Foo"
},
{
29
,
"gMockIsBestMock"
}};
EXPECT_THAT
(
v
,
Contains
(
Key
(
29
)));
}
#endif // GTEST_LANG_CXX11
TEST
(
KeyTest
,
SafelyCastsInnerMatcher
)
{
Matcher
<
int
>
is_positive
=
Gt
(
0
);
...
...
@@ -1658,6 +1586,12 @@ TEST(PairTest, MatchesCorrectly) {
EXPECT_THAT
(
p
,
Not
(
Pair
(
Lt
(
13
),
HasSubstr
(
"a"
))));
}
TEST
(
PairTest
,
WorksWithMoveOnly
)
{
pair
<
std
::
unique_ptr
<
int
>
,
std
::
unique_ptr
<
int
>>
p
;
p
.
second
.
reset
(
new
int
(
7
));
EXPECT_THAT
(
p
,
Pair
(
Eq
(
nullptr
),
Ne
(
nullptr
)));
}
TEST
(
PairTest
,
SafelyCastsInnerMatchers
)
{
Matcher
<
int
>
is_positive
=
Gt
(
0
);
Matcher
<
int
>
is_negative
=
Lt
(
0
);
...
...
@@ -1679,7 +1613,12 @@ TEST(PairTest, InsideContainsUsingMap) {
EXPECT_THAT
(
container
,
Not
(
Contains
(
Pair
(
3
,
_
))));
}
#if GTEST_LANG_CXX11
TEST
(
ContainsTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
Contains
(
Pointee
(
2
))));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
}
TEST
(
PairTest
,
UseGetInsteadOfMembers
)
{
PairWithGet
pair
{
7
,
"ABC"
};
EXPECT_THAT
(
pair
,
Pair
(
7
,
"ABC"
));
...
...
@@ -1687,9 +1626,9 @@ TEST(PairTest, UseGetInsteadOfMembers) {
EXPECT_THAT
(
pair
,
Not
(
Pair
(
Lt
(
7
),
"ABC"
)));
std
::
vector
<
PairWithGet
>
v
=
{{
11
,
"Foo"
},
{
29
,
"gMockIsBestMock"
}};
EXPECT_THAT
(
v
,
ElementsAre
(
Pair
(
11
,
string
(
"Foo"
)),
Pair
(
Ge
(
10
),
Not
(
""
))));
EXPECT_THAT
(
v
,
ElementsAre
(
Pair
(
11
,
std
::
string
(
"Foo"
)),
Pair
(
Ge
(
10
),
Not
(
""
))));
}
#endif // GTEST_LANG_CXX11
// Tests StartsWith(s).
...
...
@@ -1734,15 +1673,6 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) {
EXPECT_FALSE
(
m2
.
Matches
(
"i"
));
EXPECT_FALSE
(
m2
.
Matches
(
"Hi "
));
#if GTEST_HAS_GLOBAL_STRING
const
Matcher
<
const
::
string
&>
m3
=
EndsWith
(
::
string
(
"Hi"
));
EXPECT_TRUE
(
m3
.
Matches
(
"Hi"
));
EXPECT_TRUE
(
m3
.
Matches
(
"Wow Hi Hi"
));
EXPECT_TRUE
(
m3
.
Matches
(
"Super Hi"
));
EXPECT_FALSE
(
m3
.
Matches
(
"i"
));
EXPECT_FALSE
(
m3
.
Matches
(
"Hi "
));
#endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_ABSL
const
Matcher
<
const
absl
::
string_view
&>
m4
=
EndsWith
(
""
);
EXPECT_TRUE
(
m4
.
Matches
(
"Hi"
));
...
...
@@ -2025,197 +1955,6 @@ TEST(StdWideEndsWithTest, CanDescribeSelf) {
#endif // GTEST_HAS_STD_WSTRING
#if GTEST_HAS_GLOBAL_WSTRING
TEST
(
GlobalWideStrEqTest
,
MatchesEqual
)
{
Matcher
<
const
wchar_t
*>
m
=
StrEq
(
::
wstring
(
L"Hello"
));
EXPECT_TRUE
(
m
.
Matches
(
L"Hello"
));
EXPECT_FALSE
(
m
.
Matches
(
L"hello"
));
EXPECT_FALSE
(
m
.
Matches
(
nullptr
));
Matcher
<
const
::
wstring
&>
m2
=
StrEq
(
L"Hello"
);
EXPECT_TRUE
(
m2
.
Matches
(
L"Hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
L"Hi"
));
Matcher
<
const
::
wstring
&>
m3
=
StrEq
(
L"
\xD3\x576\x8D3\xC74D
"
);
EXPECT_TRUE
(
m3
.
Matches
(
L"
\xD3\x576\x8D3\xC74D
"
));
EXPECT_FALSE
(
m3
.
Matches
(
L"
\xD3\x576\x8D3\xC74E
"
));
::
wstring
str
(
L"01204500800"
);
str
[
3
]
=
L'\0'
;
Matcher
<
const
::
wstring
&>
m4
=
StrEq
(
str
);
EXPECT_TRUE
(
m4
.
Matches
(
str
));
str
[
0
]
=
str
[
6
]
=
str
[
7
]
=
str
[
9
]
=
str
[
10
]
=
L'\0'
;
Matcher
<
const
::
wstring
&>
m5
=
StrEq
(
str
);
EXPECT_TRUE
(
m5
.
Matches
(
str
));
}
TEST
(
GlobalWideStrEqTest
,
CanDescribeSelf
)
{
Matcher
<
::
wstring
>
m
=
StrEq
(
L"Hi-
\'\"
?
\\\a\b\f\n\r\t\v
"
);
EXPECT_EQ
(
"is equal to L
\"
Hi-
\'\\\"
?
\\\\\\
a
\\
b
\\
f
\\
n
\\
r
\\
t
\\
v
\"
"
,
Describe
(
m
));
Matcher
<
::
wstring
>
m2
=
StrEq
(
L"
\xD3\x576\x8D3\xC74D
"
);
EXPECT_EQ
(
"is equal to L
\"\\
xD3
\\
x576
\\
x8D3
\\
xC74D
\"
"
,
Describe
(
m2
));
::
wstring
str
(
L"01204500800"
);
str
[
3
]
=
L'\0'
;
Matcher
<
const
::
wstring
&>
m4
=
StrEq
(
str
);
EXPECT_EQ
(
"is equal to L
\"
012
\\
04500800
\"
"
,
Describe
(
m4
));
str
[
0
]
=
str
[
6
]
=
str
[
7
]
=
str
[
9
]
=
str
[
10
]
=
L'\0'
;
Matcher
<
const
::
wstring
&>
m5
=
StrEq
(
str
);
EXPECT_EQ
(
"is equal to L
\"\\
012
\\
045
\\
0
\\
08
\\
0
\\
0
\"
"
,
Describe
(
m5
));
}
TEST
(
GlobalWideStrNeTest
,
MatchesUnequalString
)
{
Matcher
<
const
wchar_t
*>
m
=
StrNe
(
L"Hello"
);
EXPECT_TRUE
(
m
.
Matches
(
L""
));
EXPECT_TRUE
(
m
.
Matches
(
nullptr
));
EXPECT_FALSE
(
m
.
Matches
(
L"Hello"
));
Matcher
<
::
wstring
>
m2
=
StrNe
(
::
wstring
(
L"Hello"
));
EXPECT_TRUE
(
m2
.
Matches
(
L"hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
L"Hello"
));
}
TEST
(
GlobalWideStrNeTest
,
CanDescribeSelf
)
{
Matcher
<
const
wchar_t
*>
m
=
StrNe
(
L"Hi"
);
EXPECT_EQ
(
"isn't equal to L
\"
Hi
\"
"
,
Describe
(
m
));
}
TEST
(
GlobalWideStrCaseEqTest
,
MatchesEqualStringIgnoringCase
)
{
Matcher
<
const
wchar_t
*>
m
=
StrCaseEq
(
::
wstring
(
L"Hello"
));
EXPECT_TRUE
(
m
.
Matches
(
L"Hello"
));
EXPECT_TRUE
(
m
.
Matches
(
L"hello"
));
EXPECT_FALSE
(
m
.
Matches
(
L"Hi"
));
EXPECT_FALSE
(
m
.
Matches
(
nullptr
));
Matcher
<
const
::
wstring
&>
m2
=
StrCaseEq
(
L"Hello"
);
EXPECT_TRUE
(
m2
.
Matches
(
L"hello"
));
EXPECT_FALSE
(
m2
.
Matches
(
L"Hi"
));
}
TEST
(
GlobalWideStrCaseEqTest
,
MatchesEqualStringWith0IgnoringCase
)
{
::
wstring
str1
(
L"oabocdooeoo"
);
::
wstring
str2
(
L"OABOCDOOEOO"
);
Matcher
<
const
::
wstring
&>
m0
=
StrCaseEq
(
str1
);
EXPECT_FALSE
(
m0
.
Matches
(
str2
+
::
wstring
(
1
,
L'\0'
)));
str1
[
3
]
=
str2
[
3
]
=
L'\0'
;
Matcher
<
const
::
wstring
&>
m1
=
StrCaseEq
(
str1
);
EXPECT_TRUE
(
m1
.
Matches
(
str2
));
str1
[
0
]
=
str1
[
6
]
=
str1
[
7
]
=
str1
[
10
]
=
L'\0'
;
str2
[
0
]
=
str2
[
6
]
=
str2
[
7
]
=
str2
[
10
]
=
L'\0'
;
Matcher
<
const
::
wstring
&>
m2
=
StrCaseEq
(
str1
);
str1
[
9
]
=
str2
[
9
]
=
L'\0'
;
EXPECT_FALSE
(
m2
.
Matches
(
str2
));
Matcher
<
const
::
wstring
&>
m3
=
StrCaseEq
(
str1
);
EXPECT_TRUE
(
m3
.
Matches
(
str2
));
EXPECT_FALSE
(
m3
.
Matches
(
str2
+
L"x"
));
str2
.
append
(
1
,
L'\0'
);
EXPECT_FALSE
(
m3
.
Matches
(
str2
));
EXPECT_FALSE
(
m3
.
Matches
(
::
wstring
(
str2
,
0
,
9
)));
}
TEST
(
GlobalWideStrCaseEqTest
,
CanDescribeSelf
)
{
Matcher
<
::
wstring
>
m
=
StrCaseEq
(
L"Hi"
);
EXPECT_EQ
(
"is equal to (ignoring case) L
\"
Hi
\"
"
,
Describe
(
m
));
}
TEST
(
GlobalWideStrCaseNeTest
,
MatchesUnequalStringIgnoringCase
)
{
Matcher
<
const
wchar_t
*>
m
=
StrCaseNe
(
L"Hello"
);
EXPECT_TRUE
(
m
.
Matches
(
L"Hi"
));
EXPECT_TRUE
(
m
.
Matches
(
nullptr
));
EXPECT_FALSE
(
m
.
Matches
(
L"Hello"
));
EXPECT_FALSE
(
m
.
Matches
(
L"hello"
));
Matcher
<
::
wstring
>
m2
=
StrCaseNe
(
::
wstring
(
L"Hello"
));
EXPECT_TRUE
(
m2
.
Matches
(
L""
));
EXPECT_FALSE
(
m2
.
Matches
(
L"Hello"
));
}
TEST
(
GlobalWideStrCaseNeTest
,
CanDescribeSelf
)
{
Matcher
<
const
wchar_t
*>
m
=
StrCaseNe
(
L"Hi"
);
EXPECT_EQ
(
"isn't equal to (ignoring case) L
\"
Hi
\"
"
,
Describe
(
m
));
}
// Tests that HasSubstr() works for matching wstring-typed values.
TEST
(
GlobalWideHasSubstrTest
,
WorksForStringClasses
)
{
const
Matcher
<
::
wstring
>
m1
=
HasSubstr
(
L"foo"
);
EXPECT_TRUE
(
m1
.
Matches
(
::
wstring
(
L"I love food."
)));
EXPECT_FALSE
(
m1
.
Matches
(
::
wstring
(
L"tofo"
)));
const
Matcher
<
const
::
wstring
&>
m2
=
HasSubstr
(
L"foo"
);
EXPECT_TRUE
(
m2
.
Matches
(
::
wstring
(
L"I love food."
)));
EXPECT_FALSE
(
m2
.
Matches
(
::
wstring
(
L"tofo"
)));
}
// Tests that HasSubstr() works for matching C-wide-string-typed values.
TEST
(
GlobalWideHasSubstrTest
,
WorksForCStrings
)
{
const
Matcher
<
wchar_t
*>
m1
=
HasSubstr
(
L"foo"
);
EXPECT_TRUE
(
m1
.
Matches
(
const_cast
<
wchar_t
*>
(
L"I love food."
)));
EXPECT_FALSE
(
m1
.
Matches
(
const_cast
<
wchar_t
*>
(
L"tofo"
)));
EXPECT_FALSE
(
m1
.
Matches
(
nullptr
));
const
Matcher
<
const
wchar_t
*>
m2
=
HasSubstr
(
L"foo"
);
EXPECT_TRUE
(
m2
.
Matches
(
L"I love food."
));
EXPECT_FALSE
(
m2
.
Matches
(
L"tofo"
));
EXPECT_FALSE
(
m2
.
Matches
(
nullptr
));
}
// Tests that HasSubstr(s) describes itself properly.
TEST
(
GlobalWideHasSubstrTest
,
CanDescribeSelf
)
{
Matcher
<
::
wstring
>
m
=
HasSubstr
(
L"foo
\n\"
"
);
EXPECT_EQ
(
"has substring L
\"
foo
\\
n
\\\"\"
"
,
Describe
(
m
));
}
// Tests StartsWith(s).
TEST
(
GlobalWideStartsWithTest
,
MatchesStringWithGivenPrefix
)
{
const
Matcher
<
const
wchar_t
*>
m1
=
StartsWith
(
::
wstring
(
L""
));
EXPECT_TRUE
(
m1
.
Matches
(
L"Hi"
));
EXPECT_TRUE
(
m1
.
Matches
(
L""
));
EXPECT_FALSE
(
m1
.
Matches
(
nullptr
));
const
Matcher
<
const
::
wstring
&>
m2
=
StartsWith
(
L"Hi"
);
EXPECT_TRUE
(
m2
.
Matches
(
L"Hi"
));
EXPECT_TRUE
(
m2
.
Matches
(
L"Hi Hi!"
));
EXPECT_TRUE
(
m2
.
Matches
(
L"High"
));
EXPECT_FALSE
(
m2
.
Matches
(
L"H"
));
EXPECT_FALSE
(
m2
.
Matches
(
L" Hi"
));
}
TEST
(
GlobalWideStartsWithTest
,
CanDescribeSelf
)
{
Matcher
<
const
::
wstring
>
m
=
StartsWith
(
L"Hi"
);
EXPECT_EQ
(
"starts with L
\"
Hi
\"
"
,
Describe
(
m
));
}
// Tests EndsWith(s).
TEST
(
GlobalWideEndsWithTest
,
MatchesStringWithGivenSuffix
)
{
const
Matcher
<
const
wchar_t
*>
m1
=
EndsWith
(
L""
);
EXPECT_TRUE
(
m1
.
Matches
(
L"Hi"
));
EXPECT_TRUE
(
m1
.
Matches
(
L""
));
EXPECT_FALSE
(
m1
.
Matches
(
nullptr
));
const
Matcher
<
const
::
wstring
&>
m2
=
EndsWith
(
::
wstring
(
L"Hi"
));
EXPECT_TRUE
(
m2
.
Matches
(
L"Hi"
));
EXPECT_TRUE
(
m2
.
Matches
(
L"Wow Hi Hi"
));
EXPECT_TRUE
(
m2
.
Matches
(
L"Super Hi"
));
EXPECT_FALSE
(
m2
.
Matches
(
L"i"
));
EXPECT_FALSE
(
m2
.
Matches
(
L"Hi "
));
}
TEST
(
GlobalWideEndsWithTest
,
CanDescribeSelf
)
{
Matcher
<
const
::
wstring
>
m
=
EndsWith
(
L"Hi"
);
EXPECT_EQ
(
"ends with L
\"
Hi
\"
"
,
Describe
(
m
));
}
#endif // GTEST_HAS_GLOBAL_WSTRING
typedef
::
std
::
tuple
<
long
,
int
>
Tuple2
;
// NOLINT
// Tests that Eq() matches a 2-tuple where the first field == the
...
...
@@ -2307,6 +2046,15 @@ TEST(Ne2Test, CanDescribeSelf) {
EXPECT_EQ
(
"are an unequal pair"
,
Describe
(
m
));
}
TEST
(
PairMatchBaseTest
,
WorksWithMoveOnly
)
{
using
Pointers
=
std
::
tuple
<
std
::
unique_ptr
<
int
>
,
std
::
unique_ptr
<
int
>>
;
Matcher
<
Pointers
>
matcher
=
Eq
();
Pointers
pointers
;
// Tested values don't matter; the point is that matcher does not copy the
// matched values.
EXPECT_TRUE
(
matcher
.
Matches
(
pointers
));
}
// Tests that FloatEq() matches a 2-tuple where
// FloatEq(first field) matches the second field.
TEST
(
FloatEq2Test
,
MatchesEqualArguments
)
{
...
...
@@ -2660,7 +2408,6 @@ static void AnyOfMatches(int num, const Matcher<int>& m) {
EXPECT_FALSE
(
m
.
Matches
(
num
+
1
));
}
#if GTEST_LANG_CXX11
static
void
AnyOfStringMatches
(
int
num
,
const
Matcher
<
std
::
string
>&
m
)
{
SCOPED_TRACE
(
Describe
(
m
));
EXPECT_FALSE
(
m
.
Matches
(
std
::
to_string
(
0
)));
...
...
@@ -2670,7 +2417,6 @@ static void AnyOfStringMatches(int num, const Matcher<std::string>& m) {
}
EXPECT_FALSE
(
m
.
Matches
(
std
::
to_string
(
num
+
1
)));
}
#endif
// Tests that AnyOf(m1, ..., mn) matches any value that matches at
// least one of the given matchers.
...
...
@@ -2715,7 +2461,6 @@ TEST(AnyOfTest, MatchesWhenAnyMatches) {
AnyOfMatches
(
10
,
AnyOf
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
));
}
#if GTEST_LANG_CXX11
// Tests the variadic version of the AnyOfMatcher.
TEST
(
AnyOfTest
,
VariadicMatchesWhenAnyMatches
)
{
// Also make sure AnyOf is defined in the right namespace and does not depend
...
...
@@ -2748,7 +2493,7 @@ TEST(ElementsAreTest, HugeMatcher) {
// Tests the variadic version of the UnorderedElementsAreMatcher
TEST
(
ElementsAreTest
,
HugeMatcherStr
)
{
vector
<
string
>
test_vector
{
vector
<
std
::
string
>
test_vector
{
"literal_string"
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
,
""
};
EXPECT_THAT
(
test_vector
,
UnorderedElementsAre
(
"literal_string"
,
_
,
_
,
_
,
_
,
_
,
...
...
@@ -2764,7 +2509,6 @@ TEST(ElementsAreTest, HugeMatcherUnordered) {
Eq
(
3
),
Eq
(
9
),
Eq
(
12
),
Eq
(
11
),
Ne
(
122
)));
}
#endif // GTEST_LANG_CXX11
// Tests that AnyOf(m1, ..., mn) describes itself properly.
TEST
(
AnyOfTest
,
CanDescribeSelf
)
{
...
...
@@ -2896,7 +2640,7 @@ class IsGreaterThan {
// For testing Truly().
const
int
foo
=
0
;
// This predicate returns true if
f
the argument references foo and has
// This predicate returns true if the argument references foo and has
// a zero value.
bool
ReferencesFooAndIsZero
(
const
int
&
n
)
{
return
(
&
n
==
&
foo
)
&&
(
n
==
0
);
...
...
@@ -3166,20 +2910,8 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) {
"Actual: 0"
+
OfType
(
"int"
)
+
", which is located @"
);
}
#if !GTEST_OS_SYMBIAN
// Tests that ASSERT_THAT() and EXPECT_THAT() work when the matcher is
// monomorphic.
// ASSERT_THAT("hello", starts_with_he) fails to compile with Nokia's
// Symbian compiler: it tries to compile
// template<T, U> class MatcherCastImpl { ...
// virtual bool MatchAndExplain(T x, ...) const {
// return source_matcher_.MatchAndExplain(static_cast<U>(x), ...);
// with U == string and T == const char*
// With ASSERT_THAT("hello"...) changed to ASSERT_THAT(string("hello") ... )
// the compiler silently crashes with no output.
// If MatcherCastImpl is changed to use U(x) instead of static_cast<U>(x)
// the code compiles but the converted string is bogus.
TEST
(
MatcherAssertionTest
,
WorksForMonomorphicMatcher
)
{
Matcher
<
const
char
*>
starts_with_he
=
StartsWith
(
"he"
);
ASSERT_THAT
(
"hello"
,
starts_with_he
);
...
...
@@ -3197,7 +2929,6 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) {
"Expected: is > 5
\n
"
" Actual: 5"
+
OfType
(
"int"
));
}
#endif // !GTEST_OS_SYMBIAN
// Tests floating-point matchers.
template
<
typename
RawType
>
...
...
@@ -3863,7 +3594,7 @@ class Uncopyable {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
Uncopyable
);
};
// Returns true if
f
x.value() is positive.
// Returns true if x.value() is positive.
bool
ValueIsPositive
(
const
Uncopyable
&
x
)
{
return
x
.
value
()
>
0
;
}
MATCHER_P
(
UncopyableIs
,
inner_matcher
,
""
)
{
...
...
@@ -4135,9 +3866,7 @@ class AClass {
// A getter that returns a reference to const.
const
std
::
string
&
s
()
const
{
return
s_
;
}
#if GTEST_LANG_CXX11
const
std
::
string
&
s_ref
()
const
&
{
return
s_
;
}
#endif
void
set_s
(
const
std
::
string
&
new_s
)
{
s_
=
new_s
;
}
...
...
@@ -4194,7 +3923,6 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) {
EXPECT_FALSE
(
m_with_name
.
Matches
(
a
));
}
#if GTEST_LANG_CXX11
// Tests that Property(&Foo::property, ...) works when property() is
// ref-qualified.
TEST
(
PropertyTest
,
WorksForRefQualifiedProperty
)
{
...
...
@@ -4211,7 +3939,6 @@ TEST(PropertyTest, WorksForRefQualifiedProperty) {
EXPECT_FALSE
(
m
.
Matches
(
a
));
EXPECT_FALSE
(
m_with_name
.
Matches
(
a
));
}
#endif
// Tests that Property(&Foo::property, ...) works when property()
// returns a reference to non-const.
...
...
@@ -4539,8 +4266,8 @@ TEST(ResultOfTest, WorksForFunctionReferences) {
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// function object.
struct
Functor
:
public
::
std
::
unary_function
<
int
,
std
::
string
>
{
result_type
operator
()(
argument_type
input
)
const
{
struct
Functor
{
std
::
string
operator
()(
int
input
)
const
{
return
IntToStringFunction
(
input
);
}
};
...
...
@@ -4574,7 +4301,6 @@ TEST(ResultOfTest, WorksForPolymorphicFunctors) {
EXPECT_FALSE
(
matcher_string
.
Matches
(
"shrt"
));
}
#if GTEST_LANG_CXX11
TEST
(
ResultOfTest
,
WorksForPolymorphicFunctorsIgnoringResultType
)
{
Matcher
<
int
*>
matcher
=
ResultOf
(
PolymorphicFunctor
(),
"good ptr"
);
...
...
@@ -4584,12 +4310,14 @@ TEST(ResultOfTest, WorksForPolymorphicFunctorsIgnoringResultType) {
}
TEST
(
ResultOfTest
,
WorksForLambdas
)
{
Matcher
<
int
>
matcher
=
ResultOf
([](
int
str_len
)
{
return
std
::
string
(
str_len
,
'x'
);
},
"xxx"
);
Matcher
<
int
>
matcher
=
ResultOf
(
[](
int
str_len
)
{
return
std
::
string
(
static_cast
<
size_t
>
(
str_len
),
'x'
);
},
"xxx"
);
EXPECT_TRUE
(
matcher
.
Matches
(
3
));
EXPECT_FALSE
(
matcher
.
Matches
(
1
));
}
#endif
const
int
*
ReferencingFunction
(
const
int
&
n
)
{
return
&
n
;
}
...
...
@@ -4752,6 +4480,12 @@ TEST(IsEmptyTest, ExplainsResult) {
EXPECT_EQ
(
"whose size is 1"
,
Explain
(
m
,
container
));
}
TEST
(
IsEmptyTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
IsEmpty
()));
helper
.
Call
({});
}
TEST
(
IsTrueTest
,
IsTrueIsFalse
)
{
EXPECT_THAT
(
true
,
IsTrue
());
EXPECT_THAT
(
false
,
IsFalse
());
...
...
@@ -4774,7 +4508,6 @@ TEST(IsTrueTest, IsTrueIsFalse) {
EXPECT_THAT
(
&
a
,
Not
(
IsFalse
()));
EXPECT_THAT
(
false
,
Not
(
IsTrue
()));
EXPECT_THAT
(
true
,
Not
(
IsFalse
()));
#if GTEST_LANG_CXX11
EXPECT_THAT
(
std
::
true_type
(),
IsTrue
());
EXPECT_THAT
(
std
::
true_type
(),
Not
(
IsFalse
()));
EXPECT_THAT
(
std
::
false_type
(),
IsFalse
());
...
...
@@ -4787,7 +4520,6 @@ TEST(IsTrueTest, IsTrueIsFalse) {
EXPECT_THAT
(
null_unique
,
IsFalse
());
EXPECT_THAT
(
nonnull_unique
,
IsTrue
());
EXPECT_THAT
(
nonnull_unique
,
Not
(
IsFalse
()));
#endif // GTEST_LANG_CXX11
}
TEST
(
SizeIsTest
,
ImplementsSizeIs
)
{
...
...
@@ -4822,6 +4554,12 @@ TEST(SizeIsTest, WorksWithReferences) {
EXPECT_THAT
(
container
,
m
);
}
TEST
(
SizeIsTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
SizeIs
(
3
)));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
,
3
}));
}
// SizeIs should work for any type that provides a size() member function.
// For example, a size_type member type should not need to be provided.
struct
MinimalistCustomType
{
...
...
@@ -4873,7 +4611,7 @@ typedef testing::Types<
list
<
int
>
>
ContainerEqTestTypes
;
TYPED_TEST_
CAS
E
(
ContainerEqTest
,
ContainerEqTestTypes
);
TYPED_TEST_
SUIT
E
(
ContainerEqTest
,
ContainerEqTestTypes
);
// Tests that the filled container is equal to itself.
TYPED_TEST
(
ContainerEqTest
,
EqualsSelf
)
{
...
...
@@ -5281,7 +5019,6 @@ TEST(StreamlikeTest, Iteration) {
}
}
#if GTEST_HAS_STD_FORWARD_LIST_
TEST
(
BeginEndDistanceIsTest
,
WorksWithForwardList
)
{
std
::
forward_list
<
int
>
container
;
EXPECT_THAT
(
container
,
BeginEndDistanceIs
(
0
));
...
...
@@ -5293,7 +5030,6 @@ TEST(BeginEndDistanceIsTest, WorksWithForwardList) {
EXPECT_THAT
(
container
,
Not
(
BeginEndDistanceIs
(
0
)));
EXPECT_THAT
(
container
,
BeginEndDistanceIs
(
2
));
}
#endif // GTEST_HAS_STD_FORWARD_LIST_
TEST
(
BeginEndDistanceIsTest
,
WorksWithNonStdList
)
{
const
int
a
[
5
]
=
{
1
,
2
,
3
,
4
,
5
};
...
...
@@ -5308,6 +5044,12 @@ TEST(BeginEndDistanceIsTest, CanDescribeSelf) {
DescribeNegation
(
m
));
}
TEST
(
BeginEndDistanceIsTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
BeginEndDistanceIs
(
2
)));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
}
TEST
(
BeginEndDistanceIsTest
,
ExplainsResult
)
{
Matcher
<
vector
<
int
>
>
m1
=
BeginEndDistanceIs
(
2
);
Matcher
<
vector
<
int
>
>
m2
=
BeginEndDistanceIs
(
Lt
(
2
));
...
...
@@ -5469,13 +5211,19 @@ TEST(IsSupersetOfTest, MatchAndExplain) {
" - element #2 is matched by matcher #0"
));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
IsSupersetOfTest
,
WorksForRhsInitializerList
)
{
const
int
numbers
[]
=
{
1
,
3
,
6
,
2
,
4
,
5
};
EXPECT_THAT
(
numbers
,
IsSupersetOf
({
1
,
2
}));
EXPECT_THAT
(
numbers
,
Not
(
IsSupersetOf
({
3
,
0
})));
}
#endif
TEST
(
IsSupersetOfTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
IsSupersetOf
({
Pointee
(
1
)})));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
EXPECT_CALL
(
helper
,
Call
(
Not
(
IsSupersetOf
({
Pointee
(
1
),
Pointee
(
2
)}))));
helper
.
Call
(
MakeUniquePtrs
({
2
}));
}
TEST
(
IsSubsetOfTest
,
WorksForNativeArray
)
{
const
int
subset
[]
=
{
1
,
4
};
...
...
@@ -5591,13 +5339,19 @@ TEST(IsSubsetOfTest, MatchAndExplain) {
" - element #1 is matched by matcher #2"
));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
IsSubsetOfTest
,
WorksForRhsInitializerList
)
{
const
int
numbers
[]
=
{
1
,
2
,
3
};
EXPECT_THAT
(
numbers
,
IsSubsetOf
({
1
,
2
,
3
,
4
}));
EXPECT_THAT
(
numbers
,
Not
(
IsSubsetOf
({
1
,
2
})));
}
#endif
TEST
(
IsSubsetOfTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
IsSubsetOf
({
Pointee
(
1
),
Pointee
(
2
)})));
helper
.
Call
(
MakeUniquePtrs
({
1
}));
EXPECT_CALL
(
helper
,
Call
(
Not
(
IsSubsetOf
({
Pointee
(
1
)}))));
helper
.
Call
(
MakeUniquePtrs
({
2
}));
}
// Tests using ElementsAre() and ElementsAreArray() with stream-like
// "containers".
...
...
@@ -5632,6 +5386,15 @@ TEST(ElementsAreTest, WorksWithUncopyable) {
EXPECT_THAT
(
objs
,
ElementsAre
(
UncopyableIs
(
-
3
),
Truly
(
ValueIsPositive
)));
}
TEST
(
ElementsAreTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
ElementsAre
(
Pointee
(
1
),
Pointee
(
2
))));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
EXPECT_CALL
(
helper
,
Call
(
ElementsAreArray
({
Pointee
(
3
),
Pointee
(
4
)})));
helper
.
Call
(
MakeUniquePtrs
({
3
,
4
}));
}
TEST
(
ElementsAreTest
,
TakesStlContainer
)
{
const
int
actual
[]
=
{
3
,
1
,
2
};
...
...
@@ -5699,7 +5462,6 @@ TEST(UnorderedElementsAreArrayTest, TakesStlContainer) {
EXPECT_THAT
(
actual
,
Not
(
UnorderedElementsAreArray
(
expected
)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
UnorderedElementsAreArrayTest
,
TakesInitializerList
)
{
const
int
a
[
5
]
=
{
2
,
1
,
4
,
5
,
3
};
...
...
@@ -5733,7 +5495,13 @@ TEST(UnorderedElementsAreArrayTest,
{
Eq
(
1
),
Ne
(
-
2
),
Ge
(
3
),
Le
(
4
),
Eq
(
6
)})));
}
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
UnorderedElementsAreArrayTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
UnorderedElementsAreArray
({
Pointee
(
1
),
Pointee
(
2
)})));
helper
.
Call
(
MakeUniquePtrs
({
2
,
1
}));
}
class
UnorderedElementsAreTest
:
public
testing
::
Test
{
protected:
...
...
@@ -5782,6 +5550,12 @@ TEST_F(UnorderedElementsAreTest, WorksForStreamlike) {
EXPECT_THAT
(
s
,
Not
(
UnorderedElementsAre
(
2
,
2
,
3
,
4
,
5
)));
}
TEST_F
(
UnorderedElementsAreTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
UnorderedElementsAre
(
Pointee
(
1
),
Pointee
(
2
))));
helper
.
Call
(
MakeUniquePtrs
({
2
,
1
}));
}
// One naive implementation of the matcher runs in O(N!) time, which is too
// slow for many real-world inputs. This test shows that our matcher can match
// 100 inputs very quickly (a few milliseconds). An O(100!) is 10^158
...
...
@@ -6041,11 +5815,11 @@ class BacktrackingBPMTest : public ::testing::Test { };
// Tests the MaxBipartiteMatching algorithm with square matrices.
// The single int param is the # of nodes on each of the left and right sides.
class
BipartiteTest
:
public
::
testing
::
TestWithParam
<
in
t
>
{
};
class
BipartiteTest
:
public
::
testing
::
TestWithParam
<
size_
t
>
{};
// Verify all match graphs up to some moderate number of edges.
TEST_P
(
BipartiteTest
,
Exhaustive
)
{
in
t
nodes
=
GetParam
();
size_
t
nodes
=
GetParam
();
MatchMatrix
graph
(
nodes
,
nodes
);
do
{
ElementMatcherPairs
matches
=
...
...
@@ -6069,8 +5843,8 @@ TEST_P(BipartiteTest, Exhaustive) {
}
while
(
graph
.
NextGraph
());
}
INSTANTIATE_TEST_
CAS
E_P
(
AllGraphs
,
BipartiteTest
,
::
testing
::
Range
(
0
,
5
));
INSTANTIATE_TEST_
SUIT
E_P
(
AllGraphs
,
BipartiteTest
,
::
testing
::
Range
(
size_t
{
0
},
size_t
{
5
}
));
// Parameterized by a pair interpreted as (LhsSize, RhsSize).
class
BipartiteNonSquareTest
...
...
@@ -6086,7 +5860,7 @@ TEST_F(BipartiteNonSquareTest, SimpleBacktracking) {
// :.......:
// 0 1 2
MatchMatrix
g
(
4
,
3
);
static
const
in
t
kEdges
[][
2
]
=
{{
0
,
2
},
{
1
,
1
},
{
2
,
1
},
{
3
,
0
}};
static
const
size_
t
kEdges
[][
2
]
=
{{
0
,
2
},
{
1
,
1
},
{
2
,
1
},
{
3
,
0
}};
for
(
size_t
i
=
0
;
i
<
GTEST_ARRAY_SIZE_
(
kEdges
);
++
i
)
{
g
.
SetEdge
(
kEdges
[
i
][
0
],
kEdges
[
i
][
1
],
true
);
}
...
...
@@ -6112,7 +5886,7 @@ TEST_P(BipartiteNonSquareTest, Exhaustive) {
}
while
(
graph
.
NextGraph
());
}
INSTANTIATE_TEST_
CAS
E_P
(
AllGraphs
,
BipartiteNonSquareTest
,
INSTANTIATE_TEST_
SUIT
E_P
(
AllGraphs
,
BipartiteNonSquareTest
,
testing
::
Values
(
std
::
make_pair
(
1
,
2
),
std
::
make_pair
(
2
,
1
),
...
...
@@ -6131,15 +5905,15 @@ class BipartiteRandomTest
TEST_P
(
BipartiteRandomTest
,
LargerNets
)
{
int
nodes
=
GetParam
().
first
;
int
iters
=
GetParam
().
second
;
MatchMatrix
graph
(
nodes
,
nodes
);
MatchMatrix
graph
(
static_cast
<
size_t
>
(
nodes
)
,
static_cast
<
size_t
>
(
nodes
)
)
;
testing
::
internal
::
Int32
seed
=
GTEST_FLAG
(
random_seed
);
auto
seed
=
static_cast
<
testing
::
internal
::
U
Int32
>
(
GTEST_FLAG
(
random_seed
)
)
;
if
(
seed
==
0
)
{
seed
=
static_cast
<
testing
::
internal
::
Int32
>
(
time
(
nullptr
));
seed
=
static_cast
<
testing
::
internal
::
U
Int32
>
(
time
(
nullptr
));
}
for
(;
iters
>
0
;
--
iters
,
++
seed
)
{
srand
(
static_cast
<
int
>
(
seed
));
srand
(
static_cast
<
unsigned
int
>
(
seed
));
graph
.
Randomize
();
EXPECT_EQ
(
FindBacktrackingMaxBPM
(
graph
).
size
(),
internal
::
FindMaxBipartiteMatching
(
graph
).
size
())
...
...
@@ -6150,7 +5924,7 @@ TEST_P(BipartiteRandomTest, LargerNets) {
}
// Test argument is a std::pair<int, int> representing (nodes, iters).
INSTANTIATE_TEST_
CAS
E_P
(
Samples
,
BipartiteRandomTest
,
INSTANTIATE_TEST_
SUIT
E_P
(
Samples
,
BipartiteRandomTest
,
testing
::
Values
(
std
::
make_pair
(
5
,
10000
),
std
::
make_pair
(
6
,
5000
),
...
...
@@ -6332,6 +6106,12 @@ TEST(EachTest, WorksForNativeArrayAsTuple) {
EXPECT_THAT
(
std
::
make_tuple
(
pointer
,
2
),
Not
(
Each
(
Gt
(
1
))));
}
TEST
(
EachTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
Each
(
Pointee
(
Gt
(
0
)))));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
}
// For testing Pointwise().
class
IsHalfOfMatcher
{
public:
...
...
@@ -6419,7 +6199,6 @@ TEST(PointwiseTest, WorksForVectorOfBool) {
EXPECT_THAT
(
lhs
,
Not
(
Pointwise
(
Eq
(),
rhs
)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
PointwiseTest
,
WorksForRhsInitializerList
)
{
const
vector
<
int
>
lhs
{
2
,
4
,
6
};
...
...
@@ -6427,7 +6206,6 @@ TEST(PointwiseTest, WorksForRhsInitializerList) {
EXPECT_THAT
(
lhs
,
Not
(
Pointwise
(
Lt
(),
{
3
,
3
,
7
})));
}
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
PointwiseTest
,
RejectsWrongSize
)
{
const
double
lhs
[
2
]
=
{
1
,
2
};
...
...
@@ -6470,6 +6248,17 @@ TEST(PointwiseTest, AllowsMonomorphicInnerMatcher) {
EXPECT_EQ
(
""
,
Explain
(
Pointwise
(
m2
,
rhs
),
lhs
));
}
MATCHER
(
PointeeEquals
,
"Points to an equal value"
)
{
return
ExplainMatchResult
(
::
testing
::
Pointee
(
::
testing
::
get
<
1
>
(
arg
)),
::
testing
::
get
<
0
>
(
arg
),
result_listener
);
}
TEST
(
PointwiseTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
Pointwise
(
PointeeEquals
(),
std
::
vector
<
int
>
{
1
,
2
})));
helper
.
Call
(
MakeUniquePtrs
({
1
,
2
}));
}
TEST
(
UnorderedPointwiseTest
,
DescribesSelf
)
{
vector
<
int
>
rhs
;
rhs
.
push_back
(
1
);
...
...
@@ -6530,7 +6319,6 @@ TEST(UnorderedPointwiseTest, WorksForRhsNativeArray) {
EXPECT_THAT
(
lhs
,
Not
(
UnorderedPointwise
(
Lt
(),
rhs
)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
UnorderedPointwiseTest
,
WorksForRhsInitializerList
)
{
const
vector
<
int
>
lhs
{
2
,
4
,
6
};
...
...
@@ -6538,7 +6326,6 @@ TEST(UnorderedPointwiseTest, WorksForRhsInitializerList) {
EXPECT_THAT
(
lhs
,
Not
(
UnorderedPointwise
(
Lt
(),
{
1
,
1
,
7
})));
}
#endif // GTEST_HAS_STD_INITIALIZER_LIST_
TEST
(
UnorderedPointwiseTest
,
RejectsWrongSize
)
{
const
double
lhs
[
2
]
=
{
1
,
2
};
...
...
@@ -6584,51 +6371,62 @@ TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) {
EXPECT_THAT
(
lhs
,
UnorderedPointwise
(
m2
,
rhs
));
}
TEST
(
UnorderedPointwiseTest
,
WorksWithMoveOnly
)
{
ContainerHelper
helper
;
EXPECT_CALL
(
helper
,
Call
(
UnorderedPointwise
(
PointeeEquals
(),
std
::
vector
<
int
>
{
1
,
2
})));
helper
.
Call
(
MakeUniquePtrs
({
2
,
1
}));
}
// Sample optional type implementation with minimal requirements for use with
// Optional matcher.
class
SampleOptionalInt
{
template
<
typename
T
>
class
SampleOptional
{
public:
typedef
int
value_type
;
explicit
SampleOptionalInt
(
int
value
)
:
value_
(
value
),
has_value_
(
true
)
{}
SampleOptionalInt
()
:
value_
(
0
),
has_value_
(
false
)
{}
operator
bool
()
const
{
return
has_value_
;
}
const
int
&
operator
*
()
const
{
return
value_
;
}
using
value_type
=
T
;
explicit
SampleOptional
(
T
value
)
:
value_
(
std
::
move
(
value
)),
has_value_
(
true
)
{}
SampleOptional
()
:
value_
(),
has_value_
(
false
)
{}
operator
bool
()
const
{
return
has_value_
;
}
const
T
&
operator
*
()
const
{
return
value_
;
}
private:
int
value_
;
T
value_
;
bool
has_value_
;
};
TEST
(
OptionalTest
,
DescribesSelf
)
{
const
Matcher
<
SampleOptional
I
nt
>
m
=
Optional
(
Eq
(
1
));
const
Matcher
<
SampleOptional
<
i
nt
>
>
m
=
Optional
(
Eq
(
1
));
EXPECT_EQ
(
"value is equal to 1"
,
Describe
(
m
));
}
TEST
(
OptionalTest
,
ExplainsSelf
)
{
const
Matcher
<
SampleOptional
I
nt
>
m
=
Optional
(
Eq
(
1
));
EXPECT_EQ
(
"whose value 1 matches"
,
Explain
(
m
,
SampleOptional
I
nt
(
1
)));
EXPECT_EQ
(
"whose value 2 doesn't match"
,
Explain
(
m
,
SampleOptional
I
nt
(
2
)));
const
Matcher
<
SampleOptional
<
i
nt
>
>
m
=
Optional
(
Eq
(
1
));
EXPECT_EQ
(
"whose value 1 matches"
,
Explain
(
m
,
SampleOptional
<
i
nt
>
(
1
)));
EXPECT_EQ
(
"whose value 2 doesn't match"
,
Explain
(
m
,
SampleOptional
<
i
nt
>
(
2
)));
}
TEST
(
OptionalTest
,
MatchesNonEmptyOptional
)
{
const
Matcher
<
SampleOptional
I
nt
>
m1
=
Optional
(
1
);
const
Matcher
<
SampleOptional
I
nt
>
m2
=
Optional
(
Eq
(
2
));
const
Matcher
<
SampleOptional
I
nt
>
m3
=
Optional
(
Lt
(
3
));
SampleOptional
I
nt
opt
(
1
);
const
Matcher
<
SampleOptional
<
i
nt
>
>
m1
=
Optional
(
1
);
const
Matcher
<
SampleOptional
<
i
nt
>
>
m2
=
Optional
(
Eq
(
2
));
const
Matcher
<
SampleOptional
<
i
nt
>
>
m3
=
Optional
(
Lt
(
3
));
SampleOptional
<
i
nt
>
opt
(
1
);
EXPECT_TRUE
(
m1
.
Matches
(
opt
));
EXPECT_FALSE
(
m2
.
Matches
(
opt
));
EXPECT_TRUE
(
m3
.
Matches
(
opt
));
}
TEST
(
OptionalTest
,
DoesNotMatchNullopt
)
{
const
Matcher
<
SampleOptional
I
nt
>
m
=
Optional
(
1
);
SampleOptional
I
nt
empty
;
const
Matcher
<
SampleOptional
<
i
nt
>
>
m
=
Optional
(
1
);
SampleOptional
<
i
nt
>
empty
;
EXPECT_FALSE
(
m
.
Matches
(
empty
));
}
TEST
(
OptionalTest
,
WorksWithMoveOnly
)
{
Matcher
<
SampleOptional
<
std
::
unique_ptr
<
int
>>>
m
=
Optional
(
Eq
(
nullptr
));
EXPECT_TRUE
(
m
.
Matches
(
SampleOptional
<
std
::
unique_ptr
<
int
>>
(
nullptr
)));
}
class
SampleVariantIntString
{
public:
SampleVariantIntString
(
int
i
)
:
i_
(
i
),
has_int_
(
true
)
{}
...
...
@@ -6636,7 +6434,7 @@ class SampleVariantIntString {
template
<
typename
T
>
friend
bool
holds_alternative
(
const
SampleVariantIntString
&
value
)
{
return
value
.
has_int_
==
internal
::
IsS
ame
<
T
,
int
>::
value
;
return
value
.
has_int_
==
std
::
is_s
ame
<
T
,
int
>::
value
;
}
template
<
typename
T
>
...
...
@@ -6724,7 +6522,6 @@ TEST(AnyWithTest, TestBadCastType) {
EXPECT_FALSE
(
m
.
Matches
(
SampleAnyType
(
1
)));
}
#if GTEST_LANG_CXX11
TEST
(
AnyWithTest
,
TestUseInContainers
)
{
std
::
vector
<
SampleAnyType
>
a
;
a
.
emplace_back
(
1
);
...
...
@@ -6741,7 +6538,6 @@ TEST(AnyWithTest, TestUseInContainers) {
AnyWith
<
std
::
string
>
(
"merhaba"
),
AnyWith
<
std
::
string
>
(
"salut"
)}));
}
#endif // GTEST_LANG_CXX11
TEST
(
AnyWithTest
,
TestCompare
)
{
EXPECT_THAT
(
SampleAnyType
(
1
),
AnyWith
<
int
>
(
Gt
(
0
)));
}
...
...
@@ -6884,10 +6680,10 @@ TEST(ArgsTest, ExplainsMatchResultWithoutInnerExplanation) {
// For testing Args<>'s explanation.
class
LessThanMatcher
:
public
MatcherInterface
<
std
::
tuple
<
char
,
int
>
>
{
public:
virtual
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{}
void
DescribeTo
(
::
std
::
ostream
*
/*os*/
)
const
override
{}
virtual
bool
MatchAndExplain
(
std
::
tuple
<
char
,
int
>
value
,
MatchResultListener
*
listener
)
const
{
bool
MatchAndExplain
(
std
::
tuple
<
char
,
int
>
value
,
MatchResultListener
*
listener
)
const
override
{
const
int
diff
=
std
::
get
<
0
>
(
value
)
-
std
::
get
<
1
>
(
value
);
if
(
diff
>
0
)
{
*
listener
<<
"where the first value is "
<<
diff
...
...
@@ -6958,10 +6754,6 @@ class PredicateFormatterFromMatcherTest : public ::testing::Test {
matcher
);
return
predicate_formatter
(
"dummy-name"
,
behavior
);
}
const
std
::
string
kMatcherType
=
"testing::gmock_matchers_test::PredicateFormatterFromMatcherTest::"
"Behavior"
;
};
TEST_F
(
PredicateFormatterFromMatcherTest
,
ShortCircuitOnSuccess
)
{
...
...
@@ -6976,8 +6768,7 @@ TEST_F(PredicateFormatterFromMatcherTest, NoShortCircuitOnFailure) {
EXPECT_FALSE
(
result
);
// Implicit cast to bool.
std
::
string
expect
=
"Value of: dummy-name
\n
Expected: [DescribeTo]
\n
"
" Actual: 1"
+
OfType
(
kMatcherType
)
+
", [MatchAndExplain]"
;
" Actual: 1, [MatchAndExplain]"
;
EXPECT_EQ
(
expect
,
result
.
message
());
}
...
...
@@ -6988,11 +6779,11 @@ TEST_F(PredicateFormatterFromMatcherTest, DetectsFlakyShortCircuit) {
"Value of: dummy-name
\n
Expected: [DescribeTo]
\n
"
" The matcher failed on the initial attempt; but passed when rerun to "
"generate the explanation.
\n
"
" Actual: 2"
+
OfType
(
kMatcherType
)
+
", [MatchAndExplain]"
;
" Actual: 2, [MatchAndExplain]"
;
EXPECT_EQ
(
expect
,
result
.
message
());
}
}
// namespace
}
// namespace gmock_matchers_test
}
// namespace testing
...
...
googlemock/test/gmock-nice-strict_test.cc
View file @
85f059f0
...
...
@@ -27,8 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "gmock/gmock-generated-nice-strict.h"
#include "gmock/gmock-nice-strict.h"
#include <string>
#include <utility>
...
...
@@ -114,23 +113,22 @@ class MockBar {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
};
#if GTEST_GTEST_LANG_CXX11
class
MockBaz
{
public:
class
MoveOnly
{
public:
MoveOnly
()
=
default
;
MoveOnly
(
const
MoveOnly
&
)
=
delete
;
operator
=
(
const
MoveOnly
&
)
=
delete
;
MoveOnly
&
operator
=
(
const
MoveOnly
&
)
=
delete
;
MoveOnly
(
MoveOnly
&&
)
=
default
;
operator
=
(
MoveOnly
&&
)
=
default
;
MoveOnly
&
operator
=
(
MoveOnly
&&
)
=
default
;
};
MockBaz
(
MoveOnly
)
{}
}
#endif // GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
};
#if GTEST_HAS_STREAM_REDIRECTION
...
...
@@ -292,29 +290,17 @@ TEST(NiceMockTest, AllowLeak) {
leaked
->
DoThis
();
}
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
TEST
(
NiceMockTest
,
MoveOnlyConstructor
)
{
NiceMock
<
MockBaz
>
nice_baz
(
MockBaz
::
MoveOnly
()
);
NiceMock
<
MockBaz
>
nice_baz
(
MockBaz
::
MoveOnly
{}
);
}
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that NiceMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// NiceMock to be looked up in the wrong context, and this test
// ensures that our fix works.
//
// We have to skip this test on Symbian and Windows Mobile, as it
// causes the program to crash there, for reasons unclear to us yet.
// class (as opposed to ::testing::Mock).
TEST
(
NiceMockTest
,
AcceptsClassNamedMock
)
{
NiceMock
<
::
Mock
>
nice
;
EXPECT_CALL
(
nice
,
DoThis
());
nice
.
DoThis
();
}
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
TEST
(
NiceMockTest
,
IsNaggy_IsNice_IsStrict
)
{
NiceMock
<
MockFoo
>
nice_foo
;
...
...
@@ -407,29 +393,17 @@ TEST(NaggyMockTest, AllowLeak) {
leaked
->
DoThis
();
}
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
TEST
(
NaggyMockTest
,
MoveOnlyConstructor
)
{
NaggyMock
<
MockBaz
>
naggy_baz
(
MockBaz
::
MoveOnly
()
);
NaggyMock
<
MockBaz
>
naggy_baz
(
MockBaz
::
MoveOnly
{}
);
}
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that NaggyMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// NaggyMock to be looked up in the wrong context, and this test
// ensures that our fix works.
//
// We have to skip this test on Symbian and Windows Mobile, as it
// causes the program to crash there, for reasons unclear to us yet.
// class (as opposed to ::testing::Mock).
TEST
(
NaggyMockTest
,
AcceptsClassNamedMock
)
{
NaggyMock
<
::
Mock
>
naggy
;
EXPECT_CALL
(
naggy
,
DoThis
());
naggy
.
DoThis
();
}
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
TEST
(
NaggyMockTest
,
IsNaggy_IsNice_IsStrict
)
{
NaggyMock
<
MockFoo
>
naggy_foo
;
...
...
@@ -503,29 +477,17 @@ TEST(StrictMockTest, AllowLeak) {
leaked
->
DoThis
();
}
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
TEST
(
StrictMockTest
,
MoveOnlyConstructor
)
{
StrictMock
<
MockBaz
>
strict_baz
(
MockBaz
::
MoveOnly
()
);
StrictMock
<
MockBaz
>
strict_baz
(
MockBaz
::
MoveOnly
{}
);
}
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
// Tests that StrictMock<Mock> compiles where Mock is a user-defined
// class (as opposed to ::testing::Mock). We had to work around an
// MSVC 8.0 bug that caused the symbol Mock used in the definition of
// StrictMock to be looked up in the wrong context, and this test
// ensures that our fix works.
//
// We have to skip this test on Symbian and Windows Mobile, as it
// causes the program to crash there, for reasons unclear to us yet.
// class (as opposed to ::testing::Mock).
TEST
(
StrictMockTest
,
AcceptsClassNamedMock
)
{
StrictMock
<
::
Mock
>
strict
;
EXPECT_CALL
(
strict
,
DoThis
());
strict
.
DoThis
();
}
#endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
TEST
(
StrictMockTest
,
IsNaggy_IsNice_IsStrict
)
{
StrictMock
<
MockFoo
>
strict_foo
;
...
...
googlemock/test/gmock-spec-builders_test.cc
View file @
85f059f0
...
...
@@ -78,6 +78,7 @@ using testing::Expectation;
using
testing
::
ExpectationSet
;
using
testing
::
GMOCK_FLAG
(
verbose
);
using
testing
::
Gt
;
using
testing
::
IgnoreResult
;
using
testing
::
InSequence
;
using
testing
::
Invoke
;
using
testing
::
InvokeWithoutArgs
;
...
...
@@ -1951,12 +1952,12 @@ TEST(DeletingMockEarlyTest, Failure2) {
class
EvenNumberCardinality
:
public
CardinalityInterface
{
public:
// Returns true if
f
call_count calls will satisfy this cardinality.
// Returns true if call_count calls will satisfy this cardinality.
bool
IsSatisfiedByCallCount
(
int
call_count
)
const
override
{
return
call_count
%
2
==
0
;
}
// Returns true if
f
call_count calls will saturate this cardinality.
// Returns true if call_count calls will saturate this cardinality.
bool
IsSaturatedByCallCount
(
int
/* call_count */
)
const
override
{
return
false
;
}
...
...
@@ -2177,7 +2178,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
"an EXPECT_CALL() if you don't mean to enforce the call. "
"See "
"https://github.com/google/googletest/blob/master/googlemock/docs/"
"
C
ook
B
ook.md#"
"
c
ook
_b
ook.md#"
"knowing-when-to-expect for details."
;
// A void-returning function.
...
...
googlemock/test/gmock_all_test.cc
View file @
85f059f0
...
...
@@ -39,7 +39,6 @@
#include "test/gmock-cardinalities_test.cc"
#include "test/gmock-generated-actions_test.cc"
#include "test/gmock-generated-function-mockers_test.cc"
#include "test/gmock-generated-internal-utils_test.cc"
#include "test/gmock-generated-matchers_test.cc"
#include "test/gmock-internal-utils_test.cc"
#include "test/gmock-matchers_test.cc"
...
...
Prev
1
2
3
4
5
6
7
8
…
11
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment