00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef MOCKPP_EXPECTATIONSEGMENT_H
00031 #define MOCKPP_EXPECTATIONSEGMENT_H
00032
00033
00034 #include <mockpp/mockpp.h>
00035
00036 #include <mockpp/AbstractExpectation.h>
00037 #include <mockpp/util/AssertMo.h>
00038
00039
00040 MOCKPP_NS_START
00041
00042
00046 template <class Str>
00047 class ExpectationSegment : public AbstractExpectation<Str>
00048 {
00049 public:
00050
00055 ExpectationSegment(const String &name, VerifiableList *parent = 0)
00056 : AbstractExpectation<Str>(name, parent),
00057 expectNothing(false),
00058 haveActualValue(false)
00059 {
00060 }
00061
00062
00065 virtual void reset()
00066 {
00067 this->clearFailOnVerify();
00068 clearActual();
00069 clearExpectation();
00070 }
00071
00072
00075 void clearActual()
00076 {
00077 haveActualValue = false;
00078 myActualString = Str();
00079 }
00080
00081
00085 void setActual(const Str &aString)
00086 {
00087 haveActualValue = true;
00088 myActualString = aString;
00089 if (this->shouldCheckImmediately())
00090 {
00091 verify();
00092 }
00093 }
00094
00095
00099 void setExpected(const Str &segment)
00100 {
00101 myExpectedSegment = segment;
00102 expectNothing = false;
00103 this->setHasExpectations();
00104 }
00105
00106
00113 void setExpectNothing()
00114 {
00115 expectNothing = true;
00116 this->setHasExpectations();
00117 }
00118
00119
00123 virtual void verify()
00124 {
00125 if( expectNothing )
00126 {
00127 String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 expected no value."));
00128 fmt << this->getVerifiableName();
00129 MOCKPP_ASSERT_FALSE_MESSAGE(fmt, haveActualValue );
00130
00131 }
00132 else
00133 {
00134 if (!this->hasExpectations() )
00135 return;
00136
00137 String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 expected a value."));
00138 fmt << this->getVerifiableName();
00139 MOCKPP_ASSERT_TRUE_MESSAGE(fmt, haveActualValue );
00140
00141 MOCKPP_ASSERT_INCLUDES_MESSAGE(
00142 mockpp_i18n(MOCKPP_PCHAR("Should include string segment.")),
00143 myExpectedSegment,
00144 myActualString);
00145 }
00146 }
00147
00148 protected:
00149
00152 virtual void clearExpectation()
00153 {
00154 this->clearHasExpectations();
00155 }
00156
00157
00158 private:
00159
00160 Str myExpectedSegment;
00161 Str myActualString;
00162 bool expectNothing;
00163 bool haveActualValue;
00164 };
00165
00166
00167 MOCKPP_NS_END
00168
00169
00170 #endif // MOCKPP_EXPECTATIONSEGMENT_H