00001 00008 /************************************************************************** 00009 00010 begin : Sun Aug 22 2004 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 * Original Java Sources: Copyright (c) 2000-2004, jMock.org 00030 * 00031 00032 **/ 00033 00034 #define MOCKPP_NEED_EXPORTS 00035 #include <mockpp/mockpp.h> // always first 00036 00037 #include <mockpp/framework/VerifyingTestCase.h> 00038 00039 #include <mockpp/compat/Exception.h> 00040 #include <mockpp/compat/Formatter.h> 00041 #include <mockpp/compat/AssertionFailedError.h> 00042 00043 #ifdef MOCKPP_USE_CPPUNIT 00044 00045 #include <cppunit/Exception.h> 00046 #include <cppunit/SourceLine.h> 00047 #include <cppunit/TestResult.h> 00048 00049 00050 MOCKPP_NS_START 00051 00052 00053 MOCKPP_API_IMPL0 VerifyingTestCase::VerifyingTestCase() 00054 : CppUnit::TestCase() 00055 , MockObject(MOCKPP_PCHAR("VerifyingTestCase/*"), 0) 00056 { 00057 } 00058 00059 00060 MOCKPP_API_IMPL0 00061 VerifyingTestCase::VerifyingTestCase( const MOCKPP_STD_NS::string &name) 00062 : CppUnit::TestCase(name) 00063 #ifdef MOCKPP_ALTERNATIVE_STL 00064 , MockObject(MOCKPP_PCHAR("VerifyingTestCase/")+MOCKPP_GET_STRING(name.c_str()), 0) 00065 #else 00066 , MockObject(MOCKPP_PCHAR("VerifyingTestCase/")+MOCKPP_GET_STRING(name), 0) 00067 #endif 00068 { 00069 } 00070 00071 00072 MOCKPP_API_IMPL0 VerifyingTestCase::~VerifyingTestCase() 00073 { 00074 unregisterVerifiables(); 00075 } 00076 00077 00078 void MOCKPP_API_IMPL0 VerifyingTestCase::verify() 00079 { 00080 if (numVerifiables() == 0) 00081 { 00082 String s = MOCKPP_PCHAR("VerifyingTestCase \"%1\" has no sub-objects to verify.\n") 00083 MOCKPP_PCHAR("Did you forget to register?"); 00084 s << getVerifiableName(); 00085 assertionFailed (__LINE__, __FILE__, s); 00086 } 00087 00088 MockObject::verify(); 00089 } 00090 00091 00092 void MOCKPP_API_IMPL0 VerifyingTestCase::registerVerifiable(AutoPointer<Verifiable> in_verifiable) 00093 { 00094 Verifiable *verifiable = in_verifiable.release(); 00095 registeredVerifiables.push_back(verifiable); 00096 00097 if (!hasVerifiable(verifiable)) 00098 addVerifiable(verifiable); 00099 00100 if (verifiable->getParent() == 0) 00101 verifiable->setParent(this); 00102 } 00103 00104 00105 void MOCKPP_API_IMPL0 VerifyingTestCase::unregisterVerifiables() 00106 { 00107 clearVerifiables(); 00108 for (unsigned i = 0; i < registeredVerifiables.size(); ++i) 00109 delete registeredVerifiables[i]; 00110 registeredVerifiables.clear(); 00111 } 00112 00113 00114 MOCKPP_NS_END 00115 00116 00117 #endif // MOCKPP_USE_CPPUNIT 00118