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.

1499 lines
42 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. dc1.c
  5. Abstract:
  6. data consumer test
  7. Author:
  8. 16-Jan-1997 AlanWar
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <ole2.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #define MEMPHIS
  19. #include "wmium.h"
  20. #include "wmiumkm.h"
  21. #define OffsetToPtr(Base, Offset) ((PBYTE)((PBYTE)Base + Offset))
  22. typedef struct tagTESTGUID TESTGUID;
  23. GUID BotDynGuid = {0xce5b1020,0x8ea9,0x11d0,0xa4, 0xec, 0x00, 0xa0, 0xc9,0x06,0x29,0x10};
  24. GUID TopDynGuid = {0xce5b1023,0x8ea9,0x11d0,0xa4, 0xec, 0x00, 0xa0, 0xc9,0x06,0x29,0x10};
  25. GUID RSIGuid = {0xce5b1023,0x8ea9,0x11d0,0xa4, 0xec, 0x00, 0xa0, 0xc9,0x06,0x29,0x10};
  26. GUID RSBGuid = {0xce5b1024,0x8ea9,0x11d0,0xa4, 0xec, 0x00, 0xa0, 0xc9,0x06,0x29,0x10};
  27. // both
  28. GUID SIGuid = {0xce5b1021,0x8ea9,0x11d0,0xa4, 0xec, 0x00, 0xa0, 0xc9,0x06,0x29,0x10};
  29. GUID SBGuid = {0xce5b1022,0x8ea9,0x11d0,0xa4, 0xec, 0x00, 0xa0, 0xc9,0x06,0x29,0x10};
  30. GUID UnRegGuid = {0xce5b1025,0x8ea9,0x11d0,0xa4, 0xec, 0x00, 0xa0, 0xc9,0x06,0x29,0x10};
  31. GUID GuidNull =
  32. { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } };
  33. ULONG BufferSize = 4096;
  34. BYTE Buffer[4096];
  35. void EventCallbackRoutine0(PWNODE_HEADER WnodeHeader, ULONG Context);
  36. void EventCallbackRoutine1(PWNODE_HEADER WnodeHeader, ULONG Context);
  37. void EventCallbackRoutine2(PWNODE_HEADER WnodeHeader, ULONG Context);
  38. void EventCallbackRoutine3(PWNODE_HEADER WnodeHeader, ULONG Context);
  39. void EventCallbackRoutine4(PWNODE_HEADER WnodeHeader, ULONG Context);
  40. typedef BOOLEAN (*QADVALIDATION)(
  41. TESTGUID *TestGuid,
  42. PVOID Buffer,
  43. ULONG BufferSize
  44. );
  45. typedef ULONG (*QSINSET)(
  46. TESTGUID *TestGuid,
  47. PULONG *DataList,
  48. PULONG DataListSize,
  49. PBYTE *ValueBuffer,
  50. ULONG *ValueBufferSize,
  51. ULONG Instance
  52. );
  53. typedef ULONG (*QSITSET)(
  54. TESTGUID *TestGuid,
  55. PULONG *DataList,
  56. PULONG DataListSize,
  57. PBYTE *ValueBuffer,
  58. ULONG *ValueBufferSize,
  59. ULONG Instance,
  60. ULONG ItemId
  61. );
  62. typedef BOOLEAN (*QSINTVALIDATION)(
  63. TESTGUID *TestGuid,
  64. PULONG *DataList,
  65. PULONG DataListSize,
  66. PVOID Buffer,
  67. ULONG BufferSize,
  68. ULONG Instance
  69. );
  70. typedef PWCHAR (*GETINSTANCENAME)(
  71. TESTGUID *TestGuid,
  72. ULONG Instance
  73. );
  74. typedef struct tagTESTGUID
  75. {
  76. LPGUID Guid;
  77. HANDLE Handle;
  78. PULONG DataListSize;
  79. PULONG *InitDataList;
  80. PULONG *SINDataList;
  81. PULONG *SITDataList;
  82. PWCHAR *InstanceNames;
  83. QADVALIDATION QADValidation;
  84. ULONG QADFlags;
  85. ULONG InstanceCount;
  86. GETINSTANCENAME GetInstanceName;
  87. ULONG QSINTFlags;
  88. QSINTVALIDATION QSINTValidation;
  89. QSINSET QSINSet;
  90. ULONG ItemCount;
  91. QSITSET QSITSet;
  92. ULONG EventsSent;
  93. ULONG EventsReceived;
  94. NOTIFICATIONCALLBACK NotificationCallback;
  95. } TESTGUID;
  96. //
  97. // Common validation/set routines
  98. ULONG QSINSet(
  99. TESTGUID *TestGuid,
  100. PULONG *DataList,
  101. PULONG DataListSize,
  102. PBYTE *ValueBuffer,
  103. ULONG *ValueBufferSize,
  104. ULONG Instance
  105. )
  106. {
  107. *ValueBuffer = (PBYTE)DataList[Instance];
  108. *ValueBufferSize = DataListSize[Instance];
  109. return(ERROR_SUCCESS);
  110. }
  111. BOOLEAN QSINTValidate(
  112. TESTGUID *TestGuid,
  113. PULONG *DataList,
  114. PULONG DataListSize,
  115. PVOID Buffer,
  116. ULONG BufferSize,
  117. ULONG Instance
  118. )
  119. {
  120. PWNODE_SINGLE_INSTANCE Wnode = Buffer;
  121. PULONG Data;
  122. PULONG NameOffsets;
  123. PWCHAR Name;
  124. ULONG NameLen;
  125. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  126. (Wnode->WnodeHeader.ProviderId == 0) ||
  127. (Wnode->WnodeHeader.Version != 1) ||
  128. #ifndef MEMPHIS
  129. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  130. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  131. #endif
  132. (memcmp(&Wnode->WnodeHeader.Guid, TestGuid->Guid, sizeof(GUID)) != 0) ||
  133. (Wnode->WnodeHeader.Flags != TestGuid->QSINTFlags) ||
  134. (Wnode->SizeDataBlock != DataListSize[Instance]))
  135. {
  136. return(FALSE);
  137. }
  138. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  139. if (memcmp(Data, DataList[Instance], DataListSize[Instance]) != 0)
  140. {
  141. return(FALSE);
  142. }
  143. Name = (PWCHAR)OffsetToPtr(Wnode, Wnode->OffsetInstanceName);
  144. NameLen = wcslen(TestGuid->InstanceNames[Instance]) * sizeof(WCHAR);
  145. if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  146. (memcmp(++Name, TestGuid->InstanceNames[Instance], NameLen) != 0))
  147. {
  148. return(FALSE);
  149. }
  150. return(TRUE);
  151. }
  152. ULONG QSITSet(
  153. TESTGUID *TestGuid,
  154. PULONG *DataList,
  155. PULONG DataListSize,
  156. PBYTE *ValueBuffer,
  157. ULONG *ValueBufferSize,
  158. ULONG Instance,
  159. ULONG ItemId
  160. )
  161. {
  162. *ValueBuffer = (PBYTE)(DataList[Instance] + ItemId);
  163. *ValueBufferSize = sizeof(ULONG);
  164. return(ERROR_SUCCESS);
  165. }
  166. PWCHAR GetInstanceName(
  167. TESTGUID *TestGuid,
  168. ULONG Instance
  169. )
  170. {
  171. return(TestGuid->InstanceNames[Instance]);
  172. }
  173. //
  174. // Guid 20
  175. ULONG Values20Init_1[4] = { 1,2,3,4};
  176. ULONG Values20Init_2[4] = { 5,6,7,8};
  177. PULONG Values20Init_List[4] =
  178. {
  179. Values20Init_1,
  180. Values20Init_2,
  181. Values20Init_1,
  182. Values20Init_2
  183. };
  184. ULONG Values20_Size[4] = { 0x10,0x10,0x10,0x10 };
  185. ULONG Values20_1[4] = { 0x11111111,0x22222222,0x33333333,0x44444444};
  186. ULONG Values20_2[4] = { 0x55555555,0x66666666,0x77777777,0x88888888};
  187. ULONG Values20_3[4] = { 0x12345678,0x23456789,0x3456789A,0x456789AB};
  188. ULONG Values20_4[4] = { 0x56789ABC,0x6789ABCD,0x789ABCDE,0x89ABCDEF};
  189. PULONG Values20_List[4] =
  190. {
  191. Values20_1,
  192. Values20_2,
  193. Values20_3,
  194. Values20_4
  195. };
  196. ULONG Values20T_1[4] = { 0x1000,0x2000,0x3000,0x4000};
  197. ULONG Values20T_2[4] = { 0x50000000,0x60000000,0x70000000,0x80000000};
  198. ULONG Values20T_3[4] = { 0x90000000,0xA0000000,0xB0000000,0xC0000000};
  199. ULONG Values20T_4[4] = { 0x0000D000,0x0000E000,0x0000F000,0x00000000};
  200. PULONG Values20T_List[4] =
  201. {
  202. Values20_1,
  203. Values20_2,
  204. Values20_3,
  205. Values20_4
  206. };
  207. PWCHAR InstanceName20[4] =
  208. {
  209. L"InstanceX",
  210. L"InstanceY",
  211. L"InstanceA",
  212. L"InstanceB"
  213. };
  214. BOOLEAN QADValidate20(
  215. TESTGUID *TestGuid,
  216. PVOID Buffer,
  217. ULONG BufferSize
  218. )
  219. {
  220. PWNODE_ALL_DATA Wnode = Buffer;
  221. PULONG Data;
  222. PULONG NameOffsets;
  223. PWCHAR Name;
  224. ULONG NameLen;
  225. ULONG i;
  226. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  227. (Wnode->WnodeHeader.ProviderId == 0) ||
  228. (Wnode->WnodeHeader.Version != 1) ||
  229. #ifndef MEMPHIS
  230. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  231. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  232. #endif
  233. (memcmp(&Wnode->WnodeHeader.Guid, TestGuid->Guid, sizeof(GUID)) != 0) ||
  234. (Wnode->WnodeHeader.Flags != TestGuid->QADFlags) ||
  235. (Wnode->InstanceCount != 2) ||
  236. (Wnode->FixedInstanceSize != 0x10))
  237. {
  238. return(FALSE);
  239. }
  240. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  241. for (i = 0; i < 2; i++)
  242. {
  243. if (memcmp(Data, TestGuid->InitDataList[i], TestGuid->DataListSize[i]) != 0)
  244. {
  245. return(FALSE);
  246. }
  247. Data += 4;
  248. }
  249. NameOffsets = (ULONG *)OffsetToPtr(Wnode, Wnode->OffsetInstanceNameOffsets);
  250. for (i = 0; i < 2; i++)
  251. {
  252. Name = (PWCHAR)OffsetToPtr(Wnode, *NameOffsets++);
  253. NameLen = wcslen(TestGuid->InstanceNames[i]) * sizeof(WCHAR);
  254. if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  255. ((memcmp(++Name, TestGuid->InstanceNames[i], NameLen) != 0) &&
  256. (memcmp(Name, TestGuid->InstanceNames[i+2], NameLen) != 0)))
  257. {
  258. return(FALSE);
  259. }
  260. }
  261. //
  262. // Get second wnode in chain
  263. if (Wnode->WnodeHeader.Linkage == 0)
  264. {
  265. return(FALSE);
  266. }
  267. Wnode = (PWNODE_ALL_DATA)OffsetToPtr(Wnode, Wnode->WnodeHeader.Linkage);
  268. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  269. (Wnode->WnodeHeader.ProviderId == 0) ||
  270. (Wnode->WnodeHeader.Version != 1) ||
  271. #ifndef MEMPHIS
  272. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  273. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  274. #endif
  275. (memcmp(&Wnode->WnodeHeader.Guid, TestGuid->Guid, sizeof(GUID)) != 0) ||
  276. (Wnode->WnodeHeader.Flags != TestGuid->QADFlags) ||
  277. (Wnode->InstanceCount != 2) ||
  278. (Wnode->FixedInstanceSize != 0x10))
  279. {
  280. return(FALSE);
  281. }
  282. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  283. for (i = 2; i < 4; i++)
  284. {
  285. if (memcmp(Data, TestGuid->InitDataList[i], TestGuid->DataListSize[i]) != 0)
  286. {
  287. return(FALSE);
  288. }
  289. Data += 4;
  290. }
  291. NameOffsets = (ULONG *)OffsetToPtr(Wnode, Wnode->OffsetInstanceNameOffsets);
  292. for (i = 2; i < 4; i++)
  293. {
  294. Name = (PWCHAR)OffsetToPtr(Wnode, *NameOffsets++);
  295. NameLen = wcslen(TestGuid->InstanceNames[i]) * sizeof(WCHAR);
  296. if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  297. ((memcmp(++Name, TestGuid->InstanceNames[i], NameLen) != 0) &&
  298. (memcmp(Name, TestGuid->InstanceNames[i-2], NameLen) != 0)))
  299. {
  300. return(FALSE);
  301. }
  302. }
  303. if (Wnode->WnodeHeader.Linkage != 0)
  304. {
  305. return(FALSE);
  306. }
  307. return(TRUE);
  308. }
  309. //
  310. // Guid 21
  311. PWCHAR InstanceName21[4] =
  312. {
  313. L"InstanceX",
  314. L"InstanceY",
  315. L"InstanceA",
  316. L"InstanceB"
  317. };
  318. //
  319. // Guid 22
  320. PWCHAR InstanceName22[4] =
  321. {
  322. L"Instance2",
  323. L"Instance3",
  324. L"Instance0",
  325. L"Instance1"
  326. };
  327. //
  328. // Guid 23
  329. PWCHAR InstanceName23[4] =
  330. {
  331. L"InstanceA",
  332. L"InstanceB"
  333. };
  334. BOOLEAN QADValidate23(
  335. TESTGUID *TestGuid,
  336. PVOID Buffer,
  337. ULONG BufferSize
  338. )
  339. {
  340. PWNODE_ALL_DATA Wnode = Buffer;
  341. PULONG Data;
  342. PULONG NameOffsets;
  343. PWCHAR Name;
  344. ULONG NameLen;
  345. ULONG i;
  346. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  347. (Wnode->WnodeHeader.ProviderId == 0) ||
  348. (Wnode->WnodeHeader.Version != 1) ||
  349. #ifndef MEMPHIS
  350. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  351. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  352. #endif
  353. (memcmp(&Wnode->WnodeHeader.Guid, TestGuid->Guid, sizeof(GUID)) != 0) ||
  354. (Wnode->WnodeHeader.Flags != TestGuid->QADFlags) ||
  355. (Wnode->InstanceCount != 2) ||
  356. (Wnode->FixedInstanceSize != 0x10))
  357. {
  358. return(FALSE);
  359. }
  360. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  361. for (i = 0; i < 2; i++)
  362. {
  363. if (memcmp(Data, TestGuid->InitDataList[i], TestGuid->DataListSize[i]) != 0)
  364. {
  365. return(FALSE);
  366. }
  367. Data += 4;
  368. }
  369. NameOffsets = (ULONG *)OffsetToPtr(Wnode, Wnode->OffsetInstanceNameOffsets);
  370. for (i = 0; i < 2; i++)
  371. {
  372. Name = (PWCHAR)OffsetToPtr(Wnode, *NameOffsets++);
  373. NameLen = wcslen(TestGuid->InstanceNames[i]) * sizeof(WCHAR);
  374. if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  375. (memcmp(++Name, TestGuid->InstanceNames[i], NameLen) != 0))
  376. {
  377. return(FALSE);
  378. }
  379. }
  380. if (Wnode->WnodeHeader.Linkage != 0)
  381. {
  382. return(FALSE);
  383. }
  384. return(TRUE);
  385. }
  386. //
  387. // Guid 24
  388. PWCHAR InstanceName24[4] =
  389. {
  390. L"Instance0",
  391. L"Instance1"
  392. };
  393. #define TestCount 5
  394. TESTGUID TestList[TestCount] = {
  395. {
  396. &BotDynGuid,
  397. 0,
  398. Values20_Size,
  399. Values20Init_List,
  400. Values20_List,
  401. Values20T_List,
  402. InstanceName20,
  403. QADValidate20,
  404. (WNODE_FLAG_ALL_DATA | WNODE_FLAG_FIXED_INSTANCE_SIZE),
  405. 4,
  406. GetInstanceName,
  407. WNODE_FLAG_SINGLE_INSTANCE,
  408. QSINTValidate,
  409. QSINSet,
  410. 4,
  411. QSITSet,
  412. 0,
  413. 0,
  414. EventCallbackRoutine0
  415. },
  416. {
  417. &SIGuid,
  418. 0,
  419. Values20_Size,
  420. Values20Init_List,
  421. Values20_List,
  422. Values20T_List,
  423. InstanceName21,
  424. QADValidate20,
  425. (WNODE_FLAG_ALL_DATA | WNODE_FLAG_FIXED_INSTANCE_SIZE | WNODE_FLAG_STATIC_INSTANCE_NAMES),
  426. 4,
  427. GetInstanceName,
  428. WNODE_FLAG_SINGLE_INSTANCE | WNODE_FLAG_STATIC_INSTANCE_NAMES,
  429. QSINTValidate,
  430. QSINSet,
  431. 4,
  432. QSITSet,
  433. 0,
  434. 0,
  435. EventCallbackRoutine1
  436. },
  437. {
  438. &SBGuid,
  439. 0,
  440. Values20_Size,
  441. Values20Init_List,
  442. Values20_List,
  443. Values20T_List,
  444. InstanceName22,
  445. QADValidate20,
  446. (WNODE_FLAG_ALL_DATA | WNODE_FLAG_FIXED_INSTANCE_SIZE | WNODE_FLAG_STATIC_INSTANCE_NAMES),
  447. 4,
  448. GetInstanceName,
  449. WNODE_FLAG_SINGLE_INSTANCE | WNODE_FLAG_STATIC_INSTANCE_NAMES,
  450. QSINTValidate,
  451. QSINSet,
  452. 4,
  453. QSITSet,
  454. 0,
  455. 0,
  456. EventCallbackRoutine2
  457. },
  458. {
  459. &RSIGuid,
  460. 0,
  461. Values20_Size,
  462. Values20Init_List,
  463. Values20_List,
  464. Values20T_List,
  465. InstanceName23,
  466. QADValidate23,
  467. (WNODE_FLAG_ALL_DATA | WNODE_FLAG_FIXED_INSTANCE_SIZE | WNODE_FLAG_STATIC_INSTANCE_NAMES),
  468. 2,
  469. GetInstanceName,
  470. WNODE_FLAG_SINGLE_INSTANCE | WNODE_FLAG_STATIC_INSTANCE_NAMES,
  471. QSINTValidate,
  472. QSINSet,
  473. 4,
  474. QSITSet,
  475. 0,
  476. 0,
  477. EventCallbackRoutine3
  478. },
  479. {
  480. &RSBGuid,
  481. 0,
  482. Values20_Size,
  483. Values20Init_List,
  484. Values20_List,
  485. Values20T_List,
  486. InstanceName24,
  487. QADValidate23,
  488. (WNODE_FLAG_ALL_DATA | WNODE_FLAG_FIXED_INSTANCE_SIZE | WNODE_FLAG_STATIC_INSTANCE_NAMES),
  489. 2,
  490. GetInstanceName,
  491. WNODE_FLAG_SINGLE_INSTANCE | WNODE_FLAG_STATIC_INSTANCE_NAMES,
  492. QSINTValidate,
  493. QSINSet,
  494. 4,
  495. QSITSet,
  496. 0,
  497. 0,
  498. EventCallbackRoutine4
  499. },
  500. };
  501. ULONG QADTest(
  502. ULONG FirstTestNumber,
  503. ULONG LastTestNumber
  504. )
  505. {
  506. ULONG i;
  507. ULONG Status;
  508. for (i = FirstTestNumber; i < LastTestNumber; i++)
  509. {
  510. Status = WMIOpenBlock(NULL,
  511. TestList[i].Guid,
  512. &TestList[i].Handle);
  513. if (Status != ERROR_SUCCESS)
  514. {
  515. printf("Error: QADTest: Couldn't open Handle %d %x\n", i, Status);
  516. TestList[i].Handle = (HANDLE)NULL;
  517. }
  518. }
  519. for (i = FirstTestNumber; i < LastTestNumber;i++)
  520. {
  521. if (TestList[i].Handle != (HANDLE)NULL)
  522. {
  523. BufferSize = sizeof(Buffer);
  524. Status = WMIQueryAllData(TestList[i].Handle,
  525. &BufferSize,
  526. Buffer);
  527. if (Status == ERROR_SUCCESS)
  528. {
  529. if (! (*TestList[i].QADValidation)(&TestList[i], Buffer, BufferSize))
  530. {
  531. printf("ERROR: QADValidation %d failed\n", i);
  532. }
  533. } else {
  534. printf("Error TestList WMIQueryAllData %d failed %x\n", i, Status);
  535. }
  536. }
  537. }
  538. for (i = FirstTestNumber; i < LastTestNumber;i++)
  539. {
  540. if (TestList[i].Handle != (HANDLE)NULL)
  541. {
  542. WMICloseBlock(TestList[i].Handle);
  543. }
  544. }
  545. return(ERROR_SUCCESS);
  546. }
  547. ULONG QSINTest(
  548. ULONG FirstTestNumber,
  549. ULONG LastTestNumber
  550. )
  551. {
  552. ULONG i,j;
  553. ULONG Status;
  554. ULONG InstanceCount;
  555. PWCHAR InstanceName;
  556. PBYTE ValueBuffer;
  557. ULONG ValueBufferSize;
  558. for (i = FirstTestNumber; i < LastTestNumber; i++)
  559. {
  560. Status = WMIOpenBlock(NULL,
  561. TestList[i].Guid,
  562. &TestList[i].Handle);
  563. if (Status != ERROR_SUCCESS)
  564. {
  565. printf("Error: QSINTest: Couldn't open Handle %d %x\n", i, Status);
  566. TestList[i].Handle = (HANDLE)NULL;
  567. }
  568. InstanceCount = TestList[i].InstanceCount;
  569. for (j = 0; j < InstanceCount; j++)
  570. {
  571. InstanceName = ((*TestList[i].GetInstanceName)(&TestList[i], j));
  572. //
  573. // Initial value check
  574. BufferSize = sizeof(Buffer);
  575. Status = WMIQuerySingleInstance(TestList[i].Handle,
  576. InstanceName,
  577. &BufferSize,
  578. Buffer);
  579. if (Status == ERROR_SUCCESS)
  580. {
  581. if (! (*TestList[i].QSINTValidation)(&TestList[i],
  582. TestList[i].InitDataList,
  583. TestList[i].DataListSize,
  584. Buffer, BufferSize, j))
  585. {
  586. printf("ERROR: QSINTest Init %d/%d Validation failed %x\n", i,j,Status);
  587. }
  588. } else {
  589. printf("Error QSINTest WMIQuerySingleInstance %d/%d failed %x\n", i, j, Status);
  590. }
  591. //
  592. // Set new values
  593. (*TestList[i].QSINSet)(&TestList[i],
  594. TestList[i].SINDataList,
  595. TestList[i].DataListSize,
  596. &ValueBuffer, &ValueBufferSize, j);
  597. Status = WMISetSingleInstance(TestList[i].Handle,
  598. InstanceName,
  599. 1,
  600. ValueBufferSize,
  601. ValueBuffer);
  602. if (Status != ERROR_SUCCESS)
  603. {
  604. printf("ERROR: QSINTest WMISetSingleInstance %d/%d failed %x\n", i,j,Status);
  605. }
  606. //
  607. // Check new values set properly
  608. BufferSize = sizeof(Buffer);
  609. Status = WMIQuerySingleInstance(TestList[i].Handle,
  610. InstanceName,
  611. &BufferSize,
  612. Buffer);
  613. if (Status == ERROR_SUCCESS)
  614. {
  615. if (!(*TestList[i].QSINTValidation)(&TestList[i],
  616. TestList[i].SINDataList,
  617. TestList[i].DataListSize,
  618. Buffer, BufferSize, j))
  619. {
  620. printf("ERROR: QSINTTest %d/%d Validation # 2 failed %x\n", i,j,Status);
  621. }
  622. } else {
  623. printf("ERROR: QSINTest: WMIQuerySingleInstance %d/%d failed %x\n", i,j,Status);
  624. }
  625. //
  626. // Reset to initial values
  627. (*TestList[i].QSINSet)(&TestList[i],
  628. TestList[i].InitDataList,
  629. TestList[i].DataListSize,
  630. &ValueBuffer, &ValueBufferSize, j);
  631. Status = WMISetSingleInstance(TestList[i].Handle,
  632. InstanceName,
  633. 1,
  634. ValueBufferSize,
  635. ValueBuffer);
  636. if (Status != ERROR_SUCCESS)
  637. {
  638. printf("ERROR: QSINTTest WMISetSingleInstance Init %d/%d failed %x\n", i,j,Status);
  639. }
  640. //
  641. // Check reset to initial values
  642. BufferSize = sizeof(Buffer);
  643. Status = WMIQuerySingleInstance(TestList[i].Handle,
  644. InstanceName,
  645. &BufferSize,
  646. Buffer);
  647. if (Status == ERROR_SUCCESS)
  648. {
  649. if (!(*TestList[i].QSINTValidation)(&TestList[i],
  650. TestList[i].InitDataList,
  651. TestList[i].DataListSize,
  652. Buffer, BufferSize, j))
  653. {
  654. printf("ERROR: QSINT %d/%d Validation #2 failed %x\n", i,j,Status);
  655. }
  656. } else {
  657. printf("ERROR: WMIQuerySingleInstance # 2 %d/%d failed %x\n", i,j,Status);
  658. }
  659. }
  660. }
  661. for (i = FirstTestNumber; i < LastTestNumber;i++)
  662. {
  663. if (TestList[i].Handle != (HANDLE)NULL)
  664. {
  665. WMICloseBlock(TestList[i].Handle);
  666. }
  667. }
  668. return(ERROR_SUCCESS);
  669. }
  670. ULONG QSITTest(
  671. ULONG FirstTestNumber,
  672. ULONG LastTestNumber
  673. )
  674. {
  675. ULONG i,j,k;
  676. ULONG Status;
  677. ULONG InstanceCount;
  678. PWCHAR InstanceName;
  679. ULONG ItemCount;
  680. PBYTE ValueBuffer;
  681. ULONG ValueBufferSize;
  682. for (i = FirstTestNumber; i < LastTestNumber; i++)
  683. {
  684. Status = WMIOpenBlock(NULL,
  685. TestList[i].Guid,
  686. &TestList[i].Handle);
  687. if (Status != ERROR_SUCCESS)
  688. {
  689. printf("Error: QSITTest: Couldn't open Handle %d %x\n", i, Status);
  690. TestList[i].Handle = (HANDLE)NULL;
  691. }
  692. InstanceCount = TestList[i].InstanceCount;
  693. for (j = 0; j < InstanceCount; j++)
  694. {
  695. InstanceName = (*TestList[i].GetInstanceName)(&TestList[i],j);
  696. //
  697. // Set new values
  698. ItemCount = TestList[i].ItemCount;
  699. for (k = 0; k < ItemCount; k++)
  700. {
  701. (*TestList[i].QSITSet)(&TestList[i],
  702. TestList[i].SITDataList,
  703. TestList[i].DataListSize,
  704. &ValueBuffer, &ValueBufferSize, j,k);
  705. Status = WMISetSingleItem(TestList[i].Handle,
  706. InstanceName,
  707. k,
  708. 1,
  709. ValueBufferSize,
  710. ValueBuffer);
  711. if (Status != ERROR_SUCCESS)
  712. {
  713. printf("ERROR: QSIT WMISetSingleItem %d/%d/%d failed %x\n", i,j,k,Status);
  714. }
  715. }
  716. //
  717. // Check new values set properly
  718. BufferSize = sizeof(Buffer);
  719. Status = WMIQuerySingleInstance(TestList[i].Handle,
  720. InstanceName,
  721. &BufferSize,
  722. Buffer);
  723. if (Status == ERROR_SUCCESS)
  724. {
  725. if (!(*TestList[i].QSINTValidation)(&TestList[i],
  726. TestList[i].SITDataList,
  727. TestList[i].DataListSize,
  728. Buffer, BufferSize, j))
  729. {
  730. printf("ERROR: QSIT %d/%d Validation failed %x\n", i,j,Status);
  731. }
  732. } else {
  733. printf("ERROR: QSIT %d/%d QMIQuerySingleInstance failed %x\n", i,j,Status);
  734. }
  735. //
  736. // Reset to initial values
  737. (*TestList[i].QSINSet)(&TestList[i],
  738. TestList[i].InitDataList,
  739. TestList[i].DataListSize,
  740. &ValueBuffer, &ValueBufferSize, j);
  741. Status = WMISetSingleInstance(TestList[i].Handle,
  742. InstanceName,
  743. 1,
  744. ValueBufferSize,
  745. ValueBuffer);
  746. if (Status != ERROR_SUCCESS)
  747. {
  748. printf("ERROR: QSIT WMISetSingleInstance %d/%d failed %x\n", i,j,Status);
  749. }
  750. //
  751. // Check reset to initial values
  752. BufferSize = sizeof(Buffer);
  753. Status = WMIQuerySingleInstance(TestList[i].Handle,
  754. InstanceName,
  755. &BufferSize,
  756. Buffer);
  757. if (Status == ERROR_SUCCESS)
  758. {
  759. if (!(*TestList[i].QSINTValidation)(&TestList[i],
  760. TestList[i].InitDataList,
  761. TestList[i].DataListSize,
  762. Buffer, BufferSize, j))
  763. {
  764. printf("ERROR: QSIT %d/%d Validation # 2 failed %x\n", i,j,Status);
  765. }
  766. } else {
  767. printf("ERROR: QSIT WMISetSingleInstance # 2 %d/%d failed %x\n", i,j,Status);
  768. }
  769. }
  770. }
  771. for (i = FirstTestNumber; i < LastTestNumber;i++)
  772. {
  773. if (TestList[i].Handle != (HANDLE)NULL)
  774. {
  775. WMICloseBlock(TestList[i].Handle);
  776. }
  777. }
  778. return(ERROR_SUCCESS);
  779. }
  780. #define EventDeviceName TEXT("\\\\.\\STBTest")
  781. #define EventInstanceName L"InstanceA"
  782. ULONG EventsReceived, EventsSent;
  783. ULONG GlobalEventsReceived, GlobalEventsSent;
  784. void GlobalEventCallbackRoutine(PWNODE_HEADER WnodeHeader, ULONG Context)
  785. {
  786. PULONG Data;
  787. PWNODE_SINGLE_INSTANCE Wnode = (PWNODE_SINGLE_INSTANCE)WnodeHeader;
  788. PWCHAR Name;
  789. ULONG NameLen;
  790. GlobalEventsReceived++;
  791. if (Context != 0x12345678)
  792. {
  793. printf("Event validate failed - context\n");
  794. }
  795. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  796. (Wnode->WnodeHeader.ProviderId == 0) ||
  797. (Wnode->WnodeHeader.Version != 1) ||
  798. #ifndef MEMPHIS
  799. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  800. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  801. #endif
  802. (Wnode->WnodeHeader.Flags != (WNODE_FLAG_EVENT_ITEM | WNODE_FLAG_SINGLE_INSTANCE)) ||
  803. (Wnode->SizeDataBlock != 4))
  804. {
  805. printf("Global Event validation failed #1\n");
  806. return;
  807. }
  808. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  809. // if (Data[0] != Wnode->WnodeHeader.Linkage)
  810. // {
  811. // printf("Global Event validation failed #2\n");
  812. // return;
  813. // }
  814. Name = (PWCHAR)OffsetToPtr(Wnode, Wnode->OffsetInstanceName);
  815. NameLen = wcslen(EventInstanceName) * sizeof(WCHAR);
  816. if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  817. (memcmp(++Name, EventInstanceName, NameLen) != 0))
  818. {
  819. printf("Global Event validation failed #3\n");
  820. }
  821. }
  822. void EventCallbackRoutine0(PWNODE_HEADER WnodeHeader, ULONG Context)
  823. {
  824. PULONG Data;
  825. PWNODE_SINGLE_INSTANCE Wnode = (PWNODE_SINGLE_INSTANCE)WnodeHeader;
  826. PWCHAR Name;
  827. ULONG NameLen;
  828. if (Context != 0xABCDEF01)
  829. {
  830. printf("Event validate failed - context\n");
  831. }
  832. TestList[0].EventsReceived++;
  833. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  834. (Wnode->WnodeHeader.ProviderId == 0) ||
  835. (Wnode->WnodeHeader.Version != 1) ||
  836. #ifndef MEMPHIS
  837. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  838. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  839. #endif
  840. (memcmp(&Wnode->WnodeHeader.Guid, &BotDynGuid, sizeof(GUID)) != 0) ||
  841. (Wnode->WnodeHeader.Flags != (WNODE_FLAG_EVENT_ITEM | WNODE_FLAG_SINGLE_INSTANCE)) ||
  842. (Wnode->SizeDataBlock != 4))
  843. {
  844. printf("Event validation failed #1\n");
  845. }
  846. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  847. // if (Data[0] != Wnode->WnodeHeader.Linkage)
  848. // {
  849. // printf("Event validation failed #2\n");
  850. // }
  851. // Name = (PWCHAR)OffsetToPtr(Wnode, Wnode->OffsetInstanceName);
  852. // NameLen = wcslen(EventInstanceName) * sizeof(WCHAR);
  853. //
  854. // if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  855. // (memcmp(++Name, EventInstanceName, NameLen) != 0))
  856. // {
  857. // printf("Event validation failed #3\n");
  858. // }
  859. }
  860. void EventCallbackRoutine1(PWNODE_HEADER WnodeHeader, ULONG Context)
  861. {
  862. PULONG Data;
  863. PWNODE_SINGLE_INSTANCE Wnode = (PWNODE_SINGLE_INSTANCE)WnodeHeader;
  864. PWCHAR Name;
  865. ULONG NameLen;
  866. if (Context != 0xABCDEF01)
  867. {
  868. printf("Event validate failed - context\n");
  869. }
  870. TestList[1].EventsReceived++;
  871. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  872. (Wnode->WnodeHeader.ProviderId == 0) ||
  873. (Wnode->WnodeHeader.Version != 1) ||
  874. #ifndef MEMPHIS
  875. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  876. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  877. #endif
  878. (memcmp(&Wnode->WnodeHeader.Guid, &SIGuid, sizeof(GUID)) != 0) ||
  879. (Wnode->WnodeHeader.Flags != (WNODE_FLAG_EVENT_ITEM | WNODE_FLAG_SINGLE_INSTANCE)) ||
  880. (Wnode->SizeDataBlock != 4))
  881. {
  882. printf("Event validation failed #1\n");
  883. }
  884. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  885. // if (Data[0] != Wnode->WnodeHeader.Linkage)
  886. // {
  887. // printf("Event validation failed #2\n");
  888. // }
  889. Name = (PWCHAR)OffsetToPtr(Wnode, Wnode->OffsetInstanceName);
  890. NameLen = wcslen(EventInstanceName) * sizeof(WCHAR);
  891. if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  892. (memcmp(++Name, EventInstanceName, NameLen) != 0))
  893. {
  894. printf("Event validation failed #3\n");
  895. }
  896. }
  897. void EventCallbackRoutine2(PWNODE_HEADER WnodeHeader, ULONG Context)
  898. {
  899. PULONG Data;
  900. PWNODE_SINGLE_INSTANCE Wnode = (PWNODE_SINGLE_INSTANCE)WnodeHeader;
  901. PWCHAR Name;
  902. ULONG NameLen;
  903. if (Context != 0xABCDEF01)
  904. {
  905. printf("Event validate failed - context\n");
  906. }
  907. TestList[2].EventsReceived++;
  908. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  909. (Wnode->WnodeHeader.ProviderId == 0) ||
  910. (Wnode->WnodeHeader.Version != 1) ||
  911. #ifndef MEMPHIS
  912. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  913. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  914. #endif
  915. (memcmp(&Wnode->WnodeHeader.Guid, &SBGuid, sizeof(GUID)) != 0) ||
  916. (Wnode->WnodeHeader.Flags != (WNODE_FLAG_EVENT_ITEM | WNODE_FLAG_SINGLE_INSTANCE)) ||
  917. (Wnode->SizeDataBlock != 4))
  918. {
  919. printf("Event validation failed #1\n");
  920. }
  921. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  922. // if (Data[0] != Wnode->WnodeHeader.Linkage)
  923. // {
  924. // printf("Event validation failed #2\n");
  925. // }
  926. Name = (PWCHAR)OffsetToPtr(Wnode, Wnode->OffsetInstanceName);
  927. NameLen = wcslen(EventInstanceName) * sizeof(WCHAR);
  928. if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  929. (memcmp(++Name, EventInstanceName, NameLen) != 0))
  930. {
  931. printf("Event validation failed #3\n");
  932. }
  933. }
  934. void EventCallbackRoutine3(PWNODE_HEADER WnodeHeader, ULONG Context)
  935. {
  936. PULONG Data;
  937. PWNODE_SINGLE_INSTANCE Wnode = (PWNODE_SINGLE_INSTANCE)WnodeHeader;
  938. PWCHAR Name;
  939. ULONG NameLen;
  940. if (Context != 0xABCDEF01)
  941. {
  942. printf("Event validate failed - context\n");
  943. }
  944. TestList[3].EventsReceived++;
  945. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  946. (Wnode->WnodeHeader.ProviderId == 0) ||
  947. (Wnode->WnodeHeader.Version != 1) ||
  948. #ifndef MEMPHIS
  949. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  950. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  951. #endif
  952. (memcmp(&Wnode->WnodeHeader.Guid, &RSIGuid, sizeof(GUID)) != 0) ||
  953. (Wnode->WnodeHeader.Flags != (WNODE_FLAG_EVENT_ITEM | WNODE_FLAG_SINGLE_INSTANCE)) ||
  954. (Wnode->SizeDataBlock != 4))
  955. {
  956. printf("Event validation failed #1\n");
  957. }
  958. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  959. // if (Data[0] != Wnode->WnodeHeader.Linkage)
  960. // {
  961. // printf("Event validation failed #2\n");
  962. // }
  963. Name = (PWCHAR)OffsetToPtr(Wnode, Wnode->OffsetInstanceName);
  964. NameLen = wcslen(EventInstanceName) * sizeof(WCHAR);
  965. if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  966. (memcmp(++Name, EventInstanceName, NameLen) != 0))
  967. {
  968. printf("Event validation failed #3\n");
  969. }
  970. }
  971. void EventCallbackRoutine4(PWNODE_HEADER WnodeHeader, ULONG Context)
  972. {
  973. PULONG Data;
  974. PWNODE_SINGLE_INSTANCE Wnode = (PWNODE_SINGLE_INSTANCE)WnodeHeader;
  975. PWCHAR Name;
  976. ULONG NameLen;
  977. if (Context != 0xABCDEF01)
  978. {
  979. printf("Event validate failed - context\n");
  980. }
  981. TestList[4].EventsReceived++;
  982. if ((Wnode->WnodeHeader.BufferSize == 0) ||
  983. (Wnode->WnodeHeader.ProviderId == 0) ||
  984. (Wnode->WnodeHeader.Version != 1) ||
  985. #ifndef MEMPHIS
  986. (Wnode->WnodeHeader.TimeStamp.HighPart == 0) ||
  987. (Wnode->WnodeHeader.TimeStamp.LowPart == 0) ||
  988. #endif
  989. (memcmp(&Wnode->WnodeHeader.Guid, &RSBGuid, sizeof(GUID)) != 0) ||
  990. (Wnode->WnodeHeader.Flags != (WNODE_FLAG_EVENT_ITEM | WNODE_FLAG_SINGLE_INSTANCE)) ||
  991. (Wnode->SizeDataBlock != 4))
  992. {
  993. printf("Event validation failed #1\n");
  994. }
  995. Data = (ULONG *)OffsetToPtr(Wnode, Wnode->DataBlockOffset);
  996. // if (Data[0] != Wnode->WnodeHeader.Linkage)
  997. // {
  998. // printf("Event validation failed #2\n");
  999. // }
  1000. Name = (PWCHAR)OffsetToPtr(Wnode, Wnode->OffsetInstanceName);
  1001. NameLen = wcslen(EventInstanceName) * sizeof(WCHAR);
  1002. if (((*Name != NameLen) && (*Name != NameLen+sizeof(WCHAR))) ||
  1003. (memcmp(++Name, EventInstanceName, NameLen) != 0))
  1004. {
  1005. printf("Event validation failed #3\n");
  1006. }
  1007. }
  1008. void EventTest(
  1009. ULONG Unused1,
  1010. ULONG Unused2
  1011. )
  1012. {
  1013. HANDLE STBHandle;
  1014. BOOLEAN f;
  1015. ULONG retsize;
  1016. ULONG Status;
  1017. ULONG WnodeEventSize;
  1018. PWNODE_SINGLE_INSTANCE Wnode;
  1019. PWCHAR InstanceNamePtr;
  1020. PULONG DataPtr;
  1021. ULONG i,j;
  1022. ULONG Size;
  1023. HANDLE DataBlockHandle;
  1024. Status = WMIOpenBlock(NULL,
  1025. &SIGuid,
  1026. &DataBlockHandle);
  1027. if (Status != ERROR_SUCCESS)
  1028. {
  1029. printf("ERROR: Couldn't open data block %x\n", Status);
  1030. return;
  1031. }
  1032. Size = sizeof(WNODE_SINGLE_INSTANCE) +
  1033. sizeof(EventInstanceName) + sizeof(WCHAR) +
  1034. 1 * sizeof(ULONG);
  1035. Wnode = malloc(Size);
  1036. if (Wnode == NULL)
  1037. {
  1038. printf("ERROR: couldn't alloc mem for event\n");
  1039. return;
  1040. }
  1041. STBHandle = CreateFile(
  1042. EventDeviceName,
  1043. GENERIC_READ | GENERIC_WRITE,
  1044. 0,
  1045. NULL,
  1046. OPEN_EXISTING,
  1047. FILE_ATTRIBUTE_NORMAL,
  1048. NULL
  1049. );
  1050. if (STBHandle == (HANDLE)-1)
  1051. {
  1052. printf("ERROR - couldn't open Event device file %x\n",
  1053. GetLastError());
  1054. free(Wnode);
  1055. return;
  1056. }
  1057. Status = WMINotificationRegistration(&GuidNull,
  1058. TRUE,
  1059. GlobalEventCallbackRoutine,
  1060. 0x12345678,
  1061. NULL,
  1062. 0,
  1063. 0);
  1064. if (Status != ERROR_SUCCESS)
  1065. {
  1066. printf("ERROR: WMINotificationRegistration Global Enable failed %x\n", Status);
  1067. }
  1068. for (j = 0; j < TestCount; j++)
  1069. {
  1070. Status = WMINotificationRegistration(TestList[j].Guid,
  1071. TRUE,
  1072. TestList[j].NotificationCallback,
  1073. 0xABCDEF01,
  1074. NULL,
  1075. 0,
  1076. 0);
  1077. if (Status != ERROR_SUCCESS)
  1078. {
  1079. printf("ERROR: WMINotificationRegistration Enable %d failed %x\n", j, Status);
  1080. free(Wnode);
  1081. goto done;
  1082. }
  1083. }
  1084. Wnode->WnodeHeader.BufferSize = Size;
  1085. Wnode->WnodeHeader.TimeStamp.LowPart = 1;
  1086. Wnode->WnodeHeader.TimeStamp.HighPart = 1;
  1087. Wnode->WnodeHeader.Flags = WNODE_FLAG_SINGLE_INSTANCE | WNODE_FLAG_EVENT_ITEM | WNODE_FLAG_STATIC_INSTANCE_NAMES;
  1088. Wnode->WnodeHeader.Version = 1;
  1089. // InstanceNamePtr = (PWCHAR)(&Wnode->VariableData);
  1090. // *InstanceNamePtr = sizeof(EventInstanceName);
  1091. // wcscpy(InstanceNamePtr + 1, EventInstanceName);
  1092. // DataPtr = (ULONG *)((PBYTE)InstanceNamePtr + sizeof(EventInstanceName) + sizeof(WCHAR));
  1093. // Wnode->OffsetInstanceName = (ULONG)((ULONG)InstanceNamePtr - (ULONG)Wnode);
  1094. DataPtr = (ULONG *)&Wnode->VariableData;
  1095. Wnode->SizeDataBlock = 4;
  1096. Wnode->DataBlockOffset = (ULONG)((ULONG)DataPtr - (ULONG)Wnode );
  1097. EventsSent = 0;
  1098. EventsReceived = 0;
  1099. GlobalEventsSent = 0;
  1100. GlobalEventsReceived = 0;
  1101. for (i = 0; i < 25; i++)
  1102. {
  1103. DataPtr[0] = i;
  1104. for (j = 0; j < TestCount; j++)
  1105. {
  1106. memcpy(&Wnode->WnodeHeader.Guid, TestList[j].Guid, sizeof(GUID));
  1107. Wnode->InstanceIndex = i % 5;
  1108. f = DeviceIoControl( STBHandle,
  1109. IOCTL_WMI_GENERATE_EVENT,
  1110. Wnode,
  1111. Wnode->WnodeHeader.BufferSize,
  1112. NULL,
  1113. 0,
  1114. &retsize,
  1115. NULL);
  1116. if (! f)
  1117. {
  1118. printf("ERROR: DeviceIoCOntrol(EventGen) failed %x\n", Wnode);
  1119. } else {
  1120. TestList[j].EventsSent++;
  1121. GlobalEventsSent++;
  1122. }
  1123. Sleep(1000);
  1124. }
  1125. }
  1126. //
  1127. // Send event for unregistered guid
  1128. memcpy(&Wnode->WnodeHeader.Guid, &UnRegGuid, sizeof(GUID));
  1129. Wnode->WnodeHeader.Linkage = i;
  1130. DataPtr[0] = i;
  1131. f = DeviceIoControl( STBHandle,
  1132. IOCTL_WMI_GENERATE_EVENT,
  1133. Wnode,
  1134. Wnode->WnodeHeader.BufferSize,
  1135. NULL,
  1136. 0,
  1137. &retsize,
  1138. NULL);
  1139. if (! f)
  1140. {
  1141. printf("ERROR: DeviceIoCOntrol(EventGen) failed\n");
  1142. } else {
  1143. GlobalEventsSent++;
  1144. }
  1145. Sleep(10000);
  1146. for (j = 0; j < TestCount; j++)
  1147. {
  1148. Status = WMINotificationRegistration(TestList[j].Guid,
  1149. FALSE,
  1150. NULL,
  1151. 0,
  1152. NULL,
  1153. 0,
  1154. 0);
  1155. if (Status != ERROR_SUCCESS)
  1156. {
  1157. printf("ERROR: WMINotificationRegistration disable %d failed %x\n", j, Status);
  1158. }
  1159. }
  1160. Status = WMINotificationRegistration(&GuidNull,
  1161. FALSE,
  1162. NULL,
  1163. 0,
  1164. NULL,
  1165. 0,
  1166. 0);
  1167. if (Status != ERROR_SUCCESS)
  1168. {
  1169. printf("ERROR: WMINotificationRegistration disable GuidNull failed %x\n", Status);
  1170. }
  1171. free(Wnode);
  1172. for (j = 0; j < TestCount; j++)
  1173. {
  1174. if (TestList[j].EventsReceived != TestList[j].EventsSent)
  1175. {
  1176. printf("Error - Sent %d events, but received %d for %d\n",
  1177. TestList[j].EventsSent, TestList[j].EventsReceived, j);
  1178. }
  1179. printf("Error - Sent %d events, but received %d for %d\n",
  1180. TestList[j].EventsSent, TestList[j].EventsReceived, j);
  1181. }
  1182. if (GlobalEventsReceived != GlobalEventsSent)
  1183. {
  1184. printf("Error - Sent %d global events, but received %d\n",
  1185. GlobalEventsSent, GlobalEventsReceived);
  1186. }
  1187. printf("Error - Sent %d global events, but received %d\n",
  1188. GlobalEventsSent, GlobalEventsReceived);
  1189. done:
  1190. WMICloseBlock(DataBlockHandle);
  1191. CloseHandle(STBHandle);
  1192. }
  1193. typedef ULONG (*THREADFUNC)(
  1194. ULONG FirstTestNumber,
  1195. ULONG LastTestNumber
  1196. );
  1197. typedef struct
  1198. {
  1199. THREADFUNC ThreadFunc;
  1200. ULONG FirstTestNumber;
  1201. ULONG LastTestNumber;
  1202. } LAUNCHCTX, *PLAUNCHCTX;
  1203. ULONG LaunchThreadProc(PVOID Context)
  1204. {
  1205. PLAUNCHCTX LaunchCtx = (PLAUNCHCTX)Context;
  1206. (*LaunchCtx->ThreadFunc)(LaunchCtx->FirstTestNumber,
  1207. LaunchCtx->LastTestNumber);
  1208. return(0);
  1209. }
  1210. void LaunchThread(
  1211. THREADFUNC ThreadFunc,
  1212. ULONG FirstTestNumber,
  1213. ULONG LastTestNumber
  1214. )
  1215. {
  1216. PLAUNCHCTX LaunchCtx;
  1217. HANDLE ThreadHandle;
  1218. LaunchCtx = (PLAUNCHCTX)malloc(sizeof(LAUNCHCTX));
  1219. if (LaunchCtx != NULL)
  1220. {
  1221. LaunchCtx->ThreadFunc = ThreadFunc;
  1222. LaunchCtx->FirstTestNumber = FirstTestNumber;
  1223. LaunchCtx->LastTestNumber = LastTestNumber;
  1224. ThreadHandle = CreateThread(NULL,
  1225. 0,
  1226. LaunchThreadProc,
  1227. &LaunchCtx,
  1228. 0,
  1229. NULL);
  1230. if (ThreadHandle != NULL)
  1231. {
  1232. CloseHandle(ThreadHandle);
  1233. }
  1234. }
  1235. }
  1236. int _cdecl main(int argc, char *argv[])
  1237. {
  1238. printf("At Main in DC1\n");
  1239. QADTest(0, TestCount);
  1240. QSINTest(0, TestCount);
  1241. QSITTest(0, TestCount);
  1242. EventTest(0, TestCount);
  1243. return(ERROR_SUCCESS);
  1244. }