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_TriggeredOutbound_H
00031 #define MOCKPP_TriggeredOutbound_H
00032
00033 #include <mockpp/mockpp.h>
00034
00035 #include <mockpp/constraint/TriggeredConstraint.h>
00036 #include <mockpp/compat/Formatter.h>
00037 #include <mockpp/ReturnObjectList.h>
00038
00039
00040 MOCKPP_NS_START
00041
00042
00052 template <typename T>
00053 class TriggeredOutbound : public TriggeredConstraint<T>
00054 {
00055 public:
00056
00060 TriggeredOutbound( const T &retArg )
00061 : returnObjects(MOCKPP_PCHAR("TriggeredOutbound/returnObjects"), 0)
00062 , back_ref(0)
00063 {
00064 addOutboundObject(retArg);
00065 }
00066
00071 template <class I>
00072 TriggeredOutbound( I items, I end )
00073 : returnObjects(MOCKPP_PCHAR("TriggeredOutbound/returnObjects"), 0)
00074 , back_ref(0)
00075 {
00076 addOutboundObject(items, end);
00077 }
00078
00082 void addOutboundObject( const T &retArg )
00083 {
00084 returnObjects.addObjectToReturn(retArg);
00085 }
00086
00092 template <class I>
00093 TriggeredOutbound& addOutboundObject(I items, I end)
00094 {
00095 for ( ; items != end; ++items)
00096 addOutboundObject(*items);
00097 return *this;
00098 }
00099
00102 virtual ~TriggeredOutbound()
00103 {}
00104
00110 virtual bool eval( const T &arg ) const
00111 {
00112 back_ref = const_cast<T*>(&arg);
00113 return true;
00114 }
00115
00121 virtual bool verify( const T & ) const
00122 {
00123 return returnObjects.hasMoreObjects() == 0;
00124 }
00125
00130 virtual String describeTo( String &buffer ) const
00131 {
00132 String fmt = MOCKPP_PCHAR("stores %1");
00133 fmt << returnObjects.toString();
00134 buffer += fmt;
00135 return buffer;
00136 }
00137
00141 virtual void trigger()
00142 {
00143 MOCKPP_ASSERT_TRUE(back_ref != 0);
00144 *back_ref = returnObjects.nextReturnObject();
00145 back_ref = 0;
00146 }
00147
00148 private:
00149
00150 mutable ReturnObjectList<T> returnObjects;
00151 mutable T *back_ref;
00152 };
00153
00154
00155 MOCKPP_NS_END
00156
00157
00158 #endif // MOCKPP_TriggeredOutbound_H