1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
33 // Version: $Id: runtestsdlg.cpp,v 1.14 2001/06/29 13:48:22 julians Exp $
35 // Description: Implementation file for ecRunTestsDialog
42 //####DESCRIPTIONEND####
44 //===========================================================================
47 #pragma implementation "runtestsdlg.cpp"
56 #include "wx/notebook.h"
57 #include "wx/cshelp.h"
58 #include "wx/checklst.h"
59 #include "wx/listctrl.h"
60 #include "wx/tokenzr.h"
62 #include "TestResource.h"
63 #include "runtestsdlg.h"
64 #include "configtool.h"
65 #include "settingsdlg.h"
66 #include "eCosThreadUtils.h"
67 #include "eCosTrace.h"
69 void ecRunTestsTimer::Notify()
71 static bool s_inNotify = FALSE;
78 // On Windows, simply having the timer going will ping the message queue
79 // and cause idle processing to happen.
80 // On Unix, this doesn't happen so we have to do the processing explicitly.
84 if ( ecRunTestsDialog::m_runTestsDialog )
87 ecRunTestsDialog::m_runTestsDialog->OnIdle(event);
98 IMPLEMENT_CLASS(ecRunTestsDialog, wxDialog)
100 BEGIN_EVENT_TABLE(ecRunTestsDialog, wxDialog)
101 EVT_BUTTON(wxID_OK, ecRunTestsDialog::OnOK)
102 EVT_BUTTON(ecID_RUN_TESTS_RUN, ecRunTestsDialog::OnRun)
103 EVT_BUTTON(ecID_RUN_TESTS_PROPERTIES, ecRunTestsDialog::OnProperties)
104 //EVT_BUTTON(wxID_HELP, ecRunTestsDialog::OnHelp)
105 EVT_NOTEBOOK_PAGE_CHANGED(-1, ecRunTestsDialog::OnPageChange)
106 EVT_SIZE(ecRunTestsDialog::OnSize)
107 EVT_IDLE(ecRunTestsDialog::OnIdle)
108 EVT_CLOSE(ecRunTestsDialog::OnCloseWindow)
111 #define PROPERTY_DIALOG_WIDTH 600
112 #define PROPERTY_DIALOG_HEIGHT 550
114 ecRunTestsDialog* ecRunTestsDialog::m_runTestsDialog = NULL;
116 // For 400x400 settings dialog, size your panels to about 375x325 in dialog editor
117 // (209 x 162 dialog units)
119 ecRunTestsDialog::ecRunTestsDialog(wxWindow* parent):
121 m_runStatus(ecStopped),
124 m_testsAreComplete(FALSE)
126 m_runTestsDialog = this;
128 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
130 wxDialog::Create(parent, ecID_RUN_TESTS_DIALOG, _("Run Tests"), wxPoint(0, 0), wxSize(PROPERTY_DIALOG_WIDTH, PROPERTY_DIALOG_HEIGHT),
131 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
133 // Under MSW, we don't seem to be able to react to a click on the dialog background (no
134 // event is generated).
135 SetHelpText(_("Run tests from this dialog."));
138 wxSize ppi = dc.GetPPI();
140 //double scaleFactor = ((double) charH) / 13.0;
141 double scaleFactor = ((double) ppi.y) / 96.0;
142 // Fudge the scale factor to make the dialog slightly smaller,
143 // otherwise it's a bit big. (We're assuming that most displays
144 // are 96 or 120 ppi).
147 int dialogWidth = (int)(PROPERTY_DIALOG_WIDTH * scaleFactor);
148 int dialogHeight = (int)(PROPERTY_DIALOG_HEIGHT * scaleFactor);
149 SetSize(dialogWidth, dialogHeight);
151 m_notebook = new wxNotebook(this, ecID_RUN_TESTS_NOTEBOOK,
152 wxPoint(2, 2), wxSize(PROPERTY_DIALOG_WIDTH - 4, PROPERTY_DIALOG_HEIGHT - 4));
154 m_executables = new ecRunTestsExecutablesDialog(m_notebook);
155 m_notebook->AddPage(m_executables, wxT("Executables"));
156 m_executables->TransferDataToWindow();
158 m_output = new ecRunTestsOutputDialog(m_notebook);
159 m_notebook->AddPage(m_output, wxT("Output"));
160 m_output->TransferDataToWindow();
162 m_summary = new ecRunTestsSummaryDialog(m_notebook);
163 m_notebook->AddPage(m_summary, wxT("Summary"));
164 m_summary->TransferDataToWindow();
166 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
168 item0->Add( m_notebook, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxTOP, 5 );
170 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
172 wxButton *runButton = new wxButton( this, ecID_RUN_TESTS_RUN, "&Run", wxDefaultPosition, wxDefaultSize, 0 );
173 item1->Add( runButton, 0, wxALIGN_CENTRE|wxALL, 5 );
175 wxButton *okButton = new wxButton( this, wxID_OK, "&Close", wxDefaultPosition, wxDefaultSize, 0 );
176 item1->Add( okButton, 0, wxALIGN_CENTRE|wxALL, 5 );
178 wxButton *propertiesButton = new wxButton( this, ecID_RUN_TESTS_PROPERTIES, "&Properties...", wxDefaultPosition, wxDefaultSize, 0 );
179 item1->Add( propertiesButton, 0, wxALIGN_CENTRE|wxALL, 5 );
182 wxButton *helpButton = new wxButton( this, wxID_HELP, "&Help", wxDefaultPosition, wxDefaultSize, 0 );
183 item1->Add( helpButton, 0, wxALIGN_CENTRE|wxALL, 5 );
187 // Context-sensitive help button (question mark)
188 wxButton *contextButton = new wxContextHelpButton( this );
189 item1->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );
192 // Necessary to add a spacer or the button highlight interferes with the notebook under wxGTK
193 item0->Add( 4, 4, 0, wxALIGN_CENTRE|wxALL, 0 );
195 item0->Add( item1, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
197 this->SetAutoLayout( TRUE );
198 this->SetSizer( item0 );
200 okButton->SetDefault();
201 okButton->SetFocus();
205 m_executables->Layout();
209 okButton->SetHelpText(_("Closes the dialog."));
210 runButton->SetHelpText(_("Runs one or more tests selected in the Executables window."));
211 propertiesButton->SetHelpText(_("Shows timeout and connection properties."));
212 //helpButton->SetHelpText(_("Invokes help for the selected dialog."));
216 // TODO: Is this necessary?
218 m_prop.Add(_T("Active timeout"), wxGetApp().GetSettings().GetRunTestsSettings().m_nTimeout);
219 m_prop.Add(_T("Download timeout"), wxGetApp().GetSettings().GetRunTestsSettings().m_nDownloadTimeout);
220 m_prop.Add(_T("Active timeout type"), wxGetApp().GetSettings().GetRunTestsSettings().m_nTimeoutType);
221 m_prop.Add(_T("Download timeout type"), wxGetApp().GetSettings().GetRunTestsSettings().m_nDownloadTimeoutType);
222 m_prop.Add(_T("Remote"), wxGetApp().GetSettings().GetRunTestsSettings().m_bRemote);
223 m_prop.Add(_T("Serial"), wxGetApp().GetSettings().GetRunTestsSettings().m_bSerial);
224 m_prop.Add(_T("Port"), wxGetApp().GetSettings().GetRunTestsSettings().m_strPort);
225 m_prop.Add(_T("Baud"), wxGetApp().GetSettings().GetRunTestsSettings().m_nBaud);
226 m_prop.Add(_T("Local TCPIP Host"), wxGetApp().GetSettings().GetRunTestsSettings().m_strLocalTCPIPHost);
227 m_prop.Add(_T("Local TCPIP Port"), wxGetApp().GetSettings().GetRunTestsSettings().m_nLocalTCPIPPort);
228 m_prop.Add(_T("Reset Type"), wxGetApp().GetSettings().GetRunTestsSettings().m_nReset);
229 m_prop.Add(_T("Reset String"), wxGetApp().GetSettings().GetRunTestsSettings().m_strReset);
230 m_prop.Add(_T("Resource Host"), wxGetApp().GetSettings().GetRunTestsSettings().m_strResourceHost);
231 m_prop.Add(_T("Resource Port"), wxGetApp().GetSettings().GetRunTestsSettings().m_nResourcePort);
232 m_prop.Add(_T("Remote Host"), wxGetApp().GetSettings().GetRunTestsSettings().m_strRemoteHost);
233 m_prop.Add(_T("Remote Port"), wxGetApp().GetSettings().GetRunTestsSettings().m_nRemotePort);
235 //m_prop.Add(_T("Recurse"), executionpage.m_bRecurse);
236 m_prop.Add(_T("Farmed"), wxGetApp().GetSettings().GetRunTestsSettings().m_bFarmed);
238 // m_prop.Add(_T("Extension"),executionpage.m_strExtension);
242 CeCosTrace::EnableTracing(CeCosTrace::TRACE_LEVEL_TRACE);
244 CeCosTrace::SetInteractive(TRUE);
245 CeCosTrace::SetOutput(TestOutputCallback, this);
246 CeCosTrace::SetError (TestOutputCallback, this);
251 ecRunTestsDialog::~ecRunTestsDialog()
254 CeCosTrace::SetInteractive(FALSE);
255 m_runTestsDialog = NULL;
262 void ecRunTestsDialog::OnOK(wxCommandEvent& event)
264 if (ecRunning == m_runStatus)
266 wxMessageBox(_("Tests are running. Please press Stop before quitting this dialog."),
267 wxGetApp().GetSettings().GetAppName(), wxICON_INFORMATION|wxOK, this);
271 wxDialog::OnOK(event);
274 void ecRunTestsDialog::OnCloseWindow(wxCloseEvent& event)
276 if (ecRunning == m_runStatus)
278 wxMessageBox(_("Tests are running. Please press Stop before quitting this dialog."),
279 wxGetApp().GetSettings().GetAppName(), wxICON_INFORMATION|wxOK, this);
284 this->EndModal(wxID_CANCEL);
288 void ecRunTestsDialog::OnProperties(wxCommandEvent& event)
290 ecSettingsDialog dialog(this);
291 dialog.SetSelection(3);
295 void ecRunTestsDialog::OnRun(wxCommandEvent& event)
297 if (ecRunning == m_runStatus)
299 m_output->AddLogMsg(_("Run cancelled"));
300 m_runStatus = ecStopping;
302 m_nNextToSubmit=0x7fffffff;
304 CeCosTest::CancelAllInstances();
308 if ( 0 == m_executables->SelectedTestCount())
310 wxMessageBox(_("No tests have been selected for execution."),
311 wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK, this);
316 m_ep = CeCosTest::ExecutionParameters(
317 CeCosTest::ExecutionParameters::RUN,
318 wxGetApp().GetSettings().GetRunTestsSettings().m_strTarget,
319 TIMEOUT_NONE==wxGetApp().GetSettings().GetRunTestsSettings().m_nTimeoutType?0x7fffffff:TIMEOUT_AUTOMATIC==wxGetApp().GetSettings().GetRunTestsSettings().m_nTimeoutType?900000:1000*wxGetApp().GetSettings().GetRunTestsSettings().m_nTimeout,
320 TIMEOUT_NONE==wxGetApp().GetSettings().GetRunTestsSettings().m_nDownloadTimeoutType?0x7fffffff:TIMEOUT_AUTOMATIC==wxGetApp().GetSettings().GetRunTestsSettings().m_nDownloadTimeoutType?0:1000*wxGetApp().GetSettings().GetRunTestsSettings().m_nDownloadTimeout);
322 if ( wxGetApp().GetSettings().GetRunTestsSettings().m_bRemote )
324 CTestResource::SetResourceServer(CeCosSocket::HostPort(wxGetApp().GetSettings().GetRunTestsSettings().m_strResourceHost, wxGetApp().GetSettings().GetRunTestsSettings().m_nResourcePort));
325 if (!CTestResource::Load())
327 wxMessageBox(_("Could not connect to resource server."),
328 wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK, this);
335 if (wxGetApp().GetSettings().GetRunTestsSettings().m_bSerial)
336 strPort = wxGetApp().GetSettings().GetRunTestsSettings().m_strPort;
338 strPort = (const wxChar*) CeCosSocket::HostPort(wxGetApp().GetSettings().GetRunTestsSettings().m_strLocalTCPIPHost,wxGetApp().GetSettings().GetRunTestsSettings().m_nLocalTCPIPPort);
339 if(0==strPort.Length()){
340 m_pResource=new CTestResource(_T(""),m_ep.PlatformName());
343 // Translate from e.g. COM2 to /dev/ttyS1 on Unix.
344 // Let's assume the Windows notation is the 'standard'.
345 strPort = TranslatePort(strPort);
346 int nBaud = wxGetApp().GetSettings().GetRunTestsSettings().m_bSerial ? wxGetApp().GetSettings().GetRunTestsSettings().m_nBaud:0;
347 if (RESET_X10 != wxGetApp().GetSettings().GetRunTestsSettings().m_nReset) {
348 m_pResource=new CTestResource(_T(""),m_ep.PlatformName(), strPort, nBaud);
350 m_pResource=new CTestResource(_T(""),m_ep.PlatformName(), strPort, nBaud, wxGetApp().GetSettings().GetRunTestsSettings().m_strReset);
354 m_runStatus = ecRunning;
355 m_testsAreComplete = FALSE;
357 wxButton* runButton = (wxButton*) FindWindow(ecID_RUN_TESTS_RUN);
358 runButton->SetLabel(_("&Stop"));
361 m_output->AddLogMsg(_("Run started"));
368 wxString ecRunTestsDialog::TranslatePort(const wxString& port) const
371 wxString name(port.Left(3));
372 if (name.CmpNoCase(wxT("COM")) == 0)
374 wxString strNum(port.Mid(3));
375 if (strNum.IsEmpty())
377 int num = atoi(strNum);
379 newPort.Printf(wxT("/dev/ttyS%d"), num-1);
387 void ecRunTestsDialog::SubmitTests()
390 int nResources=wxGetApp().GetSettings().GetRunTestsSettings().m_bRemote ? wxMax(1,CTestResource::GetMatchCount (m_ep)):1;
391 if(nResources>CeCosTest::InstanceCount){
392 if (m_nNextToSubmit >= m_executables->SelectedTestCount()){
393 m_runStatus = ecStopped;
395 wxButton* runButton = (wxButton*) FindWindow(ecID_RUN_TESTS_RUN);
396 runButton->SetLabel(_("&Run"));
397 m_output->AddLogMsg(_("Run complete"));
403 ecRunTestsInfo *pInfo=new ecRunTestsInfo;
404 pInfo->pTest=new CeCosTest(m_ep, m_executables->SelectedTest(m_nNextToSubmit++));
406 if(wxGetApp().GetSettings().GetRunTestsSettings().m_bRemote){
407 CeCosThreadUtils::RunThread(RunRemoteFunc,pInfo, (CeCosThreadUtils::CallbackProc*) RunCallback,_T("RunRemoteFunc"));
410 switch((ResetType)wxGetApp().GetSettings().GetRunTestsSettings().m_nReset){
416 // Resetting can take a while, so spawn a thread
418 ecResetThread* thread = new ecResetThread(pInfo);
419 if (thread->Create() != wxTHREAD_NO_ERROR)
421 // Thread will be deleted automatically when it has finished running
431 bRun=(wxOK == wxMessageBox(_("Press OK when target is reset - cancel to abort run"),_("Reset board"), wxOK|wxCANCEL));
434 m_nNextToSubmit = m_executables->SelectedTestCount();
441 if (1 < m_nNextToSubmit)
442 m_output->AddLogMsg(_("Run continuing"));
443 CeCosThreadUtils::RunThread(RunLocalFunc, pInfo, (CeCosThreadUtils::CallbackProc*) RunCallback,_T("RunLocalFunc"));
449 // thread execution starts here
450 void *ecResetThread::Entry()
455 CResetAttributes::ResetResult n=m_info->pSheet->m_pResource->Reset(str1);
457 if(CResetAttributes::RESET_OK!=n){
458 str += wxT(">>> Could not reset target\n");
462 m_info->pSheet->OutputToBuffer(str);
465 // we're already in a thread, so we can call the function directly
466 m_info->pTest->RunLocal();
468 ecRunTestsDialog::RunCallback(m_info);
473 // called when the thread exits - whether it terminates normally or is
474 // stopped with Delete() (but not when it is Kill()ed!)
475 void ecResetThread::OnExit()
479 void CALLBACK ecRunTestsDialog::RunLocalFunc(void *pParam)
481 ((ecRunTestsInfo *)pParam)->pTest->RunLocal();
484 void CALLBACK ecRunTestsDialog::RunRemoteFunc(void *pParam)
486 ((ecRunTestsInfo *)pParam)->pTest->RunRemote(NULL);
489 void ecRunTestsDialog::RunCallback(void *pParam)
491 ecRunTestsInfo *pInfo=(ecRunTestsInfo *)pParam;
492 ecRunTestsDialog *pSheet=pInfo->pSheet;
493 if (m_runTestsDialog) // Will be NULL if dialog has been closed & deleted
495 CeCosTest *pTest=pInfo->pTest;
497 pInfo->pSheet->m_CS.Enter();
499 pSheet->m_summary->AddResult(pTest);
502 // OnIdle will check this variable and reset the status and button label
503 pSheet->m_testsAreComplete = TRUE;
505 pInfo->pSheet->m_CS.Leave();
510 void ecRunTestsDialog::OnIdle(wxIdleEvent& event)
514 if (m_testsAreComplete)
516 m_testsAreComplete = FALSE;
523 void CALLBACK ecRunTestsDialog::TestOutputCallback(void *pParam,LPCTSTR psz)
525 ecRunTestsDialog* pWnd = (ecRunTestsDialog*)pParam;
526 if (ecRunTestsDialog::m_runTestsDialog)
528 pWnd->OutputToBuffer(psz);
532 // Write to the output buffer for OnIdle to pick up
533 void ecRunTestsDialog::OutputToBuffer(const wxString& str)
535 wxCriticalSection ct;
538 if (m_outputBufferPresent)
539 m_outputBuffer += str;
541 m_outputBuffer = str;
542 m_outputBufferPresent = TRUE;
547 // Write any remaining text
548 void ecRunTestsDialog::FlushBuffer()
550 if (m_outputBufferPresent)
552 m_output->AddText(m_outputBuffer);
553 m_outputBuffer = wxEmptyString;
554 m_outputBufferPresent = FALSE;
559 void ecRunTestsDialog::OnHelp(wxCommandEvent& event)
561 int sel = m_notebook->GetSelection();
563 wxASSERT_MSG( (sel != -1), wxT("A notebook tab should always be selected."));
565 wxWindow* page = (wxWindow*) m_notebook->GetPage(sel);
568 if (page == m_displayOptions)
570 helpTopic = wxT("Display options dialog");
573 if (!helpTopic.IsEmpty())
575 wxGetApp().GetHelpController().KeywordSearch(helpTopic);
580 // This sets the text for the selected page, but doesn't help
581 // when trying to click on a tab: we would expect the appropriate help
582 // for that tab. We would need to look at the tabs to do this, from within OnContextHelp -
583 // probably not worth it.
584 void ecRunTestsDialog::OnPageChange(wxNotebookEvent& event)
588 int sel = m_notebook->GetSelection();
592 wxWindow* page = m_notebook->GetPage(sel);
597 if (page == m_displayOptions)
598 helpText = _("The display options dialog allows you to change display-related options.");
599 else if (page == m_viewerOptions)
600 helpText = _("The viewer options dialog allows you to configure viewers.");
601 else if (page == m_pathOptions)
602 helpText = _("The path options dialog allows you to change tool paths.");
603 else if (page == m_conflictResolutionOptions)
604 helpText = _("The conflict resolution options dialog allows you to change options related to conflict resolution.");
605 m_notebook->SetHelpText(helpText);
610 bool ecRunTestsDialog::TransferDataToWindow()
612 // In this case there is no data to be transferred
613 m_executables->TransferDataToWindow();
614 m_output->TransferDataToWindow();
615 m_summary->TransferDataToWindow();
619 bool ecRunTestsDialog::TransferDataFromWindow()
621 // In this case there is no data to be transferred
622 m_executables->TransferDataFromWindow();
623 m_output->TransferDataFromWindow();
624 m_summary->TransferDataFromWindow();
628 void ecRunTestsDialog::OnSize(wxSizeEvent& event)
632 wxRefreshControls(this);
635 // Add the test to the dialog
636 void ecRunTestsDialog::Populate(const wxString& test, bool select)
638 wxCheckListBox* checkListBox = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
640 wxASSERT( checkListBox );
642 checkListBox->Append(test);
644 checkListBox->Check(checkListBox->Number() - 1, TRUE);
648 /* Executables dialog
651 IMPLEMENT_CLASS(ecRunTestsExecutablesDialog, wxPanel)
653 BEGIN_EVENT_TABLE(ecRunTestsExecutablesDialog, wxPanel)
654 EVT_BUTTON(ecID_RUN_TESTS_CHECK_ALL, ecRunTestsExecutablesDialog::OnCheckAll)
655 EVT_BUTTON(ecID_RUN_TESTS_UNCHECK_ALL, ecRunTestsExecutablesDialog::OnUncheckAll)
656 EVT_BUTTON(ecID_RUN_TESTS_ADD, ecRunTestsExecutablesDialog::OnAdd)
657 EVT_BUTTON(ecID_RUN_TESTS_ADD_FOLDER, ecRunTestsExecutablesDialog::OnAddFromFolder)
658 EVT_BUTTON(ecID_RUN_TESTS_REMOVE, ecRunTestsExecutablesDialog::OnRemove)
660 EVT_UPDATE_UI(ecID_RUN_TESTS_CHECK_ALL, ecRunTestsExecutablesDialog::OnUpdateCheckAll)
661 EVT_UPDATE_UI(ecID_RUN_TESTS_UNCHECK_ALL, ecRunTestsExecutablesDialog::OnUpdateUncheckAll)
665 ecRunTestsExecutablesDialog::ecRunTestsExecutablesDialog(wxWindow* parent):
666 wxPanel(parent, ecID_RUN_TESTS_EXECUTABLES)
668 CreateControls(this);
670 SetHelpText(_("The executables dialog allows you to select tests to be run."));
673 void ecRunTestsExecutablesDialog::CreateControls( wxPanel *parent)
675 // Create the foreign control
676 wxCheckListBox* listBox = new wxCheckListBox(parent, ecID_RUN_TESTS_TEST_LIST, wxDefaultPosition, wxSize(100, 100),
677 0, NULL, wxSUNKEN_BORDER|wxLB_EXTENDED);
679 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
681 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
683 wxButton *item2 = new wxButton( parent, ecID_RUN_TESTS_CHECK_ALL, "C&heck All", wxDefaultPosition, wxDefaultSize, 0 );
684 item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
686 item1->Add( 2, 2, 1, wxALIGN_CENTRE|wxALL, 0 );
688 wxButton *item3 = new wxButton( parent, ecID_RUN_TESTS_UNCHECK_ALL, "&Uncheck All", wxDefaultPosition, wxDefaultSize, 0 );
689 item1->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );
691 item1->Add( 2, 2, 1, wxALIGN_CENTRE|wxALL, 0 );
693 wxButton *item4 = new wxButton( parent, ecID_RUN_TESTS_ADD, "&Add...", wxDefaultPosition, wxDefaultSize, 0 );
694 item1->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
696 item1->Add( 2, 2, 1, wxALIGN_CENTRE|wxALL, 0 );
698 wxButton *item5 = new wxButton( parent, ecID_RUN_TESTS_ADD_FOLDER, "Add from &Folder...", wxDefaultPosition, wxDefaultSize, 0 );
699 item1->Add( item5, 0, wxALIGN_CENTRE|wxALL, 5 );
701 item1->Add( 2, 2, 1, wxALIGN_CENTRE|wxALL, 0 );
703 wxButton *item6 = new wxButton( parent, ecID_RUN_TESTS_REMOVE, "&Remove", wxDefaultPosition, wxDefaultSize, 0 );
704 item1->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
706 item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
708 wxWindow *item7 = parent->FindWindow( ecID_RUN_TESTS_TEST_LIST );
710 item0->Add( item7, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
712 // Add context-sensitive help
713 FindWindow(ecID_RUN_TESTS_TEST_LIST)->SetHelpText(_("Displays the set of tests that can be executed. Each test can be selected for execution by checking the adjacent box."));
714 FindWindow(ecID_RUN_TESTS_CHECK_ALL)->SetHelpText(_("Selects all tests for execution."));
715 FindWindow(ecID_RUN_TESTS_UNCHECK_ALL)->SetHelpText(_("Clears the selection of tests."));
716 FindWindow(ecID_RUN_TESTS_ADD)->SetHelpText(_("Adds a test to the set that can be executed."));
717 FindWindow(ecID_RUN_TESTS_ADD_FOLDER)->SetHelpText(_("Adds one or more tests to the set that can be executed, from a folder."));
718 FindWindow(ecID_RUN_TESTS_REMOVE)->SetHelpText(_("Removes a test from the set that can executed."));
720 parent->SetAutoLayout( TRUE );
721 parent->SetSizer( item0 );
724 void ecRunTestsExecutablesDialog::OnCheckAll(wxCommandEvent& event)
726 wxCheckListBox* checkList = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
731 int n = checkList->Number();
732 for (i = 0; i < n; i++)
733 checkList->Check(i, TRUE);
736 void ecRunTestsExecutablesDialog::OnUncheckAll(wxCommandEvent& event)
738 wxCheckListBox* checkList = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
743 int n = checkList->Number();
744 for (i = 0; i < n; i++)
745 checkList->Check(i, FALSE);
748 void ecRunTestsExecutablesDialog::OnAdd(wxCommandEvent& event)
750 wxCheckListBox* checkList = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
755 // wxString wildcard(wxT("Executables (*.exe)|*.exe"));
757 wxString wildcard(wxT("Executables (*)|*"));
760 wxFileDialog dialog(this, _("Choose one or more executables to add"), wxGetCwd(), wxEmptyString,
761 wildcard, wxMULTIPLE|wxOPEN);
763 if (dialog.ShowModal() == wxID_OK)
766 dialog.GetPaths(paths);
771 int n = paths.Count();
772 for (i = 0; i < n; i++)
774 // TODO: check that it's the right kind of file
775 if (-1 == checkList->FindString(paths[i]))
777 checkList->Append(paths[i]);
778 checkList->Check(checkList->Number()-1, TRUE);
784 wxMessageBox(_("One or more of the files was already present"),
785 wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK, this);
789 void ecRunTestsExecutablesDialog::OnAddFromFolder(wxCommandEvent& event)
791 wxCheckListBox* checkList = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
795 // In the MFC tool, a modified version of the folder dialog was used but
796 // we can't do that in general in wxWindows; so instead we ask the questions
797 // before we show the folder dialog.
798 // We won't bother allowing the user to change the extension: on Windows it's .exe,
799 // on Unix it's anything.
801 // wxString filespec(wxT("*.exe"));
803 wxString filespec(wxT("*"));
807 msg.Printf(_("Would you like to add from subfolders, or just the folder you specify?\nChoose Yes to add from subfolders."));
808 int ans = wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_QUESTION|wxYES_NO|wxCANCEL, this);
812 bool recurse = (ans == wxYES);
814 wxDirDialog dialog(this, _("Choose a folder to add tests from"), wxGetCwd());
815 if (dialog.ShowModal() == wxID_OK)
817 wxString folder(dialog.GetPath());
819 if (!wxDirExists(folder))
821 wxMessageBox(_("Sorry, this folder does not exist."), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK, this);
826 AddFromFolder(folder, recurse, filespec);
830 void ecRunTestsExecutablesDialog::AddFromFolder(const wxString& folder, bool recurse, const wxString& wildcard)
833 wxCheckListBox* checkList = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
837 if (!dir.Open(folder))
841 bool success = dir.GetFirst(& filename, wildcard, wxDIR_FILES);
844 wxString path = folder + wxString(wxFILE_SEP_PATH) + filename;
846 if (-1 == checkList->FindString(path))
848 checkList->Append(path);
849 checkList->Check(checkList->Number()-1, TRUE);
852 success = dir.GetNext(& filename);
856 // Recurse down the subfolders
859 wxArrayString subfolders;
863 if (!dir2.Open(folder))
866 bool success = dir2.GetFirst(& filename, wxT("*"), wxDIR_DIRS);
869 wxString path = folder + wxString(wxFILE_SEP_PATH) + filename;
870 subfolders.Add(path);
872 success = dir2.GetNext(& filename);
877 for (i = 0; i < subfolders.Count(); i ++)
879 AddFromFolder(subfolders[i], recurse, wildcard);
884 void ecRunTestsExecutablesDialog::OnRemove(wxCommandEvent& event)
886 wxCheckListBox* checkList = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
893 // Delete the selections one at a time since
894 // the indexes change when you delete one
897 if (checkList->GetSelections(ar) > 0)
899 checkList->Delete(ar[0]);
909 void ecRunTestsExecutablesDialog::OnUpdateCheckAll(wxUpdateUIEvent& event)
911 wxCheckListBox* checkList = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
915 // If there were no unchecked items, we can disable the check all button
916 event.Enable( checkList->Number() != SelectedTestCount() );
919 void ecRunTestsExecutablesDialog::OnUpdateUncheckAll(wxUpdateUIEvent& event)
921 event.Enable( SelectedTestCount() > 0 );
924 int ecRunTestsExecutablesDialog::SelectedTestCount()
926 wxCheckListBox* checkList = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
932 int n = checkList->Number();
933 for (i = 0; i < n; i++)
935 if (checkList->IsChecked(i))
943 wxString ecRunTestsExecutablesDialog::SelectedTest(int nIndex)
946 wxCheckListBox* checkList = (wxCheckListBox*) FindWindow(ecID_RUN_TESTS_TEST_LIST);
951 for (i=0; i < checkList->Number(); i++)
953 if (checkList->IsChecked(i))
957 str = checkList->GetString(i);
968 IMPLEMENT_CLASS(ecRunTestsOutputDialog, wxPanel)
970 ecRunTestsOutputDialog::ecRunTestsOutputDialog(wxWindow* parent):
971 wxPanel(parent, ecID_RUN_TESTS_OUTPUT)
973 CreateControls(this);
975 SetHelpText(_("The output dialog displays the run output."));
978 void ecRunTestsOutputDialog::CreateControls( wxPanel *parent)
980 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
982 wxTextCtrl *item1 = new wxTextCtrl( parent, ecID_RUN_TESTS_OUTPUT_TEXT, "", wxDefaultPosition, wxSize(80,40), wxTE_MULTILINE );
983 item0->Add( item1, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
985 // Add context-sensitive help
986 FindWindow(ecID_RUN_TESTS_OUTPUT_TEXT)->SetHelpText(_("Displays the output of test execution."));
988 parent->SetAutoLayout( TRUE );
989 parent->SetSizer( item0 );
992 void ecRunTestsOutputDialog::AddText(const wxString& msg)
994 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow(ecID_RUN_TESTS_OUTPUT_TEXT);
995 wxASSERT (textCtrl != NULL);
997 textCtrl->SetInsertionPointEnd();
998 textCtrl->AppendText(msg);
1001 void ecRunTestsOutputDialog::AddLogMsg(const wxString& msg)
1005 if ((msg == wxEmptyString) || (msg.Last() != wxT('\n')))
1014 IMPLEMENT_CLASS(ecRunTestsSummaryDialog, wxPanel)
1016 BEGIN_EVENT_TABLE(ecRunTestsSummaryDialog, wxPanel)
1017 EVT_LIST_COL_CLICK(ecID_RUN_TESTS_SUMMARY_LIST, ecRunTestsSummaryDialog::OnColClick)
1020 wxListCtrl* ecRunTestsSummaryDialog::m_listCtrl = NULL;
1022 ecRunTestsSummaryDialog::ecRunTestsSummaryDialog(wxWindow* parent):
1023 wxPanel(parent, ecID_RUN_TESTS_SUMMARY)
1025 CreateControls(this);
1027 SetHelpText(_("The summary dialog shows a summary of the results of each run."));
1030 void ecRunTestsSummaryDialog::CreateControls( wxPanel *parent)
1032 m_listCtrl = new wxListCtrl(parent, ecID_RUN_TESTS_SUMMARY_LIST, wxDefaultPosition, wxSize(100, 100), wxSUNKEN_BORDER|wxLC_REPORT);
1033 m_listCtrl->InsertColumn(0, "Time", wxLIST_FORMAT_LEFT, 60);
1034 m_listCtrl->InsertColumn(1, "Host", wxLIST_FORMAT_LEFT, 60);
1035 m_listCtrl->InsertColumn(2, "Platform", wxLIST_FORMAT_LEFT, 60);
1036 m_listCtrl->InsertColumn(3, "Executable", wxLIST_FORMAT_LEFT, 60);
1037 m_listCtrl->InsertColumn(4, "Status", wxLIST_FORMAT_LEFT, 60);
1038 m_listCtrl->InsertColumn(5, "Size", wxLIST_FORMAT_LEFT, 60);
1039 m_listCtrl->InsertColumn(6, "Download", wxLIST_FORMAT_LEFT, 60);
1040 m_listCtrl->InsertColumn(7, "Elapsed", wxLIST_FORMAT_LEFT, 60);
1041 m_listCtrl->InsertColumn(8, "Execution", wxLIST_FORMAT_LEFT, 60);
1043 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
1045 wxWindow *item1 = parent->FindWindow( ecID_RUN_TESTS_SUMMARY_LIST );
1047 item0->Add( item1, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1049 parent->SetAutoLayout( TRUE );
1050 parent->SetSizer( item0 );
1052 // Add context-sensitive help
1053 FindWindow(ecID_RUN_TESTS_SUMMARY_LIST)->SetHelpText(_("Displays a summary of test execution."));
1056 void ecRunTestsSummaryDialog::AddResult (CeCosTest *pTest)
1058 const wxString strResult(pTest->ResultString(FALSE));
1059 int nLength=strResult.Length();
1061 wxString strTime,strDate;
1064 // 1999-05-28 10:29:28 nan:0 TX39-jmr3904-sim tx39-jmr3904sim-libc10-signal2.exe Fail 0k/1108k D=0.0/0.0 Total=9.3 E=0.6/300.0
1065 wxStringTokenizer tok(strResult, wxT(" "));
1066 strDate = tok.GetNextToken();
1067 strTime = tok.GetNextToken();
1069 strDate += wxT(" ");
1072 for (i = 0; i < 8; i++)
1073 arstr[i] = tok.GetNextToken();
1075 // Remove characters before '=' in time fields
1076 for ( i = 5 ; i < 8 ; i ++ )
1078 wxString str = arstr[i].AfterFirst(wxT('-')) ;
1079 arstr[i] = str.IsEmpty() ? arstr[i] : str;
1082 int nItem = m_listCtrl->GetItemCount() ;
1083 int nIndex = m_listCtrl->InsertItem (nItem, strDate);
1084 m_listCtrl->SetItemData(nItem,nItem);// to support sorting
1085 for (i = 0; i < 8; i++)
1087 m_listCtrl->SetItem(nIndex, i+1, arstr[i]);
1093 // TRACE(_T("%s\n"),strResult);
1094 // 1999-05-28 10:29:28 nan:0 TX39-jmr3904-sim tx39-jmr3904sim-libc10-signal2.exe Fail 0k/1108k D=0.0/0.0 Total=9.3 E=0.6/300.0
1095 _stscanf(strResult,_T("%s %s %s %s %s %s %s %s %s %s"),
1096 strDate.GetBuffer(1+nLength),
1097 strTime.GetBuffer(1+nLength),
1098 arstr[0].GetBuffer(1+nLength),
1099 arstr[1].GetBuffer(1+nLength),
1100 arstr[2].GetBuffer(1+nLength),
1101 arstr[3].GetBuffer(1+nLength),
1102 arstr[4].GetBuffer(1+nLength),
1103 arstr[5].GetBuffer(1+nLength),
1104 arstr[6].GetBuffer(1+nLength),
1105 arstr[7].GetBuffer(1+nLength));
1107 // Remove before '=' in time fields
1109 TCHAR *pch=_tcschr(arstr[i],_TCHAR('='));
1115 strDate.ReleaseBuffer();
1116 strTime.ReleaseBuffer();
1117 strDate+=_TCHAR(' ');
1119 int nItem=m_List.GetItemCount();
1120 m_List.InsertItem(nItem,strDate);
1121 m_List.SetItemData(nItem,nItem);// to support sorting
1123 m_List.SetItemText(nItem,1+i,arstr[i]);
1124 arstr[i].ReleaseBuffer();
1130 // The function is passed the client data of the two items,
1131 // plus another general client data value which in this case
1132 // we use for the column index.
1133 int CALLBACK ecRunTestsSummaryDialog::SummarySortFunc(long data1, long data2, long col)
1135 wxString str1 = wxListCtrlGetItemTextColumn(* m_listCtrl, data1, col);
1136 wxString str2 = wxListCtrlGetItemTextColumn(* m_listCtrl, data2, col);
1138 int ret = str1.CmpNoCase(str2);
1142 void ecRunTestsSummaryDialog::OnColClick(wxListEvent& event)
1144 m_listCtrl->SortItems((wxListCtrlCompare) SummarySortFunc,(long) event.m_col);
1146 // The item data contains the index in the list control, so this needs
1147 // to be reset after sorting.
1149 for (i = m_listCtrl->GetItemCount()-1;i>=0;--i)
1151 m_listCtrl->SetItemData(i,i);