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.

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