~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/contrib/HexEditor/TestCasesHelper.h

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* This file is part of HexEditor plugin for Code::Blocks studio
 
3
* Copyright (C) 2009 Bartlomiej Swiecki
 
4
*
 
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.
 
9
*
 
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.
 
14
*
 
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/>.
 
17
*
 
18
* $Revision: $
 
19
* $Id: $
 
20
* $HeadURL: $
 
21
*/
 
22
 
 
23
#ifndef TESTCASESHELPER_H
 
24
#define TESTCASESHELPER_H
 
25
 
 
26
#include "TestCasesBase.h"
 
27
 
 
28
template< typename T, int maxTests > class TestCasesHelper;
 
29
 
 
30
namespace Detail
 
31
{
 
32
    struct RunHelperBase
 
33
    {
 
34
        template< typename T, int maxTests, int testNo >
 
35
        inline int CallRunner( TestCasesHelper< T, maxTests >& hlpr, int prevTest )
 
36
        {
 
37
            return hlpr. template Runner< testNo >( prevTest );
 
38
        }
 
39
    };
 
40
 
 
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 )
 
44
    {
 
45
        return CallRunner< T, maxTests, testNo >( hlpr, RunHelper< T, maxTests, testNo-1 >().Run( hlpr ) );
 
46
    }};
 
47
 
 
48
    template< typename T, int maxTests >
 
49
    struct RunHelper<T, maxTests, 0 > { public: inline int Run( TestCasesHelper< T, maxTests >& ) { return 0; } };
 
50
}
 
51
 
 
52
/** \brief Helper for automated test cases */
 
53
template< typename T, int maxTests = 50 >
 
54
class TestCasesHelper: public T, public TestCasesBase
 
55
{
 
56
    public:
 
57
 
 
58
        /** \brief Run the tests */
 
59
        virtual bool PerformTests()
 
60
        {
 
61
            return RunTests();
 
62
        }
 
63
 
 
64
        /** \brief Main function performing the test,
 
65
         *         Implementations are made by partial instantiation
 
66
         */
 
67
        template< int i >
 
68
        void Test()
 
69
        {
 
70
            m_NoSuchTest = true;
 
71
        }
 
72
 
 
73
        /** \brief Test condition */
 
74
        void Ensure( bool condition, const wxString& failMsg )
 
75
        {
 
76
            if ( !condition )
 
77
            {
 
78
                TestError err;
 
79
                err.m_Msg = failMsg;
 
80
                throw err;
 
81
            }
 
82
        }
 
83
 
 
84
    private:
 
85
 
 
86
        /** \brief Run all the tests */
 
87
        inline bool RunTests()
 
88
        {
 
89
            m_FailCnt = 0;
 
90
            m_PassCnt = 0;
 
91
            m_SkipCnt = 0;
 
92
 
 
93
            Detail::RunHelper< T, maxTests, maxTests > ().Run( *this );
 
94
 
 
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 ) );
 
100
 
 
101
            return m_FailCnt == 0;
 
102
        }
 
103
 
 
104
        /** \brief Run all test from 0 to testNo
 
105
         *  \return No of last available test
 
106
         */
 
107
        template< int testNo >
 
108
        inline int Runner( int prevTest )
 
109
        {
 
110
            // Check if someone has requested tests to stop
 
111
            if ( StopTest() )
 
112
            {
 
113
                return testNo;
 
114
            }
 
115
 
 
116
            wxString result;
 
117
            bool pass = true;
 
118
            m_NoSuchTest = false;
 
119
 
 
120
            // Call our own test
 
121
            try
 
122
            {
 
123
                Test< testNo >();
 
124
            }
 
125
            catch ( const TestError& err )
 
126
            {
 
127
                // Display test's info
 
128
                pass = false;
 
129
                result = wxString::Format( _T("Test %d FAILED: %s"), testNo, err.m_Msg.c_str() );
 
130
            }
 
131
 
 
132
            if ( m_NoSuchTest )
 
133
            {
 
134
                // There was no such test
 
135
                m_SkipCnt++;
 
136
                return prevTest;
 
137
            }
 
138
 
 
139
            // Enumerate skipped tests
 
140
            for ( int i = prevTest+1; i<testNo; i++ )
 
141
            {
 
142
                AddLog( wxString::Format( _T("Test %d skipped: not defined"), i)  );
 
143
            }
 
144
 
 
145
            // Log our results
 
146
            AddLog( pass ? wxString::Format( _T("Test %d passed"), testNo ) : result );
 
147
 
 
148
            ( pass ? m_PassCnt : m_FailCnt ) ++;
 
149
 
 
150
            return testNo;
 
151
        }
 
152
 
 
153
        /** \brief error report */
 
154
        struct TestError { wxString m_Msg; };
 
155
 
 
156
        int m_FailCnt;
 
157
        int m_PassCnt;
 
158
        int m_SkipCnt;
 
159
        bool m_NoSuchTest;
 
160
 
 
161
        friend class Detail::RunHelperBase;
 
162
};
 
163
 
 
164
 
 
165
 
 
166
#endif