Mercurial > flash_v2
comparison host/tools/testtool/win32/RunTestsSheet.cpp @ 76:435cced73e2f ecos-v1_3_1-release
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
| author | jlarmour |
|---|---|
| date | Tue, 28 Mar 2000 14:10:45 +0000 |
| parents | |
| children | 6736c52df507 |
comparison
equal
deleted
inserted
replaced
| 75:41bf073c0c32 | 76:435cced73e2f |
|---|---|
| 1 //####COPYRIGHTBEGIN#### | |
| 2 // | |
| 3 // ---------------------------------------------------------------------------- | |
| 4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 5 // | |
| 6 // This program is part of the eCos host tools. | |
| 7 // | |
| 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) | |
| 11 // any later version. | |
| 12 // | |
| 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 | |
| 16 // more details. | |
| 17 // | |
| 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. | |
| 21 // | |
| 22 // ---------------------------------------------------------------------------- | |
| 23 // | |
| 24 //####COPYRIGHTEND#### | |
| 25 // RunTestsSheet.cpp : implementation file | |
| 26 // | |
| 27 | |
| 28 #include "stdafx.h" | |
| 29 | |
| 30 #include "eCosTest.h" | |
| 31 #include "eCosTrace.h" | |
| 32 #include "PropertiesDialog.h" | |
| 33 #include "ResetAttributes.h" | |
| 34 #include "RunTestsSheet.h" | |
| 35 #include "TestResource.h" | |
| 36 #include "X10.h" | |
| 37 | |
| 38 #include <afxpriv.h> | |
| 39 | |
| 40 static const UINT arIds []={IDOK,IDCANCEL,ID_APPLY_NOW,IDHELP}; | |
| 41 | |
| 42 | |
| 43 #ifdef _DEBUG | |
| 44 #define new DEBUG_NEW | |
| 45 #undef THIS_FILE | |
| 46 static char THIS_FILE[] = __FILE__; | |
| 47 #endif | |
| 48 | |
| 49 | |
| 50 ///////////////////////////////////////////////////////////////////////////// | |
| 51 // CRunTestsSheet | |
| 52 | |
| 53 IMPLEMENT_DYNAMIC(CRunTestsSheet, CeCosPropertySheet) | |
| 54 | |
| 55 CRunTestsSheet::CRunTestsSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage, CBFunc pInitFunc, CRunTestsSheet **ppSheet) | |
| 56 :CeCosPropertySheet(pszCaption, pParentWnd, iSelectPage), | |
| 57 m_pResource(NULL), | |
| 58 m_pInitFunc(pInitFunc), | |
| 59 m_bAllowResizing(false), | |
| 60 m_cxMin(0), | |
| 61 m_cyMin(0), | |
| 62 m_Status(Stopped), | |
| 63 m_bHideTarget(false), | |
| 64 m_bHideRemoteControls(false), | |
| 65 m_bModal(false), | |
| 66 m_prop(_T("Software\\Red Hat\\eCos\\RunTests"),HKEY_CURRENT_USER), | |
| 67 m_ppSheet(ppSheet), | |
| 68 m_ep(CeCosTest::ExecutionParameters::RUN) | |
| 69 { | |
| 70 InitializeCriticalSection(&m_CS); | |
| 71 AddPage(&executionpage); | |
| 72 AddPage(&outputpage); | |
| 73 AddPage(&summarypage); | |
| 74 | |
| 75 } | |
| 76 | |
| 77 CRunTestsSheet::~CRunTestsSheet() | |
| 78 { | |
| 79 if(m_ppSheet){ | |
| 80 *m_ppSheet=0; | |
| 81 } | |
| 82 delete m_pResource; | |
| 83 DeleteCriticalSection(&m_CS); | |
| 84 } | |
| 85 | |
| 86 | |
| 87 BEGIN_MESSAGE_MAP(CRunTestsSheet, CeCosPropertySheet) | |
| 88 //{{AFX_MSG_MAP(CRunTestsSheet) | |
| 89 ON_BN_CLICKED(IDOK, OnRun) | |
| 90 ON_BN_CLICKED(ID_APPLY_NOW, OnProperties) | |
| 91 ON_BN_CLICKED(IDCANCEL, OnClose) | |
| 92 ON_MESSAGE(WM_TESTOUTPUT, OnTestOutput) | |
| 93 ON_MESSAGE(WM_RUNCOMPLETE, OnTestsComplete) | |
| 94 ON_WM_SYSCOMMAND() | |
| 95 ON_WM_SIZE() | |
| 96 ON_WM_GETMINMAXINFO() | |
| 97 ON_WM_TIMER() | |
| 98 ON_MESSAGE(WM_KICKIDLE, OnKickIdle) | |
| 99 ON_WM_CREATE() | |
| 100 //}}AFX_MSG_MAP | |
| 101 END_MESSAGE_MAP() | |
| 102 | |
| 103 ///////////////////////////////////////////////////////////////////////////// | |
| 104 // CRunTestsSheet message handlers | |
| 105 | |
| 106 BOOL CRunTestsSheet::OnInitDialog() | |
| 107 { | |
| 108 if(!m_bHideTarget){ | |
| 109 m_prop.Add(_T("Platform"),(void *)&m_strTarget,GetFn,PutFn); | |
| 110 } | |
| 111 m_prop.Add(_T("Active timeout"),m_nTimeout,900); | |
| 112 m_prop.Add(_T("Download timeout"),m_nDownloadTimeout,120); | |
| 113 m_prop.Add(_T("Active timeout type"),m_nTimeoutType,TIMEOUT_AUTOMATIC); | |
| 114 m_prop.Add(_T("Download timeout type"),m_nDownloadTimeoutType,TIMEOUT_AUTOMATIC); | |
| 115 m_prop.Add(_T("Remote"),m_bRemote); | |
| 116 m_prop.Add(_T("Serial"),m_bSerial,true); | |
| 117 m_prop.Add(_T("Port"),(void *)&m_strPort,GetFn,PutFn,_T("COM1")); | |
| 118 m_prop.Add(_T("Baud"),m_nBaud,38400); | |
| 119 m_prop.Add(_T("Local TCPIP Host"),(void *)&m_strLocalTCPIPHost,GetFn,PutFn); | |
| 120 m_prop.Add(_T("Local TCPIP Port"),m_nLocalTCPIPPort,1); | |
| 121 m_prop.Add(_T("Reset Type"),m_nReset,RESET_MANUAL); | |
| 122 m_prop.Add(_T("Reset String"),(void *)&m_strReset,GetFn,PutFn); | |
| 123 m_prop.Add(_T("Resource Host"),(void *)&m_strResourceHost,GetFn,PutFn); | |
| 124 m_prop.Add(_T("Resource Port"),m_nResourcePort,1); | |
| 125 m_prop.Add(_T("Remote Host"),(void *)&m_strRemoteHost,GetFn,PutFn); | |
| 126 m_prop.Add(_T("Remote Port"),m_nRemotePort,1); | |
| 127 m_prop.Add(_T("Recurse"),executionpage.m_bRecurse); | |
| 128 //m_prop.Add(_T("Loadfromdir"),executionpage.m_strLoaddir); | |
| 129 m_prop.Add(_T("Farmed"),m_bFarmed,true); | |
| 130 m_prop.Add(_T("Extension"),(void *)&executionpage.m_strExtension,GetFn,PutFn,_T("*.exe")); | |
| 131 m_prop.SetDefaults(); | |
| 132 | |
| 133 CeCosTrace::SetOutput(TestOutputCallback,this); | |
| 134 CeCosTrace::SetError (TestOutputCallback,this); | |
| 135 | |
| 136 // m_psh can only be used to set the small icon. Set the large one here. | |
| 137 m_psh.hIcon=AfxGetApp()->LoadIcon(IDR_TT_MAINFRAME); | |
| 138 //sheet.m_psh.dwFlags|=PSH_USEHICON/*|PSH_HASHELP*/; | |
| 139 if(m_psh.hIcon){ | |
| 140 SetIcon(m_psh.hIcon,FALSE); | |
| 141 SetIcon(m_psh.hIcon,TRUE); | |
| 142 } | |
| 143 GetWindowRect(m_rcPrev); | |
| 144 #ifdef _DEBUG | |
| 145 CeCosTrace::EnableTracing(true); | |
| 146 #endif | |
| 147 CeCosTrace::SetInteractive(true); | |
| 148 | |
| 149 if(m_pInitFunc){ | |
| 150 m_pInitFunc(&m_prop,false); | |
| 151 } | |
| 152 | |
| 153 GetDlgItem(IDCANCEL)->SetWindowText(_T("&Close")); | |
| 154 | |
| 155 m_nTestsToComplete=0; | |
| 156 BOOL bResult = CeCosPropertySheet::OnInitDialog(); | |
| 157 SetDlgItemText(IDOK,_T("&Run")); | |
| 158 SetDlgItemText(ID_APPLY_NOW,_T("&Properties")); | |
| 159 GetDlgItem(ID_APPLY_NOW)->EnableWindow(TRUE); | |
| 160 GetDlgItem(IDCANCEL)->EnableWindow(TRUE); // required for modeless case | |
| 161 | |
| 162 SetActivePage(&outputpage); | |
| 163 SetActivePage(&summarypage); | |
| 164 SetActivePage(&executionpage); | |
| 165 | |
| 166 if(m_pInitFunc){ | |
| 167 m_pInitFunc(&m_prop,false); | |
| 168 outputpage.UpdateData(FALSE); | |
| 169 summarypage.UpdateData(FALSE); | |
| 170 executionpage.UpdateData(FALSE); | |
| 171 } | |
| 172 /* | |
| 173 CString strCaption = _T("Output"); | |
| 174 TC_ITEM tcItem; | |
| 175 tcItem.mask = TCIF_TEXT; | |
| 176 tcItem.pszText = (LPTSTR)((LPCTSTR)strCaption); | |
| 177 GetTabControl()->SetItem(2, &tcItem ); | |
| 178 strCaption=_T("Summary"); | |
| 179 GetTabControl()->SetItem(3, &tcItem ); | |
| 180 */ | |
| 181 // Allow resizing | |
| 182 | |
| 183 // WS_OVERLAPPEDWINDOW would preclude caption bar help button | |
| 184 ModifyStyle(0,WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME ,0); | |
| 185 | |
| 186 CRect rect; | |
| 187 GetWindowRect(rect); | |
| 188 m_rcPrev=rect; | |
| 189 | |
| 190 m_cxMin=rect.Width(); | |
| 191 m_cyMin=rect.Height(); | |
| 192 | |
| 193 m_bAllowResizing=true; | |
| 194 | |
| 195 WINDOWPLACEMENT wndpl; | |
| 196 if (5==_stscanf(m_strPlacement,_T("%d %d %d %d %d"),&rect.left,&rect.top,&rect.right,&rect.bottom,&wndpl.showCmd)){ | |
| 197 CRect rcMax; | |
| 198 SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)(RECT *)rcMax, 0); | |
| 199 | |
| 200 if(rect.Width()<100 || rect.Height()<100 || rect.Width()>rcMax.Width() || rect.Height()>rcMax.Height()){ | |
| 201 rect=CFrameWnd::rectDefault; | |
| 202 } | |
| 203 | |
| 204 wndpl.length = sizeof(WINDOWPLACEMENT); | |
| 205 wndpl.flags = 0; | |
| 206 | |
| 207 wndpl.ptMinPosition = CPoint(0, 0); | |
| 208 wndpl.ptMaxPosition =CPoint(-::GetSystemMetrics(SM_CXBORDER),-::GetSystemMetrics(SM_CYBORDER)); | |
| 209 wndpl.rcNormalPosition = rect; | |
| 210 | |
| 211 // sets window's position and iconized/maximized status | |
| 212 SetWindowPlacement(&wndpl); | |
| 213 } | |
| 214 | |
| 215 // Hack: force an initial sizing (without which the tab control is badly sized) | |
| 216 m_rcOffset.left=m_rcOffset.right=m_rcOffset.top=0; | |
| 217 | |
| 218 m_rcOffset.bottom=m_bModal?50:-50; | |
| 219 MoveWindow(GetTabControl(),Stretch); | |
| 220 for(int i=0;i<GetPageCount();i++){ | |
| 221 MoveWindow(GetPage(i),Stretch); | |
| 222 } | |
| 223 #ifdef _DEBUG | |
| 224 for(CWnd *p=GetWindow(GW_CHILD);p;p=p->GetWindow(GW_HWNDNEXT)){ | |
| 225 TCHAR buf[256]; | |
| 226 ::GetClassName(p->m_hWnd,buf,sizeof buf); | |
| 227 TRACE(_T("Window %x id=%d class=%s\n"),p,p->GetDlgCtrlID(),buf); | |
| 228 } | |
| 229 #endif | |
| 230 for(i=0;i<sizeof(arIds)/sizeof(arIds[0]);i++){ | |
| 231 CWnd *pWnd=GetDlgItem(arIds[i]); | |
| 232 if(pWnd){ | |
| 233 MoveWindow(pWnd,BottomRight); | |
| 234 pWnd->ShowWindow(SW_SHOW); // necessary in the modeless case | |
| 235 } else { | |
| 236 TRACE(_T("Failed to find window id=%x\n"),arIds[i]); | |
| 237 } | |
| 238 } | |
| 239 | |
| 240 // hack to lay buttons out correctly in application case | |
| 241 if(this==AfxGetMainWnd()){ | |
| 242 CRect rect1,rect2; | |
| 243 GetDlgItem(IDOK)->GetWindowRect(rect1); | |
| 244 GetDlgItem(IDCANCEL)->GetWindowRect(rect2); | |
| 245 CRect rect(rect1); | |
| 246 rect.left-=(rect2.left-rect1.left); | |
| 247 rect.right-=(rect2.right-rect1.right); | |
| 248 ScreenToClient(rect); | |
| 249 GetDlgItem(ID_APPLY_NOW)->MoveWindow(rect); | |
| 250 GetDlgItem(ID_APPLY_NOW)->ShowWindow(SW_SHOW); | |
| 251 } | |
| 252 | |
| 253 if(!m_bModal){ | |
| 254 SetTimer(0,100,0); | |
| 255 } | |
| 256 BringWindowToTop(); | |
| 257 return bResult; | |
| 258 } | |
| 259 | |
| 260 void CRunTestsSheet::OnRun() | |
| 261 { | |
| 262 | |
| 263 if(Running==m_Status){ | |
| 264 outputpage.AddLogMsg(_T("Run canceled")); | |
| 265 m_Status=Stopping; | |
| 266 EnterCriticalSection(&m_CS); | |
| 267 m_nNextToSubmit=0x7fffffff; | |
| 268 LeaveCriticalSection(&m_CS); | |
| 269 CeCosTest::CancelAllInstances(); | |
| 270 } else { | |
| 271 outputpage.UpdateData(TRUE); | |
| 272 summarypage.UpdateData(TRUE); | |
| 273 executionpage.UpdateData(TRUE); | |
| 274 if(0==executionpage.SelectedTestCount()){ | |
| 275 MessageBox(_T("No tests have selected for execution")); | |
| 276 } else { | |
| 277 m_ep=CeCosTest::ExecutionParameters( | |
| 278 CeCosTest::ExecutionParameters::RUN, | |
| 279 m_strTarget, | |
| 280 TIMEOUT_NONE==m_nTimeoutType?0x7fffffff:TIMEOUT_AUTOMATIC==m_nTimeoutType?0:1000*m_nTimeout, | |
| 281 TIMEOUT_NONE==m_nDownloadTimeoutType?0x7fffffff:TIMEOUT_AUTOMATIC==m_nDownloadTimeoutType?0:1000*m_nDownloadTimeout); | |
| 282 if(m_bRemote){ | |
| 283 CTestResource::SetResourceServer(m_strResourceHost,m_nResourcePort); | |
| 284 if(!CTestResource::LoadSocket()){ | |
| 285 MessageBox(_T("Could not connect to resource server")); | |
| 286 return; | |
| 287 } | |
| 288 } else { | |
| 289 if(CeCosTest::IsSim(m_ep.Target())){ | |
| 290 //for(int i=0;i<m_nSimConcurrent;i++){ | |
| 291 m_pResource=new CTestResource(m_ep.Target()); | |
| 292 //} | |
| 293 } else { | |
| 294 const String strPort(m_bSerial?(LPCTSTR)m_strPort:CeCosTestSocket::HostPort(m_strLocalTCPIPHost,m_nLocalTCPIPPort)); | |
| 295 int nBaud=m_bSerial?m_nBaud:0; | |
| 296 if (RESET_X10!=m_nReset) { | |
| 297 m_pResource=new CTestResource(m_ep.Target(),strPort,nBaud); | |
| 298 } else { | |
| 299 m_pResource=new CTestResource(m_ep.Target(),strPort,nBaud,m_strReset); | |
| 300 } | |
| 301 } | |
| 302 } | |
| 303 m_Status=Running; | |
| 304 SetDlgItemText(IDOK,_T("&Stop")); | |
| 305 m_nNextToSubmit=0; | |
| 306 outputpage.AddLogMsg(_T("Run started")); | |
| 307 SubmitTests(); | |
| 308 } | |
| 309 } | |
| 310 } | |
| 311 | |
| 312 struct Info { | |
| 313 CRunTestsSheet *pSheet; | |
| 314 CeCosTest *pTest; | |
| 315 }; | |
| 316 | |
| 317 DWORD CRunTestsSheet::X10ThreadFunc (void *pParam) | |
| 318 { | |
| 319 Info *pInfo=(Info *)pParam; | |
| 320 String str; | |
| 321 bool bOk=false; | |
| 322 CResetAttributes::ResetResult n=pInfo->pSheet->m_pResource->Reset(str); | |
| 323 if(CResetAttributes::RESET_OK==n){ | |
| 324 str+=_TCHAR('\n'); | |
| 325 if(CResetAttributes::IsValidReset((void *)(LPCTSTR )str)){ | |
| 326 str+=_T(">>> Reset ok\n"); | |
| 327 bOk=true; | |
| 328 } else { | |
| 329 str+=_T(">>> Could not reset target (no valid startup string seen)\n"); | |
| 330 } | |
| 331 } else { | |
| 332 String str; | |
| 333 str+=_T(">>> Could not reset target - X10 error - "); | |
| 334 str+=CResetAttributes::Image(n); | |
| 335 str+=_TCHAR('\n'); | |
| 336 } | |
| 337 LPTSTR pszCopy=new TCHAR[1+str.GetLength()]; | |
| 338 _tcscpy(pszCopy,str); | |
| 339 pInfo->pSheet->PostMessage(WM_TESTOUTPUT,(WPARAM)pszCopy,0); | |
| 340 | |
| 341 if(bOk){ | |
| 342 // we're already in a thread, so we can call the function directly | |
| 343 pInfo->pTest->RunLocal(); | |
| 344 } | |
| 345 RunCallback(pInfo); | |
| 346 return 0; | |
| 347 } | |
| 348 | |
| 349 void CALLBACK CRunTestsSheet::RunLocalFunc(void *pParam) | |
| 350 { | |
| 351 ((Info *)pParam)->pTest->RunLocal(); | |
| 352 } | |
| 353 | |
| 354 void CALLBACK CRunTestsSheet::RunRemoteFunc(void *pParam) | |
| 355 { | |
| 356 ((Info *)pParam)->pTest->RunRemote(NULL); | |
| 357 } | |
| 358 | |
| 359 void CRunTestsSheet::SubmitTests() | |
| 360 { | |
| 361 int nResources=m_bRemote?max(1,CTestResource::GetMatchCount (m_ep)):1; | |
| 362 if(nResources>CeCosTest::InstanceCount){ | |
| 363 if(m_nNextToSubmit>=executionpage.SelectedTestCount()){ | |
| 364 return; | |
| 365 } | |
| 366 Info *pInfo=new Info; | |
| 367 pInfo->pTest=new CeCosTest(m_ep, executionpage.SelectedTest(m_nNextToSubmit++)); | |
| 368 pInfo->pSheet=this; | |
| 369 m_nTestsToComplete++; | |
| 370 if(m_bRemote){ | |
| 371 CeCosThreadUtils::RunThread(RunRemoteFunc,pInfo,RunCallback,_T("RunRemoteFunc")); | |
| 372 } else { | |
| 373 bool bRun=false; | |
| 374 if(CeCosTest::IsSim(m_ep.Target())){ | |
| 375 bRun=true; | |
| 376 } else { | |
| 377 switch((ResetType)m_nReset){ | |
| 378 case RESET_NONE: | |
| 379 bRun=true; | |
| 380 break; | |
| 381 case RESET_X10: | |
| 382 // Resetting can take a while, so spawn a thread | |
| 383 bRun=false; | |
| 384 { | |
| 385 DWORD dwID; | |
| 386 CloseHandle(CreateThread(0,0,X10ThreadFunc, pInfo, 0, &dwID)); | |
| 387 } | |
| 388 break; | |
| 389 case RESET_MANUAL: | |
| 390 bRun=(IDOK==MessageBox(_T("Press OK when target is reset - cancel to abort run"),NULL,MB_OKCANCEL)); | |
| 391 if(!bRun){ | |
| 392 m_nNextToSubmit=executionpage.SelectedTestCount(); | |
| 393 RunCallback(pInfo); | |
| 394 } | |
| 395 break; | |
| 396 } | |
| 397 } | |
| 398 if(bRun){ | |
| 399 CeCosThreadUtils::RunThread(RunLocalFunc,pInfo,RunCallback,_T("RunLocalFunc")); | |
| 400 } | |
| 401 } | |
| 402 } | |
| 403 } | |
| 404 | |
| 405 void CRunTestsSheet::RunCallback(void *pParam) | |
| 406 { | |
| 407 Info *pInfo=(Info *)pParam; | |
| 408 CRunTestsSheet *pSheet=pInfo->pSheet; | |
| 409 if(::IsWindow(pSheet->m_hWnd)){ //FIXME | |
| 410 CeCosTest *pTest=pInfo->pTest; | |
| 411 EnterCriticalSection(&pSheet->m_CS); | |
| 412 | |
| 413 pSheet->summarypage.AddResult(pTest); | |
| 414 delete pTest; | |
| 415 | |
| 416 pSheet->m_nTestsToComplete--; | |
| 417 pSheet->SubmitTests(); | |
| 418 | |
| 419 if(0==pSheet->m_nTestsToComplete){ | |
| 420 // It would be nice to do this in the handler for WM_RUNCOMPLETE, but we must be in the CS | |
| 421 delete pSheet->m_pResource; | |
| 422 pSheet->m_pResource=0; | |
| 423 pSheet->PostMessage(WM_RUNCOMPLETE,0,0); | |
| 424 } | |
| 425 LeaveCriticalSection(&pSheet->m_CS); | |
| 426 } | |
| 427 delete pInfo; | |
| 428 } | |
| 429 | |
| 430 LRESULT CRunTestsSheet::OnTestsComplete(WPARAM wParam, LPARAM lParam) | |
| 431 { | |
| 432 UNUSED_ALWAYS(wParam); | |
| 433 UNUSED_ALWAYS(lParam); | |
| 434 m_Status=Stopped; | |
| 435 SetDlgItemText(IDOK,_T("&Run")); | |
| 436 outputpage.AddLogMsg(_T("Run complete")); | |
| 437 return 0; | |
| 438 } | |
| 439 | |
| 440 void CALLBACK CRunTestsSheet::TestOutputCallback(void *pParam,LPCTSTR psz) | |
| 441 { | |
| 442 CRunTestsSheet*pWnd=(CRunTestsSheet*)pParam; | |
| 443 if(::IsWindow(pWnd->m_hWnd)){ //FIXME | |
| 444 LPTSTR pszCopy=new TCHAR[1+_tcslen(psz)]; | |
| 445 _tcscpy(pszCopy,psz); | |
| 446 pWnd->PostMessage(WM_TESTOUTPUT,(WPARAM)pszCopy,0); | |
| 447 } | |
| 448 } | |
| 449 | |
| 450 LRESULT CRunTestsSheet::OnTestOutput(WPARAM wParam, LPARAM lParam) | |
| 451 { | |
| 452 UNUSED_ALWAYS(lParam); | |
| 453 LPTSTR psz=(LPTSTR)wParam; | |
| 454 outputpage.AddText(psz); | |
| 455 delete [] psz; | |
| 456 return 0; | |
| 457 } | |
| 458 | |
| 459 void CRunTestsSheet::OnProperties() | |
| 460 { | |
| 461 CPropertiesDialog dlg(m_bHideTarget,m_bHideRemoteControls); | |
| 462 dlg.m_strTarget=m_strTarget; | |
| 463 dlg.m_nTimeout=m_nTimeout; | |
| 464 dlg.m_nDownloadTimeout=m_nDownloadTimeout; | |
| 465 dlg.m_nTimeoutType=m_nTimeoutType; | |
| 466 dlg.m_nDownloadTimeoutType=m_nDownloadTimeoutType; | |
| 467 dlg.m_bRemote=m_bRemote; | |
| 468 dlg.m_bSerial=m_bSerial; | |
| 469 dlg.m_strPort=m_strPort; | |
| 470 dlg.m_nBaud=m_nBaud; | |
| 471 dlg.m_strLocalTCPIPHost=m_strLocalTCPIPHost; | |
| 472 dlg.m_nLocalTCPIPPort=m_nLocalTCPIPPort; | |
| 473 dlg.m_nReset=m_nReset; | |
| 474 dlg.m_strReset=m_strReset; | |
| 475 dlg.m_strResourceHost=m_strResourceHost; | |
| 476 dlg.m_nResourcePort=m_nResourcePort; | |
| 477 dlg.m_strRemoteHost=m_strRemoteHost; | |
| 478 dlg.m_nRemotePort=m_nRemotePort; | |
| 479 dlg.m_strPort=m_strPort; | |
| 480 dlg.m_bFarmed=m_bFarmed; | |
| 481 if(IDOK==dlg.DoModal()){ | |
| 482 m_strTarget=dlg.m_strTarget; | |
| 483 m_nTimeout=dlg.m_nTimeout; | |
| 484 m_nDownloadTimeout=dlg.m_nDownloadTimeout; | |
| 485 m_nTimeoutType=dlg.m_nTimeoutType; | |
| 486 m_nDownloadTimeoutType=dlg.m_nDownloadTimeoutType; | |
| 487 m_bRemote=dlg.m_bRemote; | |
| 488 m_bSerial=dlg.m_bSerial; | |
| 489 m_strPort=dlg.m_strPort; | |
| 490 m_nBaud=dlg.m_nBaud; | |
| 491 m_strLocalTCPIPHost=dlg.m_strLocalTCPIPHost; | |
| 492 m_nLocalTCPIPPort=dlg.m_nLocalTCPIPPort; | |
| 493 m_nReset=dlg.m_nReset; | |
| 494 m_strReset=dlg.m_strReset; | |
| 495 m_strResourceHost=dlg.m_strResourceHost; | |
| 496 m_nResourcePort=dlg.m_nResourcePort; | |
| 497 m_strRemoteHost=dlg.m_strRemoteHost; | |
| 498 m_nRemotePort=dlg.m_nRemotePort; | |
| 499 m_bFarmed=dlg.m_bFarmed; | |
| 500 if(m_pInitFunc){ | |
| 501 m_pInitFunc(&m_prop,true); | |
| 502 } | |
| 503 } | |
| 504 } | |
| 505 | |
| 506 void CRunTestsSheet::OnClose() | |
| 507 { | |
| 508 if(m_pInitFunc){ | |
| 509 WINDOWPLACEMENT wndpl; | |
| 510 wndpl.length = sizeof(WINDOWPLACEMENT); | |
| 511 GetWindowPlacement(&wndpl); | |
| 512 if(!IsWindowVisible()){ | |
| 513 wndpl.showCmd=SW_HIDE; | |
| 514 } | |
| 515 m_strPlacement.Format(_T("%d %d %d %d %d"), | |
| 516 wndpl.rcNormalPosition.left, | |
| 517 wndpl.rcNormalPosition.top, | |
| 518 wndpl.rcNormalPosition.right, | |
| 519 wndpl.rcNormalPosition.bottom, | |
| 520 wndpl.showCmd); | |
| 521 m_pInitFunc(&m_prop,true); | |
| 522 } | |
| 523 if(m_bModal){ | |
| 524 EndDialog(IDOK); | |
| 525 } else { | |
| 526 DestroyWindow(); | |
| 527 } | |
| 528 } | |
| 529 | |
| 530 | |
| 531 | |
| 532 void CRunTestsSheet::OnSysCommand(UINT nID, LPARAM lParam) | |
| 533 { | |
| 534 if(SC_CLOSE==nID){ | |
| 535 OnClose(); | |
| 536 } else { | |
| 537 CeCosPropertySheet::OnSysCommand(nID, lParam); | |
| 538 } | |
| 539 } | |
| 540 | |
| 541 void CRunTestsSheet::OnSize(UINT nType, int cx, int cy) | |
| 542 { | |
| 543 // WS_OVERLAPPEDWINDOW would preclude caption bar help button | |
| 544 ModifyStyle(0,WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME ,0); | |
| 545 CeCosPropertySheet::OnSize(nType, cx, cy); | |
| 546 if(SIZE_MINIMIZED!=nType){ | |
| 547 CRect rect; | |
| 548 GetWindowRect(rect); | |
| 549 TRACE(_T("OnSize(%d) left=%d top=%d right=%d bottom=%d ar=%d\n"),nType,rect.left,rect.top,rect.right,rect.bottom,m_bAllowResizing); | |
| 550 | |
| 551 m_rcOffset.left =rect.left-m_rcPrev.left; | |
| 552 m_rcOffset.right =rect.right-m_rcPrev.right; | |
| 553 m_rcOffset.top =rect.top-m_rcPrev.top; | |
| 554 m_rcOffset.bottom=rect.bottom-m_rcPrev.bottom; | |
| 555 | |
| 556 m_rcPrev=rect; | |
| 557 | |
| 558 if(m_bAllowResizing){ | |
| 559 cx=max(m_cxMin,cx); | |
| 560 cy=max(m_cyMin,cy); | |
| 561 MoveWindow(GetTabControl(),Stretch); | |
| 562 CRect rc[sizeof(arIds)/sizeof(arIds[0])]; | |
| 563 CRect rcSheet; | |
| 564 GetWindowRect(rcSheet); | |
| 565 for(int i=0;i<sizeof(arIds)/sizeof(arIds[0]);i++){ | |
| 566 CWnd *pWnd=GetDlgItem(arIds[i]); | |
| 567 if(pWnd){ | |
| 568 pWnd->GetWindowRect(rc[i]); | |
| 569 ScreenToClient(rc[i]); | |
| 570 MoveWindow(pWnd,BottomRight,FALSE); | |
| 571 } | |
| 572 } | |
| 573 | |
| 574 for(i=0;i<sizeof(arIds)/sizeof(arIds[0]);i++){ | |
| 575 CWnd *pWnd=GetDlgItem(arIds[i]); | |
| 576 if(pWnd){ | |
| 577 pWnd->Invalidate(); | |
| 578 InvalidateRect(rc[i]); | |
| 579 } else { | |
| 580 TRACE(_T("Failed to find window id=%x\n"),arIds[i]); | |
| 581 } | |
| 582 } | |
| 583 | |
| 584 for(i=0;i<GetPageCount();i++){ | |
| 585 MoveWindow(GetPage(i),Stretch); | |
| 586 } | |
| 587 | |
| 588 } | |
| 589 } | |
| 590 } | |
| 591 | |
| 592 void CRunTestsSheet::MoveWindow(CWnd *pWnd, AffinityType Affinity,bool bRepaint) | |
| 593 { | |
| 594 if(m_bAllowResizing&&pWnd){ | |
| 595 TRACE(_T("MoveWindow left=%d top=%d right=%d bottom=%d\n"),m_rcOffset.left,m_rcOffset.top,m_rcOffset.right,m_rcOffset.bottom); | |
| 596 CRect rect; | |
| 597 pWnd->GetWindowRect(rect); | |
| 598 pWnd->GetParent()->ScreenToClient(rect); | |
| 599 TRACE(_T(" left=%d top=%d right=%d bottom=%d"),rect.left,rect.top,rect.right,rect.bottom); | |
| 600 int nHeight=rect.Height(); | |
| 601 int nWidth=rect.Width(); | |
| 602 | |
| 603 switch(Affinity){ | |
| 604 case BottomRight: | |
| 605 rect.right +=m_rcOffset.Width(); | |
| 606 rect.bottom+=m_rcOffset.Height(); | |
| 607 rect.top =rect.bottom-nHeight; | |
| 608 rect.left=rect.right -nWidth; | |
| 609 break; | |
| 610 case TopRight: | |
| 611 rect.right +=m_rcOffset.Width(); | |
| 612 rect.left=rect.right -nWidth; | |
| 613 break; | |
| 614 case BottomLeft: | |
| 615 rect.top +=m_rcOffset.Height(); | |
| 616 rect.right=rect.left+nWidth; | |
| 617 break; | |
| 618 case TopLeft: | |
| 619 break; | |
| 620 case Stretch: | |
| 621 rect.right +=m_rcOffset.Width(); | |
| 622 rect.bottom+=m_rcOffset.Height(); | |
| 623 break; | |
| 624 } | |
| 625 TRACE(_T(" -> left=%d top=%d right=%d bottom=%d\n"),rect.left,rect.top,rect.right,rect.bottom); | |
| 626 pWnd->MoveWindow(rect,bRepaint); | |
| 627 } | |
| 628 } | |
| 629 | |
| 630 void CRunTestsSheet::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) | |
| 631 { | |
| 632 lpMMI->ptMinTrackSize.x = m_cxMin; | |
| 633 lpMMI->ptMinTrackSize.y = 175; | |
| 634 CeCosPropertySheet::OnGetMinMaxInfo(lpMMI); | |
| 635 } | |
| 636 | |
| 637 LRESULT CRunTestsSheet::OnKickIdle(WPARAM, LPARAM) | |
| 638 { | |
| 639 // We could use WM_KICKIDLE to drive CMDUI messages, but in fact we just | |
| 640 // use an OnKickIdle handler directly (here and in the pages) to control | |
| 641 // button greying. | |
| 642 bool bEnableRunStop=false; | |
| 643 bool bEnableProperties=false; | |
| 644 switch(m_Status){ | |
| 645 case Running: | |
| 646 bEnableRunStop=true; | |
| 647 break; | |
| 648 case Stopping: | |
| 649 bEnableProperties=true; | |
| 650 break; | |
| 651 case Stopped: | |
| 652 bEnableRunStop=executionpage.SomeTestsSelected(); | |
| 653 bEnableProperties=true; | |
| 654 break; | |
| 655 } | |
| 656 GetDlgItem(IDOK)->EnableWindow(bEnableRunStop); | |
| 657 GetDlgItem(ID_APPLY_NOW)->EnableWindow(bEnableProperties); | |
| 658 SendMessageToDescendants(WM_KICKIDLE, 0, 0, FALSE, FALSE); | |
| 659 return 0; | |
| 660 } | |
| 661 | |
| 662 BOOL CRunTestsSheet::PreTranslateMessage(MSG* pMsg) | |
| 663 { | |
| 664 if(WM_KEYDOWN==pMsg->message && VK_ESCAPE==pMsg->wParam){ | |
| 665 return TRUE;// escape character handled | |
| 666 } | |
| 667 return CeCosPropertySheet::PreTranslateMessage(pMsg); | |
| 668 } | |
| 669 | |
| 670 void CRunTestsSheet::SetTarget(LPCTSTR pszTarget) | |
| 671 { | |
| 672 m_strTarget=pszTarget; | |
| 673 m_bHideTarget=true; | |
| 674 } | |
| 675 | |
| 676 void CRunTestsSheet::HideRemoteControls() | |
| 677 { | |
| 678 m_bHideRemoteControls=true; | |
| 679 } | |
| 680 | |
| 681 void CRunTestsSheet::Populate(LPCTSTR pszFile,bool bSelect/*=true*/) | |
| 682 { | |
| 683 executionpage.m_arstrPreLoad.SetAt(pszFile,bSelect?this:0); | |
| 684 } | |
| 685 | |
| 686 | |
| 687 int CRunTestsSheet::DoModal() | |
| 688 { | |
| 689 m_bModal=true; | |
| 690 return CeCosPropertySheet::DoModal(); | |
| 691 } | |
| 692 | |
| 693 void CRunTestsSheet::PostNcDestroy() | |
| 694 { | |
| 695 if(!m_bModal){ | |
| 696 delete this; | |
| 697 } else { | |
| 698 CeCosPropertySheet::PostNcDestroy(); | |
| 699 } | |
| 700 } | |
| 701 | |
| 702 void CRunTestsSheet::OnTimer(UINT nIDEvent) | |
| 703 { | |
| 704 SendMessage(WM_KICKIDLE,0,0); | |
| 705 CeCosPropertySheet::OnTimer(nIDEvent); | |
| 706 } | |
| 707 |
