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.

973 lines
45 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // BVTReposit.CPP
  4. //
  5. //
  6. // Copyright (c)2000 Microsoft Corporation, All Rights Reserved
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include <bvt.h>
  10. #define NO_ERRORS_EXPECTED FALSE,__FILE__,__LINE__
  11. #define ERRORS_CAN_BE_EXPECTED TRUE,__FILE__,__LINE__
  12. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  13. //*****************************************************************************************************************
  14. // UTility functions for this file only
  15. //*****************************************************************************************************************
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. int OpenNamespaceAndCreateTestClasses( CAutoDeleteString & sNamespace, IWbemServices ** ppNamespace)
  18. {
  19. int nRc = FATAL_ERROR;
  20. //=========================================================
  21. // Get the name of the test namespace that was created
  22. //=========================================================
  23. if( g_Options.GetOptionsForAPITest(sNamespace,APITEST4))
  24. {
  25. //=========================================================
  26. // Create classes with different properties. Some of
  27. // these should be in the following inheritance chain and
  28. // some should not inherit from the others at all:
  29. // classes = {A, B, C, D:A, E:A, F:E, G:F, H:G, I:F}.
  30. // A mix of simple string & sint32 keys are fine.
  31. //=========================================================
  32. CAutoDeleteString sClassList;
  33. if( g_Options.GetOptionsForAPITest(sClassList, APITEST5))
  34. {
  35. ClassList MasterList;
  36. //=======================================================
  37. // Get the list of the classes to be created
  38. //=======================================================
  39. if( InitMasterListOfClasses(sClassList.GetPtr(),MasterList))
  40. {
  41. // ==================================================
  42. // Open the namespace
  43. // ==================================================
  44. nRc = OpenNamespaceAndKeepOpen( ppNamespace, sNamespace.GetPtr(),TRUE);
  45. if( SUCCESS == nRc )
  46. {
  47. for( int i = 0; i < MasterList.Size(); i++ )
  48. {
  49. ClassInfo * p = MasterList.GetAt(i);
  50. CAutoDeleteString sClassInformation;
  51. if( g_Options.GetSpecificOptionForAPITest(p->Class,sClassInformation,APITEST5) )
  52. {
  53. //===========================================================
  54. // Add the keys and properties
  55. //===========================================================
  56. nRc = CreateClassAndLogErrors(*ppNamespace,p->Class, sClassInformation.GetPtr(), sNamespace.GetPtr(),NO_ERRORS_EXPECTED);
  57. if( nRc != SUCCESS )
  58. {
  59. break;
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }
  67. return nRc;
  68. }
  69. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  70. int OpenNamespaceAndCreateTestClassesAndAssociations( CAutoDeleteString & sNamespace, IWbemServices ** ppNamespace)
  71. {
  72. // =====================================================================
  73. // Open the namespace and create all of the test classes, this happens
  74. // a lot, so is is a utility function
  75. // =====================================================================
  76. int nRc = OpenNamespaceAndCreateTestClasses( sNamespace, ppNamespace );
  77. if( nRc == SUCCESS )
  78. {
  79. //=================================================
  80. // Get the list of associations to create
  81. //=================================================
  82. CAutoDeleteString sClassList;
  83. if( g_Options.GetOptionsForAPITest(sClassList, APITEST7))
  84. {
  85. ClassList MasterList;
  86. //=======================================================
  87. // Parse the list of the associations to be created
  88. //=======================================================
  89. if( InitMasterListOfClasses(sClassList.GetPtr(),MasterList))
  90. {
  91. for( int i = 0; i < MasterList.Size(); i++ )
  92. {
  93. ClassInfo * p = MasterList.GetAt(i);
  94. CAutoDeleteString sClassInformation;
  95. // =============================================================
  96. // Get definition of the association
  97. // =============================================================
  98. if( g_Options.GetSpecificOptionForAPITest(p->Class,sClassInformation,APITEST7) )
  99. {
  100. //===========================================================
  101. // Create the association
  102. //===========================================================
  103. nRc = CreateAssociationAndLogErrors(*ppNamespace,p->Class,sClassInformation.GetPtr(), sNamespace.GetPtr());
  104. if( nRc != SUCCESS )
  105. {
  106. break;
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }
  113. return nRc;
  114. }
  115. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  116. //*****************************************************************************************************************
  117. // Test 1
  118. //*****************************************************************************************************************
  119. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  120. int BasicConnectUsingIWbemLocator(void)
  121. {
  122. int nRc = FATAL_ERROR;
  123. IWbemServices * pNamespace = NULL;
  124. CAutoDeleteString sNamespace;
  125. if( g_Options.GetOptionsForAPITest(sNamespace, APITEST1) )
  126. {
  127. // =====================================================================
  128. // Open the namespace
  129. // =====================================================================
  130. nRc = OpenNamespaceAndKeepOpen( &pNamespace, sNamespace.GetPtr(),FALSE);
  131. // =====================================================================
  132. // Release the pointers
  133. // =====================================================================
  134. SAFE_RELEASE_PTR(pNamespace);
  135. }
  136. return nRc;
  137. }
  138. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  139. //*****************************************************************************************************************
  140. // Test 2
  141. //*****************************************************************************************************************
  142. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  143. int BasicSyncConnectUsingIWbemConnection(void)
  144. {
  145. int nRc = FATAL_ERROR;
  146. IWbemConnection * pConnection = NULL;
  147. CAutoDeleteString sNamespace;
  148. CAutoDeleteString sClass;
  149. if( g_Options.GetOptionsForAPITest(sNamespace,sClass,APITEST2) )
  150. {
  151. nRc = CoCreateInstanceAndLogErrors(CLSID_WbemConnection,IID_IWbemConnection,(void**)&pConnection,NO_ERRORS_EXPECTED);
  152. if( SUCCESS == nRc )
  153. {
  154. // =================================================================
  155. // Test Open with all three types:
  156. //
  157. // IWbemServices
  158. // IWbemServicesEx
  159. // IWbemClassObject
  160. //
  161. // Initialize all vars
  162. // =================================================================
  163. short FatalErrors = 0;
  164. // =================================================================
  165. // Open the namespace with IWbemServices
  166. // =================================================================
  167. IWbemServices * pNamespace = NULL;
  168. nRc = OpenObjectAndLogErrors(pConnection, IID_IWbemServices, (void**) &pNamespace, sNamespace.GetPtr(),NO_ERRORS_EXPECTED);
  169. if ( nRc != SUCCESS )
  170. {
  171. FatalErrors++;
  172. }
  173. SAFE_RELEASE_PTR(pNamespace);
  174. // =================================================================
  175. // Open the namespace with IWbemServicesEx
  176. // =================================================================
  177. IWbemServicesEx * pNamespaceEx = NULL;
  178. nRc = OpenObjectAndLogErrors(pConnection, IID_IWbemServicesEx, (void**) &pNamespaceEx,sNamespace.GetPtr(),NO_ERRORS_EXPECTED);
  179. if ( nRc != SUCCESS )
  180. {
  181. FatalErrors++;
  182. }
  183. SAFE_RELEASE_PTR(pNamespaceEx);
  184. // =================================================================
  185. // Open the Class for IWbemClassObject
  186. // =================================================================
  187. IWbemClassObject* pWbemClassObject = NULL;
  188. nRc = OpenObjectAndLogErrors(pConnection, IID_IWbemClassObject, (void**) &pWbemClassObject,sClass.GetPtr(),NO_ERRORS_EXPECTED);
  189. if ( nRc != SUCCESS )
  190. {
  191. FatalErrors++;
  192. }
  193. SAFE_RELEASE_PTR(pWbemClassObject);
  194. // =================================================================
  195. // Check to see if there were any fatal errors
  196. // =================================================================
  197. if( !FatalErrors )
  198. {
  199. nRc = SUCCESS;
  200. }
  201. }
  202. // =====================================================================
  203. // Release the locator
  204. // =====================================================================
  205. SAFE_RELEASE_PTR(pConnection);
  206. }
  207. return nRc;
  208. }
  209. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  210. //*****************************************************************************************************************
  211. // Test 3
  212. //*****************************************************************************************************************
  213. int BasicAsyncConnectUsingIWbemConnection(void)
  214. {
  215. int nRc = FATAL_ERROR;
  216. HRESULT hr = S_OK;
  217. IWbemConnection * pConnection = NULL;
  218. CAutoDeleteString sNamespace;
  219. CAutoDeleteString sClass;
  220. if( g_Options.GetOptionsForAPITest(sNamespace,sClass,APITEST2) )
  221. {
  222. nRc = CoCreateInstanceAndLogErrors(CLSID_WbemConnection,IID_IWbemConnection,(void**)&pConnection,NO_ERRORS_EXPECTED);
  223. if( SUCCESS == nRc )
  224. {
  225. // =================================================================
  226. // Test Open with all three types:
  227. //
  228. // IWbemServices
  229. // IWbemServicesEx
  230. // IWbemClassObject
  231. //
  232. // Initialize all the vars
  233. // =================================================================
  234. short FatalErrors = 0;
  235. CSinkEx * pHandler = NULL;
  236. pHandler = new CSinkEx;
  237. if( pHandler )
  238. {
  239. // =================================================================
  240. // Open the namespace with IWbemServices
  241. // =================================================================
  242. nRc = OpenObjectAsyncAndLogErrors(pConnection, IID_IWbemServices,sNamespace.GetPtr(),pHandler,NO_ERRORS_EXPECTED);
  243. if ( nRc == FATAL_ERROR )
  244. {
  245. FatalErrors++;
  246. }
  247. else
  248. {
  249. IWbemServices * pNamespace = NULL;
  250. pHandler->WaitForSignal(INFINITE);
  251. hr = pHandler->GetStatusCode();
  252. if(SUCCEEDED(hr))
  253. {
  254. pNamespace = (IWbemServices*)pHandler->GetInterface();
  255. }
  256. SAFE_RELEASE_PTR(pNamespace);
  257. }
  258. }
  259. else
  260. {
  261. g_LogFile.LogError(__FILE__,__LINE__,FATAL_ERROR, L"Allocation of new CSinkEx Failed - Out of memory.");
  262. }
  263. SAFE_DELETE_PTR(pHandler);
  264. // =================================================================
  265. // Open the namespace with IWbemServicesEx
  266. // =================================================================
  267. pHandler = new CSinkEx;
  268. if( pHandler )
  269. {
  270. nRc = OpenObjectAsyncAndLogErrors(pConnection, IID_IWbemServicesEx,sNamespace.GetPtr(), pHandler,NO_ERRORS_EXPECTED);
  271. if ( nRc == FATAL_ERROR )
  272. {
  273. FatalErrors++;
  274. }
  275. else
  276. {
  277. IWbemServicesEx * pNamespace = NULL;
  278. pHandler->WaitForSignal(INFINITE);
  279. hr = pHandler->GetStatusCode();
  280. if(SUCCEEDED(hr))
  281. {
  282. pNamespace = (IWbemServicesEx*)pHandler->GetInterface();
  283. }
  284. SAFE_RELEASE_PTR(pNamespace);
  285. }
  286. }
  287. else
  288. {
  289. g_LogFile.LogError(__FILE__,__LINE__,FATAL_ERROR, L"Allocation of new CSinkEx Failed - Out of memory.");
  290. }
  291. SAFE_DELETE_PTR(pHandler);
  292. // =================================================================
  293. // Open the class for IWbemClassObject
  294. // =================================================================
  295. pHandler = new CSinkEx;
  296. if( pHandler )
  297. {
  298. nRc = OpenObjectAsyncAndLogErrors(pConnection, IID_IWbemClassObject,sClass.GetPtr(), pHandler,NO_ERRORS_EXPECTED);
  299. if ( nRc == FATAL_ERROR )
  300. {
  301. FatalErrors++;
  302. }
  303. else
  304. {
  305. IWbemClassObject * pWbemClassObject = NULL;
  306. pHandler->WaitForSignal(INFINITE);
  307. hr = pHandler->GetStatusCode();
  308. if(SUCCEEDED(hr))
  309. {
  310. pWbemClassObject = (IWbemClassObject*)pHandler->GetInterface();
  311. }
  312. SAFE_RELEASE_PTR(pWbemClassObject);
  313. }
  314. }
  315. else
  316. {
  317. g_LogFile.LogError(__FILE__,__LINE__,FATAL_ERROR, L"Allocation of new CSinkEx Failed - Out of memory.");
  318. }
  319. SAFE_DELETE_PTR(pHandler);
  320. // =================================================================
  321. // Check to see if there are any fatal errors
  322. // =================================================================
  323. if( !FatalErrors )
  324. {
  325. nRc = SUCCESS;
  326. }
  327. }
  328. // =====================================================================
  329. // Release the locator
  330. // =====================================================================
  331. SAFE_RELEASE_PTR(pConnection);
  332. }
  333. return nRc;
  334. }
  335. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  336. //*****************************************************************************************************************
  337. // Test 4
  338. //*****************************************************************************************************************
  339. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  340. int CreateNewTestNamespace()
  341. {
  342. int nRc = SUCCESS;
  343. CAutoDeleteString sNamespace;
  344. CAutoDeleteString sInstance;
  345. if( g_Options.GetOptionsForAPITest(sNamespace, sInstance, APITEST4))
  346. {
  347. IWbemLocator * pLocator = NULL;
  348. nRc = CoCreateInstanceAndLogErrors(CLSID_WbemLocator,IID_IWbemLocator,(void**)&pLocator,NO_ERRORS_EXPECTED);
  349. if( SUCCESS == nRc )
  350. {
  351. //==========================================================================
  352. // Parse the namespace name to get the parent first, and open the parent
  353. // this one must be existing
  354. //==========================================================================
  355. IWbemServices * pParentNamespace = NULL;
  356. IWbemServices * pChildNamespace = NULL;
  357. nRc = ConnectServerAndLogErrors(pLocator,&pParentNamespace,sNamespace.GetPtr(),NO_ERRORS_EXPECTED);
  358. if( nRc == SUCCESS )
  359. {
  360. //==============================================================
  361. // If we got here, then we know that the child namespace does
  362. // not exist, so create it.
  363. //==============================================================
  364. nRc = CreateInstances(pParentNamespace, sInstance, sNamespace.GetPtr(), APITEST4 );
  365. if( SUCCESS == nRc )
  366. {
  367. //==========================================================
  368. // Open the namespace with IWbemServices as the new parent
  369. //==========================================================
  370. nRc = ConnectServerAndLogErrors(pLocator, &pChildNamespace, sNamespace.GetPtr(),NO_ERRORS_EXPECTED);
  371. }
  372. }
  373. SAFE_RELEASE_PTR(pParentNamespace);
  374. SAFE_RELEASE_PTR(pChildNamespace);
  375. }
  376. // =============================================================================
  377. // Release the locator
  378. // =============================================================================
  379. SAFE_RELEASE_PTR(pLocator);
  380. }
  381. return nRc;
  382. }
  383. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  384. //*****************************************************************************************************************
  385. // Test 5
  386. //*****************************************************************************************************************
  387. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  388. int CreateNewClassesInTestNamespace()
  389. {
  390. int nRc = FATAL_ERROR;
  391. CAutoDeleteString sNamespace;
  392. IWbemServices * pNamespace = NULL;
  393. // =====================================================================
  394. // Open the namespace and create all of the test classes, this happens
  395. // a lot, so is is a utility function
  396. // =====================================================================
  397. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  398. // =====================================================================
  399. // Release the pointers
  400. // =====================================================================
  401. SAFE_RELEASE_PTR(pNamespace);
  402. return nRc;
  403. }
  404. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  405. //*****************************************************************************************************************
  406. // Test 6
  407. //*****************************************************************************************************************
  408. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  409. int DeleteAndRecreateNewClassesInTestNamespace()
  410. {
  411. int nRc = FATAL_ERROR;
  412. CAutoDeleteString sNamespace;
  413. IWbemServices * pNamespace = NULL;
  414. // =====================================================================
  415. // Open the namespace and create all of the test classes, this happens
  416. // a lot, so is is a utility function
  417. // =====================================================================
  418. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  419. if( nRc == SUCCESS )
  420. {
  421. //=========================================
  422. // Get all of the class operations for
  423. // this test:
  424. // Classes to be deleted
  425. // Classes to be compared
  426. // Classes to be added
  427. // Classes to be compared
  428. // Classes to be added_deleted
  429. // Classes to be compared
  430. //=============================================
  431. CAutoDeleteString sDeleteClasses;
  432. CAutoDeleteString sClassesAfterDelete;
  433. CAutoDeleteString sAddClasses;
  434. CAutoDeleteString sClassesAfterAdd;
  435. CAutoDeleteString sDeleteAddClassOrder;
  436. CAutoDeleteString sClassesAfterDeleteAdd;
  437. if( g_Options.GetOptionsForAPITest( sDeleteClasses, sClassesAfterDelete,sAddClasses,
  438. sClassesAfterAdd,sDeleteAddClassOrder,
  439. sClassesAfterDeleteAdd ) )
  440. {
  441. nRc = DeleteClasses(sDeleteClasses, pNamespace, sNamespace.GetPtr());
  442. if( nRc == SUCCESS )
  443. {
  444. nRc = EnumerateClassesAndCompare(sClassesAfterDelete, pNamespace, sNamespace.GetPtr());
  445. if( nRc == SUCCESS )
  446. {
  447. nRc = AddClasses(sAddClasses, pNamespace, sNamespace.GetPtr());
  448. if( nRc == SUCCESS )
  449. {
  450. nRc = EnumerateClassesAndCompare(sClassesAfterAdd, pNamespace, sNamespace.GetPtr());
  451. if( nRc == SUCCESS )
  452. {
  453. nRc = DeleteAndAddClasses(sDeleteAddClassOrder, pNamespace, sNamespace.GetPtr());
  454. if( nRc == SUCCESS )
  455. {
  456. nRc = EnumerateClassesAndCompare(sClassesAfterDeleteAdd, pNamespace, sNamespace.GetPtr());
  457. }
  458. }
  459. }
  460. }
  461. }
  462. }
  463. }
  464. // =====================================================================
  465. // Release the pointers
  466. // =====================================================================
  467. SAFE_RELEASE_PTR(pNamespace);
  468. return nRc;
  469. }
  470. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  471. //*****************************************************************************************************************
  472. // Test 7
  473. //*****************************************************************************************************************
  474. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  475. int CreateSimpleAssociations()
  476. {
  477. int nRc = FATAL_ERROR;
  478. // =====================================================================
  479. // Made into a utility function as it is used more than once
  480. // =====================================================================
  481. CAutoDeleteString sNamespace;
  482. IWbemServices * pNamespace = NULL;
  483. nRc = OpenNamespaceAndCreateTestClassesAndAssociations( sNamespace,&pNamespace);
  484. // =====================================================================
  485. // Release the pointers
  486. // =====================================================================
  487. SAFE_RELEASE_PTR(pNamespace);
  488. return nRc;
  489. }
  490. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  491. //*****************************************************************************************************************
  492. // Test 8
  493. //*****************************************************************************************************************
  494. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  495. int QueryAllClassesInTestNamespace()
  496. {
  497. int nRc = FATAL_ERROR;
  498. CAutoDeleteString sNamespace;
  499. IWbemServices * pNamespace = NULL;
  500. // =====================================================================
  501. // Made into a utility function as it is used more than once
  502. // =====================================================================
  503. nRc = OpenNamespaceAndCreateTestClassesAndAssociations( sNamespace,&pNamespace);
  504. if( nRc == SUCCESS )
  505. {
  506. //==================================================================
  507. // Query classes in test namespace
  508. //==================================================================
  509. CAutoDeleteString sQueryList;
  510. if( g_Options.GetOptionsForAPITest(sQueryList, APITEST8))
  511. {
  512. ClassList MasterList;
  513. //=======================================================
  514. // Get the list of the queries
  515. //=======================================================
  516. if( InitMasterListOfClasses(sQueryList.GetPtr(),MasterList))
  517. {
  518. for( int i = 0; i < MasterList.Size(); i++ )
  519. {
  520. ClassInfo * p = MasterList.GetAt(i);
  521. CAutoDeleteString sQuery;
  522. if( g_Options.GetSpecificOptionForAPITest(p->Class,sQuery,APITEST8) )
  523. {
  524. //==================================================================
  525. // Regular query
  526. //==================================================================
  527. nRc = QueryAndCompareResults( pNamespace, sQuery.GetPtr(), sNamespace.GetPtr());
  528. if( nRc != S_OK )
  529. {
  530. break;
  531. }
  532. }
  533. }
  534. }
  535. }
  536. }
  537. // =====================================================================
  538. // Release the pointers
  539. // =====================================================================
  540. SAFE_RELEASE_PTR(pNamespace);
  541. return nRc;
  542. }
  543. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  544. //*****************************************************************************************************************
  545. // Test 9
  546. //*****************************************************************************************************************
  547. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  548. int CreateClassInstances()
  549. {
  550. int nRc = FATAL_ERROR;
  551. CAutoDeleteString sNamespace;
  552. IWbemServices * pNamespace = NULL;
  553. // =====================================================================
  554. // Open the namespace and create all of the test classes, this happens
  555. // a lot, so is is a utility function
  556. // =====================================================================
  557. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  558. if( nRc == SUCCESS )
  559. {
  560. // =============================================================
  561. // Get the list of classes to get instances for
  562. // =============================================================
  563. CAutoDeleteString sInstanceList;
  564. CAutoDeleteString sInstanceCompareList;
  565. if( g_Options.GetOptionsForAPITest( sInstanceList, sInstanceCompareList, APITEST9 ) )
  566. {
  567. // =========================================================
  568. // Create the instances in the namespace
  569. // =========================================================
  570. nRc = CreateInstances(pNamespace, sInstanceList, sNamespace.GetPtr(), APITEST4 );
  571. if( SUCCESS == nRc )
  572. {
  573. // =====================================================
  574. // Make sure those instances are in the namespace
  575. // =====================================================
  576. nRc = EnumerateInstancesAndCompare(pNamespace, sInstanceList, sInstanceCompareList,sNamespace.GetPtr());
  577. }
  578. }
  579. }
  580. // =====================================================================
  581. // Release the pointers
  582. // =====================================================================
  583. SAFE_RELEASE_PTR(pNamespace);
  584. return nRc;
  585. }
  586. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  587. //*****************************************************************************************************************
  588. // Test 10
  589. //*****************************************************************************************************************
  590. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  591. int DeleteClassInstances()
  592. {
  593. int nRc = FATAL_ERROR;
  594. CAutoDeleteString sNamespace;
  595. IWbemServices * pNamespace = NULL;
  596. // =====================================================================
  597. // Open the namespace and create all of the test classes, this happens
  598. // a lot, so is is a utility function
  599. //==========================================================================
  600. // Delete instances
  601. //==========================================================================
  602. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  603. if( nRc == SUCCESS )
  604. {
  605. // =============================================================
  606. // Get the list of instances to delete
  607. // =============================================================
  608. CAutoDeleteString sInstanceList;
  609. if( g_Options.GetOptionsForAPITest( sInstanceList, APITEST13 ) )
  610. {
  611. // =========================================================
  612. // Delete the instances in the namespace
  613. // =========================================================
  614. nRc = DeleteInstances(sInstanceList, pNamespace, sNamespace.GetPtr());
  615. if( SUCCESS == nRc )
  616. {
  617. // =====================================================
  618. // Make sure those instances are not in the namespace
  619. // =====================================================
  620. }
  621. }
  622. }
  623. // =====================================================================
  624. // Release the pointers
  625. // =====================================================================
  626. SAFE_RELEASE_PTR(pNamespace);
  627. return nRc;
  628. }
  629. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  630. //*****************************************************************************************************************
  631. // Test 11
  632. //*****************************************************************************************************************
  633. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  634. int EnumerateClassInstances()
  635. {
  636. //==========================================================================
  637. // Get instance enumerator for requested classes
  638. //==========================================================================
  639. int nRc = FATAL_ERROR;
  640. CAutoDeleteString sNamespace;
  641. IWbemServices * pNamespace = NULL;
  642. // =====================================================================
  643. // Open the namespace and create all of the test classes, this happens
  644. // a lot, so is is a utility function
  645. // =====================================================================
  646. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  647. if( nRc == SUCCESS )
  648. {
  649. // =============================================================
  650. // Get the list of classes to get instances for
  651. // =============================================================
  652. CAutoDeleteString sInstanceList;
  653. CAutoDeleteString sInstanceCompareList;
  654. if( g_Options.GetOptionsForAPITest( sInstanceList, sInstanceCompareList, APITEST11 ) )
  655. {
  656. // =========================================================
  657. // Make sure those instances are in the namespace
  658. // =========================================================
  659. nRc = EnumerateInstancesAndCompare(pNamespace, sInstanceList, sInstanceCompareList, sNamespace.GetPtr());
  660. }
  661. }
  662. // =====================================================================
  663. // Release the pointers
  664. // =====================================================================
  665. SAFE_RELEASE_PTR(pNamespace);
  666. return nRc;
  667. }
  668. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  669. //*****************************************************************************************************************
  670. // Test 12
  671. //*****************************************************************************************************************
  672. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  673. int CreateAssociationInstances()
  674. {
  675. //==========================================================================
  676. // Get instance enumerator for requested classes
  677. //==========================================================================
  678. int nRc = FATAL_ERROR;
  679. CAutoDeleteString sNamespace;
  680. IWbemServices * pNamespace = NULL;
  681. // =====================================================================
  682. // Open the namespace and create all of the test classes, this happens
  683. // a lot, so is is a utility function
  684. // =====================================================================
  685. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  686. if( nRc == SUCCESS )
  687. {
  688. // =============================================================
  689. // Get the list of classes to get instances for
  690. // =============================================================
  691. CAutoDeleteString sInstanceList;
  692. CAutoDeleteString sInstanceCompareList;
  693. if( g_Options.GetOptionsForAPITest( sInstanceList, sInstanceCompareList, APITEST12 ) )
  694. {
  695. // =========================================================
  696. // Create the instances in the namespace
  697. // =========================================================
  698. nRc = CreateInstances(pNamespace, sInstanceList, sNamespace.GetPtr(), APITEST4 );
  699. if( SUCCESS == nRc )
  700. {
  701. // =====================================================
  702. // Make sure those instances are in the namespace
  703. // =====================================================
  704. nRc = EnumerateInstancesAndCompare(pNamespace, sInstanceList, sInstanceCompareList,sNamespace.GetPtr());
  705. }
  706. }
  707. }
  708. // =====================================================================
  709. // Release the pointers
  710. // =====================================================================
  711. SAFE_RELEASE_PTR(pNamespace);
  712. return nRc;
  713. }
  714. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  715. //*****************************************************************************************************************
  716. // Test 13
  717. //*****************************************************************************************************************
  718. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  719. int DeleteAssociationInstances()
  720. {
  721. //==========================================================================
  722. // Delete instances
  723. //==========================================================================
  724. int nRc = FATAL_ERROR;
  725. CAutoDeleteString sNamespace;
  726. IWbemServices * pNamespace = NULL;
  727. // =====================================================================
  728. // Open the namespace and create all of the test classes, this happens
  729. // a lot, so is is a utility function
  730. // =====================================================================
  731. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  732. if( nRc == SUCCESS )
  733. {
  734. // =============================================================
  735. // Get the list of instances to delete
  736. // =============================================================
  737. CAutoDeleteString sInstanceList;
  738. if( g_Options.GetOptionsForAPITest( sInstanceList, APITEST13 ) )
  739. {
  740. // =========================================================
  741. // Delete the instances in the namespace
  742. // =========================================================
  743. nRc = DeleteInstances(sInstanceList, pNamespace, sNamespace.GetPtr());
  744. if( SUCCESS == nRc )
  745. {
  746. // =====================================================
  747. // Make sure those instances are not in the namespace
  748. // =====================================================
  749. }
  750. }
  751. }
  752. // =====================================================================
  753. // Release the pointers
  754. // =====================================================================
  755. SAFE_RELEASE_PTR(pNamespace);
  756. return nRc;
  757. }
  758. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  759. //*****************************************************************************************************************
  760. // Test 14
  761. //*****************************************************************************************************************
  762. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  763. int EnumerateAssociationInstances()
  764. {
  765. //==========================================================================
  766. // Get instance enumerator for requested classes
  767. //==========================================================================
  768. int nRc = FATAL_ERROR;
  769. CAutoDeleteString sNamespace;
  770. IWbemServices * pNamespace = NULL;
  771. // =====================================================================
  772. // Open the namespace and create all of the test classes, this happens
  773. // a lot, so is is a utility function
  774. // =====================================================================
  775. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  776. if( nRc == SUCCESS )
  777. {
  778. // =============================================================
  779. // Get the list of classes to get instances for
  780. // =============================================================
  781. CAutoDeleteString sInstanceList;
  782. CAutoDeleteString sInstanceCompareList;
  783. if( g_Options.GetOptionsForAPITest( sInstanceList, sInstanceCompareList, APITEST14 ) )
  784. {
  785. // =========================================================
  786. // Make sure those instances are in the namespace
  787. // =========================================================
  788. nRc = EnumerateInstancesAndCompare(pNamespace, sInstanceList, sInstanceCompareList, sNamespace.GetPtr());
  789. }
  790. }
  791. // =====================================================================
  792. // Release the pointers
  793. // =====================================================================
  794. SAFE_RELEASE_PTR(pNamespace);
  795. return nRc;
  796. }
  797. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  798. //*****************************************************************************************************************
  799. // Test 15
  800. //*****************************************************************************************************************
  801. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  802. int DeleteClassDeletesInstances()
  803. {
  804. int nRc = FATAL_ERROR;
  805. CAutoDeleteString sNamespace;
  806. IWbemServices * pNamespace = NULL;
  807. // =====================================================================
  808. // Open the namespace and create all of the test classes, this happens
  809. // a lot, so is is a utility function
  810. // =====================================================================
  811. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  812. if( nRc == SUCCESS )
  813. {
  814. }
  815. // =====================================================================
  816. // Release the pointers
  817. // =====================================================================
  818. SAFE_RELEASE_PTR(pNamespace);
  819. return nRc;
  820. }
  821. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  822. //*****************************************************************************************************************
  823. // Test 16
  824. //*****************************************************************************************************************
  825. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  826. int GetObjects()
  827. {
  828. //==========================================================================
  829. // Get the various types of objects (classes/instances) using the various
  830. // types of paths accepted by WMI ( WMI path/ UMI path/ HTTP path)
  831. //==========================================================================
  832. int nRc = FATAL_ERROR;
  833. CAutoDeleteString sNamespace;
  834. IWbemServices * pNamespace = NULL;
  835. // =====================================================================
  836. // Open the namespace and create all of the test classes, this happens
  837. // a lot, so is is a utility function
  838. // =====================================================================
  839. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  840. if( nRc == SUCCESS )
  841. {
  842. // =============================================================
  843. // Get the list of objexts to get
  844. // =============================================================
  845. CAutoDeleteString sObjects;
  846. if( g_Options.GetOptionsForAPITest( sObjects, APITEST16 ) )
  847. {
  848. // =========================================================
  849. // Get the requested objects
  850. // =========================================================
  851. nRc = GetSpecificObjects(sObjects, pNamespace, sNamespace.GetPtr());
  852. }
  853. }
  854. // =====================================================================
  855. // Release the pointers
  856. // =====================================================================
  857. SAFE_RELEASE_PTR(pNamespace);
  858. return nRc;
  859. }
  860. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  861. //*****************************************************************************************************************
  862. // Test 17
  863. //*****************************************************************************************************************
  864. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  865. int GetClassMethods()
  866. {
  867. // =====================================================================
  868. // Getting a list of Methods for a class
  869. // =====================================================================
  870. int nRc = FATAL_ERROR;
  871. CAutoDeleteString sNamespace;
  872. IWbemServices * pNamespace = NULL;
  873. // =====================================================================
  874. // Open the namespace and create all of the test classes, this happens
  875. // a lot, so is is a utility function
  876. // =====================================================================
  877. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  878. if( nRc == SUCCESS )
  879. {
  880. }
  881. SAFE_RELEASE_PTR(pNamespace);
  882. return nRc;
  883. }
  884. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  885. //*****************************************************************************************************************
  886. // Test 18
  887. //*****************************************************************************************************************
  888. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  889. int GetInstanceMethods()
  890. {
  891. // =====================================================================
  892. // Getting a list of Methods for an instance
  893. // =====================================================================
  894. int nRc = FATAL_ERROR;
  895. CAutoDeleteString sNamespace;
  896. IWbemServices * pNamespace = NULL;
  897. // =====================================================================
  898. // Open the namespace and create all of the test classes, this happens
  899. // a lot, so is is a utility function
  900. // =====================================================================
  901. nRc = OpenNamespaceAndCreateTestClasses( sNamespace, &pNamespace );
  902. if( nRc == SUCCESS )
  903. {
  904. }
  905. SAFE_RELEASE_PTR(pNamespace);
  906. return nRc;
  907. }