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_EXPECTATIONVALUE_H
00031 #define MOCKPP_EXPECTATIONVALUE_H
00032
00033
00034 #include <mockpp/mockpp.h>
00035
00036 #include <mockpp/AbstractExpectation.h>
00037
00038 #include <mockpp/util/AssertMo.h>
00039
00040
00041 MOCKPP_NS_START
00042
00043
00049 template <class T>
00050 class ExpectationValue : public AbstractExpectation<T>
00051 {
00052 public:
00053
00054
00059 ExpectationValue(const String &name, VerifiableList *parent = 0)
00060 : AbstractExpectation<T>(name, parent),
00061 expectNothing(false),
00062 haveActualValue(false)
00063 {
00064 }
00065
00066
00069 virtual void clearActual()
00070 {
00071 haveActualValue = false;
00072 }
00073
00074
00077 virtual void reset()
00078 {
00079 this->clearFailOnVerify();
00080 clearActual();
00081 clearExpectation();
00082 }
00083
00084
00088 void setActual(const T &value)
00089 {
00090 myActualValue = value;
00091 haveActualValue = true;
00092 if (this->shouldCheckImmediately())
00093 {
00094 verify();
00095 }
00096 }
00097
00098
00102 void setExpected(const T &value)
00103 {
00104 myExpectedValue = value;
00105 expectNothing = false;
00106 this->setHasExpectations();
00107 }
00108
00109
00116 virtual void setExpectNothing()
00117 {
00118 expectNothing = true;
00119 this->setHasExpectations();
00120 }
00121
00122
00126 virtual void verify()
00127 {
00128 if( expectNothing )
00129 {
00130 String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 expected no value."));
00131 fmt << this->getVerifiableName();
00132
00133 MOCKPP_ASSERT_FALSE_MESSAGE(fmt, haveActualValue );
00134 }
00135 else
00136 {
00137 if (!this->hasExpectations() )
00138 return;
00139
00140 String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 expected a value."));
00141 fmt << this->getVerifiableName();
00142
00143 MOCKPP_ASSERT_TRUE_MESSAGE(fmt, haveActualValue );
00144
00145 fmt = mockpp_i18n(MOCKPP_PCHAR("%1 did not receive the expected value. %2 != %3."));
00146 fmt << this->getVerifiableName() << myExpectedValue << myActualValue;
00147
00148 this->assertEquals(fmt, myExpectedValue, myActualValue);
00149 }
00150 }
00151
00152 protected:
00153
00156 virtual void clearExpectation()
00157 {
00158 expectNothing = false;
00159 this->clearHasExpectations();
00160 }
00161
00162 private:
00163
00164 T myExpectedValue;
00165 T myActualValue;
00166 bool expectNothing;
00167 bool haveActualValue;
00168 };
00169
00170
00171 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00172
00173 #ifndef MOCKP_NO_PREVENT_FLOAT_EXPECTATION
00174
00175
00176
00177
00178
00179
00182 template<>
00183 class ExpectationValue<float>
00184 {
00185 public:
00188 void dummy();
00189
00190 private:
00191 ExpectationValue<float>();
00192 void setExpected(const float &aValue);
00193 };
00194
00197 template<>
00198 class ExpectationValue<double>
00199 {
00200 public:
00203 void dummy();
00204
00205 private:
00206 ExpectationValue<double>();
00207 void setExpected(const double &aValue);
00208 };
00209
00212 template<>
00213 class ExpectationValue<long double>
00214 {
00215 public:
00218 void dummy();
00219
00220 private:
00221 ExpectationValue<long double>();
00222 void setExpected(const long double &aValue);
00223 };
00224
00225
00226 #endif // MOCKP__NO_PREVENT_FLOAT_EXPECTATION
00227
00228 #endif // DOXYGEN_SHOULD_SKIP_THIS
00229
00230 MOCKPP_NS_END
00231
00232
00233 #endif // MOCKPP_EXPECTATIONVALUE_H