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.

940 lines
24 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. method.c
  5. Abstract:
  6. acpi mapper test app
  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. #include "wmium.h"
  19. GUID AAGuid = {0xABBC0F5A, 0x8ea1, 0x11d1, 0x00, 0xa0, 0xc9, 0x06, 0x29, 0x10, 0x00, 0x00};
  20. GUID ABGuid = {0xABBC0F5B, 0x8ea1, 0x11d1, 0x00, 0xa0, 0xc9, 0x06, 0x29, 0x10, 0x00, 0x00};
  21. GUID A0Guid = {0xABBC0F5C, 0x8ea1, 0x11d1, 0x00, 0xa0, 0xc9, 0x06, 0x29, 0x10, 0x00, 0x00};
  22. GUID BAGuid = {0xABBC0F6A, 0x8ea1, 0x11d1, 0x00, 0xa0, 0xc9, 0x06, 0x29, 0x10, 0x00, 0x00};
  23. GUID BBGuid = {0xABBC0F6B, 0x8ea1, 0x11d1, 0x00, 0xa0, 0xc9, 0x06, 0x29, 0x10, 0x00, 0x00};
  24. GUID B0Guid = {0xABBC0F6C, 0x8ea1, 0x11d1, 0x00, 0xa0, 0xc9, 0x06, 0x29, 0x10, 0x00, 0x00};
  25. GUID CAGuid = {0xABBC0F7A, 0x8ea1, 0x11d1, 0x00, 0xa0, 0xc9, 0x06, 0x29, 0x10, 0x00, 0x00};
  26. #define OffsetToPtr(Base, Offset) ((PBYTE)((PBYTE)Base + Offset))
  27. ULONG InstanceCount;
  28. PCHAR *InstanceNames;
  29. #define InstanceName0 InstanceNames[0]
  30. #define InstanceName1 InstanceNames[1]
  31. #define InstanceName2 InstanceNames[2]
  32. #define MYSTRING L"XYZZY-PLUGH-PLOVER"
  33. WCHAR FUNNYSTRING[] = { sizeof(MYSTRING), MYSTRING };
  34. ULONG ValueBuffer[4] = { 0x66666666, 0x77777777, 0x88888888, 0x99999999 };
  35. ULONG DetermineInstanceNames(
  36. LPGUID Guid,
  37. PULONG InstanceCount,
  38. PCHAR **InstanceNamePtrArray
  39. )
  40. {
  41. ULONG j;
  42. WMIHANDLE Handle;
  43. ULONG status;
  44. ULONG bufferSize;
  45. PUCHAR buffer;
  46. ULONG i, iCount, linkage;
  47. PWNODE_ALL_DATA WAD;
  48. PCHAR *iNames;
  49. PULONG pInstanceNameOffsets;
  50. PCHAR pName;
  51. PUSHORT pNameSize;
  52. status = WmiOpenBlock(Guid,
  53. GENERIC_READ,
  54. &Handle);
  55. if (status != ERROR_SUCCESS)
  56. {
  57. printf("WmiOpenBlock(Statyus) => %d\n", status);
  58. return(status);
  59. }
  60. bufferSize = 0x1000;
  61. buffer = NULL;
  62. status = ERROR_INSUFFICIENT_BUFFER;
  63. while (status == ERROR_INSUFFICIENT_BUFFER)
  64. {
  65. if (buffer != NULL)
  66. {
  67. free(buffer);
  68. }
  69. buffer = malloc(bufferSize);
  70. if (buffer == NULL)
  71. {
  72. status = ERROR_NOT_ENOUGH_MEMORY;
  73. break;
  74. }
  75. status = WmiQueryAllData(Handle,
  76. &bufferSize,
  77. buffer);
  78. }
  79. if (status == ERROR_SUCCESS)
  80. {
  81. WAD = (PWNODE_ALL_DATA)buffer;
  82. linkage = 0;
  83. iCount = 0;
  84. do
  85. {
  86. WAD = (PWNODE_ALL_DATA)OffsetToPtr(WAD, linkage);
  87. linkage = WAD->WnodeHeader.Linkage;
  88. iCount += WAD->InstanceCount;
  89. } while (linkage != 0);
  90. iNames = malloc(iCount * sizeof(PCHAR));
  91. if (iNames == NULL)
  92. {
  93. status = ERROR_NOT_ENOUGH_MEMORY;
  94. return(status);
  95. }
  96. WAD = (PWNODE_ALL_DATA)buffer;
  97. linkage = 0;
  98. i = 0;
  99. do
  100. {
  101. WAD = (PWNODE_ALL_DATA)OffsetToPtr(WAD, linkage);
  102. pInstanceNameOffsets = (PULONG)OffsetToPtr(WAD, WAD->OffsetInstanceNameOffsets);
  103. for (j = 0; j < WAD->InstanceCount; j++)
  104. {
  105. pNameSize = (PUSHORT)OffsetToPtr(WAD, pInstanceNameOffsets[j]);
  106. pName = (PCHAR)OffsetToPtr(pNameSize, sizeof(USHORT));
  107. iNames[i] = malloc(*pNameSize + 1);
  108. if (iNames[i] == NULL)
  109. {
  110. status = ERROR_NOT_ENOUGH_MEMORY;
  111. return(status);
  112. }
  113. memset(iNames[i], 0, *pNameSize + 1);
  114. memcpy(iNames[i], pName, *pNameSize);
  115. i++;
  116. }
  117. linkage = WAD->WnodeHeader.Linkage;
  118. } while (linkage != 0);
  119. } else {
  120. printf("QAD(status) -> %d\n", status);
  121. }
  122. free(buffer);
  123. *InstanceCount = iCount;
  124. *InstanceNamePtrArray = iNames;
  125. return(ERROR_SUCCESS);
  126. }
  127. PCHAR GuidToString(
  128. PCHAR s,
  129. LPGUID piid
  130. )
  131. {
  132. sprintf(s, "%x-%x-%x-%x%x%x%x%x%x%x%x",
  133. piid->Data1, piid->Data2,
  134. piid->Data3,
  135. piid->Data4[0], piid->Data4[1],
  136. piid->Data4[2], piid->Data4[3],
  137. piid->Data4[4], piid->Data4[5],
  138. piid->Data4[6], piid->Data4[7]);
  139. return(s);
  140. }
  141. ULONG
  142. QuerySetCheck(
  143. LPGUID Guid,
  144. PCHAR InstanceName,
  145. BOOLEAN UseString,
  146. BOOLEAN *Success
  147. )
  148. {
  149. WMIHANDLE WmiHandle;
  150. BYTE Buffer[4096];
  151. ULONG BufferSize;
  152. PUCHAR CheckValue, Value;
  153. ULONG CheckSize, ValueSize;
  154. CHAR s[MAX_PATH];
  155. ULONG Status;
  156. PWNODE_SINGLE_INSTANCE Wnode;
  157. if (UseString)
  158. {
  159. Value = (PUCHAR)FUNNYSTRING;
  160. ValueSize = sizeof(FUNNYSTRING);
  161. } else {
  162. Value = (PUCHAR)ValueBuffer;
  163. ValueSize = sizeof(ValueBuffer);
  164. }
  165. Status = WmiOpenBlock(Guid, 0, &WmiHandle);
  166. if (Status == ERROR_SUCCESS)
  167. {
  168. Status = WmiSetSingleInstance(WmiHandle,
  169. InstanceName,
  170. 0,
  171. ValueSize,
  172. Value);
  173. if (Status == ERROR_SUCCESS)
  174. {
  175. BufferSize = sizeof(Buffer);
  176. Status = WmiQuerySingleInstance(WmiHandle,
  177. InstanceName,
  178. &BufferSize,
  179. Buffer);
  180. if (Status == ERROR_SUCCESS)
  181. {
  182. Wnode = (PWNODE_SINGLE_INSTANCE)Buffer;
  183. CheckValue = Buffer + Wnode->DataBlockOffset;
  184. CheckSize = Wnode->SizeDataBlock;
  185. *Success = ((CheckSize == ValueSize) &&
  186. (memcmp(CheckValue, Value, ValueSize) == 0));
  187. } else {
  188. printf("QuerySetCheck: WmiQuerySingleInstance(%s) -> %d\n",
  189. GuidToString(s, Guid),
  190. Status);
  191. }
  192. } else {
  193. printf("QuerySetCheck: WmiSetSingleInstance(%s) -> %d\n",
  194. GuidToString(s, Guid),
  195. Status);
  196. }
  197. WmiCloseBlock(WmiHandle);
  198. } else {
  199. printf("QuerySetCheck: WmiOpenBlock(%s) -> %d\n",
  200. GuidToString(s, Guid),
  201. Status);
  202. }
  203. return(Status);
  204. }
  205. ULONG
  206. TrySmallQuery(
  207. LPGUID Guid,
  208. PCHAR InstanceName
  209. )
  210. {
  211. UCHAR Buffer[4096];
  212. ULONG BufferSize;
  213. ULONG Status;
  214. WMIHANDLE WmiHandle;
  215. CHAR s[MAX_PATH];
  216. Status = WmiOpenBlock(Guid, 0, &WmiHandle);
  217. if (Status == ERROR_SUCCESS)
  218. {
  219. BufferSize = 0;
  220. Status = ERROR_INSUFFICIENT_BUFFER;
  221. while (Status == ERROR_INSUFFICIENT_BUFFER)
  222. {
  223. printf("TrySmallQuery(%s): size %d --> ",
  224. GuidToString(s, Guid),
  225. BufferSize);
  226. Status = WmiQuerySingleInstance(WmiHandle,
  227. InstanceName,
  228. &BufferSize,
  229. Buffer);
  230. printf("%d\n", Status);
  231. }
  232. printf("TrySmallQuery(%s): -> %d size %d\n",
  233. GuidToString(s, Guid),
  234. Status,
  235. BufferSize);
  236. } else {
  237. printf("TrySmallQuery: WmiOpenBlock(%s) -> %d\n",
  238. GuidToString(s, Guid),
  239. Status);
  240. }
  241. return(Status);
  242. }
  243. typedef struct
  244. {
  245. HANDLE Event;
  246. PUCHAR Value;
  247. ULONG ValueSize;
  248. BOOLEAN Success;
  249. } CHECK_EVENT_CONTEXT, *PCHECK_EVENT_CONTEXT;
  250. void NotificationRoutine(
  251. PWNODE_HEADER Wnode,
  252. ULONG Context
  253. )
  254. {
  255. PWNODE_SINGLE_INSTANCE WnodeSi = (PWNODE_SINGLE_INSTANCE)Wnode;
  256. PUCHAR CheckValue, Value;
  257. ULONG CheckSize, ValueSize;
  258. PCHECK_EVENT_CONTEXT CheckEventContext;
  259. CHAR s[MAX_PATH];
  260. HANDLE Handle;
  261. ULONG Status;
  262. Status = RpcImpersonateClient(0);
  263. printf("RpcImpersonateClient -> %d\n", Status);
  264. Handle = CreateFile("foo.bar",
  265. GENERIC_READ,
  266. 0,
  267. NULL,
  268. OPEN_EXISTING,
  269. FILE_ATTRIBUTE_NORMAL,
  270. NULL);
  271. if (Handle == INVALID_HANDLE_VALUE)
  272. {
  273. printf("Error opening locked file %d\n", GetLastError());
  274. } else {
  275. printf("Opened locked file\n");
  276. CloseHandle(Handle);
  277. }
  278. if (Status == ERROR_SUCCESS)
  279. {
  280. RpcRevertToSelf();
  281. }
  282. printf("Event Received for %s\n", GuidToString(s, &Wnode->Guid));
  283. CheckEventContext = (PCHECK_EVENT_CONTEXT)Context;
  284. CheckSize = WnodeSi->SizeDataBlock;
  285. CheckValue = ((PUCHAR)WnodeSi) + WnodeSi->DataBlockOffset;
  286. ValueSize = CheckEventContext->ValueSize;
  287. Value = CheckEventContext->Value;
  288. if ((CheckSize != ValueSize) ||
  289. (memcmp(CheckValue, Value, ValueSize) != 0))
  290. {
  291. printf("Event Data doesn't match %x %d != %x %d\n",
  292. Value, ValueSize, CheckValue, CheckSize);
  293. } else {
  294. CheckEventContext->Success = TRUE;
  295. }
  296. SetEvent(CheckEventContext->Event);
  297. }
  298. ULONG
  299. DoMethodAndCatchEvent(
  300. LPGUID MethodGuid,
  301. PCHAR InstanceName,
  302. LPGUID EventGuid,
  303. BOOLEAN UseString,
  304. BOOLEAN EnableEvent,
  305. PBOOLEAN MethodSuccess,
  306. PBOOLEAN EventSuccess
  307. )
  308. {
  309. UCHAR Buffer[4096];
  310. ULONG BufferSize;
  311. ULONG Status, Status2;
  312. WMIHANDLE WmiHandle;
  313. PUCHAR CheckValue, Value;
  314. ULONG CheckSize, ValueSize;
  315. HANDLE Event;
  316. CHAR s[MAX_PATH];
  317. PCHECK_EVENT_CONTEXT CheckEventContext;
  318. PWNODE_SINGLE_INSTANCE Wnode;
  319. CheckEventContext = (PCHECK_EVENT_CONTEXT)malloc(sizeof(CHECK_EVENT_CONTEXT));
  320. if (CheckEventContext != NULL)
  321. {
  322. Event = CreateEvent(NULL, FALSE, FALSE, NULL);
  323. CheckEventContext->Event = Event;
  324. if (UseString)
  325. {
  326. Value = (PUCHAR)FUNNYSTRING;
  327. ValueSize = sizeof(FUNNYSTRING);
  328. } else {
  329. Value = (PUCHAR)ValueBuffer;
  330. ValueSize = sizeof(ValueBuffer);
  331. }
  332. CheckEventContext->Value = Value;
  333. CheckEventContext->ValueSize = ValueSize;
  334. CheckEventContext->Success = FALSE;
  335. Status = WmiOpenBlock(MethodGuid, 0, &WmiHandle);
  336. if (Status == ERROR_SUCCESS)
  337. {
  338. if (EnableEvent)
  339. {
  340. Status = WmiNotificationRegistration(EventGuid,
  341. TRUE,
  342. NotificationRoutine,
  343. (ULONG)CheckEventContext,
  344. NOTIFICATION_CALLBACK_DIRECT);
  345. } else {
  346. Status = ERROR_SUCCESS;
  347. }
  348. if (Status == ERROR_SUCCESS)
  349. {
  350. CheckSize = sizeof(Buffer);
  351. Status = WmiExecuteMethod(WmiHandle,
  352. InstanceName,
  353. 1,
  354. ValueSize,
  355. Value,
  356. &CheckSize,
  357. Buffer);
  358. if (Status == ERROR_SUCCESS)
  359. {
  360. CheckValue = (PUCHAR)Buffer;
  361. *MethodSuccess = ((CheckSize == ValueSize) &&
  362. (memcmp(CheckValue, Value, ValueSize) == 0));
  363. Status2 = WaitForSingleObject(Event, 10*1000);
  364. if (Status2 == WAIT_OBJECT_0)
  365. {
  366. *EventSuccess = CheckEventContext->Success;
  367. free(CheckEventContext);
  368. } else {
  369. printf("Event for %s not received\n",
  370. GuidToString(s, EventGuid));
  371. }
  372. } else {
  373. printf("DoMethodAndCatchEvent: WmiExecuteMethod(%s) -> %d\n",
  374. GuidToString(s, MethodGuid),
  375. Status);
  376. }
  377. if (EnableEvent)
  378. {
  379. WmiNotificationRegistration(EventGuid,
  380. FALSE,
  381. NULL,
  382. 0,
  383. NOTIFICATION_CALLBACK_DIRECT);
  384. }
  385. } else {
  386. printf("DoMethodAndCatchEvent: WmiNotificationRegistration(%s) -> %d\n",
  387. GuidToString(s, EventGuid),
  388. Status);
  389. }
  390. WmiCloseBlock(WmiHandle);
  391. } else {
  392. printf("DoMethodAndCatchEvent: WmiOpenBlock(%s) -> %d\n",
  393. GuidToString(s, MethodGuid),
  394. Status);
  395. }
  396. }
  397. return(Status);
  398. }
  399. void TinyQueryTest(
  400. void
  401. )
  402. {
  403. ULONG Status;
  404. Status = TrySmallQuery(&AAGuid,
  405. InstanceName0);
  406. Status = TrySmallQuery(&BAGuid,
  407. InstanceName0);
  408. Status = TrySmallQuery(&BAGuid,
  409. InstanceName1);
  410. Status = TrySmallQuery(&BAGuid,
  411. InstanceName2);
  412. Status = TrySmallQuery(&CAGuid,
  413. InstanceName2);
  414. }
  415. ULONG QuerySetStuffTest(
  416. LPGUID Guid,
  417. CHAR *InstanceName,
  418. BOOLEAN UseString,
  419. PULONG QueryStatus,
  420. PULONG SetStatus
  421. )
  422. {
  423. WMIHANDLE WmiHandle;
  424. BYTE Buffer[4096];
  425. ULONG BufferSize;
  426. PUCHAR Value;
  427. ULONG ValueSize;
  428. CHAR s[MAX_PATH];
  429. ULONG Status;
  430. if (UseString)
  431. {
  432. Value = (PUCHAR)FUNNYSTRING;
  433. ValueSize = sizeof(FUNNYSTRING);
  434. } else {
  435. Value = (PUCHAR)ValueBuffer;
  436. ValueSize = sizeof(ValueBuffer);
  437. }
  438. Status = WmiOpenBlock(Guid, 0, &WmiHandle);
  439. if (Status == ERROR_SUCCESS)
  440. {
  441. *SetStatus = WmiSetSingleInstance(WmiHandle,
  442. InstanceName,
  443. 0,
  444. ValueSize,
  445. Value);
  446. BufferSize = sizeof(Buffer);
  447. *QueryStatus = WmiQuerySingleInstance(WmiHandle,
  448. InstanceName,
  449. &BufferSize,
  450. Buffer);
  451. WmiCloseBlock(WmiHandle);
  452. } else {
  453. printf("QuerySetTest: WmiOpenBlock(%s) -> %d\n",
  454. GuidToString(s, Guid),
  455. Status);
  456. }
  457. return(Status);
  458. }
  459. ULONG SetBadStringTest(
  460. LPGUID Guid,
  461. CHAR *InstanceName,
  462. ULONG BadStringLength,
  463. PUCHAR BadString,
  464. PULONG SetStatus
  465. )
  466. {
  467. WMIHANDLE WmiHandle;
  468. PUCHAR Value;
  469. ULONG ValueSize;
  470. CHAR s[MAX_PATH];
  471. ULONG Status;
  472. Value = (PUCHAR)BadString;
  473. ValueSize = BadStringLength;
  474. Status = WmiOpenBlock(Guid, 0, &WmiHandle);
  475. if (Status == ERROR_SUCCESS)
  476. {
  477. *SetStatus = WmiSetSingleInstance(WmiHandle,
  478. InstanceName,
  479. 0,
  480. ValueSize,
  481. Value);
  482. WmiCloseBlock(WmiHandle);
  483. } else {
  484. printf("SetBadString: WmiOpenBlock(%s) -> %d\n",
  485. GuidToString(s, Guid),
  486. Status);
  487. }
  488. return(Status);
  489. }
  490. ULONG ExecuteMethodTest(
  491. LPGUID Guid,
  492. CHAR *InstanceName,
  493. BOOLEAN UseString,
  494. PULONG OutBufferSize,
  495. PUCHAR OutBuffer,
  496. PULONG ExecuteStatus
  497. )
  498. {
  499. WMIHANDLE WmiHandle;
  500. CHAR s[MAX_PATH];
  501. PUCHAR Value;
  502. ULONG ValueSize;
  503. ULONG Status;
  504. if (UseString)
  505. {
  506. Value = (PUCHAR)FUNNYSTRING;
  507. ValueSize = sizeof(FUNNYSTRING);
  508. } else {
  509. Value = (PUCHAR)ValueBuffer;
  510. ValueSize = sizeof(ValueBuffer);
  511. }
  512. Status = WmiOpenBlock(Guid, 0, &WmiHandle);
  513. if (Status == ERROR_SUCCESS)
  514. {
  515. *ExecuteStatus = WmiExecuteMethod(WmiHandle,
  516. InstanceName,
  517. 1,
  518. ValueSize,
  519. Value,
  520. OutBufferSize,
  521. OutBuffer);
  522. WmiCloseBlock(WmiHandle);
  523. } else {
  524. printf("ExecuteMehtod: WmiOpenBlock(%s) -> %d\n",
  525. GuidToString(s, Guid),
  526. Status);
  527. }
  528. return(Status);
  529. }
  530. void QuerySetEventAndMethodTest(
  531. void
  532. )
  533. {
  534. ULONG Status;
  535. ULONG QueryStatus, SetStatus;
  536. Status = QuerySetStuffTest(&A0Guid,
  537. InstanceName0,
  538. FALSE,
  539. &QueryStatus,
  540. &SetStatus);
  541. if (Status == ERROR_SUCCESS)
  542. {
  543. printf("QuerySetStuffTest(&A0) Query -> %d, Set -> %d\n",
  544. QueryStatus,
  545. SetStatus);
  546. } else {
  547. printf("QuerySetTest: WmiOpenBlock(abbc0f5c-... is ok, not a failure\n");
  548. }
  549. Status = QuerySetStuffTest(&ABGuid,
  550. InstanceName0,
  551. TRUE,
  552. &QueryStatus,
  553. &SetStatus);
  554. if (Status != ERROR_SUCCESS)
  555. {
  556. printf("QUerySetStuffTest(&AB) failed %d\n", Status);
  557. }
  558. if ((Status == ERROR_SUCCESS) &&
  559. ((QueryStatus == ERROR_SUCCESS) || (SetStatus == ERROR_SUCCESS)))
  560. {
  561. printf("QuerySetStuffTest(&AB) Query -> %d, Set -> %d\n",
  562. QueryStatus,
  563. SetStatus);
  564. }
  565. }
  566. void
  567. SetBadStringsTest(
  568. void
  569. )
  570. {
  571. UCHAR BadStringBuffer[0x100];
  572. ULONG Status, SetStatus;
  573. *((PWCHAR)BadStringBuffer) = 0x7890;
  574. Status = SetBadStringTest(&AAGuid,
  575. InstanceName0,
  576. sizeof(BadStringBuffer),
  577. BadStringBuffer,
  578. &SetStatus);
  579. if (Status != ERROR_SUCCESS)
  580. {
  581. printf("SetBadStringTest too long failed %d\n", Status);
  582. }
  583. if ((Status == ERROR_SUCCESS) && (SetStatus == ERROR_SUCCESS))
  584. {
  585. printf("SetBadStringTest: too long -> %d\n", SetStatus);
  586. }
  587. memset(BadStringBuffer, 0xa9, sizeof(BadStringBuffer));
  588. *((PWCHAR)BadStringBuffer) = 0x10;
  589. Status = SetBadStringTest(&AAGuid,
  590. InstanceName0,
  591. sizeof(BadStringBuffer),
  592. BadStringBuffer,
  593. &SetStatus);
  594. if ((Status == ERROR_SUCCESS) && (SetStatus == ERROR_SUCCESS))
  595. {
  596. printf("SetBadStringTest: bad string -> %d - this is not a failure\n", SetStatus);
  597. } else {
  598. printf("SetBadStringTest bad string failed %d\n", Status);
  599. }
  600. }
  601. void
  602. SetEmptyTest(
  603. void
  604. )
  605. {
  606. UCHAR BadStringBuffer[0x100];
  607. ULONG Status, SetStatus;
  608. Status = SetBadStringTest(&AAGuid,
  609. InstanceName0,
  610. 0,
  611. BadStringBuffer,
  612. &SetStatus);
  613. if ((Status == ERROR_SUCCESS) && (SetStatus != ERROR_SUCCESS))
  614. {
  615. printf("SetEmptyTest: -> %d\n", SetStatus);
  616. }
  617. Status = SetBadStringTest(&BAGuid,
  618. InstanceName0,
  619. 0,
  620. BadStringBuffer,
  621. &SetStatus);
  622. if ((Status == ERROR_SUCCESS) && (SetStatus != ERROR_SUCCESS))
  623. {
  624. printf("SetEmptyTest(BA): -> %d\n", SetStatus);
  625. }
  626. // TODO: check that instances actually set to empty
  627. }
  628. void
  629. ExecuteEmptyTest(
  630. void
  631. )
  632. {
  633. UCHAR OutBuffer[0x100];
  634. ULONG Status, SetStatus;
  635. ULONG OutSize;
  636. Status = ExecuteMethodTest(&ABGuid,
  637. InstanceName0,
  638. TRUE,
  639. &OutSize,
  640. NULL,
  641. &SetStatus);
  642. if ((Status == ERROR_SUCCESS) && (SetStatus != ERROR_SUCCESS))
  643. {
  644. printf("ExecuteMethodTest (void): -> %d, size = %d\n", SetStatus, OutSize);
  645. }
  646. OutSize = 1;
  647. Status = ExecuteMethodTest(&ABGuid,
  648. InstanceName0,
  649. TRUE,
  650. &OutSize,
  651. OutBuffer,
  652. &SetStatus);
  653. if ((Status == ERROR_SUCCESS) && (SetStatus != ERROR_INSUFFICIENT_BUFFER))
  654. {
  655. printf("ExecuteMethodTest (too small): -> %d, size = %d\n", SetStatus, OutSize);
  656. }
  657. Status = ExecuteMethodTest(&ABGuid,
  658. InstanceName0,
  659. TRUE,
  660. &OutSize,
  661. OutBuffer,
  662. &SetStatus);
  663. if ((Status == ERROR_SUCCESS) && (SetStatus != ERROR_SUCCESS))
  664. {
  665. printf("ExecuteMethodTest (right size): -> %d, size = %d\n", SetStatus, OutSize);
  666. }
  667. }
  668. void
  669. QuerySetTest(
  670. void
  671. )
  672. {
  673. ULONG Status;
  674. BOOLEAN Success;
  675. Status = QuerySetCheck(&AAGuid,
  676. InstanceName0,
  677. TRUE,
  678. &Success);
  679. if (Status == ERROR_SUCCESS)
  680. {
  681. if ( ! Success)
  682. {
  683. printf("QuerySetTest AAGuid Data didn't match\n");
  684. }
  685. }
  686. Status = QuerySetCheck(&BAGuid,
  687. InstanceName0,
  688. FALSE,
  689. &Success);
  690. if (Status == ERROR_SUCCESS)
  691. {
  692. if ( ! Success)
  693. {
  694. printf("QuerySetTest BAGuid 0 Data didn't match\n");
  695. }
  696. }
  697. Status = QuerySetCheck(&BAGuid,
  698. InstanceName1,
  699. FALSE,
  700. &Success);
  701. if (Status == ERROR_SUCCESS)
  702. {
  703. if ( ! Success)
  704. {
  705. printf("QuerySetTest BAGuid 1 Data didn't match\n");
  706. }
  707. }
  708. Status = QuerySetCheck(&BAGuid,
  709. InstanceName2,
  710. FALSE,
  711. &Success);
  712. if (Status == ERROR_SUCCESS)
  713. {
  714. if ( ! Success)
  715. {
  716. printf("QuerySetTest BAGuid 2 Data didn't match\n");
  717. }
  718. }
  719. }
  720. void
  721. FireEventTest(
  722. void
  723. )
  724. {
  725. ULONG Status;
  726. BOOLEAN MethodSuccess, EventSuccess;
  727. Status = DoMethodAndCatchEvent(&ABGuid,
  728. InstanceName0,
  729. &A0Guid,
  730. TRUE,
  731. TRUE,
  732. &MethodSuccess,
  733. &EventSuccess);
  734. if (Status == ERROR_SUCCESS)
  735. {
  736. if (! MethodSuccess)
  737. {
  738. printf("FireEventTest AAGuid Method Data didn't match\n");
  739. }
  740. if (! EventSuccess)
  741. {
  742. printf("FireEventTest AAGuid Event Data didn't match\n");
  743. }
  744. }
  745. Status = DoMethodAndCatchEvent(&BBGuid,
  746. InstanceName0,
  747. &B0Guid,
  748. FALSE,
  749. TRUE,
  750. &MethodSuccess,
  751. &EventSuccess);
  752. if (Status == ERROR_SUCCESS)
  753. {
  754. if (! MethodSuccess)
  755. {
  756. printf("FireEventTest BBGuid Method Data didn't match\n");
  757. }
  758. if (! EventSuccess)
  759. {
  760. printf("FireEventTest BBGuid Event Data didn't match\n");
  761. }
  762. }
  763. }
  764. int _cdecl main(int argc, char *argv[])
  765. {
  766. ULONG Status;
  767. Status = DetermineInstanceNames(&BAGuid,
  768. &InstanceCount,
  769. &InstanceNames);
  770. if (Status != ERROR_SUCCESS)
  771. {
  772. printf("DetermineInstanceNames failed %d\n", Status);
  773. return(Status);
  774. }
  775. #if 1
  776. //
  777. // Expected successful completion tests
  778. TinyQueryTest();
  779. QuerySetTest();
  780. FireEventTest();
  781. //
  782. // Error condition tests
  783. QuerySetEventAndMethodTest();
  784. SetBadStringsTest();
  785. SetEmptyTest();
  786. ExecuteEmptyTest();
  787. #endif
  788. return(ERROR_SUCCESS);
  789. }