352 changed files with 20364 additions and 25781 deletions
-
155.clang-format
-
2.gitignore
-
591.travis.yml
-
2doc/checklist_new_release.md
-
14doc/update_resources.md
-
12resources/3rdparty/CMakeLists.txt
-
0resources/3rdparty/googletest/.clang-format
-
0resources/3rdparty/googletest/.gitignore
-
0resources/3rdparty/googletest/.travis.yml
-
13resources/3rdparty/googletest/BUILD.bazel
-
12resources/3rdparty/googletest/CMakeLists.txt
-
18resources/3rdparty/googletest/CONTRIBUTING.md
-
26resources/3rdparty/googletest/CONTRIBUTORS
-
0resources/3rdparty/googletest/LICENSE
-
140resources/3rdparty/googletest/README.md
-
24resources/3rdparty/googletest/WORKSPACE
-
126resources/3rdparty/googletest/ci/linux-presubmit.sh
-
59resources/3rdparty/googletest/ci/macos-presubmit.sh
-
1resources/3rdparty/googletest/docs/_config.yml
-
43resources/3rdparty/googletest/docs/_data/navigation.yml
-
58resources/3rdparty/googletest/docs/_layouts/default.html
-
200resources/3rdparty/googletest/docs/_sass/main.scss
-
865resources/3rdparty/googletest/docs/advanced.md
-
5resources/3rdparty/googletest/docs/assets/css/style.scss
-
7resources/3rdparty/googletest/docs/community_created_documentation.md
-
170resources/3rdparty/googletest/docs/faq.md
-
241resources/3rdparty/googletest/docs/gmock_cheat_sheet.md
-
687resources/3rdparty/googletest/docs/gmock_cook_book.md
-
16resources/3rdparty/googletest/docs/gmock_faq.md
-
94resources/3rdparty/googletest/docs/gmock_for_dummies.md
-
22resources/3rdparty/googletest/docs/index.md
-
131resources/3rdparty/googletest/docs/pkgconfig.md
-
35resources/3rdparty/googletest/docs/platforms.md
-
149resources/3rdparty/googletest/docs/primer.md
-
161resources/3rdparty/googletest/docs/quickstart-bazel.md
-
156resources/3rdparty/googletest/docs/quickstart-cmake.md
-
115resources/3rdparty/googletest/docs/reference/actions.md
-
633resources/3rdparty/googletest/docs/reference/assertions.md
-
283resources/3rdparty/googletest/docs/reference/matchers.md
-
587resources/3rdparty/googletest/docs/reference/mocking.md
-
1431resources/3rdparty/googletest/docs/reference/testing.md
-
2resources/3rdparty/googletest/docs/samples.md
-
21resources/3rdparty/googletest/googlemock/CMakeLists.txt
-
44resources/3rdparty/googletest/googlemock/README.md
-
10resources/3rdparty/googletest/googlemock/cmake/gmock.pc.in
-
10resources/3rdparty/googletest/googlemock/cmake/gmock_main.pc.in
-
4resources/3rdparty/googletest/googlemock/docs/README.md
-
639resources/3rdparty/googletest/googlemock/include/gmock/gmock-actions.h
-
6resources/3rdparty/googletest/googlemock/include/gmock/gmock-cardinalities.h
-
479resources/3rdparty/googletest/googlemock/include/gmock/gmock-function-mocker.h
-
1320resources/3rdparty/googletest/googlemock/include/gmock/gmock-matchers.h
-
573resources/3rdparty/googletest/googlemock/include/gmock/gmock-more-actions.h
-
10resources/3rdparty/googletest/googlemock/include/gmock/gmock-more-matchers.h
-
196resources/3rdparty/googletest/googlemock/include/gmock/gmock-nice-strict.h
-
177resources/3rdparty/googletest/googlemock/include/gmock/gmock-spec-builders.h
-
9resources/3rdparty/googletest/googlemock/include/gmock/gmock.h
-
0resources/3rdparty/googletest/googlemock/include/gmock/internal/custom/README.md
-
6resources/3rdparty/googletest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h
-
6resources/3rdparty/googletest/googlemock/include/gmock/internal/custom/gmock-matchers.h
-
6resources/3rdparty/googletest/googlemock/include/gmock/internal/custom/gmock-port.h
-
136resources/3rdparty/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h
-
12resources/3rdparty/googletest/googlemock/include/gmock/internal/gmock-port.h
-
122resources/3rdparty/googletest/googlemock/include/gmock/internal/gmock-pp.h
-
5resources/3rdparty/googletest/googlemock/scripts/README.md
-
128resources/3rdparty/googletest/googlemock/scripts/fuse_gmock_files.py
-
0resources/3rdparty/googletest/googlemock/scripts/generator/LICENSE
-
0resources/3rdparty/googletest/googlemock/scripts/generator/README
-
0resources/3rdparty/googletest/googlemock/scripts/generator/README.cppclean
-
0resources/3rdparty/googletest/googlemock/scripts/generator/cpp/__init__.py
-
1773resources/3rdparty/googletest/googlemock/scripts/generator/cpp/ast.py
-
156resources/3rdparty/googletest/googlemock/scripts/generator/cpp/gmock_class.py
-
246resources/3rdparty/googletest/googlemock/scripts/generator/cpp/gmock_class_test.py
-
3resources/3rdparty/googletest/googlemock/scripts/generator/cpp/keywords.py
-
3resources/3rdparty/googletest/googlemock/scripts/generator/cpp/tokenize.py
-
4resources/3rdparty/googletest/googlemock/scripts/generator/cpp/utils.py
-
1resources/3rdparty/googletest/googlemock/scripts/generator/gmock_gen.py
-
0resources/3rdparty/googletest/googlemock/src/gmock-all.cc
-
0resources/3rdparty/googletest/googlemock/src/gmock-cardinalities.cc
-
0resources/3rdparty/googletest/googlemock/src/gmock-internal-utils.cc
-
3resources/3rdparty/googletest/googlemock/src/gmock-matchers.cc
-
70resources/3rdparty/googletest/googlemock/src/gmock-spec-builders.cc
-
2resources/3rdparty/googletest/googlemock/src/gmock.cc
-
9resources/3rdparty/googletest/googlemock/src/gmock_main.cc
-
14resources/3rdparty/googletest/googlemock/test/BUILD.bazel
-
218resources/3rdparty/googletest/googlemock/test/gmock-actions_test.cc
-
0resources/3rdparty/googletest/googlemock/test/gmock-cardinalities_test.cc
-
986resources/3rdparty/googletest/googlemock/test/gmock-function-mocker_test.cc
-
33resources/3rdparty/googletest/googlemock/test/gmock-internal-utils_test.cc
-
2043resources/3rdparty/googletest/googlemock/test/gmock-matchers_test.cc
-
849resources/3rdparty/googletest/googlemock/test/gmock-more-actions_test.cc
-
39resources/3rdparty/googletest/googlemock/test/gmock-nice-strict_test.cc
-
0resources/3rdparty/googletest/googlemock/test/gmock-port_test.cc
-
0resources/3rdparty/googletest/googlemock/test/gmock-pp-string_test.cc
-
10resources/3rdparty/googletest/googlemock/test/gmock-pp_test.cc
-
6resources/3rdparty/googletest/googlemock/test/gmock-spec-builders_test.cc
-
3resources/3rdparty/googletest/googlemock/test/gmock_all_test.cc
-
0resources/3rdparty/googletest/googlemock/test/gmock_ex_test.cc
-
0resources/3rdparty/googletest/googlemock/test/gmock_leak_test.py
-
0resources/3rdparty/googletest/googlemock/test/gmock_leak_test_.cc
-
0resources/3rdparty/googletest/googlemock/test/gmock_link2_test.cc
@ -0,0 +1,155 @@ |
|||
--- |
|||
Language: Cpp |
|||
# BasedOnStyle: Google |
|||
AccessModifierOffset: -1 |
|||
AlignAfterOpenBracket: Align |
|||
AlignConsecutiveMacros: false |
|||
AlignConsecutiveAssignments: false |
|||
AlignConsecutiveBitFields: false |
|||
AlignConsecutiveDeclarations: false |
|||
AlignEscapedNewlines: Left |
|||
AlignOperands: Align |
|||
AlignTrailingComments: true |
|||
AllowAllArgumentsOnNextLine: true |
|||
AllowAllConstructorInitializersOnNextLine: true |
|||
AllowAllParametersOfDeclarationOnNextLine: true |
|||
AllowShortEnumsOnASingleLine: true |
|||
AllowShortBlocksOnASingleLine: Never |
|||
AllowShortCaseLabelsOnASingleLine: false |
|||
AllowShortFunctionsOnASingleLine: All |
|||
AllowShortLambdasOnASingleLine: All |
|||
AllowShortIfStatementsOnASingleLine: WithoutElse |
|||
AllowShortLoopsOnASingleLine: true |
|||
AlwaysBreakAfterDefinitionReturnType: None |
|||
AlwaysBreakAfterReturnType: None |
|||
AlwaysBreakBeforeMultilineStrings: true |
|||
AlwaysBreakTemplateDeclarations: Yes |
|||
BinPackArguments: true |
|||
BinPackParameters: true |
|||
BraceWrapping: |
|||
AfterCaseLabel: false |
|||
AfterClass: false |
|||
AfterControlStatement: Never |
|||
AfterEnum: false |
|||
AfterFunction: false |
|||
AfterNamespace: false |
|||
AfterObjCDeclaration: false |
|||
AfterStruct: false |
|||
AfterUnion: false |
|||
AfterExternBlock: false |
|||
BeforeCatch: false |
|||
BeforeElse: false |
|||
BeforeLambdaBody: false |
|||
BeforeWhile: false |
|||
IndentBraces: false |
|||
SplitEmptyFunction: true |
|||
SplitEmptyRecord: true |
|||
SplitEmptyNamespace: true |
|||
BreakBeforeBinaryOperators: None |
|||
BreakBeforeBraces: Attach |
|||
BreakBeforeInheritanceComma: false |
|||
BreakInheritanceList: BeforeColon |
|||
BreakBeforeTernaryOperators: true |
|||
BreakConstructorInitializersBeforeComma: false |
|||
BreakConstructorInitializers: BeforeColon |
|||
BreakAfterJavaFieldAnnotations: false |
|||
BreakStringLiterals: true |
|||
ColumnLimit: 160 |
|||
CompactNamespaces: false |
|||
ConstructorInitializerAllOnOneLineOrOnePerLine: true |
|||
ConstructorInitializerIndentWidth: 4 |
|||
ContinuationIndentWidth: 4 |
|||
Cpp11BracedListStyle: true |
|||
DeriveLineEnding: true |
|||
DerivePointerAlignment: true |
|||
DisableFormat: false |
|||
ExperimentalAutoDetectBinPacking: false |
|||
FixNamespaceComments: true |
|||
ForEachMacros: |
|||
- foreach |
|||
- Q_FOREACH |
|||
- BOOST_FOREACH |
|||
IncludeBlocks: Preserve |
|||
IncludeCategories: |
|||
- Regex: '^<storm/.*\.h>' |
|||
Priority: 2 |
|||
SortPriority: 0 |
|||
- Regex: '^<.*\.h>' |
|||
Priority: 1 |
|||
SortPriority: 0 |
|||
- Regex: '^<.*' |
|||
Priority: 2 |
|||
SortPriority: 0 |
|||
- Regex: '.*' |
|||
Priority: 3 |
|||
SortPriority: 0 |
|||
IncludeIsMainRegex: '([-_](test|unittest))?$' |
|||
IncludeIsMainSourceRegex: '' |
|||
IndentCaseLabels: true |
|||
IndentCaseBlocks: false |
|||
IndentGotoLabels: true |
|||
IndentPPDirectives: None |
|||
IndentExternBlock: AfterExternBlock |
|||
IndentWidth: 4 |
|||
IndentWrappedFunctionNames: false |
|||
InsertTrailingCommas: None |
|||
JavaScriptQuotes: Leave |
|||
JavaScriptWrapImports: true |
|||
KeepEmptyLinesAtTheStartOfBlocks: false |
|||
MacroBlockBegin: '' |
|||
MacroBlockEnd: '' |
|||
MaxEmptyLinesToKeep: 1 |
|||
NamespaceIndentation: None |
|||
PenaltyBreakAssignment: 2 |
|||
PenaltyBreakBeforeFirstCallParameter: 1 |
|||
PenaltyBreakComment: 300 |
|||
PenaltyBreakFirstLessLess: 120 |
|||
PenaltyBreakString: 1000 |
|||
PenaltyBreakTemplateDeclaration: 10 |
|||
PenaltyExcessCharacter: 1000000 |
|||
PenaltyReturnTypeOnItsOwnLine: 200 |
|||
PointerAlignment: Left |
|||
RawStringFormats: |
|||
- Language: Cpp |
|||
Delimiters: |
|||
- cc |
|||
- CC |
|||
- cpp |
|||
- Cpp |
|||
- CPP |
|||
- 'c++' |
|||
- 'C++' |
|||
CanonicalDelimiter: '' |
|||
BasedOnStyle: google |
|||
ReflowComments: true |
|||
SortIncludes: true |
|||
SortUsingDeclarations: true |
|||
SpaceAfterCStyleCast: false |
|||
SpaceAfterLogicalNot: false |
|||
SpaceAfterTemplateKeyword: false |
|||
SpaceBeforeAssignmentOperators: true |
|||
SpaceBeforeCpp11BracedList: false |
|||
SpaceBeforeCtorInitializerColon: true |
|||
SpaceBeforeInheritanceColon: true |
|||
SpaceBeforeParens: ControlStatements |
|||
SpaceBeforeRangeBasedForLoopColon: true |
|||
SpaceInEmptyBlock: false |
|||
SpaceInEmptyParentheses: false |
|||
SpacesBeforeTrailingComments: 2 |
|||
SpacesInAngles: false |
|||
SpacesInConditionalStatement: false |
|||
SpacesInContainerLiterals: true |
|||
SpacesInCStyleCastParentheses: false |
|||
SpacesInParentheses: false |
|||
SpacesInSquareBrackets: false |
|||
SpaceBeforeSquareBrackets: false |
|||
Standard: c++14 |
|||
TabWidth: 4 |
|||
UseCRLF: false |
|||
UseTab: Never |
|||
WhitespaceSensitiveMacros: |
|||
- STRINGIZE |
|||
- PP_STRINGIZE |
|||
- BOOST_PP_STRINGIZE |
|||
... |
|||
|
@ -1,591 +0,0 @@ |
|||
# |
|||
# General config |
|||
# |
|||
branches: |
|||
only: |
|||
- master |
|||
- stable |
|||
sudo: required |
|||
language: cpp |
|||
|
|||
git: |
|||
depth: false |
|||
|
|||
# Enable caching |
|||
cache: |
|||
timeout: 1000 |
|||
directories: |
|||
- build |
|||
- travis/mtime_cache |
|||
|
|||
# Enable docker support |
|||
services: |
|||
- docker |
|||
|
|||
notifications: |
|||
email: |
|||
on_failure: always |
|||
on_success: change |
|||
recipients: |
|||
- secure: "VWnsiQkt1xjgRo1hfNiNQqvLSr0fshFmLV7jJlUixhCr094mgD0U2bNKdUfebm28Byg9UyDYPbOFDC0sx7KydKiL1q7FKKXkyZH0k04wUu8XiNw+fYkDpmPnQs7G2n8oJ/GFJnr1Wp/1KI3qX5LX3xot4cJfx1I5iFC2O+p+ng6v/oSX+pewlMv4i7KL16ftHHHMo80N694v3g4B2NByn4GU2/bjVQcqlBp/TiVaUa5Nqu9DxZi/n9CJqGEaRHOblWyMO3EyTZsn45BNSWeQ3DtnMwZ73rlIr9CaEgCeuArc6RGghUAVqRI5ao+N5apekIaILwTgL6AJn+Lw/+NRPa8xclgd0rKqUQJMJCDZKjKz2lmIs3bxfELOizxJ3FJQ5R95FAxeAZ6rb/j40YqVVTw2IMBDnEE0J5ZmpUYNUtPti/Adf6GD9Fb2y8sLo0XDJzkI8OxYhfgjSy5KYmRj8O5MXcP2MAE8LQauNO3MaFnL9VMVOTZePJrPozQUgM021uyahf960+QNI06Uqlmg+PwWkSdllQlxHHplOgW7zClFhtSUpnJxcsUBzgg4kVg80gXUwAQkaDi7A9Wh2bs+TvMlmHzBwg+2SaAfWDgjeJIeOaipDkF1uSGzC+EHAiiKYMLd4Aahoi8SuelJUucoyJyLAq00WdUFQIh/izVhM4Y=" |
|||
|
|||
# |
|||
# Configurations |
|||
# |
|||
jobs: |
|||
include: |
|||
|
|||
### |
|||
# Stage: Build Carl |
|||
### |
|||
# ubuntu-20.04 - DefaultDebugTravis |
|||
- stage: Build Carl |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebugTravis TASK=TestDocker LINUX=ubuntu-20.04 COMPILER=gcc |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build_carl.sh |
|||
before_cache: |
|||
- docker cp carl:/opt/carl/. . |
|||
deploy: |
|||
- provider: script |
|||
skip_cleanup: true |
|||
script: bash travis/deploy_docker.sh carl |
|||
# ubuntu-20.04 - DefaultReleaseTravis |
|||
- stage: Build Carl |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultReleaseTravis TASK=TestDockerDoxygen LINUX=ubuntu-20.04 COMPILER=gcc |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build_carl.sh |
|||
before_cache: |
|||
- docker cp carl:/opt/carl/. . |
|||
deploy: |
|||
- provider: script |
|||
skip_cleanup: true |
|||
script: bash travis/deploy_docker.sh carl |
|||
|
|||
### |
|||
# Stage: Build (1st run) |
|||
### |
|||
# ubuntu-18.04 - DefaultDebug |
|||
- stage: Build (1st run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=ubuntu-18.04 COMPILER=gcc |
|||
install: |
|||
- rm -rf build |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build1 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-18.04 - DefaultRelease |
|||
- stage: Build (1st run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=ubuntu-18.04 COMPILER=gcc |
|||
install: |
|||
- rm -rf build |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build1 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-9 - DefaultDebug |
|||
- stage: Build (1st run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=debian-9 COMPILER=gcc |
|||
install: |
|||
- rm -rf build |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build1 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-9 - DefaultRelease |
|||
- stage: Build (1st run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=debian-9 COMPILER=gcc |
|||
install: |
|||
- rm -rf build |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build1 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-10 - DefaultDebug |
|||
- stage: Build (1st run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=debian-10 COMPILER=gcc |
|||
install: |
|||
- rm -rf build |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build1 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-10 - DefaultRelease |
|||
- stage: Build (1st run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=debian-10 COMPILER=gcc |
|||
install: |
|||
- rm -rf build |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build1 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-20.04 - DefaultDebugTravis |
|||
- stage: Build (1st run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebugTravis TASK=TestDocker LINUX=ubuntu-20.04 COMPILER=gcc |
|||
install: |
|||
- rm -rf build |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build1 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-20.04 - DefaultReleaseTravis |
|||
- stage: Build (1st run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultReleaseTravis TASK=TestDockerDoxygen LINUX=ubuntu-20.04 COMPILER=gcc |
|||
install: |
|||
- rm -rf build |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build1 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
|
|||
### |
|||
# Stage: Build (2nd run) |
|||
### |
|||
# ubuntu-18.04 - DefaultDebug |
|||
- stage: Build (2nd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=ubuntu-18.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build2 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-18.04 - DefaultRelease |
|||
- stage: Build (2nd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=ubuntu-18.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build2 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-9 - DefaultDebug |
|||
- stage: Build (2nd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=debian-9 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build2 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-9 - DefaultRelease |
|||
- stage: Build (2nd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=debian-9 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build2 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-10 - DefaultDebug |
|||
- stage: Build (2nd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=debian-10 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build2 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-10 - DefaultRelease |
|||
- stage: Build (2nd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=debian-10 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build2 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-20.04 - DefaultDebugTravis |
|||
- stage: Build (2nd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebugTravis TASK=TestDocker LINUX=ubuntu-20.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build2 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-20.04 - DefaultReleaseTravis |
|||
- stage: Build (2nd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultReleaseTravis TASK=TestDockerDoxygen LINUX=ubuntu-20.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Build2 |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
|
|||
### |
|||
# Stage: Build (3rd run) |
|||
### |
|||
# ubuntu-18.04 - DefaultDebug |
|||
- stage: Build (3rd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=ubuntu-18.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh BuildLast |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-18.04 - DefaultRelease |
|||
- stage: Build (3rd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=ubuntu-18.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh BuildLast |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-9 - DefaultDebug |
|||
- stage: Build (3rd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=debian-9 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh BuildLast |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-9 - DefaultRelease |
|||
- stage: Build (3rd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=debian-9 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh BuildLast |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-10 - DefaultDebug |
|||
- stage: Build (3rd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=debian-10 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh BuildLast |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-10 - DefaultRelease |
|||
- stage: Build (3rd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=debian-10 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh BuildLast |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-20.04 - DefaultDebugTravis |
|||
- stage: Build (3rd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebugTravis TASK=TestDocker LINUX=ubuntu-20.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh BuildLast |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-20.04 - DefaultReleaseTravis |
|||
- stage: Build (3rd run) |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultReleaseTravis TASK=TestDockerDoxygen LINUX=ubuntu-20.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh BuildLast |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
|
|||
### |
|||
# Stage: Tasks |
|||
### |
|||
# ubuntu-18.04 - DefaultDebug |
|||
- stage: Tasks |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=ubuntu-18.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Tasks |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-18.04 - DefaultRelease |
|||
- stage: Tasks |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=ubuntu-18.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Tasks |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-9 - DefaultDebug |
|||
- stage: Tasks |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=debian-9 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Tasks |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-9 - DefaultRelease |
|||
- stage: Tasks |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=debian-9 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Tasks |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-10 - DefaultDebug |
|||
- stage: Tasks |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebug TASK=Test LINUX=debian-10 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Tasks |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# debian-10 - DefaultRelease |
|||
- stage: Tasks |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultRelease TASK=Test LINUX=debian-10 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Tasks |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
# ubuntu-20.04 - DefaultDebugTravis |
|||
- stage: Tasks |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultDebugTravis TASK=TestDocker LINUX=ubuntu-20.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Tasks |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
deploy: |
|||
- provider: script |
|||
skip_cleanup: true |
|||
script: bash travis/deploy_docker.sh storm |
|||
# ubuntu-20.04 - DefaultReleaseTravis |
|||
- stage: Tasks |
|||
os: linux |
|||
compiler: gcc |
|||
env: CONFIG=DefaultReleaseTravis TASK=TestDockerDoxygen LINUX=ubuntu-20.04 COMPILER=gcc |
|||
install: |
|||
- travis/skip_test.sh |
|||
before_script: |
|||
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)" # Workaround for nonblocking mode |
|||
script: |
|||
- travis/build.sh Tasks |
|||
before_cache: |
|||
- docker cp storm:/opt/storm/. . |
|||
after_failure: |
|||
- find build -iname '*err*.log' -type f -print -exec cat {} \; |
|||
deploy: |
|||
- provider: script |
|||
skip_cleanup: true |
|||
script: bash travis/deploy_docker.sh storm |
|||
- provider: pages |
|||
skip_cleanup: true |
|||
github_token: $GITHUB_TOKEN |
|||
local_dir: build/doc/html/ |
|||
repo: moves-rwth/storm-doc |
|||
target_branch: master |
|||
on: |
|||
branch: master |
|||
|
@ -1,21 +1,17 @@ |
|||
# Note: CMake support is community-based. The maintainers do not use CMake |
|||
# internally. |
|||
|
|||
cmake_minimum_required(VERSION 2.8.8) |
|||
cmake_minimum_required(VERSION 2.8.12) |
|||
|
|||
if (POLICY CMP0048) |
|||
cmake_policy(SET CMP0048 NEW) |
|||
endif (POLICY CMP0048) |
|||
|
|||
project(googletest-distribution) |
|||
set(GOOGLETEST_VERSION 1.10.0) |
|||
set(GOOGLETEST_VERSION 1.11.0) |
|||
|
|||
if (CMAKE_VERSION VERSION_LESS "3.1") |
|||
add_definitions(-std=c++11) |
|||
else() |
|||
set(CMAKE_CXX_STANDARD 11) |
|||
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
|||
if(NOT CYGWIN) |
|||
if (CMAKE_VERSION VERSION_GREATER "3.0.2") |
|||
if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) |
|||
set(CMAKE_CXX_EXTENSIONS OFF) |
|||
endif() |
|||
endif() |
@ -0,0 +1,140 @@ |
|||
# GoogleTest |
|||
|
|||
### Announcements |
|||
|
|||
#### Live at Head |
|||
|
|||
GoogleTest now follows the |
|||
[Abseil Live at Head philosophy](https://abseil.io/about/philosophy#upgrade-support). |
|||
We recommend using the latest commit in the `master` branch in your projects. |
|||
|
|||
#### Documentation Updates |
|||
|
|||
Our documentation is now live on GitHub Pages at |
|||
https://google.github.io/googletest/. We recommend browsing the documentation on |
|||
GitHub Pages rather than directly in the repository. |
|||
|
|||
#### Release 1.10.x |
|||
|
|||
[Release 1.10.x](https://github.com/google/googletest/releases/tag/release-1.10.0) |
|||
is now available. |
|||
|
|||
#### Coming Soon |
|||
|
|||
* We are planning to take a dependency on |
|||
[Abseil](https://github.com/abseil/abseil-cpp). |
|||
* More documentation improvements are planned. |
|||
|
|||
## Welcome to **GoogleTest**, Google's C++ test framework! |
|||
|
|||
This repository is a merger of the formerly separate GoogleTest and GoogleMock |
|||
projects. These were so closely related that it makes sense to maintain and |
|||
release them together. |
|||
|
|||
### Getting Started |
|||
|
|||
See the [GoogleTest User's Guide](https://google.github.io/googletest/) for |
|||
documentation. We recommend starting with the |
|||
[GoogleTest Primer](https://google.github.io/googletest/primer.html). |
|||
|
|||
More information about building GoogleTest can be found at |
|||
[googletest/README.md](googletest/README.md). |
|||
|
|||
## Features |
|||
|
|||
* An [xUnit](https://en.wikipedia.org/wiki/XUnit) test framework. |
|||
* Test discovery. |
|||
* A rich set of assertions. |
|||
* User-defined assertions. |
|||
* Death tests. |
|||
* Fatal and non-fatal failures. |
|||
* Value-parameterized tests. |
|||
* Type-parameterized tests. |
|||
* Various options for running the tests. |
|||
* XML test report generation. |
|||
|
|||
## Supported Platforms |
|||
|
|||
GoogleTest requires a codebase and compiler compliant with the C++11 standard or |
|||
newer. |
|||
|
|||
The GoogleTest code is officially supported on the following platforms. |
|||
Operating systems or tools not listed below are community-supported. For |
|||
community-supported platforms, patches that do not complicate the code may be |
|||
considered. |
|||
|
|||
If you notice any problems on your platform, please file an issue on the |
|||
[GoogleTest GitHub Issue Tracker](https://github.com/google/googletest/issues). |
|||
Pull requests containing fixes are welcome! |
|||
|
|||
### Operating Systems |
|||
|
|||
* Linux |
|||
* macOS |
|||
* Windows |
|||
|
|||
### Compilers |
|||
|
|||
* gcc 5.0+ |
|||
* clang 5.0+ |
|||
* MSVC 2015+ |
|||
|
|||
**macOS users:** Xcode 9.3+ provides clang 5.0+. |
|||
|
|||
### Build Systems |
|||
|
|||
* [Bazel](https://bazel.build/) |
|||
* [CMake](https://cmake.org/) |
|||
|
|||
**Note:** Bazel is the build system used by the team internally and in tests. |
|||
CMake is supported on a best-effort basis and by the community. |
|||
|
|||
## Who Is Using GoogleTest? |
|||
|
|||
In addition to many internal projects at Google, GoogleTest is also used by the |
|||
following notable projects: |
|||
|
|||
* The [Chromium projects](http://www.chromium.org/) (behind the Chrome browser |
|||
and Chrome OS). |
|||
* The [LLVM](http://llvm.org/) compiler. |
|||
* [Protocol Buffers](https://github.com/google/protobuf), Google's data |
|||
interchange format. |
|||
* The [OpenCV](http://opencv.org/) computer vision library. |
|||
|
|||
## Related Open Source Projects |
|||
|
|||
[GTest Runner](https://github.com/nholthaus/gtest-runner) is a Qt5 based |
|||
automated test-runner and Graphical User Interface with powerful features for |
|||
Windows and Linux platforms. |
|||
|
|||
[GoogleTest UI](https://github.com/ospector/gtest-gbar) is a test runner that |
|||
runs your test binary, allows you to track its progress via a progress bar, and |
|||
displays a list of test failures. Clicking on one shows failure text. Google |
|||
Test UI is written in C#. |
|||
|
|||
[GTest TAP Listener](https://github.com/kinow/gtest-tap-listener) is an event |
|||
listener for GoogleTest that implements the |
|||
[TAP protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol) for test |
|||
result output. If your test runner understands TAP, you may find it useful. |
|||
|
|||
[gtest-parallel](https://github.com/google/gtest-parallel) is a test runner that |
|||
runs tests from your binary in parallel to provide significant speed-up. |
|||
|
|||
[GoogleTest Adapter](https://marketplace.visualstudio.com/items?itemName=DavidSchuldenfrei.gtest-adapter) |
|||
is a VS Code extension allowing to view GoogleTest in a tree view, and run/debug |
|||
your tests. |
|||
|
|||
[C++ TestMate](https://github.com/matepek/vscode-catch2-test-adapter) is a VS |
|||
Code extension allowing to view GoogleTest in a tree view, and run/debug your |
|||
tests. |
|||
|
|||
[Cornichon](https://pypi.org/project/cornichon/) is a small Gherkin DSL parser |
|||
that generates stub code for GoogleTest. |
|||
|
|||
## Contributing Changes |
|||
|
|||
Please read |
|||
[`CONTRIBUTING.md`](https://github.com/google/googletest/blob/master/CONTRIBUTING.md) |
|||
for details on how to contribute to this project. |
|||
|
|||
Happy testing! |
@ -0,0 +1,24 @@ |
|||
workspace(name = "com_google_googletest") |
|||
|
|||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
|||
|
|||
http_archive( |
|||
name = "com_google_absl", |
|||
urls = ["https://github.com/abseil/abseil-cpp/archive/7971fb358ae376e016d2d4fc9327aad95659b25e.zip"], # 2021-05-20T02:59:16Z |
|||
strip_prefix = "abseil-cpp-7971fb358ae376e016d2d4fc9327aad95659b25e", |
|||
sha256 = "aeba534f7307e36fe084b452299e49b97420667a8d28102cf9a0daeed340b859", |
|||
) |
|||
|
|||
http_archive( |
|||
name = "rules_cc", |
|||
urls = ["https://github.com/bazelbuild/rules_cc/archive/68cb652a71e7e7e2858c50593e5a9e3b94e5b9a9.zip"], # 2021-05-14T14:51:14Z |
|||
strip_prefix = "rules_cc-68cb652a71e7e7e2858c50593e5a9e3b94e5b9a9", |
|||
sha256 = "1e19e9a3bc3d4ee91d7fcad00653485ee6c798efbbf9588d40b34cbfbded143d", |
|||
) |
|||
|
|||
http_archive( |
|||
name = "rules_python", |
|||
urls = ["https://github.com/bazelbuild/rules_python/archive/ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2.zip"], # 2021-05-17T00:24:16Z |
|||
strip_prefix = "rules_python-ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2", |
|||
sha256 = "98b3c592faea9636ac8444bfd9de7f3fb4c60590932d6e6ac5946e3f8dbd5ff6", |
|||
) |
@ -0,0 +1,126 @@ |
|||
#!/bin/bash |
|||
# |
|||
# Copyright 2020, 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. |
|||
|
|||
set -euox pipefail |
|||
|
|||
readonly LINUX_LATEST_CONTAINER="gcr.io/google.com/absl-177019/linux_hybrid-latest:20210525" |
|||
readonly LINUX_GCC_FLOOR_CONTAINER="gcr.io/google.com/absl-177019/linux_gcc-floor:20201015" |
|||
|
|||
if [[ -z ${GTEST_ROOT:-} ]]; then |
|||
GTEST_ROOT="$(realpath $(dirname ${0})/..)" |
|||
fi |
|||
|
|||
if [[ -z ${STD:-} ]]; then |
|||
STD="c++11 c++14 c++17 c++20" |
|||
fi |
|||
|
|||
# Test the CMake build |
|||
for cc in /usr/local/bin/gcc /opt/llvm/clang/bin/clang; do |
|||
for cmake_off_on in OFF ON; do |
|||
time docker run \ |
|||
--volume="${GTEST_ROOT}:/src:ro" \ |
|||
--tmpfs="/build:exec" \ |
|||
--workdir="/build" \ |
|||
--rm \ |
|||
--env="CC=${cc}" \ |
|||
--env="CXX_FLAGS=\"-Werror -Wdeprecated\"" \ |
|||
${LINUX_LATEST_CONTAINER} \ |
|||
/bin/bash -c " |
|||
cmake /src \ |
|||
-DCMAKE_CXX_STANDARD=11 \ |
|||
-Dgtest_build_samples=ON \ |
|||
-Dgtest_build_tests=ON \ |
|||
-Dgmock_build_tests=ON \ |
|||
-Dcxx_no_exception=${cmake_off_on} \ |
|||
-Dcxx_no_rtti=${cmake_off_on} && \ |
|||
make -j$(nproc) && \ |
|||
ctest -j$(nproc) --output-on-failure" |
|||
done |
|||
done |
|||
|
|||
# Do one test with an older version of GCC |
|||
time docker run \ |
|||
--volume="${GTEST_ROOT}:/src:ro" \ |
|||
--workdir="/src" \ |
|||
--rm \ |
|||
--env="CC=/usr/local/bin/gcc" \ |
|||
${LINUX_GCC_FLOOR_CONTAINER} \ |
|||
/usr/local/bin/bazel test ... \ |
|||
--copt="-Wall" \ |
|||
--copt="-Werror" \ |
|||
--copt="-Wno-error=pragmas" \ |
|||
--keep_going \ |
|||
--show_timestamps \ |
|||
--test_output=errors |
|||
|
|||
# Test GCC |
|||
for std in ${STD}; do |
|||
for absl in 0 1; do |
|||
time docker run \ |
|||
--volume="${GTEST_ROOT}:/src:ro" \ |
|||
--workdir="/src" \ |
|||
--rm \ |
|||
--env="CC=/usr/local/bin/gcc" \ |
|||
--env="BAZEL_CXXOPTS=-std=${std}" \ |
|||
${LINUX_LATEST_CONTAINER} \ |
|||
/usr/local/bin/bazel test ... \ |
|||
--copt="-Wall" \ |
|||
--copt="-Werror" \ |
|||
--define="absl=${absl}" \ |
|||
--distdir="/bazel-distdir" \ |
|||
--keep_going \ |
|||
--show_timestamps \ |
|||
--test_output=errors |
|||
done |
|||
done |
|||
|
|||
# Test Clang |
|||
for std in ${STD}; do |
|||
for absl in 0 1; do |
|||
time docker run \ |
|||
--volume="${GTEST_ROOT}:/src:ro" \ |
|||
--workdir="/src" \ |
|||
--rm \ |
|||
--env="CC=/opt/llvm/clang/bin/clang" \ |
|||
--env="BAZEL_CXXOPTS=-std=${std}" \ |
|||
${LINUX_LATEST_CONTAINER} \ |
|||
/usr/local/bin/bazel test ... \ |
|||
--copt="--gcc-toolchain=/usr/local" \ |
|||
--copt="-Wall" \ |
|||
--copt="-Werror" \ |
|||
--define="absl=${absl}" \ |
|||
--distdir="/bazel-distdir" \ |
|||
--keep_going \ |
|||
--linkopt="--gcc-toolchain=/usr/local" \ |
|||
--show_timestamps \ |
|||
--test_output=errors |
|||
done |
|||
done |
@ -0,0 +1 @@ |
|||
title: GoogleTest |
@ -0,0 +1,43 @@ |
|||
nav: |
|||
- section: "Get Started" |
|||
items: |
|||
- title: "Supported Platforms" |
|||
url: "/platforms.html" |
|||
- title: "Quickstart: Bazel" |
|||
url: "/quickstart-bazel.html" |
|||
- title: "Quickstart: CMake" |
|||
url: "/quickstart-cmake.html" |
|||
- section: "Guides" |
|||
items: |
|||
- title: "GoogleTest Primer" |
|||
url: "/primer.html" |
|||
- title: "Advanced Topics" |
|||
url: "/advanced.html" |
|||
- title: "Mocking for Dummies" |
|||
url: "/gmock_for_dummies.html" |
|||
- title: "Mocking Cookbook" |
|||
url: "/gmock_cook_book.html" |
|||
- title: "Mocking Cheat Sheet" |
|||
url: "/gmock_cheat_sheet.html" |
|||
- section: "References" |
|||
items: |
|||
- title: "Testing Reference" |
|||
url: "/reference/testing.html" |
|||
- title: "Mocking Reference" |
|||
url: "/reference/mocking.html" |
|||
- title: "Assertions" |
|||
url: "/reference/assertions.html" |
|||
- title: "Matchers" |
|||
url: "/reference/matchers.html" |
|||
- title: "Actions" |
|||
url: "/reference/actions.html" |
|||
- title: "Testing FAQ" |
|||
url: "/faq.html" |
|||
- title: "Mocking FAQ" |
|||
url: "/gmock_faq.html" |
|||
- title: "Code Samples" |
|||
url: "/samples.html" |
|||
- title: "Using pkg-config" |
|||
url: "/pkgconfig.html" |
|||
- title: "Community Documentation" |
|||
url: "/community_created_documentation.html" |
@ -0,0 +1,58 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="{{ site.lang | default: "en-US" }}"> |
|||
<head> |
|||
<meta charset="UTF-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|||
|
|||
{% seo %} |
|||
<link rel="stylesheet" href="{{ "/assets/css/style.css?v=" | append: site.github.build_revision | relative_url }}"> |
|||
<script> |
|||
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; |
|||
ga('create', 'UA-197576187-1', { 'storage': 'none' }); |
|||
ga('set', 'referrer', document.referrer.split('?')[0]); |
|||
ga('set', 'location', window.location.href.split('?')[0]); |
|||
ga('set', 'anonymizeIp', true); |
|||
ga('send', 'pageview'); |
|||
</script> |
|||
<script async src='https://www.google-analytics.com/analytics.js'></script> |
|||
</head> |
|||
<body> |
|||
<div class="sidebar"> |
|||
<div class="header"> |
|||
<h1><a href="{{ "/" | relative_url }}">{{ site.title | default: "Documentation" }}</a></h1> |
|||
</div> |
|||
<input type="checkbox" id="nav-toggle" class="nav-toggle"> |
|||
<label for="nav-toggle" class="expander"> |
|||
<span class="arrow"></span> |
|||
</label> |
|||
<nav> |
|||
{% for item in site.data.navigation.nav %} |
|||
<h2>{{ item.section }}</h2> |
|||
<ul> |
|||
{% for subitem in item.items %} |
|||
<a href="{{subitem.url | relative_url }}"> |
|||
<li class="{% if subitem.url == page.url %}active{% endif %}"> |
|||
{{ subitem.title }} |
|||
</li> |
|||
</a> |
|||
{% endfor %} |
|||
</ul> |
|||
{% endfor %} |
|||
</nav> |
|||
</div> |
|||
<div class="main markdown-body"> |
|||
<div class="main-inner"> |
|||
{{ content }} |
|||
</div> |
|||
<div class="footer"> |
|||
GoogleTest · |
|||
<a href="https://github.com/google/googletest">GitHub Repository</a> · |
|||
<a href="https://github.com/google/googletest/blob/master/LICENSE">License</a> · |
|||
<a href="https://policies.google.com/privacy">Privacy Policy</a> |
|||
</div> |
|||
</div> |
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/4.1.0/anchor.min.js" integrity="sha256-lZaRhKri35AyJSypXXs4o6OPFTbTmUoltBbDCbdzegg=" crossorigin="anonymous"></script> |
|||
<script>anchors.add('.main h2, .main h3, .main h4, .main h5, .main h6');</script> |
|||
</body> |
|||
</html> |
@ -0,0 +1,200 @@ |
|||
// Styles for GoogleTest docs website on GitHub Pages. |
|||
// Color variables are defined in |
|||
// https://github.com/pages-themes/primer/tree/master/_sass/primer-support/lib/variables |
|||
|
|||
$sidebar-width: 260px; |
|||
|
|||
body { |
|||
display: flex; |
|||
margin: 0; |
|||
} |
|||
|
|||
.sidebar { |
|||
background: $black; |
|||
color: $text-white; |
|||
flex-shrink: 0; |
|||
height: 100vh; |
|||
overflow: auto; |
|||
position: sticky; |
|||
top: 0; |
|||
width: $sidebar-width; |
|||
} |
|||
|
|||
.sidebar h1 { |
|||
font-size: 1.5em; |
|||
} |
|||
|
|||
.sidebar h2 { |
|||
color: $gray-light; |
|||
font-size: 0.8em; |
|||
font-weight: normal; |
|||
margin-bottom: 0.8em; |
|||
padding-left: 2.5em; |
|||
text-transform: uppercase; |
|||
} |
|||
|
|||
.sidebar .header { |
|||
background: $black; |
|||
padding: 2em; |
|||
position: sticky; |
|||
top: 0; |
|||
width: 100%; |
|||
} |
|||
|
|||
.sidebar .header a { |
|||
color: $text-white; |
|||
text-decoration: none; |
|||
} |
|||
|
|||
.sidebar .nav-toggle { |
|||
display: none; |
|||
} |
|||
|
|||
.sidebar .expander { |
|||
cursor: pointer; |
|||
display: none; |
|||
height: 3em; |
|||
position: absolute; |
|||
right: 1em; |
|||
top: 1.5em; |
|||
width: 3em; |
|||
} |
|||
|
|||
.sidebar .expander .arrow { |
|||
border: solid $white; |
|||
border-width: 0 3px 3px 0; |
|||
display: block; |
|||
height: 0.7em; |
|||
margin: 1em auto; |
|||
transform: rotate(45deg); |
|||
transition: transform 0.5s; |
|||
width: 0.7em; |
|||
} |
|||
|
|||
.sidebar nav { |
|||
width: 100%; |
|||
} |
|||
|
|||
.sidebar nav ul { |
|||
list-style-type: none; |
|||
margin-bottom: 1em; |
|||
padding: 0; |
|||
|
|||
&:last-child { |
|||
margin-bottom: 2em; |
|||
} |
|||
|
|||
a { |
|||
text-decoration: none; |
|||
} |
|||
|
|||
li { |
|||
color: $text-white; |
|||
padding-left: 2em; |
|||
text-decoration: none; |
|||
} |
|||
|
|||
li.active { |
|||
background: $border-gray-darker; |
|||
font-weight: bold; |
|||
} |
|||
|
|||
li:hover { |
|||
background: $border-gray-darker; |
|||
} |
|||
} |
|||
|
|||
.main { |
|||
background-color: $bg-gray; |
|||
width: calc(100% - #{$sidebar-width}); |
|||
} |
|||
|
|||
.main .main-inner { |
|||
background-color: $white; |
|||
padding: 2em; |
|||
} |
|||
|
|||
.main .footer { |
|||
margin: 0; |
|||
padding: 2em; |
|||
} |
|||
|
|||
.main table th { |
|||
text-align: left; |
|||
} |
|||
|
|||
.main .callout { |
|||
border-left: 0.25em solid $white; |
|||
padding: 1em; |
|||
|
|||
a { |
|||
text-decoration: underline; |
|||
} |
|||
|
|||
&.important { |
|||
background-color: $bg-yellow-light; |
|||
border-color: $bg-yellow; |
|||
color: $black; |
|||
} |
|||
|
|||
&.note { |
|||
background-color: $bg-blue-light; |
|||
border-color: $text-blue; |
|||
color: $text-blue; |
|||
} |
|||
|
|||
&.tip { |
|||
background-color: $green-000; |
|||
border-color: $green-700; |
|||
color: $green-700; |
|||
} |
|||
|
|||
&.warning { |
|||
background-color: $red-000; |
|||
border-color: $text-red; |
|||
color: $text-red; |
|||
} |
|||
} |
|||
|
|||
.main .good pre { |
|||
background-color: $bg-green-light; |
|||
} |
|||
|
|||
.main .bad pre { |
|||
background-color: $red-000; |
|||
} |
|||
|
|||
@media all and (max-width: 768px) { |
|||
body { |
|||
flex-direction: column; |
|||
} |
|||
|
|||
.sidebar { |
|||
height: auto; |
|||
position: relative; |
|||
width: 100%; |
|||
} |
|||
|
|||
.sidebar .expander { |
|||
display: block; |
|||
} |
|||
|
|||
.sidebar nav { |
|||
height: 0; |
|||
overflow: hidden; |
|||
} |
|||
|
|||
.sidebar .nav-toggle:checked { |
|||
& ~ nav { |
|||
height: auto; |
|||
} |
|||
|
|||
& + .expander .arrow { |
|||
transform: rotate(-135deg); |
|||
} |
|||
} |
|||
|
|||
.main { |
|||
width: 100%; |
|||
} |
|||
} |
865
resources/3rdparty/googletest/docs/advanced.md
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,5 @@ |
|||
--- |
|||
--- |
|||
|
|||
@import "jekyll-theme-primer"; |
|||
@import "main"; |
@ -0,0 +1,7 @@ |
|||
# Community-Created Documentation |
|||
|
|||
The following is a list, in no particular order, of links to documentation |
|||
created by the Googletest community. |
|||
|
|||
* [Googlemock Insights](https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/blob/master/googletest/insights.md), |
|||
by [ElectricRCAircraftGuy](https://github.com/ElectricRCAircraftGuy) |
@ -0,0 +1,241 @@ |
|||
# gMock Cheat Sheet |
|||
|
|||
## Defining a Mock Class |
|||
|
|||
### Mocking a Normal Class {#MockClass} |
|||
|
|||
Given |
|||
|
|||
```cpp |
|||
class Foo { |
|||
... |
|||
virtual ~Foo(); |
|||
virtual int GetSize() const = 0; |
|||
virtual string Describe(const char* name) = 0; |
|||
virtual string Describe(int type) = 0; |
|||
virtual bool Process(Bar elem, int count) = 0; |
|||
}; |
|||
``` |
|||
|
|||
(note that `~Foo()` **must** be virtual) we can define its mock as |
|||
|
|||
```cpp |
|||
#include "gmock/gmock.h" |
|||
|
|||
class MockFoo : public Foo { |
|||
... |
|||
MOCK_METHOD(int, GetSize, (), (const, override)); |
|||
MOCK_METHOD(string, Describe, (const char* name), (override)); |
|||
MOCK_METHOD(string, Describe, (int type), (override)); |
|||
MOCK_METHOD(bool, Process, (Bar elem, int count), (override)); |
|||
}; |
|||
``` |
|||
|
|||
To create a "nice" mock, which ignores all uninteresting calls, a "naggy" mock, |
|||
which warns on all uninteresting calls, or a "strict" mock, which treats them as |
|||
failures: |
|||
|
|||
```cpp |
|||
using ::testing::NiceMock; |
|||
using ::testing::NaggyMock; |
|||
using ::testing::StrictMock; |
|||
|
|||
NiceMock<MockFoo> nice_foo; // The type is a subclass of MockFoo. |
|||
NaggyMock<MockFoo> naggy_foo; // The type is a subclass of MockFoo. |
|||
StrictMock<MockFoo> strict_foo; // The type is a subclass of MockFoo. |
|||
``` |
|||
|
|||
{: .callout .note} |
|||
**Note:** A mock object is currently naggy by default. We may make it nice by |
|||
default in the future. |
|||
|
|||
### Mocking a Class Template {#MockTemplate} |
|||
|
|||
Class templates can be mocked just like any class. |
|||
|
|||
To mock |
|||
|
|||
```cpp |
|||
template <typename Elem> |
|||
class StackInterface { |
|||
... |
|||
virtual ~StackInterface(); |
|||
virtual int GetSize() const = 0; |
|||
virtual void Push(const Elem& x) = 0; |
|||
}; |
|||
``` |
|||
|
|||
(note that all member functions that are mocked, including `~StackInterface()` |
|||
**must** be virtual). |
|||
|
|||
```cpp |
|||
template <typename Elem> |
|||
class MockStack : public StackInterface<Elem> { |
|||
... |
|||
MOCK_METHOD(int, GetSize, (), (const, override)); |
|||
MOCK_METHOD(void, Push, (const Elem& x), (override)); |
|||
}; |
|||
``` |
|||
|
|||
### Specifying Calling Conventions for Mock Functions |
|||
|
|||
If your mock function doesn't use the default calling convention, you can |
|||
specify it by adding `Calltype(convention)` to `MOCK_METHOD`'s 4th parameter. |
|||
For example, |
|||
|
|||
```cpp |
|||
MOCK_METHOD(bool, Foo, (int n), (Calltype(STDMETHODCALLTYPE))); |
|||
MOCK_METHOD(int, Bar, (double x, double y), |
|||
(const, Calltype(STDMETHODCALLTYPE))); |
|||
``` |
|||
|
|||
where `STDMETHODCALLTYPE` is defined by `<objbase.h>` on Windows. |
|||
|
|||
## Using Mocks in Tests {#UsingMocks} |
|||
|
|||
The typical work flow is: |
|||
|
|||
1. Import the gMock names you need to use. All gMock symbols are in the |
|||
`testing` namespace unless they are macros or otherwise noted. |
|||
2. Create the mock objects. |
|||
3. Optionally, set the default actions of the mock objects. |
|||
4. Set your expectations on the mock objects (How will they be called? What |
|||
will they do?). |
|||
5. Exercise code that uses the mock objects; if necessary, check the result |
|||
using googletest assertions. |
|||
6. When a mock object is destructed, gMock automatically verifies that all |
|||
expectations on it have been satisfied. |
|||
|
|||
Here's an example: |
|||
|
|||
```cpp |
|||
using ::testing::Return; // #1 |
|||
|
|||
TEST(BarTest, DoesThis) { |
|||
MockFoo foo; // #2 |
|||
|
|||
ON_CALL(foo, GetSize()) // #3 |
|||
.WillByDefault(Return(1)); |
|||
// ... other default actions ... |
|||
|
|||
EXPECT_CALL(foo, Describe(5)) // #4 |
|||
.Times(3) |
|||
.WillRepeatedly(Return("Category 5")); |
|||
// ... other expectations ... |
|||
|
|||
EXPECT_EQ(MyProductionFunction(&foo), "good"); // #5 |
|||
} // #6 |
|||
``` |
|||
|
|||
## Setting Default Actions {#OnCall} |
|||
|
|||
gMock has a **built-in default action** for any function that returns `void`, |
|||
`bool`, a numeric value, or a pointer. In C++11, it will additionally returns |
|||
the default-constructed value, if one exists for the given type. |
|||
|
|||
To customize the default action for functions with return type `T`, use |
|||
[`DefaultValue<T>`](reference/mocking.md#DefaultValue). For example: |
|||
|
|||
```cpp |
|||
// Sets the default action for return type std::unique_ptr<Buzz> to |
|||
// creating a new Buzz every time. |
|||
DefaultValue<std::unique_ptr<Buzz>>::SetFactory( |
|||
[] { return MakeUnique<Buzz>(AccessLevel::kInternal); }); |
|||
|
|||
// When this fires, the default action of MakeBuzz() will run, which |
|||
// will return a new Buzz object. |
|||
EXPECT_CALL(mock_buzzer_, MakeBuzz("hello")).Times(AnyNumber()); |
|||
|
|||
auto buzz1 = mock_buzzer_.MakeBuzz("hello"); |
|||
auto buzz2 = mock_buzzer_.MakeBuzz("hello"); |
|||
EXPECT_NE(buzz1, nullptr); |
|||
EXPECT_NE(buzz2, nullptr); |
|||
EXPECT_NE(buzz1, buzz2); |
|||
|
|||
// Resets the default action for return type std::unique_ptr<Buzz>, |
|||
// to avoid interfere with other tests. |
|||
DefaultValue<std::unique_ptr<Buzz>>::Clear(); |
|||
``` |
|||
|
|||
To customize the default action for a particular method of a specific mock |
|||
object, use [`ON_CALL`](reference/mocking.md#ON_CALL). `ON_CALL` has a similar |
|||
syntax to `EXPECT_CALL`, but it is used for setting default behaviors when you |
|||
do not require that the mock method is called. See |
|||
[Knowing When to Expect](gmock_cook_book.md#UseOnCall) for a more detailed |
|||
discussion. |
|||
|
|||
## Setting Expectations {#ExpectCall} |
|||
|
|||
See [`EXPECT_CALL`](reference/mocking.md#EXPECT_CALL) in the Mocking Reference. |
|||
|
|||
## Matchers {#MatcherList} |
|||
|
|||
See the [Matchers Reference](reference/matchers.md). |
|||
|
|||
## Actions {#ActionList} |
|||
|
|||
See the [Actions Reference](reference/actions.md). |
|||
|
|||
## Cardinalities {#CardinalityList} |
|||
|
|||
See the [`Times` clause](reference/mocking.md#EXPECT_CALL.Times) of |
|||
`EXPECT_CALL` in the Mocking Reference. |
|||
|
|||
## Expectation Order |
|||
|
|||
By default, expectations can be matched in *any* order. If some or all |
|||
expectations must be matched in a given order, you can use the |
|||
[`After` clause](reference/mocking.md#EXPECT_CALL.After) or |
|||
[`InSequence` clause](reference/mocking.md#EXPECT_CALL.InSequence) of |
|||
`EXPECT_CALL`, or use an [`InSequence` object](reference/mocking.md#InSequence). |
|||
|
|||
## Verifying and Resetting a Mock |
|||
|
|||
gMock will verify the expectations on a mock object when it is destructed, or |
|||
you can do it earlier: |
|||
|
|||
```cpp |
|||
using ::testing::Mock; |
|||
... |
|||
// Verifies and removes the expectations on mock_obj; |
|||
// returns true if and only if successful. |
|||
Mock::VerifyAndClearExpectations(&mock_obj); |
|||
... |
|||
// Verifies and removes the expectations on mock_obj; |
|||
// also removes the default actions set by ON_CALL(); |
|||
// returns true if and only if successful. |
|||
Mock::VerifyAndClear(&mock_obj); |
|||
``` |
|||
|
|||
Do not set new expectations after verifying and clearing a mock after its use. |
|||
Setting expectations after code that exercises the mock has undefined behavior. |
|||
See [Using Mocks in Tests](gmock_for_dummies.md#using-mocks-in-tests) for more |
|||
information. |
|||
|
|||
You can also tell gMock that a mock object can be leaked and doesn't need to be |
|||
verified: |
|||
|
|||
```cpp |
|||
Mock::AllowLeak(&mock_obj); |
|||
``` |
|||
|
|||
## Mock Classes |
|||
|
|||
gMock defines a convenient mock class template |
|||
|
|||
```cpp |
|||
class MockFunction<R(A1, ..., An)> { |
|||
public: |
|||
MOCK_METHOD(R, Call, (A1, ..., An)); |
|||
}; |
|||
``` |
|||
|
|||
See this [recipe](gmock_cook_book.md#using-check-points) for one application of |
|||
it. |
|||
|
|||
## Flags |
|||
|
|||
| Flag | Description | |
|||
| :----------------------------- | :---------------------------------------- | |
|||
| `--gmock_catch_leaked_mocks=0` | Don't report leaked mock objects as failures. | |
|||
| `--gmock_verbose=LEVEL` | Sets the default verbosity level (`info`, `warning`, or `error`) of Google Mock messages. | |
687
resources/3rdparty/googletest/docs/gmock_cook_book.md
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,22 @@ |
|||
# GoogleTest User's Guide |
|||
|
|||
## Welcome to GoogleTest! |
|||
|
|||
GoogleTest is Google's C++ testing and mocking framework. This user's guide has |
|||
the following contents: |
|||
|
|||
* [GoogleTest Primer](primer.md) - Teaches you how to write simple tests using |
|||
GoogleTest. Read this first if you are new to GoogleTest. |
|||
* [GoogleTest Advanced](advanced.md) - Read this when you've finished the |
|||
Primer and want to utilize GoogleTest to its full potential. |
|||
* [GoogleTest Samples](samples.md) - Describes some GoogleTest samples. |
|||
* [GoogleTest FAQ](faq.md) - Have a question? Want some tips? Check here |
|||
first. |
|||
* [Mocking for Dummies](gmock_for_dummies.md) - Teaches you how to create mock |
|||
objects and use them in tests. |
|||
* [Mocking Cookbook](gmock_cook_book.md) - Includes tips and approaches to |
|||
common mocking use cases. |
|||
* [Mocking Cheat Sheet](gmock_cheat_sheet.md) - A handy reference for |
|||
matchers, actions, invariants, and more. |
|||
* [Mocking FAQ](gmock_faq.md) - Contains answers to some mocking-specific |
|||
questions. |
@ -0,0 +1,35 @@ |
|||
# Supported Platforms |
|||
|
|||
GoogleTest requires a codebase and compiler compliant with the C++11 standard or |
|||
newer. |
|||
|
|||
The GoogleTest code is officially supported on the following platforms. |
|||
Operating systems or tools not listed below are community-supported. For |
|||
community-supported platforms, patches that do not complicate the code may be |
|||
considered. |
|||
|
|||
If you notice any problems on your platform, please file an issue on the |
|||
[GoogleTest GitHub Issue Tracker](https://github.com/google/googletest/issues). |
|||
Pull requests containing fixes are welcome! |
|||
|
|||
### Operating systems |
|||
|
|||
* Linux |
|||
* macOS |
|||
* Windows |
|||
|
|||
### Compilers |
|||
|
|||
* gcc 5.0+ |
|||
* clang 5.0+ |
|||
* MSVC 2015+ |
|||
|
|||
**macOS users:** Xcode 9.3+ provides clang 5.0+. |
|||
|
|||
### Build systems |
|||
|
|||
* [Bazel](https://bazel.build/) |
|||
* [CMake](https://cmake.org/) |
|||
|
|||
Bazel is the build system used by the team internally and in tests. CMake is |
|||
supported on a best-effort basis and by the community. |
@ -0,0 +1,161 @@ |
|||
# Quickstart: Building with Bazel |
|||
|
|||
This tutorial aims to get you up and running with GoogleTest using the Bazel |
|||
build system. If you're using GoogleTest for the first time or need a refresher, |
|||
we recommend this tutorial as a starting point. |
|||
|
|||
## Prerequisites |
|||
|
|||
To complete this tutorial, you'll need: |
|||
|
|||
* A compatible operating system (e.g. Linux, macOS, Windows). |
|||
* A compatible C++ compiler that supports at least C++11. |
|||
* [Bazel](https://bazel.build/), the preferred build system used by the |
|||
GoogleTest team. |
|||
|
|||
See [Supported Platforms](platforms.md) for more information about platforms |
|||
compatible with GoogleTest. |
|||
|
|||
If you don't already have Bazel installed, see the |
|||
[Bazel installation guide](https://docs.bazel.build/versions/master/install.html). |
|||
|
|||
{: .callout .note} |
|||
Note: The terminal commands in this tutorial show a Unix shell prompt, but the |
|||
commands work on the Windows command line as well. |
|||
|
|||
## Set up a Bazel workspace |
|||
|
|||
A |
|||
[Bazel workspace](https://docs.bazel.build/versions/master/build-ref.html#workspace) |
|||
is a directory on your filesystem that you use to manage source files for the |
|||
software you want to build. Each workspace directory has a text file named |
|||
`WORKSPACE` which may be empty, or may contain references to external |
|||
dependencies required to build the outputs. |
|||
|
|||
First, create a directory for your workspace: |
|||
|
|||
``` |
|||
$ mkdir my_workspace && cd my_workspace |
|||
``` |
|||
|
|||
Next, you’ll create the `WORKSPACE` file to specify dependencies. A common and |
|||
recommended way to depend on GoogleTest is to use a |
|||
[Bazel external dependency](https://docs.bazel.build/versions/master/external.html) |
|||
via the |
|||
[`http_archive` rule](https://docs.bazel.build/versions/master/repo/http.html#http_archive). |
|||
To do this, in the root directory of your workspace (`my_workspace/`), create a |
|||
file named `WORKSPACE` with the following contents: |
|||
|
|||
``` |
|||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
|||
|
|||
http_archive( |
|||
name = "com_google_googletest", |
|||
urls = ["https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip"], |
|||
strip_prefix = "googletest-609281088cfefc76f9d0ce82e1ff6c30cc3591e5", |
|||
) |
|||
``` |
|||
|
|||
The above configuration declares a dependency on GoogleTest which is downloaded |
|||
as a ZIP archive from GitHub. In the above example, |
|||
`609281088cfefc76f9d0ce82e1ff6c30cc3591e5` is the Git commit hash of the |
|||
GoogleTest version to use; we recommend updating the hash often to point to the |
|||
latest version. |
|||
|
|||
Bazel also needs a dependency on the |
|||
[`rules_cc` repository](https://github.com/bazelbuild/rules_cc) to build C++ |
|||
code, so add the following to the `WORKSPACE` file: |
|||
|
|||
``` |
|||
http_archive( |
|||
name = "rules_cc", |
|||
urls = ["https://github.com/bazelbuild/rules_cc/archive/40548a2974f1aea06215272d9c2b47a14a24e556.zip"], |
|||
strip_prefix = "rules_cc-40548a2974f1aea06215272d9c2b47a14a24e556", |
|||
) |
|||
``` |
|||
|
|||
Now you're ready to build C++ code that uses GoogleTest. |
|||
|
|||
## Create and run a binary |
|||
|
|||
With your Bazel workspace set up, you can now use GoogleTest code within your |
|||
own project. |
|||
|
|||
As an example, create a file named `hello_test.cc` in your `my_workspace` |
|||
directory with the following contents: |
|||
|
|||
```cpp |
|||
#include <gtest/gtest.h> |
|||
|
|||
// Demonstrate some basic assertions. |
|||
TEST(HelloTest, BasicAssertions) { |
|||
// Expect two strings not to be equal. |
|||
EXPECT_STRNE("hello", "world"); |
|||
// Expect equality. |
|||
EXPECT_EQ(7 * 6, 42); |
|||
} |
|||
``` |
|||
|
|||
GoogleTest provides [assertions](primer.md#assertions) that you use to test the |
|||
behavior of your code. The above sample includes the main GoogleTest header file |
|||
and demonstrates some basic assertions. |
|||
|
|||
To build the code, create a file named `BUILD` in the same directory with the |
|||
following contents: |
|||
|
|||
``` |
|||
load("@rules_cc//cc:defs.bzl", "cc_test") |
|||
|
|||
cc_test( |
|||
name = "hello_test", |
|||
size = "small", |
|||
srcs = ["hello_test.cc"], |
|||
deps = ["@com_google_googletest//:gtest_main"], |
|||
) |
|||
``` |
|||
|
|||
This `cc_test` rule declares the C++ test binary you want to build, and links to |
|||
GoogleTest (`//:gtest_main`) using the prefix you specified in the `WORKSPACE` |
|||
file (`@com_google_googletest`). For more information about Bazel `BUILD` files, |
|||
see the |
|||
[Bazel C++ Tutorial](https://docs.bazel.build/versions/master/tutorial/cpp.html). |
|||
|
|||
Now you can build and run your test: |
|||
|
|||
<pre> |
|||
<strong>my_workspace$ bazel test --test_output=all //:hello_test</strong> |
|||
INFO: Analyzed target //:hello_test (26 packages loaded, 362 targets configured). |
|||
INFO: Found 1 test target... |
|||
INFO: From Testing //:hello_test: |
|||
==================== Test output for //:hello_test: |
|||
Running main() from gmock_main.cc |
|||
[==========] Running 1 test from 1 test suite. |
|||
[----------] Global test environment set-up. |
|||
[----------] 1 test from HelloTest |
|||
[ RUN ] HelloTest.BasicAssertions |
|||
[ OK ] HelloTest.BasicAssertions (0 ms) |
|||
[----------] 1 test from HelloTest (0 ms total) |
|||
|
|||
[----------] Global test environment tear-down |
|||
[==========] 1 test from 1 test suite ran. (0 ms total) |
|||
[ PASSED ] 1 test. |
|||
================================================================================ |
|||
Target //:hello_test up-to-date: |
|||
bazel-bin/hello_test |
|||
INFO: Elapsed time: 4.190s, Critical Path: 3.05s |
|||
INFO: 27 processes: 8 internal, 19 linux-sandbox. |
|||
INFO: Build completed successfully, 27 total actions |
|||
//:hello_test PASSED in 0.1s |
|||
|
|||
INFO: Build completed successfully, 27 total actions |
|||
</pre> |
|||
|
|||
Congratulations! You've successfully built and run a test binary using |
|||
GoogleTest. |
|||
|
|||
## Next steps |
|||
|
|||
* [Check out the Primer](primer.md) to start learning how to write simple |
|||
tests. |
|||
* [See the code samples](samples.md) for more examples showing how to use a |
|||
variety of GoogleTest features. |
@ -0,0 +1,156 @@ |
|||
# Quickstart: Building with CMake |
|||
|
|||
This tutorial aims to get you up and running with GoogleTest using CMake. If |
|||
you're using GoogleTest for the first time or need a refresher, we recommend |
|||
this tutorial as a starting point. If your project uses Bazel, see the |
|||
[Quickstart for Bazel](quickstart-bazel.md) instead. |
|||
|
|||
## Prerequisites |
|||
|
|||
To complete this tutorial, you'll need: |
|||
|
|||
* A compatible operating system (e.g. Linux, macOS, Windows). |
|||
* A compatible C++ compiler that supports at least C++11. |
|||
* [CMake](https://cmake.org/) and a compatible build tool for building the |
|||
project. |
|||
* Compatible build tools include |
|||
[Make](https://www.gnu.org/software/make/), |
|||
[Ninja](https://ninja-build.org/), and others - see |
|||
[CMake Generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html) |
|||
for more information. |
|||
|
|||
See [Supported Platforms](platforms.md) for more information about platforms |
|||
compatible with GoogleTest. |
|||
|
|||
If you don't already have CMake installed, see the |
|||
[CMake installation guide](https://cmake.org/install). |
|||
|
|||
{: .callout .note} |
|||
Note: The terminal commands in this tutorial show a Unix shell prompt, but the |
|||
commands work on the Windows command line as well. |
|||
|
|||
## Set up a project |
|||
|
|||
CMake uses a file named `CMakeLists.txt` to configure the build system for a |
|||
project. You'll use this file to set up your project and declare a dependency on |
|||
GoogleTest. |
|||
|
|||
First, create a directory for your project: |
|||
|
|||
``` |
|||
$ mkdir my_project && cd my_project |
|||
``` |
|||
|
|||
Next, you'll create the `CMakeLists.txt` file and declare a dependency on |
|||
GoogleTest. There are many ways to express dependencies in the CMake ecosystem; |
|||
in this quickstart, you'll use the |
|||
[`FetchContent` CMake module](https://cmake.org/cmake/help/latest/module/FetchContent.html). |
|||
To do this, in your project directory (`my_project`), create a file named |
|||
`CMakeLists.txt` with the following contents: |
|||
|
|||
```cmake |
|||
cmake_minimum_required(VERSION 3.14) |
|||
project(my_project) |
|||
|
|||
# GoogleTest requires at least C++11 |
|||
set(CMAKE_CXX_STANDARD 11) |
|||
|
|||
include(FetchContent) |
|||
FetchContent_Declare( |
|||
googletest |
|||
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip |
|||
) |
|||
# For Windows: Prevent overriding the parent project's compiler/linker settings |
|||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
|||
FetchContent_MakeAvailable(googletest) |
|||
``` |
|||
|
|||
The above configuration declares a dependency on GoogleTest which is downloaded |
|||
from GitHub. In the above example, `609281088cfefc76f9d0ce82e1ff6c30cc3591e5` is |
|||
the Git commit hash of the GoogleTest version to use; we recommend updating the |
|||
hash often to point to the latest version. |
|||
|
|||
For more information about how to create `CMakeLists.txt` files, see the |
|||
[CMake Tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/index.html). |
|||
|
|||
## Create and run a binary |
|||
|
|||
With GoogleTest declared as a dependency, you can use GoogleTest code within |
|||
your own project. |
|||
|
|||
As an example, create a file named `hello_test.cc` in your `my_project` |
|||
directory with the following contents: |
|||
|
|||
```cpp |
|||
#include <gtest/gtest.h> |
|||
|
|||
// Demonstrate some basic assertions. |
|||
TEST(HelloTest, BasicAssertions) { |
|||
// Expect two strings not to be equal. |
|||
EXPECT_STRNE("hello", "world"); |
|||
// Expect equality. |
|||
EXPECT_EQ(7 * 6, 42); |
|||
} |
|||
``` |
|||
|
|||
GoogleTest provides [assertions](primer.md#assertions) that you use to test the |
|||
behavior of your code. The above sample includes the main GoogleTest header file |
|||
and demonstrates some basic assertions. |
|||
|
|||
To build the code, add the following to the end of your `CMakeLists.txt` file: |
|||
|
|||
```cmake |
|||
enable_testing() |
|||
|
|||
add_executable( |
|||
hello_test |
|||
hello_test.cc |
|||
) |
|||
target_link_libraries( |
|||
hello_test |
|||
gtest_main |
|||
) |
|||
|
|||
include(GoogleTest) |
|||
gtest_discover_tests(hello_test) |
|||
``` |
|||
|
|||
The above configuration enables testing in CMake, declares the C++ test binary |
|||
you want to build (`hello_test`), and links it to GoogleTest (`gtest_main`). The |
|||
last two lines enable CMake's test runner to discover the tests included in the |
|||
binary, using the |
|||
[`GoogleTest` CMake module](https://cmake.org/cmake/help/git-stage/module/GoogleTest.html). |
|||
|
|||
Now you can build and run your test: |
|||
|
|||
<pre> |
|||
<strong>my_project$ cmake -S . -B build</strong> |
|||
-- The C compiler identification is GNU 10.2.1 |
|||
-- The CXX compiler identification is GNU 10.2.1 |
|||
... |
|||
-- Build files have been written to: .../my_project/build |
|||
|
|||
<strong>my_project$ cmake --build build</strong> |
|||
Scanning dependencies of target gtest |
|||
... |
|||
[100%] Built target gmock_main |
|||
|
|||
<strong>my_project$ cd build && ctest</strong> |
|||
Test project .../my_project/build |
|||
Start 1: HelloTest.BasicAssertions |
|||
1/1 Test #1: HelloTest.BasicAssertions ........ Passed 0.00 sec |
|||
|
|||
100% tests passed, 0 tests failed out of 1 |
|||
|
|||
Total Test time (real) = 0.01 sec |
|||
</pre> |
|||
|
|||
Congratulations! You've successfully built and run a test binary using |
|||
GoogleTest. |
|||
|
|||
## Next steps |
|||
|
|||
* [Check out the Primer](primer.md) to start learning how to write simple |
|||
tests. |
|||
* [See the code samples](samples.md) for more examples showing how to use a |
|||
variety of GoogleTest features. |
@ -0,0 +1,115 @@ |
|||
# Actions Reference |
|||
|
|||
[**Actions**](../gmock_for_dummies.md#actions-what-should-it-do) specify what a |
|||
mock function should do when invoked. This page lists the built-in actions |
|||
provided by GoogleTest. All actions are defined in the `::testing` namespace. |
|||
|
|||
## Returning a Value |
|||
|
|||
| | | |
|||
| :-------------------------------- | :-------------------------------------------- | |
|||
| `Return()` | Return from a `void` mock function. | |
|||
| `Return(value)` | Return `value`. If the type of `value` is different to the mock function's return type, `value` is converted to the latter type <i>at the time the expectation is set</i>, not when the action is executed. | |
|||
| `ReturnArg<N>()` | Return the `N`-th (0-based) argument. | |
|||
| `ReturnNew<T>(a1, ..., ak)` | Return `new T(a1, ..., ak)`; a different object is created each time. | |
|||
| `ReturnNull()` | Return a null pointer. | |
|||
| `ReturnPointee(ptr)` | Return the value pointed to by `ptr`. | |
|||
| `ReturnRef(variable)` | Return a reference to `variable`. | |
|||
| `ReturnRefOfCopy(value)` | Return a reference to a copy of `value`; the copy lives as long as the action. | |
|||
| `ReturnRoundRobin({a1, ..., ak})` | Each call will return the next `ai` in the list, starting at the beginning when the end of the list is reached. | |
|||
|
|||
## Side Effects |
|||
|
|||
| | | |
|||
| :--------------------------------- | :-------------------------------------- | |
|||
| `Assign(&variable, value)` | Assign `value` to variable. | |
|||
| `DeleteArg<N>()` | Delete the `N`-th (0-based) argument, which must be a pointer. | |
|||
| `SaveArg<N>(pointer)` | Save the `N`-th (0-based) argument to `*pointer`. | |
|||
| `SaveArgPointee<N>(pointer)` | Save the value pointed to by the `N`-th (0-based) argument to `*pointer`. | |
|||
| `SetArgReferee<N>(value)` | Assign `value` to the variable referenced by the `N`-th (0-based) argument. | |
|||
| `SetArgPointee<N>(value)` | Assign `value` to the variable pointed by the `N`-th (0-based) argument. | |
|||
| `SetArgumentPointee<N>(value)` | Same as `SetArgPointee<N>(value)`. Deprecated. Will be removed in v1.7.0. | |
|||
| `SetArrayArgument<N>(first, last)` | Copies the elements in source range [`first`, `last`) to the array pointed to by the `N`-th (0-based) argument, which can be either a pointer or an iterator. The action does not take ownership of the elements in the source range. | |
|||
| `SetErrnoAndReturn(error, value)` | Set `errno` to `error` and return `value`. | |
|||
| `Throw(exception)` | Throws the given exception, which can be any copyable value. Available since v1.1.0. | |
|||
|
|||
## Using a Function, Functor, or Lambda as an Action |
|||
|
|||
In the following, by "callable" we mean a free function, `std::function`, |
|||
functor, or lambda. |
|||
|
|||
| | | |
|||
| :---------------------------------- | :------------------------------------- | |
|||
| `f` | Invoke f with the arguments passed to the mock function, where f is a callable. | |
|||
| `Invoke(f)` | Invoke `f` with the arguments passed to the mock function, where `f` can be a global/static function or a functor. | |
|||
| `Invoke(object_pointer, &class::method)` | Invoke the method on the object with the arguments passed to the mock function. | |
|||
| `InvokeWithoutArgs(f)` | Invoke `f`, which can be a global/static function or a functor. `f` must take no arguments. | |
|||
| `InvokeWithoutArgs(object_pointer, &class::method)` | Invoke the method on the object, which takes no arguments. | |
|||
| `InvokeArgument<N>(arg1, arg2, ..., argk)` | Invoke the mock function's `N`-th (0-based) argument, which must be a function or a functor, with the `k` arguments. | |
|||
|
|||
The return value of the invoked function is used as the return value of the |
|||
action. |
|||
|
|||
When defining a callable to be used with `Invoke*()`, you can declare any unused |
|||
parameters as `Unused`: |
|||
|
|||
```cpp |
|||
using ::testing::Invoke; |
|||
double Distance(Unused, double x, double y) { return sqrt(x*x + y*y); } |
|||
... |
|||
EXPECT_CALL(mock, Foo("Hi", _, _)).WillOnce(Invoke(Distance)); |
|||
``` |
|||
|
|||
`Invoke(callback)` and `InvokeWithoutArgs(callback)` take ownership of |
|||
`callback`, which must be permanent. The type of `callback` must be a base |
|||
callback type instead of a derived one, e.g. |
|||
|
|||
```cpp |
|||
BlockingClosure* done = new BlockingClosure; |
|||
... Invoke(done) ...; // This won't compile! |
|||
|
|||
Closure* done2 = new BlockingClosure; |
|||
... Invoke(done2) ...; // This works. |
|||
``` |
|||
|
|||
In `InvokeArgument<N>(...)`, if an argument needs to be passed by reference, |
|||
wrap it inside `std::ref()`. For example, |
|||
|
|||
```cpp |
|||
using ::testing::InvokeArgument; |
|||
... |
|||
InvokeArgument<2>(5, string("Hi"), std::ref(foo)) |
|||
``` |
|||
|
|||
calls the mock function's #2 argument, passing to it `5` and `string("Hi")` by |
|||
value, and `foo` by reference. |
|||
|
|||
## Default Action |
|||
|
|||
| Matcher | Description | |
|||
| :------------ | :----------------------------------------------------- | |
|||
| `DoDefault()` | Do the default action (specified by `ON_CALL()` or the built-in one). | |
|||
|
|||
{: .callout .note} |
|||
**Note:** due to technical reasons, `DoDefault()` cannot be used inside a |
|||
composite action - trying to do so will result in a run-time error. |
|||
|
|||
## Composite Actions |
|||
|
|||
| | | |
|||
| :----------------------------- | :------------------------------------------ | |
|||
| `DoAll(a1, a2, ..., an)` | Do all actions `a1` to `an` and return the result of `an` in each invocation. The first `n - 1` sub-actions must return void and will receive a readonly view of the arguments. | |
|||
| `IgnoreResult(a)` | Perform action `a` and ignore its result. `a` must not return void. | |
|||
| `WithArg<N>(a)` | Pass the `N`-th (0-based) argument of the mock function to action `a` and perform it. | |
|||
| `WithArgs<N1, N2, ..., Nk>(a)` | Pass the selected (0-based) arguments of the mock function to action `a` and perform it. | |
|||
| `WithoutArgs(a)` | Perform action `a` without any arguments. | |
|||
|
|||
## Defining Actions |
|||
|
|||
| | | |
|||
| :--------------------------------- | :-------------------------------------- | |
|||
| `ACTION(Sum) { return arg0 + arg1; }` | Defines an action `Sum()` to return the sum of the mock function's argument #0 and #1. | |
|||
| `ACTION_P(Plus, n) { return arg0 + n; }` | Defines an action `Plus(n)` to return the sum of the mock function's argument #0 and `n`. | |
|||
| `ACTION_Pk(Foo, p1, ..., pk) { statements; }` | Defines a parameterized action `Foo(p1, ..., pk)` to execute the given `statements`. | |
|||
|
|||
The `ACTION*` macros cannot be used inside a function or class. |
@ -0,0 +1,633 @@ |
|||
# Assertions Reference |
|||
|
|||
This page lists the assertion macros provided by GoogleTest for verifying code |
|||
behavior. To use them, include the header `gtest/gtest.h`. |
|||
|
|||
The majority of the macros listed below come as a pair with an `EXPECT_` variant |
|||
and an `ASSERT_` variant. Upon failure, `EXPECT_` macros generate nonfatal |
|||
failures and allow the current function to continue running, while `ASSERT_` |
|||
macros generate fatal failures and abort the current function. |
|||
|
|||
All assertion macros support streaming a custom failure message into them with |
|||
the `<<` operator, for example: |
|||
|
|||
```cpp |
|||
EXPECT_TRUE(my_condition) << "My condition is not true"; |
|||
``` |
|||
|
|||
Anything that can be streamed to an `ostream` can be streamed to an assertion |
|||
macro—in particular, C strings and string objects. If a wide string (`wchar_t*`, |
|||
`TCHAR*` in `UNICODE` mode on Windows, or `std::wstring`) is streamed to an |
|||
assertion, it will be translated to UTF-8 when printed. |
|||
|
|||
## Explicit Success and Failure {#success-failure} |
|||
|
|||
The assertions in this section generate a success or failure directly instead of |
|||
testing a value or expression. These are useful when control flow, rather than a |
|||
Boolean expression, determines the test's success or failure, as shown by the |
|||
following example: |
|||
|
|||
```c++ |
|||
switch(expression) { |
|||
case 1: |
|||
... some checks ... |
|||
case 2: |
|||
... some other checks ... |
|||
default: |
|||
FAIL() << "We shouldn't get here."; |
|||
} |
|||
``` |
|||
|
|||
### SUCCEED {#SUCCEED} |
|||
|
|||
`SUCCEED()` |
|||
|
|||
Generates a success. This *does not* make the overall test succeed. A test is |
|||
considered successful only if none of its assertions fail during its execution. |
|||
|
|||
The `SUCCEED` assertion is purely documentary and currently doesn't generate any |
|||
user-visible output. However, we may add `SUCCEED` messages to GoogleTest output |
|||
in the future. |
|||
|
|||
### FAIL {#FAIL} |
|||
|
|||
`FAIL()` |
|||
|
|||
Generates a fatal failure, which returns from the current function. |
|||
|
|||
Can only be used in functions that return `void`. See |
|||
[Assertion Placement](../advanced.md#assertion-placement) for more information. |
|||
|
|||
### ADD_FAILURE {#ADD_FAILURE} |
|||
|
|||
`ADD_FAILURE()` |
|||
|
|||
Generates a nonfatal failure, which allows the current function to continue |
|||
running. |
|||
|
|||
### ADD_FAILURE_AT {#ADD_FAILURE_AT} |
|||
|
|||
`ADD_FAILURE_AT(`*`file_path`*`,`*`line_number`*`)` |
|||
|
|||
Generates a nonfatal failure at the file and line number specified. |
|||
|
|||
## Generalized Assertion {#generalized} |
|||
|
|||
The following assertion allows [matchers](matchers.md) to be used to verify |
|||
values. |
|||
|
|||
### EXPECT_THAT {#EXPECT_THAT} |
|||
|
|||
`EXPECT_THAT(`*`value`*`,`*`matcher`*`)` \ |
|||
`ASSERT_THAT(`*`value`*`,`*`matcher`*`)` |
|||
|
|||
Verifies that *`value`* matches the [matcher](matchers.md) *`matcher`*. |
|||
|
|||
For example, the following code verifies that the string `value1` starts with |
|||
`"Hello"`, `value2` matches a regular expression, and `value3` is between 5 and |
|||
10: |
|||
|
|||
```cpp |
|||
#include "gmock/gmock.h" |
|||
|
|||
using ::testing::AllOf; |
|||
using ::testing::Gt; |
|||
using ::testing::Lt; |
|||
using ::testing::MatchesRegex; |
|||
using ::testing::StartsWith; |
|||
|
|||
... |
|||
EXPECT_THAT(value1, StartsWith("Hello")); |
|||
EXPECT_THAT(value2, MatchesRegex("Line \\d+")); |
|||
ASSERT_THAT(value3, AllOf(Gt(5), Lt(10))); |
|||
``` |
|||
|
|||
Matchers enable assertions of this form to read like English and generate |
|||
informative failure messages. For example, if the above assertion on `value1` |
|||
fails, the resulting message will be similar to the following: |
|||
|
|||
``` |
|||
Value of: value1 |
|||
Actual: "Hi, world!" |
|||
Expected: starts with "Hello" |
|||
``` |
|||
|
|||
GoogleTest provides a built-in library of matchers—see the |
|||
[Matchers Reference](matchers.md). It is also possible to write your own |
|||
matchers—see [Writing New Matchers Quickly](../gmock_cook_book.md#NewMatchers). |
|||
The use of matchers makes `EXPECT_THAT` a powerful, extensible assertion. |
|||
|
|||
*The idea for this assertion was borrowed from Joe Walnes' Hamcrest project, |
|||
which adds `assertThat()` to JUnit.* |
|||
|
|||
## Boolean Conditions {#boolean} |
|||
|
|||
The following assertions test Boolean conditions. |
|||
|
|||
### EXPECT_TRUE {#EXPECT_TRUE} |
|||
|
|||
`EXPECT_TRUE(`*`condition`*`)` \ |
|||
`ASSERT_TRUE(`*`condition`*`)` |
|||
|
|||
Verifies that *`condition`* is true. |
|||
|
|||
### EXPECT_FALSE {#EXPECT_FALSE} |
|||
|
|||
`EXPECT_FALSE(`*`condition`*`)` \ |
|||
`ASSERT_FALSE(`*`condition`*`)` |
|||
|
|||
Verifies that *`condition`* is false. |
|||
|
|||
## Binary Comparison {#binary-comparison} |
|||
|
|||
The following assertions compare two values. The value arguments must be |
|||
comparable by the assertion's comparison operator, otherwise a compiler error |
|||
will result. |
|||
|
|||
If an argument supports the `<<` operator, it will be called to print the |
|||
argument when the assertion fails. Otherwise, GoogleTest will attempt to print |
|||
them in the best way it can—see |
|||
[Teaching GoogleTest How to Print Your Values](../advanced.md#teaching-googletest-how-to-print-your-values). |
|||
|
|||
Arguments are always evaluated exactly once, so it's OK for the arguments to |
|||
have side effects. However, the argument evaluation order is undefined and |
|||
programs should not depend on any particular argument evaluation order. |
|||
|
|||
These assertions work with both narrow and wide string objects (`string` and |
|||
`wstring`). |
|||
|
|||
See also the [Floating-Point Comparison](#floating-point) assertions to compare |
|||
floating-point numbers and avoid problems caused by rounding. |
|||
|
|||
### EXPECT_EQ {#EXPECT_EQ} |
|||
|
|||
`EXPECT_EQ(`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_EQ(`*`val1`*`,`*`val2`*`)` |
|||
|
|||
Verifies that *`val1`*`==`*`val2`*. |
|||
|
|||
Does pointer equality on pointers. If used on two C strings, it tests if they |
|||
are in the same memory location, not if they have the same value. Use |
|||
[`EXPECT_STREQ`](#EXPECT_STREQ) to compare C strings (e.g. `const char*`) by |
|||
value. |
|||
|
|||
When comparing a pointer to `NULL`, use `EXPECT_EQ(`*`ptr`*`, nullptr)` instead |
|||
of `EXPECT_EQ(`*`ptr`*`, NULL)`. |
|||
|
|||
### EXPECT_NE {#EXPECT_NE} |
|||
|
|||
`EXPECT_NE(`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_NE(`*`val1`*`,`*`val2`*`)` |
|||
|
|||
Verifies that *`val1`*`!=`*`val2`*. |
|||
|
|||
Does pointer equality on pointers. If used on two C strings, it tests if they |
|||
are in different memory locations, not if they have different values. Use |
|||
[`EXPECT_STRNE`](#EXPECT_STRNE) to compare C strings (e.g. `const char*`) by |
|||
value. |
|||
|
|||
When comparing a pointer to `NULL`, use `EXPECT_NE(`*`ptr`*`, nullptr)` instead |
|||
of `EXPECT_NE(`*`ptr`*`, NULL)`. |
|||
|
|||
### EXPECT_LT {#EXPECT_LT} |
|||
|
|||
`EXPECT_LT(`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_LT(`*`val1`*`,`*`val2`*`)` |
|||
|
|||
Verifies that *`val1`*`<`*`val2`*. |
|||
|
|||
### EXPECT_LE {#EXPECT_LE} |
|||
|
|||
`EXPECT_LE(`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_LE(`*`val1`*`,`*`val2`*`)` |
|||
|
|||
Verifies that *`val1`*`<=`*`val2`*. |
|||
|
|||
### EXPECT_GT {#EXPECT_GT} |
|||
|
|||
`EXPECT_GT(`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_GT(`*`val1`*`,`*`val2`*`)` |
|||
|
|||
Verifies that *`val1`*`>`*`val2`*. |
|||
|
|||
### EXPECT_GE {#EXPECT_GE} |
|||
|
|||
`EXPECT_GE(`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_GE(`*`val1`*`,`*`val2`*`)` |
|||
|
|||
Verifies that *`val1`*`>=`*`val2`*. |
|||
|
|||
## String Comparison {#c-strings} |
|||
|
|||
The following assertions compare two **C strings**. To compare two `string` |
|||
objects, use [`EXPECT_EQ`](#EXPECT_EQ) or [`EXPECT_NE`](#EXPECT_NE) instead. |
|||
|
|||
These assertions also accept wide C strings (`wchar_t*`). If a comparison of two |
|||
wide strings fails, their values will be printed as UTF-8 narrow strings. |
|||
|
|||
To compare a C string with `NULL`, use `EXPECT_EQ(`*`c_string`*`, nullptr)` or |
|||
`EXPECT_NE(`*`c_string`*`, nullptr)`. |
|||
|
|||
### EXPECT_STREQ {#EXPECT_STREQ} |
|||
|
|||
`EXPECT_STREQ(`*`str1`*`,`*`str2`*`)` \ |
|||
`ASSERT_STREQ(`*`str1`*`,`*`str2`*`)` |
|||
|
|||
Verifies that the two C strings *`str1`* and *`str2`* have the same contents. |
|||
|
|||
### EXPECT_STRNE {#EXPECT_STRNE} |
|||
|
|||
`EXPECT_STRNE(`*`str1`*`,`*`str2`*`)` \ |
|||
`ASSERT_STRNE(`*`str1`*`,`*`str2`*`)` |
|||
|
|||
Verifies that the two C strings *`str1`* and *`str2`* have different contents. |
|||
|
|||
### EXPECT_STRCASEEQ {#EXPECT_STRCASEEQ} |
|||
|
|||
`EXPECT_STRCASEEQ(`*`str1`*`,`*`str2`*`)` \ |
|||
`ASSERT_STRCASEEQ(`*`str1`*`,`*`str2`*`)` |
|||
|
|||
Verifies that the two C strings *`str1`* and *`str2`* have the same contents, |
|||
ignoring case. |
|||
|
|||
### EXPECT_STRCASENE {#EXPECT_STRCASENE} |
|||
|
|||
`EXPECT_STRCASENE(`*`str1`*`,`*`str2`*`)` \ |
|||
`ASSERT_STRCASENE(`*`str1`*`,`*`str2`*`)` |
|||
|
|||
Verifies that the two C strings *`str1`* and *`str2`* have different contents, |
|||
ignoring case. |
|||
|
|||
## Floating-Point Comparison {#floating-point} |
|||
|
|||
The following assertions compare two floating-point values. |
|||
|
|||
Due to rounding errors, it is very unlikely that two floating-point values will |
|||
match exactly, so `EXPECT_EQ` is not suitable. In general, for floating-point |
|||
comparison to make sense, the user needs to carefully choose the error bound. |
|||
|
|||
GoogleTest also provides assertions that use a default error bound based on |
|||
Units in the Last Place (ULPs). To learn more about ULPs, see the article |
|||
[Comparing Floating Point Numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). |
|||
|
|||
### EXPECT_FLOAT_EQ {#EXPECT_FLOAT_EQ} |
|||
|
|||
`EXPECT_FLOAT_EQ(`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_FLOAT_EQ(`*`val1`*`,`*`val2`*`)` |
|||
|
|||
Verifies that the two `float` values *`val1`* and *`val2`* are approximately |
|||
equal, to within 4 ULPs from each other. |
|||
|
|||
### EXPECT_DOUBLE_EQ {#EXPECT_DOUBLE_EQ} |
|||
|
|||
`EXPECT_DOUBLE_EQ(`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_DOUBLE_EQ(`*`val1`*`,`*`val2`*`)` |
|||
|
|||
Verifies that the two `double` values *`val1`* and *`val2`* are approximately |
|||
equal, to within 4 ULPs from each other. |
|||
|
|||
### EXPECT_NEAR {#EXPECT_NEAR} |
|||
|
|||
`EXPECT_NEAR(`*`val1`*`,`*`val2`*`,`*`abs_error`*`)` \ |
|||
`ASSERT_NEAR(`*`val1`*`,`*`val2`*`,`*`abs_error`*`)` |
|||
|
|||
Verifies that the difference between *`val1`* and *`val2`* does not exceed the |
|||
absolute error bound *`abs_error`*. |
|||
|
|||
## Exception Assertions {#exceptions} |
|||
|
|||
The following assertions verify that a piece of code throws, or does not throw, |
|||
an exception. Usage requires exceptions to be enabled in the build environment. |
|||
|
|||
Note that the piece of code under test can be a compound statement, for example: |
|||
|
|||
```cpp |
|||
EXPECT_NO_THROW({ |
|||
int n = 5; |
|||
DoSomething(&n); |
|||
}); |
|||
``` |
|||
|
|||
### EXPECT_THROW {#EXPECT_THROW} |
|||
|
|||
`EXPECT_THROW(`*`statement`*`,`*`exception_type`*`)` \ |
|||
`ASSERT_THROW(`*`statement`*`,`*`exception_type`*`)` |
|||
|
|||
Verifies that *`statement`* throws an exception of type *`exception_type`*. |
|||
|
|||
### EXPECT_ANY_THROW {#EXPECT_ANY_THROW} |
|||
|
|||
`EXPECT_ANY_THROW(`*`statement`*`)` \ |
|||
`ASSERT_ANY_THROW(`*`statement`*`)` |
|||
|
|||
Verifies that *`statement`* throws an exception of any type. |
|||
|
|||
### EXPECT_NO_THROW {#EXPECT_NO_THROW} |
|||
|
|||
`EXPECT_NO_THROW(`*`statement`*`)` \ |
|||
`ASSERT_NO_THROW(`*`statement`*`)` |
|||
|
|||
Verifies that *`statement`* does not throw any exception. |
|||
|
|||
## Predicate Assertions {#predicates} |
|||
|
|||
The following assertions enable more complex predicates to be verified while |
|||
printing a more clear failure message than if `EXPECT_TRUE` were used alone. |
|||
|
|||
### EXPECT_PRED* {#EXPECT_PRED} |
|||
|
|||
`EXPECT_PRED1(`*`pred`*`,`*`val1`*`)` \ |
|||
`EXPECT_PRED2(`*`pred`*`,`*`val1`*`,`*`val2`*`)` \ |
|||
`EXPECT_PRED3(`*`pred`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`)` \ |
|||
`EXPECT_PRED4(`*`pred`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`,`*`val4`*`)` \ |
|||
`EXPECT_PRED5(`*`pred`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`,`*`val4`*`,`*`val5`*`)` |
|||
|
|||
`ASSERT_PRED1(`*`pred`*`,`*`val1`*`)` \ |
|||
`ASSERT_PRED2(`*`pred`*`,`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_PRED3(`*`pred`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`)` \ |
|||
`ASSERT_PRED4(`*`pred`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`,`*`val4`*`)` \ |
|||
`ASSERT_PRED5(`*`pred`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`,`*`val4`*`,`*`val5`*`)` |
|||
|
|||
Verifies that the predicate *`pred`* returns `true` when passed the given values |
|||
as arguments. |
|||
|
|||
The parameter *`pred`* is a function or functor that accepts as many arguments |
|||
as the corresponding macro accepts values. If *`pred`* returns `true` for the |
|||
given arguments, the assertion succeeds, otherwise the assertion fails. |
|||
|
|||
When the assertion fails, it prints the value of each argument. Arguments are |
|||
always evaluated exactly once. |
|||
|
|||
As an example, see the following code: |
|||
|
|||
```cpp |
|||
// Returns true if m and n have no common divisors except 1. |
|||
bool MutuallyPrime(int m, int n) { ... } |
|||
... |
|||
const int a = 3; |
|||
const int b = 4; |
|||
const int c = 10; |
|||
... |
|||
EXPECT_PRED2(MutuallyPrime, a, b); // Succeeds |
|||
EXPECT_PRED2(MutuallyPrime, b, c); // Fails |
|||
``` |
|||
|
|||
In the above example, the first assertion succeeds, and the second fails with |
|||
the following message: |
|||
|
|||
``` |
|||
MutuallyPrime(b, c) is false, where |
|||
b is 4 |
|||
c is 10 |
|||
``` |
|||
|
|||
Note that if the given predicate is an overloaded function or a function |
|||
template, the assertion macro might not be able to determine which version to |
|||
use, and it might be necessary to explicitly specify the type of the function. |
|||
For example, for a Boolean function `IsPositive()` overloaded to take either a |
|||
single `int` or `double` argument, it would be necessary to write one of the |
|||
following: |
|||
|
|||
```cpp |
|||
EXPECT_PRED1(static_cast<bool (*)(int)>(IsPositive), 5); |
|||
EXPECT_PRED1(static_cast<bool (*)(double)>(IsPositive), 3.14); |
|||
``` |
|||
|
|||
Writing simply `EXPECT_PRED1(IsPositive, 5);` would result in a compiler error. |
|||
Similarly, to use a template function, specify the template arguments: |
|||
|
|||
```cpp |
|||
template <typename T> |
|||
bool IsNegative(T x) { |
|||
return x < 0; |
|||
} |
|||
... |
|||
EXPECT_PRED1(IsNegative<int>, -5); // Must specify type for IsNegative |
|||
``` |
|||
|
|||
If a template has multiple parameters, wrap the predicate in parentheses so the |
|||
macro arguments are parsed correctly: |
|||
|
|||
```cpp |
|||
ASSERT_PRED2((MyPredicate<int, int>), 5, 0); |
|||
``` |
|||
|
|||
### EXPECT_PRED_FORMAT* {#EXPECT_PRED_FORMAT} |
|||
|
|||
`EXPECT_PRED_FORMAT1(`*`pred_formatter`*`,`*`val1`*`)` \ |
|||
`EXPECT_PRED_FORMAT2(`*`pred_formatter`*`,`*`val1`*`,`*`val2`*`)` \ |
|||
`EXPECT_PRED_FORMAT3(`*`pred_formatter`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`)` \ |
|||
`EXPECT_PRED_FORMAT4(`*`pred_formatter`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`,`*`val4`*`)` |
|||
\ |
|||
`EXPECT_PRED_FORMAT5(`*`pred_formatter`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`,`*`val4`*`,`*`val5`*`)` |
|||
|
|||
`ASSERT_PRED_FORMAT1(`*`pred_formatter`*`,`*`val1`*`)` \ |
|||
`ASSERT_PRED_FORMAT2(`*`pred_formatter`*`,`*`val1`*`,`*`val2`*`)` \ |
|||
`ASSERT_PRED_FORMAT3(`*`pred_formatter`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`)` \ |
|||
`ASSERT_PRED_FORMAT4(`*`pred_formatter`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`,`*`val4`*`)` |
|||
\ |
|||
`ASSERT_PRED_FORMAT5(`*`pred_formatter`*`,`*`val1`*`,`*`val2`*`,`*`val3`*`,`*`val4`*`,`*`val5`*`)` |
|||
|
|||
Verifies that the predicate *`pred_formatter`* succeeds when passed the given |
|||
values as arguments. |
|||
|
|||
The parameter *`pred_formatter`* is a *predicate-formatter*, which is a function |
|||
or functor with the signature: |
|||
|
|||
```cpp |
|||
testing::AssertionResult PredicateFormatter(const char* expr1, |
|||
const char* expr2, |
|||
... |
|||
const char* exprn, |
|||
T1 val1, |
|||
T2 val2, |
|||
... |
|||
Tn valn); |
|||
``` |
|||
|
|||
where *`val1`*, *`val2`*, ..., *`valn`* are the values of the predicate |
|||
arguments, and *`expr1`*, *`expr2`*, ..., *`exprn`* are the corresponding |
|||
expressions as they appear in the source code. The types `T1`, `T2`, ..., `Tn` |
|||
can be either value types or reference types; if an argument has type `T`, it |
|||
can be declared as either `T` or `const T&`, whichever is appropriate. For more |
|||
about the return type `testing::AssertionResult`, see |
|||
[Using a Function That Returns an AssertionResult](../advanced.md#using-a-function-that-returns-an-assertionresult). |
|||
|
|||
As an example, see the following code: |
|||
|
|||
```cpp |
|||
// Returns the smallest prime common divisor of m and n, |
|||
// or 1 when m and n are mutually prime. |
|||
int SmallestPrimeCommonDivisor(int m, int n) { ... } |
|||
|
|||
// Returns true if m and n have no common divisors except 1. |
|||
bool MutuallyPrime(int m, int n) { ... } |
|||
|
|||
// A predicate-formatter for asserting that two integers are mutually prime. |
|||
testing::AssertionResult AssertMutuallyPrime(const char* m_expr, |
|||
const char* n_expr, |
|||
int m, |
|||
int n) { |
|||
if (MutuallyPrime(m, n)) return testing::AssertionSuccess(); |
|||
|
|||
return testing::AssertionFailure() << m_expr << " and " << n_expr |
|||
<< " (" << m << " and " << n << ") are not mutually prime, " |
|||
<< "as they have a common divisor " << SmallestPrimeCommonDivisor(m, n); |
|||
} |
|||
|
|||
... |
|||
const int a = 3; |
|||
const int b = 4; |
|||
const int c = 10; |
|||
... |
|||
EXPECT_PRED_FORMAT2(AssertMutuallyPrime, a, b); // Succeeds |
|||
EXPECT_PRED_FORMAT2(AssertMutuallyPrime, b, c); // Fails |
|||
``` |
|||
|
|||
In the above example, the final assertion fails and the predicate-formatter |
|||
produces the following failure message: |
|||
|
|||
``` |
|||
b and c (4 and 10) are not mutually prime, as they have a common divisor 2 |
|||
``` |
|||
|
|||
## Windows HRESULT Assertions {#HRESULT} |
|||
|
|||
The following assertions test for `HRESULT` success or failure. For example: |
|||
|
|||
```cpp |
|||
CComPtr<IShellDispatch2> shell; |
|||
ASSERT_HRESULT_SUCCEEDED(shell.CoCreateInstance(L"Shell.Application")); |
|||
CComVariant empty; |
|||
ASSERT_HRESULT_SUCCEEDED(shell->ShellExecute(CComBSTR(url), empty, empty, empty, empty)); |
|||
``` |
|||
|
|||
The generated output contains the human-readable error message associated with |
|||
the returned `HRESULT` code. |
|||
|
|||
### EXPECT_HRESULT_SUCCEEDED {#EXPECT_HRESULT_SUCCEEDED} |
|||
|
|||
`EXPECT_HRESULT_SUCCEEDED(`*`expression`*`)` \ |
|||
`ASSERT_HRESULT_SUCCEEDED(`*`expression`*`)` |
|||
|
|||
Verifies that *`expression`* is a success `HRESULT`. |
|||
|
|||
### EXPECT_HRESULT_FAILED {#EXPECT_HRESULT_FAILED} |
|||
|
|||
`EXPECT_HRESULT_FAILED(`*`expression`*`)` \ |
|||
`EXPECT_HRESULT_FAILED(`*`expression`*`)` |
|||
|
|||
Verifies that *`expression`* is a failure `HRESULT`. |
|||
|
|||
## Death Assertions {#death} |
|||
|
|||
The following assertions verify that a piece of code causes the process to |
|||
terminate. For context, see [Death Tests](../advanced.md#death-tests). |
|||
|
|||
These assertions spawn a new process and execute the code under test in that |
|||
process. How that happens depends on the platform and the variable |
|||
`::testing::GTEST_FLAG(death_test_style)`, which is initialized from the |
|||
command-line flag `--gtest_death_test_style`. |
|||
|
|||
* On POSIX systems, `fork()` (or `clone()` on Linux) is used to spawn the |
|||
child, after which: |
|||
* If the variable's value is `"fast"`, the death test statement is |
|||
immediately executed. |
|||
* If the variable's value is `"threadsafe"`, the child process re-executes |
|||
the unit test binary just as it was originally invoked, but with some |
|||
extra flags to cause just the single death test under consideration to |
|||
be run. |
|||
* On Windows, the child is spawned using the `CreateProcess()` API, and |
|||
re-executes the binary to cause just the single death test under |
|||
consideration to be run - much like the `"threadsafe"` mode on POSIX. |
|||
|
|||
Other values for the variable are illegal and will cause the death test to fail. |
|||
Currently, the flag's default value is |
|||
**`"fast"`**. |
|||
|
|||
If the death test statement runs to completion without dying, the child process |
|||
will nonetheless terminate, and the assertion fails. |
|||
|
|||
Note that the piece of code under test can be a compound statement, for example: |
|||
|
|||
```cpp |
|||
EXPECT_DEATH({ |
|||
int n = 5; |
|||
DoSomething(&n); |
|||
}, "Error on line .* of DoSomething()"); |
|||
``` |
|||
|
|||
### EXPECT_DEATH {#EXPECT_DEATH} |
|||
|
|||
`EXPECT_DEATH(`*`statement`*`,`*`matcher`*`)` \ |
|||
`ASSERT_DEATH(`*`statement`*`,`*`matcher`*`)` |
|||
|
|||
Verifies that *`statement`* causes the process to terminate with a nonzero exit |
|||
status and produces `stderr` output that matches *`matcher`*. |
|||
|
|||
The parameter *`matcher`* is either a [matcher](matchers.md) for a `const |
|||
std::string&`, or a regular expression (see |
|||
[Regular Expression Syntax](../advanced.md#regular-expression-syntax))—a bare |
|||
string *`s`* (with no matcher) is treated as |
|||
[`ContainsRegex(s)`](matchers.md#string-matchers), **not** |
|||
[`Eq(s)`](matchers.md#generic-comparison). |
|||
|
|||
For example, the following code verifies that calling `DoSomething(42)` causes |
|||
the process to die with an error message that contains the text `My error`: |
|||
|
|||
```cpp |
|||
EXPECT_DEATH(DoSomething(42), "My error"); |
|||
``` |
|||
|
|||
### EXPECT_DEATH_IF_SUPPORTED {#EXPECT_DEATH_IF_SUPPORTED} |
|||
|
|||
`EXPECT_DEATH_IF_SUPPORTED(`*`statement`*`,`*`matcher`*`)` \ |
|||
`ASSERT_DEATH_IF_SUPPORTED(`*`statement`*`,`*`matcher`*`)` |
|||
|
|||
If death tests are supported, behaves the same as |
|||
[`EXPECT_DEATH`](#EXPECT_DEATH). Otherwise, verifies nothing. |
|||
|
|||
### EXPECT_DEBUG_DEATH {#EXPECT_DEBUG_DEATH} |
|||
|
|||
`EXPECT_DEBUG_DEATH(`*`statement`*`,`*`matcher`*`)` \ |
|||
`ASSERT_DEBUG_DEATH(`*`statement`*`,`*`matcher`*`)` |
|||
|
|||
In debug mode, behaves the same as [`EXPECT_DEATH`](#EXPECT_DEATH). When not in |
|||
debug mode (i.e. `NDEBUG` is defined), just executes *`statement`*. |
|||
|
|||
### EXPECT_EXIT {#EXPECT_EXIT} |
|||
|
|||
`EXPECT_EXIT(`*`statement`*`,`*`predicate`*`,`*`matcher`*`)` \ |
|||
`ASSERT_EXIT(`*`statement`*`,`*`predicate`*`,`*`matcher`*`)` |
|||
|
|||
Verifies that *`statement`* causes the process to terminate with an exit status |
|||
that satisfies *`predicate`*, and produces `stderr` output that matches |
|||
*`matcher`*. |
|||
|
|||
The parameter *`predicate`* is a function or functor that accepts an `int` exit |
|||
status and returns a `bool`. GoogleTest provides two predicates to handle common |
|||
cases: |
|||
|
|||
```cpp |
|||
// Returns true if the program exited normally with the given exit status code. |
|||
::testing::ExitedWithCode(exit_code); |
|||
|
|||
// Returns true if the program was killed by the given signal. |
|||
// Not available on Windows. |
|||
::testing::KilledBySignal(signal_number); |
|||
``` |
|||
|
|||
The parameter *`matcher`* is either a [matcher](matchers.md) for a `const |
|||
std::string&`, or a regular expression (see |
|||
[Regular Expression Syntax](../advanced.md#regular-expression-syntax))—a bare |
|||
string *`s`* (with no matcher) is treated as |
|||
[`ContainsRegex(s)`](matchers.md#string-matchers), **not** |
|||
[`Eq(s)`](matchers.md#generic-comparison). |
|||
|
|||
For example, the following code verifies that calling `NormalExit()` causes the |
|||
process to print a message containing the text `Success` to `stderr` and exit |
|||
with exit status code 0: |
|||
|
|||
```cpp |
|||
EXPECT_EXIT(NormalExit(), testing::ExitedWithCode(0), "Success"); |
|||
``` |
@ -0,0 +1,283 @@ |
|||
# Matchers Reference |
|||
|
|||
A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or |
|||
`EXPECT_CALL()`, or use it to validate a value directly using two macros: |
|||
|
|||
| Macro | Description | |
|||
| :----------------------------------- | :------------------------------------ | |
|||
| `EXPECT_THAT(actual_value, matcher)` | Asserts that `actual_value` matches `matcher`. | |
|||
| `ASSERT_THAT(actual_value, matcher)` | The same as `EXPECT_THAT(actual_value, matcher)`, except that it generates a **fatal** failure. | |
|||
|
|||
{: .callout .note} |
|||
**Note:** Although equality matching via `EXPECT_THAT(actual_value, |
|||
expected_value)` is supported, prefer to make the comparison explicit via |
|||
`EXPECT_THAT(actual_value, Eq(expected_value))` or `EXPECT_EQ(actual_value, |
|||
expected_value)`. |
|||
|
|||
Built-in matchers (where `argument` is the function argument, e.g. |
|||
`actual_value` in the example above, or when used in the context of |
|||
`EXPECT_CALL(mock_object, method(matchers))`, the arguments of `method`) are |
|||
divided into several categories. All matchers are defined in the `::testing` |
|||
namespace unless otherwise noted. |
|||
|
|||
## Wildcard |
|||
|
|||
Matcher | Description |
|||
:-------------------------- | :----------------------------------------------- |
|||
`_` | `argument` can be any value of the correct type. |
|||
`A<type>()` or `An<type>()` | `argument` can be any value of type `type`. |
|||
|
|||
## Generic Comparison |
|||
|
|||
| Matcher | Description | |
|||
| :--------------------- | :-------------------------------------------------- | |
|||
| `Eq(value)` or `value` | `argument == value` | |
|||
| `Ge(value)` | `argument >= value` | |
|||
| `Gt(value)` | `argument > value` | |
|||
| `Le(value)` | `argument <= value` | |
|||
| `Lt(value)` | `argument < value` | |
|||
| `Ne(value)` | `argument != value` | |
|||
| `IsFalse()` | `argument` evaluates to `false` in a Boolean context. | |
|||
| `IsTrue()` | `argument` evaluates to `true` in a Boolean context. | |
|||
| `IsNull()` | `argument` is a `NULL` pointer (raw or smart). | |
|||
| `NotNull()` | `argument` is a non-null pointer (raw or smart). | |
|||
| `Optional(m)` | `argument` is `optional<>` that contains a value matching `m`. (For testing whether an `optional<>` is set, check for equality with `nullopt`. You may need to use `Eq(nullopt)` if the inner type doesn't have `==`.)| |
|||
| `VariantWith<T>(m)` | `argument` is `variant<>` that holds the alternative of type T with a value matching `m`. | |
|||
| `Ref(variable)` | `argument` is a reference to `variable`. | |
|||
| `TypedEq<type>(value)` | `argument` has type `type` and is equal to `value`. You may need to use this instead of `Eq(value)` when the mock function is overloaded. | |
|||
|
|||
Except `Ref()`, these matchers make a *copy* of `value` in case it's modified or |
|||
destructed later. If the compiler complains that `value` doesn't have a public |
|||
copy constructor, try wrap it in `std::ref()`, e.g. |
|||
`Eq(std::ref(non_copyable_value))`. If you do that, make sure |
|||
`non_copyable_value` is not changed afterwards, or the meaning of your matcher |
|||
will be changed. |
|||
|
|||
`IsTrue` and `IsFalse` are useful when you need to use a matcher, or for types |
|||
that can be explicitly converted to Boolean, but are not implicitly converted to |
|||
Boolean. In other cases, you can use the basic |
|||
[`EXPECT_TRUE` and `EXPECT_FALSE`](assertions.md#boolean) assertions. |
|||
|
|||
## Floating-Point Matchers {#FpMatchers} |
|||
|
|||
| Matcher | Description | |
|||
| :------------------------------- | :--------------------------------- | |
|||
| `DoubleEq(a_double)` | `argument` is a `double` value approximately equal to `a_double`, treating two NaNs as unequal. | |
|||
| `FloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as unequal. | |
|||
| `NanSensitiveDoubleEq(a_double)` | `argument` is a `double` value approximately equal to `a_double`, treating two NaNs as equal. | |
|||
| `NanSensitiveFloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as equal. | |
|||
| `IsNan()` | `argument` is any floating-point type with a NaN value. | |
|||
|
|||
The above matchers use ULP-based comparison (the same as used in googletest). |
|||
They automatically pick a reasonable error bound based on the absolute value of |
|||
the expected value. `DoubleEq()` and `FloatEq()` conform to the IEEE standard, |
|||
which requires comparing two NaNs for equality to return false. The |
|||
`NanSensitive*` version instead treats two NaNs as equal, which is often what a |
|||
user wants. |
|||
|
|||
| Matcher | Description | |
|||
| :------------------------------------------------ | :----------------------- | |
|||
| `DoubleNear(a_double, max_abs_error)` | `argument` is a `double` value close to `a_double` (absolute error <= `max_abs_error`), treating two NaNs as unequal. | |
|||
| `FloatNear(a_float, max_abs_error)` | `argument` is a `float` value close to `a_float` (absolute error <= `max_abs_error`), treating two NaNs as unequal. | |
|||
| `NanSensitiveDoubleNear(a_double, max_abs_error)` | `argument` is a `double` value close to `a_double` (absolute error <= `max_abs_error`), treating two NaNs as equal. | |
|||
| `NanSensitiveFloatNear(a_float, max_abs_error)` | `argument` is a `float` value close to `a_float` (absolute error <= `max_abs_error`), treating two NaNs as equal. | |
|||
|
|||
## String Matchers |
|||
|
|||
The `argument` can be either a C string or a C++ string object: |
|||
|
|||
| Matcher | Description | |
|||
| :---------------------- | :------------------------------------------------- | |
|||
| `ContainsRegex(string)` | `argument` matches the given regular expression. | |
|||
| `EndsWith(suffix)` | `argument` ends with string `suffix`. | |
|||
| `HasSubstr(string)` | `argument` contains `string` as a sub-string. | |
|||
| `IsEmpty()` | `argument` is an empty string. | |
|||
| `MatchesRegex(string)` | `argument` matches the given regular expression with the match starting at the first character and ending at the last character. | |
|||
| `StartsWith(prefix)` | `argument` starts with string `prefix`. | |
|||
| `StrCaseEq(string)` | `argument` is equal to `string`, ignoring case. | |
|||
| `StrCaseNe(string)` | `argument` is not equal to `string`, ignoring case. | |
|||
| `StrEq(string)` | `argument` is equal to `string`. | |
|||
| `StrNe(string)` | `argument` is not equal to `string`. | |
|||
|
|||
`ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They |
|||
use the regular expression syntax defined |
|||
[here](../advanced.md#regular-expression-syntax). All of these matchers, except |
|||
`ContainsRegex()` and `MatchesRegex()` work for wide strings as well. |
|||
|
|||
## Container Matchers |
|||
|
|||
Most STL-style containers support `==`, so you can use `Eq(expected_container)` |
|||
or simply `expected_container` to match a container exactly. If you want to |
|||
write the elements in-line, match them more flexibly, or get more informative |
|||
messages, you can use: |
|||
|
|||
| Matcher | Description | |
|||
| :---------------------------------------- | :------------------------------- | |
|||
| `BeginEndDistanceIs(m)` | `argument` is a container whose `begin()` and `end()` iterators are separated by a number of increments matching `m`. E.g. `BeginEndDistanceIs(2)` or `BeginEndDistanceIs(Lt(2))`. For containers that define a `size()` method, `SizeIs(m)` may be more efficient. | |
|||
| `ContainerEq(container)` | The same as `Eq(container)` except that the failure message also includes which elements are in one container but not the other. | |
|||
| `Contains(e)` | `argument` contains an element that matches `e`, which can be either a value or a matcher. | |
|||
| `Each(e)` | `argument` is a container where *every* element matches `e`, which can be either a value or a matcher. | |
|||
| `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, where the *i*-th element matches `ei`, which can be a value or a matcher. | |
|||
| `ElementsAreArray({e0, e1, ..., en})`, `ElementsAreArray(a_container)`, `ElementsAreArray(begin, end)`, `ElementsAreArray(array)`, or `ElementsAreArray(array, count)` | The same as `ElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, iterator range, or C-style array. | |
|||
| `IsEmpty()` | `argument` is an empty container (`container.empty()`). | |
|||
| `IsSubsetOf({e0, e1, ..., en})`, `IsSubsetOf(a_container)`, `IsSubsetOf(begin, end)`, `IsSubsetOf(array)`, or `IsSubsetOf(array, count)` | `argument` matches `UnorderedElementsAre(x0, x1, ..., xk)` for some subset `{x0, x1, ..., xk}` of the expected matchers. | |
|||
| `IsSupersetOf({e0, e1, ..., en})`, `IsSupersetOf(a_container)`, `IsSupersetOf(begin, end)`, `IsSupersetOf(array)`, or `IsSupersetOf(array, count)` | Some subset of `argument` matches `UnorderedElementsAre(`expected matchers`)`. | |
|||
| `Pointwise(m, container)`, `Pointwise(m, {e0, e1, ..., en})` | `argument` contains the same number of elements as in `container`, and for all i, (the i-th element in `argument`, the i-th element in `container`) match `m`, which is a matcher on 2-tuples. E.g. `Pointwise(Le(), upper_bounds)` verifies that each element in `argument` doesn't exceed the corresponding element in `upper_bounds`. See more detail below. | |
|||
| `SizeIs(m)` | `argument` is a container whose size matches `m`. E.g. `SizeIs(2)` or `SizeIs(Lt(2))`. | |
|||
| `UnorderedElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, and under *some* permutation of the elements, each element matches an `ei` (for a different `i`), which can be a value or a matcher. | |
|||
| `UnorderedElementsAreArray({e0, e1, ..., en})`, `UnorderedElementsAreArray(a_container)`, `UnorderedElementsAreArray(begin, end)`, `UnorderedElementsAreArray(array)`, or `UnorderedElementsAreArray(array, count)` | The same as `UnorderedElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, iterator range, or C-style array. | |
|||
| `UnorderedPointwise(m, container)`, `UnorderedPointwise(m, {e0, e1, ..., en})` | Like `Pointwise(m, container)`, but ignores the order of elements. | |
|||
| `WhenSorted(m)` | When `argument` is sorted using the `<` operator, it matches container matcher `m`. E.g. `WhenSorted(ElementsAre(1, 2, 3))` verifies that `argument` contains elements 1, 2, and 3, ignoring order. | |
|||
| `WhenSortedBy(comparator, m)` | The same as `WhenSorted(m)`, except that the given comparator instead of `<` is used to sort `argument`. E.g. `WhenSortedBy(std::greater(), ElementsAre(3, 2, 1))`. | |
|||
|
|||
**Notes:** |
|||
|
|||
* These matchers can also match: |
|||
1. a native array passed by reference (e.g. in `Foo(const int (&a)[5])`), |
|||
and |
|||
2. an array passed as a pointer and a count (e.g. in `Bar(const T* buffer, |
|||
int len)` -- see [Multi-argument Matchers](#MultiArgMatchers)). |
|||
* The array being matched may be multi-dimensional (i.e. its elements can be |
|||
arrays). |
|||
* `m` in `Pointwise(m, ...)` and `UnorderedPointwise(m, ...)` should be a |
|||
matcher for `::std::tuple<T, U>` where `T` and `U` are the element type of |
|||
the actual container and the expected container, respectively. For example, |
|||
to compare two `Foo` containers where `Foo` doesn't support `operator==`, |
|||
one might write: |
|||
|
|||
```cpp |
|||
using ::std::get; |
|||
MATCHER(FooEq, "") { |
|||
return std::get<0>(arg).Equals(std::get<1>(arg)); |
|||
} |
|||
... |
|||
EXPECT_THAT(actual_foos, Pointwise(FooEq(), expected_foos)); |
|||
``` |
|||
|
|||
## Member Matchers |
|||
|
|||
| Matcher | Description | |
|||
| :------------------------------ | :----------------------------------------- | |
|||
| `Field(&class::field, m)` | `argument.field` (or `argument->field` when `argument` is a plain pointer) matches matcher `m`, where `argument` is an object of type _class_. | |
|||
| `Field(field_name, &class::field, m)` | The same as the two-parameter version, but provides a better error message. | |
|||
| `Key(e)` | `argument.first` matches `e`, which can be either a value or a matcher. E.g. `Contains(Key(Le(5)))` can verify that a `map` contains a key `<= 5`. | |
|||
| `Pair(m1, m2)` | `argument` is an `std::pair` whose `first` field matches `m1` and `second` field matches `m2`. | |
|||
| `FieldsAre(m...)` | `argument` is a compatible object where each field matches piecewise with the matchers `m...`. A compatible object is any that supports the `std::tuple_size<Obj>`+`get<I>(obj)` protocol. In C++17 and up this also supports types compatible with structured bindings, like aggregates. | |
|||
| `Property(&class::property, m)` | `argument.property()` (or `argument->property()` when `argument` is a plain pointer) matches matcher `m`, where `argument` is an object of type _class_. The method `property()` must take no argument and be declared as `const`. | |
|||
| `Property(property_name, &class::property, m)` | The same as the two-parameter version, but provides a better error message. |
|||
|
|||
**Notes:** |
|||
|
|||
* You can use `FieldsAre()` to match any type that supports structured |
|||
bindings, such as `std::tuple`, `std::pair`, `std::array`, and aggregate |
|||
types. For example: |
|||
|
|||
```cpp |
|||
std::tuple<int, std::string> my_tuple{7, "hello world"}; |
|||
EXPECT_THAT(my_tuple, FieldsAre(Ge(0), HasSubstr("hello"))); |
|||
|
|||
struct MyStruct { |
|||
int value = 42; |
|||
std::string greeting = "aloha"; |
|||
}; |
|||
MyStruct s; |
|||
EXPECT_THAT(s, FieldsAre(42, "aloha")); |
|||
``` |
|||
|
|||
* Don't use `Property()` against member functions that you do not own, because |
|||
taking addresses of functions is fragile and generally not part of the |
|||
contract of the function. |
|||
|
|||
## Matching the Result of a Function, Functor, or Callback |
|||
|
|||
| Matcher | Description | |
|||
| :--------------- | :------------------------------------------------ | |
|||
| `ResultOf(f, m)` | `f(argument)` matches matcher `m`, where `f` is a function or functor. | |
|||
|
|||
## Pointer Matchers |
|||
|
|||
| Matcher | Description | |
|||
| :------------------------ | :---------------------------------------------- | |
|||
| `Address(m)` | the result of `std::addressof(argument)` matches `m`. | |
|||
| `Pointee(m)` | `argument` (either a smart pointer or a raw pointer) points to a value that matches matcher `m`. | |
|||
| `Pointer(m)` | `argument` (either a smart pointer or a raw pointer) contains a pointer that matches `m`. `m` will match against the raw pointer regardless of the type of `argument`. | |
|||
| `WhenDynamicCastTo<T>(m)` | when `argument` is passed through `dynamic_cast<T>()`, it matches matcher `m`. | |
|||
|
|||
## Multi-argument Matchers {#MultiArgMatchers} |
|||
|
|||
Technically, all matchers match a *single* value. A "multi-argument" matcher is |
|||
just one that matches a *tuple*. The following matchers can be used to match a |
|||
tuple `(x, y)`: |
|||
|
|||
Matcher | Description |
|||
:------ | :---------- |
|||
`Eq()` | `x == y` |
|||
`Ge()` | `x >= y` |
|||
`Gt()` | `x > y` |
|||
`Le()` | `x <= y` |
|||
`Lt()` | `x < y` |
|||
`Ne()` | `x != y` |
|||
|
|||
You can use the following selectors to pick a subset of the arguments (or |
|||
reorder them) to participate in the matching: |
|||
|
|||
| Matcher | Description | |
|||
| :------------------------- | :---------------------------------------------- | |
|||
| `AllArgs(m)` | Equivalent to `m`. Useful as syntactic sugar in `.With(AllArgs(m))`. | |
|||
| `Args<N1, N2, ..., Nk>(m)` | The tuple of the `k` selected (using 0-based indices) arguments matches `m`, e.g. `Args<1, 2>(Eq())`. | |
|||
|
|||
## Composite Matchers |
|||
|
|||
You can make a matcher from one or more other matchers: |
|||
|
|||
| Matcher | Description | |
|||
| :------------------------------- | :-------------------------------------- | |
|||
| `AllOf(m1, m2, ..., mn)` | `argument` matches all of the matchers `m1` to `mn`. | |
|||
| `AllOfArray({m0, m1, ..., mn})`, `AllOfArray(a_container)`, `AllOfArray(begin, end)`, `AllOfArray(array)`, or `AllOfArray(array, count)` | The same as `AllOf()` except that the matchers come from an initializer list, STL-style container, iterator range, or C-style array. | |
|||
| `AnyOf(m1, m2, ..., mn)` | `argument` matches at least one of the matchers `m1` to `mn`. | |
|||
| `AnyOfArray({m0, m1, ..., mn})`, `AnyOfArray(a_container)`, `AnyOfArray(begin, end)`, `AnyOfArray(array)`, or `AnyOfArray(array, count)` | The same as `AnyOf()` except that the matchers come from an initializer list, STL-style container, iterator range, or C-style array. | |
|||
| `Not(m)` | `argument` doesn't match matcher `m`. | |
|||
|
|||
## Adapters for Matchers |
|||
|
|||
| Matcher | Description | |
|||
| :---------------------- | :------------------------------------ | |
|||
| `MatcherCast<T>(m)` | casts matcher `m` to type `Matcher<T>`. | |
|||
| `SafeMatcherCast<T>(m)` | [safely casts](../gmock_cook_book.md#SafeMatcherCast) matcher `m` to type `Matcher<T>`. | |
|||
| `Truly(predicate)` | `predicate(argument)` returns something considered by C++ to be true, where `predicate` is a function or functor. | |
|||
|
|||
`AddressSatisfies(callback)` and `Truly(callback)` take ownership of `callback`, |
|||
which must be a permanent callback. |
|||
|
|||
## Using Matchers as Predicates {#MatchersAsPredicatesCheat} |
|||
|
|||
| Matcher | Description | |
|||
| :---------------------------- | :------------------------------------------ | |
|||
| `Matches(m)(value)` | evaluates to `true` if `value` matches `m`. You can use `Matches(m)` alone as a unary functor. | |
|||
| `ExplainMatchResult(m, value, result_listener)` | evaluates to `true` if `value` matches `m`, explaining the result to `result_listener`. | |
|||
| `Value(value, m)` | evaluates to `true` if `value` matches `m`. | |
|||
|
|||
## Defining Matchers |
|||
|
|||
| Matcher | Description | |
|||
| :----------------------------------- | :------------------------------------ | |
|||
| `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. | |
|||
| `MATCHER_P(IsDivisibleBy, n, "") { *result_listener << "where the remainder is " << (arg % n); return (arg % n) == 0; }` | Defines a matcher `IsDivisibleBy(n)` to match a number divisible by `n`. | |
|||
| `MATCHER_P2(IsBetween, a, b, absl::StrCat(negation ? "isn't" : "is", " between ", PrintToString(a), " and ", PrintToString(b))) { return a <= arg && arg <= b; }` | Defines a matcher `IsBetween(a, b)` to match a value in the range [`a`, `b`]. | |
|||
|
|||
**Notes:** |
|||
|
|||
1. The `MATCHER*` macros cannot be used inside a function or class. |
|||
2. The matcher body must be *purely functional* (i.e. it cannot have any side |
|||
effect, and the result must not depend on anything other than the value |
|||
being matched and the matcher parameters). |
|||
3. You can use `PrintToString(x)` to convert a value `x` of any type to a |
|||
string. |
|||
4. You can use `ExplainMatchResult()` in a custom matcher to wrap another |
|||
matcher, for example: |
|||
|
|||
```cpp |
|||
MATCHER_P(NestedPropertyMatches, matcher, "") { |
|||
return ExplainMatchResult(matcher, arg.nested().property(), result_listener); |
|||
} |
|||
``` |
@ -0,0 +1,587 @@ |
|||
# Mocking Reference |
|||
|
|||
This page lists the facilities provided by GoogleTest for creating and working |
|||
with mock objects. To use them, include the header |
|||
`gmock/gmock.h`. |
|||
|
|||
## Macros {#macros} |
|||
|
|||
GoogleTest defines the following macros for working with mocks. |
|||
|
|||
### MOCK_METHOD {#MOCK_METHOD} |
|||
|
|||
`MOCK_METHOD(`*`return_type`*`,`*`method_name`*`, (`*`args...`*`));` \ |
|||
`MOCK_METHOD(`*`return_type`*`,`*`method_name`*`, (`*`args...`*`), |
|||
(`*`specs...`*`));` |
|||
|
|||
Defines a mock method *`method_name`* with arguments `(`*`args...`*`)` and |
|||
return type *`return_type`* within a mock class. |
|||
|
|||
The parameters of `MOCK_METHOD` mirror the method declaration. The optional |
|||
fourth parameter *`specs...`* is a comma-separated list of qualifiers. The |
|||
following qualifiers are accepted: |
|||
|
|||
| Qualifier | Meaning | |
|||
| -------------------------- | -------------------------------------------- | |
|||
| `const` | Makes the mocked method a `const` method. Required if overriding a `const` method. | |
|||
| `override` | Marks the method with `override`. Recommended if overriding a `virtual` method. | |
|||
| `noexcept` | Marks the method with `noexcept`. Required if overriding a `noexcept` method. | |
|||
| `Calltype(`*`calltype`*`)` | Sets the call type for the method, for example `Calltype(STDMETHODCALLTYPE)`. Useful on Windows. | |
|||
| `ref(`*`qualifier`*`)` | Marks the method with the given reference qualifier, for example `ref(&)` or `ref(&&)`. Required if overriding a method that has a reference qualifier. | |
|||
|
|||
Note that commas in arguments prevent `MOCK_METHOD` from parsing the arguments |
|||
correctly if they are not appropriately surrounded by parentheses. See the |
|||
following example: |
|||
|
|||
```cpp |
|||
class MyMock { |
|||
public: |
|||
// The following 2 lines will not compile due to commas in the arguments: |
|||
MOCK_METHOD(std::pair<bool, int>, GetPair, ()); // Error! |
|||
MOCK_METHOD(bool, CheckMap, (std::map<int, double>, bool)); // Error! |
|||
|
|||
// One solution - wrap arguments that contain commas in parentheses: |
|||
MOCK_METHOD((std::pair<bool, int>), GetPair, ()); |
|||
MOCK_METHOD(bool, CheckMap, ((std::map<int, double>), bool)); |
|||
|
|||
// Another solution - use type aliases: |
|||
using BoolAndInt = std::pair<bool, int>; |
|||
MOCK_METHOD(BoolAndInt, GetPair, ()); |
|||
using MapIntDouble = std::map<int, double>; |
|||
MOCK_METHOD(bool, CheckMap, (MapIntDouble, bool)); |
|||
}; |
|||
``` |
|||
|
|||
`MOCK_METHOD` must be used in the `public:` section of a mock class definition, |
|||
regardless of whether the method being mocked is `public`, `protected`, or |
|||
`private` in the base class. |
|||
|
|||
### EXPECT_CALL {#EXPECT_CALL} |
|||
|
|||
`EXPECT_CALL(`*`mock_object`*`,`*`method_name`*`(`*`matchers...`*`))` |
|||
|
|||
Creates an [expectation](../gmock_for_dummies.md#setting-expectations) that the |
|||
method *`method_name`* of the object *`mock_object`* is called with arguments |
|||
that match the given matchers *`matchers...`*. `EXPECT_CALL` must precede any |
|||
code that exercises the mock object. |
|||
|
|||
The parameter *`matchers...`* is a comma-separated list of |
|||
[matchers](../gmock_for_dummies.md#matchers-what-arguments-do-we-expect) that |
|||
correspond to each argument of the method *`method_name`*. The expectation will |
|||
apply only to calls of *`method_name`* whose arguments match all of the |
|||
matchers. If `(`*`matchers...`*`)` is omitted, the expectation behaves as if |
|||
each argument's matcher were a [wildcard matcher (`_`)](matchers.md#wildcard). |
|||
See the [Matchers Reference](matchers.md) for a list of all built-in matchers. |
|||
|
|||
The following chainable clauses can be used to modify the expectation, and they |
|||
must be used in the following order: |
|||
|
|||
```cpp |
|||
EXPECT_CALL(mock_object, method_name(matchers...)) |
|||
.With(multi_argument_matcher) // Can be used at most once |
|||
.Times(cardinality) // Can be used at most once |
|||
.InSequence(sequences...) // Can be used any number of times |
|||
.After(expectations...) // Can be used any number of times |
|||
.WillOnce(action) // Can be used any number of times |
|||
.WillRepeatedly(action) // Can be used at most once |
|||
.RetiresOnSaturation(); // Can be used at most once |
|||
``` |
|||
|
|||
See details for each modifier clause below. |
|||
|
|||
#### With {#EXPECT_CALL.With} |
|||
|
|||
`.With(`*`multi_argument_matcher`*`)` |
|||
|
|||
Restricts the expectation to apply only to mock function calls whose arguments |
|||
as a whole match the multi-argument matcher *`multi_argument_matcher`*. |
|||
|
|||
GoogleTest passes all of the arguments as one tuple into the matcher. The |
|||
parameter *`multi_argument_matcher`* must thus be a matcher of type |
|||
`Matcher<std::tuple<A1, ..., An>>`, where `A1, ..., An` are the types of the |
|||
function arguments. |
|||
|
|||
For example, the following code sets the expectation that |
|||
`my_mock.SetPosition()` is called with any two arguments, the first argument |
|||
being less than the second: |
|||
|
|||
```cpp |
|||
using ::testing::_; |
|||
using ::testing::Lt; |
|||
... |
|||
EXPECT_CALL(my_mock, SetPosition(_, _)) |
|||
.With(Lt()); |
|||
``` |
|||
|
|||
GoogleTest provides some built-in matchers for 2-tuples, including the `Lt()` |
|||
matcher above. See [Multi-argument Matchers](matchers.md#MultiArgMatchers). |
|||
|
|||
The `With` clause can be used at most once on an expectation and must be the |
|||
first clause. |
|||
|
|||
#### Times {#EXPECT_CALL.Times} |
|||
|
|||
`.Times(`*`cardinality`*`)` |
|||
|
|||
Specifies how many times the mock function call is expected. |
|||
|
|||
The parameter *`cardinality`* represents the number of expected calls and can be |
|||
one of the following, all defined in the `::testing` namespace: |
|||
|
|||
| Cardinality | Meaning | |
|||
| ------------------- | --------------------------------------------------- | |
|||
| `AnyNumber()` | The function can be called any number of times. | |
|||
| `AtLeast(n)` | The function call is expected at least *n* times. | |
|||
| `AtMost(n)` | The function call is expected at most *n* times. | |
|||
| `Between(m, n)` | The function call is expected between *m* and *n* times, inclusive. | |
|||
| `Exactly(n)` or `n` | The function call is expected exactly *n* times. If *n* is 0, the call should never happen. | |
|||
|
|||
If the `Times` clause is omitted, GoogleTest infers the cardinality as follows: |
|||
|
|||
* If neither [`WillOnce`](#EXPECT_CALL.WillOnce) nor |
|||
[`WillRepeatedly`](#EXPECT_CALL.WillRepeatedly) are specified, the inferred |
|||
cardinality is `Times(1)`. |
|||
* If there are *n* `WillOnce` clauses and no `WillRepeatedly` clause, where |
|||
*n* >= 1, the inferred cardinality is `Times(n)`. |
|||
* If there are *n* `WillOnce` clauses and one `WillRepeatedly` clause, where |
|||
*n* >= 0, the inferred cardinality is `Times(AtLeast(n))`. |
|||
|
|||
The `Times` clause can be used at most once on an expectation. |
|||
|
|||
#### InSequence {#EXPECT_CALL.InSequence} |
|||
|
|||
`.InSequence(`*`sequences...`*`)` |
|||
|
|||
Specifies that the mock function call is expected in a certain sequence. |
|||
|
|||
The parameter *`sequences...`* is any number of [`Sequence`](#Sequence) objects. |
|||
Expected calls assigned to the same sequence are expected to occur in the order |
|||
the expectations are declared. |
|||
|
|||
For example, the following code sets the expectation that the `Reset()` method |
|||
of `my_mock` is called before both `GetSize()` and `Describe()`, and `GetSize()` |
|||
and `Describe()` can occur in any order relative to each other: |
|||
|
|||
```cpp |
|||
using ::testing::Sequence; |
|||
Sequence s1, s2; |
|||
... |
|||
EXPECT_CALL(my_mock, Reset()) |
|||
.InSequence(s1, s2); |
|||
EXPECT_CALL(my_mock, GetSize()) |
|||
.InSequence(s1); |
|||
EXPECT_CALL(my_mock, Describe()) |
|||
.InSequence(s2); |
|||
``` |
|||
|
|||
The `InSequence` clause can be used any number of times on an expectation. |
|||
|
|||
See also the [`InSequence` class](#InSequence). |
|||
|
|||
#### After {#EXPECT_CALL.After} |
|||
|
|||
`.After(`*`expectations...`*`)` |
|||
|
|||
Specifies that the mock function call is expected to occur after one or more |
|||
other calls. |
|||
|
|||
The parameter *`expectations...`* can be up to five |
|||
[`Expectation`](#Expectation) or [`ExpectationSet`](#ExpectationSet) objects. |
|||
The mock function call is expected to occur after all of the given expectations. |
|||
|
|||
For example, the following code sets the expectation that the `Describe()` |
|||
method of `my_mock` is called only after both `InitX()` and `InitY()` have been |
|||
called. |
|||
|
|||
```cpp |
|||
using ::testing::Expectation; |
|||
... |
|||
Expectation init_x = EXPECT_CALL(my_mock, InitX()); |
|||
Expectation init_y = EXPECT_CALL(my_mock, InitY()); |
|||
EXPECT_CALL(my_mock, Describe()) |
|||
.After(init_x, init_y); |
|||
``` |
|||
|
|||
The `ExpectationSet` object is helpful when the number of prerequisites for an |
|||
expectation is large or variable, for example: |
|||
|
|||
```cpp |
|||
using ::testing::ExpectationSet; |
|||
... |
|||
ExpectationSet all_inits; |
|||
// Collect all expectations of InitElement() calls |
|||
for (int i = 0; i < element_count; i++) { |
|||
all_inits += EXPECT_CALL(my_mock, InitElement(i)); |
|||
} |
|||
EXPECT_CALL(my_mock, Describe()) |
|||
.After(all_inits); // Expect Describe() call after all InitElement() calls |
|||
``` |
|||
|
|||
The `After` clause can be used any number of times on an expectation. |
|||
|
|||
#### WillOnce {#EXPECT_CALL.WillOnce} |
|||
|
|||
`.WillOnce(`*`action`*`)` |
|||
|
|||
Specifies the mock function's actual behavior when invoked, for a single |
|||
matching function call. |
|||
|
|||
The parameter *`action`* represents the |
|||
[action](../gmock_for_dummies.md#actions-what-should-it-do) that the function |
|||
call will perform. See the [Actions Reference](actions.md) for a list of |
|||
built-in actions. |
|||
|
|||
The use of `WillOnce` implicitly sets a cardinality on the expectation when |
|||
`Times` is not specified. See [`Times`](#EXPECT_CALL.Times). |
|||
|
|||
Each matching function call will perform the next action in the order declared. |
|||
For example, the following code specifies that `my_mock.GetNumber()` is expected |
|||
to be called exactly 3 times and will return `1`, `2`, and `3` respectively on |
|||
the first, second, and third calls: |
|||
|
|||
```cpp |
|||
using ::testing::Return; |
|||
... |
|||
EXPECT_CALL(my_mock, GetNumber()) |
|||
.WillOnce(Return(1)) |
|||
.WillOnce(Return(2)) |
|||
.WillOnce(Return(3)); |
|||
``` |
|||
|
|||
The `WillOnce` clause can be used any number of times on an expectation. |
|||
|
|||
#### WillRepeatedly {#EXPECT_CALL.WillRepeatedly} |
|||
|
|||
`.WillRepeatedly(`*`action`*`)` |
|||
|
|||
Specifies the mock function's actual behavior when invoked, for all subsequent |
|||
matching function calls. Takes effect after the actions specified in the |
|||
[`WillOnce`](#EXPECT_CALL.WillOnce) clauses, if any, have been performed. |
|||
|
|||
The parameter *`action`* represents the |
|||
[action](../gmock_for_dummies.md#actions-what-should-it-do) that the function |
|||
call will perform. See the [Actions Reference](actions.md) for a list of |
|||
built-in actions. |
|||
|
|||
The use of `WillRepeatedly` implicitly sets a cardinality on the expectation |
|||
when `Times` is not specified. See [`Times`](#EXPECT_CALL.Times). |
|||
|
|||
If any `WillOnce` clauses have been specified, matching function calls will |
|||
perform those actions before the action specified by `WillRepeatedly`. See the |
|||
following example: |
|||
|
|||
```cpp |
|||
using ::testing::Return; |
|||
... |
|||
EXPECT_CALL(my_mock, GetName()) |
|||
.WillRepeatedly(Return("John Doe")); // Return "John Doe" on all calls |
|||
|
|||
EXPECT_CALL(my_mock, GetNumber()) |
|||
.WillOnce(Return(42)) // Return 42 on the first call |
|||
.WillRepeatedly(Return(7)); // Return 7 on all subsequent calls |
|||
``` |
|||
|
|||
The `WillRepeatedly` clause can be used at most once on an expectation. |
|||
|
|||
#### RetiresOnSaturation {#EXPECT_CALL.RetiresOnSaturation} |
|||
|
|||
`.RetiresOnSaturation()` |
|||
|
|||
Indicates that the expectation will no longer be active after the expected |
|||
number of matching function calls has been reached. |
|||
|
|||
The `RetiresOnSaturation` clause is only meaningful for expectations with an |
|||
upper-bounded cardinality. The expectation will *retire* (no longer match any |
|||
function calls) after it has been *saturated* (the upper bound has been |
|||
reached). See the following example: |
|||
|
|||
```cpp |
|||
using ::testing::_; |
|||
using ::testing::AnyNumber; |
|||
... |
|||
EXPECT_CALL(my_mock, SetNumber(_)) // Expectation 1 |
|||
.Times(AnyNumber()); |
|||
EXPECT_CALL(my_mock, SetNumber(7)) // Expectation 2 |
|||
.Times(2) |
|||
.RetiresOnSaturation(); |
|||
``` |
|||
|
|||
In the above example, the first two calls to `my_mock.SetNumber(7)` match |
|||
expectation 2, which then becomes inactive and no longer matches any calls. A |
|||
third call to `my_mock.SetNumber(7)` would then match expectation 1. Without |
|||
`RetiresOnSaturation()` on expectation 2, a third call to `my_mock.SetNumber(7)` |
|||
would match expectation 2 again, producing a failure since the limit of 2 calls |
|||
was exceeded. |
|||
|
|||
The `RetiresOnSaturation` clause can be used at most once on an expectation and |
|||
must be the last clause. |
|||
|
|||
### ON_CALL {#ON_CALL} |
|||
|
|||
`ON_CALL(`*`mock_object`*`,`*`method_name`*`(`*`matchers...`*`))` |
|||
|
|||
Defines what happens when the method *`method_name`* of the object |
|||
*`mock_object`* is called with arguments that match the given matchers |
|||
*`matchers...`*. Requires a modifier clause to specify the method's behavior. |
|||
*Does not* set any expectations that the method will be called. |
|||
|
|||
The parameter *`matchers...`* is a comma-separated list of |
|||
[matchers](../gmock_for_dummies.md#matchers-what-arguments-do-we-expect) that |
|||
correspond to each argument of the method *`method_name`*. The `ON_CALL` |
|||
specification will apply only to calls of *`method_name`* whose arguments match |
|||
all of the matchers. If `(`*`matchers...`*`)` is omitted, the behavior is as if |
|||
each argument's matcher were a [wildcard matcher (`_`)](matchers.md#wildcard). |
|||
See the [Matchers Reference](matchers.md) for a list of all built-in matchers. |
|||
|
|||
The following chainable clauses can be used to set the method's behavior, and |
|||
they must be used in the following order: |
|||
|
|||
```cpp |
|||
ON_CALL(mock_object, method_name(matchers...)) |
|||
.With(multi_argument_matcher) // Can be used at most once |
|||
.WillByDefault(action); // Required |
|||
``` |
|||
|
|||
See details for each modifier clause below. |
|||
|
|||
#### With {#ON_CALL.With} |
|||
|
|||
`.With(`*`multi_argument_matcher`*`)` |
|||
|
|||
Restricts the specification to only mock function calls whose arguments as a |
|||
whole match the multi-argument matcher *`multi_argument_matcher`*. |
|||
|
|||
GoogleTest passes all of the arguments as one tuple into the matcher. The |
|||
parameter *`multi_argument_matcher`* must thus be a matcher of type |
|||
`Matcher<std::tuple<A1, ..., An>>`, where `A1, ..., An` are the types of the |
|||
function arguments. |
|||
|
|||
For example, the following code sets the default behavior when |
|||
`my_mock.SetPosition()` is called with any two arguments, the first argument |
|||
being less than the second: |
|||
|
|||
```cpp |
|||
using ::testing::_; |
|||
using ::testing::Lt; |
|||
using ::testing::Return; |
|||
... |
|||
ON_CALL(my_mock, SetPosition(_, _)) |
|||
.With(Lt()) |
|||
.WillByDefault(Return(true)); |
|||
``` |
|||
|
|||
GoogleTest provides some built-in matchers for 2-tuples, including the `Lt()` |
|||
matcher above. See [Multi-argument Matchers](matchers.md#MultiArgMatchers). |
|||
|
|||
The `With` clause can be used at most once with each `ON_CALL` statement. |
|||
|
|||
#### WillByDefault {#ON_CALL.WillByDefault} |
|||
|
|||
`.WillByDefault(`*`action`*`)` |
|||
|
|||
Specifies the default behavior of a matching mock function call. |
|||
|
|||
The parameter *`action`* represents the |
|||
[action](../gmock_for_dummies.md#actions-what-should-it-do) that the function |
|||
call will perform. See the [Actions Reference](actions.md) for a list of |
|||
built-in actions. |
|||
|
|||
For example, the following code specifies that by default, a call to |
|||
`my_mock.Greet()` will return `"hello"`: |
|||
|
|||
```cpp |
|||
using ::testing::Return; |
|||
... |
|||
ON_CALL(my_mock, Greet()) |
|||
.WillByDefault(Return("hello")); |
|||
``` |
|||
|
|||
The action specified by `WillByDefault` is superseded by the actions specified |
|||
on a matching `EXPECT_CALL` statement, if any. See the |
|||
[`WillOnce`](#EXPECT_CALL.WillOnce) and |
|||
[`WillRepeatedly`](#EXPECT_CALL.WillRepeatedly) clauses of `EXPECT_CALL`. |
|||
|
|||
The `WillByDefault` clause must be used exactly once with each `ON_CALL` |
|||
statement. |
|||
|
|||
## Classes {#classes} |
|||
|
|||
GoogleTest defines the following classes for working with mocks. |
|||
|
|||
### DefaultValue {#DefaultValue} |
|||
|
|||
`::testing::DefaultValue<T>` |
|||
|
|||
Allows a user to specify the default value for a type `T` that is both copyable |
|||
and publicly destructible (i.e. anything that can be used as a function return |
|||
type). For mock functions with a return type of `T`, this default value is |
|||
returned from function calls that do not specify an action. |
|||
|
|||
Provides the static methods `Set()`, `SetFactory()`, and `Clear()` to manage the |
|||
default value: |
|||
|
|||
```cpp |
|||
// Sets the default value to be returned. T must be copy constructible. |
|||
DefaultValue<T>::Set(value); |
|||
|
|||
// Sets a factory. Will be invoked on demand. T must be move constructible. |
|||
T MakeT(); |
|||
DefaultValue<T>::SetFactory(&MakeT); |
|||
|
|||
// Unsets the default value. |
|||
DefaultValue<T>::Clear(); |
|||
``` |
|||
|
|||
### NiceMock {#NiceMock} |
|||
|
|||
`::testing::NiceMock<T>` |
|||
|
|||
Represents a mock object that suppresses warnings on |
|||
[uninteresting calls](../gmock_cook_book.md#uninteresting-vs-unexpected). The |
|||
template parameter `T` is any mock class, except for another `NiceMock`, |
|||
`NaggyMock`, or `StrictMock`. |
|||
|
|||
Usage of `NiceMock<T>` is analogous to usage of `T`. `NiceMock<T>` is a subclass |
|||
of `T`, so it can be used wherever an object of type `T` is accepted. In |
|||
addition, `NiceMock<T>` can be constructed with any arguments that a constructor |
|||
of `T` accepts. |
|||
|
|||
For example, the following code suppresses warnings on the mock `my_mock` of |
|||
type `MockClass` if a method other than `DoSomething()` is called: |
|||
|
|||
```cpp |
|||
using ::testing::NiceMock; |
|||
... |
|||
NiceMock<MockClass> my_mock("some", "args"); |
|||
EXPECT_CALL(my_mock, DoSomething()); |
|||
... code that uses my_mock ... |
|||
``` |
|||
|
|||
`NiceMock<T>` only works for mock methods defined using the `MOCK_METHOD` macro |
|||
directly in the definition of class `T`. If a mock method is defined in a base |
|||
class of `T`, a warning might still be generated. |
|||
|
|||
`NiceMock<T>` might not work correctly if the destructor of `T` is not virtual. |
|||
|
|||
### NaggyMock {#NaggyMock} |
|||
|
|||
`::testing::NaggyMock<T>` |
|||
|
|||
Represents a mock object that generates warnings on |
|||
[uninteresting calls](../gmock_cook_book.md#uninteresting-vs-unexpected). The |
|||
template parameter `T` is any mock class, except for another `NiceMock`, |
|||
`NaggyMock`, or `StrictMock`. |
|||
|
|||
Usage of `NaggyMock<T>` is analogous to usage of `T`. `NaggyMock<T>` is a |
|||
subclass of `T`, so it can be used wherever an object of type `T` is accepted. |
|||
In addition, `NaggyMock<T>` can be constructed with any arguments that a |
|||
constructor of `T` accepts. |
|||
|
|||
For example, the following code generates warnings on the mock `my_mock` of type |
|||
`MockClass` if a method other than `DoSomething()` is called: |
|||
|
|||
```cpp |
|||
using ::testing::NaggyMock; |
|||
... |
|||
NaggyMock<MockClass> my_mock("some", "args"); |
|||
EXPECT_CALL(my_mock, DoSomething()); |
|||
... code that uses my_mock ... |
|||
``` |
|||
|
|||
Mock objects of type `T` by default behave the same way as `NaggyMock<T>`. |
|||
|
|||
### StrictMock {#StrictMock} |
|||
|
|||
`::testing::StrictMock<T>` |
|||
|
|||
Represents a mock object that generates test failures on |
|||
[uninteresting calls](../gmock_cook_book.md#uninteresting-vs-unexpected). The |
|||
template parameter `T` is any mock class, except for another `NiceMock`, |
|||
`NaggyMock`, or `StrictMock`. |
|||
|
|||
Usage of `StrictMock<T>` is analogous to usage of `T`. `StrictMock<T>` is a |
|||
subclass of `T`, so it can be used wherever an object of type `T` is accepted. |
|||
In addition, `StrictMock<T>` can be constructed with any arguments that a |
|||
constructor of `T` accepts. |
|||
|
|||
For example, the following code generates a test failure on the mock `my_mock` |
|||
of type `MockClass` if a method other than `DoSomething()` is called: |
|||
|
|||
```cpp |
|||
using ::testing::StrictMock; |
|||
... |
|||
StrictMock<MockClass> my_mock("some", "args"); |
|||
EXPECT_CALL(my_mock, DoSomething()); |
|||
... code that uses my_mock ... |
|||
``` |
|||
|
|||
`StrictMock<T>` only works for mock methods defined using the `MOCK_METHOD` |
|||
macro directly in the definition of class `T`. If a mock method is defined in a |
|||
base class of `T`, a failure might not be generated. |
|||
|
|||
`StrictMock<T>` might not work correctly if the destructor of `T` is not |
|||
virtual. |
|||
|
|||
### Sequence {#Sequence} |
|||
|
|||
`::testing::Sequence` |
|||
|
|||
Represents a chronological sequence of expectations. See the |
|||
[`InSequence`](#EXPECT_CALL.InSequence) clause of `EXPECT_CALL` for usage. |
|||
|
|||
### InSequence {#InSequence} |
|||
|
|||
`::testing::InSequence` |
|||
|
|||
An object of this type causes all expectations encountered in its scope to be |
|||
put in an anonymous sequence. |
|||
|
|||
This allows more convenient expression of multiple expectations in a single |
|||
sequence: |
|||
|
|||
```cpp |
|||
using ::testing::InSequence; |
|||
{ |
|||
InSequence seq; |
|||
|
|||
// The following are expected to occur in the order declared. |
|||
EXPECT_CALL(...); |
|||
EXPECT_CALL(...); |
|||
... |
|||
EXPECT_CALL(...); |
|||
} |
|||
``` |
|||
|
|||
The name of the `InSequence` object does not matter. |
|||
|
|||
### Expectation {#Expectation} |
|||
|
|||
`::testing::Expectation` |
|||
|
|||
Represents a mock function call expectation as created by |
|||
[`EXPECT_CALL`](#EXPECT_CALL): |
|||
|
|||
```cpp |
|||
using ::testing::Expectation; |
|||
Expectation my_expectation = EXPECT_CALL(...); |
|||
``` |
|||
|
|||
Useful for specifying sequences of expectations; see the |
|||
[`After`](#EXPECT_CALL.After) clause of `EXPECT_CALL`. |
|||
|
|||
### ExpectationSet {#ExpectationSet} |
|||
|
|||
`::testing::ExpectationSet` |
|||
|
|||
Represents a set of mock function call expectations. |
|||
|
|||
Use the `+=` operator to add [`Expectation`](#Expectation) objects to the set: |
|||
|
|||
```cpp |
|||
using ::testing::ExpectationSet; |
|||
ExpectationSet my_expectations; |
|||
my_expectations += EXPECT_CALL(...); |
|||
``` |
|||
|
|||
Useful for specifying sequences of expectations; see the |
|||
[`After`](#EXPECT_CALL.After) clause of `EXPECT_CALL`. |
1431
resources/3rdparty/googletest/docs/reference/testing.md
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,4 +1,4 @@ |
|||
# Googletest Samples {#samples} |
|||
# Googletest Samples |
|||
|
|||
If you're like us, you'd like to look at |
|||
[googletest samples.](https://github.com/google/googletest/tree/master/googletest/samples) |
@ -0,0 +1,44 @@ |
|||
# Googletest Mocking (gMock) Framework |
|||
|
|||
### Overview |
|||
|
|||
Google's framework for writing and using C++ mock classes. It can help you |
|||
derive better designs of your system and write better tests. |
|||
|
|||
It is inspired by: |
|||
|
|||
* [jMock](http://www.jmock.org/) |
|||
* [EasyMock](http://www.easymock.org/) |
|||
* [Hamcrest](http://code.google.com/p/hamcrest/) |
|||
|
|||
It is designed with C++'s specifics in mind. |
|||
|
|||
gMock: |
|||
|
|||
- Provides a declarative syntax for defining mocks. |
|||
- Can define partial (hybrid) mocks, which are a cross of real and mock |
|||
objects. |
|||
- Handles functions of arbitrary types and overloaded functions. |
|||
- Comes with a rich set of matchers for validating function arguments. |
|||
- Uses an intuitive syntax for controlling the behavior of a mock. |
|||
- Does automatic verification of expectations (no record-and-replay needed). |
|||
- Allows arbitrary (partial) ordering constraints on function calls to be |
|||
expressed. |
|||
- Lets a user extend it by defining new matchers and actions. |
|||
- Does not use exceptions. |
|||
- Is easy to learn and use. |
|||
|
|||
Details and examples can be found here: |
|||
|
|||
* [gMock for Dummies](https://google.github.io/googletest/gmock_for_dummies.html) |
|||
* [Legacy gMock FAQ](https://google.github.io/googletest/gmock_faq.html) |
|||
* [gMock Cookbook](https://google.github.io/googletest/gmock_cook_book.html) |
|||
* [gMock Cheat Sheet](https://google.github.io/googletest/gmock_cheat_sheet.html) |
|||
|
|||
Please note that code under scripts/generator/ is from the |
|||
[cppclean project](http://code.google.com/p/cppclean/) and under the Apache |
|||
License, which is different from GoogleMock's license. |
|||
|
|||
GoogleMock is a part of |
|||
[GoogleTest C++ testing framework](http://github.com/google/googletest/) and a |
|||
subject to the same requirements. |
@ -0,0 +1,10 @@ |
|||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@ |
|||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ |
|||
|
|||
Name: gmock |
|||
Description: GoogleMock (without main() function) |
|||
Version: @PROJECT_VERSION@ |
|||
URL: https://github.com/google/googletest |
|||
Requires: gtest = @PROJECT_VERSION@ |
|||
Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@ |
|||
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ |
@ -0,0 +1,10 @@ |
|||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@ |
|||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ |
|||
|
|||
Name: gmock_main |
|||
Description: GoogleMock (with main() function) |
|||
Version: @PROJECT_VERSION@ |
|||
URL: https://github.com/google/googletest |
|||
Requires: gmock = @PROJECT_VERSION@ |
|||
Libs: -L${libdir} -lgmock_main @CMAKE_THREAD_LIBS_INIT@ |
|||
Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ |
@ -0,0 +1,4 @@ |
|||
# Content Moved |
|||
|
|||
We are working on updates to the GoogleTest documentation, which has moved to |
|||
the top-level [docs](../../docs) directory. |
@ -0,0 +1,479 @@ |
|||
// 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 implements MOCK_METHOD. |
|||
|
|||
// GOOGLETEST_CM0002 DO NOT DELETE |
|||
|
|||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT |
|||
#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT |
|||
|
|||
#include <type_traits> // IWYU pragma: keep |
|||
#include <utility> // IWYU pragma: keep |
|||
|
|||
#include "gmock/gmock-spec-builders.h" |
|||
#include "gmock/internal/gmock-internal-utils.h" |
|||
#include "gmock/internal/gmock-pp.h" |
|||
|
|||
namespace testing { |
|||
namespace internal { |
|||
template <typename T> |
|||
using identity_t = T; |
|||
|
|||
template <typename Pattern> |
|||
struct ThisRefAdjuster { |
|||
template <typename T> |
|||
using AdjustT = typename std::conditional< |
|||
std::is_const<typename std::remove_reference<Pattern>::type>::value, |
|||
typename std::conditional<std::is_lvalue_reference<Pattern>::value, |
|||
const T&, const T&&>::type, |
|||
typename std::conditional<std::is_lvalue_reference<Pattern>::value, T&, |
|||
T&&>::type>::type; |
|||
|
|||
template <typename MockType> |
|||
static AdjustT<MockType> Adjust(const MockType& mock) { |
|||
return static_cast<AdjustT<MockType>>(const_cast<MockType&>(mock)); |
|||
} |
|||
}; |
|||
|
|||
} // namespace internal |
|||
|
|||
// The style guide prohibits "using" statements in a namespace scope |
|||
// inside a header file. However, the FunctionMocker class template |
|||
// is meant to be defined in the ::testing namespace. The following |
|||
// line is just a trick for working around a bug in MSVC 8.0, which |
|||
// cannot handle it if we define FunctionMocker in ::testing. |
|||
using internal::FunctionMocker; |
|||
} // namespace testing |
|||
|
|||
#define MOCK_METHOD(...) \ |
|||
GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) |
|||
|
|||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \ |
|||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) |
|||
|
|||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_2(...) \ |
|||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) |
|||
|
|||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \ |
|||
GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ()) |
|||
|
|||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ |
|||
GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ |
|||
GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ |
|||
GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ |
|||
GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ |
|||
GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ |
|||
GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ |
|||
GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ |
|||
GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ |
|||
GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \ |
|||
GMOCK_INTERNAL_GET_CALLTYPE(_Spec), GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \ |
|||
(GMOCK_INTERNAL_SIGNATURE(_Ret, _Args))) |
|||
|
|||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \ |
|||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) |
|||
|
|||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_6(...) \ |
|||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) |
|||
|
|||
#define GMOCK_INTERNAL_MOCK_METHOD_ARG_7(...) \ |
|||
GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) |
|||
|
|||
#define GMOCK_INTERNAL_WRONG_ARITY(...) \ |
|||
static_assert( \ |
|||
false, \ |
|||
"MOCK_METHOD must be called with 3 or 4 arguments. _Ret, " \ |
|||
"_MethodName, _Args and optionally _Spec. _Args and _Spec must be " \ |
|||
"enclosed in parentheses. If _Ret is a type with unprotected commas, " \ |
|||
"it must also be enclosed in parentheses.") |
|||
|
|||
#define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \ |
|||
static_assert( \ |
|||
GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \ |
|||
GMOCK_PP_STRINGIZE(_Tuple) " should be enclosed in parentheses.") |
|||
|
|||
#define GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE(_N, ...) \ |
|||
static_assert( \ |
|||
std::is_function<__VA_ARGS__>::value, \ |
|||
"Signature must be a function type, maybe return type contains " \ |
|||
"unprotected comma."); \ |
|||
static_assert( \ |
|||
::testing::tuple_size<typename ::testing::internal::Function< \ |
|||
__VA_ARGS__>::ArgumentTuple>::value == _N, \ |
|||
"This method does not take " GMOCK_PP_STRINGIZE( \ |
|||
_N) " arguments. Parenthesize all types with unprotected commas.") |
|||
|
|||
#define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ |
|||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec) |
|||
|
|||
#define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \ |
|||
_Override, _Final, _NoexceptSpec, \ |
|||
_CallType, _RefSpec, _Signature) \ |
|||
typename ::testing::internal::Function<GMOCK_PP_REMOVE_PARENS( \ |
|||
_Signature)>::Result \ |
|||
GMOCK_INTERNAL_EXPAND(_CallType) \ |
|||
_MethodName(GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, _Signature, _N)) \ |
|||
GMOCK_PP_IF(_Constness, const, ) _RefSpec _NoexceptSpec \ |
|||
GMOCK_PP_IF(_Override, override, ) GMOCK_PP_IF(_Final, final, ) { \ |
|||
GMOCK_MOCKER_(_N, _Constness, _MethodName) \ |
|||
.SetOwnerAndName(this, #_MethodName); \ |
|||
return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ |
|||
.Invoke(GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \ |
|||
} \ |
|||
::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \ |
|||
GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_PARAMETER, _Signature, _N)) \ |
|||
GMOCK_PP_IF(_Constness, const, ) _RefSpec { \ |
|||
GMOCK_MOCKER_(_N, _Constness, _MethodName).RegisterOwner(this); \ |
|||
return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ |
|||
.With(GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \ |
|||
} \ |
|||
::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \ |
|||
const ::testing::internal::WithoutMatchers&, \ |
|||
GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \ |
|||
GMOCK_PP_REMOVE_PARENS(_Signature)>*) const _RefSpec _NoexceptSpec { \ |
|||
return ::testing::internal::ThisRefAdjuster<GMOCK_PP_IF( \ |
|||
_Constness, const, ) int _RefSpec>::Adjust(*this) \ |
|||
.gmock_##_MethodName(GMOCK_PP_REPEAT( \ |
|||
GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \ |
|||
} \ |
|||
mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \ |
|||
GMOCK_MOCKER_(_N, _Constness, _MethodName) |
|||
|
|||
#define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__ |
|||
|
|||
// Five Valid modifiers. |
|||
#define GMOCK_INTERNAL_HAS_CONST(_Tuple) \ |
|||
GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple)) |
|||
|
|||
#define GMOCK_INTERNAL_HAS_OVERRIDE(_Tuple) \ |
|||
GMOCK_PP_HAS_COMMA( \ |
|||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_OVERRIDE, ~, _Tuple)) |
|||
|
|||
#define GMOCK_INTERNAL_HAS_FINAL(_Tuple) \ |
|||
GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_FINAL, ~, _Tuple)) |
|||
|
|||
#define GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Tuple) \ |
|||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT, ~, _Tuple) |
|||
|
|||
#define GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT(_i, _, _elem) \ |
|||
GMOCK_PP_IF( \ |
|||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)), \ |
|||
_elem, ) |
|||
|
|||
#define GMOCK_INTERNAL_GET_REF_SPEC(_Tuple) \ |
|||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_REF_SPEC_IF_REF, ~, _Tuple) |
|||
|
|||
#define GMOCK_INTERNAL_REF_SPEC_IF_REF(_i, _, _elem) \ |
|||
GMOCK_PP_IF(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)), \ |
|||
GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), ) |
|||
|
|||
#define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \ |
|||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple) |
|||
|
|||
#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ |
|||
static_assert( \ |
|||
(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \ |
|||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \ |
|||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \ |
|||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \ |
|||
GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \ |
|||
GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \ |
|||
GMOCK_PP_STRINGIZE( \ |
|||
_elem) " cannot be recognized as a valid specification modifier."); |
|||
|
|||
// Modifiers implementation. |
|||
#define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \ |
|||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CONST_I_, _elem) |
|||
|
|||
#define GMOCK_INTERNAL_DETECT_CONST_I_const , |
|||
|
|||
#define GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem) \ |
|||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_OVERRIDE_I_, _elem) |
|||
|
|||
#define GMOCK_INTERNAL_DETECT_OVERRIDE_I_override , |
|||
|
|||
#define GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem) \ |
|||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_FINAL_I_, _elem) |
|||
|
|||
#define GMOCK_INTERNAL_DETECT_FINAL_I_final , |
|||
|
|||
#define GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem) \ |
|||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_NOEXCEPT_I_, _elem) |
|||
|
|||
#define GMOCK_INTERNAL_DETECT_NOEXCEPT_I_noexcept , |
|||
|
|||
#define GMOCK_INTERNAL_DETECT_REF(_i, _, _elem) \ |
|||
GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_REF_I_, _elem) |
|||
|
|||
#define GMOCK_INTERNAL_DETECT_REF_I_ref , |
|||
|
|||
#define GMOCK_INTERNAL_UNPACK_ref(x) x |
|||
|
|||
#define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \ |
|||
GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \ |
|||
GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \ |
|||
(_elem) |
|||
|
|||
// TODO(iserna): GMOCK_INTERNAL_IS_CALLTYPE and |
|||
// GMOCK_INTERNAL_GET_VALUE_CALLTYPE needed more expansions to work on windows |
|||
// maybe they can be simplified somehow. |
|||
#define GMOCK_INTERNAL_IS_CALLTYPE(_arg) \ |
|||
GMOCK_INTERNAL_IS_CALLTYPE_I( \ |
|||
GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) |
|||
#define GMOCK_INTERNAL_IS_CALLTYPE_I(_arg) GMOCK_PP_IS_ENCLOSED_PARENS(_arg) |
|||
|
|||
#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \ |
|||
GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \ |
|||
GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) |
|||
#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \ |
|||
GMOCK_PP_IDENTITY _arg |
|||
|
|||
#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype |
|||
|
|||
// Note: The use of `identity_t` here allows _Ret to represent return types that |
|||
// would normally need to be specified in a different way. For example, a method |
|||
// returning a function pointer must be written as |
|||
// |
|||
// fn_ptr_return_t (*method(method_args_t...))(fn_ptr_args_t...) |
|||
// |
|||
// But we only support placing the return type at the beginning. To handle this, |
|||
// we wrap all calls in identity_t, so that a declaration will be expanded to |
|||
// |
|||
// identity_t<fn_ptr_return_t (*)(fn_ptr_args_t...)> method(method_args_t...) |
|||
// |
|||
// This allows us to work around the syntactic oddities of function/method |
|||
// types. |
|||
#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \ |
|||
::testing::internal::identity_t<GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), \ |
|||
GMOCK_PP_REMOVE_PARENS, \ |
|||
GMOCK_PP_IDENTITY)(_Ret)>( \ |
|||
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args)) |
|||
|
|||
#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \ |
|||
GMOCK_PP_COMMA_IF(_i) \ |
|||
GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_elem), GMOCK_PP_REMOVE_PARENS, \ |
|||
GMOCK_PP_IDENTITY) \ |
|||
(_elem) |
|||
|
|||
#define GMOCK_INTERNAL_PARAMETER(_i, _Signature, _) \ |
|||
GMOCK_PP_COMMA_IF(_i) \ |
|||
GMOCK_INTERNAL_ARG_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature)) \ |
|||
gmock_a##_i |
|||
|
|||
#define GMOCK_INTERNAL_FORWARD_ARG(_i, _Signature, _) \ |
|||
GMOCK_PP_COMMA_IF(_i) \ |
|||
::std::forward<GMOCK_INTERNAL_ARG_O( \ |
|||
_i, GMOCK_PP_REMOVE_PARENS(_Signature))>(gmock_a##_i) |
|||
|
|||
#define GMOCK_INTERNAL_MATCHER_PARAMETER(_i, _Signature, _) \ |
|||
GMOCK_PP_COMMA_IF(_i) \ |
|||
GMOCK_INTERNAL_MATCHER_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature)) \ |
|||
gmock_a##_i |
|||
|
|||
#define GMOCK_INTERNAL_MATCHER_ARGUMENT(_i, _1, _2) \ |
|||
GMOCK_PP_COMMA_IF(_i) \ |
|||
gmock_a##_i |
|||
|
|||
#define GMOCK_INTERNAL_A_MATCHER_ARGUMENT(_i, _Signature, _) \ |
|||
GMOCK_PP_COMMA_IF(_i) \ |
|||
::testing::A<GMOCK_INTERNAL_ARG_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature))>() |
|||
|
|||
#define GMOCK_INTERNAL_ARG_O(_i, ...) \ |
|||
typename ::testing::internal::Function<__VA_ARGS__>::template Arg<_i>::type |
|||
|
|||
#define GMOCK_INTERNAL_MATCHER_O(_i, ...) \ |
|||
const ::testing::Matcher<typename ::testing::internal::Function< \ |
|||
__VA_ARGS__>::template Arg<_i>::type>& |
|||
|
|||
#define MOCK_METHOD0(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 0, __VA_ARGS__) |
|||
#define MOCK_METHOD1(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 1, __VA_ARGS__) |
|||
#define MOCK_METHOD2(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 2, __VA_ARGS__) |
|||
#define MOCK_METHOD3(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 3, __VA_ARGS__) |
|||
#define MOCK_METHOD4(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 4, __VA_ARGS__) |
|||
#define MOCK_METHOD5(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 5, __VA_ARGS__) |
|||
#define MOCK_METHOD6(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 6, __VA_ARGS__) |
|||
#define MOCK_METHOD7(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 7, __VA_ARGS__) |
|||
#define MOCK_METHOD8(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 8, __VA_ARGS__) |
|||
#define MOCK_METHOD9(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 9, __VA_ARGS__) |
|||
#define MOCK_METHOD10(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, , m, 10, __VA_ARGS__) |
|||
|
|||
#define MOCK_CONST_METHOD0(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 0, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD1(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 1, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD2(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 2, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD3(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 3, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD4(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 4, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD5(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 5, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD6(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 6, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD7(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 7, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD8(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 8, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD9(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 9, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD10(m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, , m, 10, __VA_ARGS__) |
|||
|
|||
#define MOCK_METHOD0_T(m, ...) MOCK_METHOD0(m, __VA_ARGS__) |
|||
#define MOCK_METHOD1_T(m, ...) MOCK_METHOD1(m, __VA_ARGS__) |
|||
#define MOCK_METHOD2_T(m, ...) MOCK_METHOD2(m, __VA_ARGS__) |
|||
#define MOCK_METHOD3_T(m, ...) MOCK_METHOD3(m, __VA_ARGS__) |
|||
#define MOCK_METHOD4_T(m, ...) MOCK_METHOD4(m, __VA_ARGS__) |
|||
#define MOCK_METHOD5_T(m, ...) MOCK_METHOD5(m, __VA_ARGS__) |
|||
#define MOCK_METHOD6_T(m, ...) MOCK_METHOD6(m, __VA_ARGS__) |
|||
#define MOCK_METHOD7_T(m, ...) MOCK_METHOD7(m, __VA_ARGS__) |
|||
#define MOCK_METHOD8_T(m, ...) MOCK_METHOD8(m, __VA_ARGS__) |
|||
#define MOCK_METHOD9_T(m, ...) MOCK_METHOD9(m, __VA_ARGS__) |
|||
#define MOCK_METHOD10_T(m, ...) MOCK_METHOD10(m, __VA_ARGS__) |
|||
|
|||
#define MOCK_CONST_METHOD0_T(m, ...) MOCK_CONST_METHOD0(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD1_T(m, ...) MOCK_CONST_METHOD1(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD2_T(m, ...) MOCK_CONST_METHOD2(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD3_T(m, ...) MOCK_CONST_METHOD3(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD4_T(m, ...) MOCK_CONST_METHOD4(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD5_T(m, ...) MOCK_CONST_METHOD5(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD6_T(m, ...) MOCK_CONST_METHOD6(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD7_T(m, ...) MOCK_CONST_METHOD7(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD8_T(m, ...) MOCK_CONST_METHOD8(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD9_T(m, ...) MOCK_CONST_METHOD9(m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD10_T(m, ...) MOCK_CONST_METHOD10(m, __VA_ARGS__) |
|||
|
|||
#define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 0, __VA_ARGS__) |
|||
#define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 1, __VA_ARGS__) |
|||
#define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 2, __VA_ARGS__) |
|||
#define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 3, __VA_ARGS__) |
|||
#define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 4, __VA_ARGS__) |
|||
#define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 5, __VA_ARGS__) |
|||
#define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 6, __VA_ARGS__) |
|||
#define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 7, __VA_ARGS__) |
|||
#define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 8, __VA_ARGS__) |
|||
#define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 9, __VA_ARGS__) |
|||
#define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 10, __VA_ARGS__) |
|||
|
|||
#define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 0, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 1, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 2, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 3, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 4, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 5, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 6, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 7, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 8, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 9, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \ |
|||
GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 10, __VA_ARGS__) |
|||
|
|||
#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD0_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD1_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD2_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD3_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD4_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD5_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD6_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD7_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD8_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD9_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_METHOD10_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
|
|||
#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
#define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ |
|||
MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, __VA_ARGS__) |
|||
|
|||
#define GMOCK_INTERNAL_MOCK_METHODN(constness, ct, Method, args_num, ...) \ |
|||
GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ |
|||
args_num, ::testing::internal::identity_t<__VA_ARGS__>); \ |
|||
GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ |
|||
args_num, Method, GMOCK_PP_NARG0(constness), 0, 0, , ct, , \ |
|||
(::testing::internal::identity_t<__VA_ARGS__>)) |
|||
|
|||
#define GMOCK_MOCKER_(arity, constness, Method) \ |
|||
GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) |
|||
|
|||
#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ |
1320
resources/3rdparty/googletest/googlemock/include/gmock/gmock-matchers.h
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,573 @@ |
|||
// 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 implements some commonly used variadic actions. |
|||
|
|||
// GOOGLETEST_CM0002 DO NOT DELETE |
|||
|
|||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ |
|||
#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ |
|||
|
|||
#include <memory> |
|||
#include <utility> |
|||
|
|||
#include "gmock/gmock-actions.h" |
|||
#include "gmock/internal/gmock-port.h" |
|||
|
|||
// Include any custom callback actions added by the local installation. |
|||
#include "gmock/internal/custom/gmock-generated-actions.h" |
|||
|
|||
// Sometimes you want to give an action explicit template parameters |
|||
// that cannot be inferred from its value parameters. ACTION() and |
|||
// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that |
|||
// and can be viewed as an extension to ACTION() and ACTION_P*(). |
|||
// |
|||
// The syntax: |
|||
// |
|||
// ACTION_TEMPLATE(ActionName, |
|||
// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m), |
|||
// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; } |
|||
// |
|||
// defines an action template that takes m explicit template |
|||
// parameters and n value parameters. name_i is the name of the i-th |
|||
// template parameter, and kind_i specifies whether it's a typename, |
|||
// an integral constant, or a template. p_i is the name of the i-th |
|||
// value parameter. |
|||
// |
|||
// Example: |
|||
// |
|||
// // DuplicateArg<k, T>(output) converts the k-th argument of the mock |
|||
// // function to type T and copies it to *output. |
|||
// ACTION_TEMPLATE(DuplicateArg, |
|||
// HAS_2_TEMPLATE_PARAMS(int, k, typename, T), |
|||
// AND_1_VALUE_PARAMS(output)) { |
|||
// *output = T(::std::get<k>(args)); |
|||
// } |
|||
// ... |
|||
// int n; |
|||
// EXPECT_CALL(mock, Foo(_, _)) |
|||
// .WillOnce(DuplicateArg<1, unsigned char>(&n)); |
|||
// |
|||
// To create an instance of an action template, write: |
|||
// |
|||
// ActionName<t1, ..., t_m>(v1, ..., v_n) |
|||
// |
|||
// where the ts are the template arguments and the vs are the value |
|||
// arguments. The value argument types are inferred by the compiler. |
|||
// If you want to explicitly specify the value argument types, you can |
|||
// provide additional template arguments: |
|||
// |
|||
// ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n) |
|||
// |
|||
// where u_i is the desired type of v_i. |
|||
// |
|||
// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the |
|||
// number of value parameters, but not on the number of template |
|||
// parameters. Without the restriction, the meaning of the following |
|||
// is unclear: |
|||
// |
|||
// OverloadedAction<int, bool>(x); |
|||
// |
|||
// Are we using a single-template-parameter action where 'bool' refers |
|||
// to the type of x, or are we using a two-template-parameter action |
|||
// where the compiler is asked to infer the type of x? |
|||
// |
|||
// Implementation notes: |
|||
// |
|||
// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and |
|||
// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for |
|||
// implementing ACTION_TEMPLATE. The main trick we use is to create |
|||
// new macro invocations when expanding a macro. For example, we have |
|||
// |
|||
// #define ACTION_TEMPLATE(name, template_params, value_params) |
|||
// ... GMOCK_INTERNAL_DECL_##template_params ... |
|||
// |
|||
// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...) |
|||
// to expand to |
|||
// |
|||
// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ... |
|||
// |
|||
// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the |
|||
// preprocessor will continue to expand it to |
|||
// |
|||
// ... typename T ... |
|||
// |
|||
// This technique conforms to the C++ standard and is portable. It |
|||
// allows us to implement action templates using O(N) code, where N is |
|||
// the maximum number of template/value parameters supported. Without |
|||
// using it, we'd have to devote O(N^2) amount of code to implement all |
|||
// combinations of m and n. |
|||
|
|||
// Declares the template parameters. |
|||
#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0 |
|||
#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ |
|||
name1) kind0 name0, kind1 name1 |
|||
#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2) kind0 name0, kind1 name1, kind2 name2 |
|||
#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \ |
|||
kind3 name3 |
|||
#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \ |
|||
kind2 name2, kind3 name3, kind4 name4 |
|||
#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \ |
|||
kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5 |
|||
#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ |
|||
name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ |
|||
kind5 name5, kind6 name6 |
|||
#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ |
|||
kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \ |
|||
kind4 name4, kind5 name5, kind6 name6, kind7 name7 |
|||
#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ |
|||
kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \ |
|||
kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \ |
|||
kind8 name8 |
|||
#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ |
|||
name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ |
|||
name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \ |
|||
kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \ |
|||
kind6 name6, kind7 name7, kind8 name8, kind9 name9 |
|||
|
|||
// Lists the template parameters. |
|||
#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0 |
|||
#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ |
|||
name1) name0, name1 |
|||
#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2) name0, name1, name2 |
|||
#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3) name0, name1, name2, name3 |
|||
#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \ |
|||
name4 |
|||
#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \ |
|||
name2, name3, name4, name5 |
|||
#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ |
|||
name6) name0, name1, name2, name3, name4, name5, name6 |
|||
#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ |
|||
kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7 |
|||
#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ |
|||
kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ |
|||
kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \ |
|||
name6, name7, name8 |
|||
#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ |
|||
name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ |
|||
name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \ |
|||
name3, name4, name5, name6, name7, name8, name9 |
|||
|
|||
// Declares the types of value parameters. |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS() |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \ |
|||
typename p0##_type, typename p1##_type |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \ |
|||
typename p0##_type, typename p1##_type, typename p2##_type |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ |
|||
typename p0##_type, typename p1##_type, typename p2##_type, \ |
|||
typename p3##_type |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ |
|||
typename p0##_type, typename p1##_type, typename p2##_type, \ |
|||
typename p3##_type, typename p4##_type |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ |
|||
typename p0##_type, typename p1##_type, typename p2##_type, \ |
|||
typename p3##_type, typename p4##_type, typename p5##_type |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6) , typename p0##_type, typename p1##_type, typename p2##_type, \ |
|||
typename p3##_type, typename p4##_type, typename p5##_type, \ |
|||
typename p6##_type |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \ |
|||
typename p3##_type, typename p4##_type, typename p5##_type, \ |
|||
typename p6##_type, typename p7##_type |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \ |
|||
typename p3##_type, typename p4##_type, typename p5##_type, \ |
|||
typename p6##_type, typename p7##_type, typename p8##_type |
|||
#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \ |
|||
typename p2##_type, typename p3##_type, typename p4##_type, \ |
|||
typename p5##_type, typename p6##_type, typename p7##_type, \ |
|||
typename p8##_type, typename p9##_type |
|||
|
|||
// Initializes the value parameters. |
|||
#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\ |
|||
() |
|||
#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\ |
|||
(p0##_type gmock_p0) : p0(::std::move(gmock_p0)) |
|||
#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\ |
|||
(p0##_type gmock_p0, p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \ |
|||
p1(::std::move(gmock_p1)) |
|||
#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\ |
|||
(p0##_type gmock_p0, p1##_type gmock_p1, \ |
|||
p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \ |
|||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)) |
|||
#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\ |
|||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
|||
p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \ |
|||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ |
|||
p3(::std::move(gmock_p3)) |
|||
#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\ |
|||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
|||
p3##_type gmock_p3, p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \ |
|||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ |
|||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)) |
|||
#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\ |
|||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
|||
p3##_type gmock_p3, p4##_type gmock_p4, \ |
|||
p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \ |
|||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ |
|||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ |
|||
p5(::std::move(gmock_p5)) |
|||
#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\ |
|||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
|||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
|||
p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \ |
|||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ |
|||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ |
|||
p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)) |
|||
#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\ |
|||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
|||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
|||
p6##_type gmock_p6, p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \ |
|||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ |
|||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ |
|||
p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ |
|||
p7(::std::move(gmock_p7)) |
|||
#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8)\ |
|||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
|||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
|||
p6##_type gmock_p6, p7##_type gmock_p7, \ |
|||
p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \ |
|||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ |
|||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ |
|||
p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ |
|||
p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)) |
|||
#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8, p9)\ |
|||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ |
|||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ |
|||
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ |
|||
p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \ |
|||
p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ |
|||
p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ |
|||
p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ |
|||
p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \ |
|||
p9(::std::move(gmock_p9)) |
|||
|
|||
// Defines the copy constructor |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_0_VALUE_PARAMS() \ |
|||
{} // Avoid https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134 |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_1_VALUE_PARAMS(...) = default; |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_2_VALUE_PARAMS(...) = default; |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_3_VALUE_PARAMS(...) = default; |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_4_VALUE_PARAMS(...) = default; |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_5_VALUE_PARAMS(...) = default; |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_6_VALUE_PARAMS(...) = default; |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_7_VALUE_PARAMS(...) = default; |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_8_VALUE_PARAMS(...) = default; |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_9_VALUE_PARAMS(...) = default; |
|||
#define GMOCK_INTERNAL_DEFN_COPY_AND_10_VALUE_PARAMS(...) = default; |
|||
|
|||
// Declares the fields for storing the value parameters. |
|||
#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS() |
|||
#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0; |
|||
#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \ |
|||
p1##_type p1; |
|||
#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \ |
|||
p1##_type p1; p2##_type p2; |
|||
#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \ |
|||
p1##_type p1; p2##_type p2; p3##_type p3; |
|||
#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ |
|||
p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; |
|||
#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ |
|||
p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ |
|||
p5##_type p5; |
|||
#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ |
|||
p5##_type p5; p6##_type p6; |
|||
#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ |
|||
p5##_type p5; p6##_type p6; p7##_type p7; |
|||
#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ |
|||
p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; |
|||
#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ |
|||
p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \ |
|||
p9##_type p9; |
|||
|
|||
// Lists the value parameters. |
|||
#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS() |
|||
#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0 |
|||
#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1 |
|||
#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2 |
|||
#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3 |
|||
#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \ |
|||
p2, p3, p4 |
|||
#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \ |
|||
p1, p2, p3, p4, p5 |
|||
#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6) p0, p1, p2, p3, p4, p5, p6 |
|||
#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7) p0, p1, p2, p3, p4, p5, p6, p7 |
|||
#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8 |
|||
#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 |
|||
|
|||
// Lists the value parameter types. |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS() |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \ |
|||
p1##_type |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \ |
|||
p1##_type, p2##_type |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ |
|||
p0##_type, p1##_type, p2##_type, p3##_type |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ |
|||
p0##_type, p1##_type, p2##_type, p3##_type, p4##_type |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ |
|||
p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ |
|||
p6##_type |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
|||
p5##_type, p6##_type, p7##_type |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
|||
p5##_type, p6##_type, p7##_type, p8##_type |
|||
#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ |
|||
p5##_type, p6##_type, p7##_type, p8##_type, p9##_type |
|||
|
|||
// Declares the value parameters. |
|||
#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS() |
|||
#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0 |
|||
#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \ |
|||
p1##_type p1 |
|||
#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \ |
|||
p1##_type p1, p2##_type p2 |
|||
#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \ |
|||
p1##_type p1, p2##_type p2, p3##_type p3 |
|||
#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ |
|||
p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4 |
|||
#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ |
|||
p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
|||
p5##_type p5 |
|||
#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ |
|||
p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
|||
p5##_type p5, p6##_type p6 |
|||
#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ |
|||
p5##_type p5, p6##_type p6, p7##_type p7 |
|||
#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
|||
p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8 |
|||
#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ |
|||
p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ |
|||
p9##_type p9 |
|||
|
|||
// The suffix of the class template implementing the action template. |
|||
#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS() |
|||
#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P |
|||
#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2 |
|||
#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3 |
|||
#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4 |
|||
#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5 |
|||
#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6 |
|||
#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7 |
|||
#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7) P8 |
|||
#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8) P9 |
|||
#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ |
|||
p7, p8, p9) P10 |
|||
|
|||
// The name of the class template implementing the action template. |
|||
#define GMOCK_ACTION_CLASS_(name, value_params)\ |
|||
GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) |
|||
|
|||
#define ACTION_TEMPLATE(name, template_params, value_params) \ |
|||
template <GMOCK_INTERNAL_DECL_##template_params \ |
|||
GMOCK_INTERNAL_DECL_TYPE_##value_params> \ |
|||
class GMOCK_ACTION_CLASS_(name, value_params) { \ |
|||
public: \ |
|||
explicit GMOCK_ACTION_CLASS_(name, value_params)( \ |
|||
GMOCK_INTERNAL_DECL_##value_params) \ |
|||
GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ |
|||
= default; , \ |
|||
: impl_(std::make_shared<gmock_Impl>( \ |
|||
GMOCK_INTERNAL_LIST_##value_params)) { }) \ |
|||
GMOCK_ACTION_CLASS_(name, value_params)( \ |
|||
const GMOCK_ACTION_CLASS_(name, value_params)&) noexcept \ |
|||
GMOCK_INTERNAL_DEFN_COPY_##value_params \ |
|||
GMOCK_ACTION_CLASS_(name, value_params)( \ |
|||
GMOCK_ACTION_CLASS_(name, value_params)&&) noexcept \ |
|||
GMOCK_INTERNAL_DEFN_COPY_##value_params \ |
|||
template <typename F> \ |
|||
operator ::testing::Action<F>() const { \ |
|||
return GMOCK_PP_IF( \ |
|||
GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ |
|||
(::testing::internal::MakeAction<F, gmock_Impl>()), \ |
|||
(::testing::internal::MakeAction<F>(impl_))); \ |
|||
} \ |
|||
private: \ |
|||
class gmock_Impl { \ |
|||
public: \ |
|||
explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {} \ |
|||
template <typename function_type, typename return_type, \ |
|||
typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ |
|||
return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ |
|||
GMOCK_INTERNAL_DEFN_##value_params \ |
|||
}; \ |
|||
GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), \ |
|||
, std::shared_ptr<const gmock_Impl> impl_;) \ |
|||
}; \ |
|||
template <GMOCK_INTERNAL_DECL_##template_params \ |
|||
GMOCK_INTERNAL_DECL_TYPE_##value_params> \ |
|||
GMOCK_ACTION_CLASS_(name, value_params)< \ |
|||
GMOCK_INTERNAL_LIST_##template_params \ |
|||
GMOCK_INTERNAL_LIST_TYPE_##value_params> name( \ |
|||
GMOCK_INTERNAL_DECL_##value_params) GTEST_MUST_USE_RESULT_; \ |
|||
template <GMOCK_INTERNAL_DECL_##template_params \ |
|||
GMOCK_INTERNAL_DECL_TYPE_##value_params> \ |
|||
inline GMOCK_ACTION_CLASS_(name, value_params)< \ |
|||
GMOCK_INTERNAL_LIST_##template_params \ |
|||
GMOCK_INTERNAL_LIST_TYPE_##value_params> name( \ |
|||
GMOCK_INTERNAL_DECL_##value_params) { \ |
|||
return GMOCK_ACTION_CLASS_(name, value_params)< \ |
|||
GMOCK_INTERNAL_LIST_##template_params \ |
|||
GMOCK_INTERNAL_LIST_TYPE_##value_params>( \ |
|||
GMOCK_INTERNAL_LIST_##value_params); \ |
|||
} \ |
|||
template <GMOCK_INTERNAL_DECL_##template_params \ |
|||
GMOCK_INTERNAL_DECL_TYPE_##value_params> \ |
|||
template <typename function_type, typename return_type, typename args_type, \ |
|||
GMOCK_ACTION_TEMPLATE_ARGS_NAMES_> \ |
|||
return_type GMOCK_ACTION_CLASS_(name, value_params)< \ |
|||
GMOCK_INTERNAL_LIST_##template_params \ |
|||
GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl::gmock_PerformImpl( \ |
|||
GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const |
|||
|
|||
namespace testing { |
|||
|
|||
// The ACTION*() macros trigger warning C4100 (unreferenced formal |
|||
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in |
|||
// the macro definition, as the warnings are generated when the macro |
|||
// is expanded and macro expansion cannot contain #pragma. Therefore |
|||
// we suppress them here. |
|||
#ifdef _MSC_VER |
|||
# pragma warning(push) |
|||
# pragma warning(disable:4100) |
|||
#endif |
|||
|
|||
namespace internal { |
|||
|
|||
// internal::InvokeArgument - a helper for InvokeArgument action. |
|||
// The basic overloads are provided here for generic functors. |
|||
// Overloads for other custom-callables are provided in the |
|||
// internal/custom/gmock-generated-actions.h header. |
|||
template <typename F, typename... Args> |
|||
auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) { |
|||
return f(args...); |
|||
} |
|||
|
|||
template <std::size_t index, typename... Params> |
|||
struct InvokeArgumentAction { |
|||
template <typename... Args> |
|||
auto operator()(Args&&... args) const -> decltype(internal::InvokeArgument( |
|||
std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)), |
|||
std::declval<const Params&>()...)) { |
|||
internal::FlatTuple<Args&&...> args_tuple(FlatTupleConstructTag{}, |
|||
std::forward<Args>(args)...); |
|||
return params.Apply([&](const Params&... unpacked_params) { |
|||
auto&& callable = args_tuple.template Get<index>(); |
|||
return internal::InvokeArgument( |
|||
std::forward<decltype(callable)>(callable), unpacked_params...); |
|||
}); |
|||
} |
|||
|
|||
internal::FlatTuple<Params...> params; |
|||
}; |
|||
|
|||
} // namespace internal |
|||
|
|||
// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th |
|||
// (0-based) argument, which must be a k-ary callable, of the mock |
|||
// function, with arguments a1, a2, ..., a_k. |
|||
// |
|||
// Notes: |
|||
// |
|||
// 1. The arguments are passed by value by default. If you need to |
|||
// pass an argument by reference, wrap it inside std::ref(). For |
|||
// example, |
|||
// |
|||
// InvokeArgument<1>(5, string("Hello"), std::ref(foo)) |
|||
// |
|||
// passes 5 and string("Hello") by value, and passes foo by |
|||
// reference. |
|||
// |
|||
// 2. If the callable takes an argument by reference but std::ref() is |
|||
// not used, it will receive the reference to a copy of the value, |
|||
// instead of the original value. For example, when the 0-th |
|||
// argument of the mock function takes a const string&, the action |
|||
// |
|||
// InvokeArgument<0>(string("Hello")) |
|||
// |
|||
// makes a copy of the temporary string("Hello") object and passes a |
|||
// reference of the copy, instead of the original temporary object, |
|||
// to the callable. This makes it easy for a user to define an |
|||
// InvokeArgument action from temporary values and have it performed |
|||
// later. |
|||
template <std::size_t index, typename... Params> |
|||
internal::InvokeArgumentAction<index, typename std::decay<Params>::type...> |
|||
InvokeArgument(Params&&... params) { |
|||
return {internal::FlatTuple<typename std::decay<Params>::type...>( |
|||
internal::FlatTupleConstructTag{}, std::forward<Params>(params)...)}; |
|||
} |
|||
|
|||
#ifdef _MSC_VER |
|||
# pragma warning(pop) |
|||
#endif |
|||
|
|||
} // namespace testing |
|||
|
|||
#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ |
@ -0,0 +1,6 @@ |
|||
// GOOGLETEST_CM0002 DO NOT DELETE |
|||
|
|||
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ |
|||
#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ |
|||
|
|||
#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ |
@ -0,0 +1,5 @@ |
|||
# Please Note: |
|||
|
|||
Files in this directory are no longer supported by the maintainers. They |
|||
represent mostly historical artifacts and supported by the community only. There |
|||
is no guarantee whatsoever that these scripts still work. |
1773
resources/3rdparty/googletest/googlemock/scripts/generator/cpp/ast.py
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,986 @@ |
|||
// 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 function mocker classes.
|
|||
#include "gmock/gmock-function-mocker.h"
|
|||
|
|||
#if GTEST_OS_WINDOWS
|
|||
// MSDN says the header file to be included for STDMETHOD is BaseTyps.h but
|
|||
// we are getting compiler errors if we use basetyps.h, hence including
|
|||
// objbase.h for definition of STDMETHOD.
|
|||
# include <objbase.h>
|
|||
#endif // GTEST_OS_WINDOWS
|
|||
|
|||
#include <functional>
|
|||
#include <map>
|
|||
#include <string>
|
|||
#include <type_traits>
|
|||
|
|||
#include "gmock/gmock.h"
|
|||
#include "gtest/gtest.h"
|
|||
|
|||
namespace testing { |
|||
namespace gmock_function_mocker_test { |
|||
|
|||
using testing::_; |
|||
using testing::A; |
|||
using testing::An; |
|||
using testing::AnyNumber; |
|||
using testing::Const; |
|||
using testing::DoDefault; |
|||
using testing::Eq; |
|||
using testing::Lt; |
|||
using testing::MockFunction; |
|||
using testing::Ref; |
|||
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() {} |
|||
|
|||
virtual void VoidReturning(int x) = 0; |
|||
|
|||
virtual int Nullary() = 0; |
|||
virtual bool Unary(int x) = 0; |
|||
virtual long Binary(short x, int y) = 0; // NOLINT
|
|||
virtual int Decimal(bool b, char c, short d, int e, long f, // NOLINT
|
|||
float g, double h, unsigned i, char* j, |
|||
const std::string& k) = 0; |
|||
|
|||
virtual bool TakesNonConstReference(int& n) = 0; // NOLINT
|
|||
virtual std::string TakesConstReference(const int& n) = 0; |
|||
virtual bool TakesConst(const int x) = 0; |
|||
|
|||
virtual int OverloadedOnArgumentNumber() = 0; |
|||
virtual int OverloadedOnArgumentNumber(int n) = 0; |
|||
|
|||
virtual int OverloadedOnArgumentType(int n) = 0; |
|||
virtual char OverloadedOnArgumentType(char c) = 0; |
|||
|
|||
virtual int OverloadedOnConstness() = 0; |
|||
virtual char OverloadedOnConstness() const = 0; |
|||
|
|||
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; |
|||
|
|||
virtual int (*ReturnsFunctionPointer1(int))(bool) = 0; |
|||
using fn_ptr = int (*)(bool); |
|||
virtual fn_ptr ReturnsFunctionPointer2(int) = 0; |
|||
|
|||
virtual int RefQualifiedConstRef() const& = 0; |
|||
virtual int RefQualifiedConstRefRef() const&& = 0; |
|||
virtual int RefQualifiedRef() & = 0; |
|||
virtual int RefQualifiedRefRef() && = 0; |
|||
|
|||
virtual int RefQualifiedOverloaded() const& = 0; |
|||
virtual int RefQualifiedOverloaded() const&& = 0; |
|||
virtual int RefQualifiedOverloaded() & = 0; |
|||
virtual int RefQualifiedOverloaded() && = 0; |
|||
|
|||
#if GTEST_OS_WINDOWS
|
|||
STDMETHOD_(int, CTNullary)() = 0; |
|||
STDMETHOD_(bool, CTUnary)(int x) = 0; |
|||
STDMETHOD_(int, CTDecimal) |
|||
(bool b, char c, short d, int e, long f, // NOLINT
|
|||
float g, double h, unsigned i, char* j, const std::string& k) = 0; |
|||
STDMETHOD_(char, CTConst)(int x) const = 0; |
|||
#endif // GTEST_OS_WINDOWS
|
|||
}; |
|||
|
|||
// Const qualifiers on arguments were once (incorrectly) considered
|
|||
// significant in determining whether two virtual functions had the same
|
|||
// signature. This was fixed in Visual Studio 2008. However, the compiler
|
|||
// still emits a warning that alerts about this change in behavior.
|
|||
#ifdef _MSC_VER
|
|||
# pragma warning(push)
|
|||
# pragma warning(disable : 4373)
|
|||
#endif
|
|||
class MockFoo : public FooInterface { |
|||
public: |
|||
MockFoo() {} |
|||
|
|||
// Makes sure that a mock function parameter can be named.
|
|||
MOCK_METHOD(void, VoidReturning, (int n)); // NOLINT
|
|||
|
|||
MOCK_METHOD(int, Nullary, ()); // NOLINT
|
|||
|
|||
// Makes sure that a mock function parameter can be unnamed.
|
|||
MOCK_METHOD(bool, Unary, (int)); // NOLINT
|
|||
MOCK_METHOD(long, Binary, (short, int)); // NOLINT
|
|||
MOCK_METHOD(int, Decimal, |
|||
(bool, char, short, int, long, float, // NOLINT
|
|||
double, unsigned, char*, const std::string& str), |
|||
(override)); |
|||
|
|||
MOCK_METHOD(bool, TakesNonConstReference, (int&)); // NOLINT
|
|||
MOCK_METHOD(std::string, TakesConstReference, (const int&)); |
|||
MOCK_METHOD(bool, TakesConst, (const int)); // NOLINT
|
|||
|
|||
// Tests that the function return type can contain unprotected comma.
|
|||
MOCK_METHOD((std::map<int, std::string>), ReturnTypeWithComma, (), ()); |
|||
MOCK_METHOD((std::map<int, std::string>), ReturnTypeWithComma, (int), |
|||
(const)); // NOLINT
|
|||
|
|||
MOCK_METHOD(int, OverloadedOnArgumentNumber, ()); // NOLINT
|
|||
MOCK_METHOD(int, OverloadedOnArgumentNumber, (int)); // NOLINT
|
|||
|
|||
MOCK_METHOD(int, OverloadedOnArgumentType, (int)); // NOLINT
|
|||
MOCK_METHOD(char, OverloadedOnArgumentType, (char)); // NOLINT
|
|||
|
|||
MOCK_METHOD(int, OverloadedOnConstness, (), (override)); // NOLINT
|
|||
MOCK_METHOD(char, OverloadedOnConstness, (), (override, const)); // NOLINT
|
|||
|
|||
MOCK_METHOD(int, TypeWithHole, (int (*)()), ()); // NOLINT
|
|||
MOCK_METHOD(int, TypeWithComma, ((const std::map<int, std::string>&))); |
|||
MOCK_METHOD(int, TypeWithTemplatedCopyCtor, |
|||
(const TemplatedCopyable<int>&)); // NOLINT
|
|||
|
|||
MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ()); |
|||
MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ()); |
|||
|
|||
#if GTEST_OS_WINDOWS
|
|||
MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE))); |
|||
MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE))); |
|||
MOCK_METHOD(int, CTDecimal, |
|||
(bool b, char c, short d, int e, long f, float g, double h, |
|||
unsigned i, char* j, const std::string& k), |
|||
(Calltype(STDMETHODCALLTYPE))); |
|||
MOCK_METHOD(char, CTConst, (int), (const, Calltype(STDMETHODCALLTYPE))); |
|||
MOCK_METHOD((std::map<int, std::string>), CTReturnTypeWithComma, (), |
|||
(Calltype(STDMETHODCALLTYPE))); |
|||
#endif // GTEST_OS_WINDOWS
|
|||
|
|||
// Test reference qualified functions.
|
|||
MOCK_METHOD(int, RefQualifiedConstRef, (), (const, ref(&), override)); |
|||
MOCK_METHOD(int, RefQualifiedConstRefRef, (), (const, ref(&&), override)); |
|||
MOCK_METHOD(int, RefQualifiedRef, (), (ref(&), override)); |
|||
MOCK_METHOD(int, RefQualifiedRefRef, (), (ref(&&), override)); |
|||
|
|||
MOCK_METHOD(int, RefQualifiedOverloaded, (), (const, ref(&), override)); |
|||
MOCK_METHOD(int, RefQualifiedOverloaded, (), (const, ref(&&), override)); |
|||
MOCK_METHOD(int, RefQualifiedOverloaded, (), (ref(&), override)); |
|||
MOCK_METHOD(int, RefQualifiedOverloaded, (), (ref(&&), override)); |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo); |
|||
}; |
|||
|
|||
class LegacyMockFoo : public FooInterface { |
|||
public: |
|||
LegacyMockFoo() {} |
|||
|
|||
// Makes sure that a mock function parameter can be named.
|
|||
MOCK_METHOD1(VoidReturning, void(int n)); // NOLINT
|
|||
|
|||
MOCK_METHOD0(Nullary, int()); // NOLINT
|
|||
|
|||
// Makes sure that a mock function parameter can be unnamed.
|
|||
MOCK_METHOD1(Unary, bool(int)); // NOLINT
|
|||
MOCK_METHOD2(Binary, long(short, int)); // NOLINT
|
|||
MOCK_METHOD10(Decimal, int(bool, char, short, int, long, float, // NOLINT
|
|||
double, unsigned, char*, const std::string& str)); |
|||
|
|||
MOCK_METHOD1(TakesNonConstReference, bool(int&)); // NOLINT
|
|||
MOCK_METHOD1(TakesConstReference, std::string(const int&)); |
|||
MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT
|
|||
|
|||
// Tests that the function return type can contain unprotected comma.
|
|||
MOCK_METHOD0(ReturnTypeWithComma, std::map<int, std::string>()); |
|||
MOCK_CONST_METHOD1(ReturnTypeWithComma, |
|||
std::map<int, std::string>(int)); // NOLINT
|
|||
|
|||
MOCK_METHOD0(OverloadedOnArgumentNumber, int()); // NOLINT
|
|||
MOCK_METHOD1(OverloadedOnArgumentNumber, int(int)); // NOLINT
|
|||
|
|||
MOCK_METHOD1(OverloadedOnArgumentType, int(int)); // NOLINT
|
|||
MOCK_METHOD1(OverloadedOnArgumentType, char(char)); // NOLINT
|
|||
|
|||
MOCK_METHOD0(OverloadedOnConstness, int()); // NOLINT
|
|||
MOCK_CONST_METHOD0(OverloadedOnConstness, char()); // NOLINT
|
|||
|
|||
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
|
|||
|
|||
MOCK_METHOD1(ReturnsFunctionPointer1, int (*(int))(bool)); |
|||
MOCK_METHOD1(ReturnsFunctionPointer2, fn_ptr(int)); |
|||
|
|||
#if GTEST_OS_WINDOWS
|
|||
MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int()); |
|||
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int)); // NOLINT
|
|||
MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal, |
|||
int(bool b, char c, short d, int e, // NOLINT
|
|||
long f, float g, double h, // NOLINT
|
|||
unsigned i, char* j, const std::string& k)); |
|||
MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst, |
|||
char(int)); // NOLINT
|
|||
|
|||
// Tests that the function return type can contain unprotected comma.
|
|||
MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTReturnTypeWithComma, |
|||
std::map<int, std::string>()); |
|||
#endif // GTEST_OS_WINDOWS
|
|||
|
|||
// We can't mock these with the old macros, but we need to define them to make
|
|||
// it concrete.
|
|||
int RefQualifiedConstRef() const& override { return 0; } |
|||
int RefQualifiedConstRefRef() const&& override { return 0; } |
|||
int RefQualifiedRef() & override { return 0; } |
|||
int RefQualifiedRefRef() && override { return 0; } |
|||
int RefQualifiedOverloaded() const& override { return 0; } |
|||
int RefQualifiedOverloaded() const&& override { return 0; } |
|||
int RefQualifiedOverloaded() & override { return 0; } |
|||
int RefQualifiedOverloaded() && override { return 0; } |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockFoo); |
|||
}; |
|||
|
|||
#ifdef _MSC_VER
|
|||
# pragma warning(pop)
|
|||
#endif
|
|||
|
|||
template <class T> |
|||
class FunctionMockerTest : public testing::Test { |
|||
protected: |
|||
FunctionMockerTest() : foo_(&mock_foo_) {} |
|||
|
|||
FooInterface* const foo_; |
|||
T mock_foo_; |
|||
}; |
|||
using FunctionMockerTestTypes = ::testing::Types<MockFoo, LegacyMockFoo>; |
|||
TYPED_TEST_SUITE(FunctionMockerTest, FunctionMockerTestTypes); |
|||
|
|||
// Tests mocking a void-returning function.
|
|||
TYPED_TEST(FunctionMockerTest, MocksVoidFunction) { |
|||
EXPECT_CALL(this->mock_foo_, VoidReturning(Lt(100))); |
|||
this->foo_->VoidReturning(0); |
|||
} |
|||
|
|||
// Tests mocking a nullary function.
|
|||
TYPED_TEST(FunctionMockerTest, MocksNullaryFunction) { |
|||
EXPECT_CALL(this->mock_foo_, Nullary()) |
|||
.WillOnce(DoDefault()) |
|||
.WillOnce(Return(1)); |
|||
|
|||
EXPECT_EQ(0, this->foo_->Nullary()); |
|||
EXPECT_EQ(1, this->foo_->Nullary()); |
|||
} |
|||
|
|||
// Tests mocking a unary function.
|
|||
TYPED_TEST(FunctionMockerTest, MocksUnaryFunction) { |
|||
EXPECT_CALL(this->mock_foo_, Unary(Eq(2))).Times(2).WillOnce(Return(true)); |
|||
|
|||
EXPECT_TRUE(this->foo_->Unary(2)); |
|||
EXPECT_FALSE(this->foo_->Unary(2)); |
|||
} |
|||
|
|||
// Tests mocking a binary function.
|
|||
TYPED_TEST(FunctionMockerTest, MocksBinaryFunction) { |
|||
EXPECT_CALL(this->mock_foo_, Binary(2, _)).WillOnce(Return(3)); |
|||
|
|||
EXPECT_EQ(3, this->foo_->Binary(2, 1)); |
|||
} |
|||
|
|||
// Tests mocking a decimal function.
|
|||
TYPED_TEST(FunctionMockerTest, MocksDecimalFunction) { |
|||
EXPECT_CALL(this->mock_foo_, |
|||
Decimal(true, 'a', 0, 0, 1L, A<float>(), Lt(100), 5U, NULL, "hi")) |
|||
.WillOnce(Return(5)); |
|||
|
|||
EXPECT_EQ(5, this->foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi")); |
|||
} |
|||
|
|||
// Tests mocking a function that takes a non-const reference.
|
|||
TYPED_TEST(FunctionMockerTest, MocksFunctionWithNonConstReferenceArgument) { |
|||
int a = 0; |
|||
EXPECT_CALL(this->mock_foo_, TakesNonConstReference(Ref(a))) |
|||
.WillOnce(Return(true)); |
|||
|
|||
EXPECT_TRUE(this->foo_->TakesNonConstReference(a)); |
|||
} |
|||
|
|||
// Tests mocking a function that takes a const reference.
|
|||
TYPED_TEST(FunctionMockerTest, MocksFunctionWithConstReferenceArgument) { |
|||
int a = 0; |
|||
EXPECT_CALL(this->mock_foo_, TakesConstReference(Ref(a))) |
|||
.WillOnce(Return("Hello")); |
|||
|
|||
EXPECT_EQ("Hello", this->foo_->TakesConstReference(a)); |
|||
} |
|||
|
|||
// Tests mocking a function that takes a const variable.
|
|||
TYPED_TEST(FunctionMockerTest, MocksFunctionWithConstArgument) { |
|||
EXPECT_CALL(this->mock_foo_, TakesConst(Lt(10))).WillOnce(DoDefault()); |
|||
|
|||
EXPECT_FALSE(this->foo_->TakesConst(5)); |
|||
} |
|||
|
|||
// Tests mocking functions overloaded on the number of arguments.
|
|||
TYPED_TEST(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) { |
|||
EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentNumber()) |
|||
.WillOnce(Return(1)); |
|||
EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentNumber(_)) |
|||
.WillOnce(Return(2)); |
|||
|
|||
EXPECT_EQ(2, this->foo_->OverloadedOnArgumentNumber(1)); |
|||
EXPECT_EQ(1, this->foo_->OverloadedOnArgumentNumber()); |
|||
} |
|||
|
|||
// Tests mocking functions overloaded on the types of argument.
|
|||
TYPED_TEST(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentType) { |
|||
EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentType(An<int>())) |
|||
.WillOnce(Return(1)); |
|||
EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentType(TypedEq<char>('a'))) |
|||
.WillOnce(Return('b')); |
|||
|
|||
EXPECT_EQ(1, this->foo_->OverloadedOnArgumentType(0)); |
|||
EXPECT_EQ('b', this->foo_->OverloadedOnArgumentType('a')); |
|||
} |
|||
|
|||
// Tests mocking functions overloaded on the const-ness of this object.
|
|||
TYPED_TEST(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) { |
|||
EXPECT_CALL(this->mock_foo_, OverloadedOnConstness()); |
|||
EXPECT_CALL(Const(this->mock_foo_), OverloadedOnConstness()) |
|||
.WillOnce(Return('a')); |
|||
|
|||
EXPECT_EQ(0, this->foo_->OverloadedOnConstness()); |
|||
EXPECT_EQ('a', Const(*this->foo_).OverloadedOnConstness()); |
|||
} |
|||
|
|||
TYPED_TEST(FunctionMockerTest, MocksReturnTypeWithComma) { |
|||
const std::map<int, std::string> a_map; |
|||
EXPECT_CALL(this->mock_foo_, ReturnTypeWithComma()).WillOnce(Return(a_map)); |
|||
EXPECT_CALL(this->mock_foo_, ReturnTypeWithComma(42)).WillOnce(Return(a_map)); |
|||
|
|||
EXPECT_EQ(a_map, this->mock_foo_.ReturnTypeWithComma()); |
|||
EXPECT_EQ(a_map, this->mock_foo_.ReturnTypeWithComma(42)); |
|||
} |
|||
|
|||
TYPED_TEST(FunctionMockerTest, MocksTypeWithTemplatedCopyCtor) { |
|||
EXPECT_CALL(this->mock_foo_, TypeWithTemplatedCopyCtor(_)) |
|||
.WillOnce(Return(true)); |
|||
EXPECT_TRUE(this->foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable<int>())); |
|||
} |
|||
|
|||
#if GTEST_OS_WINDOWS
|
|||
// Tests mocking a nullary function with calltype.
|
|||
TYPED_TEST(FunctionMockerTest, MocksNullaryFunctionWithCallType) { |
|||
EXPECT_CALL(this->mock_foo_, CTNullary()) |
|||
.WillOnce(Return(-1)) |
|||
.WillOnce(Return(0)); |
|||
|
|||
EXPECT_EQ(-1, this->foo_->CTNullary()); |
|||
EXPECT_EQ(0, this->foo_->CTNullary()); |
|||
} |
|||
|
|||
// Tests mocking a unary function with calltype.
|
|||
TYPED_TEST(FunctionMockerTest, MocksUnaryFunctionWithCallType) { |
|||
EXPECT_CALL(this->mock_foo_, CTUnary(Eq(2))) |
|||
.Times(2) |
|||
.WillOnce(Return(true)) |
|||
.WillOnce(Return(false)); |
|||
|
|||
EXPECT_TRUE(this->foo_->CTUnary(2)); |
|||
EXPECT_FALSE(this->foo_->CTUnary(2)); |
|||
} |
|||
|
|||
// Tests mocking a decimal function with calltype.
|
|||
TYPED_TEST(FunctionMockerTest, MocksDecimalFunctionWithCallType) { |
|||
EXPECT_CALL(this->mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(), |
|||
Lt(100), 5U, NULL, "hi")) |
|||
.WillOnce(Return(10)); |
|||
|
|||
EXPECT_EQ(10, this->foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, NULL, "hi")); |
|||
} |
|||
|
|||
// Tests mocking functions overloaded on the const-ness of this object.
|
|||
TYPED_TEST(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) { |
|||
EXPECT_CALL(Const(this->mock_foo_), CTConst(_)).WillOnce(Return('a')); |
|||
|
|||
EXPECT_EQ('a', Const(*this->foo_).CTConst(0)); |
|||
} |
|||
|
|||
TYPED_TEST(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) { |
|||
const std::map<int, std::string> a_map; |
|||
EXPECT_CALL(this->mock_foo_, CTReturnTypeWithComma()).WillOnce(Return(a_map)); |
|||
|
|||
EXPECT_EQ(a_map, this->mock_foo_.CTReturnTypeWithComma()); |
|||
} |
|||
|
|||
#endif // GTEST_OS_WINDOWS
|
|||
|
|||
TEST(FunctionMockerTest, RefQualified) { |
|||
MockFoo mock_foo; |
|||
|
|||
EXPECT_CALL(mock_foo, RefQualifiedConstRef).WillOnce(Return(1)); |
|||
EXPECT_CALL(std::move(mock_foo), // NOLINT
|
|||
RefQualifiedConstRefRef) |
|||
.WillOnce(Return(2)); |
|||
EXPECT_CALL(mock_foo, RefQualifiedRef).WillOnce(Return(3)); |
|||
EXPECT_CALL(std::move(mock_foo), // NOLINT
|
|||
RefQualifiedRefRef) |
|||
.WillOnce(Return(4)); |
|||
|
|||
EXPECT_CALL(static_cast<const MockFoo&>(mock_foo), RefQualifiedOverloaded()) |
|||
.WillOnce(Return(5)); |
|||
EXPECT_CALL(static_cast<const MockFoo&&>(mock_foo), RefQualifiedOverloaded()) |
|||
.WillOnce(Return(6)); |
|||
EXPECT_CALL(static_cast<MockFoo&>(mock_foo), RefQualifiedOverloaded()) |
|||
.WillOnce(Return(7)); |
|||
EXPECT_CALL(static_cast<MockFoo&&>(mock_foo), RefQualifiedOverloaded()) |
|||
.WillOnce(Return(8)); |
|||
|
|||
EXPECT_EQ(mock_foo.RefQualifiedConstRef(), 1); |
|||
EXPECT_EQ(std::move(mock_foo).RefQualifiedConstRefRef(), 2); // NOLINT
|
|||
EXPECT_EQ(mock_foo.RefQualifiedRef(), 3); |
|||
EXPECT_EQ(std::move(mock_foo).RefQualifiedRefRef(), 4); // NOLINT
|
|||
|
|||
EXPECT_EQ(std::cref(mock_foo).get().RefQualifiedOverloaded(), 5); |
|||
EXPECT_EQ(std::move(std::cref(mock_foo).get()) // NOLINT
|
|||
.RefQualifiedOverloaded(), |
|||
6); |
|||
EXPECT_EQ(mock_foo.RefQualifiedOverloaded(), 7); |
|||
EXPECT_EQ(std::move(mock_foo).RefQualifiedOverloaded(), 8); // NOLINT
|
|||
} |
|||
|
|||
class MockB { |
|||
public: |
|||
MockB() {} |
|||
|
|||
MOCK_METHOD(void, DoB, ()); |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB); |
|||
}; |
|||
|
|||
class LegacyMockB { |
|||
public: |
|||
LegacyMockB() {} |
|||
|
|||
MOCK_METHOD0(DoB, void()); |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockB); |
|||
}; |
|||
|
|||
template <typename T> |
|||
class ExpectCallTest : public ::testing::Test {}; |
|||
using ExpectCallTestTypes = ::testing::Types<MockB, LegacyMockB>; |
|||
TYPED_TEST_SUITE(ExpectCallTest, ExpectCallTestTypes); |
|||
|
|||
// Tests that functions with no EXPECT_CALL() rules can be called any
|
|||
// number of times.
|
|||
TYPED_TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) { |
|||
{ TypeParam b; } |
|||
|
|||
{ |
|||
TypeParam b; |
|||
b.DoB(); |
|||
} |
|||
|
|||
{ |
|||
TypeParam b; |
|||
b.DoB(); |
|||
b.DoB(); |
|||
} |
|||
} |
|||
|
|||
// Tests mocking template interfaces.
|
|||
|
|||
template <typename T> |
|||
class StackInterface { |
|||
public: |
|||
virtual ~StackInterface() {} |
|||
|
|||
// Template parameter appears in function parameter.
|
|||
virtual void Push(const T& value) = 0; |
|||
virtual void Pop() = 0; |
|||
virtual int GetSize() const = 0; |
|||
// Template parameter appears in function return type.
|
|||
virtual const T& GetTop() const = 0; |
|||
}; |
|||
|
|||
template <typename T> |
|||
class MockStack : public StackInterface<T> { |
|||
public: |
|||
MockStack() {} |
|||
|
|||
MOCK_METHOD(void, Push, (const T& elem), ()); |
|||
MOCK_METHOD(void, Pop, (), (final)); |
|||
MOCK_METHOD(int, GetSize, (), (const, override)); |
|||
MOCK_METHOD(const T&, GetTop, (), (const)); |
|||
|
|||
// Tests that the function return type can contain unprotected comma.
|
|||
MOCK_METHOD((std::map<int, int>), ReturnTypeWithComma, (), ()); |
|||
MOCK_METHOD((std::map<int, int>), ReturnTypeWithComma, (int), (const)); |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStack); |
|||
}; |
|||
|
|||
template <typename T> |
|||
class LegacyMockStack : public StackInterface<T> { |
|||
public: |
|||
LegacyMockStack() {} |
|||
|
|||
MOCK_METHOD1_T(Push, void(const T& elem)); |
|||
MOCK_METHOD0_T(Pop, void()); |
|||
MOCK_CONST_METHOD0_T(GetSize, int()); // NOLINT
|
|||
MOCK_CONST_METHOD0_T(GetTop, const T&()); |
|||
|
|||
// Tests that the function return type can contain unprotected comma.
|
|||
MOCK_METHOD0_T(ReturnTypeWithComma, std::map<int, int>()); |
|||
MOCK_CONST_METHOD1_T(ReturnTypeWithComma, std::map<int, int>(int)); // NOLINT
|
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockStack); |
|||
}; |
|||
|
|||
template <typename T> |
|||
class TemplateMockTest : public ::testing::Test {}; |
|||
using TemplateMockTestTypes = |
|||
::testing::Types<MockStack<int>, LegacyMockStack<int>>; |
|||
TYPED_TEST_SUITE(TemplateMockTest, TemplateMockTestTypes); |
|||
|
|||
// Tests that template mock works.
|
|||
TYPED_TEST(TemplateMockTest, Works) { |
|||
TypeParam mock; |
|||
|
|||
EXPECT_CALL(mock, GetSize()) |
|||
.WillOnce(Return(0)) |
|||
.WillOnce(Return(1)) |
|||
.WillOnce(Return(0)); |
|||
EXPECT_CALL(mock, Push(_)); |
|||
int n = 5; |
|||
EXPECT_CALL(mock, GetTop()) |
|||
.WillOnce(ReturnRef(n)); |
|||
EXPECT_CALL(mock, Pop()) |
|||
.Times(AnyNumber()); |
|||
|
|||
EXPECT_EQ(0, mock.GetSize()); |
|||
mock.Push(5); |
|||
EXPECT_EQ(1, mock.GetSize()); |
|||
EXPECT_EQ(5, mock.GetTop()); |
|||
mock.Pop(); |
|||
EXPECT_EQ(0, mock.GetSize()); |
|||
} |
|||
|
|||
TYPED_TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) { |
|||
TypeParam mock; |
|||
|
|||
const std::map<int, int> a_map; |
|||
EXPECT_CALL(mock, ReturnTypeWithComma()) |
|||
.WillOnce(Return(a_map)); |
|||
EXPECT_CALL(mock, ReturnTypeWithComma(1)) |
|||
.WillOnce(Return(a_map)); |
|||
|
|||
EXPECT_EQ(a_map, mock.ReturnTypeWithComma()); |
|||
EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1)); |
|||
} |
|||
|
|||
#if GTEST_OS_WINDOWS
|
|||
// Tests mocking template interfaces with calltype.
|
|||
|
|||
template <typename T> |
|||
class StackInterfaceWithCallType { |
|||
public: |
|||
virtual ~StackInterfaceWithCallType() {} |
|||
|
|||
// Template parameter appears in function parameter.
|
|||
STDMETHOD_(void, Push)(const T& value) = 0; |
|||
STDMETHOD_(void, Pop)() = 0; |
|||
STDMETHOD_(int, GetSize)() const = 0; |
|||
// Template parameter appears in function return type.
|
|||
STDMETHOD_(const T&, GetTop)() const = 0; |
|||
}; |
|||
|
|||
template <typename T> |
|||
class MockStackWithCallType : public StackInterfaceWithCallType<T> { |
|||
public: |
|||
MockStackWithCallType() {} |
|||
|
|||
MOCK_METHOD(void, Push, (const T& elem), |
|||
(Calltype(STDMETHODCALLTYPE), override)); |
|||
MOCK_METHOD(void, Pop, (), (Calltype(STDMETHODCALLTYPE), override)); |
|||
MOCK_METHOD(int, GetSize, (), (Calltype(STDMETHODCALLTYPE), override, const)); |
|||
MOCK_METHOD(const T&, GetTop, (), |
|||
(Calltype(STDMETHODCALLTYPE), override, const)); |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStackWithCallType); |
|||
}; |
|||
|
|||
template <typename T> |
|||
class LegacyMockStackWithCallType : public StackInterfaceWithCallType<T> { |
|||
public: |
|||
LegacyMockStackWithCallType() {} |
|||
|
|||
MOCK_METHOD1_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Push, void(const T& elem)); |
|||
MOCK_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Pop, void()); |
|||
MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetSize, int()); |
|||
MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetTop, const T&()); |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockStackWithCallType); |
|||
}; |
|||
|
|||
template <typename T> |
|||
class TemplateMockTestWithCallType : public ::testing::Test {}; |
|||
using TemplateMockTestWithCallTypeTypes = |
|||
::testing::Types<MockStackWithCallType<int>, |
|||
LegacyMockStackWithCallType<int>>; |
|||
TYPED_TEST_SUITE(TemplateMockTestWithCallType, |
|||
TemplateMockTestWithCallTypeTypes); |
|||
|
|||
// Tests that template mock with calltype works.
|
|||
TYPED_TEST(TemplateMockTestWithCallType, Works) { |
|||
TypeParam mock; |
|||
|
|||
EXPECT_CALL(mock, GetSize()) |
|||
.WillOnce(Return(0)) |
|||
.WillOnce(Return(1)) |
|||
.WillOnce(Return(0)); |
|||
EXPECT_CALL(mock, Push(_)); |
|||
int n = 5; |
|||
EXPECT_CALL(mock, GetTop()) |
|||
.WillOnce(ReturnRef(n)); |
|||
EXPECT_CALL(mock, Pop()) |
|||
.Times(AnyNumber()); |
|||
|
|||
EXPECT_EQ(0, mock.GetSize()); |
|||
mock.Push(5); |
|||
EXPECT_EQ(1, mock.GetSize()); |
|||
EXPECT_EQ(5, mock.GetTop()); |
|||
mock.Pop(); |
|||
EXPECT_EQ(0, mock.GetSize()); |
|||
} |
|||
#endif // GTEST_OS_WINDOWS
|
|||
|
|||
#define MY_MOCK_METHODS1_ \
|
|||
MOCK_METHOD(void, Overloaded, ()); \ |
|||
MOCK_METHOD(int, Overloaded, (int), (const)); \ |
|||
MOCK_METHOD(bool, Overloaded, (bool f, int n)) |
|||
|
|||
#define LEGACY_MY_MOCK_METHODS1_ \
|
|||
MOCK_METHOD0(Overloaded, void()); \ |
|||
MOCK_CONST_METHOD1(Overloaded, int(int n)); \ |
|||
MOCK_METHOD2(Overloaded, bool(bool f, int n)) |
|||
|
|||
class MockOverloadedOnArgNumber { |
|||
public: |
|||
MockOverloadedOnArgNumber() {} |
|||
|
|||
MY_MOCK_METHODS1_; |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnArgNumber); |
|||
}; |
|||
|
|||
class LegacyMockOverloadedOnArgNumber { |
|||
public: |
|||
LegacyMockOverloadedOnArgNumber() {} |
|||
|
|||
LEGACY_MY_MOCK_METHODS1_; |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockOverloadedOnArgNumber); |
|||
}; |
|||
|
|||
template <typename T> |
|||
class OverloadedMockMethodTest : public ::testing::Test {}; |
|||
using OverloadedMockMethodTestTypes = |
|||
::testing::Types<MockOverloadedOnArgNumber, |
|||
LegacyMockOverloadedOnArgNumber>; |
|||
TYPED_TEST_SUITE(OverloadedMockMethodTest, OverloadedMockMethodTestTypes); |
|||
|
|||
TYPED_TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) { |
|||
TypeParam mock; |
|||
EXPECT_CALL(mock, Overloaded()); |
|||
EXPECT_CALL(mock, Overloaded(1)).WillOnce(Return(2)); |
|||
EXPECT_CALL(mock, Overloaded(true, 1)).WillOnce(Return(true)); |
|||
|
|||
mock.Overloaded(); |
|||
EXPECT_EQ(2, mock.Overloaded(1)); |
|||
EXPECT_TRUE(mock.Overloaded(true, 1)); |
|||
} |
|||
|
|||
#define MY_MOCK_METHODS2_ \
|
|||
MOCK_CONST_METHOD1(Overloaded, int(int n)); \ |
|||
MOCK_METHOD1(Overloaded, int(int n)) |
|||
|
|||
class MockOverloadedOnConstness { |
|||
public: |
|||
MockOverloadedOnConstness() {} |
|||
|
|||
MY_MOCK_METHODS2_; |
|||
|
|||
private: |
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnConstness); |
|||
}; |
|||
|
|||
TEST(MockMethodOverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) { |
|||
MockOverloadedOnConstness mock; |
|||
const MockOverloadedOnConstness* const_mock = &mock; |
|||
EXPECT_CALL(mock, Overloaded(1)).WillOnce(Return(2)); |
|||
EXPECT_CALL(*const_mock, Overloaded(1)).WillOnce(Return(3)); |
|||
|
|||
EXPECT_EQ(2, mock.Overloaded(1)); |
|||
EXPECT_EQ(3, const_mock->Overloaded(1)); |
|||
} |
|||
|
|||
TEST(MockMethodMockFunctionTest, WorksForVoidNullary) { |
|||
MockFunction<void()> foo; |
|||
EXPECT_CALL(foo, Call()); |
|||
foo.Call(); |
|||
} |
|||
|
|||
TEST(MockMethodMockFunctionTest, WorksForNonVoidNullary) { |
|||
MockFunction<int()> foo; |
|||
EXPECT_CALL(foo, Call()) |
|||
.WillOnce(Return(1)) |
|||
.WillOnce(Return(2)); |
|||
EXPECT_EQ(1, foo.Call()); |
|||
EXPECT_EQ(2, foo.Call()); |
|||
} |
|||
|
|||
TEST(MockMethodMockFunctionTest, WorksForVoidUnary) { |
|||
MockFunction<void(int)> foo; |
|||
EXPECT_CALL(foo, Call(1)); |
|||
foo.Call(1); |
|||
} |
|||
|
|||
TEST(MockMethodMockFunctionTest, WorksForNonVoidBinary) { |
|||
MockFunction<int(bool, int)> foo; |
|||
EXPECT_CALL(foo, Call(false, 42)) |
|||
.WillOnce(Return(1)) |
|||
.WillOnce(Return(2)); |
|||
EXPECT_CALL(foo, Call(true, Ge(100))) |
|||
.WillOnce(Return(3)); |
|||
EXPECT_EQ(1, foo.Call(false, 42)); |
|||
EXPECT_EQ(2, foo.Call(false, 42)); |
|||
EXPECT_EQ(3, foo.Call(true, 120)); |
|||
} |
|||
|
|||
TEST(MockMethodMockFunctionTest, WorksFor10Arguments) { |
|||
MockFunction<int(bool a0, char a1, int a2, int a3, int a4, |
|||
int a5, int a6, char a7, int a8, bool a9)> foo; |
|||
EXPECT_CALL(foo, Call(_, 'a', _, _, _, _, _, _, _, _)) |
|||
.WillOnce(Return(1)) |
|||
.WillOnce(Return(2)); |
|||
EXPECT_EQ(1, foo.Call(false, 'a', 0, 0, 0, 0, 0, 'b', 0, true)); |
|||
EXPECT_EQ(2, foo.Call(true, 'a', 0, 0, 0, 0, 0, 'b', 1, false)); |
|||
} |
|||
|
|||
TEST(MockMethodMockFunctionTest, AsStdFunction) { |
|||
MockFunction<int(int)> foo; |
|||
auto call = [](const std::function<int(int)> &f, int i) { |
|||
return f(i); |
|||
}; |
|||
EXPECT_CALL(foo, Call(1)).WillOnce(Return(-1)); |
|||
EXPECT_CALL(foo, Call(2)).WillOnce(Return(-2)); |
|||
EXPECT_EQ(-1, call(foo.AsStdFunction(), 1)); |
|||
EXPECT_EQ(-2, call(foo.AsStdFunction(), 2)); |
|||
} |
|||
|
|||
TEST(MockMethodMockFunctionTest, AsStdFunctionReturnsReference) { |
|||
MockFunction<int&()> foo; |
|||
int value = 1; |
|||
EXPECT_CALL(foo, Call()).WillOnce(ReturnRef(value)); |
|||
int& ref = foo.AsStdFunction()(); |
|||
EXPECT_EQ(1, ref); |
|||
value = 2; |
|||
EXPECT_EQ(2, ref); |
|||
} |
|||
|
|||
TEST(MockMethodMockFunctionTest, AsStdFunctionWithReferenceParameter) { |
|||
MockFunction<int(int &)> foo; |
|||
auto call = [](const std::function<int(int& )> &f, int &i) { |
|||
return f(i); |
|||
}; |
|||
int i = 42; |
|||
EXPECT_CALL(foo, Call(i)).WillOnce(Return(-1)); |
|||
EXPECT_EQ(-1, call(foo.AsStdFunction(), i)); |
|||
} |
|||
|
|||
namespace { |
|||
|
|||
template <typename Expected, typename F> |
|||
static constexpr bool IsMockFunctionTemplateArgumentDeducedTo( |
|||
const internal::MockFunction<F>&) { |
|||
return std::is_same<F, Expected>::value; |
|||
} |
|||
|
|||
} // namespace
|
|||
|
|||
template <typename F> |
|||
class MockMethodMockFunctionSignatureTest : public Test {}; |
|||
|
|||
using MockMethodMockFunctionSignatureTypes = |
|||
Types<void(), int(), void(int), int(int), int(bool, int), |
|||
int(bool, char, int, int, int, int, int, char, int, bool)>; |
|||
TYPED_TEST_SUITE(MockMethodMockFunctionSignatureTest, |
|||
MockMethodMockFunctionSignatureTypes); |
|||
|
|||
TYPED_TEST(MockMethodMockFunctionSignatureTest, |
|||
IsMockFunctionTemplateArgumentDeducedForRawSignature) { |
|||
using Argument = TypeParam; |
|||
MockFunction<Argument> foo; |
|||
EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo<TypeParam>(foo)); |
|||
} |
|||
|
|||
TYPED_TEST(MockMethodMockFunctionSignatureTest, |
|||
IsMockFunctionTemplateArgumentDeducedForStdFunction) { |
|||
using Argument = std::function<TypeParam>; |
|||
MockFunction<Argument> foo; |
|||
EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo<TypeParam>(foo)); |
|||
} |
|||
|
|||
TYPED_TEST( |
|||
MockMethodMockFunctionSignatureTest, |
|||
IsMockFunctionCallMethodSignatureTheSameForRawSignatureAndStdFunction) { |
|||
using ForRawSignature = decltype(&MockFunction<TypeParam>::Call); |
|||
using ForStdFunction = |
|||
decltype(&MockFunction<std::function<TypeParam>>::Call); |
|||
EXPECT_TRUE((std::is_same<ForRawSignature, ForStdFunction>::value)); |
|||
} |
|||
|
|||
template <typename F> |
|||
struct AlternateCallable { |
|||
}; |
|||
|
|||
TYPED_TEST(MockMethodMockFunctionSignatureTest, |
|||
IsMockFunctionTemplateArgumentDeducedForAlternateCallable) { |
|||
using Argument = AlternateCallable<TypeParam>; |
|||
MockFunction<Argument> foo; |
|||
EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo<TypeParam>(foo)); |
|||
} |
|||
|
|||
TYPED_TEST( |
|||
MockMethodMockFunctionSignatureTest, |
|||
IsMockFunctionCallMethodSignatureTheSameForAlternateCallable) { |
|||
using ForRawSignature = decltype(&MockFunction<TypeParam>::Call); |
|||
using ForStdFunction = |
|||
decltype(&MockFunction<std::function<TypeParam>>::Call); |
|||
EXPECT_TRUE((std::is_same<ForRawSignature, ForStdFunction>::value)); |
|||
} |
|||
|
|||
|
|||
struct MockMethodSizes0 { |
|||
MOCK_METHOD(void, func, ()); |
|||
}; |
|||
struct MockMethodSizes1 { |
|||
MOCK_METHOD(void, func, (int)); |
|||
}; |
|||
struct MockMethodSizes2 { |
|||
MOCK_METHOD(void, func, (int, int)); |
|||
}; |
|||
struct MockMethodSizes3 { |
|||
MOCK_METHOD(void, func, (int, int, int)); |
|||
}; |
|||
struct MockMethodSizes4 { |
|||
MOCK_METHOD(void, func, (int, int, int, int)); |
|||
}; |
|||
|
|||
struct LegacyMockMethodSizes0 { |
|||
MOCK_METHOD0(func, void()); |
|||
}; |
|||
struct LegacyMockMethodSizes1 { |
|||
MOCK_METHOD1(func, void(int)); |
|||
}; |
|||
struct LegacyMockMethodSizes2 { |
|||
MOCK_METHOD2(func, void(int, int)); |
|||
}; |
|||
struct LegacyMockMethodSizes3 { |
|||
MOCK_METHOD3(func, void(int, int, int)); |
|||
}; |
|||
struct LegacyMockMethodSizes4 { |
|||
MOCK_METHOD4(func, void(int, int, int, int)); |
|||
}; |
|||
|
|||
|
|||
TEST(MockMethodMockFunctionTest, MockMethodSizeOverhead) { |
|||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes1)); |
|||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes2)); |
|||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes3)); |
|||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes4)); |
|||
|
|||
EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes1)); |
|||
EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes2)); |
|||
EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes3)); |
|||
EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes4)); |
|||
|
|||
EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(MockMethodSizes0)); |
|||
} |
|||
|
|||
void hasTwoParams(int, int); |
|||
void MaybeThrows(); |
|||
void DoesntThrow() noexcept; |
|||
struct MockMethodNoexceptSpecifier { |
|||
MOCK_METHOD(void, func1, (), (noexcept)); |
|||
MOCK_METHOD(void, func2, (), (noexcept(true))); |
|||
MOCK_METHOD(void, func3, (), (noexcept(false))); |
|||
MOCK_METHOD(void, func4, (), (noexcept(noexcept(MaybeThrows())))); |
|||
MOCK_METHOD(void, func5, (), (noexcept(noexcept(DoesntThrow())))); |
|||
MOCK_METHOD(void, func6, (), (noexcept(noexcept(DoesntThrow())), const)); |
|||
MOCK_METHOD(void, func7, (), (const, noexcept(noexcept(DoesntThrow())))); |
|||
// Put commas in the noexcept expression
|
|||
MOCK_METHOD(void, func8, (), (noexcept(noexcept(hasTwoParams(1, 2))), const)); |
|||
}; |
|||
|
|||
TEST(MockMethodMockFunctionTest, NoexceptSpecifierPreserved) { |
|||
EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func1())); |
|||
EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func2())); |
|||
EXPECT_FALSE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func3())); |
|||
EXPECT_FALSE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func4())); |
|||
EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func5())); |
|||
EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func6())); |
|||
EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func7())); |
|||
EXPECT_EQ(noexcept(std::declval<MockMethodNoexceptSpecifier>().func8()), |
|||
noexcept(hasTwoParams(1, 2))); |
|||
} |
|||
|
|||
} // namespace gmock_function_mocker_test
|
|||
} // namespace testing
|
2043
resources/3rdparty/googletest/googlemock/test/gmock-matchers_test.cc
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
849
resources/3rdparty/googletest/googlemock/test/gmock-more-actions_test.cc
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Some files were not shown because too many files changed in this diff
Reference in new issue
xxxxxxxxxx