2 // MuleUnit: A minimalistic C++ Unit testing framework based on EasyUnit.
4 // Copyright (c) 2005-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2004-2008 Barthelemy Dagenais ( barthelemy@prologique.com )
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "testregistry.h"
26 using namespace muleunit
;
28 /** Entry for a context. */
31 BTEntry(const wxChar
* f
, int l
, const wxString
& m
)
44 static std::list
<BTEntry
> g_backtrace
;
47 /** Structure used to contain a snapshot of the contexts. */
50 BTList(const std::list
<BTEntry
>& lst
)
55 std::list
<BTEntry
> snapshot
;
60 CTestFailureException::CTestFailureException(const wxString
& msg
, const wxChar
* file
, long lineNumber
)
61 : m_bt(new BTList(g_backtrace
)), m_message(msg
.ToAscii())
63 m_bt
->snapshot
.push_back(BTEntry(file
, lineNumber
, msg
));
67 CTestFailureException::~CTestFailureException() throw()
73 void CTestFailureException::PrintBT() const
75 wxString indent
= wxT("\t\t");
76 std::list
<BTEntry
>::const_iterator it
= m_bt
->snapshot
.begin();
77 for (; it
!= m_bt
->snapshot
.end(); ++it
) {
80 Printf(indent
+ it
->file
+ wxT(":%i -- ") + it
->msg
, it
->line
);
85 const char* CTestFailureException::what () const throw ()
87 return m_message
.c_str();
91 CContext::CContext(const wxChar
* file
, int line
, const wxString
& msg
)
93 g_backtrace
.push_back(BTEntry(file
, line
, msg
));
99 g_backtrace
.pop_back();
102 extern unsigned s_disableAssertions
;
105 CAssertOff::CAssertOff()
107 s_disableAssertions
++;
110 CAssertOff::~CAssertOff()
112 s_disableAssertions
--;
117 Test::Test(const wxString
& testCaseName
, const wxString
& testName
)
118 : m_testCaseName(testCaseName
),
121 TestRegistry::addTest(this);
135 void Test::tearDown()
145 const wxString
& Test::getTestName() const
151 const wxString
& Test::getTestCaseName() const
153 return m_testCaseName
;