Source code of Windows XP (NT5)
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.

3111 lines
96 KiB

  1. /**------------------------------------------------------------------
  2. regress.c
  3. ------------------------------------------------------------------**/
  4. //
  5. // Includes
  6. //
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <wtypes.h>
  11. #include <cfgmgr32.h>
  12. #include <malloc.h>
  13. #include <regstr.h>
  14. #include "cmtest.h"
  15. //
  16. // Private Prototypes
  17. //
  18. VOID
  19. RegressionTest_Range(
  20. HWND hDlg
  21. );
  22. VOID
  23. RegressionTest_Class(
  24. HWND hDlg
  25. );
  26. VOID
  27. RegressionTest_Traverse(
  28. HWND hDlg
  29. );
  30. VOID
  31. RegressionTest_HardwareProfile(
  32. HWND hDlg
  33. );
  34. VOID
  35. RegressionTest_DeviceList(
  36. HWND hDlg
  37. );
  38. VOID
  39. RegressionTest_LogConf(
  40. HWND hDlg
  41. );
  42. VOID
  43. RegressionTest_CreateDevNode(
  44. HWND hDlg
  45. );
  46. VOID
  47. RegressionTest_Properties(
  48. HWND hDlg
  49. );
  50. VOID
  51. RegressionTest_DeviceClass(
  52. HWND hDlg
  53. );
  54. BOOL
  55. DisplayRange(
  56. IN HWND hDlg,
  57. IN RANGE_LIST rlh
  58. );
  59. BOOL
  60. TraverseAndCheckParents (
  61. DEVNODE dnParent
  62. );
  63. //
  64. // Globals
  65. //
  66. TCHAR szPresentDeviceID[] = TEXT("Test\\Present\\0000");
  67. TCHAR szNonExistantDeviceID[] = TEXT("Test\\XXX\\0000");
  68. TCHAR szInvalidDeviceID[] = TEXT("Test\\0000");
  69. TCHAR szNotFoundDeviceID[] = TEXT("Test\\NotFound\\0000");
  70. TCHAR szMovedDeviceID[] = TEXT("Test\\Moved\\0000");
  71. TCHAR szNoBaseDeviceID[] = TEXT("Test\\NoBaseDevice\\0000");
  72. TCHAR szMissingParentDeviceID[] = TEXT("Test\\ParentMissing\\0000");
  73. TCHAR szNotFoundParentDeviceID[] = TEXT("Test\\ParentNotFound\\0000");
  74. TCHAR szMovedParentDeviceID[] = TEXT("Test\\ParentMoved\\0000");
  75. TCHAR szNoAttachedDeviceID[] = TEXT("Test\\NoAttachedComponents\\0000");
  76. TCHAR szMissingChildDeviceID[] = TEXT("Test\\ChildMissing\\0000");
  77. TCHAR szNotFoundChildDeviceID[] = TEXT("Test\\ChildNotFound\\0000");
  78. TCHAR szMovedChildDeviceID[] = TEXT("Test\\ChildMoved\\0000");
  79. TCHAR szValid2ndChildDeviceID[] = TEXT("Test\\Valid2ndChild\\0000");
  80. TCHAR szMissingSiblingDeviceID[] = TEXT("Test\\SiblingMissing\\0000");
  81. TCHAR szNotFoundSiblingDeviceID[] = TEXT("Test\\SiblingNotFound\\0000");
  82. TCHAR szMovedSiblingDeviceID[] = TEXT("Test\\SiblingMoved\\0000");
  83. TCHAR szValid3rdChildDeviceID[] = TEXT("Test\\Valid3rdChild\\0000");
  84. TCHAR szEnabledDeviceID[] = TEXT("Test\\Enabled\\0000");
  85. TCHAR szDisabledDeviceID[] = TEXT("Test\\Disabled\\0000");
  86. TCHAR szCreateDeviceID[] = TEXT("Test\\Create\\0000");
  87. TCHAR szDoNotCreateDeviceID[] = TEXT("Test\\DoNotCreate\\0000");
  88. TCHAR szPhantomDeviceID[] = TEXT("Test\\Phantom\\0000");
  89. TCHAR szRemoveDeviceID[] = TEXT("Test\\Remove\\0000");
  90. TCHAR szClassGuid_0[] = TEXT("{00000000-0000-0000-0000-000000000000}");
  91. TCHAR szClassGuid_None[] = TEXT("{99999999-9999-9999-9999-999999999999}");
  92. TCHAR szDev_MovedTo[] = TEXT("TEST\\MovedTo\\0000");
  93. TCHAR szDev_MovedFrom[] = TEXT("TEXT\\MovedFrom\\0000");
  94. extern HMACHINE hMachine;
  95. /**----------------------------------------------------------------------**/
  96. LRESULT CALLBACK
  97. RegressionDlgProc(
  98. HWND hDlg,
  99. UINT message,
  100. WPARAM wParam,
  101. LPARAM lParam
  102. )
  103. {
  104. CONFIGRET Status = CR_SUCCESS;
  105. TCHAR szDeviceID[MAX_DEVICE_ID_LEN];
  106. TCHAR szParentID[MAX_DEVICE_ID_LEN];
  107. DEVNODE dnDevNode, dnParentDevNode;
  108. ULONG ulFlags;
  109. switch (message) {
  110. case WM_INITDIALOG:
  111. SetDlgItemText(hDlg, ID_ST_PARENT, (LPCTSTR)lParam);
  112. CheckDlgButton(hDlg, ID_RD_NORMAL, 1);
  113. return TRUE;
  114. case WM_COMMAND:
  115. switch(LOWORD(wParam)) {
  116. case IDOK:
  117. EndDialog(hDlg, TRUE);
  118. return TRUE;
  119. case ID_BT_CLEAR:
  120. SendDlgItemMessage(
  121. hDlg, ID_LB_REGRESSION, LB_RESETCONTENT, 0, 0);
  122. break;
  123. case ID_BT_START:
  124. if (IsDlgButtonChecked(hDlg, ID_CHK_RANGE)) {
  125. RegressionTest_Range(hDlg);
  126. }
  127. if (IsDlgButtonChecked(hDlg, ID_CHK_CLASS)) {
  128. RegressionTest_Class(hDlg);
  129. }
  130. if (IsDlgButtonChecked(hDlg, ID_CHK_TRAVERSE)) {
  131. RegressionTest_Traverse(hDlg);
  132. }
  133. if (IsDlgButtonChecked(hDlg, ID_CHK_HWPROF)) {
  134. RegressionTest_HardwareProfile(hDlg);
  135. }
  136. if (IsDlgButtonChecked(hDlg, ID_CHK_DEVLIST)) {
  137. RegressionTest_DeviceList(hDlg);
  138. }
  139. if (IsDlgButtonChecked(hDlg, ID_CHK_LOGCONF)) {
  140. RegressionTest_LogConf(hDlg);
  141. }
  142. if (IsDlgButtonChecked(hDlg, ID_CHK_CREATE)) {
  143. RegressionTest_CreateDevNode(hDlg);
  144. }
  145. if (IsDlgButtonChecked(hDlg, ID_CHK_PROPERTIES)) {
  146. RegressionTest_Properties(hDlg);
  147. }
  148. if (IsDlgButtonChecked(hDlg, ID_CHK_DEVCLASS)) {
  149. RegressionTest_DeviceClass(hDlg);
  150. }
  151. }
  152. break;
  153. }
  154. return FALSE;
  155. } // RegressionDlgProc
  156. //-----------------------------------------------------------------------------
  157. VOID
  158. RegressionTest_Range(
  159. HWND hDlg
  160. )
  161. {
  162. CONFIGRET Status = CR_SUCCESS;
  163. RANGE_LIST rlh1, rlh2, rlh3;
  164. RANGE_ELEMENT rElement;
  165. DWORDLONG ullStart, ullEnd;
  166. TCHAR szMsg[MAX_PATH], szMsg1[MAX_PATH];
  167. lstrcpy(szMsg, TEXT("1. Create Range List: "));
  168. Status = CM_Create_Range_List(&rlh1, 0);
  169. if (Status != CR_SUCCESS) {
  170. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  171. }
  172. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  173. lstrcat(szMsg, szMsg1);
  174. SendDlgItemMessage(
  175. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  176. (LPARAM)(LPTSTR)szMsg);
  177. //------------------------------------------------------
  178. // Add range test
  179. //------------------------------------------------------
  180. lstrcpy(szMsg, TEXT("2. Add Ranges: "));
  181. Status = CM_Add_Range(12, 15, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  182. if (Status != CR_SUCCESS) {
  183. wsprintf(szMsg1, TEXT("(12,15) Failed (%xh)"), Status);
  184. goto DoneAddingRanges;
  185. }
  186. DisplayRange(hDlg, rlh1);
  187. Status = CM_Add_Range(7, 9, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  188. if (Status != CR_SUCCESS) {
  189. wsprintf(szMsg1, TEXT("(7,9) Failed (%xh)"), Status);
  190. goto DoneAddingRanges;
  191. }
  192. DisplayRange(hDlg, rlh1);
  193. Status = CM_Add_Range(21, 25, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  194. if (Status != CR_SUCCESS) {
  195. wsprintf(szMsg1, TEXT("(21,25) Failed (%xh)"), Status);
  196. goto DoneAddingRanges;
  197. }
  198. DisplayRange(hDlg, rlh1);
  199. // A1
  200. Status = CM_Add_Range(4, 5, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  201. if (Status != CR_SUCCESS) {
  202. wsprintf(szMsg1, TEXT("(4,5) Failed (%xh)"), Status);
  203. goto DoneAddingRanges;
  204. }
  205. DisplayRange(hDlg, rlh1);
  206. // A2
  207. Status = CM_Add_Range(11, 13, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  208. if (Status != CR_SUCCESS) {
  209. wsprintf(szMsg1, TEXT("(11,13) Failed (%xh)"), Status);
  210. goto DoneAddingRanges;
  211. }
  212. DisplayRange(hDlg, rlh1);
  213. // A3
  214. Status = CM_Add_Range(20, 26, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  215. if (Status != CR_SUCCESS) {
  216. wsprintf(szMsg1, TEXT("(20,26) Failed (%xh)"), Status);
  217. goto DoneAddingRanges;
  218. }
  219. DisplayRange(hDlg, rlh1);
  220. // B1
  221. Status = CM_Add_Range(6, 8, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  222. if (Status != CR_SUCCESS) {
  223. wsprintf(szMsg1, TEXT("(6,8) Failed (%xh)"), Status);
  224. goto DoneAddingRanges;
  225. }
  226. DisplayRange(hDlg, rlh1);
  227. // B2
  228. Status = CM_Add_Range(14, 16, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  229. if (Status != CR_SUCCESS) {
  230. wsprintf(szMsg1, TEXT("(14,16) Failed (%xh)"), Status);
  231. goto DoneAddingRanges;
  232. }
  233. DisplayRange(hDlg, rlh1);
  234. // special cases
  235. Status = CM_Add_Range(10, 14, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  236. if (Status != CR_SUCCESS) {
  237. wsprintf(szMsg1, TEXT("(10,14) Failed (%xh)"), Status);
  238. goto DoneAddingRanges;
  239. }
  240. DisplayRange(hDlg, rlh1);
  241. // add "join" cases
  242. DoneAddingRanges:
  243. lstrcat(szMsg, szMsg1);
  244. SendDlgItemMessage(
  245. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  246. (LPARAM)(LPTSTR)szMsg);
  247. // conflict cases
  248. Status = CM_Add_Range(2, 4, rlh1, CM_ADD_RANGE_DONOTADDIFCONFLICT);
  249. if (Status != CR_FAILURE) {
  250. wsprintf(szMsg, TEXT("(2,4) Should've Failed due to conflict"));
  251. SendDlgItemMessage(
  252. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  253. (LPARAM)(LPTSTR)szMsg);
  254. }
  255. Status = CM_Add_Range(20, 22, rlh1, CM_ADD_RANGE_DONOTADDIFCONFLICT);
  256. if (Status != CR_FAILURE) {
  257. wsprintf(szMsg, TEXT("(20,22) Should've Failed due to conflict"));
  258. SendDlgItemMessage(
  259. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  260. (LPARAM)(LPTSTR)szMsg);
  261. }
  262. Status = CM_Add_Range(10, 12, rlh1, CM_ADD_RANGE_DONOTADDIFCONFLICT);
  263. if (Status != CR_FAILURE) {
  264. wsprintf(szMsg, TEXT("(10,12) Should've Failed due to conflict"));
  265. SendDlgItemMessage(
  266. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  267. (LPARAM)(LPTSTR)szMsg);
  268. }
  269. Status = CM_Add_Range(26, 28, rlh1, CM_ADD_RANGE_DONOTADDIFCONFLICT);
  270. if (Status != CR_FAILURE) {
  271. wsprintf(szMsg, TEXT("(26,28) Should've Failed due to conflict"));
  272. SendDlgItemMessage(
  273. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  274. (LPARAM)(LPTSTR)szMsg);
  275. }
  276. Status = CM_Add_Range(18, 30, rlh1, CM_ADD_RANGE_DONOTADDIFCONFLICT);
  277. if (Status != CR_FAILURE) {
  278. wsprintf(szMsg, TEXT("(18,30) Should've Failed due to conflict"));
  279. SendDlgItemMessage(
  280. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  281. (LPARAM)(LPTSTR)szMsg);
  282. }
  283. //------------------------------------------------------
  284. // Duplicate range list test
  285. //------------------------------------------------------
  286. SendDlgItemMessage(
  287. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  288. (LPARAM)(LPTSTR)TEXT("_____Duplicate Range List Test__________"));
  289. Status = CM_Create_Range_List(&rlh2, 0);
  290. if (Status != CR_SUCCESS) {
  291. wsprintf(szMsg1, TEXT("CM_Create_Range_List Failed (%xh)"), Status);
  292. SendDlgItemMessage(
  293. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  294. (LPARAM)(LPTSTR)szMsg1);
  295. return;
  296. }
  297. // new range is empty
  298. Status = CM_Dup_Range_List(rlh1, rlh2, 0);
  299. if (Status != CR_SUCCESS) {
  300. SendDlgItemMessage(
  301. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  302. (LPARAM)(LPTSTR)TEXT("Dup failed to empty range list"));
  303. return;
  304. }
  305. SendDlgItemMessage(
  306. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  307. (LPARAM)(LPTSTR)TEXT("Original Range:"));
  308. DisplayRange(hDlg, rlh1);
  309. SendDlgItemMessage(
  310. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  311. (LPARAM)(LPTSTR)TEXT("Duplicated Range:"));
  312. DisplayRange(hDlg, rlh2);
  313. // new range is not empty
  314. Status = CM_Dup_Range_List(rlh1, rlh2, 0);
  315. if (Status != CR_SUCCESS) {
  316. SendDlgItemMessage(
  317. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  318. (LPARAM)(LPTSTR)TEXT("Dup failed to non-empty range list"));
  319. return;
  320. }
  321. SendDlgItemMessage(
  322. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  323. (LPARAM)(LPTSTR)TEXT("Original Range:"));
  324. DisplayRange(hDlg, rlh1);
  325. SendDlgItemMessage(
  326. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  327. (LPARAM)(LPTSTR)TEXT("Duplicated Range:"));
  328. DisplayRange(hDlg, rlh2);
  329. //------------------------------------------------------
  330. // Delete range list test
  331. //------------------------------------------------------
  332. SendDlgItemMessage(
  333. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  334. (LPARAM)(LPTSTR)TEXT("_____Delete Range Test__________"));
  335. Status = CM_Delete_Range(1,3, rlh2, 0);
  336. if (Status != CR_SUCCESS) {
  337. wsprintf(szMsg, TEXT("CM_Delete_Range Failed (%xh)"), Status);
  338. SendDlgItemMessage(
  339. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  340. (LPARAM)(LPTSTR)szMsg);
  341. return;
  342. }
  343. SendDlgItemMessage(
  344. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  345. (LPARAM)(LPTSTR)TEXT("Deleting (1,3)"));
  346. DisplayRange(hDlg, rlh2);
  347. Status = CM_Delete_Range(17,19, rlh2, 0);
  348. if (Status != CR_SUCCESS) {
  349. wsprintf(szMsg, TEXT("CM_Delete_Range Failed (%xh)"), Status);
  350. SendDlgItemMessage(
  351. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  352. (LPARAM)(LPTSTR)szMsg);
  353. return;
  354. }
  355. SendDlgItemMessage(
  356. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  357. (LPARAM)(LPTSTR)TEXT("Deleting (17,19)"));
  358. DisplayRange(hDlg, rlh2);
  359. Status = CM_Delete_Range(27,30, rlh2, 0);
  360. if (Status != CR_SUCCESS) {
  361. wsprintf(szMsg, TEXT("CM_Delete_Range Failed (%xh)"), Status);
  362. SendDlgItemMessage(
  363. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  364. (LPARAM)(LPTSTR)szMsg);
  365. return;
  366. }
  367. SendDlgItemMessage(
  368. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  369. (LPARAM)(LPTSTR)TEXT("Deleting (27,30)"));
  370. DisplayRange(hDlg, rlh2);
  371. Status = CM_Delete_Range(3,6, rlh2, 0);
  372. if (Status != CR_SUCCESS) {
  373. wsprintf(szMsg, TEXT("CM_Delete_Range Failed (%xh)"), Status);
  374. SendDlgItemMessage(
  375. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  376. (LPARAM)(LPTSTR)szMsg);
  377. return;
  378. }
  379. SendDlgItemMessage(
  380. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  381. (LPARAM)(LPTSTR)TEXT("Deleting (3,6)"));
  382. DisplayRange(hDlg, rlh2);
  383. Status = CM_Delete_Range(13,16, rlh2, 0);
  384. if (Status != CR_SUCCESS) {
  385. wsprintf(szMsg, TEXT("CM_Delete_Range Failed (%xh)"), Status);
  386. SendDlgItemMessage(
  387. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  388. (LPARAM)(LPTSTR)szMsg);
  389. return;
  390. }
  391. SendDlgItemMessage(
  392. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  393. (LPARAM)(LPTSTR)TEXT("Deleting (13,16)"));
  394. DisplayRange(hDlg, rlh2);
  395. Status = CM_Delete_Range(8,10, rlh2, 0);
  396. if (Status != CR_SUCCESS) {
  397. wsprintf(szMsg, TEXT("CM_Delete_Range Failed (%xh)"), Status);
  398. SendDlgItemMessage(
  399. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  400. (LPARAM)(LPTSTR)szMsg);
  401. return;
  402. }
  403. SendDlgItemMessage(
  404. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  405. (LPARAM)(LPTSTR)TEXT("Deleting (8,10)"));
  406. DisplayRange(hDlg, rlh2);
  407. Status = CM_Delete_Range(9,21, rlh2, 0);
  408. if (Status != CR_SUCCESS) {
  409. wsprintf(szMsg, TEXT("CM_Delete_Range Failed (%xh)"), Status);
  410. SendDlgItemMessage(
  411. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  412. (LPARAM)(LPTSTR)szMsg);
  413. return;
  414. }
  415. SendDlgItemMessage(
  416. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  417. (LPARAM)(LPTSTR)TEXT("Deleting (9,21)"));
  418. DisplayRange(hDlg, rlh2);
  419. // special cases
  420. Status = CM_Delete_Range(0,DWORD_MAX, rlh2, 0);
  421. if (Status != CR_SUCCESS) {
  422. wsprintf(szMsg, TEXT("CM_Delete_Range Failed (%xh)"), Status);
  423. SendDlgItemMessage(
  424. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  425. (LPARAM)(LPTSTR)szMsg);
  426. return;
  427. }
  428. SendDlgItemMessage(
  429. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  430. (LPARAM)(LPTSTR)TEXT("Deleting (0,DWORD_MAX)"));
  431. DisplayRange(hDlg, rlh2);
  432. // re-dup range list 2 again, it's currently empty
  433. CM_Dup_Range_List(rlh1, rlh2, 0);
  434. SendDlgItemMessage(
  435. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  436. (LPARAM)(LPTSTR)TEXT("Resetting range list to:"));
  437. DisplayRange(hDlg, rlh2);
  438. Status = CM_Delete_Range(0,DWORDLONG_MAX, rlh2, 0);
  439. if (Status != CR_SUCCESS) {
  440. wsprintf(szMsg, TEXT("CM_Delete_Range Failed (%xh)"), Status);
  441. SendDlgItemMessage(
  442. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  443. (LPARAM)(LPTSTR)szMsg);
  444. return;
  445. }
  446. SendDlgItemMessage(
  447. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  448. (LPARAM)(LPTSTR)TEXT("Deleting (0,DWORDLONG_MAX)"));
  449. DisplayRange(hDlg, rlh2);
  450. //------------------------------------------------------
  451. // Test range available
  452. //------------------------------------------------------
  453. SendDlgItemMessage(
  454. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  455. (LPARAM)(LPTSTR)TEXT("______Test Range Available____________"));
  456. DisplayRange(hDlg, rlh1);
  457. Status = CM_Test_Range_Available(0, 2, rlh1, 0);
  458. if (Status == CR_SUCCESS) {
  459. lstrcpy(szMsg, TEXT("Range (0,2) is available (expected)"));
  460. } else {
  461. wsprintf(szMsg, TEXT("Range (0,2) not available (%d)"), Status);
  462. }
  463. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  464. (LPARAM)(LPTSTR)szMsg);
  465. Status = CM_Test_Range_Available(17, 19, rlh1, 0);
  466. if (Status == CR_SUCCESS) {
  467. lstrcpy(szMsg, TEXT("Range (17,19) is available (expected)"));
  468. } else {
  469. wsprintf(szMsg, TEXT("Range (17,19) not available (%d)"), Status);
  470. }
  471. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  472. (LPARAM)(LPTSTR)szMsg);
  473. Status = CM_Test_Range_Available(30, 40, rlh1, 0);
  474. if (Status == CR_SUCCESS) {
  475. lstrcpy(szMsg, TEXT("Range (30,40) is available (expected)"));
  476. } else {
  477. wsprintf(szMsg, TEXT("Range (30,40) not available (%d)"), Status);
  478. }
  479. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  480. (LPARAM)(LPTSTR)szMsg);
  481. Status = CM_Test_Range_Available(3, 4, rlh1, 0);
  482. if (Status == CR_SUCCESS) {
  483. lstrcpy(szMsg, TEXT("Range (3,4) is available"));
  484. } else {
  485. wsprintf(szMsg, TEXT("Range (3,4) not available, %d (expected)"), Status);
  486. }
  487. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  488. (LPARAM)(LPTSTR)szMsg);
  489. Status = CM_Test_Range_Available(26, 50, rlh1, 0);
  490. if (Status == CR_SUCCESS) {
  491. lstrcpy(szMsg, TEXT("Range (26,50) is available"));
  492. } else {
  493. wsprintf(szMsg, TEXT("Range (26,50) not available, %d (expected)"), Status);
  494. }
  495. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  496. (LPARAM)(LPTSTR)szMsg);
  497. Status = CM_Test_Range_Available(16, 20, rlh1, 0);
  498. if (Status == CR_SUCCESS) {
  499. lstrcpy(szMsg, TEXT("Range (16,20) is available"));
  500. } else {
  501. wsprintf(szMsg, TEXT("Range (16,20) not available, %d (epxected)"), Status);
  502. }
  503. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  504. (LPARAM)(LPTSTR)szMsg);
  505. Status = CM_Test_Range_Available(3, 21, rlh1, 0);
  506. if (Status == CR_SUCCESS) {
  507. lstrcpy(szMsg, TEXT("Range (3,21) is available"));
  508. } else {
  509. wsprintf(szMsg, TEXT("Range (3,21) not available, %d (expected)"), Status);
  510. }
  511. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  512. (LPARAM)(LPTSTR)szMsg);
  513. Status = CM_Test_Range_Available(5, 24, rlh1, 0);
  514. if (Status == CR_SUCCESS) {
  515. lstrcpy(szMsg, TEXT("Range (5,24) is available"));
  516. } else {
  517. wsprintf(szMsg, TEXT("Range (5,24) not available, %d (expected)"), Status);
  518. }
  519. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  520. (LPARAM)(LPTSTR)szMsg);
  521. Status = CM_Test_Range_Available(24, 25, rlh1, 0);
  522. if (Status == CR_SUCCESS) {
  523. lstrcpy(szMsg, TEXT("Range (24,25) is available"));
  524. } else {
  525. wsprintf(szMsg, TEXT("Range (24,25) not available, %d (expected)"), Status);
  526. }
  527. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  528. (LPARAM)(LPTSTR)szMsg);
  529. //------------------------------------------------------
  530. // Invert Range test
  531. //------------------------------------------------------
  532. Status = CM_Create_Range_List(&rlh3, 0);
  533. SendDlgItemMessage(
  534. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  535. (LPARAM)(LPTSTR)TEXT("Original range to invert:"));
  536. DisplayRange(hDlg, rlh1);
  537. Status = CM_Invert_Range_List(rlh1, rlh2, 100, 0);
  538. if (Status != CR_SUCCESS) {
  539. wsprintf(szMsg, TEXT("CM_Invert_Range Failed (%xh)"), Status);
  540. SendDlgItemMessage(
  541. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  542. (LPARAM)(LPTSTR)szMsg);
  543. return;
  544. }
  545. SendDlgItemMessage(
  546. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  547. (LPARAM)(LPTSTR)TEXT("Inverting into empty range:"));
  548. DisplayRange(hDlg, rlh2);
  549. Status = CM_Invert_Range_List(rlh1, rlh2, 25, 0);
  550. if (Status != CR_SUCCESS) {
  551. wsprintf(szMsg, TEXT("CM_Invert_Range Failed (%xh)"), Status);
  552. SendDlgItemMessage(
  553. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  554. (LPARAM)(LPTSTR)szMsg);
  555. return;
  556. }
  557. SendDlgItemMessage(
  558. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  559. (LPARAM)(LPTSTR)TEXT("Inverting into non-empty range, MAX=25:"));
  560. DisplayRange(hDlg, rlh2);
  561. Status = CM_Invert_Range_List(rlh1, rlh2, 50, 0);
  562. if (Status != CR_SUCCESS) {
  563. wsprintf(szMsg, TEXT("CM_Invert_Range Failed (%xh)"), Status);
  564. SendDlgItemMessage(
  565. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  566. (LPARAM)(LPTSTR)szMsg);
  567. return;
  568. }
  569. SendDlgItemMessage(
  570. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  571. (LPARAM)(LPTSTR)TEXT("Inverting into non-empty range, MAX=50:"));
  572. DisplayRange(hDlg, rlh2);
  573. Status = CM_Invert_Range_List(rlh3, rlh2, 1000, 0);
  574. if (Status != CR_SUCCESS) {
  575. wsprintf(szMsg, TEXT("CM_Invert_Range Failed (%xh)"), Status);
  576. SendDlgItemMessage(
  577. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  578. (LPARAM)(LPTSTR)szMsg);
  579. return;
  580. }
  581. SendDlgItemMessage(
  582. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  583. (LPARAM)(LPTSTR)TEXT("Inverting from empty range, MAX = 1000:"));
  584. DisplayRange(hDlg, rlh2);
  585. //------------------------------------------------------
  586. // Free range list test
  587. //------------------------------------------------------
  588. Status = CM_Free_Range_List(rlh1, 0);
  589. if (Status != CR_SUCCESS) {
  590. wsprintf(szMsg, TEXT("CM_Free_Range_List Failed (%xh)"), Status);
  591. SendDlgItemMessage(
  592. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  593. (LPARAM)(LPTSTR)szMsg);
  594. }
  595. Status = CM_Free_Range_List(rlh2, 0);
  596. if (Status != CR_SUCCESS) {
  597. wsprintf(szMsg, TEXT("CM_Free_Range_List Failed (%xh)"), Status);
  598. SendDlgItemMessage(
  599. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  600. (LPARAM)(LPTSTR)szMsg);
  601. }
  602. Status = CM_Free_Range_List(rlh3, 0);
  603. if (Status != CR_SUCCESS) {
  604. wsprintf(szMsg, TEXT("CM_Free_Range_List Failed (%xh)"), Status);
  605. SendDlgItemMessage(
  606. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  607. (LPARAM)(LPTSTR)szMsg);
  608. }
  609. Status = CM_Free_Range_List(rlh3, 0);
  610. if (Status != CR_INVALID_RANGE_LIST) {
  611. lstrcpy(szMsg, TEXT("Error: freeing already free list should have failed"));
  612. } else {
  613. lstrcpy(szMsg, TEXT("Freeing a freed list caused expected error"));
  614. }
  615. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0, (LPARAM)(LPTSTR)szMsg);
  616. //------------------------------------------------------
  617. // Intersection test
  618. //------------------------------------------------------
  619. CM_Create_Range_List(&rlh1, 0);
  620. CM_Add_Range(1, 3, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  621. CM_Add_Range(13, 18, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  622. CM_Add_Range(25, 27, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  623. CM_Add_Range(30, 36, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  624. CM_Add_Range(42, 45, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  625. CM_Add_Range(48, 52, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  626. DisplayRange(hDlg, rlh1);
  627. CM_Create_Range_List(&rlh2, 0);
  628. CM_Add_Range(8, 9, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  629. CM_Add_Range(12, 14, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  630. CM_Add_Range(17, 19, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  631. CM_Add_Range(32, 34, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  632. CM_Add_Range(40, 50, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  633. DisplayRange(hDlg, rlh2);
  634. CM_Create_Range_List(&rlh3, 0);
  635. Status = CM_Intersect_Range_List(rlh1, rlh2, rlh3, 0);
  636. if (Status != CR_SUCCESS) {
  637. wsprintf(szMsg, TEXT("CM_Intersect_Range_List Failed (%xh)"), Status);
  638. SendDlgItemMessage(
  639. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  640. (LPARAM)(LPTSTR)szMsg);
  641. }
  642. SendDlgItemMessage(
  643. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  644. (LPARAM)(LPTSTR)TEXT("Expected intersection: (13,14)(17,18)(32,34)(42,45)(48,50):"));
  645. DisplayRange(hDlg, rlh3);
  646. //------------------------------------------------------
  647. // Merge (union) test
  648. //------------------------------------------------------
  649. // use same rlh1 and rlh2 from the intersection test, non-emptry rlh3
  650. Status = CM_Merge_Range_List(rlh1, rlh2, rlh3, 0);
  651. if (Status != CR_SUCCESS) {
  652. wsprintf(szMsg, TEXT("CM_Merge_Range_List Failed (%xh)"), Status);
  653. SendDlgItemMessage(
  654. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  655. (LPARAM)(LPTSTR)szMsg);
  656. }
  657. SendDlgItemMessage(
  658. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  659. (LPARAM)(LPTSTR)TEXT("Expected union: (1,3)(8,9)(12,19)(25,27)(30,36)(40,52)"));
  660. DisplayRange(hDlg, rlh3);
  661. // both ranges empty
  662. CM_Free_Range_List(rlh1, 0);
  663. CM_Free_Range_List(rlh2, 0);
  664. CM_Create_Range_List(&rlh1, 0);
  665. CM_Create_Range_List(&rlh2, 0);
  666. Status = CM_Merge_Range_List(rlh1, rlh2, rlh3, 0);
  667. if (Status != CR_SUCCESS) {
  668. wsprintf(szMsg, TEXT("CM_Merge_Range_List Failed (%xh)"), Status);
  669. SendDlgItemMessage(
  670. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  671. (LPARAM)(LPTSTR)szMsg);
  672. }
  673. SendDlgItemMessage(
  674. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  675. (LPARAM)(LPTSTR)TEXT("Expected union: none"));
  676. DisplayRange(hDlg, rlh3);
  677. // first range empty
  678. CM_Add_Range(8, 9, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  679. CM_Add_Range(12, 14, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  680. CM_Add_Range(17, 19, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  681. CM_Add_Range(32, 34, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  682. CM_Add_Range(40, 50, rlh2, CM_ADD_RANGE_ADDIFCONFLICT);
  683. Status = CM_Merge_Range_List(rlh1, rlh2, rlh3, 0);
  684. if (Status != CR_SUCCESS) {
  685. wsprintf(szMsg, TEXT("CM_Merge_Range_List Failed (%xh)"), Status);
  686. SendDlgItemMessage(
  687. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  688. (LPARAM)(LPTSTR)szMsg);
  689. }
  690. SendDlgItemMessage(
  691. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  692. (LPARAM)(LPTSTR)TEXT("Expected union: (8,9)(12,14)(17,19)(32,34)(40,50)"));
  693. DisplayRange(hDlg, rlh3);
  694. // second range empty
  695. CM_Free_Range_List(rlh2, 0);
  696. CM_Create_Range_List(&rlh2, 0);
  697. CM_Add_Range(1, 3, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  698. CM_Add_Range(13, 18, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  699. CM_Add_Range(25, 27, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  700. CM_Add_Range(30, 36, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  701. CM_Add_Range(42, 45, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  702. CM_Add_Range(48, 52, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  703. Status = CM_Merge_Range_List(rlh1, rlh2, rlh3, 0);
  704. if (Status != CR_SUCCESS) {
  705. wsprintf(szMsg, TEXT("CM_Merge_Range_List Failed (%xh)"), Status);
  706. SendDlgItemMessage(
  707. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  708. (LPARAM)(LPTSTR)szMsg);
  709. }
  710. SendDlgItemMessage(
  711. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  712. (LPARAM)(LPTSTR)TEXT("Expected union: (1,3)(13,18)(25,27)(30,36)(42,45)(48,52)"));
  713. DisplayRange(hDlg, rlh3);
  714. CM_Free_Range_List(rlh1, 0);
  715. CM_Free_Range_List(rlh2, 0);
  716. CM_Free_Range_List(rlh3, 0);
  717. //------------------------------------------------------
  718. // Find Range test
  719. //------------------------------------------------------
  720. CM_Create_Range_List(&rlh1, 0);
  721. // should be a hit on the first try
  722. CM_Add_Range(10, 20, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  723. Status = CM_Find_Range(&ullStart, 256, 512, 0xFFFFFFFFFFFFFFF0, 1024, rlh1, 0);
  724. if (Status != CR_SUCCESS) {
  725. wsprintf(szMsg, TEXT("CM_Test_Range Failed (%xh)"), Status);
  726. SendDlgItemMessage(
  727. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  728. (LPARAM)(LPTSTR)szMsg);
  729. return;
  730. }
  731. wsprintf(szMsg, TEXT("Found Range at %d (expecting 256)"), (DWORD)ullStart);
  732. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  733. (LPARAM)(LPTSTR)szMsg);
  734. // should find it but after skipping one range
  735. CM_Add_Range(300, 320, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  736. Status = CM_Find_Range(&ullStart, 256, 512, 0xFFFFFFFFFFFFFFF0, 1024, rlh1, 0);
  737. if (Status != CR_SUCCESS) {
  738. wsprintf(szMsg, TEXT("CM_Test_Range Failed (%xh)"), Status);
  739. SendDlgItemMessage(
  740. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  741. (LPARAM)(LPTSTR)szMsg);
  742. return;
  743. }
  744. wsprintf(szMsg, TEXT("Found Range at %d (expecting 336)"), (DWORD)ullStart);
  745. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  746. (LPARAM)(LPTSTR)szMsg);
  747. // should fail the find
  748. CM_Add_Range(500, 600, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  749. Status = CM_Find_Range(&ullStart, 256, 512, 0xFFFFFFFFFFFFFFF0, 1024, rlh1, 0);
  750. if (Status != CR_FAILURE) {
  751. wsprintf(szMsg, TEXT("CM_Test_Range should have Failed (%xh)"), Status);
  752. SendDlgItemMessage(
  753. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  754. (LPARAM)(LPTSTR)szMsg);
  755. return;
  756. }
  757. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  758. (LPARAM)(LPTSTR)TEXT("Test range failed as expected"));
  759. CM_Free_Range_List(rlh1, 0);
  760. //---------------------------------------------------------------------
  761. // Special Test 1 - error condition found by LeslieF
  762. //---------------------------------------------------------------------
  763. CM_Create_Range_List(&rlh1, 0); // Create range list.
  764. CM_Add_Range(0, 50, rlh1, CM_ADD_RANGE_ADDIFCONFLICT); // Add range [0-50].
  765. CM_Delete_Range(0, 9, rlh1, 0); // Delete the range [0-9].
  766. CM_Delete_Range(21, 29, rlh1, 0); // Delete the range [21-29].
  767. CM_Delete_Range(41, 50, rlh1, 0); // Delete the range [41-50].
  768. // There should be two ranges left [10-20] and [30-40].
  769. CM_First_Range(rlh1, &ullStart, &ullEnd, &rElement, 0);
  770. CM_Next_Range(&rElement, &ullStart, &ullEnd, 0);
  771. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  772. (LPARAM)(LPTSTR)TEXT("Special Test 1, expected (10,20),(30,40)"));
  773. DisplayRange(hDlg, rlh1);
  774. CM_Free_Range_List(rlh1, 0);
  775. //---------------------------------------------------------------------
  776. // Special Test 2 - error condition found by LeslieF
  777. //---------------------------------------------------------------------
  778. Status = CM_Dup_Range_List(0, 0,0);
  779. if (Status == CR_INVALID_RANGE_LIST) {
  780. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  781. (LPARAM)(LPTSTR)TEXT("Special Test 2 - passed"));
  782. } else {
  783. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  784. (LPARAM)(LPTSTR)TEXT("Special Test 2 - failed"));
  785. }
  786. //---------------------------------------------------------------------
  787. // Special Test 3 - error condition found by LeslieF
  788. //---------------------------------------------------------------------
  789. Status = CM_Find_Range(NULL, 0, 0, 0, 0, 0, 0);
  790. if (Status == CR_INVALID_RANGE_LIST) {
  791. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  792. (LPARAM)(LPTSTR)TEXT("Special Test 3 - passed"));
  793. } else {
  794. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  795. (LPARAM)(LPTSTR)TEXT("Special Test 3 - failed"));
  796. }
  797. //---------------------------------------------------------------------
  798. // Special Test 4 - error condition found by LeslieF
  799. //---------------------------------------------------------------------
  800. CM_Create_Range_List(&rlh1, 0);
  801. CM_Free_Range_List(rlh1, 0);
  802. CM_Free_Range_List(rlh1, 0);
  803. //---------------------------------------------------------------------
  804. // Special Test 5 - error condition found by LeslieF
  805. //---------------------------------------------------------------------
  806. CM_Intersect_Range_List(0, 0, 0, 0);
  807. CM_Invert_Range_List(0, 0, 0, 0);
  808. CM_Merge_Range_List(0, 0, 0, 0);
  809. //---------------------------------------------------------------------
  810. // Special Test 6 - error condition found by LeslieF
  811. //---------------------------------------------------------------------
  812. CM_Create_Range_List(&rlh1, 0);
  813. CM_Create_Range_List(&rlh2, 0);
  814. // Add range [10-20].
  815. CM_Add_Range(10, 20, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  816. // Add range [30-40].
  817. CM_Add_Range(30, 40, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  818. // Duplicate range list.
  819. CM_Dup_Range_List(rlh1, rlh2, 0);
  820. // There should be two ranges in rlh2, [10-20] and [30-40].
  821. // Get the first.
  822. CM_First_Range(rlh2, &ullStart, &ullEnd, &rElement, 0);
  823. // Get the next.
  824. CM_Next_Range(&rElement, &ullStart, &ullEnd, 0); // *** Returns CR_FAILURE *** Should return CR_SUCCESS
  825. // Free the range lists.
  826. CM_Free_Range_List(rlh1, 0);
  827. CM_Free_Range_List(rlh2, 0);
  828. // Example2:
  829. CM_Create_Range_List(&rlh1, 0);
  830. CM_Create_Range_List(&rlh2, 0);
  831. // Add range [10-20][30-40].
  832. CM_Add_Range(10, 20, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  833. CM_Add_Range(30, 40, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  834. // Invert range list.
  835. CM_Invert_Range_List(rlh1, rlh2, 40, 0);
  836. // There should be two ranges [0-9] and [21-29].
  837. // Get the first.
  838. CM_First_Range(rlh2, &ullStart, &ullEnd, &rElement, 0);
  839. // Get the next.
  840. CM_Next_Range(&rElement, &ullStart, &ullEnd, 0); // *** Returns CR_FAILURE *** Should return CR_SUCCESS
  841. // Free the range lists.
  842. CM_Free_Range_List(rlh1, 0);
  843. CM_Free_Range_List(rlh2, 0);
  844. //---------------------------------------------------------------------
  845. // Special Test 7 - error condition found by LeslieF
  846. //---------------------------------------------------------------------
  847. CM_Create_Range_List(&rlh1, 0);
  848. CM_Add_Range(10, 20, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  849. CM_Add_Range(30, 40, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  850. Status = CM_Test_Range_Available(9, 21, rlh1, 0);
  851. if (Status != CR_FAILURE) {
  852. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  853. (LPARAM)(LPTSTR)TEXT("Special Test 7 - failed"));
  854. }
  855. CM_Free_Range_List(rlh1, 0);
  856. //---------------------------------------------------------------------
  857. // Special Test 8 - error condition found by Bogdan
  858. //---------------------------------------------------------------------
  859. CM_Create_Range_List(&rlh1, 0);
  860. CM_Create_Range_List(&rlh2, 0);
  861. CM_Add_Range(0, 10, rlh1, CM_ADD_RANGE_ADDIFCONFLICT);
  862. CM_First_Range(rlh1, &ullStart, &ullEnd, &rElement, 0);
  863. if (ullStart != 0 || ullEnd != 10) {
  864. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  865. (LPARAM)(LPTSTR)TEXT("Special Test 8 - failure 1"));
  866. }
  867. // As expected, ullStart = 0 and ullEnd = 10
  868. CM_Invert_Range_List(rlh1, rlh2, 20, 0);
  869. CM_First_Range(rlh2, &ullStart, &ullEnd, &rElement, 0);
  870. // Expected ullStart = 11, ullEnd = 20, but ullStart = 0 and ullEnd = 0xFFFFFFFFFFFFFFFFF
  871. // The next range is correct one [11, 20]
  872. //CM_Next_Range(&rElement, &ullStart, &ullEnd, 0);
  873. CM_Free_Range_List(rlh1, 0);
  874. CM_Free_Range_List(rlh2, 0);
  875. CM_Free_Range_List(rlh2, 0); // test deleting already deleted range list
  876. return;
  877. } // RegressionTest_Range
  878. //-----------------------------------------------------------------------------
  879. VOID
  880. RegressionTest_Class(
  881. HWND hDlg
  882. )
  883. {
  884. CONFIGRET Status = CR_SUCCESS;
  885. GUID ClassGuid;
  886. UUID ClassUuid;
  887. TCHAR szClass[MAX_CLASS_NAME_LEN];
  888. DEVNODE dnDevNode;
  889. TCHAR szMsg[MAX_PATH], szMsg1[MAX_PATH];
  890. ULONG ulStatus=0, ulProblem=0, ulLength = 0, ulSize = 0, i = 0;
  891. PTSTR pBuffer = NULL;
  892. HKEY hKey = NULL, hKey1 = NULL;
  893. #if 0
  894. i = 0;
  895. while (Status == CR_SUCCESS) {
  896. Status = CM_Enumerate_Classes_Ex(i, &ClassGuid, 0, hMachine);
  897. if (Status == CR_SUCCESS) {
  898. ulLength = MAX_CLASS_NAME_LEN;
  899. Status = CM_Get_Class_Name(&ClassGuid, szClass, &ulLength, 0);
  900. if (Status == CR_SUCCESS) {
  901. wsprintf(szMsg, TEXT("Class %d, Name: %s"), i, szClass);
  902. SendDlgItemMessage(
  903. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  904. (LPARAM)(LPTSTR)szMsg);
  905. }
  906. }
  907. i++;
  908. }
  909. return;
  910. Status = CM_Locate_DevNode(&dnDevNode, NULL, 0);
  911. if (Status != CR_SUCCESS) {
  912. MessageBox(hDlg, TEXT("Locate Root failed"), TEXT("Test"), MB_OK);
  913. return;
  914. }
  915. Status = CM_Reenumerate_DevNode(dnDevNode, 0);
  916. if (Status != CR_SUCCESS) {
  917. MessageBox(hDlg, TEXT("Reenumeration of Root Failed"), TEXT("Test"), MB_OK);
  918. }
  919. Status = CM_Locate_DevNode(&dnDevNode, TEXT("Test\\A1\\0000"), 0);
  920. if (Status != CR_SUCCESS) {
  921. return;
  922. }
  923. lstrcpy(szMsg, TEXT("1. Reenumerate Test\\A1\\0000: "));
  924. Status = CM_Reenumerate_DevNode(dnDevNode, 0);
  925. if (Status != CR_SUCCESS) {
  926. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  927. }
  928. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  929. lstrcat(szMsg, szMsg1);
  930. SendDlgItemMessage(
  931. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  932. (LPARAM)(LPTSTR)szMsg);
  933. Status = CM_Locate_DevNode(&dnDevNode, TEXT("Test\\A2\\0001"), 0);
  934. if (Status != CR_SUCCESS) {
  935. return;
  936. }
  937. lstrcpy(szMsg, TEXT("2. QueryRemove SubTree Test\\A2\\0001: "));
  938. Status = CM_Query_Remove_SubTree(dnDevNode, CM_QUERY_REMOVE_UI_OK);
  939. if (Status != CR_SUCCESS) {
  940. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  941. }
  942. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  943. lstrcat(szMsg, szMsg1);
  944. SendDlgItemMessage(
  945. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  946. (LPARAM)(LPTSTR)szMsg);
  947. lstrcpy(szMsg, TEXT("3. Remove SubTree Test\\A2\\0001: "));
  948. Status = CM_Remove_SubTree(dnDevNode, CM_REMOVE_UI_OK);
  949. if (Status != CR_SUCCESS) {
  950. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  951. }
  952. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  953. lstrcat(szMsg, szMsg1);
  954. SendDlgItemMessage(
  955. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  956. (LPARAM)(LPTSTR)szMsg);
  957. #endif
  958. lstrcpy(szMsg, TEXT("Test Delete Class Key only, no other keys exist"));
  959. UuidFromString(TEXT("00000000-0000-0000-0000-000000000000"), &ClassGuid);
  960. Status = CM_Open_Class_Key(&ClassGuid, TEXT("Madeup class"), KEY_ALL_ACCESS,
  961. RegDisposition_OpenAlways, &hKey, 0);
  962. if (Status != CR_SUCCESS) {
  963. wsprintf(szMsg1, TEXT("CM_Open_Class_Key Failed (%xh)"), Status);
  964. }
  965. else wsprintf(szMsg1, TEXT("CM_Open_Class_Key Passed"));
  966. SendDlgItemMessage(
  967. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  968. (LPARAM)(LPTSTR)szMsg1);
  969. RegCloseKey(hKey);
  970. Status = CM_Delete_Class_Key(&ClassGuid, CM_DELETE_CLASS_ONLY);
  971. if (Status != CR_SUCCESS) {
  972. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  973. }
  974. else wsprintf(szMsg1, TEXT("Passed"));
  975. lstrcat(szMsg, szMsg1);
  976. SendDlgItemMessage(
  977. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  978. (LPARAM)(LPTSTR)szMsg);
  979. lstrcpy(szMsg, TEXT("Test Delete Class Key only, subkeys exist"));
  980. UuidFromString(TEXT("00000000-0000-0000-0000-000000000001"), &ClassGuid);
  981. Status = CM_Delete_Class_Key(&ClassGuid, CM_DELETE_CLASS_ONLY);
  982. if (Status != CR_SUCCESS) {
  983. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  984. }
  985. else wsprintf(szMsg1, TEXT("Passed"));
  986. lstrcat(szMsg, szMsg1);
  987. SendDlgItemMessage(
  988. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  989. (LPARAM)(LPTSTR)szMsg);
  990. lstrcpy(szMsg, TEXT("Test Delete Class Key, subkeys too"));
  991. UuidFromString(TEXT("00000000-0000-0000-0000-000000000002"), &ClassGuid);
  992. Status = CM_Open_Class_Key(&ClassGuid, NULL, KEY_ALL_ACCESS,
  993. RegDisposition_OpenAlways, &hKey, 0);
  994. if (Status != CR_SUCCESS) {
  995. wsprintf(szMsg1, TEXT("CM_Open_Class_Key Failed (%xh)"), Status);
  996. }
  997. else wsprintf(szMsg1, TEXT("CM_Open_Class_Key Passed"));
  998. SendDlgItemMessage(
  999. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1000. (LPARAM)(LPTSTR)szMsg1);
  1001. RegCreateKeyEx(hKey, TEXT("Subkey1"), 0, NULL, REG_OPTION_NON_VOLATILE,
  1002. KEY_ALL_ACCESS, NULL, &hKey1, NULL);
  1003. MessageBox(NULL, TEXT("Does 0000...0002\\SubKey1 exist?"), TEXT("Test"), MB_OK);
  1004. RegCloseKey(hKey);
  1005. RegCloseKey(hKey1);
  1006. Status = CM_Delete_Class_Key(&ClassGuid, CM_DELETE_CLASS_SUBKEYS);
  1007. if (Status != CR_SUCCESS) {
  1008. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1009. }
  1010. else wsprintf(szMsg1, TEXT("Passed"));
  1011. lstrcat(szMsg, szMsg1);
  1012. SendDlgItemMessage(
  1013. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1014. (LPARAM)(LPTSTR)szMsg);
  1015. Status = CM_Locate_DevNode(&dnDevNode, TEXT("Root\\Device001\\0000"), 0);
  1016. if (Status != CR_SUCCESS) {
  1017. return;
  1018. }
  1019. lstrcpy(szMsg, TEXT("4. Get Status for Test\\A2\\0001: "));
  1020. Status = CM_Get_DevNode_Status(&ulStatus, &ulProblem, dnDevNode, 0);
  1021. if (Status != CR_SUCCESS) {
  1022. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1023. }
  1024. else wsprintf(szMsg1, TEXT("Passed, Status=%xh, Problem=%xh"), ulStatus, ulProblem);
  1025. lstrcat(szMsg, szMsg1);
  1026. SendDlgItemMessage(
  1027. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1028. (LPARAM)(LPTSTR)szMsg);
  1029. return;
  1030. } // RegressionTest_Class
  1031. //-----------------------------------------------------------------------------
  1032. VOID
  1033. RegressionTest_Traverse(
  1034. HWND hDlg
  1035. )
  1036. {
  1037. CONFIGRET Status = CR_SUCCESS;
  1038. TCHAR szMsg[MAX_PATH], szMsg1[MAX_PATH];
  1039. DEVNODE dnDevNode, dnRootDevNode, dnChildDevNode, dnParentDevNode;
  1040. TCHAR Buffer[512];
  1041. ULONG ulDepth;
  1042. SendDlgItemMessage(
  1043. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1044. (LPARAM)TEXT("____TRAVERSE REGRESSION TEST_____"));
  1045. /*
  1046. lstrcpy(szMsg, TEXT("1. Get parent of invalid devnode: "));
  1047. Status = CM_Get_Parent(&dnDevNode, 1, 0);
  1048. if (Status != CR_INVALID_DEVNODE) {
  1049. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1050. }
  1051. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1052. lstrcat(szMsg, szMsg1);
  1053. SendDlgItemMessage(
  1054. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1055. (LPARAM)(LPTSTR)szMsg);
  1056. lstrcpy(szMsg, TEXT("2. Get parent of root: "));
  1057. CM_Locate_DevNode(&dnRootDevNode, NULL, 0);
  1058. Status = CM_Get_Parent(&dnDevNode, dnRootDevNode, 0);
  1059. if (Status != CR_NO_SUCH_DEVNODE) {
  1060. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1061. }
  1062. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1063. lstrcat(szMsg, szMsg1);
  1064. SendDlgItemMessage(
  1065. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1066. (LPARAM)(LPTSTR)szMsg);
  1067. lstrcpy(szMsg, TEXT("3. Get parent with no BaseDevicePath value: "));
  1068. CM_Locate_DevNode(&dnDevNode, szNoBaseDeviceID, 0);
  1069. Status = CM_Get_Parent(&dnDevNode, dnDevNode, 0);
  1070. if (Status != CR_NO_SUCH_DEVINST) {
  1071. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1072. }
  1073. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1074. lstrcat(szMsg, szMsg1);
  1075. SendDlgItemMessage(
  1076. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1077. (LPARAM)(LPTSTR)szMsg);
  1078. lstrcpy(szMsg, TEXT("4. Get parent that doesn't exist in registry: "));
  1079. CM_Locate_DevNode(&dnDevNode, szMissingParentDeviceID, 0);
  1080. Status = CM_Get_Parent(&dnDevNode, dnDevNode, 0);
  1081. if (Status != CR_NO_SUCH_DEVINST) {
  1082. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1083. }
  1084. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1085. lstrcat(szMsg, szMsg1);
  1086. SendDlgItemMessage(
  1087. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1088. (LPARAM)(LPTSTR)szMsg);
  1089. lstrcpy(szMsg, TEXT("5. Get parent that isn't marked as found: "));
  1090. CM_Locate_DevNode(&dnDevNode, szNotFoundParentDeviceID, 0);
  1091. Status = CM_Get_Parent(&dnDevNode, dnDevNode, 0);
  1092. if (Status != CR_NO_SUCH_DEVNODE) {
  1093. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1094. }
  1095. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1096. lstrcat(szMsg, szMsg1);
  1097. SendDlgItemMessage(
  1098. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1099. (LPARAM)(LPTSTR)szMsg);
  1100. wsprintf(szMsg, TEXT("6. Get parent that has been moved: "));
  1101. CM_Locate_DevNode(&dnDevNode, szMovedParentDeviceID, 0);
  1102. Status = CM_Get_Parent(&dnDevNode, dnDevNode, 0);
  1103. if (Status != CR_NO_SUCH_DEVNODE) {
  1104. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1105. }
  1106. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1107. lstrcat(szMsg, szMsg1);
  1108. SendDlgItemMessage(
  1109. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1110. (LPARAM)(LPTSTR)szMsg);
  1111. lstrcpy(szMsg, TEXT("7. Get valid parent: "));
  1112. Status = CM_Locate_DevNode(&dnDevNode, szPresentDeviceID, 0);
  1113. if (Status != CR_SUCCESS) {
  1114. wsprintf(szMsg1, TEXT("Failed Locate (%xh)"), Status);
  1115. }
  1116. else {
  1117. Status = CM_Get_Parent(&dnParentDevNode, dnDevNode, 0);
  1118. if (Status != CR_SUCCESS) {
  1119. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1120. }
  1121. else wsprintf(szMsg1, TEXT("Passed (DevNode=%xh)"), dnDevNode);
  1122. }
  1123. lstrcat(szMsg, szMsg1);
  1124. SendDlgItemMessage(
  1125. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1126. (LPARAM)(LPTSTR)szMsg);
  1127. lstrcpy(szMsg, TEXT("8. Get child of invalid devnode: "));
  1128. Status = CM_Get_Child(&dnDevNode, 1, 0);
  1129. if (Status != CR_INVALID_DEVNODE) {
  1130. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1131. }
  1132. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1133. lstrcat(szMsg, szMsg1);
  1134. SendDlgItemMessage(
  1135. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1136. (LPARAM)(LPTSTR)szMsg);
  1137. lstrcpy(szMsg, TEXT("9. Get child with no AttachedComponents: "));
  1138. CM_Locate_DevNode(&dnDevNode, szNoAttachedDeviceID, 0);
  1139. Status = CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1140. if (Status != CR_NO_SUCH_DEVINST) {
  1141. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1142. }
  1143. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1144. lstrcat(szMsg, szMsg1);
  1145. SendDlgItemMessage(
  1146. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1147. (LPARAM)(LPTSTR)szMsg);
  1148. lstrcpy(szMsg, TEXT("10. Get child that doesn't exist in registry: "));
  1149. CM_Locate_DevNode(&dnDevNode, szMissingChildDeviceID, 0);
  1150. Status = CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1151. if (Status != CR_NO_SUCH_DEVINST) {
  1152. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1153. }
  1154. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1155. lstrcat(szMsg, szMsg1);
  1156. SendDlgItemMessage(
  1157. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1158. (LPARAM)(LPTSTR)szMsg);
  1159. lstrcpy(szMsg, TEXT("11. Get child that isn't marked as found: "));
  1160. CM_Locate_DevNode(&dnDevNode, szNotFoundChildDeviceID, 0);
  1161. Status = CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1162. if (Status != CR_NO_SUCH_DEVNODE) {
  1163. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1164. }
  1165. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1166. lstrcat(szMsg, szMsg1);
  1167. SendDlgItemMessage(
  1168. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1169. (LPARAM)(LPTSTR)szMsg);
  1170. lstrcpy(szMsg, TEXT("12. Get child that has been moved: "));
  1171. CM_Locate_DevNode(&dnDevNode, szMovedChildDeviceID, 0);
  1172. Status = CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1173. if (Status != CR_NO_SUCH_DEVNODE) {
  1174. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1175. }
  1176. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1177. lstrcat(szMsg, szMsg1);
  1178. SendDlgItemMessage(
  1179. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1180. (LPARAM)(LPTSTR)szMsg);
  1181. lstrcpy(szMsg, TEXT("13. First child isn't valid: "));
  1182. CM_Locate_DevNode(&dnDevNode, szValid2ndChildDeviceID, 0);
  1183. Status = CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1184. if (Status != CR_SUCCESS) {
  1185. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1186. }
  1187. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1188. lstrcat(szMsg, szMsg1);
  1189. SendDlgItemMessage(
  1190. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1191. (LPARAM)(LPTSTR)szMsg);
  1192. lstrcpy(szMsg, TEXT("14. Get valid child: "));
  1193. Status = CM_Get_Child(&dnChildDevNode, dnParentDevNode, 0);
  1194. if (Status != CR_SUCCESS) {
  1195. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1196. }
  1197. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1198. lstrcat(szMsg, szMsg1);
  1199. SendDlgItemMessage(
  1200. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1201. (LPARAM)(LPTSTR)szMsg);
  1202. lstrcpy(szMsg, TEXT("15. Get sibling of invalid devnode: "));
  1203. Status = CM_Get_Sibling(&dnDevNode, 1, 0);
  1204. if (Status != CR_INVALID_DEVNODE) {
  1205. wsprintf(szMsg1, TEXT("Failed (%xh"), Status);
  1206. }
  1207. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1208. lstrcat(szMsg, szMsg1);
  1209. SendDlgItemMessage(
  1210. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1211. (LPARAM)(LPTSTR)szMsg);
  1212. lstrcpy(szMsg, TEXT("16. Get sibling of Root: "));
  1213. Status = CM_Get_Sibling(&dnDevNode, dnRootDevNode, 0);
  1214. if (Status != CR_NO_SUCH_DEVNODE) {
  1215. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1216. }
  1217. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1218. lstrcat(szMsg, szMsg1);
  1219. SendDlgItemMessage(
  1220. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1221. (LPARAM)(LPTSTR)szMsg);
  1222. lstrcpy(szMsg, TEXT("17. Get sibling with no AttachedComponents: "));
  1223. CM_Locate_DevNode(&dnDevNode, szNoAttachedDeviceID, 0);
  1224. Status = CM_Get_Sibling(&dnDevNode, dnDevNode, 0);
  1225. if (Status != CR_NO_SUCH_DEVINST) {
  1226. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1227. }
  1228. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1229. lstrcat(szMsg, szMsg1);
  1230. SendDlgItemMessage(
  1231. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1232. (LPARAM)(LPTSTR)szMsg);
  1233. lstrcpy(szMsg, TEXT("18. Get sibling that doesn't exist in registry: "));
  1234. CM_Locate_DevNode(&dnDevNode, szMissingSiblingDeviceID, 0);
  1235. CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1236. Status = CM_Get_Sibling(&dnDevNode, dnDevNode, 0);
  1237. if (Status != CR_NO_SUCH_DEVINST) {
  1238. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1239. }
  1240. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1241. lstrcat(szMsg, szMsg1);
  1242. SendDlgItemMessage(
  1243. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1244. (LPARAM)(LPTSTR)szMsg);
  1245. lstrcpy(szMsg, TEXT("19. Get sibling that isn't marked as found: "));
  1246. CM_Locate_DevNode(&dnDevNode, szNotFoundSiblingDeviceID, 0);
  1247. CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1248. Status = CM_Get_Sibling(&dnDevNode, dnDevNode, 0);
  1249. if (Status != CR_NO_SUCH_DEVNODE) {
  1250. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1251. }
  1252. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1253. lstrcat(szMsg, szMsg1);
  1254. SendDlgItemMessage(
  1255. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1256. (LPARAM)(LPTSTR)szMsg);
  1257. lstrcpy(szMsg, TEXT("20. Get sibling that has been moved: "));
  1258. CM_Locate_DevNode(&dnDevNode, szMovedSiblingDeviceID, 0);
  1259. CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1260. Status = CM_Get_Sibling(&dnDevNode, dnDevNode, 0);
  1261. if (Status != CR_NO_SUCH_DEVNODE) {
  1262. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1263. }
  1264. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1265. lstrcat(szMsg, szMsg1);
  1266. SendDlgItemMessage(
  1267. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1268. (LPARAM)(LPTSTR)szMsg);
  1269. wsprintf(szMsg, TEXT("21. First sibling isn't valid: "));
  1270. CM_Locate_DevNode(&dnDevNode, szValid3rdChildDeviceID, 0);
  1271. Status = CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1272. if (Status != CR_SUCCESS) {
  1273. wsprintf(szMsg1, TEXT("Get Child Failed (%xh)"), Status);
  1274. } else {
  1275. Status = CM_Get_Sibling(&dnDevNode, dnDevNode, 0);
  1276. if (Status != CR_SUCCESS) {
  1277. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1278. }
  1279. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1280. }
  1281. lstrcat(szMsg, szMsg1);
  1282. SendDlgItemMessage(
  1283. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1284. (LPARAM)(LPTSTR)szMsg);
  1285. */
  1286. wsprintf(szMsg, TEXT("Finding all children of %s:"), szPresentDeviceID);
  1287. SendDlgItemMessage(
  1288. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1289. (LPARAM)(LPTSTR)szMsg);
  1290. CM_Locate_DevNode(&dnDevNode, szPresentDeviceID, 0);
  1291. CM_Get_Child(&dnDevNode, dnDevNode, 0);
  1292. CM_Get_Device_ID(dnDevNode, Buffer, MAX_PATH, 0);
  1293. wsprintf(szMsg, TEXT(" Child DeviceID = %s (DevNode = %d)"),
  1294. Buffer, dnDevNode);
  1295. SendDlgItemMessage(
  1296. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1297. (LPARAM)(LPTSTR)szMsg);
  1298. while (Status == CR_SUCCESS) {
  1299. Status = CM_Get_Sibling(&dnDevNode, dnDevNode, 0);
  1300. if (Status == CR_SUCCESS) {
  1301. CM_Get_Device_ID(dnDevNode, Buffer, MAX_PATH, 0);
  1302. wsprintf(szMsg, TEXT(" Sibling DeviceID = %s (DevNode = %d)"),
  1303. Buffer, dnDevNode);
  1304. SendDlgItemMessage(
  1305. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1306. (LPARAM)(LPTSTR)szMsg);
  1307. }
  1308. }
  1309. if (Status != CR_NO_SUCH_DEVINST) {
  1310. wsprintf(szMsg, TEXT("CM_Get_Sibling failed (%xh)"), Status);
  1311. SendDlgItemMessage(
  1312. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1313. (LPARAM)(LPTSTR)szMsg);
  1314. }
  1315. //----------------------------------------------------------------
  1316. // Do recursive traversal test
  1317. //----------------------------------------------------------------
  1318. // Create a new node.
  1319. Status = CM_Locate_DevNode_Ex(&dnRootDevNode, NULL, 0, hMachine);
  1320. if (Status == CR_SUCCESS) {
  1321. if (TraverseAndCheckParents(dnRootDevNode)) {
  1322. SendDlgItemMessage(
  1323. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1324. (LPARAM)(LPTSTR)TEXT("Recursive Traversal Test: PASSED"));
  1325. } else {
  1326. SendDlgItemMessage(
  1327. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1328. (LPARAM)(LPTSTR)TEXT("Recursive Traversal Test: FAILED"));
  1329. }
  1330. } else {
  1331. SendDlgItemMessage(
  1332. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1333. (LPARAM)(LPTSTR)TEXT("Locate Root DevNode: FAILED"));
  1334. }
  1335. //----------------------------------------------------------------
  1336. // Get Depth Test
  1337. //----------------------------------------------------------------
  1338. lstrcpy(szMsg, TEXT("Get Depth of Root: "));
  1339. CM_Locate_DevNode_Ex(&dnDevNode, NULL, 0, hMachine);
  1340. Status = CM_Get_Depth_Ex(&ulDepth, dnDevNode, 0, hMachine);
  1341. if (Status != CR_SUCCESS || ulDepth != 0) {
  1342. wsprintf(szMsg1, TEXT("Failed, Depth = %d (%xh)"), ulDepth, Status);
  1343. }
  1344. else wsprintf(szMsg1, TEXT("Passed, Depth = %d (%xh)"), ulDepth, Status);
  1345. lstrcat(szMsg, szMsg1);
  1346. SendDlgItemMessage(
  1347. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1348. (LPARAM)(LPTSTR)szMsg);
  1349. lstrcpy(szMsg, TEXT("Get Depth of 1st Level Node: "));
  1350. CM_Locate_DevNode_Ex(&dnDevNode, TEXT("Root\\Device001\\0000"), 0, hMachine);
  1351. Status = CM_Get_Depth_Ex(&ulDepth, dnDevNode, 0, hMachine);
  1352. if (Status != CR_SUCCESS || ulDepth != 1) {
  1353. wsprintf(szMsg1, TEXT("Failed, Depth = %d (%xh)"), ulDepth, Status);
  1354. }
  1355. else wsprintf(szMsg1, TEXT("Passed, Depth = %d (%xh)"), ulDepth, Status);
  1356. lstrcat(szMsg, szMsg1);
  1357. SendDlgItemMessage(
  1358. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1359. (LPARAM)(LPTSTR)szMsg);
  1360. lstrcpy(szMsg, TEXT("Get Depth of 2nd Level Node: "));
  1361. CM_Locate_DevNode_Ex(&dnDevNode, TEXT("Root\\Device002\\0000"), 0, hMachine);
  1362. Status = CM_Get_Depth_Ex(&ulDepth, dnDevNode, 0, hMachine);
  1363. if (Status != CR_SUCCESS || ulDepth != 2) {
  1364. wsprintf(szMsg1, TEXT("Failed, Depth = %d (%xh)"), ulDepth, Status);
  1365. }
  1366. else wsprintf(szMsg1, TEXT("Passed, Depth = %d (%xh)"), ulDepth, Status);
  1367. lstrcat(szMsg, szMsg1);
  1368. SendDlgItemMessage(
  1369. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1370. (LPARAM)(LPTSTR)szMsg);
  1371. return;
  1372. } // RegressionTest_Traverse
  1373. //-----------------------------------------------------------------------------
  1374. VOID
  1375. RegressionTest_HardwareProfile(
  1376. HWND hDlg
  1377. )
  1378. {
  1379. CONFIGRET Status;
  1380. TCHAR szMsg[MAX_PATH], szMsg1[MAX_PATH];
  1381. DEVNODE dnDevNode;
  1382. TCHAR Buffer[512];
  1383. HWPROFILEINFO HWProfileInfo;
  1384. ULONG ulValue = 0, Index =0;
  1385. ULONG C0 = CSCONFIGFLAG_DO_NOT_CREATE;
  1386. ULONG C1 = CSCONFIGFLAG_DO_NOT_START;
  1387. ULONG C2 = CSCONFIGFLAG_DISABLED;
  1388. SendDlgItemMessage(
  1389. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1390. (LPARAM)TEXT("____HARDWARE PROFILES REGRESSION TEST_____"));
  1391. /*
  1392. lstrcpy(szMsg, TEXT("Get HwProf Flags for Missing Device ID: "));
  1393. Status = CM_Get_HW_Prof_Flags(szNonExistantDeviceID, 0, &ulValue, 0);
  1394. if (Status != CR_SUCCESS) {
  1395. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1396. }
  1397. else wsprintf(szMsg1, TEXT("Passed (%xh), Flags = %xh"), Status, ulValue);
  1398. lstrcat(szMsg, szMsg1);
  1399. SendDlgItemMessage(
  1400. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1401. (LPARAM)(LPTSTR)szMsg);
  1402. lstrcpy(szMsg, TEXT("Get Hw Profile for invalid config: "));
  1403. Status = CM_Get_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 13, &ulValue, 0);
  1404. if (Status != CR_REGISTRY_ERROR) {
  1405. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1406. }
  1407. else wsprintf(szMsg1, TEXT("Passed (%xh), Flags = %xh"), Status, ulValue);
  1408. lstrcat(szMsg, szMsg1);
  1409. SendDlgItemMessage(
  1410. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1411. (LPARAM)(LPTSTR)szMsg);
  1412. //---------------------------------------------------------------
  1413. // Profile 1
  1414. //---------------------------------------------------------------
  1415. lstrcpy(szMsg, TEXT("Set HwProf Flags for config 1: "));
  1416. Status = CM_Set_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 1, C1, 0);
  1417. if (Status != CR_SUCCESS) {
  1418. wsprintf(szMsg1, TEXT("Failed (%xh), Flags = %xh"), Status, C1);
  1419. }
  1420. else wsprintf(szMsg1, TEXT("Passed (%xh), Flags = %xh"), Status, C1);
  1421. lstrcat(szMsg, szMsg1);
  1422. SendDlgItemMessage(
  1423. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1424. (LPARAM)(LPTSTR)szMsg);
  1425. lstrcpy(szMsg, TEXT("Get Hw Profile for config 1: "));
  1426. ulValue = 0;
  1427. Status = CM_Get_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 1, &ulValue, 0);
  1428. if (Status != CR_SUCCESS || C1 != ulValue) {
  1429. wsprintf(szMsg1, TEXT("Failed (%xh), Flags = %xh"), Status, ulValue);
  1430. }
  1431. else wsprintf(szMsg1, TEXT("Passed (%xh), Flags = %xh"), Status, ulValue);
  1432. lstrcat(szMsg, szMsg1);
  1433. SendDlgItemMessage(
  1434. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1435. (LPARAM)(LPTSTR)szMsg);
  1436. //---------------------------------------------------------------
  1437. // Profile 2
  1438. //---------------------------------------------------------------
  1439. lstrcpy(szMsg, TEXT("Set HwProf Flags for config 2: "));
  1440. Status = CM_Set_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 2, C2, 0);
  1441. if (Status != CR_SUCCESS) {
  1442. wsprintf(szMsg1, TEXT("Failed (%xh), Flags = %xh"), Status, C2);
  1443. }
  1444. else wsprintf(szMsg1, TEXT("Passed (%xh), Flags = %xh"), Status, C2);
  1445. lstrcat(szMsg, szMsg1);
  1446. SendDlgItemMessage(
  1447. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1448. (LPARAM)(LPTSTR)szMsg);
  1449. lstrcpy(szMsg, TEXT("Get Hw Profile for config 2: "));
  1450. ulValue = 0;
  1451. Status = CM_Get_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 2, &ulValue, 0);
  1452. if (Status != CR_SUCCESS || C2 != ulValue) {
  1453. wsprintf(szMsg1, TEXT("Failed (%xh), Flags = %xh"), Status, ulValue);
  1454. }
  1455. else wsprintf(szMsg1, TEXT("Passed (%xh), Flags = %xh"), Status, ulValue);
  1456. lstrcat(szMsg, szMsg1);
  1457. SendDlgItemMessage(
  1458. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1459. (LPARAM)(LPTSTR)szMsg);
  1460. //---------------------------------------------------------------
  1461. // Current Profile
  1462. //---------------------------------------------------------------
  1463. lstrcpy(szMsg, TEXT("Set HwProf Flags for current config: "));
  1464. Status = CM_Set_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 0, C0, 0);
  1465. if (Status != CR_SUCCESS) {
  1466. wsprintf(szMsg1, TEXT("Failed (%xh), Flags = %xh"), Status, C0);
  1467. }
  1468. else wsprintf(szMsg1, TEXT("Passed (%xh), Flags = %xh"), Status, C0);
  1469. lstrcat(szMsg, szMsg1);
  1470. SendDlgItemMessage(
  1471. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1472. (LPARAM)(LPTSTR)szMsg);
  1473. lstrcpy(szMsg, TEXT("Get Hw Profile for current config: "));
  1474. ulValue = 0;
  1475. Status = CM_Get_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 0, &ulValue, 0);
  1476. if (Status != CR_SUCCESS || C0 != ulValue) {
  1477. wsprintf(szMsg1, TEXT("Failed (%xh), Flags = %xh"), Status, ulValue);
  1478. }
  1479. else wsprintf(szMsg1, TEXT("Passed (%xh), Flags = %xh"), Status, ulValue);
  1480. lstrcat(szMsg, szMsg1);
  1481. SendDlgItemMessage(
  1482. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1483. (LPARAM)(LPTSTR)szMsg);
  1484. */
  1485. //---------------------------------------------------------------
  1486. // Test CM_Get_HW_Prof_Info
  1487. //---------------------------------------------------------------
  1488. lstrcpy(szMsg, TEXT("Get HwProf Info test:"));
  1489. Status = CM_Get_Hardware_Profile_Info_Ex(0xFFFFFFFF, &HWProfileInfo, 0, hMachine);
  1490. if (Status != CR_SUCCESS) {
  1491. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1492. }
  1493. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1494. lstrcat(szMsg, szMsg1);
  1495. SendDlgItemMessage(
  1496. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1497. (LPARAM)(LPTSTR)szMsg);
  1498. wsprintf(szMsg, TEXT(" Current (%u) HW Profile: %s, Flags=%xh"),
  1499. HWProfileInfo.HWPI_ulHWProfile,
  1500. HWProfileInfo.HWPI_szFriendlyName,
  1501. HWProfileInfo.HWPI_dwFlags);
  1502. SendDlgItemMessage(
  1503. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1504. (LPARAM)(LPTSTR)szMsg);
  1505. Index = 0;
  1506. Status = CR_SUCCESS;
  1507. while (Status == CR_SUCCESS) {
  1508. Status = CM_Get_Hardware_Profile_Info(Index, &HWProfileInfo, 0);
  1509. if (Status == CR_SUCCESS) {
  1510. wsprintf(szMsg, TEXT(" HW Profile %u: %s, Flags=%xh"),
  1511. HWProfileInfo.HWPI_ulHWProfile,
  1512. HWProfileInfo.HWPI_szFriendlyName,
  1513. HWProfileInfo.HWPI_dwFlags);
  1514. SendDlgItemMessage(
  1515. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1516. (LPARAM)(LPTSTR)szMsg);
  1517. }
  1518. Index++;
  1519. }
  1520. // reset to pre-test conditions
  1521. CM_Set_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 0, 0, 0);
  1522. CM_Set_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 1, 0, 0);
  1523. CM_Set_HW_Prof_Flags(TEXT("Root\\Device001\\0000"), 2, 0, 0);
  1524. return;
  1525. } // RegressionTest_HardwareProfile
  1526. //-----------------------------------------------------------------------------
  1527. VOID
  1528. RegressionTest_DeviceList(
  1529. HWND hDlg
  1530. )
  1531. {
  1532. CONFIGRET Status = CR_SUCCESS;
  1533. PTSTR pBuffer = NULL, p = NULL;
  1534. ULONG ulSize = 0;
  1535. TCHAR szMsg[MAX_PATH], szMsg1[MAX_PATH];
  1536. TCHAR pDeviceID[MAX_PATH];
  1537. GUID InterfaceGuid;
  1538. TCHAR szAlias[MAX_PATH];
  1539. lstrcpy(szMsg, TEXT("Test Device ID List Size:"));
  1540. Status = CM_Get_Device_ID_List_Size_Ex(&ulSize, NULL,
  1541. CM_GETIDLIST_FILTER_NONE, hMachine);
  1542. if (Status != CR_SUCCESS) {
  1543. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1544. }
  1545. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1546. lstrcat(szMsg, szMsg1);
  1547. SendDlgItemMessage(
  1548. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1549. (LPARAM)(LPTSTR)szMsg);
  1550. lstrcpy(szMsg, TEXT("Test Device ID List:"));
  1551. pBuffer = malloc(ulSize * sizeof(TCHAR));
  1552. Status = CM_Get_Device_ID_List_Ex(NULL, pBuffer, ulSize,
  1553. CM_GETIDLIST_FILTER_NONE, hMachine);
  1554. if (Status != CR_SUCCESS) {
  1555. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1556. }
  1557. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1558. lstrcat(szMsg, szMsg1);
  1559. SendDlgItemMessage(
  1560. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1561. (LPARAM)(LPTSTR)szMsg);
  1562. lstrcpy(szMsg, TEXT("Device ID List (small buffer):"));
  1563. Status = CM_Get_Device_ID_List_Ex(NULL, pBuffer, ulSize/2,
  1564. CM_GETIDLIST_FILTER_NONE, NULL);
  1565. if (Status != CR_BUFFER_SMALL) {
  1566. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1567. }
  1568. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1569. lstrcat(szMsg, szMsg1);
  1570. SendDlgItemMessage(
  1571. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1572. (LPARAM)(LPTSTR)szMsg);
  1573. free(pBuffer);
  1574. // initialize device instance and interface guid for tests
  1575. lstrcpy(pDeviceID, TEXT("Root\\PnPTest\\0000"));
  1576. UuidFromString(TEXT("aaaaaaa2-e3f0-101b-8488-00aa003e5601"), &InterfaceGuid);
  1577. // Test 1. No DevNode, Get Present
  1578. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1579. (LPARAM)(LPTSTR)TEXT("Test 1 - No Devnode, Get-present"));
  1580. /*
  1581. Status = CM_Get_Interface_Device_List_Size(&ulSize, &InterfaceGuid, 0,
  1582. CM_GET_INTERFACE_DEVICE_LIST_PRESENT);
  1583. if (Status == CR_SUCCESS) {
  1584. wsprintf(szMsg, TEXT("Size = %d"), ulSize);
  1585. } else {
  1586. wsprintf(szMsg, TEXT("Error getting size, %d"), Status);
  1587. }
  1588. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1589. (LPARAM)(LPTSTR)szMsg);
  1590. */
  1591. ulSize = 0x53;
  1592. pBuffer = malloc(ulSize * sizeof(TCHAR));
  1593. Status = CM_Get_Device_Interface_List(&InterfaceGuid, 0, pBuffer, ulSize,
  1594. CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
  1595. if (Status != CR_SUCCESS) {
  1596. wsprintf(szMsg, TEXT("Status = %d"), Status);
  1597. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1598. (LPARAM)(LPTSTR)szMsg);
  1599. } else {
  1600. for (p = pBuffer; *p; p += lstrlen(pBuffer) + 1) {
  1601. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1602. (LPARAM)(LPTSTR)p);
  1603. }
  1604. }
  1605. free(pBuffer);
  1606. // Test 2. Devnode specified, Get Present
  1607. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1608. (LPARAM)(LPTSTR)TEXT("Test 2 - Devnode, Get-present"));
  1609. Status = CM_Get_Device_Interface_List_Size(&ulSize, &InterfaceGuid, pDeviceID,
  1610. CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
  1611. if (Status == CR_SUCCESS) {
  1612. wsprintf(szMsg, TEXT("Size = %d"), ulSize);
  1613. } else {
  1614. wsprintf(szMsg, TEXT("Error getting size, %d"), Status);
  1615. }
  1616. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1617. (LPARAM)(LPTSTR)szMsg);
  1618. pBuffer = malloc(ulSize * sizeof(TCHAR));
  1619. Status = CM_Get_Device_Interface_List(&InterfaceGuid, pDeviceID, pBuffer, ulSize,
  1620. CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
  1621. if (Status != CR_SUCCESS) {
  1622. wsprintf(szMsg, TEXT("Status = %d"), Status);
  1623. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1624. (LPARAM)(LPTSTR)szMsg);
  1625. } else {
  1626. for (p = pBuffer; *p; p += lstrlen(pBuffer) + 1) {
  1627. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1628. (LPARAM)(LPTSTR)p);
  1629. }
  1630. }
  1631. free(pBuffer);
  1632. // Test 3. No Devnode, Get All
  1633. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1634. (LPARAM)(LPTSTR)TEXT("Test 3 - No Devnode, Get-all"));
  1635. Status = CM_Get_Device_Interface_List_Size(&ulSize, &InterfaceGuid, 0,
  1636. CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES);
  1637. if (Status == CR_SUCCESS) {
  1638. wsprintf(szMsg, TEXT("Size = %d"), ulSize);
  1639. } else {
  1640. wsprintf(szMsg, TEXT("Error getting size, %d"), Status);
  1641. }
  1642. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1643. (LPARAM)(LPTSTR)szMsg);
  1644. pBuffer = malloc(ulSize * sizeof(TCHAR));
  1645. Status = CM_Get_Device_Interface_List(&InterfaceGuid, 0, pBuffer, ulSize,
  1646. CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES);
  1647. if (Status != CR_SUCCESS) {
  1648. wsprintf(szMsg, TEXT("Status = %d"), Status);
  1649. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1650. (LPARAM)(LPTSTR)szMsg);
  1651. } else {
  1652. for (p = pBuffer; *p; p += lstrlen(pBuffer) + 1) {
  1653. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1654. (LPARAM)(LPTSTR)p);
  1655. ulSize = MAX_PATH;
  1656. Status = CM_Get_Device_Interface_Alias(p, &InterfaceGuid, szAlias, &ulSize, 0);
  1657. if (Status == CR_SUCCESS) {
  1658. wsprintf(szMsg, TEXT("Alias: %s"), szAlias);
  1659. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1660. (LPARAM)(LPTSTR)szMsg);
  1661. } else {
  1662. wsprintf(szMsg, TEXT("Error getting alias, %d"), Status);
  1663. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1664. (LPARAM)(LPTSTR)szMsg);
  1665. }
  1666. }
  1667. }
  1668. free(pBuffer);
  1669. // Test 4. Devnode specified, Get All
  1670. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1671. (LPARAM)(LPTSTR)TEXT("Test 4 - Devnode, Get-all"));
  1672. Status = CM_Get_Device_Interface_List_Size(&ulSize, &InterfaceGuid, pDeviceID,
  1673. CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES);
  1674. if (Status == CR_SUCCESS) {
  1675. wsprintf(szMsg, TEXT("Size = %d"), ulSize);
  1676. } else {
  1677. wsprintf(szMsg, TEXT("Error getting size, %d"), Status);
  1678. }
  1679. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1680. (LPARAM)(LPTSTR)szMsg);
  1681. pBuffer = malloc(ulSize * sizeof(TCHAR));
  1682. Status = CM_Get_Device_Interface_List(&InterfaceGuid, pDeviceID, pBuffer, ulSize,
  1683. CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES);
  1684. if (Status != CR_SUCCESS) {
  1685. wsprintf(szMsg, TEXT("Status = %d"), Status);
  1686. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1687. (LPARAM)(LPTSTR)szMsg);
  1688. } else {
  1689. for (p = pBuffer; *p; p += lstrlen(pBuffer) + 1) {
  1690. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1691. (LPARAM)(LPTSTR)p);
  1692. }
  1693. }
  1694. free(pBuffer);
  1695. // Test 5. Get aliases
  1696. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1697. (LPARAM)(LPTSTR)TEXT("Test 5 - Get aliases"));
  1698. CM_Get_Device_Interface_List_Size(&ulSize, &InterfaceGuid, pDeviceID,
  1699. CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES);
  1700. pBuffer = malloc(ulSize * sizeof(TCHAR));
  1701. CM_Get_Device_Interface_List(&InterfaceGuid, pDeviceID, pBuffer, ulSize,
  1702. CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES);
  1703. for (p = pBuffer; *p; p += lstrlen(pBuffer) + 1) {
  1704. ulSize = MAX_PATH;
  1705. Status = CM_Get_Device_Interface_Alias(p, &InterfaceGuid, szAlias, &ulSize, 0);
  1706. if (Status == CR_SUCCESS) {
  1707. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1708. (LPARAM)(LPTSTR)szAlias);
  1709. } else {
  1710. wsprintf(szMsg, TEXT("Error getting alias, %d"), Status);
  1711. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1712. (LPARAM)(LPTSTR)szMsg);
  1713. }
  1714. }
  1715. free(pBuffer);
  1716. return;
  1717. } // RegressionTest_DeviceList
  1718. //-----------------------------------------------------------------------------
  1719. VOID
  1720. RegressionTest_CreateDevNode(
  1721. HWND hDlg
  1722. )
  1723. {
  1724. CONFIGRET Status = CR_SUCCESS;
  1725. DEVNODE dnDevNode, dnParent, dnDevNode1, dnTemp;
  1726. TCHAR szMsg[MAX_PATH], szMsg1[MAX_PATH], szTemp[MAX_PATH];
  1727. ULONG ulSize = 0;
  1728. SendDlgItemMessage(
  1729. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1730. (LPARAM)TEXT("____CreateDevNode REGRESSION TEST_____"));
  1731. lstrcpy(szMsg, TEXT("1. Locate Root DevNode: "));
  1732. Status = CM_Locate_DevNode(&dnParent, NULL, CM_LOCATE_DEVNODE_NORMAL);
  1733. if (Status != CR_SUCCESS) {
  1734. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1735. }
  1736. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1737. lstrcat(szMsg, szMsg1);
  1738. SendDlgItemMessage(
  1739. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1740. (LPARAM)(LPTSTR)szMsg);
  1741. lstrcpy(szMsg, TEXT("2. Create Root\\CreateTest\\0000: "));
  1742. Status = CM_Create_DevNode(&dnDevNode, TEXT("Root\\CreateTest\\0000"),
  1743. dnParent, 0);
  1744. if (Status != CR_SUCCESS) {
  1745. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1746. }
  1747. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1748. lstrcat(szMsg, szMsg1);
  1749. SendDlgItemMessage(
  1750. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1751. (LPARAM)(LPTSTR)szMsg);
  1752. lstrcpy(szMsg, TEXT("3. Locate Root\\CreateTest\\0000: "));
  1753. Status = CM_Locate_DevNode(&dnDevNode, TEXT("Root\\CreateTest\\0000"),
  1754. CM_LOCATE_DEVNODE_NORMAL);
  1755. if (Status != CR_SUCCESS) {
  1756. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1757. }
  1758. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1759. lstrcat(szMsg, szMsg1);
  1760. SendDlgItemMessage(
  1761. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1762. (LPARAM)(LPTSTR)szMsg);
  1763. lstrcpy(szMsg, TEXT("4. Test generate id with bad device: "));
  1764. Status = CM_Create_DevNode(&dnTemp, TEXT("Create\\Test"),
  1765. dnParent, CM_CREATE_DEVNODE_GENERATE_ID);
  1766. if (Status != CR_INVALID_DEVICE_ID) {
  1767. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1768. }
  1769. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1770. lstrcat(szMsg, szMsg1);
  1771. SendDlgItemMessage(
  1772. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1773. (LPARAM)(LPTSTR)szMsg);
  1774. lstrcpy(szMsg, TEXT("5. Create based on CreateTest1: "));
  1775. Status = CM_Create_DevNode(&dnDevNode1, TEXT("CreateTest1"),
  1776. dnParent, CM_CREATE_DEVNODE_GENERATE_ID);
  1777. if (Status != CR_SUCCESS) {
  1778. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1779. }
  1780. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1781. lstrcat(szMsg, szMsg1);
  1782. SendDlgItemMessage(
  1783. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1784. (LPARAM)(LPTSTR)szMsg);
  1785. lstrcpy(szMsg, TEXT("6. Create Phantom Root\\CreateTest2\\0000: "));
  1786. Status = CM_Create_DevNode(&dnTemp, TEXT("Root\\CreateTest2\\0000"),
  1787. dnParent, CM_CREATE_DEVNODE_PHANTOM);
  1788. if (Status != CR_SUCCESS) {
  1789. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1790. }
  1791. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1792. lstrcat(szMsg, szMsg1);
  1793. SendDlgItemMessage(
  1794. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1795. (LPARAM)(LPTSTR)szMsg);
  1796. lstrcpy(szMsg, TEXT("7. Uninstall phantom Root\\CreateTest2\\0000: "));
  1797. Status = CM_Uninstall_DevNode(dnTemp, 0);
  1798. if (Status != CR_SUCCESS) {
  1799. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1800. }
  1801. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1802. lstrcat(szMsg, szMsg1);
  1803. SendDlgItemMessage(
  1804. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1805. (LPARAM)(LPTSTR)szMsg);
  1806. lstrcpy(szMsg, TEXT("8. Uninstall real Root\\CreateTest1\\0000: "));
  1807. Status = CM_Uninstall_DevNode(dnDevNode1, 0);
  1808. if (Status != CR_SUCCESS) {
  1809. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1810. }
  1811. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1812. lstrcat(szMsg, szMsg1);
  1813. SendDlgItemMessage(
  1814. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1815. (LPARAM)(LPTSTR)szMsg);
  1816. lstrcpy(szMsg, TEXT("8. Cancel remove or real Root\\CreateTest1\\0000: "));
  1817. Status = CM_Locate_DevNode(&dnDevNode1, TEXT("Root\\CreateTest1\\0000"), CM_LOCATE_DEVNODE_CANCELREMOVE);
  1818. if (Status != CR_SUCCESS) {
  1819. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1820. }
  1821. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1822. lstrcat(szMsg, szMsg1);
  1823. SendDlgItemMessage(
  1824. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1825. (LPARAM)(LPTSTR)szMsg);
  1826. lstrcpy(szMsg, TEXT("9. Register device driver for Root\\Device001\\0000: "));
  1827. Status = CM_Locate_DevNode(&dnDevNode1, TEXT("Root\\Device001\\0000"), CM_LOCATE_DEVNODE_NORMAL);
  1828. if (Status != CR_SUCCESS) {
  1829. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1830. }
  1831. else {
  1832. Status = CM_Register_Device_Driver(dnDevNode1,
  1833. CM_REGISTER_DEVICE_DRIVER_DISABLEABLE | CM_REGISTER_DEVICE_DRIVER_REMOVABLE);
  1834. if (Status != CR_SUCCESS) {
  1835. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1836. } else {
  1837. wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1838. }
  1839. }
  1840. lstrcat(szMsg, szMsg1);
  1841. SendDlgItemMessage(
  1842. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1843. (LPARAM)(LPTSTR)szMsg);
  1844. lstrcpy(szMsg, TEXT("REG1. test devnode handle consistency: "));
  1845. // create device id with generated instance
  1846. CM_Create_DevNode(&dnDevNode, TEXT("GenerateID"), dnParent,
  1847. CM_CREATE_DEVNODE_NORMAL | CM_CREATE_DEVNODE_GENERATE_ID);
  1848. // Get back the device id
  1849. CM_Get_Device_ID(dnDevNode, szTemp, MAX_PATH - 1, 0);
  1850. wsprintf(szMsg, TEXT(" Generated device instance: %s"), szTemp);
  1851. SendDlgItemMessage(
  1852. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1853. (LPARAM)(LPTSTR)szMsg);
  1854. CM_Locate_DevNode(&dnDevNode1, szTemp, 0);
  1855. if (dnDevNode != dnDevNode1) {
  1856. SendDlgItemMessage(
  1857. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1858. (LPARAM)(LPTSTR)TEXT("Created and located devnode handles don't match (error)"));
  1859. } else {
  1860. SendDlgItemMessage(
  1861. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1862. (LPARAM)(LPTSTR)TEXT("Created and located devnode handles match (expected)"));
  1863. }
  1864. // if not generating an instance, the devinst must be a full valid devinst
  1865. // with the three component parts.
  1866. lstrcpy(szMsg, TEXT("REG2. Invalid device instance, no generate: "));
  1867. Status = CM_Create_DevNode(&dnDevNode, TEXT("BadDevInst"), dnParent,
  1868. CM_CREATE_DEVNODE_NORMAL);
  1869. if (Status == CR_INVALID_DEVINST) {
  1870. lstrcat(szMsg, TEXT("Failed (expected)"));
  1871. } else {
  1872. lstrcat(szMsg, TEXT("Error: should've failed"));
  1873. }
  1874. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1875. (LPARAM)(LPTSTR)szMsg);
  1876. /*
  1877. lstrcpy(szMsg, TEXT("9. Move CreateTest\\0000 to CreateTest1\\0000: "));
  1878. Status = CM_Move_DevNode(dnDevNode, dnDevNode1, 0);
  1879. if (Status != CR_SUCCESS) {
  1880. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1881. }
  1882. else wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  1883. lstrcat(szMsg, szMsg1);
  1884. SendDlgItemMessage(
  1885. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1886. (LPARAM)(LPTSTR)szMsg);
  1887. */
  1888. return;
  1889. } // RegressionTest_CreateDevNode
  1890. //-----------------------------------------------------------------------------
  1891. VOID
  1892. RegressionTest_Properties(
  1893. HWND hDlg
  1894. )
  1895. {
  1896. CONFIGRET Status = CR_SUCCESS;
  1897. DEVNODE dnDevNode;
  1898. TCHAR szMsg[MAX_PATH], szMsg1[MAX_PATH], pszString[MAX_PATH];
  1899. LPTSTR p = NULL;
  1900. ULONG ulValue = 0, ulSize = 0, ulType = 0;
  1901. TCHAR pData[1024];
  1902. SendDlgItemMessage(
  1903. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1904. (LPARAM)TEXT("____Properties REGRESSION TEST_____"));
  1905. Status = CM_Locate_DevNode(&dnDevNode, TEXT("Root\\Device001\\0000"),
  1906. CM_LOCATE_DEVNODE_NORMAL);
  1907. if (Status != CR_SUCCESS) {
  1908. return;
  1909. }
  1910. CM_Set_DevNode_Registry_Property(dnDevNode, CM_DRP_FRIENDLYNAME, NULL, 0, 0);
  1911. lstrcpy(szMsg, TEXT("Set/Get CM_DRP_FRIENDLYNAME: "));
  1912. lstrcpy(pszString, TEXT("FriendlyName"));
  1913. ulSize = (lstrlen(pszString) + 1) * sizeof(TCHAR);
  1914. Status = CM_Set_DevNode_Registry_Property(dnDevNode, CM_DRP_FRIENDLYNAME,
  1915. pszString, ulSize, 0);
  1916. if (Status != CR_SUCCESS) {
  1917. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1918. }
  1919. else {
  1920. pszString[0] = '\0';
  1921. Status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_FRIENDLYNAME,
  1922. &ulType, pszString, &ulSize, 0);
  1923. if (Status != CR_SUCCESS) {
  1924. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1925. }
  1926. else wsprintf(szMsg1, TEXT("Passed, %s, %d"), pszString, ulType);
  1927. }
  1928. lstrcat(szMsg, szMsg1);
  1929. SendDlgItemMessage(
  1930. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1931. (LPARAM)(LPTSTR)szMsg);
  1932. CM_Set_DevNode_Registry_Property(dnDevNode, CM_DRP_DEVICEDESC, NULL, 0, 0);
  1933. lstrcpy(szMsg, TEXT("Set/Get DeviceDesc: "));
  1934. lstrcpy(pszString, TEXT("DeviceDesc"));
  1935. ulSize = (lstrlen(pszString) + 1) * sizeof(TCHAR);
  1936. Status = CM_Set_DevNode_Registry_Property(dnDevNode, CM_DRP_DEVICEDESC,
  1937. pszString, ulSize, 0);
  1938. if (Status != CR_SUCCESS) {
  1939. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1940. }
  1941. else {
  1942. pszString[0] = '\0';
  1943. Status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_DEVICEDESC,
  1944. &ulType, pszString, &ulSize, 0);
  1945. if (Status != CR_SUCCESS) {
  1946. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1947. }
  1948. else wsprintf(szMsg1, TEXT("Passed, %s, %d"), pszString, ulType);
  1949. }
  1950. lstrcat(szMsg, szMsg1);
  1951. SendDlgItemMessage(
  1952. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1953. (LPARAM)(LPTSTR)szMsg);
  1954. CM_Set_DevNode_Registry_Property(dnDevNode, CM_DRP_CONFIGFLAGS, NULL, 0, 0);
  1955. lstrcpy(szMsg, TEXT("Set/Get CM_DRP_CONFIGFLAGS: "));
  1956. ulValue = 0x0008;
  1957. ulSize = sizeof(DWORD);
  1958. Status = CM_Set_DevNode_Registry_Property(dnDevNode, CM_DRP_CONFIGFLAGS,
  1959. &ulValue, ulSize, 0);
  1960. if (Status != CR_SUCCESS) {
  1961. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1962. }
  1963. else {
  1964. ulValue = 0;
  1965. Status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_CONFIGFLAGS,
  1966. &ulType, &ulValue, &ulSize, 0);
  1967. if (Status != CR_SUCCESS) {
  1968. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1969. }
  1970. else wsprintf(szMsg1, TEXT("Passed, %d, %d"), ulValue, ulType);
  1971. }
  1972. lstrcat(szMsg, szMsg1);
  1973. SendDlgItemMessage(
  1974. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1975. (LPARAM)(LPTSTR)szMsg);
  1976. //
  1977. // CM_DRP_LOCATION_INFORMATION
  1978. //
  1979. lstrcpy(szMsg, TEXT("CM_DRP_LOCATION_INFORMATION: "));
  1980. lstrcpy(pszString, TEXT("Madeup location"));
  1981. ulSize = (lstrlen(pszString) + 1) * sizeof(TCHAR);
  1982. Status = CM_Set_DevNode_Registry_Property(dnDevNode, CM_DRP_LOCATION_INFORMATION,
  1983. pszString, ulSize, 0);
  1984. if (Status != CR_SUCCESS) {
  1985. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1986. } else {
  1987. pszString[0] = '\0';
  1988. Status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_LOCATION_INFORMATION,
  1989. &ulType, pszString, &ulSize, 0);
  1990. if (Status != CR_SUCCESS) {
  1991. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  1992. } else {
  1993. wsprintf(szMsg1, TEXT("Passed, %s, %d"), pszString, ulType);
  1994. }
  1995. }
  1996. lstrcat(szMsg, szMsg1);
  1997. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  1998. (LPARAM)(LPTSTR)szMsg);
  1999. //
  2000. // CM_DRP_UPPER_FILTERS
  2001. //
  2002. lstrcpy(szMsg, TEXT("CM_DRP_LOWERFILTERS: "));
  2003. ulSize = MAX_PATH/sizeof(WCHAR);
  2004. pszString[0] = '\0';
  2005. Status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_LOWERFILTERS,
  2006. &ulType, pszString, &ulSize, 0);
  2007. if (Status != CR_SUCCESS) {
  2008. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2009. lstrcat(szMsg, szMsg1);
  2010. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2011. (LPARAM)(LPTSTR)szMsg);
  2012. } else {
  2013. wsprintf(szMsg1, TEXT("Passed, %d"), ulType);
  2014. lstrcat(szMsg, szMsg1);
  2015. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2016. (LPARAM)(LPTSTR)szMsg);
  2017. for (p = pszString; *p; p += lstrlen(p) + 1) {
  2018. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2019. (LPARAM)(LPTSTR)p);
  2020. }
  2021. }
  2022. //
  2023. // CM_DRP_UPPER_FILTERS
  2024. //
  2025. lstrcpy(szMsg, TEXT("CM_DRP_UPPERFILTERS: "));
  2026. ulSize = MAX_PATH/sizeof(WCHAR);
  2027. pszString[0] = '\0';
  2028. Status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_UPPERFILTERS,
  2029. &ulType, pszString, &ulSize, 0);
  2030. if (Status != CR_SUCCESS) {
  2031. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2032. lstrcat(szMsg, szMsg1);
  2033. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2034. (LPARAM)(LPTSTR)szMsg);
  2035. } else {
  2036. wsprintf(szMsg1, TEXT("Passed, %d"), ulType);
  2037. lstrcat(szMsg, szMsg1);
  2038. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2039. (LPARAM)(LPTSTR)szMsg);
  2040. for (p = pszString; *p; p += lstrlen(p) + 1) {
  2041. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2042. (LPARAM)(LPTSTR)p);
  2043. }
  2044. }
  2045. //
  2046. // CM_DRP_CAPABILITIES
  2047. //
  2048. lstrcpy(szMsg, TEXT("CM_DRP_CAPABILITIES: "));
  2049. ulSize = sizeof(DWORD);
  2050. ulValue = 0;
  2051. Status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_CAPABILITIES,
  2052. &ulType, &ulValue, &ulSize, 0);
  2053. if (Status != CR_SUCCESS) {
  2054. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2055. } else {
  2056. wsprintf(szMsg1, TEXT("Passed, value = %d, %d"), ulValue, ulType);
  2057. }
  2058. lstrcat(szMsg, szMsg1);
  2059. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2060. (LPARAM)(LPTSTR)szMsg);
  2061. //
  2062. // CM_DRP_UI_NUMBER
  2063. //
  2064. lstrcpy(szMsg, TEXT("CM_DRP_UI_NUMBER: "));
  2065. ulSize = sizeof(DWORD);
  2066. ulValue = 0;
  2067. Status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_UI_NUMBER,
  2068. &ulType, &ulValue, &ulSize, 0);
  2069. if (Status != CR_SUCCESS) {
  2070. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2071. } else {
  2072. wsprintf(szMsg1, TEXT("Passed, value = %d, %d"), ulValue, ulType);
  2073. }
  2074. lstrcat(szMsg, szMsg1);
  2075. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2076. (LPARAM)(LPTSTR)szMsg);
  2077. //
  2078. // Another special test, go to a real devnode made by pnptest for this property
  2079. // since it's not in the registry: CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME
  2080. //
  2081. Status = CM_Locate_DevNode(&dnDevNode, TEXT("PnPTest\\Pdo0\\Root&LEGACY_PNPTEST&0000&1111"),
  2082. CM_LOCATE_DEVNODE_NORMAL);
  2083. if (Status != CR_SUCCESS) {
  2084. return;
  2085. }
  2086. lstrcpy(szMsg, TEXT("CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME: "));
  2087. ulSize = MAX_PATH/sizeof(WCHAR);
  2088. pszString[0] = '\0';
  2089. Status = CM_Get_DevNode_Registry_Property(dnDevNode, CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME,
  2090. &ulType, pszString, &ulSize, 0);
  2091. if (Status != CR_SUCCESS) {
  2092. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2093. } else {
  2094. wsprintf(szMsg1, TEXT("Passed, %s, %d"), pszString, ulType);
  2095. }
  2096. lstrcat(szMsg, szMsg1);
  2097. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2098. (LPARAM)(LPTSTR)szMsg);
  2099. //----------------------------------------------------------------
  2100. // Add_ID test
  2101. //----------------------------------------------------------------
  2102. // clear hardware id property
  2103. CM_Set_DevNode_Registry_Property_Ex(dnDevNode, CM_DRP_HARDWAREID, NULL,
  2104. 0, 0, hMachine);
  2105. lstrcpy(szMsg, TEXT("Add Hardware ID (SomeHardwareID\\0001): "));
  2106. Status = CM_Add_ID_Ex(dnDevNode, TEXT("SomeHardwareID\\0001"),
  2107. CM_ADD_ID_HARDWARE, hMachine);
  2108. if (Status != CR_SUCCESS) {
  2109. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2110. }
  2111. else {
  2112. wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  2113. }
  2114. lstrcat(szMsg, szMsg1);
  2115. SendDlgItemMessage(
  2116. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2117. (LPARAM)(LPTSTR)szMsg);
  2118. lstrcpy(szMsg, TEXT("Add Hardware ID (AnotherHardwareID\\0002): "));
  2119. Status = CM_Add_ID_Ex(dnDevNode, TEXT("AnotherHardwareID\\0002"),
  2120. CM_ADD_ID_HARDWARE, hMachine);
  2121. if (Status != CR_SUCCESS) {
  2122. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2123. }
  2124. else {
  2125. wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  2126. }
  2127. lstrcat(szMsg, szMsg1);
  2128. SendDlgItemMessage(
  2129. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2130. (LPARAM)(LPTSTR)szMsg);
  2131. ulSize = 1024;
  2132. Status = CM_Get_DevNode_Registry_Property_Ex(dnDevNode, CM_DRP_HARDWAREID,
  2133. &ulType, pData, &ulSize, 0, hMachine);
  2134. lstrcpy(szMsg, TEXT("Current HardwareID: "));
  2135. for (p = pData; *p; p += lstrlen(p) + 1) {
  2136. lstrcat(szMsg, p);
  2137. lstrcat(szMsg, TEXT(" "));
  2138. }
  2139. SendDlgItemMessage(
  2140. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2141. (LPARAM)(LPTSTR)szMsg);
  2142. // clear compatible id property
  2143. CM_Set_DevNode_Registry_Property_Ex(dnDevNode, CM_DRP_COMPATIBLEIDS, NULL,
  2144. 0, 0, hMachine);
  2145. lstrcpy(szMsg, TEXT("Add Compatible ID (SomeCompatibleID\\0001): "));
  2146. Status = CM_Add_ID_Ex(dnDevNode, TEXT("SomeCompatibleID\\0001"),
  2147. CM_ADD_ID_COMPATIBLE, hMachine);
  2148. if (Status != CR_SUCCESS) {
  2149. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2150. }
  2151. else {
  2152. wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  2153. }
  2154. lstrcat(szMsg, szMsg1);
  2155. SendDlgItemMessage(
  2156. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2157. (LPARAM)(LPTSTR)szMsg);
  2158. lstrcpy(szMsg, TEXT("Add Compatible ID (AnotherCompatibleID\\0002): "));
  2159. Status = CM_Add_ID_Ex(dnDevNode, TEXT("AnotherCompatibleID\\0002"),
  2160. CM_ADD_ID_COMPATIBLE, hMachine);
  2161. if (Status != CR_SUCCESS) {
  2162. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2163. }
  2164. else {
  2165. wsprintf(szMsg1, TEXT("Passed (%xh)"), Status);
  2166. }
  2167. lstrcat(szMsg, szMsg1);
  2168. SendDlgItemMessage(
  2169. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2170. (LPARAM)(LPTSTR)szMsg);
  2171. ulSize = 1024;
  2172. Status = CM_Get_DevNode_Registry_Property_Ex(dnDevNode, CM_DRP_COMPATIBLEIDS,
  2173. &ulType, pData, &ulSize, 0, hMachine);
  2174. lstrcpy(szMsg, TEXT("Current CompatibleID: "));
  2175. for (p = pData; *p; p += lstrlen(p) + 1) {
  2176. lstrcat(szMsg, p);
  2177. lstrcat(szMsg, TEXT(" "));
  2178. }
  2179. SendDlgItemMessage(
  2180. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2181. (LPARAM)(LPTSTR)szMsg);
  2182. /*
  2183. lstrcpy(szMsg, TEXT("Read CM_DRP_DEVICEDESC: "));
  2184. ulSize = MAX_PATH;
  2185. Status = CM_Get_DevNode_Registry_Property(
  2186. dnDevNode, CM_DRP_DEVICEDESC, &ulType, pszString, &ulSize, 0);
  2187. if (Status != CR_SUCCESS) {
  2188. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2189. }
  2190. else wsprintf(szMsg1, TEXT("Passed, %s %d"), pszString, ulType);
  2191. lstrcat(szMsg, szMsg1);
  2192. SendDlgItemMessage(
  2193. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2194. (LPARAM)(LPTSTR)szMsg);
  2195. lstrcpy(szMsg, TEXT("2. Read CM_DRP_HARDWAREID: "));
  2196. ulSize = MAX_PATH;
  2197. Status = CM_Get_DevNode_Registry_Property(
  2198. dnDevNode, CM_DRP_HARDWAREID, &ulType, pszString, &ulSize, 0);
  2199. if (Status != CR_SUCCESS) {
  2200. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2201. }
  2202. else {
  2203. wsprintf(szMsg1, TEXT("Passed, %d, "), ulType);
  2204. for (p = pszString; *p; p += lstrlen(p)+1) {
  2205. lstrcat(szMsg1, p);
  2206. }
  2207. }
  2208. lstrcat(szMsg, szMsg1);
  2209. SendDlgItemMessage(
  2210. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2211. (LPARAM)(LPTSTR)szMsg);
  2212. lstrcpy(szMsg, TEXT("3. Read CM_DRP_COMPATIBLEIDS: "));
  2213. ulSize = MAX_PATH;
  2214. Status = CM_Get_DevNode_Registry_Property(
  2215. dnDevNode, CM_DRP_COMPATIBLEIDS, &ulType, pszString, &ulSize, 0);
  2216. if (Status != CR_SUCCESS) {
  2217. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2218. }
  2219. else {
  2220. wsprintf(szMsg1, TEXT("Passed, %d, "), ulType);
  2221. for (p = pszString; *p; p += lstrlen(p)+1) {
  2222. lstrcat(szMsg1, p);
  2223. }
  2224. }
  2225. lstrcat(szMsg, szMsg1);
  2226. SendDlgItemMessage(
  2227. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2228. (LPARAM)(LPTSTR)szMsg);
  2229. lstrcpy(szMsg, TEXT("4. Read CM_DRP_CONFIGFLAGS: "));
  2230. ulSize = sizeof(ULONG);
  2231. Status = CM_Get_DevNode_Registry_Property(
  2232. dnDevNode, CM_DRP_CONFIGFLAGS, &ulType, &ulValue, &ulSize, 0);
  2233. if (Status != CR_SUCCESS) {
  2234. wsprintf(szMsg1, TEXT("Failed (%xh)"), Status);
  2235. }
  2236. else {
  2237. wsprintf(szMsg1, TEXT("Passed, %d %d"), ulValue, ulType);
  2238. }
  2239. lstrcat(szMsg, szMsg1);
  2240. SendDlgItemMessage(
  2241. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2242. (LPARAM)(LPTSTR)szMsg);
  2243. */
  2244. return;
  2245. } // RegressionTest_Properties
  2246. //-----------------------------------------------------------------------------
  2247. VOID
  2248. RegressionTest_DeviceClass(
  2249. HWND hDlg
  2250. )
  2251. {
  2252. CONFIGRET Status;
  2253. TCHAR szMsg[MAX_PATH], szMsg1[MAX_PATH];
  2254. TCHAR szDevice[MAX_PATH], szReference[MAX_PATH], szInterfaceDevice[MAX_PATH];
  2255. DEVNODE dnDevNode;
  2256. TCHAR Buffer[512];
  2257. PTSTR pBuffer = NULL;
  2258. GUID InterfaceGuid;
  2259. ULONG ulSize;
  2260. lstrcpy(szDevice, TEXT("PnPTest\\Pdo0\\Root&LEGACY_PNPTEST&0000&1111"));
  2261. //UuidFromString(TEXT("aaaaaaa2-e3f0-101b-8488-00aa003e5601"), &InterfaceGuid);
  2262. UuidFromString(TEXT("11111111-2222-3333-4444-555555555555"), &InterfaceGuid);
  2263. SendDlgItemMessage(
  2264. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2265. (LPARAM)TEXT("____DEVICE CLASS REGRESSION TEST_____"));
  2266. //
  2267. // get a devinst handle for this device instance
  2268. //
  2269. Status = CM_Locate_DevNode(&dnDevNode, szDevice, CM_LOCATE_DEVNODE_NORMAL);
  2270. if (Status != CR_SUCCESS) {
  2271. return;
  2272. }
  2273. //
  2274. // Register a device class assocation with a ref string
  2275. //
  2276. lstrcpy(szReference, TEXT("RefStringA"));
  2277. ulSize = MAX_PATH;
  2278. Status = CM_Register_Device_Interface(dnDevNode, &InterfaceGuid,
  2279. szReference, szInterfaceDevice,
  2280. &ulSize, 0);
  2281. if (Status == CR_SUCCESS) {
  2282. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2283. (LPARAM)(LPTSTR)szInterfaceDevice);
  2284. } else {
  2285. wsprintf(szMsg, TEXT("Error registering dev class association, %d"), Status);
  2286. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2287. (LPARAM)(LPTSTR)szMsg);
  2288. }
  2289. //
  2290. // Unregister the device class association
  2291. //
  2292. Status = CM_Unregister_Device_Interface(szInterfaceDevice, 0);
  2293. if (Status != CR_SUCCESS) {
  2294. wsprintf(szMsg, TEXT("Error unregistering dev class association, %d"), Status);
  2295. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2296. (LPARAM)(LPTSTR)szMsg);
  2297. }
  2298. //
  2299. // Register a device class association without a ref string
  2300. //
  2301. ulSize = MAX_PATH;
  2302. Status = CM_Register_Device_Interface(dnDevNode, &InterfaceGuid,
  2303. NULL, szInterfaceDevice,
  2304. &ulSize, 0);
  2305. if (Status == CR_SUCCESS) {
  2306. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2307. (LPARAM)(LPTSTR)szInterfaceDevice);
  2308. } else {
  2309. wsprintf(szMsg, TEXT("Error registering dev class association, %d"), Status);
  2310. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2311. (LPARAM)(LPTSTR)szMsg);
  2312. }
  2313. //
  2314. // Unregister the device class association
  2315. //
  2316. Status = CM_Unregister_Device_Interface(szInterfaceDevice, 0);
  2317. if (Status != CR_SUCCESS) {
  2318. wsprintf(szMsg, TEXT("Error unregistering dev class association, %d"), Status);
  2319. SendDlgItemMessage(hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2320. (LPARAM)(LPTSTR)szMsg);
  2321. }
  2322. return;
  2323. } // RegressionTest_DeviceClass
  2324. BOOL
  2325. DisplayRange(
  2326. IN HWND hDlg,
  2327. IN RANGE_LIST rlh
  2328. )
  2329. {
  2330. CONFIGRET Status = CR_SUCCESS;
  2331. DWORDLONG ulStart = 0, ulEnd = 0;
  2332. TCHAR szMsg[MAX_PATH], szTemp[MAX_PATH];
  2333. RANGE_LIST rlh1;
  2334. RANGE_ELEMENT rlElement;
  2335. Status = CM_First_Range(rlh, &ulStart, &ulEnd, &rlElement, 0);
  2336. if (Status != CR_SUCCESS) {
  2337. wsprintf(szMsg, TEXT("CM_First_Range failed (%xh)"), Status);
  2338. goto Clean0;
  2339. }
  2340. wsprintf(szMsg, TEXT("(%d,%d)"), (DWORD)ulStart, (DWORD)ulEnd);
  2341. while (Status == CR_SUCCESS) {
  2342. Status = CM_Next_Range(&rlElement, &ulStart, &ulEnd, 0);
  2343. if (Status == CR_SUCCESS) {
  2344. wsprintf(szTemp, TEXT(",(%d,%d)"), (DWORD)ulStart, (DWORD)ulEnd);
  2345. lstrcat(szMsg, szTemp);
  2346. }
  2347. }
  2348. Clean0:
  2349. SendDlgItemMessage(
  2350. hDlg, ID_LB_REGRESSION, LB_ADDSTRING, 0,
  2351. (LPARAM)(LPTSTR)szMsg);
  2352. return TRUE;
  2353. } // DisplayRange
  2354. BOOL
  2355. TraverseAndCheckParents (
  2356. DEVNODE dnParent
  2357. )
  2358. {
  2359. CONFIGRET configRet;
  2360. DEVNODE dnChild, dnDevNode;
  2361. // Get first child.
  2362. configRet = CM_Get_Child_Ex(&dnChild, dnParent, 0, hMachine);
  2363. if ((configRet != CR_SUCCESS) && (configRet != CR_NO_SUCH_DEVNODE)) {
  2364. MessageBox(NULL, TEXT("CM_Get_Child failed"), TEXT("Traversal Test"), MB_OK);
  2365. return FALSE;
  2366. }
  2367. // Check to see that the parent is correct and iterate thru the siblings.
  2368. while (configRet == CR_SUCCESS) {
  2369. configRet = CM_Get_Parent_Ex(&dnDevNode, dnChild, 0, hMachine);
  2370. if (configRet == CR_SUCCESS) {
  2371. if (dnDevNode != dnParent) {
  2372. // No parent, or not the correct parent.
  2373. MessageBox(NULL, TEXT("Not correct parent"), TEXT("Traversal Test"), MB_OK);
  2374. return FALSE;
  2375. }
  2376. } else {
  2377. MessageBox(NULL, TEXT("CM_Get_Parent failed"), TEXT("Traversal Test"), MB_OK);
  2378. return FALSE;
  2379. }
  2380. // Recursively traverse the hardware tree.
  2381. if (!TraverseAndCheckParents(dnChild)) {
  2382. return FALSE;
  2383. }
  2384. // Iterate thru the siblings.
  2385. configRet = CM_Get_Sibling_Ex(&dnChild, dnChild, 0, hMachine);
  2386. if ((configRet != CR_SUCCESS) && (configRet != CR_NO_SUCH_DEVNODE)) {
  2387. MessageBox(NULL, TEXT("CM_Get_Sibling failed"), TEXT("Traversal Test"), MB_OK);
  2388. return FALSE;
  2389. }
  2390. }
  2391. return TRUE;
  2392. } // TraverseAndCheckParents