| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ |
| 62 |
#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ |
| 63 |
|
| 64 |
#include <functional> |
| 65 |
#include <map> |
| 66 |
#include <memory> |
| 67 |
#include <set> |
| 68 |
#include <sstream> |
| 69 |
#include <string> |
| 70 |
#include <type_traits> |
| 71 |
#include <utility> |
| 72 |
#include <vector> |
| 73 |
#include "gmock/gmock-actions.h" |
| 74 |
#include "gmock/gmock-cardinalities.h" |
| 75 |
#include "gmock/gmock-matchers.h" |
| 76 |
#include "gmock/internal/gmock-internal-utils.h" |
| 77 |
#include "gmock/internal/gmock-port.h" |
| 78 |
#include "gtest/gtest.h" |
| 79 |
|
| 80 |
#if GTEST_HAS_EXCEPTIONS |
| 81 |
# include <stdexcept> |
| 82 |
#endif |
| 83 |
|
| 84 |
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ |
| 85 |
) |
| 86 |
|
| 87 |
namespace testing { |
| 88 |
|
| 89 |
|
| 90 |
class Expectation; |
| 91 |
|
| 92 |
|
| 93 |
class ExpectationSet; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
namespace internal { |
| 98 |
|
| 99 |
|
| 100 |
template <typename F> class FunctionMocker; |
| 101 |
|
| 102 |
|
| 103 |
class ExpectationBase; |
| 104 |
|
| 105 |
|
| 106 |
template <typename F> class TypedExpectation; |
| 107 |
|
| 108 |
|
| 109 |
class ExpectationTester; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex); |
| 123 |
|
| 124 |
|
| 125 |
class UntypedActionResultHolderBase; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
class GTEST_API_ UntypedFunctionMockerBase { |
| 131 |
public: |
| 132 |
UntypedFunctionMockerBase(); |
| 133 |
virtual ~UntypedFunctionMockerBase(); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
bool VerifyAndClearExpectationsLocked() |
| 139 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); |
| 140 |
|
| 141 |
|
| 142 |
virtual void ClearDefaultActionsLocked() |
| 143 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( |
| 155 |
void* untyped_args, const std::string& call_description) const = 0; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
virtual UntypedActionResultHolderBase* UntypedPerformAction( |
| 161 |
const void* untyped_action, void* untyped_args) const = 0; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
virtual void UntypedDescribeUninterestingCall( |
| 167 |
const void* untyped_args, |
| 168 |
::std::ostream* os) const |
| 169 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
virtual const ExpectationBase* UntypedFindMatchingExpectation( |
| 178 |
const void* untyped_args, |
| 179 |
const void** untyped_action, bool* is_excessive, |
| 180 |
::std::ostream* what, ::std::ostream* why) |
| 181 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0; |
| 182 |
|
| 183 |
|
| 184 |
virtual void UntypedPrintArgs(const void* untyped_args, |
| 185 |
::std::ostream* os) const = 0; |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
void RegisterOwner(const void* mock_obj) |
| 192 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex); |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
void SetOwnerAndName(const void* mock_obj, const char* name) |
| 198 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex); |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
const void* MockObject() const |
| 204 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex); |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
const char* Name() const |
| 209 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex); |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
UntypedActionResultHolderBase* UntypedInvokeWith(void* untyped_args) |
| 216 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex); |
| 217 |
|
| 218 |
protected: |
| 219 |
typedef std::vector<const void*> UntypedOnCallSpecs; |
| 220 |
|
| 221 |
using UntypedExpectations = std::vector<std::shared_ptr<ExpectationBase>>; |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
Expectation GetHandleOf(ExpectationBase* exp); |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
const void* mock_obj_; |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
const char* name_; |
| 235 |
|
| 236 |
|
| 237 |
UntypedOnCallSpecs untyped_on_call_specs_; |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
UntypedExpectations untyped_expectations_; |
| 249 |
}; |
| 250 |
|
| 251 |
|
| 252 |
class UntypedOnCallSpecBase { |
| 253 |
public: |
| 254 |
|
| 255 |
UntypedOnCallSpecBase(const char* a_file, int a_line) |
| 256 |
: file_(a_file), line_(a_line), last_clause_(kNone) {} |
| 257 |
|
| 258 |
|
| 259 |
const char* file() const { return file_; } |
| 260 |
int line() const { return line_; } |
| 261 |
|
| 262 |
protected: |
| 263 |
|
| 264 |
enum Clause { |
| 265 |
|
| 266 |
|
| 267 |
kNone, |
| 268 |
kWith, |
| 269 |
kWillByDefault |
| 270 |
}; |
| 271 |
|
| 272 |
|
| 273 |
void AssertSpecProperty(bool property, |
| 274 |
const std::string& failure_message) const { |
| 275 |
Assert(property, file_, line_, failure_message); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
void ExpectSpecProperty(bool property, |
| 280 |
const std::string& failure_message) const { |
| 281 |
Expect(property, file_, line_, failure_message); |
| 282 |
} |
| 283 |
|
| 284 |
const char* file_; |
| 285 |
int line_; |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
Clause last_clause_; |
| 290 |
}; |
| 291 |
|
| 292 |
|
| 293 |
template <typename F> |
| 294 |
class OnCallSpec : public UntypedOnCallSpecBase { |
| 295 |
public: |
| 296 |
typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 297 |
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
OnCallSpec(const char* a_file, int a_line, |
| 302 |
const ArgumentMatcherTuple& matchers) |
| 303 |
: UntypedOnCallSpecBase(a_file, a_line), |
| 304 |
matchers_(matchers), |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
extra_matcher_(A<const ArgumentTuple&>()) {} |
| 309 |
|
| 310 |
|
| 311 |
OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) { |
| 312 |
|
| 313 |
ExpectSpecProperty(last_clause_ < kWith, |
| 314 |
".With() cannot appear " |
| 315 |
"more than once in an ON_CALL()."); |
| 316 |
last_clause_ = kWith; |
| 317 |
|
| 318 |
extra_matcher_ = m; |
| 319 |
return *this; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
OnCallSpec& WillByDefault(const Action<F>& action) { |
| 324 |
ExpectSpecProperty(last_clause_ < kWillByDefault, |
| 325 |
".WillByDefault() must appear " |
| 326 |
"exactly once in an ON_CALL()."); |
| 327 |
last_clause_ = kWillByDefault; |
| 328 |
|
| 329 |
ExpectSpecProperty(!action.IsDoDefault(), |
| 330 |
"DoDefault() cannot be used in ON_CALL()."); |
| 331 |
action_ = action; |
| 332 |
return *this; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
bool Matches(const ArgumentTuple& args) const { |
| 337 |
return TupleMatches(matchers_, args) && extra_matcher_.Matches(args); |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
const Action<F>& GetAction() const { |
| 342 |
AssertSpecProperty(last_clause_ == kWillByDefault, |
| 343 |
".WillByDefault() must appear exactly " |
| 344 |
"once in an ON_CALL()."); |
| 345 |
return action_; |
| 346 |
} |
| 347 |
|
| 348 |
private: |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
ArgumentMatcherTuple matchers_; |
| 363 |
Matcher<const ArgumentTuple&> extra_matcher_; |
| 364 |
Action<F> action_; |
| 365 |
}; |
| 366 |
|
| 367 |
|
| 368 |
enum CallReaction { |
| 369 |
kAllow, |
| 370 |
kWarn, |
| 371 |
kFail, |
| 372 |
}; |
| 373 |
|
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
class GTEST_API_ Mock { |
| 378 |
public: |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
static void AllowLeak(const void* mock_obj) |
| 384 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
static bool VerifyAndClearExpectations(void* mock_obj) |
| 390 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
static bool VerifyAndClear(void* mock_obj) |
| 396 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 397 |
|
| 398 |
|
| 399 |
static bool IsNaggy(void* mock_obj) |
| 400 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 401 |
|
| 402 |
static bool IsNice(void* mock_obj) |
| 403 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 404 |
|
| 405 |
static bool IsStrict(void* mock_obj) |
| 406 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 407 |
|
| 408 |
private: |
| 409 |
friend class internal::UntypedFunctionMockerBase; |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
template <typename F> |
| 414 |
friend class internal::FunctionMocker; |
| 415 |
|
| 416 |
template <typename M> |
| 417 |
friend class NiceMock; |
| 418 |
|
| 419 |
template <typename M> |
| 420 |
friend class NaggyMock; |
| 421 |
|
| 422 |
template <typename M> |
| 423 |
friend class StrictMock; |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
static void AllowUninterestingCalls(const void* mock_obj) |
| 428 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
static void WarnUninterestingCalls(const void* mock_obj) |
| 433 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
static void FailUninterestingCalls(const void* mock_obj) |
| 438 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
static void UnregisterCallReaction(const void* mock_obj) |
| 443 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
static internal::CallReaction GetReactionOnUninterestingCalls( |
| 448 |
const void* mock_obj) |
| 449 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
static bool VerifyAndClearExpectationsLocked(void* mock_obj) |
| 455 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex); |
| 456 |
|
| 457 |
|
| 458 |
static void ClearDefaultActionsLocked(void* mock_obj) |
| 459 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex); |
| 460 |
|
| 461 |
|
| 462 |
static void Register( |
| 463 |
const void* mock_obj, |
| 464 |
internal::UntypedFunctionMockerBase* mocker) |
| 465 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
static void RegisterUseByOnCallOrExpectCall( |
| 471 |
const void* mock_obj, const char* file, int line) |
| 472 |
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker) |
| 479 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex); |
| 480 |
}; |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
class GTEST_API_ Expectation { |
| 499 |
public: |
| 500 |
|
| 501 |
Expectation(); |
| 502 |
|
| 503 |
~Expectation(); |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
Expectation(internal::ExpectationBase& exp); |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
bool operator==(const Expectation& rhs) const { |
| 522 |
return expectation_base_ == rhs.expectation_base_; |
| 523 |
} |
| 524 |
|
| 525 |
bool operator!=(const Expectation& rhs) const { return !(*this == rhs); } |
| 526 |
|
| 527 |
private: |
| 528 |
friend class ExpectationSet; |
| 529 |
friend class Sequence; |
| 530 |
friend class ::testing::internal::ExpectationBase; |
| 531 |
friend class ::testing::internal::UntypedFunctionMockerBase; |
| 532 |
|
| 533 |
template <typename F> |
| 534 |
friend class ::testing::internal::FunctionMocker; |
| 535 |
|
| 536 |
template <typename F> |
| 537 |
friend class ::testing::internal::TypedExpectation; |
| 538 |
|
| 539 |
|
| 540 |
class Less { |
| 541 |
public: |
| 542 |
bool operator()(const Expectation& lhs, const Expectation& rhs) const { |
| 543 |
return lhs.expectation_base_.get() < rhs.expectation_base_.get(); |
| 544 |
} |
| 545 |
}; |
| 546 |
|
| 547 |
typedef ::std::set<Expectation, Less> Set; |
| 548 |
|
| 549 |
Expectation( |
| 550 |
const std::shared_ptr<internal::ExpectationBase>& expectation_base); |
| 551 |
|
| 552 |
|
| 553 |
const std::shared_ptr<internal::ExpectationBase>& expectation_base() const { |
| 554 |
return expectation_base_; |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
std::shared_ptr<internal::ExpectationBase> expectation_base_; |
| 559 |
}; |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
class ExpectationSet { |
| 575 |
public: |
| 576 |
|
| 577 |
typedef Expectation::Set::const_iterator const_iterator; |
| 578 |
|
| 579 |
|
| 580 |
typedef Expectation::Set::value_type value_type; |
| 581 |
|
| 582 |
|
| 583 |
ExpectationSet() {} |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
ExpectationSet(internal::ExpectationBase& exp) { |
| 589 |
*this += Expectation(exp); |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
ExpectationSet(const Expectation& e) { |
| 596 |
*this += e; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
bool operator==(const ExpectationSet& rhs) const { |
| 605 |
return expectations_ == rhs.expectations_; |
| 606 |
} |
| 607 |
|
| 608 |
bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); } |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
ExpectationSet& operator+=(const Expectation& e) { |
| 613 |
expectations_.insert(e); |
| 614 |
return *this; |
| 615 |
} |
| 616 |
|
| 617 |
int size() const { return static_cast<int>(expectations_.size()); } |
| 618 |
|
| 619 |
const_iterator begin() const { return expectations_.begin(); } |
| 620 |
const_iterator end() const { return expectations_.end(); } |
| 621 |
|
| 622 |
private: |
| 623 |
Expectation::Set expectations_; |
| 624 |
}; |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
class GTEST_API_ Sequence { |
| 631 |
public: |
| 632 |
|
| 633 |
Sequence() : last_expectation_(new Expectation) {} |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
void AddExpectation(const Expectation& expectation) const; |
| 638 |
|
| 639 |
private: |
| 640 |
|
| 641 |
std::shared_ptr<Expectation> last_expectation_; |
| 642 |
}; |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
class GTEST_API_ InSequence { |
| 669 |
public: |
| 670 |
InSequence(); |
| 671 |
~InSequence(); |
| 672 |
private: |
| 673 |
bool sequence_created_; |
| 674 |
|
| 675 |
GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); |
| 676 |
} GTEST_ATTRIBUTE_UNUSED_; |
| 677 |
|
| 678 |
namespace internal { |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence; |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
class GTEST_API_ ExpectationBase { |
| 699 |
public: |
| 700 |
|
| 701 |
ExpectationBase(const char* file, int line, const std::string& source_text); |
| 702 |
|
| 703 |
virtual ~ExpectationBase(); |
| 704 |
|
| 705 |
|
| 706 |
const char* file() const { return file_; } |
| 707 |
int line() const { return line_; } |
| 708 |
const char* source_text() const { return source_text_.c_str(); } |
| 709 |
|
| 710 |
const Cardinality& cardinality() const { return cardinality_; } |
| 711 |
|
| 712 |
|
| 713 |
void DescribeLocationTo(::std::ostream* os) const { |
| 714 |
*os << FormatFileLocation(file(), line()) << " "; |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
void DescribeCallCountTo(::std::ostream* os) const |
| 720 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0; |
| 725 |
|
| 726 |
protected: |
| 727 |
friend class ::testing::Expectation; |
| 728 |
friend class UntypedFunctionMockerBase; |
| 729 |
|
| 730 |
enum Clause { |
| 731 |
|
| 732 |
kNone, |
| 733 |
kWith, |
| 734 |
kTimes, |
| 735 |
kInSequence, |
| 736 |
kAfter, |
| 737 |
kWillOnce, |
| 738 |
kWillRepeatedly, |
| 739 |
kRetiresOnSaturation |
| 740 |
}; |
| 741 |
|
| 742 |
typedef std::vector<const void*> UntypedActions; |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
virtual Expectation GetHandle() = 0; |
| 747 |
|
| 748 |
|
| 749 |
void AssertSpecProperty(bool property, |
| 750 |
const std::string& failure_message) const { |
| 751 |
Assert(property, file_, line_, failure_message); |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
void ExpectSpecProperty(bool property, |
| 756 |
const std::string& failure_message) const { |
| 757 |
Expect(property, file_, line_, failure_message); |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
void SpecifyCardinality(const Cardinality& cardinality); |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
bool cardinality_specified() const { return cardinality_specified_; } |
| 767 |
|
| 768 |
|
| 769 |
void set_cardinality(const Cardinality& a_cardinality) { |
| 770 |
cardinality_ = a_cardinality; |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
void RetireAllPreRequisites() |
| 779 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); |
| 780 |
|
| 781 |
|
| 782 |
bool is_retired() const |
| 783 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 784 |
g_gmock_mutex.AssertHeld(); |
| 785 |
return retired_; |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
void Retire() |
| 790 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 791 |
g_gmock_mutex.AssertHeld(); |
| 792 |
retired_ = true; |
| 793 |
} |
| 794 |
|
| 795 |
|
| 796 |
bool IsSatisfied() const |
| 797 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 798 |
g_gmock_mutex.AssertHeld(); |
| 799 |
return cardinality().IsSatisfiedByCallCount(call_count_); |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
bool IsSaturated() const |
| 804 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 805 |
g_gmock_mutex.AssertHeld(); |
| 806 |
return cardinality().IsSaturatedByCallCount(call_count_); |
| 807 |
} |
| 808 |
|
| 809 |
|
| 810 |
bool IsOverSaturated() const |
| 811 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 812 |
g_gmock_mutex.AssertHeld(); |
| 813 |
return cardinality().IsOverSaturatedByCallCount(call_count_); |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
bool AllPrerequisitesAreSatisfied() const |
| 819 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); |
| 820 |
|
| 821 |
|
| 822 |
void FindUnsatisfiedPrerequisites(ExpectationSet* result) const |
| 823 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex); |
| 824 |
|
| 825 |
|
| 826 |
int call_count() const |
| 827 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 828 |
g_gmock_mutex.AssertHeld(); |
| 829 |
return call_count_; |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
void IncrementCallCount() |
| 834 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 835 |
g_gmock_mutex.AssertHeld(); |
| 836 |
call_count_++; |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
void CheckActionCountIfNotDone() const |
| 844 |
GTEST_LOCK_EXCLUDED_(mutex_); |
| 845 |
|
| 846 |
friend class ::testing::Sequence; |
| 847 |
friend class ::testing::internal::ExpectationTester; |
| 848 |
|
| 849 |
template <typename Function> |
| 850 |
friend class TypedExpectation; |
| 851 |
|
| 852 |
|
| 853 |
void UntypedTimes(const Cardinality& a_cardinality); |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
const char* file_; |
| 858 |
int line_; |
| 859 |
const std::string source_text_; |
| 860 |
|
| 861 |
bool cardinality_specified_; |
| 862 |
Cardinality cardinality_; |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
ExpectationSet immediate_prerequisites_; |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
int call_count_; |
| 874 |
bool retired_; |
| 875 |
UntypedActions untyped_actions_; |
| 876 |
bool extra_matcher_specified_; |
| 877 |
bool repeated_action_specified_; |
| 878 |
bool retires_on_saturation_; |
| 879 |
Clause last_clause_; |
| 880 |
mutable bool action_count_checked_; |
| 881 |
mutable Mutex mutex_; |
| 882 |
|
| 883 |
GTEST_DISALLOW_ASSIGN_(ExpectationBase); |
| 884 |
}; |
| 885 |
|
| 886 |
|
| 887 |
template <typename F> |
| 888 |
class TypedExpectation : public ExpectationBase { |
| 889 |
public: |
| 890 |
typedef typename Function<F>::ArgumentTuple ArgumentTuple; |
| 891 |
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; |
| 892 |
typedef typename Function<F>::Result Result; |
| 893 |
|
| 894 |
TypedExpectation(FunctionMocker<F>* owner, const char* a_file, int a_line, |
| 895 |
const std::string& a_source_text, |
| 896 |
const ArgumentMatcherTuple& m) |
| 897 |
: ExpectationBase(a_file, a_line, a_source_text), |
| 898 |
owner_(owner), |
| 899 |
matchers_(m), |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
extra_matcher_(A<const ArgumentTuple&>()), |
| 904 |
repeated_action_(DoDefault()) {} |
| 905 |
|
| 906 |
~TypedExpectation() override { |
| 907 |
|
| 908 |
|
| 909 |
CheckActionCountIfNotDone(); |
| 910 |
for (UntypedActions::const_iterator it = untyped_actions_.begin(); |
| 911 |
it != untyped_actions_.end(); ++it) { |
| 912 |
delete static_cast<const Action<F>*>(*it); |
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) { |
| 918 |
if (last_clause_ == kWith) { |
| 919 |
ExpectSpecProperty(false, |
| 920 |
".With() cannot appear " |
| 921 |
"more than once in an EXPECT_CALL()."); |
| 922 |
} else { |
| 923 |
ExpectSpecProperty(last_clause_ < kWith, |
| 924 |
".With() must be the first " |
| 925 |
"clause in an EXPECT_CALL()."); |
| 926 |
} |
| 927 |
last_clause_ = kWith; |
| 928 |
|
| 929 |
extra_matcher_ = m; |
| 930 |
extra_matcher_specified_ = true; |
| 931 |
return *this; |
| 932 |
} |
| 933 |
|
| 934 |
|
| 935 |
TypedExpectation& Times(const Cardinality& a_cardinality) { |
| 936 |
ExpectationBase::UntypedTimes(a_cardinality); |
| 937 |
return *this; |
| 938 |
} |
| 939 |
|
| 940 |
|
| 941 |
TypedExpectation& Times(int n) { |
| 942 |
return Times(Exactly(n)); |
| 943 |
} |
| 944 |
|
| 945 |
|
| 946 |
TypedExpectation& InSequence(const Sequence& s) { |
| 947 |
ExpectSpecProperty(last_clause_ <= kInSequence, |
| 948 |
".InSequence() cannot appear after .After()," |
| 949 |
" .WillOnce(), .WillRepeatedly(), or " |
| 950 |
".RetiresOnSaturation()."); |
| 951 |
last_clause_ = kInSequence; |
| 952 |
|
| 953 |
s.AddExpectation(GetHandle()); |
| 954 |
return *this; |
| 955 |
} |
| 956 |
TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) { |
| 957 |
return InSequence(s1).InSequence(s2); |
| 958 |
} |
| 959 |
TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, |
| 960 |
const Sequence& s3) { |
| 961 |
return InSequence(s1, s2).InSequence(s3); |
| 962 |
} |
| 963 |
TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, |
| 964 |
const Sequence& s3, const Sequence& s4) { |
| 965 |
return InSequence(s1, s2, s3).InSequence(s4); |
| 966 |
} |
| 967 |
TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, |
| 968 |
const Sequence& s3, const Sequence& s4, |
| 969 |
const Sequence& s5) { |
| 970 |
return InSequence(s1, s2, s3, s4).InSequence(s5); |
| 971 |
} |
| 972 |
|
| 973 |
|
| 974 |
TypedExpectation& After(const ExpectationSet& s) { |
| 975 |
ExpectSpecProperty(last_clause_ <= kAfter, |
| 976 |
".After() cannot appear after .WillOnce()," |
| 977 |
" .WillRepeatedly(), or " |
| 978 |
".RetiresOnSaturation()."); |
| 979 |
last_clause_ = kAfter; |
| 980 |
|
| 981 |
for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) { |
| 982 |
immediate_prerequisites_ += *it; |
| 983 |
} |
| 984 |
return *this; |
| 985 |
} |
| 986 |
TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) { |
| 987 |
return After(s1).After(s2); |
| 988 |
} |
| 989 |
TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, |
| 990 |
const ExpectationSet& s3) { |
| 991 |
return After(s1, s2).After(s3); |
| 992 |
} |
| 993 |
TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, |
| 994 |
const ExpectationSet& s3, const ExpectationSet& s4) { |
| 995 |
return After(s1, s2, s3).After(s4); |
| 996 |
} |
| 997 |
TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, |
| 998 |
const ExpectationSet& s3, const ExpectationSet& s4, |
| 999 |
const ExpectationSet& s5) { |
| 1000 |
return After(s1, s2, s3, s4).After(s5); |
| 1001 |
} |
| 1002 |
|
| 1003 |
|
| 1004 |
TypedExpectation& WillOnce(const Action<F>& action) { |
| 1005 |
ExpectSpecProperty(last_clause_ <= kWillOnce, |
| 1006 |
".WillOnce() cannot appear after " |
| 1007 |
".WillRepeatedly() or .RetiresOnSaturation()."); |
| 1008 |
last_clause_ = kWillOnce; |
| 1009 |
|
| 1010 |
untyped_actions_.push_back(new Action<F>(action)); |
| 1011 |
if (!cardinality_specified()) { |
| 1012 |
set_cardinality(Exactly(static_cast<int>(untyped_actions_.size()))); |
| 1013 |
} |
| 1014 |
return *this; |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
TypedExpectation& WillRepeatedly(const Action<F>& action) { |
| 1019 |
if (last_clause_ == kWillRepeatedly) { |
| 1020 |
ExpectSpecProperty(false, |
| 1021 |
".WillRepeatedly() cannot appear " |
| 1022 |
"more than once in an EXPECT_CALL()."); |
| 1023 |
} else { |
| 1024 |
ExpectSpecProperty(last_clause_ < kWillRepeatedly, |
| 1025 |
".WillRepeatedly() cannot appear " |
| 1026 |
"after .RetiresOnSaturation()."); |
| 1027 |
} |
| 1028 |
last_clause_ = kWillRepeatedly; |
| 1029 |
repeated_action_specified_ = true; |
| 1030 |
|
| 1031 |
repeated_action_ = action; |
| 1032 |
if (!cardinality_specified()) { |
| 1033 |
set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size()))); |
| 1034 |
} |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
CheckActionCountIfNotDone(); |
| 1039 |
return *this; |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
TypedExpectation& RetiresOnSaturation() { |
| 1044 |
ExpectSpecProperty(last_clause_ < kRetiresOnSaturation, |
| 1045 |
".RetiresOnSaturation() cannot appear " |
| 1046 |
"more than once."); |
| 1047 |
last_clause_ = kRetiresOnSaturation; |
| 1048 |
retires_on_saturation_ = true; |
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
CheckActionCountIfNotDone(); |
| 1053 |
return *this; |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
const ArgumentMatcherTuple& matchers() const { |
| 1059 |
return matchers_; |
| 1060 |
} |
| 1061 |
|
| 1062 |
|
| 1063 |
const Matcher<const ArgumentTuple&>& extra_matcher() const { |
| 1064 |
return extra_matcher_; |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
const Action<F>& repeated_action() const { return repeated_action_; } |
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
void MaybeDescribeExtraMatcherTo(::std::ostream* os) override { |
| 1073 |
if (extra_matcher_specified_) { |
| 1074 |
*os << " Expected args: "; |
| 1075 |
extra_matcher_.DescribeTo(os); |
| 1076 |
*os << "\n"; |
| 1077 |
} |
| 1078 |
} |
| 1079 |
|
| 1080 |
private: |
| 1081 |
template <typename Function> |
| 1082 |
friend class FunctionMocker; |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
Expectation GetHandle() override { return owner_->GetHandleOf(this); } |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
bool Matches(const ArgumentTuple& args) const |
| 1094 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1095 |
g_gmock_mutex.AssertHeld(); |
| 1096 |
return TupleMatches(matchers_, args) && extra_matcher_.Matches(args); |
| 1097 |
} |
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
bool ShouldHandleArguments(const ArgumentTuple& args) const |
| 1102 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1103 |
g_gmock_mutex.AssertHeld(); |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
CheckActionCountIfNotDone(); |
| 1110 |
return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args); |
| 1111 |
} |
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
void ExplainMatchResultTo( |
| 1116 |
const ArgumentTuple& args, |
| 1117 |
::std::ostream* os) const |
| 1118 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1119 |
g_gmock_mutex.AssertHeld(); |
| 1120 |
|
| 1121 |
if (is_retired()) { |
| 1122 |
*os << " Expected: the expectation is active\n" |
| 1123 |
<< " Actual: it is retired\n"; |
| 1124 |
} else if (!Matches(args)) { |
| 1125 |
if (!TupleMatches(matchers_, args)) { |
| 1126 |
ExplainMatchFailureTupleTo(matchers_, args, os); |
| 1127 |
} |
| 1128 |
StringMatchResultListener listener; |
| 1129 |
if (!extra_matcher_.MatchAndExplain(args, &listener)) { |
| 1130 |
*os << " Expected args: "; |
| 1131 |
extra_matcher_.DescribeTo(os); |
| 1132 |
*os << "\n Actual: don't match"; |
| 1133 |
|
| 1134 |
internal::PrintIfNotEmpty(listener.str(), os); |
| 1135 |
*os << "\n"; |
| 1136 |
} |
| 1137 |
} else if (!AllPrerequisitesAreSatisfied()) { |
| 1138 |
*os << " Expected: all pre-requisites are satisfied\n" |
| 1139 |
<< " Actual: the following immediate pre-requisites " |
| 1140 |
<< "are not satisfied:\n"; |
| 1141 |
ExpectationSet unsatisfied_prereqs; |
| 1142 |
FindUnsatisfiedPrerequisites(&unsatisfied_prereqs); |
| 1143 |
int i = 0; |
| 1144 |
for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin(); |
| 1145 |
it != unsatisfied_prereqs.end(); ++it) { |
| 1146 |
it->expectation_base()->DescribeLocationTo(os); |
| 1147 |
*os << "pre-requisite #" << i++ << "\n"; |
| 1148 |
} |
| 1149 |
*os << " (end of pre-requisites)\n"; |
| 1150 |
} else { |
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
*os << "The call matches the expectation.\n"; |
| 1156 |
} |
| 1157 |
} |
| 1158 |
|
| 1159 |
|
| 1160 |
const Action<F>& GetCurrentAction(const FunctionMocker<F>* mocker, |
| 1161 |
const ArgumentTuple& args) const |
| 1162 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1163 |
g_gmock_mutex.AssertHeld(); |
| 1164 |
const int count = call_count(); |
| 1165 |
Assert(count >= 1, __FILE__, __LINE__, |
| 1166 |
"call_count() is <= 0 when GetCurrentAction() is " |
| 1167 |
"called - this should never happen."); |
| 1168 |
|
| 1169 |
const int action_count = static_cast<int>(untyped_actions_.size()); |
| 1170 |
if (action_count > 0 && !repeated_action_specified_ && |
| 1171 |
count > action_count) { |
| 1172 |
|
| 1173 |
|
| 1174 |
::std::stringstream ss; |
| 1175 |
DescribeLocationTo(&ss); |
| 1176 |
ss << "Actions ran out in " << source_text() << "...\n" |
| 1177 |
<< "Called " << count << " times, but only " |
| 1178 |
<< action_count << " WillOnce()" |
| 1179 |
<< (action_count == 1 ? " is" : "s are") << " specified - "; |
| 1180 |
mocker->DescribeDefaultActionTo(args, &ss); |
| 1181 |
Log(kWarning, ss.str(), 1); |
| 1182 |
} |
| 1183 |
|
| 1184 |
return count <= action_count |
| 1185 |
? *static_cast<const Action<F>*>( |
| 1186 |
untyped_actions_[static_cast<size_t>(count - 1)]) |
| 1187 |
: repeated_action(); |
| 1188 |
} |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
const Action<F>* GetActionForArguments(const FunctionMocker<F>* mocker, |
| 1198 |
const ArgumentTuple& args, |
| 1199 |
::std::ostream* what, |
| 1200 |
::std::ostream* why) |
| 1201 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1202 |
g_gmock_mutex.AssertHeld(); |
| 1203 |
if (IsSaturated()) { |
| 1204 |
|
| 1205 |
IncrementCallCount(); |
| 1206 |
*what << "Mock function called more times than expected - "; |
| 1207 |
mocker->DescribeDefaultActionTo(args, what); |
| 1208 |
DescribeCallCountTo(why); |
| 1209 |
|
| 1210 |
return nullptr; |
| 1211 |
} |
| 1212 |
|
| 1213 |
IncrementCallCount(); |
| 1214 |
RetireAllPreRequisites(); |
| 1215 |
|
| 1216 |
if (retires_on_saturation_ && IsSaturated()) { |
| 1217 |
Retire(); |
| 1218 |
} |
| 1219 |
|
| 1220 |
|
| 1221 |
*what << "Mock function call matches " << source_text() <<"...\n"; |
| 1222 |
return &(GetCurrentAction(mocker, args)); |
| 1223 |
} |
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
FunctionMocker<F>* const owner_; |
| 1228 |
ArgumentMatcherTuple matchers_; |
| 1229 |
Matcher<const ArgumentTuple&> extra_matcher_; |
| 1230 |
Action<F> repeated_action_; |
| 1231 |
|
| 1232 |
GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation); |
| 1233 |
}; |
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity, |
| 1247 |
const char* file, int line, |
| 1248 |
const std::string& message); |
| 1249 |
|
| 1250 |
template <typename F> |
| 1251 |
class MockSpec { |
| 1252 |
public: |
| 1253 |
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; |
| 1254 |
typedef typename internal::Function<F>::ArgumentMatcherTuple |
| 1255 |
ArgumentMatcherTuple; |
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
MockSpec(internal::FunctionMocker<F>* function_mocker, |
| 1260 |
const ArgumentMatcherTuple& matchers) |
| 1261 |
: function_mocker_(function_mocker), matchers_(matchers) {} |
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
internal::OnCallSpec<F>& InternalDefaultActionSetAt( |
| 1266 |
const char* file, int line, const char* obj, const char* call) { |
| 1267 |
LogWithLocation(internal::kInfo, file, line, |
| 1268 |
std::string("ON_CALL(") + obj + ", " + call + ") invoked"); |
| 1269 |
return function_mocker_->AddNewOnCallSpec(file, line, matchers_); |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
internal::TypedExpectation<F>& InternalExpectedAt( |
| 1275 |
const char* file, int line, const char* obj, const char* call) { |
| 1276 |
const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " + |
| 1277 |
call + ")"); |
| 1278 |
LogWithLocation(internal::kInfo, file, line, source_text + " invoked"); |
| 1279 |
return function_mocker_->AddNewExpectation( |
| 1280 |
file, line, source_text, matchers_); |
| 1281 |
} |
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
MockSpec<F>& operator()(const internal::WithoutMatchers&, void* const) { |
| 1287 |
return *this; |
| 1288 |
} |
| 1289 |
|
| 1290 |
private: |
| 1291 |
template <typename Function> |
| 1292 |
friend class internal::FunctionMocker; |
| 1293 |
|
| 1294 |
|
| 1295 |
internal::FunctionMocker<F>* const function_mocker_; |
| 1296 |
|
| 1297 |
ArgumentMatcherTuple matchers_; |
| 1298 |
|
| 1299 |
GTEST_DISALLOW_ASSIGN_(MockSpec); |
| 1300 |
}; |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
template <typename T> |
| 1312 |
class ReferenceOrValueWrapper { |
| 1313 |
public: |
| 1314 |
|
| 1315 |
explicit ReferenceOrValueWrapper(T value) |
| 1316 |
: value_(std::move(value)) { |
| 1317 |
} |
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
T Unwrap() { return std::move(value_); } |
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
const T& Peek() const { |
| 1329 |
return value_; |
| 1330 |
} |
| 1331 |
|
| 1332 |
private: |
| 1333 |
T value_; |
| 1334 |
}; |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
template <typename T> |
| 1339 |
class ReferenceOrValueWrapper<T&> { |
| 1340 |
public: |
| 1341 |
|
| 1342 |
|
| 1343 |
typedef T& reference; |
| 1344 |
explicit ReferenceOrValueWrapper(reference ref) |
| 1345 |
: value_ptr_(&ref) {} |
| 1346 |
T& Unwrap() { return *value_ptr_; } |
| 1347 |
const T& Peek() const { return *value_ptr_; } |
| 1348 |
|
| 1349 |
private: |
| 1350 |
T* value_ptr_; |
| 1351 |
}; |
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355) |
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
class UntypedActionResultHolderBase { |
| 1369 |
public: |
| 1370 |
virtual ~UntypedActionResultHolderBase() {} |
| 1371 |
|
| 1372 |
|
| 1373 |
virtual void PrintAsActionResult(::std::ostream* os) const = 0; |
| 1374 |
}; |
| 1375 |
|
| 1376 |
|
| 1377 |
template <typename T> |
| 1378 |
class ActionResultHolder : public UntypedActionResultHolderBase { |
| 1379 |
public: |
| 1380 |
|
| 1381 |
T Unwrap() { |
| 1382 |
return result_.Unwrap(); |
| 1383 |
} |
| 1384 |
|
| 1385 |
|
| 1386 |
void PrintAsActionResult(::std::ostream* os) const override { |
| 1387 |
*os << "\n Returns: "; |
| 1388 |
|
| 1389 |
UniversalPrinter<T>::Print(result_.Peek(), os); |
| 1390 |
} |
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
template <typename F> |
| 1395 |
static ActionResultHolder* PerformDefaultAction( |
| 1396 |
const FunctionMocker<F>* func_mocker, |
| 1397 |
typename Function<F>::ArgumentTuple&& args, |
| 1398 |
const std::string& call_description) { |
| 1399 |
return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction( |
| 1400 |
std::move(args), call_description))); |
| 1401 |
} |
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
template <typename F> |
| 1406 |
static ActionResultHolder* PerformAction( |
| 1407 |
const Action<F>& action, typename Function<F>::ArgumentTuple&& args) { |
| 1408 |
return new ActionResultHolder( |
| 1409 |
Wrapper(action.Perform(std::move(args)))); |
| 1410 |
} |
| 1411 |
|
| 1412 |
private: |
| 1413 |
typedef ReferenceOrValueWrapper<T> Wrapper; |
| 1414 |
|
| 1415 |
explicit ActionResultHolder(Wrapper result) |
| 1416 |
: result_(std::move(result)) { |
| 1417 |
} |
| 1418 |
|
| 1419 |
Wrapper result_; |
| 1420 |
|
| 1421 |
GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder); |
| 1422 |
}; |
| 1423 |
|
| 1424 |
|
| 1425 |
template <> |
| 1426 |
class ActionResultHolder<void> : public UntypedActionResultHolderBase { |
| 1427 |
public: |
| 1428 |
void Unwrap() { } |
| 1429 |
|
| 1430 |
void PrintAsActionResult(::std::ostream* ) const override {} |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
template <typename F> |
| 1435 |
static ActionResultHolder* PerformDefaultAction( |
| 1436 |
const FunctionMocker<F>* func_mocker, |
| 1437 |
typename Function<F>::ArgumentTuple&& args, |
| 1438 |
const std::string& call_description) { |
| 1439 |
func_mocker->PerformDefaultAction(std::move(args), call_description); |
| 1440 |
return new ActionResultHolder; |
| 1441 |
} |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
template <typename F> |
| 1446 |
static ActionResultHolder* PerformAction( |
| 1447 |
const Action<F>& action, typename Function<F>::ArgumentTuple&& args) { |
| 1448 |
action.Perform(std::move(args)); |
| 1449 |
return new ActionResultHolder; |
| 1450 |
} |
| 1451 |
|
| 1452 |
private: |
| 1453 |
ActionResultHolder() {} |
| 1454 |
GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder); |
| 1455 |
}; |
| 1456 |
|
| 1457 |
template <typename F> |
| 1458 |
class FunctionMocker; |
| 1459 |
|
| 1460 |
template <typename R, typename... Args> |
| 1461 |
class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { |
| 1462 |
using F = R(Args...); |
| 1463 |
|
| 1464 |
public: |
| 1465 |
using Result = R; |
| 1466 |
using ArgumentTuple = std::tuple<Args...>; |
| 1467 |
using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>; |
| 1468 |
|
| 1469 |
FunctionMocker() {} |
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
FunctionMocker(const FunctionMocker&) = delete; |
| 1484 |
FunctionMocker& operator=(const FunctionMocker&) = delete; |
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
~FunctionMocker() override GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { |
| 1490 |
MutexLock l(&g_gmock_mutex); |
| 1491 |
VerifyAndClearExpectationsLocked(); |
| 1492 |
Mock::UnregisterLocked(this); |
| 1493 |
ClearDefaultActionsLocked(); |
| 1494 |
} |
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
const OnCallSpec<F>* FindOnCallSpec( |
| 1500 |
const ArgumentTuple& args) const { |
| 1501 |
for (UntypedOnCallSpecs::const_reverse_iterator it |
| 1502 |
= untyped_on_call_specs_.rbegin(); |
| 1503 |
it != untyped_on_call_specs_.rend(); ++it) { |
| 1504 |
const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it); |
| 1505 |
if (spec->Matches(args)) |
| 1506 |
return spec; |
| 1507 |
} |
| 1508 |
|
| 1509 |
return nullptr; |
| 1510 |
} |
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
Result PerformDefaultAction(ArgumentTuple&& args, |
| 1520 |
const std::string& call_description) const { |
| 1521 |
const OnCallSpec<F>* const spec = |
| 1522 |
this->FindOnCallSpec(args); |
| 1523 |
if (spec != nullptr) { |
| 1524 |
return spec->GetAction().Perform(std::move(args)); |
| 1525 |
} |
| 1526 |
const std::string message = |
| 1527 |
call_description + |
| 1528 |
"\n The mock function has no default action " |
| 1529 |
"set, and its return type has no default value set."; |
| 1530 |
#if GTEST_HAS_EXCEPTIONS |
| 1531 |
if (!DefaultValue<Result>::Exists()) { |
| 1532 |
throw std::runtime_error(message); |
| 1533 |
} |
| 1534 |
#else |
| 1535 |
Assert(DefaultValue<Result>::Exists(), "", -1, message); |
| 1536 |
#endif |
| 1537 |
return DefaultValue<Result>::Get(); |
| 1538 |
} |
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
UntypedActionResultHolderBase* UntypedPerformDefaultAction( |
| 1546 |
void* untyped_args, |
| 1547 |
const std::string& call_description) const override { |
| 1548 |
ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args); |
| 1549 |
return ResultHolder::PerformDefaultAction(this, std::move(*args), |
| 1550 |
call_description); |
| 1551 |
} |
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
UntypedActionResultHolderBase* UntypedPerformAction( |
| 1558 |
const void* untyped_action, void* untyped_args) const override { |
| 1559 |
|
| 1560 |
|
| 1561 |
const Action<F> action = *static_cast<const Action<F>*>(untyped_action); |
| 1562 |
ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args); |
| 1563 |
return ResultHolder::PerformAction(action, std::move(*args)); |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
void ClearDefaultActionsLocked() override |
| 1569 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1570 |
g_gmock_mutex.AssertHeld(); |
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
UntypedOnCallSpecs specs_to_delete; |
| 1580 |
untyped_on_call_specs_.swap(specs_to_delete); |
| 1581 |
|
| 1582 |
g_gmock_mutex.Unlock(); |
| 1583 |
for (UntypedOnCallSpecs::const_iterator it = |
| 1584 |
specs_to_delete.begin(); |
| 1585 |
it != specs_to_delete.end(); ++it) { |
| 1586 |
delete static_cast<const OnCallSpec<F>*>(*it); |
| 1587 |
} |
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
g_gmock_mutex.Lock(); |
| 1592 |
} |
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
Result Invoke(Args... args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { |
| 1598 |
ArgumentTuple tuple(std::forward<Args>(args)...); |
| 1599 |
std::unique_ptr<ResultHolder> holder(DownCast_<ResultHolder*>( |
| 1600 |
this->UntypedInvokeWith(static_cast<void*>(&tuple)))); |
| 1601 |
return holder->Unwrap(); |
| 1602 |
} |
| 1603 |
|
| 1604 |
MockSpec<F> With(Matcher<Args>... m) { |
| 1605 |
return MockSpec<F>(this, ::std::make_tuple(std::move(m)...)); |
| 1606 |
} |
| 1607 |
|
| 1608 |
protected: |
| 1609 |
template <typename Function> |
| 1610 |
friend class MockSpec; |
| 1611 |
|
| 1612 |
typedef ActionResultHolder<Result> ResultHolder; |
| 1613 |
|
| 1614 |
|
| 1615 |
OnCallSpec<F>& AddNewOnCallSpec( |
| 1616 |
const char* file, int line, |
| 1617 |
const ArgumentMatcherTuple& m) |
| 1618 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { |
| 1619 |
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); |
| 1620 |
OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m); |
| 1621 |
untyped_on_call_specs_.push_back(on_call_spec); |
| 1622 |
return *on_call_spec; |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
TypedExpectation<F>& AddNewExpectation(const char* file, int line, |
| 1627 |
const std::string& source_text, |
| 1628 |
const ArgumentMatcherTuple& m) |
| 1629 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { |
| 1630 |
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); |
| 1631 |
TypedExpectation<F>* const expectation = |
| 1632 |
new TypedExpectation<F>(this, file, line, source_text, m); |
| 1633 |
const std::shared_ptr<ExpectationBase> untyped_expectation(expectation); |
| 1634 |
|
| 1635 |
|
| 1636 |
untyped_expectations_.push_back(untyped_expectation); |
| 1637 |
|
| 1638 |
|
| 1639 |
Sequence* const implicit_sequence = g_gmock_implicit_sequence.get(); |
| 1640 |
if (implicit_sequence != nullptr) { |
| 1641 |
implicit_sequence->AddExpectation(Expectation(untyped_expectation)); |
| 1642 |
} |
| 1643 |
|
| 1644 |
return *expectation; |
| 1645 |
} |
| 1646 |
|
| 1647 |
private: |
| 1648 |
template <typename Func> friend class TypedExpectation; |
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
void DescribeDefaultActionTo(const ArgumentTuple& args, |
| 1656 |
::std::ostream* os) const { |
| 1657 |
const OnCallSpec<F>* const spec = FindOnCallSpec(args); |
| 1658 |
|
| 1659 |
if (spec == nullptr) { |
| 1660 |
*os << (std::is_void<Result>::value ? "returning directly.\n" |
| 1661 |
: "returning default value.\n"); |
| 1662 |
} else { |
| 1663 |
*os << "taking default action specified at:\n" |
| 1664 |
<< FormatFileLocation(spec->file(), spec->line()) << "\n"; |
| 1665 |
} |
| 1666 |
} |
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
void UntypedDescribeUninterestingCall(const void* untyped_args, |
| 1672 |
::std::ostream* os) const override |
| 1673 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { |
| 1674 |
const ArgumentTuple& args = |
| 1675 |
*static_cast<const ArgumentTuple*>(untyped_args); |
| 1676 |
*os << "Uninteresting mock function call - "; |
| 1677 |
DescribeDefaultActionTo(args, os); |
| 1678 |
*os << " Function call: " << Name(); |
| 1679 |
UniversalPrint(args, os); |
| 1680 |
} |
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
const ExpectationBase* UntypedFindMatchingExpectation( |
| 1699 |
const void* untyped_args, const void** untyped_action, bool* is_excessive, |
| 1700 |
::std::ostream* what, ::std::ostream* why) override |
| 1701 |
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { |
| 1702 |
const ArgumentTuple& args = |
| 1703 |
*static_cast<const ArgumentTuple*>(untyped_args); |
| 1704 |
MutexLock l(&g_gmock_mutex); |
| 1705 |
TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args); |
| 1706 |
if (exp == nullptr) { |
| 1707 |
this->FormatUnexpectedCallMessageLocked(args, what, why); |
| 1708 |
return nullptr; |
| 1709 |
} |
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
*is_excessive = exp->IsSaturated(); |
| 1715 |
const Action<F>* action = exp->GetActionForArguments(this, args, what, why); |
| 1716 |
if (action != nullptr && action->IsDoDefault()) |
| 1717 |
action = nullptr; |
| 1718 |
*untyped_action = action; |
| 1719 |
return exp; |
| 1720 |
} |
| 1721 |
|
| 1722 |
|
| 1723 |
void UntypedPrintArgs(const void* untyped_args, |
| 1724 |
::std::ostream* os) const override { |
| 1725 |
const ArgumentTuple& args = |
| 1726 |
*static_cast<const ArgumentTuple*>(untyped_args); |
| 1727 |
UniversalPrint(args, os); |
| 1728 |
} |
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
TypedExpectation<F>* FindMatchingExpectationLocked( |
| 1733 |
const ArgumentTuple& args) const |
| 1734 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1735 |
g_gmock_mutex.AssertHeld(); |
| 1736 |
|
| 1737 |
|
| 1738 |
for (typename UntypedExpectations::const_reverse_iterator it = |
| 1739 |
untyped_expectations_.rbegin(); |
| 1740 |
it != untyped_expectations_.rend(); ++it) { |
| 1741 |
TypedExpectation<F>* const exp = |
| 1742 |
static_cast<TypedExpectation<F>*>(it->get()); |
| 1743 |
if (exp->ShouldHandleArguments(args)) { |
| 1744 |
return exp; |
| 1745 |
} |
| 1746 |
} |
| 1747 |
return nullptr; |
| 1748 |
} |
| 1749 |
|
| 1750 |
|
| 1751 |
void FormatUnexpectedCallMessageLocked( |
| 1752 |
const ArgumentTuple& args, |
| 1753 |
::std::ostream* os, |
| 1754 |
::std::ostream* why) const |
| 1755 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1756 |
g_gmock_mutex.AssertHeld(); |
| 1757 |
*os << "\nUnexpected mock function call - "; |
| 1758 |
DescribeDefaultActionTo(args, os); |
| 1759 |
PrintTriedExpectationsLocked(args, why); |
| 1760 |
} |
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
void PrintTriedExpectationsLocked( |
| 1765 |
const ArgumentTuple& args, |
| 1766 |
::std::ostream* why) const |
| 1767 |
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { |
| 1768 |
g_gmock_mutex.AssertHeld(); |
| 1769 |
const size_t count = untyped_expectations_.size(); |
| 1770 |
*why << "Google Mock tried the following " << count << " " |
| 1771 |
<< (count == 1 ? "expectation, but it didn't match" : |
| 1772 |
"expectations, but none matched") |
| 1773 |
<< ":\n"; |
| 1774 |
for (size_t i = 0; i < count; i++) { |
| 1775 |
TypedExpectation<F>* const expectation = |
| 1776 |
static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get()); |
| 1777 |
*why << "\n"; |
| 1778 |
expectation->DescribeLocationTo(why); |
| 1779 |
if (count > 1) { |
| 1780 |
*why << "tried expectation #" << i << ": "; |
| 1781 |
} |
| 1782 |
*why << expectation->source_text() << "...\n"; |
| 1783 |
expectation->ExplainMatchResultTo(args, why); |
| 1784 |
expectation->DescribeCallCountTo(why); |
| 1785 |
} |
| 1786 |
} |
| 1787 |
}; |
| 1788 |
|
| 1789 |
GTEST_DISABLE_MSC_WARNINGS_POP_() |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
void ReportUninterestingCall(CallReaction reaction, const std::string& msg); |
| 1794 |
|
| 1795 |
} |
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
template <typename F> |
| 1844 |
class MockFunction; |
| 1845 |
|
| 1846 |
template <typename R, typename... Args> |
| 1847 |
class MockFunction<R(Args...)> { |
| 1848 |
public: |
| 1849 |
MockFunction() {} |
| 1850 |
MockFunction(const MockFunction&) = delete; |
| 1851 |
MockFunction& operator=(const MockFunction&) = delete; |
| 1852 |
|
| 1853 |
std::function<R(Args...)> AsStdFunction() { |
| 1854 |
return [this](Args... args) -> R { |
| 1855 |
return this->Call(std::forward<Args>(args)...); |
| 1856 |
}; |
| 1857 |
} |
| 1858 |
|
| 1859 |
|
| 1860 |
R Call(Args... args) { |
| 1861 |
mock_.SetOwnerAndName(this, "Call"); |
| 1862 |
return mock_.Invoke(std::forward<Args>(args)...); |
| 1863 |
} |
| 1864 |
|
| 1865 |
internal::MockSpec<R(Args...)> gmock_Call(Matcher<Args>... m) { |
| 1866 |
mock_.RegisterOwner(this); |
| 1867 |
return mock_.With(std::move(m)...); |
| 1868 |
} |
| 1869 |
|
| 1870 |
internal::MockSpec<R(Args...)> gmock_Call(const internal::WithoutMatchers&, |
| 1871 |
R (*)(Args...)) { |
| 1872 |
return this->gmock_Call(::testing::A<Args>()...); |
| 1873 |
} |
| 1874 |
|
| 1875 |
private: |
| 1876 |
internal::FunctionMocker<R(Args...)> mock_; |
| 1877 |
}; |
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
using internal::MockSpec; |
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
template <typename T> |
| 1902 |
inline const T& Const(const T& x) { return x; } |
| 1903 |
|
| 1904 |
|
| 1905 |
inline Expectation::Expectation(internal::ExpectationBase& exp) |
| 1906 |
: expectation_base_(exp.GetHandle().expectation_base()) {} |
| 1907 |
|
| 1908 |
} |
| 1909 |
|
| 1910 |
GTEST_DISABLE_MSC_WARNINGS_POP_() |
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \ |
| 1975 |
((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \ |
| 1976 |
nullptr) \ |
| 1977 |
.Setter(__FILE__, __LINE__, #mock_expr, #call) |
| 1978 |
|
| 1979 |
#define ON_CALL(obj, call) \ |
| 1980 |
GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call) |
| 1981 |
|
| 1982 |
#define EXPECT_CALL(obj, call) \ |
| 1983 |
GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call) |
| 1984 |
|
| 1985 |
#endif |