2
* This file is part of HexEditor plugin for Code::Blocks Studio
3
* Copyright (C) 2008-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 pluging 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. If not, see <http://www.gnu.org/licenses/>.
19
* $Id: TestCasesDlg.cpp 6104 2010-01-23 12:56:12Z mortenmacfly $
20
* $HeadURL: svn+ssh://jenslody@svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/contrib/HexEditor/TestCasesDlg.cpp $
23
#include "TestCasesDlg.h"
25
//(*InternalHeaders(TestCasesDlg)
26
#include <wx/string.h>
30
//(*IdInit(TestCasesDlg)
31
const long TestCasesDlg::ID_LISTBOX1 = wxNewId();
32
const long TestCasesDlg::ID_BUTTON1 = wxNewId();
33
const long TestCasesDlg::ID_TIMER1 = wxNewId();
36
BEGIN_EVENT_TABLE(TestCasesDlg,wxScrollingDialog)
37
//(*EventTable(TestCasesDlg)
41
TestCasesDlg::TestCasesDlg(wxWindow* parent, TestCasesBase& tests): m_Tests( tests ), m_Thread( 0 )
43
m_Tests.InitOutput( *this );
47
void TestCasesDlg::BuildContent(wxWindow* parent)
49
//(*Initialize(TestCasesDlg)
50
wxBoxSizer* BoxSizer1;
51
wxStaticBoxSizer* StaticBoxSizer1;
53
Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
54
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
55
StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("Test log:"));
56
ListBox1 = new wxListBox(this, ID_LISTBOX1, wxDefaultPosition, wxSize(410,268), 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1"));
57
StaticBoxSizer1->Add(ListBox1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
58
Button1 = new wxButton(this, ID_BUTTON1, _("Stop"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
59
StaticBoxSizer1->Add(Button1, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
60
BoxSizer1->Add(StaticBoxSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
62
Timer1.SetOwner(this, ID_TIMER1);
63
Timer1.Start(50, false);
65
BoxSizer1->SetSizeHints(this);
67
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&TestCasesDlg::OnButton1Click);
68
Connect(ID_TIMER1,wxEVT_TIMER,(wxObjectEventFunction)&TestCasesDlg::OnTimer1Trigger);
69
Connect(wxID_ANY,wxEVT_CLOSE_WINDOW,(wxObjectEventFunction)&TestCasesDlg::OnClose);
73
m_StopRequest = false;
77
m_Thread = new MyThread( this );
82
TestCasesDlg::~TestCasesDlg()
84
//(*Destroy(TestCasesDlg)
90
int TestCasesDlg::Entry()
92
m_Result = m_Tests.PerformTests();
97
bool TestCasesDlg::StopTest()
99
// Don't have to lock anything since
100
// we only send one bit of information
101
return m_StopRequest;
104
void TestCasesDlg::AddLog( const wxString& logLine )
106
wxCriticalSectionLocker lock( m_Section );
107
m_NewLogs.Add( logLine );
110
void TestCasesDlg::OnButton1Click(wxCommandEvent& event)
114
m_StopRequest = true;
116
AddLog( _T("Cancelled by the user") );
118
else if ( m_BtnChanged )
120
EndDialog( wxID_OK );
124
void TestCasesDlg::OnTimer1Trigger(wxTimerEvent& event)
126
if ( !m_Running && !m_BtnChanged )
130
Button1->SetLabel( _("Close") );
133
wxCriticalSectionLocker lock( m_Section );
134
if ( !m_NewLogs.IsEmpty() )
136
ListBox1->Append( m_NewLogs );
139
ListBox1->SetFirstItem( ListBox1->GetCount() - 1 );
143
void TestCasesDlg::OnClose(wxCloseEvent& event)
145
if ( m_Running && event.CanVeto() )
151
m_StopRequest = true;