Upstream tarball 20080823
[amule.git] / unittests / muleunit / test.cpp
blobf05edef3b4868913feff7e5b6c1a922300b9826e
1 //
2 // MuleUnit: A minimalistic C++ Unit testing framework based on EasyUnit.
3 //
4 // Copyright (c) 2005-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2004-2008 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.
11 //
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.
16 //
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
20 //
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_message(msg.ToAscii())
62 , m_bt(new BTList(g_backtrace))
64 m_bt->snapshot.push_back(BTEntry(file, lineNumber, msg));
68 CTestFailureException::~CTestFailureException() throw()
70 delete m_bt;
74 void CTestFailureException::PrintBT() const
76 wxString indent = wxT("\t\t");
77 std::list<BTEntry>::const_iterator it = m_bt->snapshot.begin();
78 for (; it != m_bt->snapshot.end(); ++it) {
79 indent += ' ';
81 Printf(wxT("%s%s:%i -- %s"),
82 wxString(indent.c_str(), wxConvLocal).c_str(),
83 it->file.c_str(),
84 it->line,
85 it->msg.c_str());
90 const char* CTestFailureException::what () const throw ()
92 return m_message.c_str();
96 CContext::CContext(const wxChar* file, int line, const wxString& msg)
98 g_backtrace.push_back(BTEntry(file, line, msg));
102 CContext::~CContext()
104 g_backtrace.pop_back();
107 extern unsigned s_disableAssertions;
110 CAssertOff::CAssertOff()
112 s_disableAssertions++;
115 CAssertOff::~CAssertOff()
117 s_disableAssertions--;
122 Test::Test(const wxString& testCaseName, const wxString& testName)
123 : m_testCaseName(testCaseName),
124 m_testName(testName)
126 TestRegistry::addTest(this);
130 Test::~Test()
135 void Test::setUp()
140 void Test::tearDown()
145 void Test::run()
150 const wxString& Test::getTestName() const
152 return m_testName;
156 const wxString& Test::getTestCaseName() const
158 return m_testCaseName;