00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
00061 #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
00062
00063 #include <map>
00064 #include <set>
00065 #include <sstream>
00066 #include <string>
00067 #include <vector>
00068
00069 #if GTEST_HAS_EXCEPTIONS
00070 # include <stdexcept>
00071 #endif
00072
00073 #include "gmock/gmock-actions.h"
00074 #include "gmock/gmock-cardinalities.h"
00075 #include "gmock/gmock-matchers.h"
00076 #include "gmock/internal/gmock-internal-utils.h"
00077 #include "gmock/internal/gmock-port.h"
00078 #include "gtest/gtest.h"
00079
00080 namespace testing {
00081
00082
00083 class Expectation;
00084
00085
00086 class ExpectationSet;
00087
00088
00089
00090 namespace internal {
00091
00092
00093 template <typename F> class FunctionMocker;
00094
00095
00096 class ExpectationBase;
00097
00098
00099 template <typename F> class TypedExpectation;
00100
00101
00102 class ExpectationTester;
00103
00104
00105 template <typename F> class FunctionMockerBase;
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
00119
00120
00121 class UntypedActionResultHolderBase;
00122
00123
00124
00125
00126 class GTEST_API_ UntypedFunctionMockerBase {
00127 public:
00128 UntypedFunctionMockerBase();
00129 virtual ~UntypedFunctionMockerBase();
00130
00131
00132
00133
00134 bool VerifyAndClearExpectationsLocked()
00135 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
00136
00137
00138 virtual void ClearDefaultActionsLocked()
00139 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
00151 const void* untyped_args,
00152 const string& call_description) const = 0;
00153
00154
00155
00156
00157 virtual UntypedActionResultHolderBase* UntypedPerformAction(
00158 const void* untyped_action,
00159 const void* untyped_args) const = 0;
00160
00161
00162
00163
00164 virtual void UntypedDescribeUninterestingCall(
00165 const void* untyped_args,
00166 ::std::ostream* os) const
00167 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
00168
00169
00170
00171
00172
00173
00174
00175 virtual const ExpectationBase* UntypedFindMatchingExpectation(
00176 const void* untyped_args,
00177 const void** untyped_action, bool* is_excessive,
00178 ::std::ostream* what, ::std::ostream* why)
00179 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
00180
00181
00182 virtual void UntypedPrintArgs(const void* untyped_args,
00183 ::std::ostream* os) const = 0;
00184
00185
00186
00187
00188
00189
00190 void RegisterOwner(const void* mock_obj)
00191 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
00192
00193
00194
00195
00196 void SetOwnerAndName(const void* mock_obj, const char* name)
00197 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
00198
00199
00200
00201
00202 const void* MockObject() const
00203 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
00204
00205
00206
00207 const char* Name() const
00208 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
00209
00210
00211
00212
00213
00214 UntypedActionResultHolderBase* UntypedInvokeWith(
00215 const void* untyped_args)
00216 GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
00217
00218 protected:
00219 typedef std::vector<const void*> UntypedOnCallSpecs;
00220
00221 typedef std::vector<internal::linked_ptr<ExpectationBase> >
00222 UntypedExpectations;
00223
00224
00225
00226 Expectation GetHandleOf(ExpectationBase* exp);
00227
00228
00229
00230
00231 const void* mock_obj_;
00232
00233
00234
00235 const char* name_;
00236
00237
00238 UntypedOnCallSpecs untyped_on_call_specs_;
00239
00240
00241 UntypedExpectations untyped_expectations_;
00242 };
00243
00244
00245 class UntypedOnCallSpecBase {
00246 public:
00247
00248 UntypedOnCallSpecBase(const char* a_file, int a_line)
00249 : file_(a_file), line_(a_line), last_clause_(kNone) {}
00250
00251
00252 const char* file() const { return file_; }
00253 int line() const { return line_; }
00254
00255 protected:
00256
00257 enum Clause {
00258
00259
00260 kNone,
00261 kWith,
00262 kWillByDefault
00263 };
00264
00265
00266 void AssertSpecProperty(bool property, const string& failure_message) const {
00267 Assert(property, file_, line_, failure_message);
00268 }
00269
00270
00271 void ExpectSpecProperty(bool property, const string& failure_message) const {
00272 Expect(property, file_, line_, failure_message);
00273 }
00274
00275 const char* file_;
00276 int line_;
00277
00278
00279
00280 Clause last_clause_;
00281 };
00282
00283
00284 template <typename F>
00285 class OnCallSpec : public UntypedOnCallSpecBase {
00286 public:
00287 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
00288 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
00289
00290
00291
00292 OnCallSpec(const char* a_file, int a_line,
00293 const ArgumentMatcherTuple& matchers)
00294 : UntypedOnCallSpecBase(a_file, a_line),
00295 matchers_(matchers),
00296
00297
00298
00299
00300 extra_matcher_(A<const ArgumentTuple&>()) {
00301 }
00302
00303
00304 OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
00305
00306 ExpectSpecProperty(last_clause_ < kWith,
00307 ".With() cannot appear "
00308 "more than once in an ON_CALL().");
00309 last_clause_ = kWith;
00310
00311 extra_matcher_ = m;
00312 return *this;
00313 }
00314
00315
00316 OnCallSpec& WillByDefault(const Action<F>& action) {
00317 ExpectSpecProperty(last_clause_ < kWillByDefault,
00318 ".WillByDefault() must appear "
00319 "exactly once in an ON_CALL().");
00320 last_clause_ = kWillByDefault;
00321
00322 ExpectSpecProperty(!action.IsDoDefault(),
00323 "DoDefault() cannot be used in ON_CALL().");
00324 action_ = action;
00325 return *this;
00326 }
00327
00328
00329 bool Matches(const ArgumentTuple& args) const {
00330 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
00331 }
00332
00333
00334 const Action<F>& GetAction() const {
00335 AssertSpecProperty(last_clause_ == kWillByDefault,
00336 ".WillByDefault() must appear exactly "
00337 "once in an ON_CALL().");
00338 return action_;
00339 }
00340
00341 private:
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 ArgumentMatcherTuple matchers_;
00356 Matcher<const ArgumentTuple&> extra_matcher_;
00357 Action<F> action_;
00358 };
00359
00360
00361 enum CallReaction {
00362 kAllow,
00363 kWarn,
00364 kFail,
00365 kDefault = kWarn
00366 };
00367
00368 }
00369
00370
00371 class GTEST_API_ Mock {
00372 public:
00373
00374
00375
00376
00377 static void AllowLeak(const void* mock_obj)
00378 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00379
00380
00381
00382
00383 static bool VerifyAndClearExpectations(void* mock_obj)
00384 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00385
00386
00387
00388
00389 static bool VerifyAndClear(void* mock_obj)
00390 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00391
00392 private:
00393 friend class internal::UntypedFunctionMockerBase;
00394
00395
00396
00397 template <typename F>
00398 friend class internal::FunctionMockerBase;
00399
00400 template <typename M>
00401 friend class NiceMock;
00402
00403 template <typename M>
00404 friend class NaggyMock;
00405
00406 template <typename M>
00407 friend class StrictMock;
00408
00409
00410
00411 static void AllowUninterestingCalls(const void* mock_obj)
00412 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00413
00414
00415
00416 static void WarnUninterestingCalls(const void* mock_obj)
00417 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00418
00419
00420
00421 static void FailUninterestingCalls(const void* mock_obj)
00422 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00423
00424
00425
00426 static void UnregisterCallReaction(const void* mock_obj)
00427 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00428
00429
00430
00431 static internal::CallReaction GetReactionOnUninterestingCalls(
00432 const void* mock_obj)
00433 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00434
00435
00436
00437
00438 static bool VerifyAndClearExpectationsLocked(void* mock_obj)
00439 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
00440
00441
00442 static void ClearDefaultActionsLocked(void* mock_obj)
00443 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
00444
00445
00446 static void Register(
00447 const void* mock_obj,
00448 internal::UntypedFunctionMockerBase* mocker)
00449 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00450
00451
00452
00453
00454 static void RegisterUseByOnCallOrExpectCall(
00455 const void* mock_obj, const char* file, int line)
00456 GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
00457
00458
00459
00460
00461
00462 static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
00463 GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
00464 };
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487 class GTEST_API_ Expectation {
00488 public:
00489
00490 Expectation();
00491
00492 ~Expectation();
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503 Expectation(internal::ExpectationBase& exp);
00504
00505
00506
00507
00508
00509 bool operator==(const Expectation& rhs) const {
00510 return expectation_base_ == rhs.expectation_base_;
00511 }
00512
00513 bool operator!=(const Expectation& rhs) const { return !(*this == rhs); }
00514
00515 private:
00516 friend class ExpectationSet;
00517 friend class Sequence;
00518 friend class ::testing::internal::ExpectationBase;
00519 friend class ::testing::internal::UntypedFunctionMockerBase;
00520
00521 template <typename F>
00522 friend class ::testing::internal::FunctionMockerBase;
00523
00524 template <typename F>
00525 friend class ::testing::internal::TypedExpectation;
00526
00527
00528 class Less {
00529 public:
00530 bool operator()(const Expectation& lhs, const Expectation& rhs) const {
00531 return lhs.expectation_base_.get() < rhs.expectation_base_.get();
00532 }
00533 };
00534
00535 typedef ::std::set<Expectation, Less> Set;
00536
00537 Expectation(
00538 const internal::linked_ptr<internal::ExpectationBase>& expectation_base);
00539
00540
00541 const internal::linked_ptr<internal::ExpectationBase>&
00542 expectation_base() const {
00543 return expectation_base_;
00544 }
00545
00546
00547 internal::linked_ptr<internal::ExpectationBase> expectation_base_;
00548 };
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563 class ExpectationSet {
00564 public:
00565
00566 typedef Expectation::Set::const_iterator const_iterator;
00567
00568
00569 typedef Expectation::Set::value_type value_type;
00570
00571
00572 ExpectationSet() {}
00573
00574
00575
00576
00577 ExpectationSet(internal::ExpectationBase& exp) {
00578 *this += Expectation(exp);
00579 }
00580
00581
00582
00583
00584 ExpectationSet(const Expectation& e) {
00585 *this += e;
00586 }
00587
00588
00589
00590
00591
00592
00593 bool operator==(const ExpectationSet& rhs) const {
00594 return expectations_ == rhs.expectations_;
00595 }
00596
00597 bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); }
00598
00599
00600
00601 ExpectationSet& operator+=(const Expectation& e) {
00602 expectations_.insert(e);
00603 return *this;
00604 }
00605
00606 int size() const { return static_cast<int>(expectations_.size()); }
00607
00608 const_iterator begin() const { return expectations_.begin(); }
00609 const_iterator end() const { return expectations_.end(); }
00610
00611 private:
00612 Expectation::Set expectations_;
00613 };
00614
00615
00616
00617
00618
00619 class GTEST_API_ Sequence {
00620 public:
00621
00622 Sequence() : last_expectation_(new Expectation) {}
00623
00624
00625
00626 void AddExpectation(const Expectation& expectation) const;
00627
00628 private:
00629
00630
00631
00632
00633 internal::linked_ptr<Expectation> last_expectation_;
00634 };
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 class GTEST_API_ InSequence {
00661 public:
00662 InSequence();
00663 ~InSequence();
00664 private:
00665 bool sequence_created_;
00666
00667 GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence);
00668 } GTEST_ATTRIBUTE_UNUSED_;
00669
00670 namespace internal {
00671
00672
00673
00674 GTEST_API_ extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690 class GTEST_API_ ExpectationBase {
00691 public:
00692
00693 ExpectationBase(const char* file, int line, const string& source_text);
00694
00695 virtual ~ExpectationBase();
00696
00697
00698 const char* file() const { return file_; }
00699 int line() const { return line_; }
00700 const char* source_text() const { return source_text_.c_str(); }
00701
00702 const Cardinality& cardinality() const { return cardinality_; }
00703
00704
00705 void DescribeLocationTo(::std::ostream* os) const {
00706 *os << FormatFileLocation(file(), line()) << " ";
00707 }
00708
00709
00710
00711 void DescribeCallCountTo(::std::ostream* os) const
00712 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
00713
00714
00715
00716 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
00717
00718 protected:
00719 friend class ::testing::Expectation;
00720 friend class UntypedFunctionMockerBase;
00721
00722 enum Clause {
00723
00724 kNone,
00725 kWith,
00726 kTimes,
00727 kInSequence,
00728 kAfter,
00729 kWillOnce,
00730 kWillRepeatedly,
00731 kRetiresOnSaturation
00732 };
00733
00734 typedef std::vector<const void*> UntypedActions;
00735
00736
00737
00738 virtual Expectation GetHandle() = 0;
00739
00740
00741 void AssertSpecProperty(bool property, const string& failure_message) const {
00742 Assert(property, file_, line_, failure_message);
00743 }
00744
00745
00746 void ExpectSpecProperty(bool property, const string& failure_message) const {
00747 Expect(property, file_, line_, failure_message);
00748 }
00749
00750
00751
00752 void SpecifyCardinality(const Cardinality& cardinality);
00753
00754
00755
00756 bool cardinality_specified() const { return cardinality_specified_; }
00757
00758
00759 void set_cardinality(const Cardinality& a_cardinality) {
00760 cardinality_ = a_cardinality;
00761 }
00762
00763
00764
00765
00766
00767
00768 void RetireAllPreRequisites()
00769 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
00770
00771
00772 bool is_retired() const
00773 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
00774 g_gmock_mutex.AssertHeld();
00775 return retired_;
00776 }
00777
00778
00779 void Retire()
00780 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
00781 g_gmock_mutex.AssertHeld();
00782 retired_ = true;
00783 }
00784
00785
00786 bool IsSatisfied() const
00787 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
00788 g_gmock_mutex.AssertHeld();
00789 return cardinality().IsSatisfiedByCallCount(call_count_);
00790 }
00791
00792
00793 bool IsSaturated() const
00794 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
00795 g_gmock_mutex.AssertHeld();
00796 return cardinality().IsSaturatedByCallCount(call_count_);
00797 }
00798
00799
00800 bool IsOverSaturated() const
00801 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
00802 g_gmock_mutex.AssertHeld();
00803 return cardinality().IsOverSaturatedByCallCount(call_count_);
00804 }
00805
00806
00807 bool AllPrerequisitesAreSatisfied() const
00808 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
00809
00810
00811 void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
00812 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
00813
00814
00815 int call_count() const
00816 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
00817 g_gmock_mutex.AssertHeld();
00818 return call_count_;
00819 }
00820
00821
00822 void IncrementCallCount()
00823 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
00824 g_gmock_mutex.AssertHeld();
00825 call_count_++;
00826 }
00827
00828
00829
00830
00831
00832 void CheckActionCountIfNotDone() const
00833 GTEST_LOCK_EXCLUDED_(mutex_);
00834
00835 friend class ::testing::Sequence;
00836 friend class ::testing::internal::ExpectationTester;
00837
00838 template <typename Function>
00839 friend class TypedExpectation;
00840
00841
00842 void UntypedTimes(const Cardinality& a_cardinality);
00843
00844
00845
00846 const char* file_;
00847 int line_;
00848 const string source_text_;
00849
00850 bool cardinality_specified_;
00851 Cardinality cardinality_;
00852
00853
00854
00855
00856
00857
00858 ExpectationSet immediate_prerequisites_;
00859
00860
00861
00862 int call_count_;
00863 bool retired_;
00864 UntypedActions untyped_actions_;
00865 bool extra_matcher_specified_;
00866 bool repeated_action_specified_;
00867 bool retires_on_saturation_;
00868 Clause last_clause_;
00869 mutable bool action_count_checked_;
00870 mutable Mutex mutex_;
00871
00872 GTEST_DISALLOW_ASSIGN_(ExpectationBase);
00873 };
00874
00875
00876 template <typename F>
00877 class TypedExpectation : public ExpectationBase {
00878 public:
00879 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
00880 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
00881 typedef typename Function<F>::Result Result;
00882
00883 TypedExpectation(FunctionMockerBase<F>* owner,
00884 const char* a_file, int a_line, const string& a_source_text,
00885 const ArgumentMatcherTuple& m)
00886 : ExpectationBase(a_file, a_line, a_source_text),
00887 owner_(owner),
00888 matchers_(m),
00889
00890
00891
00892
00893 extra_matcher_(A<const ArgumentTuple&>()),
00894 repeated_action_(DoDefault()) {}
00895
00896 virtual ~TypedExpectation() {
00897
00898
00899 CheckActionCountIfNotDone();
00900 for (UntypedActions::const_iterator it = untyped_actions_.begin();
00901 it != untyped_actions_.end(); ++it) {
00902 delete static_cast<const Action<F>*>(*it);
00903 }
00904 }
00905
00906
00907 TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) {
00908 if (last_clause_ == kWith) {
00909 ExpectSpecProperty(false,
00910 ".With() cannot appear "
00911 "more than once in an EXPECT_CALL().");
00912 } else {
00913 ExpectSpecProperty(last_clause_ < kWith,
00914 ".With() must be the first "
00915 "clause in an EXPECT_CALL().");
00916 }
00917 last_clause_ = kWith;
00918
00919 extra_matcher_ = m;
00920 extra_matcher_specified_ = true;
00921 return *this;
00922 }
00923
00924
00925 TypedExpectation& Times(const Cardinality& a_cardinality) {
00926 ExpectationBase::UntypedTimes(a_cardinality);
00927 return *this;
00928 }
00929
00930
00931 TypedExpectation& Times(int n) {
00932 return Times(Exactly(n));
00933 }
00934
00935
00936 TypedExpectation& InSequence(const Sequence& s) {
00937 ExpectSpecProperty(last_clause_ <= kInSequence,
00938 ".InSequence() cannot appear after .After(),"
00939 " .WillOnce(), .WillRepeatedly(), or "
00940 ".RetiresOnSaturation().");
00941 last_clause_ = kInSequence;
00942
00943 s.AddExpectation(GetHandle());
00944 return *this;
00945 }
00946 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) {
00947 return InSequence(s1).InSequence(s2);
00948 }
00949 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
00950 const Sequence& s3) {
00951 return InSequence(s1, s2).InSequence(s3);
00952 }
00953 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
00954 const Sequence& s3, const Sequence& s4) {
00955 return InSequence(s1, s2, s3).InSequence(s4);
00956 }
00957 TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2,
00958 const Sequence& s3, const Sequence& s4,
00959 const Sequence& s5) {
00960 return InSequence(s1, s2, s3, s4).InSequence(s5);
00961 }
00962
00963
00964 TypedExpectation& After(const ExpectationSet& s) {
00965 ExpectSpecProperty(last_clause_ <= kAfter,
00966 ".After() cannot appear after .WillOnce(),"
00967 " .WillRepeatedly(), or "
00968 ".RetiresOnSaturation().");
00969 last_clause_ = kAfter;
00970
00971 for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) {
00972 immediate_prerequisites_ += *it;
00973 }
00974 return *this;
00975 }
00976 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) {
00977 return After(s1).After(s2);
00978 }
00979 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
00980 const ExpectationSet& s3) {
00981 return After(s1, s2).After(s3);
00982 }
00983 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
00984 const ExpectationSet& s3, const ExpectationSet& s4) {
00985 return After(s1, s2, s3).After(s4);
00986 }
00987 TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2,
00988 const ExpectationSet& s3, const ExpectationSet& s4,
00989 const ExpectationSet& s5) {
00990 return After(s1, s2, s3, s4).After(s5);
00991 }
00992
00993
00994 TypedExpectation& WillOnce(const Action<F>& action) {
00995 ExpectSpecProperty(last_clause_ <= kWillOnce,
00996 ".WillOnce() cannot appear after "
00997 ".WillRepeatedly() or .RetiresOnSaturation().");
00998 last_clause_ = kWillOnce;
00999
01000 untyped_actions_.push_back(new Action<F>(action));
01001 if (!cardinality_specified()) {
01002 set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
01003 }
01004 return *this;
01005 }
01006
01007
01008 TypedExpectation& WillRepeatedly(const Action<F>& action) {
01009 if (last_clause_ == kWillRepeatedly) {
01010 ExpectSpecProperty(false,
01011 ".WillRepeatedly() cannot appear "
01012 "more than once in an EXPECT_CALL().");
01013 } else {
01014 ExpectSpecProperty(last_clause_ < kWillRepeatedly,
01015 ".WillRepeatedly() cannot appear "
01016 "after .RetiresOnSaturation().");
01017 }
01018 last_clause_ = kWillRepeatedly;
01019 repeated_action_specified_ = true;
01020
01021 repeated_action_ = action;
01022 if (!cardinality_specified()) {
01023 set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
01024 }
01025
01026
01027
01028 CheckActionCountIfNotDone();
01029 return *this;
01030 }
01031
01032
01033 TypedExpectation& RetiresOnSaturation() {
01034 ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
01035 ".RetiresOnSaturation() cannot appear "
01036 "more than once.");
01037 last_clause_ = kRetiresOnSaturation;
01038 retires_on_saturation_ = true;
01039
01040
01041
01042 CheckActionCountIfNotDone();
01043 return *this;
01044 }
01045
01046
01047
01048 const ArgumentMatcherTuple& matchers() const {
01049 return matchers_;
01050 }
01051
01052
01053 const Matcher<const ArgumentTuple&>& extra_matcher() const {
01054 return extra_matcher_;
01055 }
01056
01057
01058 const Action<F>& repeated_action() const { return repeated_action_; }
01059
01060
01061
01062 virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
01063 if (extra_matcher_specified_) {
01064 *os << " Expected args: ";
01065 extra_matcher_.DescribeTo(os);
01066 *os << "\n";
01067 }
01068 }
01069
01070 private:
01071 template <typename Function>
01072 friend class FunctionMockerBase;
01073
01074
01075
01076 virtual Expectation GetHandle() {
01077 return owner_->GetHandleOf(this);
01078 }
01079
01080
01081
01082
01083
01084
01085 bool Matches(const ArgumentTuple& args) const
01086 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
01087 g_gmock_mutex.AssertHeld();
01088 return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
01089 }
01090
01091
01092 bool ShouldHandleArguments(const ArgumentTuple& args) const
01093 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
01094 g_gmock_mutex.AssertHeld();
01095
01096
01097
01098
01099
01100 CheckActionCountIfNotDone();
01101 return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args);
01102 }
01103
01104
01105
01106 void ExplainMatchResultTo(
01107 const ArgumentTuple& args,
01108 ::std::ostream* os) const
01109 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
01110 g_gmock_mutex.AssertHeld();
01111
01112 if (is_retired()) {
01113 *os << " Expected: the expectation is active\n"
01114 << " Actual: it is retired\n";
01115 } else if (!Matches(args)) {
01116 if (!TupleMatches(matchers_, args)) {
01117 ExplainMatchFailureTupleTo(matchers_, args, os);
01118 }
01119 StringMatchResultListener listener;
01120 if (!extra_matcher_.MatchAndExplain(args, &listener)) {
01121 *os << " Expected args: ";
01122 extra_matcher_.DescribeTo(os);
01123 *os << "\n Actual: don't match";
01124
01125 internal::PrintIfNotEmpty(listener.str(), os);
01126 *os << "\n";
01127 }
01128 } else if (!AllPrerequisitesAreSatisfied()) {
01129 *os << " Expected: all pre-requisites are satisfied\n"
01130 << " Actual: the following immediate pre-requisites "
01131 << "are not satisfied:\n";
01132 ExpectationSet unsatisfied_prereqs;
01133 FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
01134 int i = 0;
01135 for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
01136 it != unsatisfied_prereqs.end(); ++it) {
01137 it->expectation_base()->DescribeLocationTo(os);
01138 *os << "pre-requisite #" << i++ << "\n";
01139 }
01140 *os << " (end of pre-requisites)\n";
01141 } else {
01142
01143
01144
01145
01146 *os << "The call matches the expectation.\n";
01147 }
01148 }
01149
01150
01151 const Action<F>& GetCurrentAction(
01152 const FunctionMockerBase<F>* mocker,
01153 const ArgumentTuple& args) const
01154 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
01155 g_gmock_mutex.AssertHeld();
01156 const int count = call_count();
01157 Assert(count >= 1, __FILE__, __LINE__,
01158 "call_count() is <= 0 when GetCurrentAction() is "
01159 "called - this should never happen.");
01160
01161 const int action_count = static_cast<int>(untyped_actions_.size());
01162 if (action_count > 0 && !repeated_action_specified_ &&
01163 count > action_count) {
01164
01165
01166 ::std::stringstream ss;
01167 DescribeLocationTo(&ss);
01168 ss << "Actions ran out in " << source_text() << "...\n"
01169 << "Called " << count << " times, but only "
01170 << action_count << " WillOnce()"
01171 << (action_count == 1 ? " is" : "s are") << " specified - ";
01172 mocker->DescribeDefaultActionTo(args, &ss);
01173 Log(kWarning, ss.str(), 1);
01174 }
01175
01176 return count <= action_count ?
01177 *static_cast<const Action<F>*>(untyped_actions_[count - 1]) :
01178 repeated_action();
01179 }
01180
01181
01182
01183
01184
01185
01186
01187
01188 const Action<F>* GetActionForArguments(
01189 const FunctionMockerBase<F>* mocker,
01190 const ArgumentTuple& args,
01191 ::std::ostream* what,
01192 ::std::ostream* why)
01193 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
01194 g_gmock_mutex.AssertHeld();
01195 if (IsSaturated()) {
01196
01197 IncrementCallCount();
01198 *what << "Mock function called more times than expected - ";
01199 mocker->DescribeDefaultActionTo(args, what);
01200 DescribeCallCountTo(why);
01201
01202
01203
01204
01205 return NULL;
01206 }
01207
01208 IncrementCallCount();
01209 RetireAllPreRequisites();
01210
01211 if (retires_on_saturation_ && IsSaturated()) {
01212 Retire();
01213 }
01214
01215
01216 *what << "Mock function call matches " << source_text() <<"...\n";
01217 return &(GetCurrentAction(mocker, args));
01218 }
01219
01220
01221
01222 FunctionMockerBase<F>* const owner_;
01223 ArgumentMatcherTuple matchers_;
01224 Matcher<const ArgumentTuple&> extra_matcher_;
01225 Action<F> repeated_action_;
01226
01227 GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
01228 };
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241 GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
01242 const char* file, int line,
01243 const string& message);
01244
01245 template <typename F>
01246 class MockSpec {
01247 public:
01248 typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
01249 typedef typename internal::Function<F>::ArgumentMatcherTuple
01250 ArgumentMatcherTuple;
01251
01252
01253
01254 explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker)
01255 : function_mocker_(function_mocker) {}
01256
01257
01258
01259 internal::OnCallSpec<F>& InternalDefaultActionSetAt(
01260 const char* file, int line, const char* obj, const char* call) {
01261 LogWithLocation(internal::kInfo, file, line,
01262 string("ON_CALL(") + obj + ", " + call + ") invoked");
01263 return function_mocker_->AddNewOnCallSpec(file, line, matchers_);
01264 }
01265
01266
01267
01268 internal::TypedExpectation<F>& InternalExpectedAt(
01269 const char* file, int line, const char* obj, const char* call) {
01270 const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")");
01271 LogWithLocation(internal::kInfo, file, line, source_text + " invoked");
01272 return function_mocker_->AddNewExpectation(
01273 file, line, source_text, matchers_);
01274 }
01275
01276 private:
01277 template <typename Function>
01278 friend class internal::FunctionMocker;
01279
01280 void SetMatchers(const ArgumentMatcherTuple& matchers) {
01281 matchers_ = matchers;
01282 }
01283
01284
01285 internal::FunctionMockerBase<F>* const function_mocker_;
01286
01287 ArgumentMatcherTuple matchers_;
01288
01289 GTEST_DISALLOW_ASSIGN_(MockSpec);
01290 };
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301 template <typename T>
01302 class ReferenceOrValueWrapper {
01303 public:
01304
01305 explicit ReferenceOrValueWrapper(T value)
01306 : value_(::testing::internal::move(value)) {
01307 }
01308
01309
01310
01311
01312 T Unwrap() { return ::testing::internal::move(value_); }
01313
01314
01315
01316
01317
01318 const T& Peek() const {
01319 return value_;
01320 }
01321
01322 private:
01323 T value_;
01324 };
01325
01326
01327
01328 template <typename T>
01329 class ReferenceOrValueWrapper<T&> {
01330 public:
01331
01332
01333 typedef T& reference;
01334 explicit ReferenceOrValueWrapper(reference ref)
01335 : value_ptr_(&ref) {}
01336 T& Unwrap() { return *value_ptr_; }
01337 const T& Peek() const { return *value_ptr_; }
01338
01339 private:
01340 T* value_ptr_;
01341 };
01342
01343
01344
01345
01346
01347
01348 #ifdef _MSC_VER
01349 # pragma warning(push) // Saves the current warning state.
01350 # pragma warning(disable:4355) // Temporarily disables warning 4355.
01351 #endif // _MSV_VER
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362 class UntypedActionResultHolderBase {
01363 public:
01364 virtual ~UntypedActionResultHolderBase() {}
01365
01366
01367 virtual void PrintAsActionResult(::std::ostream* os) const = 0;
01368 };
01369
01370
01371 template <typename T>
01372 class ActionResultHolder : public UntypedActionResultHolderBase {
01373 public:
01374
01375 T Unwrap() {
01376 return result_.Unwrap();
01377 }
01378
01379
01380 virtual void PrintAsActionResult(::std::ostream* os) const {
01381 *os << "\n Returns: ";
01382
01383 UniversalPrinter<T>::Print(result_.Peek(), os);
01384 }
01385
01386
01387
01388 template <typename F>
01389 static ActionResultHolder* PerformDefaultAction(
01390 const FunctionMockerBase<F>* func_mocker,
01391 const typename Function<F>::ArgumentTuple& args,
01392 const string& call_description) {
01393 return new ActionResultHolder(Wrapper(
01394 func_mocker->PerformDefaultAction(args, call_description)));
01395 }
01396
01397
01398
01399 template <typename F>
01400 static ActionResultHolder*
01401 PerformAction(const Action<F>& action,
01402 const typename Function<F>::ArgumentTuple& args) {
01403 return new ActionResultHolder(Wrapper(action.Perform(args)));
01404 }
01405
01406 private:
01407 typedef ReferenceOrValueWrapper<T> Wrapper;
01408
01409 explicit ActionResultHolder(Wrapper result)
01410 : result_(::testing::internal::move(result)) {
01411 }
01412
01413 Wrapper result_;
01414
01415 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
01416 };
01417
01418
01419 template <>
01420 class ActionResultHolder<void> : public UntypedActionResultHolderBase {
01421 public:
01422 void Unwrap() { }
01423
01424 virtual void PrintAsActionResult(::std::ostream* ) const {}
01425
01426
01427
01428 template <typename F>
01429 static ActionResultHolder* PerformDefaultAction(
01430 const FunctionMockerBase<F>* func_mocker,
01431 const typename Function<F>::ArgumentTuple& args,
01432 const string& call_description) {
01433 func_mocker->PerformDefaultAction(args, call_description);
01434 return new ActionResultHolder;
01435 }
01436
01437
01438
01439 template <typename F>
01440 static ActionResultHolder* PerformAction(
01441 const Action<F>& action,
01442 const typename Function<F>::ArgumentTuple& args) {
01443 action.Perform(args);
01444 return new ActionResultHolder;
01445 }
01446
01447 private:
01448 ActionResultHolder() {}
01449 GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionResultHolder);
01450 };
01451
01452
01453
01454
01455 template <typename F>
01456 class FunctionMockerBase : public UntypedFunctionMockerBase {
01457 public:
01458 typedef typename Function<F>::Result Result;
01459 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
01460 typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
01461
01462 FunctionMockerBase() : current_spec_(this) {}
01463
01464
01465
01466
01467 virtual ~FunctionMockerBase()
01468 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
01469 MutexLock l(&g_gmock_mutex);
01470 VerifyAndClearExpectationsLocked();
01471 Mock::UnregisterLocked(this);
01472 ClearDefaultActionsLocked();
01473 }
01474
01475
01476
01477
01478 const OnCallSpec<F>* FindOnCallSpec(
01479 const ArgumentTuple& args) const {
01480 for (UntypedOnCallSpecs::const_reverse_iterator it
01481 = untyped_on_call_specs_.rbegin();
01482 it != untyped_on_call_specs_.rend(); ++it) {
01483 const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
01484 if (spec->Matches(args))
01485 return spec;
01486 }
01487
01488 return NULL;
01489 }
01490
01491
01492
01493
01494
01495
01496
01497
01498 Result PerformDefaultAction(const ArgumentTuple& args,
01499 const string& call_description) const {
01500 const OnCallSpec<F>* const spec =
01501 this->FindOnCallSpec(args);
01502 if (spec != NULL) {
01503 return spec->GetAction().Perform(args);
01504 }
01505 const string message = call_description +
01506 "\n The mock function has no default action "
01507 "set, and its return type has no default value set.";
01508 #if GTEST_HAS_EXCEPTIONS
01509 if (!DefaultValue<Result>::Exists()) {
01510 throw std::runtime_error(message);
01511 }
01512 #else
01513 Assert(DefaultValue<Result>::Exists(), "", -1, message);
01514 #endif
01515 return DefaultValue<Result>::Get();
01516 }
01517
01518
01519
01520
01521
01522
01523 virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
01524 const void* untyped_args,
01525 const string& call_description) const {
01526 const ArgumentTuple& args =
01527 *static_cast<const ArgumentTuple*>(untyped_args);
01528 return ResultHolder::PerformDefaultAction(this, args, call_description);
01529 }
01530
01531
01532
01533
01534
01535 virtual UntypedActionResultHolderBase* UntypedPerformAction(
01536 const void* untyped_action, const void* untyped_args) const {
01537
01538
01539 const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
01540 const ArgumentTuple& args =
01541 *static_cast<const ArgumentTuple*>(untyped_args);
01542 return ResultHolder::PerformAction(action, args);
01543 }
01544
01545
01546
01547 virtual void ClearDefaultActionsLocked()
01548 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
01549 g_gmock_mutex.AssertHeld();
01550
01551
01552
01553
01554
01555
01556
01557
01558 UntypedOnCallSpecs specs_to_delete;
01559 untyped_on_call_specs_.swap(specs_to_delete);
01560
01561 g_gmock_mutex.Unlock();
01562 for (UntypedOnCallSpecs::const_iterator it =
01563 specs_to_delete.begin();
01564 it != specs_to_delete.end(); ++it) {
01565 delete static_cast<const OnCallSpec<F>*>(*it);
01566 }
01567
01568
01569
01570 g_gmock_mutex.Lock();
01571 }
01572
01573 protected:
01574 template <typename Function>
01575 friend class MockSpec;
01576
01577 typedef ActionResultHolder<Result> ResultHolder;
01578
01579
01580
01581
01582 Result InvokeWith(const ArgumentTuple& args)
01583 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
01584 scoped_ptr<ResultHolder> holder(
01585 DownCast_<ResultHolder*>(this->UntypedInvokeWith(&args)));
01586 return holder->Unwrap();
01587 }
01588
01589
01590 OnCallSpec<F>& AddNewOnCallSpec(
01591 const char* file, int line,
01592 const ArgumentMatcherTuple& m)
01593 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
01594 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
01595 OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
01596 untyped_on_call_specs_.push_back(on_call_spec);
01597 return *on_call_spec;
01598 }
01599
01600
01601 TypedExpectation<F>& AddNewExpectation(
01602 const char* file,
01603 int line,
01604 const string& source_text,
01605 const ArgumentMatcherTuple& m)
01606 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
01607 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
01608 TypedExpectation<F>* const expectation =
01609 new TypedExpectation<F>(this, file, line, source_text, m);
01610 const linked_ptr<ExpectationBase> untyped_expectation(expectation);
01611 untyped_expectations_.push_back(untyped_expectation);
01612
01613
01614 Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
01615 if (implicit_sequence != NULL) {
01616 implicit_sequence->AddExpectation(Expectation(untyped_expectation));
01617 }
01618
01619 return *expectation;
01620 }
01621
01622
01623
01624 MockSpec<F>& current_spec() { return current_spec_; }
01625
01626 private:
01627 template <typename Func> friend class TypedExpectation;
01628
01629
01630
01631
01632
01633
01634 void DescribeDefaultActionTo(const ArgumentTuple& args,
01635 ::std::ostream* os) const {
01636 const OnCallSpec<F>* const spec = FindOnCallSpec(args);
01637
01638 if (spec == NULL) {
01639 *os << (internal::type_equals<Result, void>::value ?
01640 "returning directly.\n" :
01641 "returning default value.\n");
01642 } else {
01643 *os << "taking default action specified at:\n"
01644 << FormatFileLocation(spec->file(), spec->line()) << "\n";
01645 }
01646 }
01647
01648
01649
01650
01651 virtual void UntypedDescribeUninterestingCall(
01652 const void* untyped_args,
01653 ::std::ostream* os) const
01654 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
01655 const ArgumentTuple& args =
01656 *static_cast<const ArgumentTuple*>(untyped_args);
01657 *os << "Uninteresting mock function call - ";
01658 DescribeDefaultActionTo(args, os);
01659 *os << " Function call: " << Name();
01660 UniversalPrint(args, os);
01661 }
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679 virtual const ExpectationBase* UntypedFindMatchingExpectation(
01680 const void* untyped_args,
01681 const void** untyped_action, bool* is_excessive,
01682 ::std::ostream* what, ::std::ostream* why)
01683 GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
01684 const ArgumentTuple& args =
01685 *static_cast<const ArgumentTuple*>(untyped_args);
01686 MutexLock l(&g_gmock_mutex);
01687 TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
01688 if (exp == NULL) {
01689 this->FormatUnexpectedCallMessageLocked(args, what, why);
01690 return NULL;
01691 }
01692
01693
01694
01695
01696 *is_excessive = exp->IsSaturated();
01697 const Action<F>* action = exp->GetActionForArguments(this, args, what, why);
01698 if (action != NULL && action->IsDoDefault())
01699 action = NULL;
01700 *untyped_action = action;
01701 return exp;
01702 }
01703
01704
01705 virtual void UntypedPrintArgs(const void* untyped_args,
01706 ::std::ostream* os) const {
01707 const ArgumentTuple& args =
01708 *static_cast<const ArgumentTuple*>(untyped_args);
01709 UniversalPrint(args, os);
01710 }
01711
01712
01713
01714 TypedExpectation<F>* FindMatchingExpectationLocked(
01715 const ArgumentTuple& args) const
01716 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
01717 g_gmock_mutex.AssertHeld();
01718 for (typename UntypedExpectations::const_reverse_iterator it =
01719 untyped_expectations_.rbegin();
01720 it != untyped_expectations_.rend(); ++it) {
01721 TypedExpectation<F>* const exp =
01722 static_cast<TypedExpectation<F>*>(it->get());
01723 if (exp->ShouldHandleArguments(args)) {
01724 return exp;
01725 }
01726 }
01727 return NULL;
01728 }
01729
01730
01731 void FormatUnexpectedCallMessageLocked(
01732 const ArgumentTuple& args,
01733 ::std::ostream* os,
01734 ::std::ostream* why) const
01735 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
01736 g_gmock_mutex.AssertHeld();
01737 *os << "\nUnexpected mock function call - ";
01738 DescribeDefaultActionTo(args, os);
01739 PrintTriedExpectationsLocked(args, why);
01740 }
01741
01742
01743
01744 void PrintTriedExpectationsLocked(
01745 const ArgumentTuple& args,
01746 ::std::ostream* why) const
01747 GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
01748 g_gmock_mutex.AssertHeld();
01749 const int count = static_cast<int>(untyped_expectations_.size());
01750 *why << "Google Mock tried the following " << count << " "
01751 << (count == 1 ? "expectation, but it didn't match" :
01752 "expectations, but none matched")
01753 << ":\n";
01754 for (int i = 0; i < count; i++) {
01755 TypedExpectation<F>* const expectation =
01756 static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get());
01757 *why << "\n";
01758 expectation->DescribeLocationTo(why);
01759 if (count > 1) {
01760 *why << "tried expectation #" << i << ": ";
01761 }
01762 *why << expectation->source_text() << "...\n";
01763 expectation->ExplainMatchResultTo(args, why);
01764 expectation->DescribeCallCountTo(why);
01765 }
01766 }
01767
01768
01769
01770 MockSpec<F> current_spec_;
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784 GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase);
01785 };
01786
01787 #ifdef _MSC_VER
01788 # pragma warning(pop) // Restores the warning state.
01789 #endif // _MSV_VER
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799 void ReportUninterestingCall(CallReaction reaction, const string& msg);
01800
01801 }
01802
01803
01804
01805
01806
01807
01808 using internal::MockSpec;
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825 template <typename T>
01826 inline const T& Const(const T& x) { return x; }
01827
01828
01829 inline Expectation::Expectation(internal::ExpectationBase& exp)
01830 : expectation_base_(exp.GetHandle().expectation_base()) {}
01831
01832 }
01833
01834
01835
01836
01837
01838 #define GMOCK_ON_CALL_IMPL_(obj, call) \
01839 ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \
01840 #obj, #call)
01841 #define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call)
01842
01843 #define GMOCK_EXPECT_CALL_IMPL_(obj, call) \
01844 ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
01845 #define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call)
01846
01847 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_