1 // This file was GENERATED by command: 2 // pump.py mock_callback.h.pump 3 // DO NOT EDIT BY HAND!!! 4 5 // Copyright 2017 The Chromium Authors 6 // Use of this source code is governed by a BSD-style license that can be 7 // found in the LICENSE file. 8 9 // Analogous to GMock's built-in MockFunction, but for base::Callback instead of 10 // std::function. It takes the full callback type as a parameter, so that it can 11 // support both OnceCallback and RepeatingCallback. Furthermore, this file 12 // defines convenience typedefs in the form of MockOnceCallback<Signature>, 13 // MockRepeatingCallback<Signature>, MockOnceClosure and MockRepeatingClosure. 14 // 15 // Use: 16 // using FooCallback = base::RepeatingCallback<int(std::string)>; 17 // 18 // TEST(FooTest, RunsCallbackWithBarArgument) { 19 // base::MockCallback<FooCallback> callback; 20 // EXPECT_CALL(callback, Run("bar")).WillOnce(Return(1)); 21 // Foo(callback.Get()); 22 // } 23 // 24 // Or equivalently: 25 // 26 // TEST(FooTest, RunsCallbackWithBarArgument) { 27 // base::MockRepeatingCallback<int(std::string)> callback; 28 // EXPECT_CALL(callback, Run("bar")).WillOnce(Return(1)); 29 // Foo(callback.Get()); 30 // } 31 // 32 // 33 // Can be used with StrictMock and NiceMock. Caller must ensure that it outlives 34 // any base::Callback obtained from it. 35 36 #ifndef BASE_TEST_MOCK_CALLBACK_H_ 37 #define BASE_TEST_MOCK_CALLBACK_H_ 38 39 #include "base/functional/bind.h" 40 #include "base/functional/callback.h" 41 #include "testing/gmock/include/gmock/gmock.h" 42 43 namespace base { 44 45 // clang-format off 46 47 template <typename F> 48 class MockCallback; 49 50 template <typename Signature> 51 using MockOnceCallback = MockCallback<OnceCallback<Signature>>; 52 template <typename Signature> 53 using MockRepeatingCallback = MockCallback<RepeatingCallback<Signature>>; 54 55 using MockOnceClosure = MockCallback<OnceClosure>; 56 using MockRepeatingClosure = MockCallback<RepeatingClosure>; 57 58 template <typename R> 59 class MockCallback<RepeatingCallback<R()>> { 60 public: 61 MockCallback() = default; 62 63 MockCallback(const MockCallback&) = delete; 64 MockCallback& operator=(const MockCallback&) = delete; 65 66 MOCK_METHOD0_T(Run, R()); 67 Get()68 RepeatingCallback<R()> Get() { 69 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 70 } 71 }; 72 73 template <typename R> 74 class MockCallback<OnceCallback<R()>> { 75 public: 76 MockCallback() = default; 77 78 MockCallback(const MockCallback&) = delete; 79 MockCallback& operator=(const MockCallback&) = delete; 80 81 MOCK_METHOD0_T(Run, R()); 82 Get()83 OnceCallback<R()> Get() { 84 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 85 } 86 }; 87 88 template <typename R, typename A1> 89 class MockCallback<RepeatingCallback<R(A1)>> { 90 public: 91 MockCallback() = default; 92 93 MockCallback(const MockCallback&) = delete; 94 MockCallback& operator=(const MockCallback&) = delete; 95 96 MOCK_METHOD1_T(Run, R(A1)); 97 Get()98 RepeatingCallback<R(A1)> Get() { 99 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 100 } 101 }; 102 103 template <typename R, typename A1> 104 class MockCallback<OnceCallback<R(A1)>> { 105 public: 106 MockCallback() = default; 107 108 MockCallback(const MockCallback&) = delete; 109 MockCallback& operator=(const MockCallback&) = delete; 110 111 MOCK_METHOD1_T(Run, R(A1)); 112 Get()113 OnceCallback<R(A1)> Get() { 114 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 115 } 116 }; 117 118 template <typename R, typename A1, typename A2> 119 class MockCallback<RepeatingCallback<R(A1, A2)>> { 120 public: 121 MockCallback() = default; 122 123 MockCallback(const MockCallback&) = delete; 124 MockCallback& operator=(const MockCallback&) = delete; 125 126 MOCK_METHOD2_T(Run, R(A1, A2)); 127 Get()128 RepeatingCallback<R(A1, A2)> Get() { 129 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 130 } 131 }; 132 133 template <typename R, typename A1, typename A2> 134 class MockCallback<OnceCallback<R(A1, A2)>> { 135 public: 136 MockCallback() = default; 137 138 MockCallback(const MockCallback&) = delete; 139 MockCallback& operator=(const MockCallback&) = delete; 140 141 MOCK_METHOD2_T(Run, R(A1, A2)); 142 Get()143 OnceCallback<R(A1, A2)> Get() { 144 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 145 } 146 }; 147 148 template <typename R, typename A1, typename A2, typename A3> 149 class MockCallback<RepeatingCallback<R(A1, A2, A3)>> { 150 public: 151 MockCallback() = default; 152 153 MockCallback(const MockCallback&) = delete; 154 MockCallback& operator=(const MockCallback&) = delete; 155 156 MOCK_METHOD3_T(Run, R(A1, A2, A3)); 157 Get()158 RepeatingCallback<R(A1, A2, A3)> Get() { 159 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 160 } 161 }; 162 163 template <typename R, typename A1, typename A2, typename A3> 164 class MockCallback<OnceCallback<R(A1, A2, A3)>> { 165 public: 166 MockCallback() = default; 167 168 MockCallback(const MockCallback&) = delete; 169 MockCallback& operator=(const MockCallback&) = delete; 170 171 MOCK_METHOD3_T(Run, R(A1, A2, A3)); 172 Get()173 OnceCallback<R(A1, A2, A3)> Get() { 174 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 175 } 176 }; 177 178 template <typename R, typename A1, typename A2, typename A3, typename A4> 179 class MockCallback<RepeatingCallback<R(A1, A2, A3, A4)>> { 180 public: 181 MockCallback() = default; 182 183 MockCallback(const MockCallback&) = delete; 184 MockCallback& operator=(const MockCallback&) = delete; 185 186 MOCK_METHOD4_T(Run, R(A1, A2, A3, A4)); 187 Get()188 RepeatingCallback<R(A1, A2, A3, A4)> Get() { 189 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 190 } 191 }; 192 193 template <typename R, typename A1, typename A2, typename A3, typename A4> 194 class MockCallback<OnceCallback<R(A1, A2, A3, A4)>> { 195 public: 196 MockCallback() = default; 197 198 MockCallback(const MockCallback&) = delete; 199 MockCallback& operator=(const MockCallback&) = delete; 200 201 MOCK_METHOD4_T(Run, R(A1, A2, A3, A4)); 202 Get()203 OnceCallback<R(A1, A2, A3, A4)> Get() { 204 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 205 } 206 }; 207 208 template <typename R, typename A1, typename A2, typename A3, typename A4, 209 typename A5> 210 class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5)>> { 211 public: 212 MockCallback() = default; 213 214 MockCallback(const MockCallback&) = delete; 215 MockCallback& operator=(const MockCallback&) = delete; 216 217 MOCK_METHOD5_T(Run, R(A1, A2, A3, A4, A5)); 218 Get()219 RepeatingCallback<R(A1, A2, A3, A4, A5)> Get() { 220 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 221 } 222 }; 223 224 template <typename R, typename A1, typename A2, typename A3, typename A4, 225 typename A5> 226 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5)>> { 227 public: 228 MockCallback() = default; 229 230 MockCallback(const MockCallback&) = delete; 231 MockCallback& operator=(const MockCallback&) = delete; 232 233 MOCK_METHOD5_T(Run, R(A1, A2, A3, A4, A5)); 234 Get()235 OnceCallback<R(A1, A2, A3, A4, A5)> Get() { 236 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 237 } 238 }; 239 240 template <typename R, typename A1, typename A2, typename A3, typename A4, 241 typename A5, typename A6> 242 class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6)>> { 243 public: 244 MockCallback() = default; 245 246 MockCallback(const MockCallback&) = delete; 247 MockCallback& operator=(const MockCallback&) = delete; 248 249 MOCK_METHOD6_T(Run, R(A1, A2, A3, A4, A5, A6)); 250 Get()251 RepeatingCallback<R(A1, A2, A3, A4, A5, A6)> Get() { 252 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 253 } 254 }; 255 256 template <typename R, typename A1, typename A2, typename A3, typename A4, 257 typename A5, typename A6> 258 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6)>> { 259 public: 260 MockCallback() = default; 261 262 MockCallback(const MockCallback&) = delete; 263 MockCallback& operator=(const MockCallback&) = delete; 264 265 MOCK_METHOD6_T(Run, R(A1, A2, A3, A4, A5, A6)); 266 Get()267 OnceCallback<R(A1, A2, A3, A4, A5, A6)> Get() { 268 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 269 } 270 }; 271 272 template <typename R, typename A1, typename A2, typename A3, typename A4, 273 typename A5, typename A6, typename A7> 274 class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7)>> { 275 public: 276 MockCallback() = default; 277 278 MockCallback(const MockCallback&) = delete; 279 MockCallback& operator=(const MockCallback&) = delete; 280 281 MOCK_METHOD7_T(Run, R(A1, A2, A3, A4, A5, A6, A7)); 282 Get()283 RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7)> Get() { 284 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 285 } 286 }; 287 288 template <typename R, typename A1, typename A2, typename A3, typename A4, 289 typename A5, typename A6, typename A7> 290 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7)>> { 291 public: 292 MockCallback() = default; 293 294 MockCallback(const MockCallback&) = delete; 295 MockCallback& operator=(const MockCallback&) = delete; 296 297 MOCK_METHOD7_T(Run, R(A1, A2, A3, A4, A5, A6, A7)); 298 Get()299 OnceCallback<R(A1, A2, A3, A4, A5, A6, A7)> Get() { 300 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 301 } 302 }; 303 304 template <typename R, typename A1, typename A2, typename A3, typename A4, 305 typename A5, typename A6, typename A7, typename A8> 306 class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)>> { 307 public: 308 MockCallback() = default; 309 310 MockCallback(const MockCallback&) = delete; 311 MockCallback& operator=(const MockCallback&) = delete; 312 313 MOCK_METHOD8_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8)); 314 Get()315 RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)> Get() { 316 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 317 } 318 }; 319 320 template <typename R, typename A1, typename A2, typename A3, typename A4, 321 typename A5, typename A6, typename A7, typename A8> 322 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)>> { 323 public: 324 MockCallback() = default; 325 326 MockCallback(const MockCallback&) = delete; 327 MockCallback& operator=(const MockCallback&) = delete; 328 329 MOCK_METHOD8_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8)); 330 Get()331 OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)> Get() { 332 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 333 } 334 }; 335 336 template <typename R, typename A1, typename A2, typename A3, typename A4, 337 typename A5, typename A6, typename A7, typename A8, typename A9> 338 class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>> { 339 public: 340 MockCallback() = default; 341 342 MockCallback(const MockCallback&) = delete; 343 MockCallback& operator=(const MockCallback&) = delete; 344 345 MOCK_METHOD9_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9)); 346 Get()347 RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> Get() { 348 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 349 } 350 }; 351 352 template <typename R, typename A1, typename A2, typename A3, typename A4, 353 typename A5, typename A6, typename A7, typename A8, typename A9> 354 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>> { 355 public: 356 MockCallback() = default; 357 358 MockCallback(const MockCallback&) = delete; 359 MockCallback& operator=(const MockCallback&) = delete; 360 361 MOCK_METHOD9_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9)); 362 Get()363 OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> Get() { 364 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 365 } 366 }; 367 368 template <typename R, typename A1, typename A2, typename A3, typename A4, 369 typename A5, typename A6, typename A7, typename A8, typename A9, 370 typename A10> 371 class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, 372 A10)>> { 373 public: 374 MockCallback() = default; 375 376 MockCallback(const MockCallback&) = delete; 377 MockCallback& operator=(const MockCallback&) = delete; 378 379 MOCK_METHOD10_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)); 380 Get()381 RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> Get() { 382 return ::base::BindRepeating(&MockCallback::Run, ::base::Unretained(this)); 383 } 384 }; 385 386 template <typename R, typename A1, typename A2, typename A3, typename A4, 387 typename A5, typename A6, typename A7, typename A8, typename A9, 388 typename A10> 389 class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>> { 390 public: 391 MockCallback() = default; 392 393 MockCallback(const MockCallback&) = delete; 394 MockCallback& operator=(const MockCallback&) = delete; 395 396 MOCK_METHOD10_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)); 397 Get()398 OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> Get() { 399 return ::base::BindOnce(&MockCallback::Run, ::base::Unretained(this)); 400 } 401 }; 402 403 // clang-format on 404 405 } // namespace base 406 407 #endif // BASE_TEST_MOCK_CALLBACK_H_ 408