Removed the commented leftovers from the changes.
[amule.git] / unittests / muleunit / test.cpp
blobbd9ce94df19c23186f7375f2acb338a7d3666718
1 //
2 // MuleUnit: A minimalistic C++ Unit testing framework based on EasyUnit.
3 //
4 // Copyright (c) 2005-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2004-2011 Barthelemy Dagenais ( barthelemy@prologique.com )
6 //
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
22 #include "test.h"
23 #include "testregistry.h"
24 #include <list>
26 using namespace muleunit;
28 /** Entry for a context. */
29 struct BTEntry
31 BTEntry(const wxChar* f, int l, const wxString& m)
32 : file(f)
33 , line(l)
34 , msg(m)
38 wxString file;
39 int line;
40 wxString msg;
44 static std::list<BTEntry> g_backtrace;
46 namespace muleunit {
47 /** Structure used to contain a snapshot of the contexts. */
48 struct BTList
50 BTList(const std::list<BTEntry>& lst)
51 : snapshot(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()
69 delete m_bt;
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) {
78 indent += ' ';
80 Print(indent + it->file + wxString::Format(wxT(":%i -- "), it->line) + it->msg);
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));
97 CContext::~CContext()
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),
119 m_testName(testName)
121 TestRegistry::addTest(this);
125 Test::~Test()
130 void Test::setUp()
135 void Test::tearDown()
140 void Test::run()
145 const wxString& Test::getTestName() const
147 return m_testName;
151 const wxString& Test::getTestCaseName() const
153 return m_testCaseName;