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/MockObject.h>
00037
00038 #include <mockpp/util/AssertMo.h>
00039
00040
00041 MOCKPP_NS_START
00042
00043
00044 MOCKPP_API_IMPL0 MockObject::MockObject(const String &name, VerifiableList *parent)
00045 : VerifiableList(name, parent)
00046 {
00047 }
00048
00049
00050 MOCKPP_API_IMPL(void) MockObject::notImplemented()
00051 {
00052 #ifndef MOCKPP_NO_RTTI
00053 # ifdef MOCKPP_UNICODE
00054 MOCKPP_NOT_IMPLEMENTED(getUnicode(typeid(*this).name()));
00055 # else
00056 MOCKPP_NOT_IMPLEMENTED(typeid(*this).name());
00057 # endif
00058 #else
00059 MOCKPP_NOT_IMPLEMENTED(MOCKPP_PCHAR("[rtti-disabled in MockObject::notImplemented()") );
00060 #endif
00061 }
00062
00063
00064 MOCKPP_API_IMPL(void) MockObject::reset()
00065 {
00066 for (unsigned i = 0; i < numVerifiables(); ++i)
00067 getVerifiable(i)->reset();
00068 }
00069
00070
00071 MOCKPP_API_IMPL(void) MockObject::verify()
00072 {
00073 verifyAnObject(this);
00074 }
00075
00076
00077 MOCKPP_API_IMPL(void) MockObject::verifyAnObject(VerifiableList* anObject)
00078 {
00079 VerifierVec myProcessingObjects;
00080 myProcessingObjects.push_back(anObject);
00081 verifySubFields(anObject, myProcessingObjects);
00082 }
00083
00084
00085 MOCKPP_API_IMPL(void) MockObject::verifySubFields(Verifiable *anObject,
00086 VerifierVec &alreadyProcessed)
00087 {
00088 if (anObject == 0)
00089 return;
00090
00091 if (anObject != 0)
00092 verifyField(anObject, alreadyProcessed);
00093
00094 for (unsigned i = 0; i < anObject->numVerifiables(); ++i)
00095 verifySubFields(anObject->getVerifiable(i), alreadyProcessed);
00096
00097 }
00098
00099
00100 MOCKPP_API_IMPL(void) MockObject::verifyField(Verifiable *anObject,
00101 VerifierVec &alreadyProcessed)
00102 {
00103 if ( isVerifiable(anObject)
00104 && MOCKPP_STL::find(alreadyProcessed.begin(), alreadyProcessed.end(), anObject) == alreadyProcessed.end())
00105 {
00106 alreadyProcessed.push_back(anObject);
00107 anObject->verify();
00108 }
00109 }
00110
00111
00112 MOCKPP_API_IMPL(bool) MockObject::isVerifiable(const Verifiable *anObject)
00113 {
00114 return dynamic_cast<const Verifiable*>(anObject) != 0;
00115 }
00116
00117
00118 MOCKPP_NS_END