00001
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 #ifndef MOCKPP_CHAININGMOCKBUILDER_H
00035 #define MOCKPP_CHAININGMOCKBUILDER_H
00036
00037 #include <mockpp/mockpp.h>
00038
00039 #include MOCKPP_MAP_H
00040
00041 #include <mockpp/chaining/DynamicChainingMock.h>
00042 #include <mockpp/chaining/InvocationMocker.h>
00043
00044 #include <mockpp/builder/BuilderNamespace.h>
00045 #include <mockpp/builder/MatchBuilder.h>
00046 #include <mockpp/builder/InvocationMockerBuilder.h>
00047
00048 #include <mockpp/matcher/MatcherHolder.h>
00049
00050
00051 MOCKPP_NS_START
00052
00053
00057 template <typename AMB>
00058 class ChainingMockBuilder : public DynamicChainingMock < typename AMB::ReturnType,
00059 typename AMB::InvocationType >
00060 {
00061 typedef typename AMB::ReturnType R;
00062 typedef typename AMB::InvocationType I;
00063
00064 public:
00065
00072 ChainingMockBuilder( DynamicChainingMock<R, I> *in_coreMock,
00073 BuilderNamespace *in_buildernamespace,
00074 const String &name )
00075 : DynamicChainingMock<R, I>(name )
00076 , coreMock( in_coreMock )
00077 , buildernamespace(in_buildernamespace)
00078 {}
00079
00083 String toString() const
00084 {
00085 return coreMock->toString();
00086 }
00087
00091 virtual void verify()
00092 {
00093 coreMock->verify();
00094 }
00095
00099 virtual void addInvokable( typename Invokable<R, I>::AP invokable )
00100 {
00101 coreMock->addInvokable( invokable );
00102 }
00103
00108 InvocationMockerBuilder<AMB>& stubs()
00109 {
00110 return addNewInvocationMocker();
00111 }
00112
00118 InvocationMockerBuilder<AMB>& stubs( const MatcherHolder<I> &customMatcher )
00119 {
00120 return expects(customMatcher);
00121 }
00122
00128 InvocationMockerBuilder<AMB>& expects( const MatcherHolder<I> &expectation )
00129 {
00130 InvocationMockerBuilder<AMB>& builder = addNewInvocationMocker();
00131 builder.match( expectation );
00132 return builder;
00133 }
00134
00139 virtual void setDefaultStub( const MOCKPP_NS::StubHolder<R, I> &newDefaultStub )
00140 {
00141 coreMock->setDefaultStub( newDefaultStub );
00142 }
00143
00146 void reset()
00147 {
00148 buildernamespace->reset();
00149 coreMock->reset();
00150 }
00151
00156 MatchBuilderAdapterBase *lookupID( const String &id ) const
00157 {
00158 MatchBuilderAdapterBase *tmb = buildernamespace->lookupID(id);
00159 if ( tmb == 0 )
00160 assertionFailed( __LINE__, __FILE__,
00161 MOCKPP_PCHAR( "no expected invocation named '" )
00162 + id
00163 + MOCKPP_PCHAR( "'" ) );
00164 return tmb;
00165 }
00166
00171 void registerUniqueID( const String &id, MatchBuilderAdapterBase *builder )
00172 {
00173 buildernamespace->registerUniqueID(id, builder);
00174 }
00175
00176 private:
00177
00181 InvocationMockerBuilder<AMB>& addNewInvocationMocker()
00182 {
00183 InvocationMocker<R, I> *mocker =
00184 new InvocationMocker<R, I>( new typename InvocationMocker<R, I>::DefaultDescriber() );
00185 addInvokable( mocker );
00186
00187 InvocationMockerBuilder<AMB> *builder = new InvocationMockerBuilder<AMB>( mocker, buildernamespace );
00188 buildernamespace->storeBuilder(new MatchBuilderAdapter<R, I>(builder, true));
00189 return *builder;
00190 }
00191
00192 DynamicChainingMock<R, I> *coreMock;
00193 BuilderNamespace *buildernamespace;
00194 };
00195
00196
00197 MOCKPP_NS_END
00198
00199
00200 #endif // MOCKPP_CHAININGMOCKBUILDER_H
00201