~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// TreeHierarchyDlg.cpp : implementation file
 
2
//
 
3
 
 
4
#include "stdafx.h"
 
5
#include "resource.h"
 
6
#include "TreeHierarchyDlg.h"
 
7
#include "TestRunnerModel.h"
 
8
#include "ResourceLoaders.h"
 
9
#include <algorithm>
 
10
 
 
11
 
 
12
#ifdef _DEBUG
 
13
#define new DEBUG_NEW
 
14
#undef THIS_FILE
 
15
static char THIS_FILE[] = __FILE__;
 
16
#endif
 
17
 
 
18
/////////////////////////////////////////////////////////////////////////////
 
19
// TreeHierarchyDlg dialog
 
20
 
 
21
 
 
22
TreeHierarchyDlg::TreeHierarchyDlg(CWnd* pParent )
 
23
        : cdxCDynamicDialog(_T("CPP_UNIT_TEST_RUNNER_IDD_DIALOG_TEST_HIERARCHY"), pParent)
 
24
  , m_selectedTest( NULL )
 
25
{
 
26
  ModifyFlags( flSWPCopyBits, 0 );      // anti-flickering option for resizing
 
27
 
 
28
        //{{AFX_DATA_INIT(TreeHierarchyDlg)
 
29
                // NOTE: the ClassWizard will add member initialization here
 
30
        //}}AFX_DATA_INIT
 
31
}
 
32
 
 
33
 
 
34
void 
 
35
TreeHierarchyDlg::DoDataExchange(CDataExchange* pDX)
 
36
{
 
37
        cdxCDynamicDialog::DoDataExchange(pDX);
 
38
        //{{AFX_DATA_MAP(TreeHierarchyDlg)
 
39
        DDX_Control(pDX, IDC_TREE_TEST, m_treeTests);
 
40
        //}}AFX_DATA_MAP
 
41
}
 
42
 
 
43
 
 
44
BEGIN_MESSAGE_MAP(TreeHierarchyDlg, cdxCDynamicDialog)
 
45
        //{{AFX_MSG_MAP(TreeHierarchyDlg)
 
46
        //}}AFX_MSG_MAP
 
47
END_MESSAGE_MAP()
 
48
 
 
49
 
 
50
 
 
51
void 
 
52
TreeHierarchyDlg::setRootTest( CPPUNIT_NS::Test *test )
 
53
{
 
54
  m_rootTest = test;
 
55
}
 
56
 
 
57
 
 
58
BOOL 
 
59
TreeHierarchyDlg::OnInitDialog() 
 
60
{
 
61
  cdxCDynamicDialog::OnInitDialog();
 
62
        
 
63
  fillTree();
 
64
  initializeLayout();
 
65
  RestoreWindowPosition( TestRunnerModel::settingKey, 
 
66
                         TestRunnerModel::settingBrowseDialogKey );
 
67
        
 
68
  return TRUE;
 
69
}
 
70
 
 
71
 
 
72
void 
 
73
TreeHierarchyDlg::initializeLayout()
 
74
{
 
75
  // see DynamicWindow/doc for documentation
 
76
  AddSzControl( IDC_TREE_TEST, mdResize, mdResize );
 
77
  AddSzControl( IDOK, mdRepos, mdNone );
 
78
  AddSzControl( IDCANCEL, mdRepos, mdNone );
 
79
}
 
80
 
 
81
 
 
82
void 
 
83
TreeHierarchyDlg::fillTree()
 
84
{
 
85
  VERIFY( m_imageList.Create( _T("CPP_UNIT_TEST_RUNNER_IDB_TEST_TYPE"), 
 
86
                              16, 1, RGB( 255,0,255 ) ) );
 
87
 
 
88
  m_treeTests.SetImageList( &m_imageList, TVSIL_NORMAL );
 
89
 
 
90
  HTREEITEM hSuite = addTest( m_rootTest, TVI_ROOT );
 
91
  m_treeTests.Expand( hSuite, TVE_EXPAND );
 
92
}
 
93
 
 
94
 
 
95
HTREEITEM
 
96
TreeHierarchyDlg::addTest( CPPUNIT_NS::Test *test, 
 
97
                           HTREEITEM hParent )
 
98
{
 
99
  int testType = isSuite( test ) ? imgSuite : imgUnitTest;
 
100
  HTREEITEM hItem = m_treeTests.InsertItem( CString(test->getName().c_str()),
 
101
                                            testType,
 
102
                                            testType,
 
103
                                            hParent );
 
104
  if ( hItem != NULL )
 
105
  {
 
106
    VERIFY( m_treeTests.SetItemData( hItem, (DWORD)test ) );
 
107
    if ( isSuite( test ) )
 
108
      addTestSuiteChildrenTo( test, hItem );
 
109
  }
 
110
  return hItem;
 
111
}
 
112
 
 
113
 
 
114
void 
 
115
TreeHierarchyDlg::addTestSuiteChildrenTo( CPPUNIT_NS::Test *suite,
 
116
                                          HTREEITEM hItemSuite )
 
117
{
 
118
  Tests tests;
 
119
  int childIndex = 0;
 
120
  for ( ; childIndex < suite->getChildTestCount(); ++childIndex )
 
121
    tests.push_back( suite->getChildTestAt( childIndex ) );
 
122
  sortByName( tests );
 
123
 
 
124
  for ( childIndex = 0; childIndex < suite->getChildTestCount(); ++childIndex )
 
125
    addTest( suite->getChildTestAt( childIndex ), hItemSuite );
 
126
}
 
127
 
 
128
 
 
129
bool 
 
130
TreeHierarchyDlg::isSuite( CPPUNIT_NS::Test *test )
 
131
{
 
132
  return ( test->getChildTestCount() > 0  ||    // suite with test
 
133
           test->countTestCases() == 0 );       // empty suite
 
134
}
 
135
 
 
136
 
 
137
struct PredSortTest
 
138
{
 
139
  bool operator()( CPPUNIT_NS::Test *test1, CPPUNIT_NS::Test *test2 ) const
 
140
  {
 
141
    bool isTest1Suite = TreeHierarchyDlg::isSuite( test1 );
 
142
    bool isTest2Suite = TreeHierarchyDlg::isSuite( test2 );
 
143
    if ( isTest1Suite  &&  !isTest2Suite )
 
144
      return true;
 
145
    if ( isTest1Suite  &&  isTest2Suite )
 
146
      return test1->getName() < test2->getName();
 
147
    return false;
 
148
  }
 
149
};
 
150
 
 
151
void 
 
152
TreeHierarchyDlg::sortByName( Tests &tests ) const
 
153
{
 
154
  std::stable_sort( tests.begin(), tests.end(), PredSortTest() );
 
155
}
 
156
 
 
157
 
 
158
void 
 
159
TreeHierarchyDlg::OnOK() 
 
160
{
 
161
  CPPUNIT_NS::Test *test = findSelectedTest();
 
162
  if ( test == NULL )
 
163
  {
 
164
    AfxMessageBox( loadCString(IDS_ERROR_SELECT_TEST), MB_OK );
 
165
    return;
 
166
  }
 
167
 
 
168
  m_selectedTest = test;
 
169
  storeDialogBounds();
 
170
  cdxCDynamicDialog::OnOK();
 
171
}
 
172
 
 
173
 
 
174
void 
 
175
TreeHierarchyDlg::OnCancel() 
 
176
{
 
177
  storeDialogBounds();
 
178
        cdxCDynamicDialog::OnCancel();
 
179
}
 
180
 
 
181
 
 
182
CPPUNIT_NS::Test *
 
183
TreeHierarchyDlg::findSelectedTest()
 
184
{
 
185
  HTREEITEM hItem = m_treeTests.GetSelectedItem();
 
186
  if ( hItem != NULL )
 
187
  {
 
188
    DWORD data;
 
189
    VERIFY( data = m_treeTests.GetItemData( hItem ) );
 
190
    return reinterpret_cast<CPPUNIT_NS::Test *>( data );
 
191
  }
 
192
  return NULL;
 
193
}
 
194
 
 
195
 
 
196
CPPUNIT_NS::Test *
 
197
TreeHierarchyDlg::getSelectedTest() const
 
198
{
 
199
  return m_selectedTest;
 
200
}
 
201
 
 
202
 
 
203
void 
 
204
TreeHierarchyDlg::storeDialogBounds()
 
205
{
 
206
  StoreWindowPosition( TestRunnerModel::settingKey, 
 
207
                       TestRunnerModel::settingBrowseDialogKey );
 
208
}