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.

1172 lines
54 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. // Test 1
  15. //*****************************************************************************************************************
  16. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. int BasicConnectUsingIWbemLocator(BOOL fCompareResults, BOOL fSuppressHeader )
  18. {
  19. int nRc = FATAL_ERROR;
  20. IWbemServices * pNamespace = NULL;
  21. CHString sNamespace;
  22. LogTestBeginning(1,fSuppressHeader);
  23. if( g_Options.GetSpecificOptionForAPITest(L"NAMESPACE",sNamespace, 1) )
  24. {
  25. // =====================================================================
  26. // Open the namespace
  27. // =====================================================================
  28. nRc = OpenNamespaceAndKeepOpen( &pNamespace, WPTR sNamespace,FALSE,fCompareResults);
  29. // =====================================================================
  30. // Release the pointers
  31. // =====================================================================
  32. SAFE_RELEASE_PTR(pNamespace);
  33. }
  34. LogTestEnding(1,nRc,fSuppressHeader);
  35. return nRc;
  36. }
  37. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38. //*****************************************************************************************************************
  39. // Test 2
  40. //*****************************************************************************************************************
  41. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42. int BasicSyncConnectUsingIWbemConnection(BOOL fCompareResults, BOOL fSuppressHeader )
  43. {
  44. int nRc = FATAL_ERROR;
  45. IWbemConnection * pConnection = NULL;
  46. CHString sNamespace;
  47. CHString sClass;
  48. LogTestBeginning(2,fSuppressHeader);
  49. if( g_Options.GetSpecificOptionForAPITest(L"NAMESPACE",sNamespace,2) )
  50. {
  51. if( g_Options.GetSpecificOptionForAPITest(L"CLASS",sClass,2) )
  52. {
  53. nRc = CoCreateInstanceAndLogErrors(CLSID_WbemConnection,IID_IWbemConnection,(void**)&pConnection,NO_ERRORS_EXPECTED);
  54. if( SUCCESS == nRc )
  55. {
  56. // =================================================================
  57. // Test Open with all three types:
  58. //
  59. // IWbemServices
  60. // IWbemServicesEx
  61. // IWbemClassObject
  62. //
  63. // Initialize all vars
  64. // =================================================================
  65. short FatalErrors = 0;
  66. // =================================================================
  67. // Open the namespace with IWbemServices
  68. // =================================================================
  69. IWbemServices * pNamespace = NULL;
  70. nRc = OpenObjectAndLogErrors(pConnection, IID_IWbemServices, (void**) &pNamespace, WPTR sNamespace,NO_ERRORS_EXPECTED);
  71. if ( nRc != SUCCESS )
  72. {
  73. FatalErrors++;
  74. }
  75. SAFE_RELEASE_PTR(pNamespace);
  76. // =================================================================
  77. // Open the namespace with IWbemServicesEx
  78. // =================================================================
  79. IWbemServicesEx * pNamespaceEx = NULL;
  80. nRc = OpenObjectAndLogErrors(pConnection, IID_IWbemServicesEx, (void**) &pNamespaceEx,WPTR sNamespace,NO_ERRORS_EXPECTED);
  81. if ( nRc != SUCCESS )
  82. {
  83. FatalErrors++;
  84. }
  85. SAFE_RELEASE_PTR(pNamespaceEx);
  86. // =================================================================
  87. // Open the Class for IWbemClassObject
  88. // =================================================================
  89. IWbemClassObject* pWbemClassObject = NULL;
  90. nRc = OpenObjectAndLogErrors(pConnection, IID_IWbemClassObject, (void**) &pWbemClassObject, WPTR sClass,NO_ERRORS_EXPECTED);
  91. if ( nRc != SUCCESS )
  92. {
  93. FatalErrors++;
  94. }
  95. SAFE_RELEASE_PTR(pWbemClassObject);
  96. // =================================================================
  97. // Check to see if there were any fatal errors
  98. // =================================================================
  99. if( !FatalErrors )
  100. {
  101. nRc = SUCCESS;
  102. }
  103. }
  104. // =====================================================================
  105. // Release the locator
  106. // =====================================================================
  107. SAFE_RELEASE_PTR(pConnection);
  108. }
  109. }
  110. LogTestEnding(2,nRc,fSuppressHeader);
  111. return nRc;
  112. }
  113. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  114. //*****************************************************************************************************************
  115. // Test 3
  116. //*****************************************************************************************************************
  117. int BasicAsyncConnectUsingIWbemConnection(BOOL fCompareResults, BOOL fSuppressHeader )
  118. {
  119. int nRc = FATAL_ERROR;
  120. HRESULT hr = S_OK;
  121. IWbemConnection * pConnection = NULL;
  122. CHString sNamespace;
  123. CHString sClass;
  124. LogTestBeginning(3,fSuppressHeader);
  125. if( g_Options.GetSpecificOptionForAPITest(L"NAMESPACE",sNamespace,2) )
  126. {
  127. if( g_Options.GetSpecificOptionForAPITest(L"CLASS",sClass,2))
  128. {
  129. nRc = CoCreateInstanceAndLogErrors(CLSID_WbemConnection,IID_IWbemConnection,(void**)&pConnection,NO_ERRORS_EXPECTED);
  130. if( SUCCESS == nRc )
  131. {
  132. // =================================================================
  133. // Test Open with all three types:
  134. //
  135. // IWbemServices
  136. // IWbemServicesEx
  137. // IWbemClassObject
  138. //
  139. // Initialize all the vars
  140. // =================================================================
  141. short FatalErrors = 0;
  142. CSinkEx * pHandler = NULL;
  143. pHandler = new CSinkEx;
  144. if( pHandler )
  145. {
  146. // =================================================================
  147. // Open the namespace with IWbemServices
  148. // =================================================================
  149. nRc = OpenObjectAsyncAndLogErrors(pConnection, IID_IWbemServices,WPTR sNamespace,pHandler,NO_ERRORS_EXPECTED);
  150. if ( nRc == FATAL_ERROR )
  151. {
  152. FatalErrors++;
  153. }
  154. else
  155. {
  156. IWbemServices * pNamespace = NULL;
  157. pHandler->WaitForSignal(INFINITE);
  158. hr = pHandler->GetStatusCode();
  159. if(SUCCEEDED(hr))
  160. {
  161. pNamespace = (IWbemServices*)pHandler->GetInterface();
  162. }
  163. SAFE_RELEASE_PTR(pNamespace);
  164. }
  165. }
  166. else
  167. {
  168. gp_LogFile->LogError(__FILE__,__LINE__,FATAL_ERROR, L"Allocation of new CSinkEx Failed - Out of memory.");
  169. }
  170. SAFE_DELETE_PTR(pHandler);
  171. // =================================================================
  172. // Open the namespace with IWbemServicesEx
  173. // =================================================================
  174. pHandler = new CSinkEx;
  175. if( pHandler )
  176. {
  177. nRc = OpenObjectAsyncAndLogErrors(pConnection, IID_IWbemServicesEx,WPTR sNamespace, pHandler,NO_ERRORS_EXPECTED);
  178. if ( nRc == FATAL_ERROR )
  179. {
  180. FatalErrors++;
  181. }
  182. else
  183. {
  184. IWbemServicesEx * pNamespace = NULL;
  185. pHandler->WaitForSignal(INFINITE);
  186. hr = pHandler->GetStatusCode();
  187. if(SUCCEEDED(hr))
  188. {
  189. pNamespace = (IWbemServicesEx*)pHandler->GetInterface();
  190. }
  191. SAFE_RELEASE_PTR(pNamespace);
  192. }
  193. }
  194. else
  195. {
  196. gp_LogFile->LogError(__FILE__,__LINE__,FATAL_ERROR, L"Allocation of new CSinkEx Failed - Out of memory.");
  197. }
  198. SAFE_DELETE_PTR(pHandler);
  199. // =================================================================
  200. // Open the class for IWbemClassObject
  201. // =================================================================
  202. pHandler = new CSinkEx;
  203. if( pHandler )
  204. {
  205. nRc = OpenObjectAsyncAndLogErrors(pConnection, IID_IWbemClassObject, WPTR sClass, pHandler,NO_ERRORS_EXPECTED);
  206. if ( nRc == FATAL_ERROR )
  207. {
  208. FatalErrors++;
  209. }
  210. else
  211. {
  212. IWbemClassObject * pWbemClassObject = NULL;
  213. pHandler->WaitForSignal(INFINITE);
  214. hr = pHandler->GetStatusCode();
  215. if(SUCCEEDED(hr))
  216. {
  217. pWbemClassObject = (IWbemClassObject*)pHandler->GetInterface();
  218. }
  219. SAFE_RELEASE_PTR(pWbemClassObject);
  220. }
  221. }
  222. else
  223. {
  224. gp_LogFile->LogError(__FILE__,__LINE__,FATAL_ERROR, L"Allocation of new CSinkEx Failed - Out of memory.");
  225. }
  226. SAFE_DELETE_PTR(pHandler);
  227. // =================================================================
  228. // Check to see if there are any fatal errors
  229. // =================================================================
  230. if( !FatalErrors )
  231. {
  232. nRc = SUCCESS;
  233. }
  234. }
  235. // =====================================================================
  236. // Release the locator
  237. // =====================================================================
  238. SAFE_RELEASE_PTR(pConnection);
  239. }
  240. }
  241. LogTestEnding(3,nRc,fSuppressHeader);
  242. return nRc;
  243. }
  244. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  245. //*****************************************************************************************************************
  246. // Test 4
  247. //*****************************************************************************************************************
  248. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  249. int CreateNewTestNamespace(BOOL fCompareResults, BOOL fSuppressHeader )
  250. {
  251. int nRc = SUCCESS;
  252. CHString sNamespace;
  253. CHString sParentNamespace;
  254. CHString sInstance;
  255. LogTestBeginning(4,fSuppressHeader);
  256. if( g_Options.GetSpecificOptionForAPITest(L"PARENT_NAMESPACE",sParentNamespace, 4))
  257. {
  258. if( g_Options.GetSpecificOptionForAPITest(L"NAMESPACE",sNamespace, 4))
  259. {
  260. if( g_Options.GetSpecificOptionForAPITest(L"CLASSES",sInstance, 4 ))
  261. {
  262. IWbemLocator * pLocator = NULL;
  263. nRc = CoCreateInstanceAndLogErrors(CLSID_WbemLocator,IID_IWbemLocator,(void**)&pLocator,NO_ERRORS_EXPECTED);
  264. if( SUCCESS == nRc )
  265. {
  266. //==========================================================================
  267. // Parse the namespace name to get the parent first, and open the parent
  268. // this one must be existing
  269. //==========================================================================
  270. IWbemServices * pParentNamespace = NULL;
  271. IWbemServices * pChildNamespace = NULL;
  272. nRc = ConnectServerAndLogErrors(pLocator,&pParentNamespace, WPTR sParentNamespace,NO_ERRORS_EXPECTED);
  273. if( nRc == SUCCESS )
  274. {
  275. //==============================================================
  276. // If we got here, then we know that the child namespace does
  277. // not exist, so create it.
  278. //==============================================================
  279. nRc = CreateInstances(pParentNamespace,sInstance, WPTR sParentNamespace, 4 );
  280. if( SUCCESS == nRc )
  281. {
  282. //==========================================================
  283. // Open the namespace with IWbemServices as the new parent
  284. //==========================================================
  285. nRc = ConnectServerAndLogErrors(pLocator, &pChildNamespace,WPTR sNamespace,NO_ERRORS_EXPECTED);
  286. }
  287. }
  288. SAFE_RELEASE_PTR(pParentNamespace);
  289. SAFE_RELEASE_PTR(pChildNamespace);
  290. }
  291. // =============================================================================
  292. // Release the locator
  293. // =============================================================================
  294. SAFE_RELEASE_PTR(pLocator);
  295. }
  296. }
  297. }
  298. LogTestEnding(4,nRc,fSuppressHeader);
  299. return nRc;
  300. }
  301. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  302. //*****************************************************************************************************************
  303. // Test 5
  304. //*****************************************************************************************************************
  305. int CreateNewClassesInTestNamespace(BOOL fCompareResults, BOOL fSuppressHeader )
  306. {
  307. int nRc = FATAL_ERROR;
  308. CHString sNamespace;
  309. IWbemServices * pNamespace = NULL;
  310. LogTestBeginning(5,fSuppressHeader);
  311. // =====================================================================
  312. // Run the requested tests and get then namespace open
  313. // =====================================================================
  314. nRc = RunRequestedTestsAndOpenNamespace(5, sNamespace, &pNamespace, fCompareResults);
  315. if( SUCCESS == nRc )
  316. {
  317. //=========================================================
  318. // Create classes with different properties. Some of
  319. // these should be in the following inheritance chain and
  320. // some should not inherit from the others at all:
  321. // classes = {A, B, C, D:A, E:A, F:E, G:F, H:G, I:F}.
  322. // A mix of simple string & sint32 keys are fine.
  323. //=========================================================
  324. nRc = CreateClassesForSpecificTest(pNamespace, WPTR sNamespace,L"CLASSES",5);
  325. }
  326. // =====================================================================
  327. // Release the pointers
  328. // =====================================================================
  329. SAFE_RELEASE_PTR(pNamespace);
  330. LogTestEnding(5,nRc,fSuppressHeader);
  331. return nRc;
  332. }
  333. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  334. //*****************************************************************************************************************
  335. // Test 6
  336. //*****************************************************************************************************************
  337. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  338. int DeleteAndRecreateNewClassesInTestNamespace(BOOL fCompareResults, BOOL fSuppressHeader )
  339. {
  340. int nRc = FATAL_ERROR;
  341. CHString sNamespace;
  342. IWbemServices * pNamespace = NULL;
  343. LogTestBeginning(6,fSuppressHeader);
  344. // =====================================================================
  345. // Run the requested tests and get then namespace open
  346. // =====================================================================
  347. nRc = RunRequestedTestsAndOpenNamespace(6, sNamespace, &pNamespace, fCompareResults);
  348. if( SUCCESS == nRc )
  349. {
  350. //=========================================
  351. // Get all of the class operations for
  352. // this test:
  353. // Classes to be deleted
  354. // Classes to be compared
  355. // Classes to be added
  356. // Classes to be compared
  357. // Classes to be added_deleted
  358. // Classes to be compared
  359. //=============================================
  360. CHString sDeleteClasses;
  361. CHString sClassesAfterDelete;
  362. CHString sAddClasses;
  363. CHString sClassesAfterAdd;
  364. CHString sDeleteAddClassOrder;
  365. CHString sClassesAfterDeleteAdd;
  366. if( g_Options.GetSpecificOptionForAPITest( L"DELETE_CLASSES", sDeleteClasses, 6))
  367. {
  368. if( g_Options.GetSpecificOptionForAPITest( L"CLASSES_AFTER_DELETE", sClassesAfterDelete, 6))
  369. {
  370. if( g_Options.GetSpecificOptionForAPITest( L"ADD_CLASSES", sAddClasses, 6))
  371. {
  372. if( g_Options.GetSpecificOptionForAPITest( L"CLASSES_AFTER_ADD", sClassesAfterAdd, 6))
  373. {
  374. if( g_Options.GetSpecificOptionForAPITest( L"DELETE_ADD_CLASS_ORDER", sDeleteAddClassOrder, 6))
  375. {
  376. if( g_Options.GetSpecificOptionForAPITest( L"CLASSES_AFTER_DELETE_ADD", sClassesAfterDeleteAdd, 6))
  377. {
  378. nRc = DeleteClasses(sDeleteClasses, 6, fCompareResults,pNamespace,WPTR sNamespace);
  379. if( nRc == SUCCESS )
  380. {
  381. nRc = EnumerateClassesAndCompare(sClassesAfterDelete, 6,fCompareResults, pNamespace,WPTR sNamespace);
  382. if( nRc == SUCCESS )
  383. {
  384. nRc = AddClasses(sAddClasses, pNamespace, WPTR sNamespace, 6 );
  385. if( nRc == SUCCESS )
  386. {
  387. nRc = EnumerateClassesAndCompare(sClassesAfterAdd,6,fCompareResults, pNamespace, WPTR sNamespace);
  388. if( nRc == SUCCESS )
  389. {
  390. nRc = DeleteAndAddClasses(sDeleteAddClassOrder, pNamespace, WPTR sNamespace, 6);
  391. if( nRc == SUCCESS )
  392. {
  393. nRc = EnumerateClassesAndCompare(sClassesAfterDeleteAdd,6, fCompareResults,pNamespace, WPTR sNamespace);
  394. }
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. }
  402. }
  403. }
  404. }
  405. }
  406. // =====================================================================
  407. // Release the pointers
  408. // =====================================================================
  409. SAFE_RELEASE_PTR(pNamespace);
  410. LogTestEnding(6,nRc,fSuppressHeader);
  411. return nRc;
  412. }
  413. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  414. //*****************************************************************************************************************
  415. // Test 7
  416. //*****************************************************************************************************************
  417. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  418. int CreateSimpleAssociations(BOOL fCompareResults, BOOL fSuppressHeader )
  419. {
  420. int nRc = FATAL_ERROR;
  421. CHString sNamespace;
  422. IWbemServices * pNamespace = NULL;
  423. LogTestBeginning(7,fSuppressHeader);
  424. // =====================================================================
  425. // Run the requested tests and get then namespace open
  426. // =====================================================================
  427. nRc = RunRequestedTestsAndOpenNamespace(7, sNamespace, &pNamespace, fCompareResults);
  428. if( SUCCESS == nRc )
  429. {
  430. //=================================================
  431. // Get the list of associations to create
  432. //=================================================
  433. CHString sItemList;
  434. if( g_Options.GetSpecificOptionForAPITest(L"CLASSES",sItemList, 7))
  435. {
  436. ItemList MasterList;
  437. //=======================================================
  438. // Parse the list of the associations to be created
  439. //=======================================================
  440. if( InitMasterList(sItemList,MasterList))
  441. {
  442. for( int i = 0; i < MasterList.Size(); i++ )
  443. {
  444. ItemInfo * p = MasterList.GetAt(i);
  445. CHString sItemInformation;
  446. // =============================================================
  447. // Get definition of the association
  448. // =============================================================
  449. int nWhichTest = 0;
  450. CHString sClassDef;
  451. nRc = GetClassDefinitionSection(7, sClassDef, nWhichTest );
  452. if( SUCCESS == nRc )
  453. {
  454. if( g_Options.GetSpecificOptionForAPITest(p->Item,sItemInformation,nWhichTest) )
  455. {
  456. //===========================================================
  457. // Create the association
  458. //===========================================================
  459. nRc = CreateAssociationAndLogErrors(pNamespace,p->Item,WPTR sItemInformation,WPTR sNamespace);
  460. if( nRc != SUCCESS )
  461. {
  462. break;
  463. }
  464. }
  465. }
  466. }
  467. }
  468. }
  469. }
  470. // =====================================================================
  471. // Release the pointers
  472. // =====================================================================
  473. SAFE_RELEASE_PTR(pNamespace);
  474. LogTestEnding(7,nRc,fSuppressHeader);
  475. return nRc;
  476. }
  477. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  478. //*****************************************************************************************************************
  479. // Test 8
  480. //*****************************************************************************************************************
  481. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  482. int QueryAllClassesInTestNamespace(BOOL fCompareResults, BOOL fSuppressHeader )
  483. {
  484. int nRc = FATAL_ERROR;
  485. CHString sNamespace;
  486. IWbemServices * pNamespace = NULL;
  487. LogTestBeginning(8,fSuppressHeader);
  488. // =====================================================================
  489. // Run the requested tests and get then namespace open
  490. // =====================================================================
  491. nRc = RunRequestedTestsAndOpenNamespace(8, sNamespace, &pNamespace, fCompareResults);
  492. if( SUCCESS == nRc )
  493. {
  494. //==================================================================
  495. // Query classes in test namespace
  496. //==================================================================
  497. CHString sQueryList;
  498. if( g_Options.GetSpecificOptionForAPITest(L"QUERY_LIST",sQueryList, 8))
  499. {
  500. ItemList MasterList;
  501. //=======================================================
  502. // Get the list of the queries
  503. //=======================================================
  504. if( InitMasterList(sQueryList,MasterList))
  505. {
  506. for( int i = 0; i < MasterList.Size(); i++ )
  507. {
  508. ItemInfo * p = MasterList.GetAt(i);
  509. CHString sQuery;
  510. if( g_Options.GetSpecificOptionForAPITest(p->Item,sQuery,8) )
  511. {
  512. EventInfo Query;
  513. nRc = CrackEvent(WPTR sQuery, Query,NO_ERRORS_EXPECTED);
  514. if( SUCCESS == nRc )
  515. {
  516. //==================================================================
  517. // Regular query
  518. //==================================================================
  519. nRc = QueryAndCompareResults( pNamespace,WPTR Query.Query,Query.Results,WPTR sNamespace);
  520. if( nRc != S_OK )
  521. {
  522. break;
  523. }
  524. }
  525. }
  526. }
  527. }
  528. }
  529. }
  530. // =====================================================================
  531. // Release the pointers
  532. // =====================================================================
  533. SAFE_RELEASE_PTR(pNamespace);
  534. LogTestEnding(8,nRc,fSuppressHeader);
  535. return nRc;
  536. }
  537. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  538. //*****************************************************************************************************************
  539. // Test 9
  540. //*****************************************************************************************************************
  541. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  542. int CreateClassInstances(BOOL fCompareResults, BOOL fSuppressHeader )
  543. {
  544. int nRc = FATAL_ERROR;
  545. CHString sNamespace;
  546. IWbemServices * pNamespace = NULL;
  547. LogTestBeginning(9,fSuppressHeader);
  548. // =====================================================================
  549. // Run the requested tests and get then namespace open
  550. // =====================================================================
  551. nRc = RunRequestedTestsAndOpenNamespace(9, sNamespace, &pNamespace, fCompareResults);
  552. if( SUCCESS == nRc )
  553. {
  554. nRc = CreateInstancesForSpecificTest(pNamespace, WPTR sNamespace,L"INSTANCE_LIST",9,TRUE);
  555. }
  556. // =====================================================================
  557. // Release the pointers
  558. // =====================================================================
  559. SAFE_RELEASE_PTR(pNamespace);
  560. LogTestEnding(9,nRc,fSuppressHeader);
  561. return nRc;
  562. }
  563. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  564. //*****************************************************************************************************************
  565. // Test 10
  566. //*****************************************************************************************************************
  567. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  568. int DeleteClassInstances(BOOL fCompareResults, BOOL fSuppressHeader )
  569. {
  570. int nRc = FATAL_ERROR;
  571. CHString sNamespace;
  572. IWbemServices * pNamespace = NULL;
  573. LogTestBeginning(10,fSuppressHeader);
  574. // =====================================================================
  575. // Run the requested tests and get then namespace open
  576. // =====================================================================
  577. nRc = RunRequestedTestsAndOpenNamespace(10, sNamespace, &pNamespace, fCompareResults);
  578. if( SUCCESS == nRc )
  579. {
  580. // =============================================================
  581. // Get the list of instances to delete
  582. // =============================================================
  583. CHString sInstanceList;
  584. if( g_Options.GetSpecificOptionForAPITest( L"INSTANCE_LIST",sInstanceList, 10 ) )
  585. {
  586. // =========================================================
  587. // Delete the instances in the namespace
  588. // =========================================================
  589. nRc = DeleteInstancesAndCompareResults(sInstanceList, 10, pNamespace, WPTR sNamespace);
  590. }
  591. }
  592. // =====================================================================
  593. // Release the pointers
  594. // =====================================================================
  595. SAFE_RELEASE_PTR(pNamespace);
  596. LogTestEnding(10,nRc,fSuppressHeader);
  597. return nRc;
  598. }
  599. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  600. //*****************************************************************************************************************
  601. // Test 11
  602. //*****************************************************************************************************************
  603. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  604. int EnumerateClassInstances(BOOL fCompareResults, BOOL fSuppressHeader )
  605. {
  606. int nRc = FATAL_ERROR;
  607. CHString sNamespace;
  608. IWbemServices * pNamespace = NULL;
  609. LogTestBeginning(11,fSuppressHeader);
  610. // =====================================================================
  611. // Run the requested tests and get then namespace open
  612. // =====================================================================
  613. nRc = RunRequestedTestsAndOpenNamespace(11, sNamespace, &pNamespace, fCompareResults);
  614. if( SUCCESS == nRc )
  615. {
  616. // =============================================================
  617. // Get the list of classes to get instances for
  618. // =============================================================
  619. CHString sInstanceList;
  620. if( g_Options.GetSpecificOptionForAPITest( L"INSTANCE_LIST", sInstanceList, 11 ) )
  621. {
  622. // =========================================================
  623. // Get the enumeration flags
  624. // =========================================================
  625. ItemList FlagList;
  626. nRc = GetFlags(11, FlagList);
  627. if( SUCCESS == nRc )
  628. {
  629. for( int i = 0; i < FlagList.Size(); i++ )
  630. {
  631. ItemInfo * p = FlagList.GetAt(i);
  632. // =================================================
  633. // Make sure those instances are in the namespace
  634. // =================================================
  635. nRc = EnumerateInstancesAndCompare( sInstanceList, 11, fCompareResults, pNamespace,WPTR sNamespace);
  636. }
  637. }
  638. }
  639. }
  640. // =====================================================================
  641. // Release the pointers
  642. // =====================================================================
  643. SAFE_RELEASE_PTR(pNamespace);
  644. LogTestEnding(11,nRc,fSuppressHeader);
  645. return nRc;
  646. }
  647. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  648. //*****************************************************************************************************************
  649. // Test 12
  650. //*****************************************************************************************************************
  651. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  652. int CreateAssociationInstances(BOOL fCompareResults, BOOL fSuppressHeader )
  653. {
  654. int nRc = FATAL_ERROR;
  655. CHString sNamespace;
  656. IWbemServices * pNamespace = NULL;
  657. LogTestBeginning(12,fSuppressHeader);
  658. // =====================================================================
  659. // Run the requested tests and get then namespace open
  660. // =====================================================================
  661. nRc = RunRequestedTestsAndOpenNamespace(12, sNamespace, &pNamespace, fCompareResults);
  662. if( SUCCESS == nRc )
  663. {
  664. nRc = CreateInstancesForSpecificTest(pNamespace, WPTR sNamespace,L"INSTANCE_LIST",12,TRUE);
  665. }
  666. // =====================================================================
  667. // Release the pointers
  668. // =====================================================================
  669. SAFE_RELEASE_PTR(pNamespace);
  670. LogTestEnding(12,nRc,fSuppressHeader);
  671. return nRc;
  672. }
  673. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  674. //*****************************************************************************************************************
  675. // Test 13
  676. //*****************************************************************************************************************
  677. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  678. int DeleteAssociationInstances(BOOL fCompareResults, BOOL fSuppressHeader )
  679. {
  680. int nRc = FATAL_ERROR;
  681. CHString sNamespace;
  682. IWbemServices * pNamespace = NULL;
  683. LogTestBeginning(13,fSuppressHeader);
  684. // =====================================================================
  685. // Run the requested tests and get then namespace open
  686. // =====================================================================
  687. nRc = RunRequestedTestsAndOpenNamespace(13, sNamespace, &pNamespace, fCompareResults);
  688. if( SUCCESS == nRc )
  689. {
  690. // =============================================================
  691. // Get the list of instances to delete
  692. // =============================================================
  693. CHString sInstanceList;
  694. if( g_Options.GetSpecificOptionForAPITest(L"INSTANCE_LIST", sInstanceList, 13 ) )
  695. {
  696. // =========================================================
  697. // Delete the instances in the namespace
  698. // =========================================================
  699. nRc = DeleteInstancesAndCompareResults(sInstanceList,13, pNamespace, WPTR sNamespace);
  700. }
  701. }
  702. // =====================================================================
  703. // Release the pointers
  704. // =====================================================================
  705. SAFE_RELEASE_PTR(pNamespace);
  706. LogTestEnding(13,nRc,fSuppressHeader);
  707. return nRc;
  708. }
  709. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  710. //*****************************************************************************************************************
  711. // Test 14
  712. //*****************************************************************************************************************
  713. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  714. int EnumerateAssociationInstances(BOOL fCompareResults, BOOL fSuppressHeader )
  715. {
  716. int nRc = FATAL_ERROR;
  717. CHString sNamespace;
  718. IWbemServices * pNamespace = NULL;
  719. LogTestBeginning(14,fSuppressHeader);
  720. // =====================================================================
  721. // Run the requested tests and get then namespace open
  722. // =====================================================================
  723. nRc = RunRequestedTestsAndOpenNamespace(14, sNamespace, &pNamespace, fCompareResults);
  724. if( SUCCESS == nRc )
  725. {
  726. // =============================================================
  727. // Get the list of classes to get instances for
  728. // =============================================================
  729. CHString sInstanceList;
  730. if( g_Options.GetSpecificOptionForAPITest( L"INSTANCE_LIST", sInstanceList, 14 ) )
  731. {
  732. // =========================================================
  733. // Get the enumeration flags
  734. // =========================================================
  735. ItemList FlagList;
  736. nRc = GetFlags(14, FlagList);
  737. if( SUCCESS == nRc )
  738. {
  739. for( int i = 0; i < FlagList.Size(); i++ )
  740. {
  741. ItemInfo * p = FlagList.GetAt(i);
  742. // =========================================================
  743. // Make sure those instances are in the namespace
  744. // =========================================================
  745. nRc = EnumerateInstancesAndCompare( sInstanceList, 14, fCompareResults, pNamespace,WPTR sNamespace);
  746. }
  747. }
  748. }
  749. }
  750. // =====================================================================
  751. // Release the pointers
  752. // =====================================================================
  753. SAFE_RELEASE_PTR(pNamespace);
  754. LogTestEnding(14,nRc,fSuppressHeader);
  755. return nRc;
  756. }
  757. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  758. //*****************************************************************************************************************
  759. // Test 15
  760. //*****************************************************************************************************************
  761. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  762. int DeleteClassDeletesInstances(BOOL fCompareResults, BOOL fSuppressHeader )
  763. {
  764. int nRc = FATAL_ERROR;
  765. CHString sNamespace;
  766. IWbemServices * pNamespace = NULL;
  767. LogTestBeginning(15,fSuppressHeader);
  768. // =====================================================================
  769. // Run the requested tests and get then namespace open
  770. // =====================================================================
  771. nRc = RunRequestedTestsAndOpenNamespace(15, sNamespace, &pNamespace, fCompareResults);
  772. if( SUCCESS == nRc )
  773. {
  774. // =============================================================
  775. // Get the list of classes to delete
  776. // =============================================================
  777. CHString sClassList;
  778. if( g_Options.GetSpecificOptionForAPITest( L"CLASSES", sClassList, 15 ) )
  779. {
  780. // =========================================================
  781. // Get the enumeration flags
  782. // =========================================================
  783. ItemList FlagList;
  784. nRc = GetFlags(15, FlagList);
  785. if( SUCCESS == nRc )
  786. {
  787. for( int i = 0; i < FlagList.Size(); i++ )
  788. {
  789. ItemInfo * p = FlagList.GetAt(i);
  790. // ==================================================
  791. // Make sure those instances are in the namespace
  792. // ==================================================
  793. nRc = DeleteClasses(sClassList,15,fCompareResults,pNamespace,WPTR sNamespace);
  794. }
  795. }
  796. }
  797. }
  798. // =====================================================================
  799. // Release the pointers
  800. // =====================================================================
  801. SAFE_RELEASE_PTR(pNamespace);
  802. LogTestEnding(15,nRc,fSuppressHeader);
  803. return nRc;
  804. }
  805. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  806. //*****************************************************************************************************************
  807. // Test 16
  808. //*****************************************************************************************************************
  809. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  810. int GetObjects(BOOL fCompareResults, BOOL fSuppressHeader )
  811. {
  812. //==========================================================================
  813. // Get the various types of objects (classes/instances) using the various
  814. // types of paths accepted by WMI ( WMI path/ UMI path/ HTTP path)
  815. //==========================================================================
  816. int nRc = FATAL_ERROR;
  817. CHString sNamespace;
  818. IWbemServices * pNamespace = NULL;
  819. LogTestBeginning(16,fSuppressHeader);
  820. // =====================================================================
  821. // Run the requested tests and get then namespace open
  822. // =====================================================================
  823. nRc = RunRequestedTestsAndOpenNamespace(16, sNamespace, &pNamespace, fCompareResults);
  824. if( SUCCESS == nRc )
  825. {
  826. // =============================================================
  827. // Get the list of objexts to get
  828. // =============================================================
  829. CHString sObjects;
  830. if( g_Options.GetSpecificOptionForAPITest( L"OBJECT_LIST",sObjects, 16 ) )
  831. {
  832. // =========================================================
  833. // Get the requested objects
  834. // =========================================================
  835. nRc = GetSpecificObjects(sObjects, pNamespace, 16,WPTR sNamespace);
  836. }
  837. }
  838. // =====================================================================
  839. // Release the pointers
  840. // =====================================================================
  841. SAFE_RELEASE_PTR(pNamespace);
  842. LogTestEnding(16,nRc,fSuppressHeader);
  843. return nRc;
  844. }
  845. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  846. //*****************************************************************************************************************
  847. // Test 17
  848. //*****************************************************************************************************************
  849. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  850. int CreateMethods(BOOL fCompareResults, BOOL fSuppressHeader )
  851. {
  852. // =====================================================================
  853. // Getting a list of Methods for a class and instance
  854. // =====================================================================
  855. int nRc = FATAL_ERROR;
  856. CHString sNamespace;
  857. IWbemServices * pNamespace = NULL;
  858. LogTestBeginning(17,fSuppressHeader);
  859. // =====================================================================
  860. // Run the requested tests and get then namespace open
  861. // =====================================================================
  862. nRc = RunRequestedTestsAndOpenNamespace(17, sNamespace, &pNamespace, fCompareResults);
  863. if( SUCCESS == nRc )
  864. {
  865. // =============================================================
  866. // Get the list of methods to create
  867. // =============================================================
  868. CHString sObjects;
  869. if( g_Options.GetSpecificOptionForAPITest( L"METHOD_LIST",sObjects, 17 ) )
  870. {
  871. // =========================================================
  872. // Create the methods
  873. // =========================================================
  874. nRc = CreateMethodsAndCompare(sObjects, pNamespace, 17, fCompareResults, WPTR sNamespace);
  875. }
  876. }
  877. SAFE_RELEASE_PTR(pNamespace);
  878. LogTestEnding(17,nRc,fSuppressHeader);
  879. return nRc;
  880. }
  881. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  882. //*****************************************************************************************************************
  883. // Test 18
  884. //*****************************************************************************************************************
  885. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  886. int DeleteMethods(BOOL fCompareResults, BOOL fSuppressHeader )
  887. {
  888. // =====================================================================
  889. // Getting a list of Methods for a class and instance
  890. // =====================================================================
  891. int nRc = FATAL_ERROR;
  892. CHString sNamespace;
  893. IWbemServices * pNamespace = NULL;
  894. LogTestBeginning(18,fSuppressHeader);
  895. // =====================================================================
  896. // Run the requested tests and get then namespace open
  897. // =====================================================================
  898. nRc = RunRequestedTestsAndOpenNamespace(18, sNamespace, &pNamespace, fCompareResults);
  899. if( SUCCESS == nRc )
  900. {
  901. // =============================================================
  902. // Get the list of methods to delete
  903. // =============================================================
  904. CHString sObjects;
  905. if( g_Options.GetSpecificOptionForAPITest( L"METHOD_LIST",sObjects, 18 ) )
  906. {
  907. // =========================================================
  908. // Delete the methods
  909. // =========================================================
  910. nRc = DeleteMethodsAndCompare(sObjects, pNamespace, 18,fCompareResults,WPTR sNamespace);
  911. }
  912. }
  913. SAFE_RELEASE_PTR(pNamespace);
  914. LogTestEnding(18,nRc,fSuppressHeader);
  915. return nRc;
  916. }
  917. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  918. //*****************************************************************************************************************
  919. // Test 19
  920. //*****************************************************************************************************************
  921. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  922. int ListMethods(BOOL fCompareResults, BOOL fSuppressHeader )
  923. {
  924. // =====================================================================
  925. // Getting a list of Methods for a class and instance
  926. // =====================================================================
  927. int nRc = FATAL_ERROR;
  928. CHString sNamespace;
  929. IWbemServices * pNamespace = NULL;
  930. LogTestBeginning(19,fSuppressHeader);
  931. // =====================================================================
  932. // Run the requested tests and get then namespace open
  933. // =====================================================================
  934. nRc = RunRequestedTestsAndOpenNamespace(19, sNamespace, &pNamespace, fCompareResults);
  935. if( SUCCESS == nRc )
  936. {
  937. // =============================================================
  938. // Get the list of methods to delete
  939. // =============================================================
  940. CHString sObjects;
  941. if( g_Options.GetSpecificOptionForAPITest( L"METHOD_LIST",sObjects, 19 ) )
  942. {
  943. // =========================================================
  944. // Delete the methods
  945. // =========================================================
  946. nRc = EnumerateMethodsAndCompare(sObjects, pNamespace, 19,fCompareResults,WPTR sNamespace);
  947. }
  948. }
  949. SAFE_RELEASE_PTR(pNamespace);
  950. LogTestEnding(19,nRc,fSuppressHeader);
  951. return nRc;
  952. }
  953. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  954. //*****************************************************************************************************************
  955. // Test 20
  956. //*****************************************************************************************************************
  957. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  958. int DeleteAllNonSystemClasses(BOOL fCompareResults, BOOL fSuppressHeader )
  959. {
  960. int nRc = FATAL_ERROR;
  961. CHString sNamespace;
  962. IWbemServices * pNamespace = NULL;
  963. LogTestBeginning(20,fSuppressHeader);
  964. // =====================================================================
  965. // Run the requested tests and get then namespace open
  966. // =====================================================================
  967. nRc = RunRequestedTestsAndOpenNamespace(20, sNamespace, &pNamespace, fCompareResults);
  968. if( SUCCESS == nRc )
  969. {
  970. IEnumWbemClassObject * pEnum = NULL;
  971. //===========================================================
  972. // Begin enumerating all of the classes in the namespace
  973. //===========================================================
  974. nRc = EnumerateClassesAndLogErrors(pNamespace,&pEnum, WBEM_FLAG_RETURN_IMMEDIATELY|WBEM_FLAG_FORWARD_ONLY , NULL, WPTR sNamespace,NO_ERRORS_EXPECTED);
  975. if( nRc == S_OK )
  976. {
  977. //===================================================
  978. // while we get the classes in the namespace
  979. //===================================================
  980. IWbemClassObject * pClass = NULL;
  981. while( TRUE )
  982. {
  983. nRc = NextClassAndLogErrors(pEnum, &pClass,WPTR sNamespace,NO_ERRORS_EXPECTED);
  984. if( nRc == NO_MORE_DATA )
  985. {
  986. nRc = SUCCESS;
  987. break;
  988. }
  989. if( nRc != SUCCESS )
  990. {
  991. break;
  992. }
  993. CVARIANT vProperty;
  994. CIMTYPE pType = 0;
  995. LONG lFlavor = 0;
  996. //===================================================
  997. // Get the name of the class
  998. //===================================================
  999. nRc = GetPropertyAndLogErrors( pClass, L"__CLASS", &vProperty, &pType, &lFlavor, NULL,WPTR sNamespace, NO_ERRORS_EXPECTED);
  1000. if( nRc == S_OK )
  1001. {
  1002. //===============================================
  1003. // filter out system classes
  1004. //===============================================
  1005. if( wcsncmp( vProperty.GetStr(), L"__", 2 ) != 0 )
  1006. {
  1007. //===============================================
  1008. // Delete it, however, it may not be there if
  1009. // the parent class has already been deleted.
  1010. //===============================================
  1011. DeleteClassAndLogErrors(pNamespace, vProperty.GetStr(), WPTR sNamespace,ERRORS_CAN_BE_EXPECTED);
  1012. }
  1013. }
  1014. SAFE_RELEASE_PTR(pClass);
  1015. }
  1016. SAFE_RELEASE_PTR(pClass);
  1017. }
  1018. }
  1019. SAFE_RELEASE_PTR(pNamespace);
  1020. LogTestEnding(20,nRc,fSuppressHeader);
  1021. return nRc;
  1022. }
  1023. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1024. //*****************************************************************************************************************
  1025. // Test 21
  1026. //*****************************************************************************************************************
  1027. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1028. int DeleteRequestedNamespace(BOOL fCompareResults, BOOL fSuppressHeader )
  1029. {
  1030. int nRc = FATAL_ERROR;
  1031. CHString sNamespace;
  1032. IWbemServices * pNamespace = NULL;
  1033. LogTestBeginning(21,fSuppressHeader);
  1034. // =====================================================================
  1035. // Run the requested tests
  1036. // Go to the parent namespace
  1037. // =====================================================================
  1038. nRc = RunRequestedTestsAndOpenNamespace(21, sNamespace, &pNamespace, fCompareResults);
  1039. if( SUCCESS == nRc )
  1040. {
  1041. //==================================================================
  1042. // Get the name of the namespace to delete
  1043. //==================================================================
  1044. CHString sObjects;
  1045. if( g_Options.GetSpecificOptionForAPITest( L"NAMESPACE_TO_DELETE",sObjects, 21 ) )
  1046. {
  1047. // =========================================================
  1048. // See if the instance exists
  1049. // =========================================================
  1050. IWbemClassObject * pClass = NULL;
  1051. nRc = GetClassObjectAndLogErrors( pNamespace, sObjects, &pClass,WPTR sNamespace,ERRORS_CAN_BE_EXPECTED);
  1052. SAFE_RELEASE_PTR(pClass);
  1053. if( SUCCESS == nRc )
  1054. {
  1055. // =========================================================
  1056. // Delete the instances of the namespace
  1057. // =========================================================
  1058. nRc = DeleteInstanceAndLogErrors(pNamespace, sObjects, WPTR sNamespace, NO_ERRORS_EXPECTED );
  1059. }
  1060. else
  1061. {
  1062. if( nRc == FAILED_AS_EXPECTED )
  1063. {
  1064. nRc = SUCCESS;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. SAFE_RELEASE_PTR(pNamespace);
  1070. LogTestEnding(21,nRc,fSuppressHeader);
  1071. return nRc;
  1072. }