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.

1113 lines
30 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999-2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * perftest.cpp
  8. *
  9. * Abstract:
  10. *
  11. * Contains the UI and initialization code for the GDI+ performance test.
  12. *
  13. * Revision History:
  14. *
  15. * 01/03/2000 ericvan
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #include "perftest.h"
  20. #include <winuser.h>
  21. #include "../gpinit.inc"
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // Test settings:
  24. BOOL AutoRun = FALSE; // TRUE if invoked from command-line
  25. BOOL ExcelOut = FALSE; // Should we format our output for Excel?
  26. BOOL Regressions = FALSE; // We're running the check-in regressions
  27. BOOL TestRender = FALSE; // Only draw one iteration, for test purposes
  28. BOOL Icecap = FALSE; // Start/stop profiling before and after every test
  29. BOOL FoundIcecap = FALSE; // True if we could find ICECAP.DLL
  30. // Windows state:
  31. HINSTANCE ghInstance = NULL; // Handle to the Application Instance
  32. HBRUSH ghbrWhite = NULL; // white brush handle for background
  33. HWND ghwndMain = NULL;
  34. HWND ghwndStatus = NULL;
  35. // Information about the system:
  36. LPTSTR processor = NULL;
  37. TCHAR osVer[MAX_PATH];
  38. TCHAR deviceName[MAX_PATH];
  39. TCHAR machineName[MAX_PATH];
  40. // Test data:
  41. TestConfig *TestList; // Allocation used for sorting tests
  42. TestResult *ResultsList; // Allocation to track test results
  43. Config ApiList[Api_Count] =
  44. {
  45. { _T("1 - Api - GDI+") },
  46. { _T("1 - Api - GDI") }
  47. };
  48. Config DestinationList[Destination_Count] =
  49. {
  50. { _T("2 - Destination - Screen - Current") },
  51. { _T("2 - Destination - Screen - 800x600x8bppDefaultPalette") },
  52. { _T("2 - Destination - Screen - 800x600x8bppHalftonePalette") },
  53. { _T("2 - Destination - Screen - 800x600x16bpp") },
  54. { _T("2 - Destination - Screen - 800x600x24bpp") },
  55. { _T("2 - Destination - Screen - 800x600x32bpp") },
  56. { _T("2 - Destination - CompatibleBitmap - 8bpp") },
  57. { _T("2 - Destination - DIB - 15bpp") },
  58. { _T("2 - Destination - DIB - 16bpp") },
  59. { _T("2 - Destination - DIB - 24bpp") },
  60. { _T("2 - Destination - DIB - 32bpp") },
  61. { _T("2 - Destination - Bitmap - 32bpp ARGB") },
  62. { _T("2 - Destination - Bitmap - 32bpp PARGB (office cached format)") },
  63. };
  64. Config StateList[State_Count] =
  65. {
  66. { _T("3 - State - Default") },
  67. { _T("3 - State - Antialias") },
  68. };
  69. TestGroup TestGroups[] =
  70. {
  71. DrawTests, DrawTests_Count,
  72. FillTests, FillTests_Count,
  73. ImageTests, ImageTests_Count,
  74. TextTests, TextTests_Count,
  75. OtherTests, OtherTests_Count,
  76. };
  77. INT TestGroups_Count = sizeof(TestGroups) / sizeof(TestGroups[0]);
  78. // Number of test groups
  79. INT Test_Count; // Total number of tests across all groups
  80. /***************************************************************************\
  81. * RegressionsInit
  82. *
  83. * Sets the state for running the standard regressions.
  84. *
  85. \***************************************************************************/
  86. void RegressionsInit()
  87. {
  88. INT i;
  89. DestinationList[Destination_Screen_Current].Enabled = TRUE;
  90. DestinationList[Destination_Bitmap_32bpp_ARGB].Enabled = TRUE;
  91. StateList[State_Default].Enabled = TRUE;
  92. ApiList[Api_GdiPlus].Enabled = TRUE;
  93. ApiList[Api_Gdi].Enabled = TRUE;
  94. for (i = 0; i < Test_Count; i++)
  95. {
  96. TestList[i].Enabled = TRUE;
  97. }
  98. }
  99. /***************************************************************************\
  100. * RestoreInit
  101. *
  102. * Load the 'perftest.ini' file to retrieve all the saved test settings.
  103. *
  104. \***************************************************************************/
  105. void RestoreInit()
  106. {
  107. INT i;
  108. FILE* outfile;
  109. outfile = _tfopen(_T("perftest.ini"), _T("r"));
  110. if (!outfile)
  111. {
  112. // may not have been created yet, first run?!
  113. return;
  114. }
  115. _ftscanf(outfile, _T("%d\n"), &ExcelOut);
  116. INT switchType = -1;
  117. while (!feof(outfile))
  118. {
  119. int tmp = -9999;
  120. _ftscanf(outfile, _T("%d\n"), &tmp);
  121. // Tags are indicated by negative numbers:
  122. if (tmp < 0)
  123. {
  124. switchType = tmp;
  125. }
  126. else
  127. {
  128. // We've figured out the type, now process it:
  129. switch(switchType)
  130. {
  131. case -1:
  132. // Tests are indexed by their unique identifier, because
  133. // they're added to very frequently:
  134. for (i = 0; i < Test_Count; i++)
  135. {
  136. if (TestList[i].TestEntry->UniqueIdentifier == tmp)
  137. {
  138. TestList[i].Enabled = TRUE;
  139. }
  140. }
  141. break;
  142. case -2:
  143. if (tmp < Destination_Count)
  144. DestinationList[tmp].Enabled = TRUE;
  145. break;
  146. case -3:
  147. if (tmp < State_Count)
  148. StateList[tmp].Enabled = TRUE;
  149. break;
  150. case -4:
  151. if (tmp < Api_Count)
  152. ApiList[tmp].Enabled = TRUE;
  153. break;
  154. }
  155. }
  156. }
  157. fclose(outfile);
  158. }
  159. /***************************************************************************\
  160. * SaveInit
  161. *
  162. * Save all the current test settings into a 'perftest.ini' file.
  163. *
  164. \***************************************************************************/
  165. void SaveInit()
  166. {
  167. INT i;
  168. FILE* outfile;
  169. outfile = _tfopen(_T("perftest.ini"), _T("w"));
  170. if (!outfile)
  171. {
  172. MessageF(_T("Can't create: perftest.ini"));
  173. return;
  174. }
  175. // I purposefully do not save the state of 'Icecap' or 'TestRender'
  176. // because they're too annoying when on accidentally.
  177. _ftprintf(outfile, _T("%d\n"), ExcelOut);
  178. _ftprintf(outfile, _T("-1\n")); // Test List
  179. for (i=0; i<Test_Count; i++)
  180. {
  181. // Tests are indexed by their unique identifier, because
  182. // they're added to very frequently:
  183. if (TestList[i].Enabled)
  184. _ftprintf(outfile, _T("%d\n"), TestList[i].TestEntry->UniqueIdentifier);
  185. }
  186. _ftprintf(outfile, _T("-2\n")); // Destination List
  187. for (i=0; i<Destination_Count; i++)
  188. {
  189. if (DestinationList[i].Enabled)
  190. _ftprintf(outfile, _T("%d\n"), i);
  191. }
  192. _ftprintf(outfile, _T("-3\n")); // State List
  193. for (i=0; i<State_Count; i++)
  194. {
  195. if (StateList[i].Enabled)
  196. _ftprintf(outfile, _T("%d\n"), i);
  197. }
  198. _ftprintf(outfile, _T("-4\n")); // Api List
  199. for (i=0; i<Api_Count; i++)
  200. {
  201. if (ApiList[i].Enabled)
  202. _ftprintf(outfile, _T("%d\n"), i);
  203. }
  204. fclose(outfile);
  205. }
  206. /***************************************************************************\
  207. * CmdArgument
  208. *
  209. * search for string and return just after it.
  210. *
  211. \***************************************************************************/
  212. LPSTR CmdArgument(LPSTR arglist, LPSTR arg)
  213. {
  214. LPSTR str = strstr(arglist, arg);
  215. if (str)
  216. return str + strlen(arg);
  217. else
  218. return NULL;
  219. }
  220. /***************************************************************************\
  221. * MessageF
  222. *
  223. * Display a message in a pop-up dialog
  224. *
  225. \***************************************************************************/
  226. VOID
  227. MessageF(
  228. LPTSTR fmt,
  229. ...
  230. )
  231. {
  232. TCHAR buf[1024];
  233. va_list arglist;
  234. va_start(arglist, fmt);
  235. _vstprintf(buf, fmt, arglist);
  236. va_end(arglist);
  237. MessageBox(ghwndMain, &buf[0], _T("PerfTest"), MB_OK | MB_ICONEXCLAMATION);
  238. }
  239. /***************************************************************************\
  240. * UpdateList
  241. *
  242. * Update the active tests according to whatever is enabled in the list-
  243. * boxes.
  244. *
  245. \***************************************************************************/
  246. void
  247. UpdateList(
  248. HWND hwnd
  249. )
  250. {
  251. INT i;
  252. HWND hwndIcecap = GetDlgItem(hwnd, IDC_ICECAP);
  253. Icecap=
  254. (SendMessage(hwndIcecap, BM_GETCHECK, 0, 0) == BST_CHECKED);
  255. DeleteObject(hwndIcecap);
  256. HWND hwndTestRender = GetDlgItem(hwnd, IDC_TESTRENDER);
  257. TestRender=
  258. (SendMessage(hwndTestRender, BM_GETCHECK, 0, 0) == BST_CHECKED);
  259. DeleteObject(hwndTestRender);
  260. HWND hwndExcel = GetDlgItem(hwnd, IDC_EXCELOUT);
  261. ExcelOut=
  262. (SendMessage(hwndExcel, BM_GETCHECK, 0, 0) == BST_CHECKED);
  263. DeleteObject(hwndExcel);
  264. // iterate through test case list and flag enabled/disabled
  265. HWND hwndList = GetDlgItem(hwnd, IDC_TESTLIST);
  266. for (i=0; i<Api_Count; i++)
  267. ApiList[i].Enabled =
  268. (SendMessage(hwndList,
  269. LB_FINDSTRINGEXACT,
  270. -1,
  271. (LPARAM) ApiList[i].Description) != LB_ERR);
  272. for (i=0; i<Destination_Count; i++)
  273. DestinationList[i].Enabled =
  274. (SendMessage(hwndList,
  275. LB_FINDSTRINGEXACT,
  276. -1,
  277. (LPARAM) DestinationList[i].Description) != LB_ERR);
  278. for (i=0; i<State_Count; i++)
  279. StateList[i].Enabled =
  280. (SendMessage(hwndList,
  281. LB_FINDSTRINGEXACT,
  282. 0,
  283. (LPARAM) StateList[i].Description) != LB_ERR);
  284. for (i=0; i<Test_Count; i++)
  285. TestList[i].Enabled =
  286. (SendMessage(hwndList,
  287. LB_FINDSTRINGEXACT,
  288. -1,
  289. (LPARAM) TestList[i].TestEntry->Description) != LB_ERR);
  290. DeleteObject(hwndList);
  291. }
  292. /***************************************************************************\
  293. * MainWindowProc
  294. *
  295. * Windows call-back procedure.
  296. *
  297. \***************************************************************************/
  298. LRESULT
  299. MainWindowProc(
  300. HWND hwnd,
  301. UINT message,
  302. WPARAM wParam,
  303. LPARAM lParam
  304. )
  305. {
  306. PAINTSTRUCT ps;
  307. switch (message)
  308. {
  309. case WM_CREATE:
  310. if (Regressions)
  311. RegressionsInit();
  312. else
  313. RestoreInit();
  314. break;
  315. case WM_DISPLAYCHANGE:
  316. case WM_SIZE:
  317. TCHAR windText[MAX_PATH];
  318. GetWindowText(ghwndStatus, &windText[0], MAX_PATH);
  319. DestroyWindow(ghwndStatus);
  320. ghwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE,
  321. _T("Performance Test Application"),
  322. ghwndMain,
  323. -1);
  324. SetWindowText(ghwndStatus, &windText[0]);
  325. break;
  326. case WM_COMMAND:
  327. switch(LOWORD(wParam))
  328. {
  329. case IDM_QUIT:
  330. if (!Regressions)
  331. {
  332. UpdateList(hwnd);
  333. SaveInit();
  334. }
  335. exit(0);
  336. break;
  337. default:
  338. MessageBox(hwnd,
  339. _T("Help Me - I've Fallen and Can't Get Up!"),
  340. _T("Help!"),
  341. MB_OK);
  342. break;
  343. }
  344. break;
  345. case WM_DESTROY:
  346. PostQuitMessage(0);
  347. DeleteObject(ghbrWhite);
  348. return(DefWindowProc(hwnd, message, wParam, lParam));
  349. default:
  350. return(DefWindowProc(hwnd, message, wParam, lParam));
  351. }
  352. return(0);
  353. }
  354. /***************************************************************************\
  355. * GetSystemInformation
  356. *
  357. * Initializes some globals describing the current system.
  358. *
  359. \***************************************************************************/
  360. void
  361. GetSystemInformation()
  362. {
  363. // Getting machine name assumes we have TCP/IP setup. However, this
  364. // is true in all of our cases.
  365. LPCTSTR TCPIP_PARAMS_KEY =
  366. _T("System\\CurrentControlSet\\Services\\Tcpip\\Parameters");
  367. DWORD size;
  368. HKEY hKeyHostname;
  369. DWORD type;
  370. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  371. TCPIP_PARAMS_KEY,
  372. 0,
  373. KEY_READ,
  374. &hKeyHostname) == ERROR_SUCCESS)
  375. {
  376. size = sizeof(machineName);
  377. if (RegQueryValueEx(hKeyHostname,
  378. _T("Hostname"),
  379. NULL,
  380. (LPDWORD)&type,
  381. (LPBYTE)&machineName[0],
  382. (LPDWORD)&size) == ERROR_SUCCESS)
  383. {
  384. if (type != REG_SZ)
  385. {
  386. lstrcpy(&machineName[0], _T("Unknown"));
  387. }
  388. }
  389. RegCloseKey(hKeyHostname);
  390. }
  391. OSVERSIONINFO osver;
  392. osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  393. GetVersionEx(&osver);
  394. _stprintf(&osVer[0], _T("%s %d.%02d"),
  395. osver.dwPlatformId == VER_PLATFORM_WIN32_NT ?
  396. _T("Windows NT") : _T("Windows 9x"),
  397. osver.dwMajorVersion,
  398. osver.dwMinorVersion);
  399. SYSTEM_INFO sysinfo;
  400. GetSystemInfo(&sysinfo);
  401. if (osver.dwPlatformId = VER_PLATFORM_WIN32_NT)
  402. {
  403. // we are assuming wProcessorArchitecture==PROCESSOR_ARCHITECTURE_INTEL
  404. // WinNT processor
  405. switch (sysinfo.wProcessorLevel)
  406. {
  407. case 3: processor = _T("Intel 80386"); break;
  408. case 4: processor = _T("Intel 80486"); break;
  409. case 5: processor = _T("Intel Pentium"); break;
  410. case 6: processor = _T("Intel Pentium Pro or Pentium II"); break;
  411. default: processor = _T("???"); break;
  412. }
  413. }
  414. else // win 9x
  415. {
  416. switch (sysinfo.dwProcessorType)
  417. {
  418. case PROCESSOR_INTEL_386: processor = _T("Intel 80386"); break;
  419. case PROCESSOR_INTEL_486: processor = _T("Intel 80486"); break;
  420. case PROCESSOR_INTEL_PENTIUM: processor = _T("Intel Pentium"); break;
  421. default: processor = _T("???");
  422. }
  423. }
  424. // Query the driver name:
  425. DEVMODE devMode;
  426. devMode.dmSize = sizeof(DEVMODE);
  427. devMode.dmDriverExtra = 0;
  428. INT result = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devMode);
  429. _tcscpy(deviceName, (result) ? (TCHAR*) &devMode.dmDeviceName[0] : _T("Unknown"));
  430. }
  431. INT CurrentTestIndex;
  432. CHAR CurrentTestDescription[2048];
  433. ICCONTROLPROFILEFUNC ICStartProfile=NULL, ICStopProfile=NULL;
  434. ICCOMMENTMARKPROFILEFUNC ICCommentMarkProfile=NULL;
  435. /***************************************************************************\
  436. * LoadIcecap
  437. *
  438. * Try to dynamically load ICECAP.DLL
  439. * If we fail, disable the check box
  440. *
  441. \***************************************************************************/
  442. void LoadIcecap(HWND checkBox)
  443. {
  444. if (!FoundIcecap)
  445. {
  446. HMODULE module = LoadLibraryA("icecap.dll");
  447. if (module)
  448. {
  449. ICStartProfile = (ICCONTROLPROFILEFUNC) GetProcAddress(module, "StartProfile");
  450. ICStopProfile = (ICCONTROLPROFILEFUNC) GetProcAddress(module, "StopProfile");
  451. ICCommentMarkProfile = (ICCOMMENTMARKPROFILEFUNC) GetProcAddress(module, "CommentMarkProfile");
  452. if (ICStartProfile && ICStopProfile && ICCommentMarkProfile)
  453. {
  454. EnableWindow(checkBox, TRUE);
  455. FoundIcecap = TRUE;
  456. return;
  457. }
  458. }
  459. EnableWindow(checkBox, FALSE);
  460. Icecap = FALSE;
  461. }
  462. }
  463. /***************************************************************************\
  464. * DialogProc
  465. *
  466. * Dialog call-back procedure.
  467. *
  468. \***************************************************************************/
  469. INT_PTR
  470. DialogProc(
  471. HWND hwnd,
  472. UINT message,
  473. WPARAM wParam,
  474. LPARAM lParam
  475. )
  476. {
  477. PAINTSTRUCT ps;
  478. switch (message)
  479. {
  480. case WM_INITDIALOG:
  481. {
  482. {
  483. INT i;
  484. HWND hwndTemp;
  485. HWND hwndTemp2;
  486. TCHAR fileName[MAX_PATH];
  487. hwndTemp = GetDlgItem(hwnd, IDC_PROCESSOR);
  488. SetWindowText(hwndTemp, processor);
  489. DeleteObject(hwndTemp);
  490. hwndTemp = GetDlgItem(hwnd, IDC_FILE);
  491. GetOutputFileName(fileName);
  492. SetWindowText(hwndTemp, fileName);
  493. DeleteObject(hwndTemp);
  494. hwndTemp = GetDlgItem(hwnd, IDC_OS);
  495. SetWindowText(hwndTemp, &osVer[0]);
  496. DeleteObject(hwndTemp);
  497. hwndTemp = GetDlgItem(hwnd, IDC_VDRIVER);
  498. SetWindowText(hwndTemp, deviceName);
  499. DeleteObject(hwndTemp);
  500. hwndTemp = GetDlgItem(hwnd, IDC_ICECAP);
  501. LoadIcecap(hwndTemp);
  502. SendMessage(hwndTemp, BM_SETCHECK, (WPARAM) (Icecap ?
  503. BST_CHECKED :
  504. BST_UNCHECKED), 0);
  505. DeleteObject(hwndTemp);
  506. hwndTemp = GetDlgItem(hwnd, IDC_TESTRENDER);
  507. SendMessage(hwndTemp, BM_SETCHECK, (WPARAM) (TestRender ?
  508. BST_CHECKED :
  509. BST_UNCHECKED), 0);
  510. DeleteObject(hwndTemp);
  511. hwndTemp = GetDlgItem(hwnd, IDC_EXCELOUT);
  512. SendMessage(hwndTemp, BM_SETCHECK, (WPARAM) (ExcelOut ?
  513. BST_CHECKED :
  514. BST_UNCHECKED), 0);
  515. DeleteObject(hwndTemp);
  516. // populate the perf test scenarios
  517. hwndTemp = GetDlgItem(hwnd, IDC_TESTLIST);
  518. hwndTemp2 = GetDlgItem(hwnd, IDC_SKIPLIST);
  519. for (i=0; i<Api_Count; i++)
  520. {
  521. if (ApiList[i].Description)
  522. {
  523. SendMessage(ApiList[i].Enabled ? hwndTemp : hwndTemp2,
  524. LB_ADDSTRING,
  525. 0,
  526. (LPARAM) ApiList[i].Description);
  527. }
  528. }
  529. for (i=0; i<Destination_Count; i++)
  530. {
  531. if (DestinationList[i].Description)
  532. {
  533. SendMessage(DestinationList[i].Enabled ? hwndTemp : hwndTemp2,
  534. LB_ADDSTRING,
  535. 0,
  536. (LPARAM) DestinationList[i].Description);
  537. }
  538. }
  539. for (i=0; i<State_Count; i++)
  540. {
  541. if (StateList[i].Description)
  542. {
  543. SendMessage(StateList[i].Enabled ? hwndTemp : hwndTemp2,
  544. LB_ADDSTRING,
  545. 0,
  546. (LPARAM) StateList[i].Description);
  547. }
  548. }
  549. for (i=0; i<Test_Count; i++)
  550. {
  551. if (TestList[i].TestEntry->Description)
  552. {
  553. SendMessage(TestList[i].Enabled ? hwndTemp : hwndTemp2,
  554. LB_ADDSTRING,
  555. 0,
  556. (LPARAM) TestList[i].TestEntry->Description);
  557. }
  558. }
  559. DeleteObject(hwndTemp);
  560. return FALSE;
  561. }
  562. }
  563. break;
  564. case WM_COMMAND:
  565. WORD wCommand = LOWORD(wParam);
  566. switch(wCommand)
  567. {
  568. case IDOK:
  569. {
  570. UpdateList(hwnd);
  571. ShowWindow(hwnd, SW_HIDE);
  572. // start running the tests
  573. {
  574. TestSuite testSuite;
  575. testSuite.Run(ghwndMain);
  576. }
  577. ShowWindow(hwnd, SW_SHOW);
  578. return TRUE;
  579. }
  580. break;
  581. case IDC_ADDTEST:
  582. {
  583. TCHAR temp[MAX_PATH];
  584. HWND hwndTestList = GetDlgItem(hwnd, IDC_TESTLIST);
  585. HWND hwndNopeList = GetDlgItem(hwnd, IDC_SKIPLIST);
  586. LRESULT curSel = SendMessage(hwndNopeList, LB_GETCURSEL, 0, 0);
  587. if (curSel != LB_ERR)
  588. {
  589. SendMessage(hwndNopeList,
  590. LB_GETTEXT,
  591. (WPARAM) curSel,
  592. (LPARAM) &temp[0]);
  593. SendMessage(hwndNopeList,
  594. LB_DELETESTRING,
  595. (WPARAM) curSel,
  596. 0);
  597. SendMessage(hwndTestList,
  598. LB_ADDSTRING,
  599. 0,
  600. (LPARAM) &temp[0]);
  601. }
  602. DeleteObject(hwndTestList);
  603. DeleteObject(hwndNopeList);
  604. }
  605. break;
  606. case IDC_DELTEST:
  607. {
  608. TCHAR temp[MAX_PATH];
  609. HWND hwndTestList = GetDlgItem(hwnd, IDC_TESTLIST);
  610. HWND hwndNopeList = GetDlgItem(hwnd, IDC_SKIPLIST);
  611. LRESULT curSel = SendMessage(hwndTestList, LB_GETCURSEL, 0, 0);
  612. if (curSel != LB_ERR)
  613. {
  614. SendMessage(hwndTestList,
  615. LB_GETTEXT,
  616. (WPARAM) curSel,
  617. (LPARAM) &temp[0]);
  618. SendMessage(hwndTestList,
  619. LB_DELETESTRING,
  620. (WPARAM) curSel,
  621. 0);
  622. SendMessage(hwndNopeList,
  623. LB_ADDSTRING,
  624. 0,
  625. (LPARAM) &temp[0]);
  626. }
  627. DeleteObject(hwndTestList);
  628. DeleteObject(hwndNopeList);
  629. }
  630. break;
  631. case IDC_DELALLTEST:
  632. case IDC_ADDALLTEST:
  633. {
  634. TCHAR temp[MAX_PATH];
  635. HWND hwndTestList;
  636. HWND hwndNopeList;
  637. if (wCommand == IDC_DELALLTEST)
  638. {
  639. hwndTestList = GetDlgItem(hwnd, IDC_TESTLIST);
  640. hwndNopeList = GetDlgItem(hwnd, IDC_SKIPLIST);
  641. }
  642. else
  643. {
  644. hwndTestList = GetDlgItem(hwnd, IDC_SKIPLIST);
  645. hwndNopeList = GetDlgItem(hwnd, IDC_TESTLIST);
  646. }
  647. LRESULT count = SendMessage(hwndTestList, LB_GETCOUNT, 0, 0);
  648. LRESULT curSel;
  649. for (curSel = count - 1; curSel >= 0; curSel--)
  650. {
  651. SendMessage(hwndTestList,
  652. LB_GETTEXT,
  653. (WPARAM) curSel,
  654. (LPARAM) &temp[0]);
  655. SendMessage(hwndTestList,
  656. LB_DELETESTRING,
  657. (WPARAM) curSel,
  658. 0);
  659. SendMessage(hwndNopeList,
  660. LB_ADDSTRING,
  661. 0,
  662. (LPARAM) &temp[0]);
  663. }
  664. DeleteObject(hwndTestList);
  665. DeleteObject(hwndNopeList);
  666. }
  667. break;
  668. case IDCANCEL:
  669. if (!Regressions)
  670. {
  671. UpdateList(hwnd);
  672. SaveInit();
  673. }
  674. exit(-1);
  675. return TRUE;
  676. case WM_CLOSE:
  677. if (!Regressions)
  678. {
  679. UpdateList(hwnd);
  680. SaveInit();
  681. }
  682. DestroyWindow(hwnd);
  683. return TRUE;
  684. }
  685. break;
  686. }
  687. return FALSE;
  688. }
  689. /***************************************************************************\
  690. * TestComparison
  691. *
  692. * Comparitor function for sorting the tests by Description.
  693. *
  694. \***************************************************************************/
  695. int _cdecl TestComparison(const void *a, const void *b)
  696. {
  697. const TestConfig* testA = static_cast<const TestConfig*>(a);
  698. const TestConfig* testB = static_cast<const TestConfig*>(b);
  699. return(_tcscmp(testA->TestEntry->Description, testB->TestEntry->Description));
  700. }
  701. /***************************************************************************\
  702. * InitializeTests()
  703. *
  704. * Initializes test state.
  705. *
  706. \***************************************************************************/
  707. BOOL InitializeTests()
  708. {
  709. INT i;
  710. INT j;
  711. TestConfig* testList;
  712. // Count the total number of tests:
  713. Test_Count = 0;
  714. for (i = 0; i < TestGroups_Count; i++)
  715. {
  716. Test_Count += TestGroups[i].Count;
  717. }
  718. // Create one tracking array:
  719. TestList = static_cast<TestConfig*>
  720. (malloc(sizeof(TestConfig) * Test_Count));
  721. if (TestList == NULL)
  722. return(FALSE);
  723. // Initialize the tracking array and sort it by description:
  724. testList = TestList;
  725. for (i = 0; i < TestGroups_Count; i++)
  726. {
  727. for (j = 0; j < TestGroups[i].Count; j++)
  728. {
  729. testList->Enabled = FALSE;
  730. testList->TestEntry = &TestGroups[i].Tests[j];
  731. testList++;
  732. }
  733. }
  734. qsort(TestList, Test_Count, sizeof(TestList[0]), TestComparison);
  735. // Now do some validation, by verifying that there is no repeated
  736. // uniqueness number:
  737. for (i = 0; i < Test_Count; i++)
  738. {
  739. for (j = i + 1; j < Test_Count; j++)
  740. {
  741. if (TestList[i].TestEntry->UniqueIdentifier ==
  742. TestList[j].TestEntry->UniqueIdentifier)
  743. {
  744. MessageF(_T("Oops, there are two test functions with the same unique identifier: %li. Please fix."),
  745. TestList[i].TestEntry->UniqueIdentifier);
  746. return(FALSE);
  747. }
  748. }
  749. }
  750. // Allocate our 3 dimensional results array:
  751. ResultsList = static_cast<TestResult*>
  752. (malloc(sizeof(TestResult) * ResultCount()));
  753. if (ResultsList == NULL)
  754. return(FALSE);
  755. for (i = 0; i < ResultCount(); i++)
  756. {
  757. ResultsList[i].Score = 0.0f;
  758. }
  759. return(TRUE);
  760. }
  761. /***************************************************************************\
  762. * UninitializeTests()
  763. *
  764. * Initializes tests.
  765. *
  766. \***************************************************************************/
  767. VOID UninitializeTests()
  768. {
  769. free(ResultsList);
  770. free(TestList);
  771. }
  772. /***************************************************************************\
  773. * InitializeApplication()
  774. *
  775. * Initializes app.
  776. *
  777. \***************************************************************************/
  778. BOOL InitializeApplication(VOID)
  779. {
  780. WNDCLASS wc;
  781. if (!InitializeTests())
  782. {
  783. return(FALSE);
  784. }
  785. GetSystemInformation();
  786. ghbrWhite = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
  787. wc.style = 0;
  788. wc.lpfnWndProc = MainWindowProc;
  789. wc.cbClsExtra = 0;
  790. wc.cbWndExtra = 0;
  791. wc.hInstance = ghInstance;
  792. wc.hIcon = NULL;
  793. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  794. wc.hbrBackground = ghbrWhite;
  795. wc.lpszMenuName = NULL;
  796. wc.lpszClassName = _T("TestClass");
  797. if (!RegisterClass(&wc))
  798. {
  799. return(FALSE);
  800. }
  801. ghwndMain = CreateWindowEx(
  802. 0,
  803. _T("TestClass"),
  804. _T("GDI+ Performance Test"),
  805. WS_OVERLAPPED |
  806. WS_CAPTION |
  807. WS_BORDER |
  808. WS_THICKFRAME |
  809. WS_MAXIMIZEBOX |
  810. WS_MINIMIZEBOX |
  811. WS_CLIPCHILDREN |
  812. WS_VISIBLE |
  813. WS_MAXIMIZE |
  814. WS_SYSMENU,
  815. 80,
  816. 70,
  817. 500,
  818. 500,
  819. NULL,
  820. NULL,
  821. ghInstance,
  822. NULL);
  823. if (ghwndMain == NULL)
  824. {
  825. return(FALSE);
  826. }
  827. SetFocus(ghwndMain);
  828. ghwndStatus = CreateStatusWindow(WS_CHILD|WS_VISIBLE,
  829. _T("Performance Test Application"),
  830. ghwndMain,
  831. -1);
  832. return(TRUE);
  833. }
  834. /***************************************************************************\
  835. * main(argc, argv[])
  836. *
  837. * Sets up the message loop.
  838. *
  839. \***************************************************************************/
  840. _cdecl
  841. main(
  842. INT argc,
  843. PCHAR argv[]
  844. )
  845. {
  846. MSG msg;
  847. HACCEL haccel;
  848. CHAR* pSrc;
  849. CHAR* pDst;
  850. if (!gGdiplusInitHelper.IsValid())
  851. {
  852. return 0;
  853. }
  854. INT curarg = 1;
  855. while (curarg < argc)
  856. {
  857. if (CmdArgument(argv[curarg],"/?") ||
  858. CmdArgument(argv[curarg],"/h") ||
  859. CmdArgument(argv[curarg],"/H"))
  860. {
  861. MessageF(_T("GDI+ Perf Test\n")
  862. _T("==============\n")
  863. _T("\n")
  864. _T("/b Run batch mode\n")
  865. _T("/e Excel output format\n")
  866. _T("/r Regressions\n"));
  867. exit(-1);
  868. }
  869. if (CmdArgument(argv[curarg],"/b"))
  870. AutoRun = TRUE;
  871. if (CmdArgument(argv[curarg],"/e"))
  872. ExcelOut = TRUE;
  873. if (CmdArgument(argv[curarg],"/r"))
  874. Regressions = TRUE;
  875. curarg++;
  876. }
  877. ghInstance = GetModuleHandle(NULL);
  878. if (!InitializeApplication())
  879. {
  880. return(0);
  881. }
  882. // turn batching off to get true timing per call
  883. GdiSetBatchLimit(1);
  884. if (AutoRun)
  885. {
  886. // start running the tests
  887. TestSuite testSuite;
  888. testSuite.Run(ghwndMain);
  889. }
  890. else
  891. {
  892. HWND hwndDlg = CreateDialog(ghInstance,
  893. MAKEINTRESOURCE(IDD_STARTDIALOG),
  894. ghwndMain,
  895. &DialogProc);
  896. while (GetMessage(&msg, NULL, 0, 0))
  897. {
  898. TranslateMessage(&msg);
  899. DispatchMessage(&msg);
  900. }
  901. }
  902. UninitializeTests();
  903. return(1);
  904. }