~ubuntu-branches/ubuntu/oneiric/squid3/oneiric-security

« back to all changes in this revision

Viewing changes to lib/cppunit-1.10.0/src/msvc6/testrunner/TestRunnerDlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2007-05-13 16:03:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070513160316-2h6kn6h1z0q1fvyo
Tags: 3.0.PRE6-1
* New upstream release
  - Removed patches integrated upsteam:
    + 04-m68k-ftbfs

* debian/rules
  - Enable delay pools (Closes: #410785)
  - Enable cache digests (Closes: #416631)
  - Enable ICAP client
  - Raised Max Filedescriptor limit to 65536

* debian/control
  - Added real package dependency for httpd in squid3-cgi

* debian/patches/02-makefile-defaults
  - Fix default configuration file for cachemgr.cgi (Closes: #416630)

* debian/squid3.postinst
  - Fixed bashish in postinst (Closes: #411797)

* debian/patches/05-helpers-typo
  - Added upstream patch fixing compilation error in src/helpers.cc

* debian/patches/06-mem-obj-reference
  - Added upstream patch fixing a mem_obj reference in src/store.cc

* debian/patches/07-close-icap-connections
  - Added upstream patch fixing icap connection starvation

* debian/squid3.rc
  - Added LSB-compliant description to rc script

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// TestRunnerDlg.cpp : implementation file
2
 
//
3
 
 
4
 
#include "stdafx.h"
5
 
#include "mmsystem.h"
6
 
#include "TestRunnerApp.h"
7
 
#include "TestRunnerDlg.h"
8
 
#include "Resource.h"
9
 
#include "ActiveTest.h"
10
 
#include "ProgressBar.h"
11
 
#include "TreeHierarchyDlg.h"
12
 
#include "ListCtrlFormatter.h"
13
 
#include "ListCtrlSetter.h"
14
 
#include "MfcSynchronizationObject.h"
15
 
#include "ResourceLoaders.h"
16
 
#include <cppunit/TestFailure.h>
17
 
 
18
 
#ifdef _DEBUG
19
 
#define new DEBUG_NEW
20
 
#undef THIS_FILE
21
 
static char THIS_FILE[] = __FILE__;
22
 
#endif
23
 
 
24
 
/* Notes:
25
 
 - code duplication between OnOK() and OnQuitApplication()
26
 
 - the threading need to be rewrite, so that GUI update occures in the original
27
 
 thread, not in the thread that is running the tests. This slow down the time
28
 
 needed to run the test much...
29
 
 */
30
 
 
31
 
 
32
 
/////////////////////////////////////////////////////////////////////////////
33
 
// TestRunnerDlg dialog
34
 
 
35
 
const CString TestRunnerDlg::ms_cppunitKey( "CppUnit" );
36
 
 
37
 
 
38
 
TestRunnerDlg::TestRunnerDlg( TestRunnerModel *model,
39
 
                              int nDialogResourceId,
40
 
                              CWnd* pParent )
41
 
    : cdxCDynamicDialog( nDialogResourceId, pParent )
42
 
{
43
 
  ASSERT(0); // this constructor should not be used because of possible resource problems
44
 
             // => use the constructor with the string parameter
45
 
  init(model);
46
 
}
47
 
 
48
 
TestRunnerDlg::TestRunnerDlg( TestRunnerModel *model,
49
 
                              const TCHAR* szDialogResourceId,
50
 
                              CWnd* pParent )
51
 
    : cdxCDynamicDialog( szDialogResourceId == NULL ? 
52
 
                                _T("CPP_UNIT_TEST_RUNNER_IDD_DIALOG_TESTRUNNER")
53
 
                              : szDialogResourceId, 
54
 
                         pParent)
55
 
{
56
 
  init(model);
57
 
}
58
 
 
59
 
void
60
 
TestRunnerDlg::init(TestRunnerModel *model)
61
 
{
62
 
  m_model = model;
63
 
 
64
 
  //{{AFX_DATA_INIT(TestRunnerDlg)
65
 
    m_bAutorunAtStartup = FALSE;
66
 
  //}}AFX_DATA_INIT
67
 
 
68
 
  m_testsProgress     = 0;
69
 
  m_selectedTest      = 0;
70
 
  m_bAutorunAtStartup = true;
71
 
  m_bIsRunning = false;
72
 
 
73
 
  ModifyFlags( flSWPCopyBits, 0 );      // anti-flickering option for resizing
74
 
}
75
 
 
76
 
void 
77
 
TestRunnerDlg::DoDataExchange(CDataExchange* pDX)
78
 
{
79
 
  cdxCDynamicDialog::DoDataExchange(pDX);
80
 
  //{{AFX_DATA_MAP(TestRunnerDlg)
81
 
    DDX_Control(pDX, IDC_DETAILS, m_details);
82
 
    DDX_Control(pDX, IDC_LIST, m_listCtrl);
83
 
    DDX_Control(pDX, IDOK, m_buttonClose);
84
 
    DDX_Control(pDX, ID_STOP, m_buttonStop);
85
 
    DDX_Control(pDX, ID_RUN, m_buttonRun);
86
 
    DDX_Control(pDX, IDC_BROWSE_TEST, m_buttonBrowse);
87
 
    DDX_Check(pDX, IDC_CHECK_AUTORUN, m_bAutorunAtStartup);
88
 
        //}}AFX_DATA_MAP
89
 
}
90
 
 
91
 
 
92
 
BEGIN_MESSAGE_MAP(TestRunnerDlg, cdxCDynamicDialog)
93
 
  //{{AFX_MSG_MAP(TestRunnerDlg)
94
 
  ON_BN_CLICKED(ID_RUN, OnRun)
95
 
  ON_BN_CLICKED(ID_STOP, OnStop)
96
 
  ON_BN_CLICKED(IDC_BROWSE_TEST, OnBrowseTest)
97
 
  ON_COMMAND(ID_QUIT_APPLICATION, OnQuitApplication)
98
 
  ON_WM_CLOSE()
99
 
        ON_WM_SIZE()
100
 
        ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnSelectedFailureChange)
101
 
        ON_CBN_SELCHANGE(IDC_COMBO_TEST, OnSelectTestInHistoryCombo)
102
 
        //}}AFX_MSG_MAP
103
 
END_MESSAGE_MAP()
104
 
 
105
 
/////////////////////////////////////////////////////////////////////////////
106
 
// TestRunnerDlg message handlers
107
 
 
108
 
BOOL 
109
 
TestRunnerDlg::OnInitDialog() 
110
 
{
111
 
  cdxCDynamicDialog::OnInitDialog();
112
 
 
113
 
#ifdef CPPUNIT_SUBCLASSING_TESTRUNNERDLG_BUILD
114
 
  m_hAccelerator = ::LoadAccelerators( AfxGetResourceHandle(),
115
 
#else
116
 
  m_hAccelerator = ::LoadAccelerators( g_testRunnerResource,
117
 
#endif
118
 
                                       MAKEINTRESOURCE( IDR_ACCELERATOR_TEST_RUNNER ) );
119
 
// It always fails!!! I don't understand why. Complain about not finding the resource name!
120
 
  ASSERT( m_hAccelerator !=NULL );
121
 
  
122
 
  CComboBox   *comboBox = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
123
 
 
124
 
  ASSERT (comboBox);
125
 
 
126
 
  VERIFY( m_errorListBitmap.Create( _T("CPP_UNIT_TEST_RUNNER_IDB_ERROR_TYPE"), 
127
 
                                    16, 1, 
128
 
                                    RGB( 255,0,255 ) ) );
129
 
 
130
 
  m_testsProgress = new ProgressBar();
131
 
  m_testsProgress->Create( NULL, NULL, WS_CHILD, CRect(), this, 0 );
132
 
  m_testsProgress->ShowWindow( SW_SHOW );
133
 
  m_testsProgress->MoveWindow( getItemClientRect( IDC_STATIC_PROGRESS_BAR ) );
134
 
 
135
 
  initializeLayout();
136
 
  loadSettings();
137
 
  initializeFixedSizeFont();
138
 
  m_details.SetFont( &m_fixedSizeFont );  // Does not work. Need to investigate...
139
 
      
140
 
  m_listCtrl.SetImageList( &m_errorListBitmap, LVSIL_SMALL );
141
 
  m_listCtrl.SetExtendedStyle( m_listCtrl.GetExtendedStyle() | LVS_EX_FULLROWSELECT );
142
 
 
143
 
  int total_col_1_4 = m_settings.col_1 + m_settings.col_2 + 
144
 
                      m_settings.col_3 + m_settings.col_4;
145
 
 
146
 
  CRect listBounds;
147
 
  m_listCtrl.GetClientRect(&listBounds);
148
 
  int col_5_width = listBounds.Width() - total_col_1_4; // 5th column = rest of listview space
149
 
  ListCtrlFormatter formatter( m_listCtrl );
150
 
  formatter.AddColumn( loadCString(IDS_ERRORLIST_TYPE), m_settings.col_1, LVCFMT_LEFT, 0 );
151
 
  formatter.AddColumn( loadCString(IDS_ERRORLIST_NAME), m_settings.col_2, LVCFMT_LEFT, 1 );
152
 
  formatter.AddColumn( loadCString(IDS_ERRORLIST_FAILED_CONDITION), m_settings.col_3, LVCFMT_LEFT, 2 );
153
 
  m_listCtrl.setLineNumberSubItem( formatter.GetNextColumnIndex() );
154
 
  formatter.AddColumn( loadCString(IDS_ERRORLIST_LINE_NUMBER), m_settings.col_4, LVCFMT_LEFT, 3 );
155
 
  m_listCtrl.setFileNameSubItem( formatter.GetNextColumnIndex() );
156
 
  formatter.AddColumn( loadCString(IDS_ERRORLIST_FILE_NAME), col_5_width, LVCFMT_LEFT, 4 );
157
 
 
158
 
  reset ();
159
 
  updateHistoryCombo();
160
 
  UpdateData( FALSE );
161
 
 
162
 
  updateListColumnSize();
163
 
 
164
 
  m_buttonRun.SetFocus();
165
 
 
166
 
  if ( m_bAutorunAtStartup )
167
 
    OnRun();
168
 
  
169
 
  return FALSE;  // return TRUE unless you set the focus to a control
170
 
                 // EXCEPTION: OCX Property Pages should return FALSE
171
 
}
172
 
 
173
 
 
174
 
TestRunnerDlg::~TestRunnerDlg()
175
 
176
 
  freeState();
177
 
  delete m_testsProgress;
178
 
}
179
 
 
180
 
 
181
 
void 
182
 
TestRunnerDlg::OnRun() 
183
 
{
184
 
  if ( m_bIsRunning )
185
 
    return;
186
 
 
187
 
  m_selectedTest = m_model->selectedTest();
188
 
 
189
 
  if ( m_selectedTest == 0 )
190
 
    return;
191
 
 
192
 
  freeState(); 
193
 
  reset();
194
 
 
195
 
  beRunning();
196
 
 
197
 
  int numberOfTests = m_selectedTest->countTestCases();
198
 
 
199
 
  m_testsProgress->start( numberOfTests );
200
 
 
201
 
  
202
 
  m_result = new CPPUNIT_NS::TestResultCollector( new MfcSynchronizationObject() );
203
 
  m_testObserver = new CPPUNIT_NS::TestResult( new MfcSynchronizationObject() );
204
 
  m_testObserver->addListener( m_result );
205
 
  m_testObserver->addListener( this );
206
 
  m_activeTest = new ActiveTest( m_selectedTest );
207
 
 
208
 
  m_testStartTime = timeGetTime();
209
 
 
210
 
  m_activeTest->run( m_testObserver );
211
 
 
212
 
  m_testEndTime = timeGetTime();
213
 
}
214
 
 
215
 
 
216
 
void 
217
 
TestRunnerDlg::addListEntry( const CPPUNIT_NS::TestFailure &failure )
218
 
{
219
 
  CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
220
 
  int currentEntry = m_result->testErrors() + 
221
 
                     m_result->testFailures() -1;
222
 
 
223
 
  ErrorTypeBitmaps errorType;
224
 
  if ( failure.isError() )
225
 
    errorType = errorTypeError;
226
 
  else
227
 
    errorType = errorTypeFailure;
228
 
 
229
 
  ListCtrlSetter setter( *listCtrl );
230
 
  setter.insertLine( currentEntry );
231
 
  setter.addSubItem( failure.isError() ? _T("Error") : _T("Failure"), errorType );
232
 
 
233
 
  // Set test name
234
 
  setter.addSubItem( failure.failedTestName().c_str(), errorType );
235
 
 
236
 
  // Set the asserted text
237
 
  CString message( failure.thrownException()->message().shortDescription().c_str() );
238
 
  message.Replace( '\n', ' ' );   // should only print the short description there,
239
 
  setter.addSubItem( message );   // and dump the detail on an edit control when clicked.
240
 
 
241
 
  // Set the line number
242
 
  if ( failure.sourceLine().isValid() )
243
 
  {
244
 
    CString lineNumber;
245
 
    lineNumber.Format( _T("%ld"), failure.sourceLine().lineNumber() );
246
 
    setter.addSubItem( lineNumber );
247
 
  }
248
 
  else
249
 
    setter.addSubItem( _T("") );
250
 
 
251
 
  // Set the file name
252
 
  setter.addSubItem( failure.sourceLine().fileName().c_str() );
253
 
 
254
 
  if ( !listCtrl->GetFirstSelectedItemPosition() )
255
 
  {
256
 
    // Select first entry => display details of first entry.
257
 
    listCtrl->SetItemState( currentEntry, LVIS_SELECTED, LVIS_SELECTED );
258
 
    listCtrl->SetFocus();   // Does not work ?!?
259
 
  }
260
 
 
261
 
  listCtrl->RedrawItems( currentEntry, currentEntry );
262
 
  listCtrl->UpdateWindow();
263
 
}
264
 
 
265
 
 
266
 
void 
267
 
TestRunnerDlg::startTest( CPPUNIT_NS::Test *test )
268
 
{
269
 
  CWnd *runningTestCaseLabel = GetDlgItem(IDC_RUNNING_TEST_CASE_LABEL);
270
 
  if ( runningTestCaseLabel )
271
 
    runningTestCaseLabel->SetWindowText( CString( test->getName().c_str() ) );
272
 
}
273
 
 
274
 
 
275
 
void 
276
 
TestRunnerDlg::addFailure( const CPPUNIT_NS::TestFailure &failure )
277
 
{
278
 
  addListEntry( failure );
279
 
  if ( failure.isError() )
280
 
    m_errors++;
281
 
  else
282
 
    m_failures++;
283
 
 
284
 
  updateCountsDisplay();
285
 
}
286
 
 
287
 
 
288
 
void 
289
 
TestRunnerDlg::endTest( CPPUNIT_NS::Test *test )
290
 
{
291
 
  if ( m_selectedTest == 0 )
292
 
    return;
293
 
 
294
 
  m_testsRun++;
295
 
  updateCountsDisplay();
296
 
  m_testsProgress->step( m_failures == 0  &&  m_errors == 0 );
297
 
 
298
 
  m_testEndTime = timeGetTime();
299
 
 
300
 
  updateCountsDisplay();
301
 
 
302
 
  if ( m_testsRun >= m_selectedTest->countTestCases() )
303
 
    beIdle ();
304
 
}
305
 
 
306
 
 
307
 
void 
308
 
TestRunnerDlg::beRunning()
309
 
{
310
 
  m_bIsRunning = true;
311
 
  m_buttonRun.EnableWindow( FALSE );
312
 
  m_buttonClose.EnableWindow( FALSE );
313
 
  m_buttonBrowse.EnableWindow( FALSE );
314
 
 
315
 
//    m_buttonRun.SetButtonStyle( m_buttonRun.GetButtonStyle() & ~BS_DEFPUSHBUTTON );
316
 
//    m_buttonStop.SetButtonStyle( m_buttonStop.GetButtonStyle() | BS_DEFPUSHBUTTON );
317
 
}
318
 
 
319
 
 
320
 
void 
321
 
TestRunnerDlg::beIdle()
322
 
{
323
 
  m_bIsRunning = false;
324
 
  m_buttonRun.EnableWindow( TRUE );
325
 
  m_buttonBrowse.EnableWindow( TRUE );
326
 
  m_buttonClose.EnableWindow( TRUE );
327
 
 
328
 
  m_buttonRun.SetButtonStyle( m_buttonRun.GetButtonStyle() | BS_DEFPUSHBUTTON );
329
 
//    m_buttonStop.SetButtonStyle( m_buttonStop.GetButtonStyle() & ~BS_DEFPUSHBUTTON );
330
 
}
331
 
 
332
 
 
333
 
void 
334
 
TestRunnerDlg::beRunDisabled()
335
 
{
336
 
  m_bIsRunning = false;
337
 
  m_buttonRun.EnableWindow( FALSE );
338
 
  m_buttonBrowse.EnableWindow( FALSE );
339
 
  m_buttonStop.EnableWindow( FALSE );
340
 
  m_buttonClose.EnableWindow( TRUE );
341
 
 
342
 
//    m_buttonRun.SetButtonStyle( m_buttonRun.GetButtonStyle() | BS_DEFPUSHBUTTON );
343
 
//    m_buttonStop.SetButtonStyle( m_buttonStop.GetButtonStyle() & ~BS_DEFPUSHBUTTON );
344
 
}
345
 
 
346
 
 
347
 
void 
348
 
TestRunnerDlg::freeState()
349
 
{
350
 
  delete m_activeTest;
351
 
  delete m_result;
352
 
  delete m_testObserver;
353
 
}
354
 
 
355
 
 
356
 
void 
357
 
TestRunnerDlg::reset()
358
 
{
359
 
  m_testsRun = 0;
360
 
  m_errors = 0;
361
 
  m_failures = 0;
362
 
  m_testEndTime = m_testStartTime;
363
 
 
364
 
  updateCountsDisplay();
365
 
 
366
 
  m_activeTest = NULL;
367
 
  m_result = NULL;
368
 
  m_testObserver = NULL;
369
 
 
370
 
  CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
371
 
 
372
 
  listCtrl->DeleteAllItems();
373
 
  m_testsProgress->reset();
374
 
  displayFailureDetailsFor( -1 );
375
 
}
376
 
 
377
 
 
378
 
void 
379
 
TestRunnerDlg::updateCountsDisplay()
380
 
{
381
 
  CStatic *statTestsRun = (CStatic *)GetDlgItem( IDC_STATIC_RUNS );
382
 
  CStatic *statErrors = (CStatic *)GetDlgItem( IDC_STATIC_ERRORS );
383
 
  CStatic *statFailures = (CStatic *)GetDlgItem( IDC_STATIC_FAILURES );
384
 
  CEdit *editTime = (CEdit *)GetDlgItem( IDC_EDIT_TIME );
385
 
 
386
 
  CString argumentString;
387
 
 
388
 
  argumentString.Format( _T("%d"), m_testsRun );
389
 
  statTestsRun->SetWindowText (argumentString);
390
 
 
391
 
  argumentString.Format( _T("%d"), m_errors );
392
 
  statErrors->SetWindowText( argumentString );
393
 
 
394
 
  argumentString.Format( _T("%d"), m_failures );
395
 
  statFailures->SetWindowText( argumentString );
396
 
 
397
 
  argumentString.Format( _T("Execution time: %3.3lf seconds"), 
398
 
                         (m_testEndTime - m_testStartTime) / 1000.0 );
399
 
  editTime->SetWindowText( argumentString );
400
 
}
401
 
 
402
 
 
403
 
void 
404
 
TestRunnerDlg::OnStop() 
405
 
{
406
 
  if ( m_testObserver )
407
 
    m_testObserver->stop ();
408
 
 
409
 
  beIdle ();
410
 
}
411
 
 
412
 
 
413
 
void 
414
 
TestRunnerDlg::OnOK() 
415
 
{
416
 
  if ( m_testObserver )
417
 
    m_testObserver->stop ();
418
 
 
419
 
  UpdateData();
420
 
  saveSettings();
421
 
 
422
 
  cdxCDynamicDialog::OnOK ();
423
 
}
424
 
 
425
 
 
426
 
void 
427
 
TestRunnerDlg::OnSelectTestInHistoryCombo() 
428
 
{
429
 
  unsigned int currentSelection = getHistoryCombo()->GetCurSel ();
430
 
 
431
 
  if ( currentSelection >= 0  &&
432
 
       currentSelection < m_model->history().size() )
433
 
  {
434
 
    CPPUNIT_NS::Test *selectedTest = m_model->history()[currentSelection];
435
 
    m_model->selectHistoryTest( selectedTest );
436
 
    updateHistoryCombo();
437
 
    beIdle();
438
 
  }
439
 
  else
440
 
    beRunDisabled();
441
 
}
442
 
 
443
 
 
444
 
void
445
 
TestRunnerDlg::updateHistoryCombo()
446
 
{
447
 
  getHistoryCombo()->LockWindowUpdate();
448
 
 
449
 
  getHistoryCombo()->ResetContent();
450
 
 
451
 
  const TestRunnerModel::History &history = m_model->history();
452
 
  for ( TestRunnerModel::History::const_iterator it = history.begin(); 
453
 
        it != history.end(); 
454
 
        ++it )
455
 
  {
456
 
    CPPUNIT_NS::Test *test = *it;
457
 
    getHistoryCombo()->AddString( CString(test->getName().c_str()) );
458
 
  }
459
 
 
460
 
  if ( history.size() > 0 )
461
 
  {
462
 
    getHistoryCombo()->SetCurSel( 0 );
463
 
    beIdle();
464
 
  }
465
 
  else
466
 
  {
467
 
    beRunDisabled();
468
 
    m_buttonBrowse.EnableWindow( TRUE );
469
 
        }
470
 
 
471
 
  getHistoryCombo()->UnlockWindowUpdate();
472
 
}
473
 
 
474
 
 
475
 
void 
476
 
TestRunnerDlg::OnBrowseTest() 
477
 
{
478
 
  TreeHierarchyDlg dlg;
479
 
  dlg.setRootTest( m_model->rootTest() );
480
 
  if ( dlg.DoModal() == IDOK )
481
 
  {
482
 
    m_model->selectHistoryTest( dlg.getSelectedTest() );
483
 
    updateHistoryCombo();
484
 
  }
485
 
}
486
 
 
487
 
 
488
 
BOOL 
489
 
TestRunnerDlg::PreTranslateMessage(MSG* pMsg) 
490
 
{
491
 
  if ( ::TranslateAccelerator( m_hWnd,
492
 
                               m_hAccelerator,
493
 
                               pMsg ) )
494
 
  {
495
 
    return TRUE;
496
 
  }
497
 
  return cdxCDynamicDialog::PreTranslateMessage(pMsg);
498
 
}
499
 
 
500
 
 
501
 
CComboBox *
502
 
TestRunnerDlg::getHistoryCombo()
503
 
{
504
 
  CComboBox   *comboBox = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
505
 
  ASSERT (comboBox);
506
 
  return comboBox;
507
 
}
508
 
 
509
 
 
510
 
void
511
 
TestRunnerDlg::loadSettings()
512
 
{
513
 
  m_model->loadSettings(m_settings);
514
 
  RestoreWindowPosition( TestRunnerModel::settingKey, 
515
 
                         TestRunnerModel::settingMainDialogKey );
516
 
 
517
 
 
518
 
  m_bAutorunAtStartup = m_settings.autorunOnLaunch;
519
 
}
520
 
 
521
 
 
522
 
void
523
 
TestRunnerDlg::saveSettings()
524
 
{
525
 
  m_settings.autorunOnLaunch = ( m_bAutorunAtStartup != 0 );
526
 
  StoreWindowPosition( TestRunnerModel::settingKey, 
527
 
                       TestRunnerModel::settingMainDialogKey );
528
 
  
529
 
  m_settings.col_1 = m_listCtrl.GetColumnWidth(0);
530
 
  m_settings.col_2 = m_listCtrl.GetColumnWidth(1);
531
 
  m_settings.col_3 = m_listCtrl.GetColumnWidth(2);
532
 
  m_settings.col_4 = m_listCtrl.GetColumnWidth(3);
533
 
 
534
 
  m_model->saveSettings(m_settings);
535
 
}
536
 
 
537
 
 
538
 
void 
539
 
TestRunnerDlg::OnQuitApplication() 
540
 
{
541
 
  if ( m_testObserver )
542
 
    m_testObserver->stop();
543
 
 
544
 
  UpdateData();
545
 
  saveSettings();
546
 
  
547
 
  CWinApp *app = AfxGetApp();
548
 
  ASSERT( app != NULL );
549
 
  app->PostThreadMessage( WM_QUIT, 0, 0 );
550
 
}
551
 
 
552
 
 
553
 
TestRunnerModel &
554
 
TestRunnerDlg::model()
555
 
{
556
 
  ASSERT( m_model != NULL );
557
 
  return *m_model;
558
 
}
559
 
 
560
 
 
561
 
void 
562
 
TestRunnerDlg::OnClose() 
563
 
{
564
 
        OnOK();
565
 
}
566
 
 
567
 
 
568
 
CRect 
569
 
TestRunnerDlg::getItemWindowRect( unsigned int itemId )
570
 
{
571
 
  CWnd * pItem = GetDlgItem( itemId );
572
 
  CRect rect;
573
 
  if ( pItem )
574
 
    pItem->GetWindowRect( &rect );
575
 
  return rect;
576
 
}
577
 
 
578
 
 
579
 
CRect 
580
 
TestRunnerDlg::getItemClientRect( unsigned int itemId )
581
 
{
582
 
  CRect rect = getItemWindowRect( itemId );
583
 
  if ( !rect.IsRectNull() )
584
 
  {
585
 
    CPoint clientTopLeft = rect.TopLeft();
586
 
    ScreenToClient( &clientTopLeft );
587
 
    rect = CRect( clientTopLeft, rect.Size() );
588
 
  }
589
 
 
590
 
  return rect;
591
 
}
592
 
 
593
 
 
594
 
void 
595
 
TestRunnerDlg::initializeLayout()
596
 
{
597
 
  // see DynamicWindow/doc for documentation
598
 
  const int listGrowthRatio = 30;
599
 
  AddSzXControl( IDC_COMBO_TEST, mdResize );
600
 
  AddSzXControl( IDC_BROWSE_TEST, mdRepos );
601
 
  AddSzXControl( IDC_RUNNING_TEST_CASE_LABEL, mdResize );
602
 
  AddSzXControl( ID_RUN, mdRepos );
603
 
  AddSzXControl( *m_testsProgress, mdResize );
604
 
  AddSzXControl( IDC_CHECK_AUTORUN, mdRepos );
605
 
  AddSzControl( IDC_LIST, 0, 0, 100, listGrowthRatio );
606
 
  AddSzXControl( ID_STOP, mdRepos );
607
 
  AddSzXControl( IDOK, mdRepos );
608
 
  AddSzYControl( IDC_STATIC_DETAILS, listGrowthRatio, listGrowthRatio );
609
 
  AddSzControl( IDC_DETAILS, 0, listGrowthRatio, 100, 100 );
610
 
  AddSzControl( IDC_EDIT_TIME, mdResize, mdRepos );
611
 
}
612
 
 
613
 
 
614
 
void 
615
 
TestRunnerDlg::OnSize( UINT nType, int cx, int cy ) 
616
 
{
617
 
        cdxCDynamicDialog::OnSize(nType, cx, cy);
618
 
        updateListColumnSize();
619
 
}
620
 
 
621
 
 
622
 
void 
623
 
TestRunnerDlg::updateListColumnSize()
624
 
{
625
 
  if ( !m_listCtrl.GetSafeHwnd() )
626
 
    return;
627
 
 
628
 
  // resize to fit last column
629
 
  CRect listBounds = getItemClientRect( IDC_LIST );
630
 
  
631
 
  int width_1_4 = 0;
632
 
  for (int i = 0; i < 4; ++i)
633
 
    width_1_4 += m_listCtrl.GetColumnWidth( i );
634
 
  
635
 
  // the 4 offset is so no horiz scroll bar will appear
636
 
  m_listCtrl.SetColumnWidth(4, listBounds.Width() - width_1_4 - 4); 
637
 
}
638
 
 
639
 
 
640
 
void 
641
 
TestRunnerDlg::OnSelectedFailureChange( NMHDR* pNMHDR, 
642
 
                                        LRESULT* pResult )
643
 
{
644
 
        NM_LISTVIEW *pNMListView = (NM_LISTVIEW*)pNMHDR;
645
 
 
646
 
  if ( (pNMListView->uNewState & LVIS_SELECTED) != 0 )  // item selected
647
 
    displayFailureDetailsFor( pNMListView->iItem );
648
 
        
649
 
        *pResult = 0;
650
 
}
651
 
 
652
 
 
653
 
void 
654
 
TestRunnerDlg::displayFailureDetailsFor( unsigned int failureIndex )
655
 
{
656
 
  CString details;
657
 
  if ( m_result  &&  failureIndex < m_result->failures().size() )
658
 
    details = m_result->failures()[ failureIndex ]->thrownException()->what();
659
 
 
660
 
  details.Replace( _T("\n"), _T("\r\n") );
661
 
 
662
 
  m_details.SetWindowText( details );
663
 
}
664
 
 
665
 
 
666
 
void 
667
 
TestRunnerDlg::initializeFixedSizeFont()
668
 
{
669
 
  LOGFONT font;
670
 
  GetFont()->GetLogFont( &font );
671
 
  font.lfPitchAndFamily = FIXED_PITCH | //VARIABLE_PITCH
672
 
                          (font.lfPitchAndFamily & ~15);   // font family
673
 
  m_fixedSizeFont.CreateFontIndirect( &font );
674
 
}