4
// $Id: //poco/1.2/CppUnit/WinTestRunner/src/TestRunnerDlg.cpp#1 $
12
#include "TestRunnerDlg.h"
13
#include "ActiveTest.h"
14
#include "GUITestResult.h"
15
#include "ProgressBar.h"
16
#include "CppUnit/TestSuite.h"
17
#include "TestRunnerDlg.h"
23
TestRunnerDlg::TestRunnerDlg(CWnd* pParent): CDialog(TestRunnerDlg::IDD, pParent)
25
//{{AFX_DATA_INIT(TestRunnerDlg)
26
// NOTE: the ClassWizard will add member initialization here
34
void TestRunnerDlg::DoDataExchange(CDataExchange* pDX)
36
CDialog::DoDataExchange(pDX);
37
//{{AFX_DATA_MAP(TestRunnerDlg)
38
// NOTE: the ClassWizard will add DDX and DDV calls here
43
BEGIN_MESSAGE_MAP(TestRunnerDlg, CDialog)
44
//{{AFX_MSG_MAP(TestRunnerDlg)
45
ON_BN_CLICKED(ID_RUN, OnRun)
46
ON_BN_CLICKED(ID_STOP, OnStop)
47
ON_CBN_SELCHANGE(IDC_COMBO_TEST, OnSelchangeComboTest)
48
ON_BN_CLICKED(IDC_CHK_AUTORUN, OnBnClickedAutorun)
54
BOOL TestRunnerDlg::OnInitDialog()
56
CDialog::OnInitDialog();
58
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
59
CComboBox *comboBox = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
67
title.Append(" [debug]");
69
title.Append(" [release]");
73
listCtrl->InsertColumn (0,"Type", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("Type"), 1);
74
listCtrl->InsertColumn (1,"Name", LVCFMT_LEFT, 16 * listCtrl->GetStringWidth ("X"), 2);
75
listCtrl->InsertColumn (2,"Failed Condition", LVCFMT_LEFT, 24 * listCtrl->GetStringWidth ("M"), 3);
76
listCtrl->InsertColumn (3,"Line", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("0000"), 4);
77
listCtrl->InsertColumn (4,"File Name", LVCFMT_LEFT, 36 * listCtrl->GetStringWidth ("M"), 5);
79
int numberOfCases = 0;
81
CWinApp* pApp = AfxGetApp();
82
CString lastTestCS = pApp->GetProfileString("Tests", "lastTest");
83
std::string lastTest((LPCSTR) lastTestCS);
85
for (std::vector<TestInfo>::iterator it = _tests.begin (); it != _tests.end (); ++it)
87
std::string cbName(it->level*4, ' ');
88
cbName.append(it->pTest->toString());
89
comboBox->AddString (cbName.c_str ());
92
if (lastTest.empty() || lastTest == it->pTest->toString())
94
_selectedTest = it->pTest;
101
if (numberOfCases > 0)
105
_selectedTest = _tests[0].pTest;
108
comboBox->SetCurSel (sel);
114
CWnd *pProgress = GetDlgItem(IDC_PROGRESS);
116
pProgress->GetWindowRect(&rect);
117
_testsProgress = new ProgressBar (this, rect);
119
CButton* autoRunBtn = (CButton*) GetDlgItem(IDC_CHK_AUTORUN);
120
autoRunBtn->SetCheck(pApp->GetProfileInt("Tests", "autoRun", BST_UNCHECKED));
124
if (autoRunBtn->GetCheck() == BST_CHECKED)
129
return TRUE; // return TRUE unless you set the focus to a control
130
// EXCEPTION: OCX Property Pages should return FALSE
134
TestRunnerDlg::~TestRunnerDlg ()
137
delete _testsProgress;
141
void TestRunnerDlg::OnRun()
143
if (_selectedTest == 0)
151
int numberOfTests = _selectedTest->countTestCases ();
153
_testsProgress->start (numberOfTests);
155
_result = new GUITestResult ((TestRunnerDlg *)this);
156
_activeTest = new ActiveTest (_selectedTest);
158
_testStartTime = timeGetTime ();
160
_activeTest->run (_result);
162
_testEndTime = timeGetTime ();
167
void TestRunnerDlg::addListEntry(const std::string& type, TestResult *result, Test *test, CppUnitException *e)
171
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
172
int currentEntry = result->testErrors () + result->testFailures () -1;
174
sprintf (stage, "%s", type.c_str ());
176
lvi.mask = LVIF_TEXT;
177
lvi.iItem = currentEntry;
184
listCtrl->InsertItem (&lvi);
187
listCtrl->SetItemText (currentEntry, 1, test->toString ().c_str ());
189
// Set the asserted text
190
listCtrl->SetItemText(currentEntry, 2, e->what ());
192
// Set the line number
193
if (e->lineNumber () == CppUnitException::CPPUNIT_UNKNOWNLINENUMBER)
194
sprintf (stage, "<unknown>");
196
sprintf (stage, "%ld", e->lineNumber ());
198
listCtrl->SetItemText(currentEntry, 3, stage);
201
listCtrl->SetItemText(currentEntry, 4, e->fileName ().c_str ());
203
listCtrl->RedrawItems (currentEntry, currentEntry);
204
listCtrl->UpdateWindow ();
209
void TestRunnerDlg::addError (TestResult *result, Test *test, CppUnitException *e)
211
addListEntry ("Error", result, test, e);
214
updateCountsDisplay ();
219
void TestRunnerDlg::addFailure (TestResult *result, Test *test, CppUnitException *e)
221
addListEntry ("Failure", result, test, e);
224
updateCountsDisplay ();
229
void TestRunnerDlg::endTest (TestResult *result, Test *test)
231
if (_selectedTest == 0)
235
updateCountsDisplay ();
236
_testsProgress->step (_failures == 0 && _errors == 0);
238
_testEndTime = timeGetTime ();
240
updateCountsDisplay ();
242
if (_testsRun >= _selectedTest->countTestCases ())
247
void TestRunnerDlg::beRunning ()
249
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
250
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
252
runButton->EnableWindow (FALSE);
253
closeButton->EnableWindow (FALSE);
258
void TestRunnerDlg::beIdle ()
260
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
261
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
263
runButton->EnableWindow (TRUE);
264
closeButton->EnableWindow (TRUE);
269
void TestRunnerDlg::beRunDisabled ()
271
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
272
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
273
CButton *stopButton = (CButton *)GetDlgItem (ID_STOP);
275
runButton->EnableWindow (FALSE);
276
stopButton->EnableWindow (FALSE);
277
closeButton->EnableWindow (TRUE);
282
void TestRunnerDlg::freeState ()
290
void TestRunnerDlg::reset ()
295
_testEndTime = _testStartTime;
297
updateCountsDisplay ();
302
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
304
listCtrl->DeleteAllItems ();
305
_testsProgress->reset ();
310
void TestRunnerDlg::updateCountsDisplay ()
312
CStatic *statTestsRun = (CStatic *)GetDlgItem (IDC_STATIC_RUNS);
313
CStatic *statErrors = (CStatic *)GetDlgItem (IDC_STATIC_ERRORS);
314
CStatic *statFailures = (CStatic *)GetDlgItem (IDC_STATIC_FAILURES);
315
CEdit *editTime = (CEdit *)GetDlgItem (IDC_EDIT_TIME);
317
CString argumentString;
319
argumentString.Format ("%d", _testsRun);
320
statTestsRun ->SetWindowText (argumentString);
322
argumentString.Format ("%d", _errors);
323
statErrors ->SetWindowText (argumentString);
325
argumentString.Format ("%d", _failures);
326
statFailures ->SetWindowText (argumentString);
328
argumentString.Format ("Execution time: %3.3lf seconds", (_testEndTime - _testStartTime) / 1000.0);
329
editTime ->SetWindowText (argumentString);
335
void TestRunnerDlg::OnStop()
345
void TestRunnerDlg::OnOK()
354
void TestRunnerDlg::OnSelchangeComboTest()
356
CComboBox *testsSelection = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
358
int currentSelection = testsSelection->GetCurSel ();
360
if (currentSelection >= 0 && currentSelection < _tests.size ())
362
_selectedTest = (_tests.begin () + currentSelection)->pTest;
364
CWinApp* pApp = AfxGetApp();
365
pApp->WriteProfileString("Tests", "lastTest", _selectedTest->toString().c_str());
380
void TestRunnerDlg::OnBnClickedAutorun()
382
CButton *autoRunBtn = (CButton *)GetDlgItem (IDC_CHK_AUTORUN);
383
CWinApp* pApp = AfxGetApp();
384
pApp->WriteProfileInt("Tests", "autoRun", autoRunBtn->GetCheck());
388
void TestRunnerDlg::OnPaint()
392
_testsProgress->paint (dc);
396
void TestRunnerDlg::setTests(const std::vector<Test*>& tests)
399
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
406
void TestRunnerDlg::addTest(Test* pTest, int level)
411
_tests.push_back(ti);
412
TestSuite* pSuite = dynamic_cast<TestSuite*>(pTest);
415
const std::vector<Test*>& tests = pSuite->tests();
416
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
418
addTest(*it, level + 1);
424
} // namespace CppUnit