📄 testrunnerframe.cpp
字号:
/////////////////////////////////////////////////////////////////////////////// Name: TestRunnerFrame.h// Purpose: Implementation for class TestRunnerFrame// Author: Baptiste Lepilleur// Modified by: Anthon Pang// Created: 2003.09.11// RCS-ID:// Copyright: (C) 2003 by Anthon Pang and Baptiste Lepilleur// Licence: LGPL// Reference: cppunit/src/qttestrunner/TestRunnerDlgImpl.h// wxWidgets/samples/controls/controls.cpp// wxWidgets/samples/listctrl/listtest.cpp/////////////////////////////////////////////////////////////////////////////// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------// For compilers that support precompilation, includes "wx/wx.h".#include <wx/wxprec.h>#ifdef __BORLANDC__# pragma hdrstop#endif// for all others, include the necessary headers (this file is usually all you// need because it includes almost all "standard" wxWidgets headers)#ifndef WX_PRECOMP# include <wx/wx.h>#endif#include "TestRunnerFrame.h"#ifndef CPPUNIT_EXCEPTION_H#include <cppunit/Exception.h>#endif#include <wx/listctrl.h>#ifndef TESTRUNNERMODEL_H#include "TestRunnerModel.h"#endif#ifndef TESTBROWSERDIALOG_H#include "TestBrowserDialog.h"#endif#ifndef TESTFAILUREINFO_H#include "TestFailureInfo.h"#endif// ----------------------------------------------------------------------------// resources// ----------------------------------------------------------------------------// the application icon (under Windows and OS/2 it is in resources)#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)# include "res/wxicon.xpm"#endif// ----------------------------------------------------------------------------// private classes// ----------------------------------------------------------------------------// ----------------------------------------------------------------------------// constants// ----------------------------------------------------------------------------enum{ // menu items MENU_FILE_EXIT = wxID_EXIT, MENU_HELP_ABOUT = wxID_ABOUT, // control items BUTTON_BROWSE = wxID_HIGHEST, BUTTON_RUN, BUTTON_STOP, BUTTON_CLOSE, CHOICE_TEST, CHECK_AUTORUN, LISTCTRL_ERRORS_AND_FAILURES, TEXT_DETAILS};// ----------------------------------------------------------------------------// event tables and other macros for wxWidgets// ----------------------------------------------------------------------------// the event tables connect the wxWidgets events with the functions (event// handlers) which process them. It can be also done at run-time, but for the// simple menu events like this the static method is much simpler.BEGIN_EVENT_TABLE(TestRunnerFrame, wxFrame) EVT_MENU(MENU_FILE_EXIT, TestRunnerFrame::OnMenuFileExit) EVT_MENU(MENU_HELP_ABOUT, TestRunnerFrame::OnMenuHelpAbout) EVT_BUTTON(BUTTON_BROWSE, TestRunnerFrame::OnButtonBrowse) EVT_BUTTON(BUTTON_RUN, TestRunnerFrame::OnButtonRun) EVT_BUTTON(BUTTON_STOP, TestRunnerFrame::OnButtonStop) EVT_BUTTON(BUTTON_CLOSE, TestRunnerFrame::OnButtonClose) EVT_CHOICE(CHOICE_TEST, TestRunnerFrame::OnChoiceSelectedTest) EVT_LIST_ITEM_SELECTED(LISTCTRL_ERRORS_AND_FAILURES, TestRunnerFrame::OnListSelectedError) EVT_TEST_RUNNER_THREAD_EVENT(-1, TestRunnerFrame::OnTestRunnerEvent)END_EVENT_TABLE()// ============================================================================// implementation// ============================================================================// ----------------------------------------------------------------------------// main dialog// ----------------------------------------------------------------------------TestRunnerFrame::TestRunnerFrame(TestRunnerModel *model) : wxFrame( NULL, -1, _("wxWidgets Test Runner"), wxPoint(0, 0), wxSize(450, 400), wxDEFAULT_FRAME_STYLE ), m_model( model ){ initializeFrame(); initView(); // initialize Model PushEventHandler( m_model );}TestRunnerFrame::~TestRunnerFrame(){ PopEventHandler(); delete m_model;}void TestRunnerFrame::initializeFrame(){ // set the frame icon SetIcon(wxICON(wxicon));#if wxUSE_MENUS wxMenu *fileMenu = new wxMenu; wxMenu *helpMenu = new wxMenu; fileMenu->Append(MENU_FILE_EXIT, _("E&xit\tAlt-X"), _("Quit this program")); helpMenu->Append(MENU_HELP_ABOUT, _("&About..."), _("Show about dialog")); // now append the freshly created menus to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(fileMenu, _("&File")); menuBar->Append(helpMenu, _("&Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar);#endif // wxUSE_MENUS#if wxUSE_STATUSBAR // create a status bar (single pane) CreateStatusBar(1); SetStatusText(_("Ready."));#endif // wxUSE_STATUSBAR // create controls // Note: order of construction determines the tab order wxPanel *panel = new wxPanel( this ); wxStaticText *labelTest = new wxStaticText(panel, -1, _("&Test:")); wxStaticText *labelProgress = new wxStaticText(panel, -1, _("Progress:")); wxStaticText *labelTests = new wxStaticText(panel, -1, _("Tests:")); wxStaticText *labelRuns = new wxStaticText(panel, -1, _("Runs:")); wxStaticText *labelErrors = new wxStaticText(panel, -1, _("Errors:")); wxStaticText *labelFailures = new wxStaticText(panel, -1, _("Failures:")); wxStaticText *labelErrorList = new wxStaticText(panel, -1, _("Errors and Failures:")); wxStaticText *labelDetails = new wxStaticText(panel, -1, _("Details:")); wxString choices[] = { "" }; m_choiceTest = new wxChoice( panel, CHOICE_TEST, wxDefaultPosition, wxDefaultSize, 0, choices, wxCB_SORT );// TODO: m_checkAutoRun = new wxCheckBox( panel, CHECK_AUTORUN, _("Auto-run at startup") ); m_labelNofTests = new wxStaticText(panel, -1, "0"); m_labelNofRuns = new wxStaticText(panel, -1, "0"); m_labelNofErrors = new wxStaticText(panel, -1, "0"); m_labelNofFailures = new wxStaticText(panel, -1, "0"); // the initial range of 100 is arbitrary m_gaugeProgress = new wxGauge( panel, -1, 100, wxDefaultPosition, wxSize(350, wxSIZE_AUTO_HEIGHT) ); m_gaugeProgress->SetForegroundColour(*wxGREEN); m_btnBrowse = new wxButton( panel, BUTTON_BROWSE, _("&Browse") ); m_btnRun = new wxButton( panel, BUTTON_RUN, _("&Run") ); m_btnRun->SetDefault(); m_btnStop = new wxButton( panel, BUTTON_STOP, _("&Stop") ); m_btnClose = new wxButton( panel, BUTTON_CLOSE, _("&Close") ); m_listErrors = new wxListCtrl( panel, LISTCTRL_ERRORS_AND_FAILURES, wxDefaultPosition, wxDefaultSize, wxLC_REPORT ); m_listErrors->InsertColumn(0, _("Type")); m_listErrors->InsertColumn(1, _("Name")); m_listErrors->InsertColumn(2, _("Failed Condition")); m_listErrors->InsertColumn(3, _("Line Number")); m_listErrors->InsertColumn(4, _("File Name")); m_textDetails = new wxTextCtrl( panel, TEXT_DETAILS, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY /*| wxTE_DONTWRAP*/ ); // layout controls wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); panel->SetSizer( topSizer ); panel->SetAutoLayout( TRUE ); wxBoxSizer *hTopSizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer *vSizerLeft = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *hSizer = new wxBoxSizer( wxHORIZONTAL ); hSizer->Add( labelTest, 0, wxRIGHT | wxALIGN_CENTER, 5 ); hSizer->Add( m_choiceTest, 1, wxGROW | wxRIGHT, 30 ); m_choiceSizer = hSizer;// TODO: hSizer->Add( m_checkAutoRun, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5 ); vSizerLeft->Add( hSizer, 0, wxALL, 5 ); vSizerLeft->Add( labelProgress, 0, wxLEFT | wxTOP, 5 ); vSizerLeft->Add( m_gaugeProgress, 1, wxGROW | wxLEFT | wxTOP | wxBOTTOM, 5 ); hSizer = new wxBoxSizer( wxHORIZONTAL ); hSizer->Add( labelTests, 0, wxRIGHT, 5 ); hSizer->Add( m_labelNofTests, 0, wxRIGHT, 15 ); hSizer->Add( labelRuns, 0, wxRIGHT, 5 ); hSizer->Add( m_labelNofRuns, 0, wxRIGHT, 15 ); hSizer->Add( labelErrors, 0, wxRIGHT, 5 ); hSizer->Add( m_labelNofErrors, 0, wxRIGHT, 15 ); hSizer->Add( labelFailures, 0, wxRIGHT, 5 ); hSizer->Add( m_labelNofFailures ); vSizerLeft->Add( hSizer, 0, wxALL | wxALIGN_CENTER, 5 ); hTopSizer->Add( vSizerLeft, 1, wxGROW ); wxBoxSizer *vSizerRight = new wxBoxSizer( wxVERTICAL ); vSizerRight->Add( m_btnBrowse, 0, wxALL, 5 ); vSizerRight->Add( m_btnRun, 0, wxALL, 5 ); vSizerRight->Add( m_btnStop, 0, wxALL, 5 ); vSizerRight->Add( m_btnClose, 0, wxALL, 5 ); hTopSizer->Add( vSizerRight, 0 /*, wxALIGN_RIGHT */); topSizer->Add( hTopSizer ); topSizer->Add( labelErrorList, 0, wxLEFT | wxTOP, 5 ); topSizer->Add( m_listErrors, 1, wxGROW | wxALL, 5 ); topSizer->Add( labelDetails, 0, wxLEFT | wxTOP, 5 ); topSizer->Add( m_textDetails, 1, wxGROW | wxALL, 5 ); topSizer->SetSizeHints( panel ); topSizer->Fit( panel );}// ----------------------------------------------------------------------------// event handlers// ----------------------------------------------------------------------------void TestRunnerFrame::OnMenuFileExit(wxCommandEvent& WXUNUSED(event)){ Close();}void TestRunnerFrame::OnMenuHelpAbout(wxCommandEvent& WXUNUSED(event)){ wxString msg; msg.Printf( _("This is the wxWidgets Test Runner.\n\n" "Copyright 2003 by Anthon Pang and Baptiste Lepilleur.")); wxMessageBox(msg, _("About WxTestRunner"), wxOK | wxICON_INFORMATION, this);}void TestRunnerFrame::OnButtonBrowse(wxCommandEvent& WXUNUSED(event)){ browseTests();}void TestRunnerFrame::OnButtonRun(wxCommandEvent& WXUNUSED(event)){ runTest();}void TestRunnerFrame::OnButtonStop(wxCommandEvent& WXUNUSED(event)){ stopTest();}void TestRunnerFrame::OnButtonClose(wxCommandEvent& WXUNUSED(event)){ Close();}void TestRunnerFrame::OnChoiceSelectedTest(wxCommandEvent& event){ int idx = event.GetSelection();}void TestRunnerFrame::OnListSelectedError(wxListEvent& event){ int idx = event.m_itemIndex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -