Add TOC to googletest and googlemoc docs markdowns

This commit is contained in:
bricoletc
2020-03-23 11:41:45 +00:00
parent 749148f1ac
commit 12b7f5dbf9
9 changed files with 239 additions and 0 deletions

View File

@@ -1,5 +1,18 @@
## gMock Cheat Sheet
## Contents
1. [Defining a Mock Class](#defining-a-mock-class)
1. [Using Mocks in Tests {#UsingMocks}](#using-mocks-in-tests-usingmocks)
1. [Setting Default Actions {#OnCall}](#setting-default-actions-oncall)
1. [Setting Expectations {#ExpectCall}](#setting-expectations-expectcall)
1. [Matchers {#MatcherList}](#matchers-matcherlist)
1. [Actions {#ActionList}](#actions-actionlist)
1. [Cardinalities {#CardinalityList}](#cardinalities-cardinalitylist)
1. [Expectation Order](#expectation-order)
1. [Verifying and Resetting a Mock](#verifying-and-resetting-a-mock)
1. [Mock Classes](#mock-classes)
1. [Flags](#flags)
<!-- GOOGLETEST_CM0019 DO NOT DELETE -->
<!-- GOOGLETEST_CM0033 DO NOT DELETE -->

View File

@@ -1,5 +1,91 @@
# gMock Cookbook
## Contents
1. [Creating Mock Classes](#creating-mock-classes)
1. [Dealing with unprotected commas](#dealing-with-unprotected-commas)
1. [Mocking Private or Protected Methods](#mocking-private-or-protected-methods)
1. [Mocking Overloaded Methods](#mocking-overloaded-methods)
1. [Mocking Class Templates](#mocking-class-templates)
1. [Mocking Non-virtual Methods {#MockingNonVirtualMethods}](#mocking-non-virtual-methods-mockingnonvirtualmethods)
1. [Mocking Free Functions](#mocking-free-functions)
1. [Old-Style `MOCK_METHODn` Macros](#old-style-mock_methodn-macros)
1. [The Nice, the Strict, and the Naggy {#NiceStrictNaggy}](#the-nice-the-strict-and-the-naggy-nicestrictnaggy)
1. [Simplifying the Interface without Breaking Existing Code {#SimplerInterfaces}](#simplifying-the-interface-without-breaking-existing-code-simplerinterfaces)
1. [Alternative to Mocking Concrete Classes](#alternative-to-mocking-concrete-classes)
1. [Delegating Calls to a Fake {#DelegatingToFake}](#delegating-calls-to-a-fake-delegatingtofake)
1. [Delegating Calls to a Real Object](#delegating-calls-to-a-real-object)
1. [Delegating Calls to a Parent Class](#delegating-calls-to-a-parent-class)
1. [Using Matchers](#using-matchers)
1. [Matching Argument Values Exactly](#matching-argument-values-exactly)
1. [Using Simple Matchers](#using-simple-matchers)
1. [Combining Matchers {#CombiningMatchers}](#combining-matchers-combiningmatchers)
1. [Casting Matchers {#SafeMatcherCast}](#casting-matchers-safematchercast)
1. [Selecting Between Overloaded Functions {#SelectOverload}](#selecting-between-overloaded-functions-selectoverload)
1. [Performing Different Actions Based on the Arguments](#performing-different-actions-based-on-the-arguments)
1. [Matching Multiple Arguments as a Whole](#matching-multiple-arguments-as-a-whole)
1. [Using Matchers as Predicates](#using-matchers-as-predicates)
1. [Using Matchers in googletest Assertions](#using-matchers-in-googletest-assertions)
1. [Using Predicates as Matchers](#using-predicates-as-matchers)
1. [Matching Arguments that Are Not Copyable](#matching-arguments-that-are-not-copyable)
1. [Validating a Member of an Object](#validating-a-member-of-an-object)
1. [Validating the Value Pointed to by a Pointer Argument](#validating-the-value-pointed-to-by-a-pointer-argument)
1. [Testing a Certain Property of an Object](#testing-a-certain-property-of-an-object)
1. [Matching Containers](#matching-containers)
1. [Sharing Matchers](#sharing-matchers)
1. [Matchers must have no side-effects {#PureMatchers}](#matchers-must-have-no-side-effects-purematchers)
1. [Setting Expectations](#setting-expectations)
1. [Knowing When to Expect {#UseOnCall}](#knowing-when-to-expect-useoncall)
1. [Ignoring Uninteresting Calls](#ignoring-uninteresting-calls)
1. [Disallowing Unexpected Calls](#disallowing-unexpected-calls)
1. [Understanding Uninteresting vs Unexpected Calls {#uninteresting-vs-unexpected}](#understanding-uninteresting-vs-unexpected-calls-uninteresting-vs-unexpected)
1. [Ignoring Uninteresting Arguments {#ParameterlessExpectations}](#ignoring-uninteresting-arguments-parameterlessexpectations)
1. [Expecting Ordered Calls {#OrderedCalls}](#expecting-ordered-calls-orderedcalls)
1. [Expecting Partially Ordered Calls {#PartialOrder}](#expecting-partially-ordered-calls-partialorder)
1. [Controlling When an Expectation Retires](#controlling-when-an-expectation-retires)
1. [Using Actions](#using-actions)
1. [Returning References from Mock Methods](#returning-references-from-mock-methods)
1. [Returning Live Values from Mock Methods](#returning-live-values-from-mock-methods)
1. [Combining Actions](#combining-actions)
1. [Verifying Complex Arguments {#SaveArgVerify}](#verifying-complex-arguments-saveargverify)
1. [Mocking Side Effects {#MockingSideEffects}](#mocking-side-effects-mockingsideeffects)
1. [Changing a Mock Object's Behavior Based on the State](#changing-a-mock-object's-behavior-based-on-the-state)
1. [Setting the Default Value for a Return Type {#DefaultValue}](#setting-the-default-value-for-a-return-type-defaultvalue)
1. [Setting the Default Actions for a Mock Method](#setting-the-default-actions-for-a-mock-method)
1. [Using Functions/Methods/Functors/Lambdas as Actions {#FunctionsAsActions}](#using-functionsmethodsfunctorslambdas-as-actions-functionsasactions)
1. [Using Functions with Extra Info as Actions](#using-functions-with-extra-info-as-actions)
1. [Invoking a Function/Method/Functor/Lambda/Callback Without Arguments](#invoking-a-functionmethodfunctorlambdacallback-without-arguments)
1. [Invoking an Argument of the Mock Function](#invoking-an-argument-of-the-mock-function)
1. [Ignoring an Action's Result](#ignoring-an-action's-result)
1. [Selecting an Action's Arguments {#SelectingArgs}](#selecting-an-action's-arguments-selectingargs)
1. [Ignoring Arguments in Action Functions](#ignoring-arguments-in-action-functions)
1. [Sharing Actions](#sharing-actions)
1. [Testing Asynchronous Behavior](#testing-asynchronous-behavior)
1. [Misc Recipes on Using gMock](#misc-recipes-on-using-gmock)
1. [Mocking Methods That Use Move-Only Types](#mocking-methods-that-use-move-only-types)
1. [Making the Compilation Faster](#making-the-compilation-faster)
1. [Forcing a Verification](#forcing-a-verification)
1. [Using Check Points {#UsingCheckPoints}](#using-check-points-usingcheckpoints)
1. [Mocking Destructors](#mocking-destructors)
1. [Using gMock and Threads {#UsingThreads}](#using-gmock-and-threads-usingthreads)
1. [Controlling How Much Information gMock Prints](#controlling-how-much-information-gmock-prints)
1. [Gaining Super Vision into Mock Calls](#gaining-super-vision-into-mock-calls)
1. [Running Tests in Emacs](#running-tests-in-emacs)
1. [Extending gMock](#extending-gmock)
1. [Writing New Matchers Quickly {#NewMatchers}](#writing-new-matchers-quickly-newmatchers)
1. [Writing New Parameterized Matchers Quickly](#writing-new-parameterized-matchers-quickly)
1. [Writing New Monomorphic Matchers](#writing-new-monomorphic-matchers)
1. [Writing New Polymorphic Matchers](#writing-new-polymorphic-matchers)
1. [Writing New Cardinalities](#writing-new-cardinalities)
1. [Writing New Actions Quickly {#QuickNewActions}](#writing-new-actions-quickly-quicknewactions)
1. [Restricting the Type of an Argument or Parameter in an ACTION](#restricting-the-type-of-an-argument-or-parameter-in-an-action)
1. [Writing New Action Templates Quickly](#writing-new-action-templates-quickly)
1. [Using the ACTION Object's Type](#using-the-action-object's-type)
1. [Writing New Monomorphic Actions {#NewMonoActions}](#writing-new-monomorphic-actions-newmonoactions)
1. [Writing New Polymorphic Actions {#NewPolyActions}](#writing-new-polymorphic-actions-newpolyactions)
1. [Teaching gMock How to Print Your Values](#teaching-gmock-how-to-print-your-values)
1. [Useful Mocks Created Using gMock](#useful-mocks-created-using-gmock)
1. [Mock std::function {#MockFunction}](#mock-stdfunction-mockfunction)
<!-- GOOGLETEST_CM0012 DO NOT DELETE -->
You can find recipes for using gMock here. If you haven't yet, please read

View File

@@ -1,5 +1,14 @@
## gMock for Dummies {#GMockForDummies}
## Contents
1. [What Is gMock?](#what-is-gmock)
1. [Why gMock?](#why-gmock)
1. [Getting Started](#getting-started)
1. [A Case for Mock Turtles](#a-case-for-mock-turtles)
1. [Writing the Mock Class](#writing-the-mock-class)
1. [Using Mocks in Tests](#using-mocks-in-tests)
1. [Setting Expectations](#setting-expectations)
<!-- GOOGLETEST_CM0013 DO NOT DELETE -->
### What Is gMock?

View File

@@ -1,5 +1,25 @@
## Legacy gMock FAQ {#GMockFaq}
## Contents
1. [When I call a method on my mock object, the method for the real object is invoked instead. What's the problem?](#when-i-call-a-method-on-my-mock-object-the-method-for-the-real-object-is-invoked-instead-what's-the-problem)
1. [Can I mock a variadic function?](#can-i-mock-a-variadic-function)
1. [MSVC gives me warning C4301 or C4373 when I define a mock method with a const parameter. Why?](#msvc-gives-me-warning-c4301-or-c4373-when-i-define-a-mock-method-with-a-const-parameter-why)
1. [I can't figure out why gMock thinks my expectations are not satisfied. What should I do?](#i-can't-figure-out-why-gmock-thinks-my-expectations-are-not-satisfied-what-should-i-do)
1. [My program crashed and `ScopedMockLog` spit out tons of messages. Is it a gMock bug?](#my-program-crashed-and-scopedmocklog-spit-out-tons-of-messages-is-it-a-gmock-bug)
1. [How can I assert that a function is NEVER called?](#how-can-i-assert-that-a-function-is-never-called)
1. [I have a failed test where gMock tells me TWICE that a particular expectation is not satisfied. Isn't this redundant?](#i-have-a-failed-test-where-gmock-tells-me-twice-that-a-particular-expectation-is-not-satisfied-isn't-this-redundant)
1. [I get a heapcheck failure when using a mock object, but using a real object is fine. What can be wrong?](#i-get-a-heapcheck-failure-when-using-a-mock-object-but-using-a-real-object-is-fine-what-can-be-wrong)
1. [The "newer expectations override older ones" rule makes writing expectations awkward. Why does gMock do that?](#the-newer-expectations-override-older-ones-rule-makes-writing-expectations-awkward-why-does-gmock-do-that)
1. [gMock prints a warning when a function without EXPECT_CALL is called, even if I have set its behavior using ON_CALL. Would it be reasonable not to show the warning in this case?](#gmock-prints-a-warning-when-a-function-without-expect_call-is-called-even-if-i-have-set-its-behavior-using-on_call-would-it-be-reasonable-not-to-show-the-warning-in-this-case)
1. [How can I delete the mock function's argument in an action?](#how-can-i-delete-the-mock-function's-argument-in-an-action)
1. [How can I perform an arbitrary action on a mock function's argument?](#how-can-i-perform-an-arbitrary-action-on-a-mock-function's-argument)
1. [My code calls a static/global function. Can I mock it?](#my-code-calls-a-staticglobal-function-can-i-mock-it)
1. [My mock object needs to do complex stuff. It's a lot of pain to specify the actions. gMock sucks!](#my-mock-object-needs-to-do-complex-stuff-it's-a-lot-of-pain-to-specify-the-actions-gmock-sucks)
1. [I got a warning "Uninteresting function call encountered - default action taken.." Should I panic?](#i-got-a-warning-uninteresting-function-call-encountered---default-action-taken-should-i-panic)
1. [I want to define a custom action. Should I use Invoke() or implement the ActionInterface interface?](#i-want-to-define-a-custom-action-should-i-use-invoke-or-implement-the-actioninterface-interface)
1. [I use SetArgPointee() in WillOnce(), but gcc complains about "conflicting return type specified". What does it mean?](#i-use-setargpointee-in-willonce-but-gcc-complains-about-conflicting-return-type-specified-what-does-it-mean)
1. [I have a huge mock class, and Microsoft Visual C++ runs out of memory when compiling it. What can I do?](#i-have-a-huge-mock-class-and-microsoft-visual-c++-runs-out-of-memory-when-compiling-it-what-can-i-do)
<!-- GOOGLETEST_CM0021 DO NOT DELETE -->
### When I call a method on my mock object, the method for the real object is invoked instead. What's the problem?

View File

@@ -2,6 +2,16 @@
# The Problem
## Contents
1. [Our Solution](#our-solution)
1. [Highlights](#highlights)
1. [Examples](#examples)
1. [Constructs](#constructs)
1. [Grammar](#grammar)
1. [Code](#code)
1. [Real Examples](#real-examples)
1. [Tips](#tips)
Template and macro libraries often need to define many classes, functions, or
macros that vary only (or almost only) in the number of arguments they take.
It's a lot of repetitive, mechanical, and error-prone work.