00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #define MOCKPP_NEED_EXPORTS
00032 #include <mockpp/mockpp.h>
00033
00034 #include MOCKPP_ALGORITHM_H
00035
00036 #include <mockpp/chaining/ChainableMockObject.h>
00037
00038
00039 MOCKPP_NS_START
00040
00041
00042 MOCKPP_API_IMPL0 ChainableMockObjectBase::ChainableMockObjectBase(const String &name)
00043 : BuilderNamespace(name)
00044 {
00045 }
00046
00047
00048 MOCKPP_API_IMPL0 ChainableMockObjectBase::~ChainableMockObjectBase()
00049 {
00050 chainableReset();
00051 }
00052
00053
00054 MOCKPP_API_IMPL(void) ChainableMockObjectBase::chainableVerify()
00055 {
00056 checkPendingRecorders();
00057 }
00058
00059
00060 MOCKPP_API_IMPL(void) ChainableMockObjectBase::checkPendingRecorders() const
00061 {
00062 String penders;
00063 while(pendingRecorders.size() != 0)
00064 {
00065 if (penders.length() != 0)
00066 penders += MOCKPP_PCHAR(", ");
00067
00068 penders += (*pendingRecorders.begin()).first;
00069 delete (*pendingRecorders.begin()).second;
00070 pendingRecorders.erase(pendingRecorders.begin());
00071 }
00072
00073 if (penders.length() != 0)
00074 assertionFailed( __LINE__, __FILE__,
00075 MOCKPP_PCHAR("Chaining mock object \"") + getIdent()
00076 + MOCKPP_PCHAR( "\": there are unassigned idenfiers:\n " )
00077 + penders);
00078 }
00079
00080
00081 MOCKPP_API_IMPL(MatchBuilderAdapterBase *) ChainableMockObjectBase::lookupID( const String &id ) const
00082 {
00083 TableType::const_iterator it = idTable.find( id );
00084 if ( it == idTable.end() )
00085 return 0;
00086
00087 return ( (*it).second );
00088 }
00089
00090
00091 MOCKPP_API_IMPL(void) ChainableMockObjectBase::registerUniqueID( const String &id, MatchBuilderAdapterBase *builder )
00092 {
00093 MatchBuilderAdapterBase *tmb = lookupID(id);
00094 if ( tmb != 0 )
00095 assertionFailed( __LINE__, __FILE__,
00096 MOCKPP_PCHAR( "duplicate invocation named \"" )
00097 + id
00098 + MOCKPP_PCHAR( "\"" ) );
00099 storeID(id, builder);
00100 }
00101
00102
00103 MOCKPP_API_IMPL(void) ChainableMockObjectBase::storeBuilder( AutoPointer<MatchBuilderAdapterBase> builder )
00104 {
00105 allBuilders.push_back(builder.release());
00106 }
00107
00108
00109 MOCKPP_API_IMPL(void) ChainableMockObjectBase::addPendingRecorder(const String &id, InvokedRecorder::AP recorder)
00110 {
00111 pendingRecorders.insert( PendingType::value_type(id, recorder.release()) );
00112 }
00113
00114
00115 MOCKPP_API_IMPL(void) ChainableMockObjectBase::storeID( const String &id, MatchBuilderAdapterBase *builder )
00116 {
00117 idTable.insert( MOCKPP_STL::make_pair(id, builder) );
00118
00119 PendingType::iterator it;
00120 while ( (it = pendingRecorders.find( id )) != pendingRecorders.end() )
00121 {
00122 builder->match( (*it).second );
00123 pendingRecorders.erase(it);
00124 }
00125 }
00126
00127
00128 MOCKPP_API_IMPL(void) ChainableMockObjectBase::chainableReset()
00129 {
00130 while(idTable.size() != 0)
00131 {
00132 delete (*idTable.begin()).second;
00133 idTable.erase(idTable.begin());
00134 }
00135
00136 for (unsigned i = 0; i < allBuilders.size(); ++i)
00137 delete allBuilders[i];
00138 allBuilders.clear();
00139
00140 while(pendingRecorders.size() != 0)
00141 {
00142 delete (*pendingRecorders.begin()).second;
00143 pendingRecorders.erase(pendingRecorders.begin());
00144 }
00145 }
00146
00147
00149
00150
00151 MOCKPP_API_IMPL0 ChainableMockObject::ChainableMockObject(const String &name, VerifiableList *parent)
00152 : MockObject(name, parent)
00153 , ChainableMockObjectBase(name)
00154 {
00155 }
00156
00157
00158 MOCKPP_API_IMPL0 ChainableMockObject::~ChainableMockObject()
00159 {
00160 reset();
00161 }
00162
00163
00164 MOCKPP_API_IMPL(void) ChainableMockObject::verify()
00165 {
00166 MockObject::verify();
00167 chainableVerify();
00168 }
00169
00170
00171 MOCKPP_API_IMPL(void) ChainableMockObject::reset()
00172 {
00173 MockObject::reset();
00174 chainableReset();
00175 }
00176
00177
00178 MOCKPP_NS_END