~lukas-kde/miral/shellchrome-windowinfo

« back to all changes in this revision

Viewing changes to miral-qt/tests/framework/gmock_fixes.h

  • Committer: Larry Price
  • Date: 2016-09-13 16:19:29 UTC
  • mto: (330.4.1 miral)
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: larry.price@canonical.com-20160913161929-vs9ka1capmljq1es
Removing miral-qt from release branch, updating copyright file, and adding GPL3 license to root dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// Copyright © 2012 Canonical Ltd. Copyright 2007, Google Inc.
3
 
//
4
 
// All rights reserved.
5
 
//
6
 
// Redistribution and use in source and binary forms, with or without
7
 
// modification, are permitted provided that the following conditions are
8
 
// met:
9
 
//
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
15
 
// distribution.
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.
19
 
//
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.
31
 
//
32
 
// Author: wan@google.com (Zhanyong Wan)
33
 
// Authored by: Alan Griffiths <alan@octopull.co.uk>
34
 
 
35
 
#ifndef MIR_TEST_GMOCK_FIXES_H_
36
 
#define MIR_TEST_GMOCK_FIXES_H_
37
 
 
38
 
#include <memory>
39
 
#include <gmock/gmock.h>
40
 
 
41
 
namespace testing
42
 
{
43
 
namespace internal
44
 
{
45
 
 
46
 
template<typename T>
47
 
class ActionResultHolder<std::unique_ptr<T>>
48
 
: public UntypedActionResultHolderBase {
49
 
 public:
50
 
  explicit ActionResultHolder(std::unique_ptr<T>&& a_value) :
51
 
  value_(std::move(a_value)) {}
52
 
 
53
 
  // The compiler-generated copy constructor and assignment operator
54
 
  // are exactly what we need, so we don't need to define them.
55
 
 
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_));
59
 
    delete this;
60
 
    return retval;
61
 
  }
62
 
 
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);
68
 
  }
69
 
 
70
 
  // Performs the given mock function's default action and returns the
71
 
  // result in a new-ed ActionResultHolder.
72
 
  template <typename F>
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));
79
 
  }
80
 
 
81
 
  // Performs the given action and returns the result in a new-ed
82
 
  // ActionResultHolder.
83
 
  template <typename F>
84
 
  static ActionResultHolder*
85
 
  PerformAction(const Action<F>& action,
86
 
                const typename Function<F>::ArgumentTuple& args) {
87
 
    return new ActionResultHolder(action.Perform(args));
88
 
  }
89
 
 
90
 
 private:
91
 
  std::unique_ptr<T> mutable value_;
92
 
 
93
 
  // T could be a reference type, so = isn't supported.
94
 
  GTEST_DISALLOW_ASSIGN_(ActionResultHolder);
95
 
};
96
 
 
97
 
}
98
 
 
99
 
template<typename T>
100
 
class DefaultValue<std::unique_ptr<T>> {
101
 
 public:
102
 
  // Unsets the default value for type T.
103
 
  static void Clear() {}
104
 
 
105
 
  // Returns true iff the user has set the default value for type T.
106
 
  static bool IsSet() { return false; }
107
 
 
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() {
111
 
    return true;
112
 
  }
113
 
 
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>();
119
 
  }
120
 
};
121
 
 
122
 
}
123
 
 
124
 
#endif /* MIR_TEST_GMOCK_FIXES_H_ */