/*** mockcpp is a generic C/C++ mock framework. Copyright (C) <2009> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ***/ #ifndef __MOCKCPP_CHAINING_MOCK_HELPER_H #define __MOCKCPP_CHAINING_MOCK_HELPER_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include MOCKCPP_NS_START struct Matcher; struct Stub; Matcher* once(); Matcher* never(); Matcher* atLeast(unsigned int times); Matcher* atMost(unsigned int times); Matcher* exactly(unsigned int times); template Constraint* eq(const T& val) { return new IsEqual(val); } template Constraint* neq(const T& val) { return new IsNotEqual(val); } template Constraint* gt(const T& val) { return new IsGreaterThan(val); } template Constraint* lt(const T& val) { return new IsLessThan(val); } //////////////////////////////////////////////////////////////// #if 0 static inline Constraint* eq(const char* s) { return new IsEqual(s); } #endif template Constraint* spy(T& val) { return new Spy(val); } template struct PredictTypeTraits { }; template struct PredictTypeTraits { typedef T ParaType; }; template Constraint* checkWith(Predict pred) { typedef typename PredictTypeTraits::ParaType T; return new CheckWith(pred); } //////////////////////////////////////////////////////////////// template Constraint* checkWith(bool (*pred)(T)) { return new CheckWith(pred); } //////////////////////////////////////////////////////////////// template Constraint* processWith(Proc proc) { typedef typename PredictTypeTraits::ParaType T; return new ProcessWith(proc); } //////////////////////////////////////////////////////////////// template Constraint* processWith(void (*proc)(T)) { return new ProcessWith(proc); } //////////////////////////////////////////////////////////////// template Constraint* outBound(const T& val, Constraint* constraint = 0) { return new OutBound(val, constraint); } //////////////////////////////////////////////////////////////// // outBoundP //////////////////////////////////////////////////////////////// template Constraint* outBoundP(T* p, size_t size, Constraint* constraint = 0) { return new OutBoundPointer(p, size, constraint); } //////////////////////////////////////////////////////////////// Constraint* outBoundP(void* p, size_t size, Constraint* constraint = 0); //////////////////////////////////////////////////////////////// template Constraint* outBoundP(T* p, Constraint* constraint = 0) { return new OutBoundPointer(p, sizeof(T), constraint); } /////////////////////////////////////////////////////////////////// // mirror /////////////////////////////////////////////////////////////////// #if defined(__GNUC__) && (__GNUC__ > 3) template Constraint* mirror(const T& obj) { return new IsMirror(obj); } #endif /////////////////////////////////////////////////////////////////// template Constraint* mirror(T* p, size_t size = 0) { return new IsMirror(p, size); } /////////////////////////////////////////////////////////////////// Constraint* mirror(void* p, size_t size); #if 0 Constraint* startWith(char*); Constraint* startWith(const char*); Constraint* startWith(unsigned char*); Constraint* startWith(unsigned const char*); #endif Constraint* startWith(const std::string&); #if 0 Constraint* endWith(char*); Constraint* endWith(const char*); Constraint* endWith(unsigned char*); Constraint* endWith(unsigned const char*); #endif Constraint* endWith(const std::string&); #if 0 Constraint* contains(char*); Constraint* contains(const char*); Constraint* contains(unsigned char*); Constraint* contains(unsigned const char*); #endif Constraint* contains(const std::string&); /////////////////////////////////////////////////////////////////// // smirror /////////////////////////////////////////////////////////////////// Constraint* smirror(char* s); Constraint* smirror(const char* s); Constraint* smirror(unsigned char* s); Constraint* smirror(const unsigned char* s); /////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// Stub* die(int code = 0); Stub* returnValue(const Any& val); Stub* repeat(const Any& val, unsigned int repeatTimes); Stub* ignoreReturnValue(); Stub* returnObjectList( const Any& o01 , const Any& o02 = Any() , const Any& o03 = Any() , const Any& o04 = Any() , const Any& o05 = Any() , const Any& o06 = Any() , const Any& o07 = Any() , const Any& o08 = Any() , const Any& o09 = Any() , const Any& o10 = Any() , const Any& o11 = Any() , const Any& o12 = Any()); template Stub* increase(const T& from, const T& to) { return new TypelessStubAdapter(new IncrementStub(from, to)); } template Stub* increase(const T& from) { return new TypelessStubAdapter(new IncrementStub(from)); } template Stub* throws(const T& ex) { return new TypelessStubAdapter(new ThrowExceptionStub(ex)); } MOCKCPP_NS_END #endif