00001 00009 /************************************************************************** 00010 00011 begin : Thu Oct 22 2005 00012 copyright : (C) 2002-2010 by Ewald Arnold 00013 email : mockpp at ewald-arnold dot de 00014 00015 This program is free software; you can redistribute it and/or modify 00016 it under the terms of the GNU Lesser General Public License as 00017 published by the Free Software Foundation; either version 2 of the License, 00018 or (at your option) any later version. 00019 00020 This program is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU Lesser General Public License 00026 along with this program; if not, write to the Free Software 00027 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00028 00029 **/ 00030 00031 #ifndef MOCKPP_VisitableMockMethod0_H 00032 #define MOCKPP_VisitableMockMethod0_H 00033 00034 #include <mockpp/mockpp.h> 00035 00036 #include <mockpp/visiting/VisitableMockObject.h> 00037 #include <mockpp/visiting/VisitableMockMethod.h> 00038 00039 00040 MOCKPP_NS_START 00041 00042 00046 template <typename R> 00047 class VisitableMockMethod0Common : public VisitableMockReturningMethodBase<R> 00048 { 00049 public: 00050 00055 VisitableMockMethod0Common(const String &name, VisitableMockObject *parent) 00056 : VisitableMockReturningMethodBase<R>(name, parent) 00057 { 00058 } 00059 00060 protected: 00061 00064 void forward_param() const 00065 { 00066 if (!this->getVisitableMockObject()->isActivated() ) 00067 { 00068 this->getVisitableMockObject()->addExpectedMethod(this->getMethodIdentifier()); 00069 } 00070 else 00071 { 00072 this->getVisitableMockObject()->addActualMethod(this->getMethodIdentifier()); 00073 this->throwAvailableException(); 00074 } 00075 } 00076 public: 00077 00078 }; 00079 00080 00084 template <typename R> 00085 class VisitableMockMethod0 00086 : public VisitableMockMethod0Common<R> 00087 { 00088 public: 00089 00094 VisitableMockMethod0(const String &name, VisitableMockObject *parent) 00095 : VisitableMockMethod0Common<R>(name, parent) 00096 { 00097 } 00098 00102 R forward() const 00103 { 00104 this->forward_param(); 00105 00106 if (this->getVisitableMockObject()->isActivated() ) 00107 { 00108 return this->determineReturnValue(); 00109 } 00110 else 00111 return R(); // only dummy value to make the compiler happy 00112 } 00113 }; 00114 00115 00120 template <> 00121 class VisitableMockMethod0<void> 00122 : public VisitableMockMethod0Common<void> 00123 { 00124 public: 00125 00130 VisitableMockMethod0(const String &name, VisitableMockObject *parent) 00131 : VisitableMockMethod0Common<void>(name, parent) 00132 { 00133 } 00134 00138 void forward() const 00139 { 00140 this->forward_param(); 00141 } 00142 }; 00143 00144 00145 MOCKPP_NS_END 00146 00147 00148 #endif // MOCKPP_VisitableMockMethod0_H 00149