00001
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 #ifndef MOCKPP_INVOCATIONBUILDER_H
00036 #define MOCKPP_INVOCATIONBUILDER_H
00037
00038 #include <mockpp/mockpp.h>
00039
00040 #include <mockpp/builder/BuilderNamespace.h>
00041 #include <mockpp/builder/IdentityBuilder.h>
00042 #include <mockpp/builder/MatchBuilder.h>
00043
00044 #include <mockpp/stub/StubHolder.h>
00045
00046 #include <mockpp/matcher/ArgumentsMatcher.h>
00047 #include <mockpp/matcher/MatcherHolder.h>
00048
00049 #include <mockpp/chaining/StubMatchersCollection.h>
00050
00051
00052 MOCKPP_NS_START
00053
00058 template <typename AMB>
00059 class InvocationMockerBuilder : public AMB
00060 {
00061 typedef typename AMB::ReturnType R;
00062 typedef typename AMB::InvocationType I;
00063 typedef typename AMB::ConstraintSetType MOCKPP_CS;
00064
00065 public:
00066
00072 InvocationMockerBuilder( StubMatchersCollection<R, I> *in_mocker,
00073 BuilderNamespace *in_builderNamespace )
00074 : mocker( in_mocker )
00075 , builderNamespace( in_builderNamespace )
00076 {}
00077
00082 virtual MatchBuilder<R, I> &match( const MatcherHolder<I> &customMatcher )
00083 {
00084 return addMatcher( customMatcher );
00085 }
00086
00091 IdentityBuilder &expect( const MatcherHolder<I> &expectation )
00092 {
00093 return addMatcher( expectation );
00094 }
00095
00100 void id( const String &invocationID )
00101 {
00102 mocker->setName( invocationID );
00103 builderNamespace->registerUniqueID( invocationID, new MatchBuilderAdapter<R, I>(this) );
00104 }
00105
00109 virtual void setStub( const StubHolder<R, I> &stubAction )
00110 {
00111 mocker->setStub( stubAction );
00112 }
00113
00114 protected:
00115
00120 virtual MatchBuilder<R, I> &with_cs( const MOCKPP_CS &constraintset )
00121 {
00122 return internalWith_cs( constraintset);
00123 }
00124
00130 virtual MatchBuilder<R, I> &internalWith_cs( const MOCKPP_CS &constraintset )
00131 {
00132 return addMatcher( new ArgumentsMatcher<I>( constraintset ) );
00133 }
00134
00138 virtual BuilderNamespace *getBuilderNamespace()
00139 {
00140 return builderNamespace;
00141 }
00142
00146 virtual StubMatchersCollection<R, I> *getMocker()
00147 {
00148 return mocker;
00149 }
00150
00151 private:
00152
00157 virtual MatchBuilder<R, I> &addMatcher( const MatcherHolder<I> &matcher )
00158 {
00159 mocker->addMatcher( matcher );
00160 return *this;
00161 }
00162
00163 StubMatchersCollection<R, I> *mocker;
00164 BuilderNamespace *builderNamespace;
00165 };
00166
00167
00168 MOCKPP_NS_END
00169
00170
00171 #endif // MOCKPP_INVOCATIONBUILDER_H