00001 00008 /************************************************************************** 00009 00010 begin : We Jan 22 2003 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 #define MOCKPP_NEED_EXPORTS 00031 #include <mockpp/mockpp.h> // always first 00032 00033 #include <mockpp/compat/Asserter.h> 00034 #include <mockpp/compat/Formatter.h> 00035 00036 #include <mockpp/ThrowableList.h> 00037 00038 MOCKPP_NS_START 00039 00040 00041 MOCKPP_API_IMPL0 ThrowableList::ThrowableList(const String &name, VerifiableList *parent) 00042 : Verifiable (name, parent) 00043 { 00044 } 00045 00046 00047 MOCKPP_API_IMPL0 ThrowableList::~ThrowableList() throw() 00048 { 00049 reset(); 00050 } 00051 00052 00053 MOCKPP_API_IMPL(void) ThrowableList::push_back(Throwable* t) 00054 { 00055 addObjectToThrow(t); 00056 } 00057 00058 00059 MOCKPP_API_IMPL(void) ThrowableList::addObjectToThrow(Throwable* t) 00060 { 00061 // MOCKPP_ASSERT_TRUE(t != 0); Tricky: ResonseVector uses 0 to distinguish 00062 // between values and throwables 00063 list.push_back(t); 00064 } 00065 00066 00067 MOCKPP_API_IMPL(unsigned) ThrowableList::size() const 00068 { 00069 return already_used.size() + list.size(); 00070 } 00071 00072 00073 MOCKPP_API_IMPL(Throwable *) ThrowableList::at(unsigned i) 00074 { 00075 MOCKPP_ASSERT_TRUE(i < already_used.size() + list.size()); 00076 if (i < already_used.size() ) 00077 return already_used[i]; 00078 00079 return list[i-already_used.size()]; 00080 /* 00081 if (i < already_used.size() ) 00082 return already_used.at(i); 00083 00084 return list.at(i-already_used.size()); 00085 */ 00086 } 00087 00088 00089 MOCKPP_API_IMPL(Throwable *) ThrowableList::nextThrowableObject() 00090 { 00091 String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 has run out of objects.")); 00092 fmt << getVerifiableName(); 00093 00094 MOCKPP_ASSERT_TRUE_MESSAGE(fmt, list.size() > 0); 00095 Throwable *temp = list[0]; 00096 list.erase(list.begin()); 00097 already_used.push_back(temp); 00098 00099 return temp; 00100 } 00101 00102 00103 MOCKPP_API_IMPL(bool) ThrowableList::hasMoreObjects() const 00104 { 00105 return list.size() != 0; 00106 } 00107 00108 00109 MOCKPP_API_IMPL(void) ThrowableList::reset() 00110 { 00111 for (unsigned i1 = 0; i1 < list.size(); ++i1) 00112 delete list[i1]; 00113 list.clear(); 00114 00115 for (unsigned i2 = 0; i2 < already_used.size(); ++i2) 00116 delete already_used[i2]; 00117 already_used.clear(); 00118 } 00119 00120 00121 MOCKPP_API_IMPL(void) ThrowableList::verify() 00122 { 00123 String fmt = mockpp_i18n(MOCKPP_PCHAR("%1 has %2 un-used objects.")); 00124 fmt << getVerifiableName() << list.size(); 00125 00126 MOCKPP_ASSERT_EQUALS_MESSAGE(fmt, (size_t)0, list.size()); 00127 } 00128 00129 MOCKPP_NS_END 00130