2
* This file is part of HexEditor plugin for Code::Blocks studio
3
* Copyright (C) 2009 Bartlomiej Swiecki
5
* HexEditor plugin is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* HexEditor plugin is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with HexEditor plugin. If not, see <http://www.gnu.org/licenses/>.
23
#ifndef TESTCASESHELPER_H
24
#define TESTCASESHELPER_H
26
#include "TestCasesBase.h"
28
template< typename T, int maxTests > class TestCasesHelper;
34
template< typename T, int maxTests, int testNo >
35
inline int CallRunner( TestCasesHelper< T, maxTests >& hlpr, int prevTest )
37
return hlpr. template Runner< testNo >( prevTest );
41
/** \brief Extra structure needed because of lack of partial function template specialization */
42
template< typename T, int maxTests, int testNo >
43
struct RunHelper: public RunHelperBase { public: inline int Run( TestCasesHelper< T, maxTests >& hlpr )
45
return CallRunner< T, maxTests, testNo >( hlpr, RunHelper< T, maxTests, testNo-1 >().Run( hlpr ) );
48
template< typename T, int maxTests >
49
struct RunHelper<T, maxTests, 0 > { public: inline int Run( TestCasesHelper< T, maxTests >& ) { return 0; } };
52
/** \brief Helper for automated test cases */
53
template< typename T, int maxTests = 50 >
54
class TestCasesHelper: public T, public TestCasesBase
58
/** \brief Run the tests */
59
virtual bool PerformTests()
64
/** \brief Main function performing the test,
65
* Implementations are made by partial instantiation
73
/** \brief Test condition */
74
void Ensure( bool condition, const wxString& failMsg )
86
/** \brief Run all the tests */
87
inline bool RunTests()
93
Detail::RunHelper< T, maxTests, maxTests > ().Run( *this );
95
AddLog( wxString::Format( _T("===============================") ) );
96
AddLog( wxString::Format( _T("Summary:") ) );
97
AddLog( wxString::Format( _T(" Passed: %d"), m_PassCnt ) );
98
AddLog( wxString::Format( _T(" Failed: %d"), m_FailCnt ) );
99
AddLog( wxString::Format( _T(" Total: %d"), m_PassCnt + m_FailCnt ) );
101
return m_FailCnt == 0;
104
/** \brief Run all test from 0 to testNo
105
* \return No of last available test
107
template< int testNo >
108
inline int Runner( int prevTest )
110
// Check if someone has requested tests to stop
118
m_NoSuchTest = false;
125
catch ( const TestError& err )
127
// Display test's info
129
result = wxString::Format( _T("Test %d FAILED: %s"), testNo, err.m_Msg.c_str() );
134
// There was no such test
139
// Enumerate skipped tests
140
for ( int i = prevTest+1; i<testNo; i++ )
142
AddLog( wxString::Format( _T("Test %d skipped: not defined"), i) );
146
AddLog( pass ? wxString::Format( _T("Test %d passed"), testNo ) : result );
148
( pass ? m_PassCnt : m_FailCnt ) ++;
153
/** \brief error report */
154
struct TestError { wxString m_Msg; };
161
friend class Detail::RunHelperBase;