View | Details | Raw Unified | Return to bug 255915
Collapse All | Expand All

(-)b/net-im/licq/files/patch-3rdparty_gmock_include_gmock_gmock-actions.h (+92 lines)
Added Link Here
1
--- 3rdparty/gmock/include/gmock/gmock-actions.h.orig	2014-10-22 20:07:20 UTC
2
+++ 3rdparty/gmock/include/gmock/gmock-actions.h
3
@@ -163,18 +163,27 @@ class DefaultValue {
4
   // Sets the default value for type T; requires T to be
5
   // copy-constructable and have a public destructor.
6
   static void Set(T x) {
7
-    delete value_;
8
-    value_ = new T(x);
9
+    delete producer_;
10
+    producer_ = new FixedValueProducer(x);
11
   }
12
 
13
+  // Provides a factory function to be called to generate the default value.
14
+  // This method can be used even if T is only move-constructible, but it is not
15
+  // limited to that case.
16
+  typedef T (*FactoryFunction)();
17
+  static void SetFactory(FactoryFunction factory) {
18
+    delete producer_;
19
+    producer_ = new FactoryValueProducer(factory);
20
+  }
21
+
22
   // Unsets the default value for type T.
23
   static void Clear() {
24
-    delete value_;
25
-    value_ = NULL;
26
+    delete producer_;
27
+    producer_ = NULL;
28
   }
29
 
30
   // Returns true iff the user has set the default value for type T.
31
-  static bool IsSet() { return value_ != NULL; }
32
+  static bool IsSet() { return producer_ != NULL; }
33
 
34
   // Returns true if T has a default return value set by the user or there
35
   // exists a built-in default value.
36
@@ -183,15 +192,42 @@ class DefaultValue {
37
   }
38
 
39
   // Returns the default value for type T if the user has set one;
40
-  // otherwise returns the built-in default value if there is one;
41
-  // otherwise aborts the process.
42
+  // otherwise returns the built-in default value. Requires that Exists()
43
+  // is true, which ensures that the return value is well-defined.
44
   static T Get() {
45
-    return value_ == NULL ?
46
-        internal::BuiltInDefaultValue<T>::Get() : *value_;
47
+    return producer_ == NULL ?
48
+        internal::BuiltInDefaultValue<T>::Get() : producer_->Produce();
49
   }
50
 
51
  private:
52
-  static const T* value_;
53
+  class ValueProducer {
54
+   public:
55
+    virtual ~ValueProducer() {}
56
+    virtual T Produce() = 0;
57
+  };
58
+
59
+  class FixedValueProducer : public ValueProducer {
60
+   public:
61
+    explicit FixedValueProducer(T value) : value_(value) {}
62
+    virtual T Produce() { return value_; }
63
+
64
+   private:
65
+    const T value_;
66
+    GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
67
+  };
68
+
69
+  class FactoryValueProducer : public ValueProducer {
70
+   public:
71
+    explicit FactoryValueProducer(FactoryFunction factory)
72
+        : factory_(factory) {}
73
+    virtual T Produce() { return factory_(); }
74
+
75
+   private:
76
+    const FactoryFunction factory_;
77
+    GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
78
+  };
79
+
80
+  static ValueProducer* producer_;
81
 };
82
 
83
 // This partial specialization allows a user to set default values for
84
@@ -241,7 +277,7 @@ class DefaultValue<void> {
85
 
86
 // Points to the user-set default value for type T.
87
 template <typename T>
88
-const T* DefaultValue<T>::value_ = NULL;
89
+typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = NULL;
90
 
91
 // Points to the user-set default value for type T&.
92
 template <typename T>
(-)b/net-im/licq/files/patch-3rdparty_gmock_include_gmock_gmock-spec-builders.h (+183 lines)
Added Link Here
1
--- 3rdparty/gmock/include/gmock/gmock-spec-builders.h.orig	2014-10-22 20:07:20 UTC
2
+++ 3rdparty/gmock/include/gmock/gmock-spec-builders.h
3
@@ -211,7 +211,7 @@ class GTEST_API_ UntypedFunctionMockerBase {
4
   // arguments.  This function can be safely called from multiple
5
   // threads concurrently.  The caller is responsible for deleting the
6
   // result.
7
-  const UntypedActionResultHolderBase* UntypedInvokeWith(
8
+  UntypedActionResultHolderBase* UntypedInvokeWith(
9
       const void* untyped_args)
10
           GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
11
 
12
@@ -1289,6 +1289,58 @@ class MockSpec {
13
   GTEST_DISALLOW_ASSIGN_(MockSpec);
14
 };  // class MockSpec
15
 
16
+// Wrapper type for generically holding an ordinary value or lvalue reference.
17
+// If T is not a reference type, it must be copyable or movable.
18
+// ReferenceOrValueWrapper<T> is movable, and will also be copyable unless
19
+// T is a move-only value type (which means that it will always be copyable
20
+// if the current platform does not support move semantics).
21
+//
22
+// The primary template defines handling for values, but function header
23
+// comments describe the contract for the whole template (including
24
+// specializations).
25
+template <typename T>
26
+class ReferenceOrValueWrapper {
27
+ public:
28
+  // Constructs a wrapper from the given value/reference.
29
+  explicit ReferenceOrValueWrapper(T value)
30
+      : value_(GTEST_MOVE_(value)) {}
31
+
32
+  // Unwraps and returns the underlying value/reference, exactly as
33
+  // originally passed. The behavior of calling this more than once on
34
+  // the same object is unspecified.
35
+  T Unwrap() {
36
+    return GTEST_MOVE_(value_);
37
+  }
38
+
39
+  // Provides nondestructive access to the underlying value/reference.
40
+  // Always returns a const reference (more precisely,
41
+  // const RemoveReference<T>&). The behavior of calling this after
42
+  // calling Unwrap on the same object is unspecified.
43
+  const T& Peek() const {
44
+    return value_;
45
+  }
46
+
47
+ private:
48
+  T value_;
49
+};
50
+
51
+// Specialization for lvalue reference types. See primary template
52
+// for documentation.
53
+template <typename T>
54
+class ReferenceOrValueWrapper<T&> {
55
+ public:
56
+  // Workaround for debatable pass-by-reference lint warning (c-library-team
57
+  // policy precludes NOLINT in this context)
58
+  typedef T& reference;
59
+  explicit ReferenceOrValueWrapper(reference ref)
60
+      : value_ptr_(&ref) {}
61
+  T& Unwrap() { return *value_ptr_; }
62
+  const T& Peek() const { return *value_ptr_; }
63
+
64
+ private:
65
+  T* value_ptr_;
66
+};
67
+
68
 // MSVC warns about using 'this' in base member initializer list, so
69
 // we need to temporarily disable the warning.  We have to do it for
70
 // the entire class to suppress the warning, even though it's about
71
@@ -1320,23 +1372,16 @@ class UntypedActionResultHolderBase {
72
 template <typename T>
73
 class ActionResultHolder : public UntypedActionResultHolderBase {
74
  public:
75
-  explicit ActionResultHolder(T a_value) : value_(a_value) {}
76
-
77
-  // The compiler-generated copy constructor and assignment operator
78
-  // are exactly what we need, so we don't need to define them.
79
-
80
-  // Returns the held value and deletes this object.
81
-  T GetValueAndDelete() const {
82
-    T retval(value_);
83
-    delete this;
84
-    return retval;
85
+  // Returns the held value. Must not be called more than once.
86
+  T Unwrap() {
87
+    return result_.Unwrap();
88
   }
89
 
90
   // Prints the held value as an action's result to os.
91
   virtual void PrintAsActionResult(::std::ostream* os) const {
92
     *os << "\n          Returns: ";
93
     // T may be a reference type, so we don't use UniversalPrint().
94
-    UniversalPrinter<T>::Print(value_, os);
95
+    UniversalPrinter<T>::Print(result_.Peek(), os);
96
   }
97
 
98
   // Performs the given mock function's default action and returns the
99
@@ -1346,8 +1391,8 @@ class ActionResultHolder : public UntypedActionResultH
100
       const FunctionMockerBase<F>* func_mocker,
101
       const typename Function<F>::ArgumentTuple& args,
102
       const string& call_description) {
103
-    return new ActionResultHolder(
104
-        func_mocker->PerformDefaultAction(args, call_description));
105
+    return new ActionResultHolder(Wrapper(
106
+        func_mocker->PerformDefaultAction(args, call_description)));
107
   }
108
 
109
   // Performs the given action and returns the result in a new-ed
110
@@ -1356,42 +1401,52 @@ class ActionResultHolder : public UntypedActionResultH
111
   static ActionResultHolder*
112
   PerformAction(const Action<F>& action,
113
                 const typename Function<F>::ArgumentTuple& args) {
114
-    return new ActionResultHolder(action.Perform(args));
115
+    return new ActionResultHolder(Wrapper(action.Perform(args)));
116
   }
117
 
118
  private:
119
-  T value_;
120
+  typedef ReferenceOrValueWrapper<T> Wrapper;
121
 
122
-  // T could be a reference type, so = isn't supported.
123
-  GTEST_DISALLOW_ASSIGN_(ActionResultHolder);
124
+  explicit ActionResultHolder(Wrapper result)
125
+      : result_(GTEST_MOVE_(result)) {}
126
+
127
+  Wrapper result_;
128
+
129
+  GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
130
 };
131
 
132
 // Specialization for T = void.
133
 template <>
134
 class ActionResultHolder<void> : public UntypedActionResultHolderBase {
135
  public:
136
-  void GetValueAndDelete() const { delete this; }
137
+  void Unwrap() { }
138
 
139
   virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
140
 
141
-  // Performs the given mock function's default action and returns NULL;
142
+  // Performs the given mock function's default action and returns ownership
143
+  // of an empty ActionResultHolder*.
144
   template <typename F>
145
   static ActionResultHolder* PerformDefaultAction(
146
       const FunctionMockerBase<F>* func_mocker,
147
       const typename Function<F>::ArgumentTuple& args,
148
       const string& call_description) {
149
     func_mocker->PerformDefaultAction(args, call_description);
150
-    return NULL;
151
+    return new ActionResultHolder;
152
   }
153
 
154
-  // Performs the given action and returns NULL.
155
+  // Performs the given action and returns ownership of an empty
156
+  // ActionResultHolder*.
157
   template <typename F>
158
   static ActionResultHolder* PerformAction(
159
       const Action<F>& action,
160
       const typename Function<F>::ArgumentTuple& args) {
161
     action.Perform(args);
162
-    return NULL;
163
+    return new ActionResultHolder;
164
   }
165
+
166
+ private:
167
+  ActionResultHolder() {}
168
+  GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
169
 };
170
 
171
 // The base of the function mocker class for the given function type.
172
@@ -1526,8 +1581,9 @@ class FunctionMockerBase : public UntypedFunctionMocke
173
   // threads concurrently.
174
   Result InvokeWith(const ArgumentTuple& args)
175
         GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
176
-    return static_cast<const ResultHolder*>(
177
-        this->UntypedInvokeWith(&args))->GetValueAndDelete();
178
+    scoped_ptr<ResultHolder> holder(
179
+        DownCast_<ResultHolder*>(this->UntypedInvokeWith(&args)));
180
+    return holder->Unwrap();
181
   }
182
 
183
   // Adds and returns a default action spec for this mock function.
(-)b/net-im/licq/files/patch-3rdparty_gmock_include_gmock_internal_gmock-internal-utils.h (+38 lines)
Added Link Here
1
--- 3rdparty/gmock/include/gmock/internal/gmock-internal-utils.h.orig	2014-10-22 20:07:20 UTC
2
+++ 3rdparty/gmock/include/gmock/internal/gmock-internal-utils.h
3
@@ -361,17 +361,30 @@ template <typename T> struct DecayArray<T[]> {
4
   typedef const T* type;
5
 };
6
 
7
-// Invalid<T>() returns an invalid value of type T.  This is useful
8
+// Disable MSVC warnings for infinite recursion, since in this case the
9
+// the recursion is unreachable.
10
+#ifdef _MSC_VER
11
+# pragma warning(push)
12
+# pragma warning(disable:4717)
13
+#endif
14
+
15
+// Invalid<T>() is usable as an expression of type T, but will terminate
16
+// the program with an assertion failure if actually run.  This is useful
17
 // when a value of type T is needed for compilation, but the statement
18
 // will not really be executed (or we don't care if the statement
19
 // crashes).
20
 template <typename T>
21
 inline T Invalid() {
22
-  return const_cast<typename remove_reference<T>::type&>(
23
-      *static_cast<volatile typename remove_reference<T>::type*>(NULL));
24
+  Assert(false, "", -1, "Internal error: attempt to return invalid value");
25
+  // This statement is unreachable, and would never terminate even if it
26
+  // could be reached. It is provided only to placate compiler warnings
27
+  // about missing return statements.
28
+  return Invalid<T>();
29
 }
30
-template <>
31
-inline void Invalid<void>() {}
32
+
33
+#ifdef _MSC_VER
34
+# pragma warning(pop)
35
+#endif
36
 
37
 // Given a raw type (i.e. having no top-level reference or const
38
 // modifier) RawContainer that's either an STL-style container or a
(-)b/net-im/licq/files/patch-3rdparty_gmock_src_gmock-spec-builders.cc (+29 lines)
Added Link Here
1
--- 3rdparty/gmock/src/gmock-spec-builders.cc.orig	2014-10-22 20:07:20 UTC
2
+++ 3rdparty/gmock/src/gmock-spec-builders.cc
3
@@ -325,7 +325,7 @@ const char* UntypedFunctionMockerBase::Name() const
4
 // Calculates the result of invoking this mock function with the given
5
 // arguments, prints it, and returns it.  The caller is responsible
6
 // for deleting the result.
7
-const UntypedActionResultHolderBase*
8
+UntypedActionResultHolderBase*
9
 UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
10
     GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
11
   if (untyped_expectations_.size() == 0) {
12
@@ -363,7 +363,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const voi
13
     this->UntypedDescribeUninterestingCall(untyped_args, &ss);
14
 
15
     // Calculates the function result.
16
-    const UntypedActionResultHolderBase* const result =
17
+    UntypedActionResultHolderBase* const result =
18
         this->UntypedPerformDefaultAction(untyped_args, ss.str());
19
 
20
     // Prints the function result.
21
@@ -410,7 +410,7 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const voi
22
     untyped_expectation->DescribeLocationTo(&loc);
23
   }
24
 
25
-  const UntypedActionResultHolderBase* const result =
26
+  UntypedActionResultHolderBase* const result =
27
       untyped_action == NULL ?
28
       this->UntypedPerformDefaultAction(untyped_args, ss.str()) :
29
       this->UntypedPerformAction(untyped_action, untyped_args);
(-)b/net-im/licq/files/patch-3rdparty_gtest_include_gtest_internal_gtest-port.h (+34 lines)
Added Link Here
1
--- 3rdparty/gtest/include/gtest/internal/gtest-port.h.orig	2014-10-22 20:07:20 UTC
2
+++ 3rdparty/gtest/include/gtest/internal/gtest-port.h
3
@@ -141,6 +141,10 @@
4
 //   GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
5
 //   GTEST_MUST_USE_RESULT_   - declares that a function's result must be used.
6
 //
7
+// C++11 feature wrappers:
8
+//
9
+//   GTEST_MOVE_          - portability wrapper for std::move.
10
+//
11
 // Synchronization:
12
 //   Mutex, MutexLock, ThreadLocal, GetThreadCount()
13
 //                  - synchronization primitives.
14
@@ -211,6 +215,7 @@
15
 #include <iostream>  // NOLINT
16
 #include <sstream>  // NOLINT
17
 #include <string>  // NOLINT
18
+#include <utility>
19
 
20
 #define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
21
 #define GTEST_FLAG_PREFIX_ "gtest_"
22
@@ -737,6 +742,12 @@ using ::std::tuple_size;
23
 #else
24
 # define GTEST_MUST_USE_RESULT_
25
 #endif  // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
26
+
27
+#if GTEST_LANG_CXX11
28
+# define GTEST_MOVE_(x) ::std::move(x)  // NOLINT
29
+#else
30
+# define GTEST_MOVE_(x) x
31
+#endif
32
 
33
 // Determine whether the compiler supports Microsoft's Structured Exception
34
 // Handling.  This is supported by several Windows compilers but generally

Return to bug 255915