2
// Copyright © 2012 Canonical Ltd. Copyright 2007, Google Inc.
4
// All rights reserved.
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
10
// * Redistributions of source code must retain the above copyright
11
// notice, this list of conditions and the following disclaimer.
12
// * Redistributions in binary form must reproduce the above
13
// copyright notice, this list of conditions and the following disclaimer
14
// in the documentation and/or other materials provided with the
16
// * Neither the name of Google Inc. nor the names of its
17
// contributors may be used to endorse or promote products derived from
18
// this software without specific prior written permission.
20
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
// Author: wan@google.com (Zhanyong Wan)
33
// Authored by: Alan Griffiths <alan@octopull.co.uk>
35
#ifndef MIR_TEST_GMOCK_FIXES_H_
36
#define MIR_TEST_GMOCK_FIXES_H_
39
#include <gmock/gmock.h>
47
class ActionResultHolder<std::unique_ptr<T>>
48
: public UntypedActionResultHolderBase {
50
explicit ActionResultHolder(std::unique_ptr<T>&& a_value) :
51
value_(std::move(a_value)) {}
53
// The compiler-generated copy constructor and assignment operator
54
// are exactly what we need, so we don't need to define them.
56
// Returns the held value and deletes this object.
57
std::unique_ptr<T> GetValueAndDelete() const {
58
std::unique_ptr<T> retval(std::move(value_));
63
// Prints the held value as an action's result to os.
64
virtual void PrintAsActionResult(::std::ostream* os) const {
65
*os << "\n Returns: ";
66
// T may be a reference type, so we don't use UniversalPrint().
67
UniversalPrinter<std::unique_ptr<T>>::Print(value_, os);
70
// Performs the given mock function's default action and returns the
71
// result in a new-ed ActionResultHolder.
73
static ActionResultHolder* PerformDefaultAction(
74
const FunctionMockerBase<F>* func_mocker,
75
const typename Function<F>::ArgumentTuple& args,
76
const string& call_description) {
77
return new ActionResultHolder(
78
func_mocker->PerformDefaultAction(args, call_description));
81
// Performs the given action and returns the result in a new-ed
82
// ActionResultHolder.
84
static ActionResultHolder*
85
PerformAction(const Action<F>& action,
86
const typename Function<F>::ArgumentTuple& args) {
87
return new ActionResultHolder(action.Perform(args));
91
std::unique_ptr<T> mutable value_;
93
// T could be a reference type, so = isn't supported.
94
GTEST_DISALLOW_ASSIGN_(ActionResultHolder);
100
class DefaultValue<std::unique_ptr<T>> {
102
// Unsets the default value for type T.
103
static void Clear() {}
105
// Returns true iff the user has set the default value for type T.
106
static bool IsSet() { return false; }
108
// Returns true if T has a default return value set by the user or there
109
// exists a built-in default value.
110
static bool Exists() {
114
// Returns the default value for type T if the user has set one;
115
// otherwise returns the built-in default value if there is one;
116
// otherwise aborts the process.
117
static std::unique_ptr<T> Get() {
118
return std::unique_ptr<T>();
124
#endif /* MIR_TEST_GMOCK_FIXES_H_ */