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_EXPECTATIONBOUNDARY_H
00031 #define MOCKPP_EXPECTATIONBOUNDARY_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
00048 template <class T>
00049 class ExpectationBoundary : public AbstractExpectation<T>
00050 {
00051 private:
00052
00053 T lower_bound;
00054 T upper_bound;
00055 T actualValue;
00056 bool haveActualValue;
00057 bool expectNothing;
00058
00059 public:
00060
00065 ExpectationBoundary(const String &name, VerifiableList *parent = 0)
00066 : AbstractExpectation<T>(name, parent),
00067 expectNothing(false)
00068 {
00069 clearActual();
00070 }
00071
00072
00076 void setActual(const T &value )
00077 {
00078 actualValue = value;
00079 haveActualValue = true;
00080 if (this->shouldCheckImmediately())
00081 {
00082 verify();
00083 }
00084 }
00085
00086
00091 void setExpected(const T &lower, const T &upper )
00092 {
00093 MOCKPP_ASSERT_TRUE(lower <= upper);
00094 lower_bound = lower;
00095 upper_bound = upper;
00096 expectNothing = false;
00097 this->setHasExpectations();
00098 }
00099
00100
00101 #if MOCKPP_BOUNDARY_DELTA != 0
00102
00117 void setExpectedDelta(const T &median, const T &delta )
00118 {
00119 T lower = median - delta;
00120 T upper = median + delta;
00121 if (lower <= upper)
00122 setExpected(lower, upper);
00123 else
00124 setExpected(upper, lower);
00125 }
00126 #endif
00127
00128
00132 virtual void reset()
00133 {
00134 this->clearFailOnVerify();
00135 clearActual();
00136 clearExpectation();
00137 expectNothing = false;
00138 }
00139
00140
00144 virtual void clearActual()
00145 {
00146 haveActualValue = false;
00147 lower_bound = 0;
00148 upper_bound = 0;
00149 actualValue = 0;
00150 }
00151
00152
00160 virtual void setExpectNothing()
00161 {
00162 expectNothing = true;
00163 clearActual();
00164 this->setHasExpectations();
00165 }
00166
00167
00171 virtual void verify()
00172 {
00173 if( expectNothing )
00174 {
00175 String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 expected no value."));
00176 fmt << this->getVerifiableName();
00177
00178 MOCKPP_ASSERT_FALSE_MESSAGE(fmt, haveActualValue );
00179 }
00180 else
00181 {
00182 if (!this->hasExpectations() )
00183 return;
00184
00185 String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 expected a value."));
00186 fmt << this->getVerifiableName();
00187 MOCKPP_ASSERT_TRUE_MESSAGE(fmt, haveActualValue );
00188
00189 fmt = mockpp_i18n(MOCKPP_PCHAR("%1 received a value of %2 which is less than the expected value of %3."));
00190 fmt << this->getVerifiableName() << actualValue << lower_bound;
00191 MOCKPP_ASSERT_TRUE_MESSAGE(fmt, lower_bound <= actualValue );
00192
00193 fmt = mockpp_i18n(MOCKPP_PCHAR("%1 received a value of %2 which is greater than the expected value of %3."));
00194 fmt << this->getVerifiableName() << actualValue << upper_bound;
00195 MOCKPP_ASSERT_TRUE_MESSAGE(fmt, actualValue <= upper_bound);
00196 }
00197 }
00198
00199 protected:
00200
00204 virtual void clearExpectation()
00205 {
00206 this->clearHasExpectations();
00207 }
00208 };
00209
00210
00211 MOCKPP_NS_END
00212
00213
00214 #endif // MOCKPP_EXPECTATIONBOUNDARY_H