00001 00008 /************************************************************************** 00009 00010 begin : Fri Feb 18 2005 00011 copyright : (C) 2002-2010 by Ewald Arnold 00012 email : mockpp at ewald-arnold dot de 00013 00014 This program is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU Lesser General Public License as 00016 published by the Free Software Foundation; either version 2 of the License, 00017 or (at your option) any later version. 00018 00019 This program is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU Lesser General Public License 00025 along with this program; if not, write to the Free Software 00026 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 00028 **/ 00029 00030 #ifndef MOCKPP_TrackingCounter_H 00031 #define MOCKPP_TrackingCounter_H 00032 00033 00034 #include <mockpp/mockpp.h> // always first 00035 00036 #include <mockpp/AbstractExpectation.h> 00037 00038 #include MOCKPP_VECTOR_H 00039 00040 00041 MOCKPP_NS_START 00042 00043 00050 class MOCKPP_API_DECL0 TrackingCounterBase : public AbstractExpectation<unsigned> 00051 { 00052 public: 00053 00058 TrackingCounterBase(const String &name, VerifiableList *parent = 0); 00059 00062 virtual void clearActual() = 0; 00063 00066 virtual void reset(); 00067 00071 void setExpected(unsigned expectedValue); 00072 00077 void setExpected(unsigned expectedMinValue, unsigned expectedMaxValue); 00078 00085 void setExpectNothing(); 00086 00090 virtual unsigned getActual() const = 0; 00091 00092 protected: 00093 00097 unsigned getExpectedMinValue() const; 00098 00102 unsigned getExpectedMaxValue() const; 00103 00106 virtual void clearExpectation(); 00107 00110 virtual bool isExpectNothing() const; 00111 00112 private: 00113 00114 unsigned myExpectedMinVal; 00115 unsigned myExpectedMaxVal; 00116 bool expectNothing; 00117 }; 00118 00119 00120 class TrackingCounterClient; 00121 00122 00127 class MOCKPP_API_DECL0 TrackingCounterMaster : public TrackingCounterBase 00128 { 00129 public: 00130 00135 TrackingCounterMaster(const String &name, VerifiableList *parent = 0); 00136 00140 virtual void verify(); 00141 00144 virtual void clearActual(); 00145 00149 virtual unsigned getActual() const; 00150 00154 unsigned numClients () const; 00155 00156 protected: 00157 00158 friend class TrackingCounterClient; 00159 00163 virtual void addClient (TrackingCounterClient* vf); 00164 00168 void removeClient (TrackingCounterClient* vf); 00169 00172 unsigned increment(); 00173 00174 private: 00175 00176 TrackingCounterMaster (const TrackingCounterMaster &); // forbid 00177 TrackingCounterMaster& operator=(TrackingCounterMaster&); 00178 00179 MOCKPP_STL::vector<TrackingCounterClient*> clients; 00180 unsigned myActualValue; 00181 }; 00182 00183 00189 class MOCKPP_API_DECL0 TrackingCounterClient : public TrackingCounterBase 00190 { 00191 public: 00192 00197 TrackingCounterClient(const String &name, TrackingCounterMaster &master); 00198 00201 virtual ~TrackingCounterClient(); 00202 00205 unsigned inc(); 00206 00210 unsigned operator++ () 00211 { 00212 return inc(); 00213 } 00214 00218 unsigned operator++ (int) 00219 { 00220 return inc(); 00221 } 00222 00226 virtual void verify(); 00227 00230 virtual void clearActual(); 00231 00235 virtual unsigned getActual() const; 00236 00239 unsigned numTags() const; 00240 00243 unsigned getTag(unsigned index) const; 00244 00245 private: 00246 00247 TrackingCounterClient (const TrackingCounterClient &); // forbid 00248 TrackingCounterClient& operator=(TrackingCounterClient&); 00249 00250 MOCKPP_STL::vector<unsigned> countervalues; 00251 TrackingCounterMaster *master; 00252 unsigned myActualValue; 00253 }; 00254 00255 00256 MOCKPP_NS_END 00257 00258 00259 #endif // MOCKPP_TrackingCounter_H