Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

556 lines
16 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: CFuncTest.cpp
  3. *
  4. * This file contains the code to support the functionality test harness
  5. * for GDI+. This includes menu options and calling the appropriate
  6. * functions for execution.
  7. *
  8. * Created: 05-May-2000 - Jeff Vezina [t-jfvez]
  9. *
  10. * Copyright (c) 2000 Microsoft Corporation
  11. *
  12. \**************************************************************************/
  13. #undef UNICODE
  14. #undef _UNICODE
  15. #include "CFuncTest.h"
  16. #include "Resource.h"
  17. #include "CRegression.h"
  18. #include "CHDC.h"
  19. extern CFuncTest g_FuncTest; // Initialized in Main.cpp
  20. extern HBRUSH g_hbrBackground; // Initialized in Main.cpp
  21. extern CRegression g_Regression; // Initialized in Main.cpp
  22. extern CHDC g_HDC; // Initialized in Main.cpp
  23. extern int g_nResult; // Initialized in Main.cpp
  24. CFuncTest::CFuncTest()
  25. {
  26. m_hWndDlg=NULL;
  27. m_hWndMain=NULL;
  28. m_bUsePageDelay=true; // Default use page delay or page pause
  29. m_bEraseBkgd=true; // Default erace background
  30. m_bAppendTest=false; // Default append test
  31. m_nPageDelay=1000; // Default page delay
  32. m_nPageRow=0;
  33. m_nPageCol=0;
  34. }
  35. CFuncTest::~CFuncTest()
  36. {
  37. EndDialog(m_hWndDlg,0);
  38. m_hWndDlg=NULL;
  39. m_hWndMain=NULL;
  40. }
  41. BOOL CFuncTest::Init(HWND hWndParent)
  42. // Initializes functest
  43. {
  44. HWND hWnd;
  45. char szDelay[10];
  46. m_hWndMain=hWndParent;
  47. // Create options dialog box
  48. m_hWndDlg=CreateDialogA(GetModuleHandleA(NULL),MAKEINTRESOURCEA(IDD_FUNCTEST),hWndParent,&DlgProc);
  49. if (m_hWndDlg==NULL)
  50. return false;
  51. // Set default options in dialog box using defaults in constructor
  52. if (m_bUsePageDelay)
  53. {
  54. hWnd=GetDlgItem(m_hWndDlg,IDC_PAGEDELAY);
  55. SendMessageA(hWnd,BM_SETCHECK,(WPARAM)BST_CHECKED,0);
  56. }
  57. else
  58. {
  59. hWnd=GetDlgItem(m_hWndDlg,IDC_PAGEPAUSE);
  60. SendMessageA(hWnd,BM_SETCHECK,(WPARAM)BST_CHECKED,0);
  61. }
  62. hWnd=GetDlgItem(m_hWndDlg,IDC_DELAY);
  63. SendMessageA(hWnd,WM_SETTEXT,0,(LPARAM)_itoa(m_nPageDelay,szDelay,10));
  64. if (m_bEraseBkgd)
  65. {
  66. hWnd=GetDlgItem(m_hWndDlg,IDC_ERASEBKGD);
  67. SendMessageA(hWnd,BM_SETCHECK,(WPARAM)BST_CHECKED,0);
  68. }
  69. if (m_bAppendTest)
  70. {
  71. hWnd=GetDlgItem(m_hWndDlg,IDC_APPENDTEST);
  72. SendMessageA(hWnd,BM_SETCHECK,(WPARAM)BST_CHECKED,0);
  73. }
  74. return true;
  75. }
  76. void CFuncTest::RunOptions()
  77. // Toggle options dialog box
  78. {
  79. if (m_hWndDlg!=NULL)
  80. {
  81. if (!IsWindowVisible(m_hWndDlg))
  82. ShowWindow(m_hWndDlg,SW_SHOW);
  83. else
  84. ShowWindow(m_hWndDlg,SW_HIDE);
  85. }
  86. }
  87. BOOL CFuncTest::AddPrimitive(CPrimitive *pPrimitive)
  88. // Adds a primitive to the primitive test list in options dialog box
  89. {
  90. HWND hWnd;
  91. LRESULT iItem;
  92. hWnd=GetDlgItem(m_hWndDlg,IDC_PRIMITIVES);
  93. SendMessageA(hWnd,LB_SETSEL,(WPARAM)false,0); // Reset selection
  94. iItem=SendMessageA(hWnd,LB_ADDSTRING,0,(LPARAM)pPrimitive->m_szName);
  95. if (iItem<0)
  96. return false;
  97. SendMessageA(hWnd,LB_SETSEL,(WPARAM)true,0); // Pick top element as selection
  98. // Data is a pointer to the primitive base class
  99. SendMessageA(hWnd,LB_SETITEMDATA,(WPARAM)iItem,(LPARAM)pPrimitive);
  100. return true;
  101. }
  102. BOOL CFuncTest::AddOutput(COutput *pOutput)
  103. // Adds an output to the output list in options dialog box
  104. {
  105. HWND hWnd;
  106. LRESULT iItem;
  107. hWnd=GetDlgItem(m_hWndDlg,IDC_OUTPUTS);
  108. SendMessageA(hWnd,LB_SETSEL,(WPARAM)false,0); // Reset selection
  109. iItem=SendMessageA(hWnd,LB_ADDSTRING,0,(LPARAM)pOutput->m_szName);
  110. if (iItem<0)
  111. return false;
  112. SendMessageA(hWnd,LB_SETSEL,(WPARAM)true,0); // Pick top element as selection
  113. // Data is a pointer to the output base class
  114. SendMessageA(hWnd,LB_SETITEMDATA,(WPARAM)iItem,(LPARAM)pOutput);
  115. return true;
  116. }
  117. BOOL CFuncTest::AddSetting(CSetting *pSetting)
  118. // Adds a setting to the settings list in options dialog box
  119. {
  120. HWND hWnd;
  121. LRESULT iItem;
  122. hWnd=GetDlgItem(m_hWndDlg,IDC_SETTINGS);
  123. iItem=SendMessageA(hWnd,LB_ADDSTRING,0,(LPARAM)pSetting->m_szName);
  124. if (iItem<0)
  125. return false;
  126. // Data is a pointer to the setting base class
  127. SendMessageA(hWnd,LB_SETITEMDATA,(WPARAM)iItem,(LPARAM)pSetting);
  128. return true;
  129. }
  130. RECT CFuncTest::GetTestRect(int nCol,int nRow)
  131. {
  132. RECT Rect;
  133. // Create test area rect
  134. Rect.top=nRow*(int)TESTAREAHEIGHT;
  135. Rect.left=nCol*(int)TESTAREAWIDTH;
  136. Rect.right=Rect.left+(int)TESTAREAWIDTH;
  137. Rect.bottom=Rect.top+(int)TESTAREAHEIGHT;
  138. return Rect;
  139. }
  140. void CFuncTest::RunTest(COutput *pOutput,CPrimitive *pPrimitive)
  141. // Runs one test using the given output, primitive, and settings that have m_bUseSetting=true
  142. {
  143. char szBuffer[256];
  144. MSG Msg;
  145. Graphics *g=NULL;
  146. CSetting *pSetting;
  147. RECT Rect;
  148. HDC hDC;
  149. HWND hWnd;
  150. int iItem;
  151. LRESULT cItemMax;
  152. int nX;
  153. int nY;
  154. BOOL bFirstSetting=true;
  155. __try
  156. {
  157. sprintf(szBuffer,"%s on %s",pPrimitive->m_szName,pOutput->m_szName);
  158. Rect=GetTestRect(m_nPageCol,m_nPageRow); // Get test area
  159. // Clear test area
  160. if (m_bEraseBkgd)
  161. {
  162. hDC=GetDC(m_hWndMain);
  163. FillRect(hDC,&Rect,g_hbrBackground);
  164. ReleaseDC(m_hWndMain,hDC);
  165. }
  166. // Initialize output and get graphics pointer
  167. // Let pOutput modify the nX,nY in case we are drawing to a dib, we do not
  168. // want to be translating.
  169. nX=Rect.left;
  170. nY=Rect.top;
  171. g=pOutput->PreDraw(nX,nY);
  172. if (g==NULL)
  173. return;
  174. // Move test to test area
  175. g->TranslateTransform((float)nX,(float)nY);
  176. // Set each setting in the list box
  177. hWnd=GetDlgItem(m_hWndDlg,IDC_SETTINGS);
  178. cItemMax=SendMessageA(hWnd,LB_GETCOUNT,0,0);
  179. for (iItem=0;iItem<cItemMax;iItem++) {
  180. pSetting=(CSetting*)SendMessageA(hWnd,LB_GETITEMDATA,(WPARAM)iItem,0);
  181. pSetting->Set(g);
  182. if (pSetting->m_bUseSetting)
  183. {
  184. if (bFirstSetting)
  185. {
  186. strcat(szBuffer," (");
  187. bFirstSetting=false;
  188. }
  189. else
  190. {
  191. strcat(szBuffer,", ");
  192. }
  193. strcat(szBuffer,pSetting->m_szName);
  194. }
  195. }
  196. if (!bFirstSetting)
  197. strcat(szBuffer,")");
  198. // We do have some primitives (CachedBitmap) which don't respect the
  199. // world transform so we need some way to access the offset to the
  200. // test rectangle.
  201. pPrimitive->SetOffset(nX, nY);
  202. // Draw primitive test
  203. pPrimitive->Draw(g);
  204. // Destroy graphics pointer
  205. delete g;
  206. // Finish off the output
  207. pOutput->PostDraw(Rect);
  208. // Write description of test
  209. hDC=GetDC(m_hWndMain);
  210. SetBkMode(hDC,TRANSPARENT);
  211. DrawTextA(hDC,szBuffer,-1,&Rect,DT_CENTER|DT_WORDBREAK);
  212. ReleaseDC(m_hWndMain,hDC);
  213. // Determine page col/row where next test will be drawn
  214. GetClientRect(m_hWndMain,&Rect);
  215. m_nPageCol++;
  216. if (m_nPageCol*TESTAREAWIDTH+TESTAREAWIDTH>Rect.right)
  217. {
  218. m_nPageCol=0;
  219. m_nPageRow++;
  220. if (m_nPageRow*TESTAREAHEIGHT+TESTAREAHEIGHT>Rect.bottom)
  221. // If graphics page is full, wait or pause
  222. {
  223. m_nPageRow=0;
  224. if (m_bUsePageDelay)
  225. Sleep(m_nPageDelay); // Wait
  226. else
  227. { // Pause for next input message
  228. // Clear old input messages
  229. while (GetInputState())
  230. PeekMessageA(&Msg,NULL,0,0,PM_REMOVE);
  231. // Wait for new input message
  232. while (!GetInputState())
  233. Sleep(100);
  234. }
  235. }
  236. }
  237. }__except(EXCEPTION_ACCESS_VIOLATION,1){
  238. printf("%s caused AV\n",szBuffer);
  239. g_nResult=1; // Return 1 if there was an AV
  240. }
  241. }
  242. void CFuncTest::InitRun()
  243. // Initialise test run, grabs all info from the options dialog box
  244. {
  245. HWND hWnd;
  246. char szDelay[10];
  247. RECT Rect;
  248. HDC hDC;
  249. // Hide options dialog
  250. // ShowWindow(m_hWndDlg,SW_HIDE);
  251. // Grab options
  252. hWnd=GetDlgItem(m_hWndDlg,IDC_PAGEDELAY);
  253. if (SendMessageA(hWnd,BM_GETCHECK,0,0)==BST_CHECKED)
  254. m_bUsePageDelay=true;
  255. else
  256. m_bUsePageDelay=false;
  257. hWnd=GetDlgItem(m_hWndDlg,IDC_DELAY);
  258. SendMessageA(hWnd,WM_GETTEXT,(WPARAM)10,(LPARAM)szDelay);
  259. m_nPageDelay=atoi(szDelay);
  260. hWnd=GetDlgItem(m_hWndDlg,IDC_ERASEBKGD);
  261. if (SendMessageA(hWnd,BM_GETCHECK,0,0)==BST_CHECKED)
  262. m_bEraseBkgd=true;
  263. else
  264. m_bEraseBkgd=false;
  265. hWnd=GetDlgItem(m_hWndDlg,IDC_APPENDTEST);
  266. if (SendMessageA(hWnd,BM_GETCHECK,0,0)==BST_CHECKED)
  267. m_bAppendTest=true;
  268. else
  269. m_bAppendTest=false;
  270. // Erase entire main window
  271. if (!m_bAppendTest && m_bEraseBkgd)
  272. {
  273. GetClientRect(m_hWndMain,&Rect);
  274. hDC=GetDC(m_hWndMain);
  275. FillRect(hDC,&Rect,g_hbrBackground);
  276. ReleaseDC(m_hWndMain,hDC);
  277. }
  278. if (!m_bAppendTest)
  279. {
  280. // Reset page row/col
  281. m_nPageRow=0;
  282. m_nPageCol=0;
  283. }
  284. }
  285. void CFuncTest::EndRun()
  286. {
  287. int nX;
  288. int nY;
  289. RECT rTestArea;
  290. RECT rWindow;
  291. HDC hDC;
  292. hDC=GetDC(m_hWndMain);
  293. GetClientRect(m_hWndMain,&rWindow);
  294. // Draw lines on bottom right corner of last test
  295. // Figure out what was the last m_nPageCol and m_nPageRow
  296. nX=m_nPageCol-1;
  297. nY=m_nPageRow;
  298. if (nX<0) {
  299. nX=(rWindow.right/(int)TESTAREAWIDTH)-1;
  300. nY--;
  301. if (nY<0) {
  302. nY=(rWindow.bottom/(int)TESTAREAHEIGHT)-1;
  303. }
  304. }
  305. // Get the x,y coordinates
  306. nX=nX*(int)TESTAREAWIDTH;
  307. nY=nY*(int)TESTAREAHEIGHT;
  308. // Draw both lines
  309. Rectangle(hDC,nX+(int)TESTAREAWIDTH-3,nY,nX+(int)TESTAREAWIDTH,nY+(int)TESTAREAHEIGHT);
  310. Rectangle(hDC,nX,nY+(int)TESTAREAHEIGHT-3,nX+(int)TESTAREAWIDTH,nY+(int)TESTAREAWIDTH);
  311. // Clear the rest of the test areas on page
  312. if (m_bEraseBkgd)
  313. {
  314. nX=m_nPageCol;
  315. nY=m_nPageRow;
  316. while ((nX>0) || (nY>0))
  317. {
  318. rTestArea=GetTestRect(nX,nY);
  319. FillRect(hDC,&rTestArea,g_hbrBackground);
  320. nX++;
  321. if (nX*TESTAREAWIDTH+TESTAREAWIDTH>rWindow.right)
  322. {
  323. nX=0;
  324. nY++;
  325. if (nY*TESTAREAHEIGHT+TESTAREAHEIGHT>rWindow.bottom)
  326. // If graphics page is full
  327. {
  328. nY=0;
  329. }
  330. }
  331. }
  332. }
  333. ReleaseDC(m_hWndMain,hDC);
  334. }
  335. void CFuncTest::Run()
  336. // Runs all selected tests
  337. {
  338. COutput *pOutput;
  339. CPrimitive *pPrimitive;
  340. CSetting *pSetting;
  341. HWND hWnd;
  342. HWND hWndOutput;
  343. int iOutput;
  344. LRESULT cOutputMax;
  345. int iItem;
  346. LRESULT cItemMax;
  347. InitRun(); // Init test run
  348. // Do the selected output loop
  349. hWndOutput=GetDlgItem(m_hWndDlg,IDC_OUTPUTS);
  350. cOutputMax=SendMessageA(hWndOutput,LB_GETCOUNT,0,0);
  351. for (iOutput=0;iOutput<cOutputMax;iOutput++) {
  352. pOutput=(COutput*)SendMessageA(hWndOutput,LB_GETITEMDATA,(WPARAM)iOutput,0);
  353. if (SendMessageA(hWndOutput,LB_GETSEL,(WPARAM)iOutput,0)<=0)
  354. continue;
  355. // Set each setting according to what is selected in the list box
  356. hWnd=GetDlgItem(m_hWndDlg,IDC_SETTINGS);
  357. cItemMax=SendMessageA(hWnd,LB_GETCOUNT,0,0);
  358. for (iItem=0;iItem<cItemMax;iItem++) {
  359. pSetting=(CSetting*)SendMessageA(hWnd,LB_GETITEMDATA,(WPARAM)iItem,0);
  360. if (SendMessageA(hWnd,LB_GETSEL,(WPARAM)iItem,0)>0)
  361. pSetting->m_bUseSetting=true;
  362. else
  363. pSetting->m_bUseSetting=false;
  364. }
  365. // Draw each primitive selected in the list box
  366. hWnd=GetDlgItem(m_hWndDlg,IDC_PRIMITIVES);
  367. cItemMax=SendMessageA(hWnd,LB_GETCOUNT,0,0);
  368. for (iItem=0;iItem<cItemMax;iItem++) {
  369. pPrimitive=(CPrimitive*)SendMessageA(hWnd,LB_GETITEMDATA,(WPARAM)iItem,0);
  370. if (SendMessageA(hWnd,LB_GETSEL,(WPARAM)iItem,0)>0)
  371. RunTest(pOutput,pPrimitive);
  372. }
  373. }
  374. EndRun();
  375. }
  376. void CFuncTest::RunRegression()
  377. // Runs regression test suite
  378. {
  379. COutput *pOutput;
  380. CPrimitive *pPrimitive;
  381. CSetting *pSetting;
  382. HWND hWnd;
  383. HWND hWndOutput;
  384. int iOutput;
  385. LRESULT cOutputMax;
  386. int iItem;
  387. LRESULT cItemMax;
  388. InitRun(); // Init test run
  389. // Do the output regression loop
  390. hWndOutput=GetDlgItem(m_hWndDlg,IDC_OUTPUTS);
  391. cOutputMax=SendMessageA(hWndOutput,LB_GETCOUNT,0,0);
  392. for (iOutput=0;iOutput<cOutputMax;iOutput++) {
  393. pOutput=(COutput*)SendMessageA(hWndOutput,LB_GETITEMDATA,(WPARAM)iOutput,0);
  394. if (!pOutput->m_bRegression)
  395. continue;
  396. ClearAllSettings();
  397. RunTest(pOutput,&g_Regression);
  398. }
  399. // Do the primitive regression loop
  400. hWnd=GetDlgItem(m_hWndDlg,IDC_PRIMITIVES);
  401. cItemMax=SendMessageA(hWnd,LB_GETCOUNT,0,0);
  402. for (iItem=0;iItem<cItemMax;iItem++) {
  403. pPrimitive=(CPrimitive*)SendMessageA(hWnd,LB_GETITEMDATA,(WPARAM)iItem,0);
  404. if (!pPrimitive->m_bRegression)
  405. continue;
  406. ClearAllSettings();
  407. RunTest(&g_HDC,pPrimitive);
  408. }
  409. // Do the settings regression loop
  410. hWnd=GetDlgItem(m_hWndDlg,IDC_SETTINGS);
  411. cItemMax=SendMessageA(hWnd,LB_GETCOUNT,0,0);
  412. for (iItem=0;iItem<cItemMax;iItem++) {
  413. pSetting=(CSetting*)SendMessageA(hWnd,LB_GETITEMDATA,(WPARAM)iItem,0);
  414. if (!pSetting->m_bRegression)
  415. continue;
  416. ClearAllSettings();
  417. pSetting->m_bUseSetting=true;
  418. RunTest(&g_HDC,&g_Regression);
  419. }
  420. EndRun();
  421. }
  422. void CFuncTest::ClearAllSettings()
  423. // Clear all settings to m_bUseSetting=false
  424. {
  425. CSetting *pSetting;
  426. HWND hWnd;
  427. LRESULT cItemMax;
  428. int iItem;
  429. // Set all settings off
  430. hWnd=GetDlgItem(m_hWndDlg,IDC_SETTINGS);
  431. cItemMax=SendMessageA(hWnd,LB_GETCOUNT,0,0);
  432. for (iItem=0;iItem<cItemMax;iItem++) {
  433. pSetting=(CSetting*)SendMessageA(hWnd,LB_GETITEMDATA,(WPARAM)iItem,0);
  434. pSetting->m_bUseSetting=false;
  435. }
  436. }
  437. INT_PTR CALLBACK CFuncTest::DlgProc(HWND hWndDlg,UINT Msg,WPARAM wParam,LPARAM lParam)
  438. // Options dialog proc
  439. {
  440. switch (Msg)
  441. {
  442. case WM_INITDIALOG:
  443. return true;
  444. case WM_COMMAND:
  445. if (HIWORD(wParam)==BN_CLICKED)
  446. {
  447. switch (LOWORD(wParam))
  448. {
  449. case IDC_RUN:
  450. g_FuncTest.Run();
  451. return true;
  452. case IDC_REGRESSION:
  453. g_FuncTest.RunRegression();
  454. return true;
  455. }
  456. }
  457. else if (HIWORD(wParam)==LBN_DBLCLK)
  458. {
  459. switch (LOWORD(wParam))
  460. {
  461. case IDC_PRIMITIVES:
  462. g_FuncTest.Run();
  463. return true;
  464. }
  465. }
  466. break;
  467. case WM_CLOSE:
  468. ShowWindow(hWndDlg,SW_HIDE);
  469. return true;
  470. }
  471. return false;
  472. }
  473. #define UNICODE
  474. #define _UNICODE