Leaked source code of windows server 2003
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.

831 lines
23 KiB

  1. <!--
  2. ******************************************************************
  3. '
  4. ' container.wsf
  5. '
  6. ' Purpose: test SWbemServicesEx and SWbemObjectEx containers
  7. '
  8. ' Parameters: none
  9. '
  10. ' Returns: 0 - success
  11. ' 1 - failure
  12. '
  13. '*****************************************************************
  14. -->
  15. <job id="WMI Container Test">
  16. <reference object="WbemScripting.SWbemLocator" version="1.2"/>
  17. <script language="VBScript">
  18. on error resume next
  19. set scriptHelper = CreateObject("WMIScriptHelper.WSC")
  20. scriptHelper.logFile = "c:\temp\container.txt"
  21. scriptHelper.loggingLevel = 3
  22. scriptHelper.testName = "WMI Container"
  23. scriptHelper.testStart
  24. dim l
  25. dim ns
  26. TestPreamble
  27. TestLocatorOpen
  28. TestServicesOpen
  29. TestScopeOnObject
  30. TestCollection
  31. TestCollectionOnObject
  32. 'TestPostamble
  33. scriptHelper.testComplete
  34. if scriptHelper.statusOK then
  35. WScript.Echo "PASS"
  36. WScript.Quit 0
  37. else
  38. WScript.Echo "FAIL"
  39. WScript.Quit 1
  40. end if
  41. '******************************************************************
  42. '
  43. ' TestPreamble
  44. '
  45. ' Purpose: Create some objects for this test
  46. '
  47. '*****************************************************************
  48. Sub TestPreamble
  49. on error resume next
  50. ' Create a locator
  51. set l = CreateObject("WbemScripting.SWbemLocatorEx")
  52. if err <> 0 then
  53. scriptHelper.writeErrorToLog err, "Failed to create locator"
  54. else
  55. scriptHelper.writeToLog "Successful creation of locator", 2
  56. end if
  57. ' Connect to the namespace
  58. set ns = l.ConnectServer (,"root\default")
  59. if err <> 0 then
  60. scriptHelper.writeErrorToLog err, "Failed to connect to root\default"
  61. else
  62. scriptHelper.writeToLog "Successful connection to root\default", 2
  63. end if
  64. 'Make a new class
  65. set newClass = ns.Get
  66. if err <> 0 then
  67. scriptHelper.writeErrorToLog err, "Failed to get empty class"
  68. else
  69. scriptHelper.writeToLog "Successful retrieval of empty class", 2
  70. end if
  71. newClass.Path_.Class = "CONTAINER000TEST"
  72. ' Add a key property (uint32)
  73. set p0 = newClass.Properties_.Add ("p0", wbemCimtypeUint32)
  74. p0.Qualifiers_.Add "key", true
  75. if err <> 0 then
  76. scriptHelper.writeErrorToLog err, "Failed to define class"
  77. else
  78. scriptHelper.writeToLog "Successful definition of class", 2
  79. end if
  80. ' Save the class
  81. newClass.Put_
  82. if err <> 0 then
  83. scriptHelper.writeErrorToLog err, "Failed to save class"
  84. else
  85. scriptHelper.writeToLog "Successful save of class", 2
  86. end if
  87. ' Get it back and make an instance
  88. set newInstance = ns.Get ("CONTAINER000TEST").SpawnInstance_
  89. if err <> 0 then
  90. scriptHelper.writeErrorToLog err, "Failed to get class"
  91. else
  92. scriptHelper.writeToLog "Successful get of class", 2
  93. end if
  94. ' Create an instance
  95. newInstance.p0 = 1
  96. newInstance.Put_
  97. if err <> 0 then
  98. scriptHelper.writeErrorToLog err, "Failed to create instance"
  99. else
  100. scriptHelper.writeToLog "Successful creation of instance", 2
  101. end if
  102. 'Make another new class
  103. newClass.Path_.Class = "CONTAINER001TEST"
  104. newClass.Put_
  105. if err <> 0 then
  106. scriptHelper.writeErrorToLog err, "Failed to define class"
  107. else
  108. scriptHelper.writeToLog "Successful definition of class", 2
  109. end if
  110. 'Make an association class
  111. set newClass = ns.Get
  112. newClass.Path_.Class = "CONTAINER000TESTASSOC"
  113. newClass.Qualifiers_.Add "association", true
  114. set propList = newClass.Properties_
  115. set p1 = propList.Add ("p000", wbemCimtypeReference)
  116. p1.Qualifiers_.Add "key", true
  117. p1.Qualifiers_.Add "cimtype", "ref:CONTAINER000TEST"
  118. set p2 = propList.Add ("p001", wbemCimtypeReference)
  119. p2.Qualifiers_.Add "key", true
  120. p2.Qualifiers_.Add "cimtype", "ref:CONTAINER001TEST"
  121. newClass.Put_
  122. if err <> 0 then
  123. scriptHelper.writeErrorToLog err, "Failed to define assoc class"
  124. else
  125. scriptHelper.writeToLog "Successful definition of assoc class", 2
  126. end if
  127. End Sub
  128. '******************************************************************
  129. '
  130. ' TestPostamble
  131. '
  132. ' Purpose: Create some objects for this test
  133. '
  134. '*****************************************************************
  135. Sub TestPostamble
  136. on error resume next
  137. ' Clean up
  138. ns.Delete ("CONTAINER000TEST")
  139. ns.Delete ("CONTAINER001TEST")
  140. ns.Delete ("CONTAINER000TESTASSOC")
  141. if err <> 0 then
  142. scriptHelper.writeErrorToLog err, "Failed to delete class"
  143. else
  144. scriptHelper.writeToLog "Successful delete of class", 2
  145. end if
  146. End Sub
  147. '******************************************************************
  148. '
  149. ' TestLocatorOpen
  150. '
  151. ' Purpose: test SWbemLocatorEx scope functionality
  152. '
  153. '*****************************************************************
  154. Sub TestLocatorOpen
  155. on error resume next
  156. scriptHelper.writeToLog ">>>", 2
  157. scriptHelper.writeToLog ">>> TestLocatorOpen", 2
  158. scriptHelper.writeToLog ">>>", 2
  159. ' Open the instance as a scope
  160. set scope = l.Open ("root\default:CONTAINER000TEST=1", ,,,,, wbemTypeServices)
  161. if err <> 0 then
  162. scriptHelper.writeErrorToLog err, "Failed to open instance as scope"
  163. else
  164. scriptHelper.writeToLog "Successful opening of instance as scope", 2
  165. TestScope scope
  166. end if
  167. scriptHelper.writeToLog "<<<", 2
  168. scriptHelper.writeToLog "<<< TestLocatorOpen", 2
  169. scriptHelper.writeToLog "<<<", 2
  170. End Sub
  171. '******************************************************************
  172. '
  173. ' TestScope
  174. '
  175. ' Purpose: test SWbemServicesEx scope functionality
  176. '
  177. '*****************************************************************
  178. Sub TestScope (scope)
  179. on error resume next
  180. scriptHelper.writeToLog ">>>", 2
  181. scriptHelper.writeToLog ">>> TestScope", 2
  182. scriptHelper.writeToLog ">>>", 2
  183. ' Add an object to the scope (note class retrieval is from scope!)
  184. set newInstance = scope.Get ("CONTAINER000TEST").SpawnInstance_
  185. if err <> 0 then
  186. scriptHelper.writeErrorToLog err, "Failed to get class from scope"
  187. else
  188. scriptHelper.writeToLog "Successful retrieval of class from scope", 2
  189. end if
  190. newInstance.p0 = 2
  191. scope.Put (newInstance)
  192. if err <> 0 then
  193. scriptHelper.writeErrorToLog err, "Failed to save instance in scope"
  194. else
  195. scriptHelper.writeToLog "Successful saving of instance in scope", 2
  196. end if
  197. ' Check we can access the scoped element from the parent namespace
  198. set newInstance = ns.Get("CONTAINER000TEST=1:CONTAINER000TEST=2")
  199. if err <> 0 then
  200. scriptHelper.writeErrorToLog err, "Failed to get instance from parent namespace"
  201. else
  202. scriptHelper.writeToLog "Successful retrieval of instance from parent namespace", 2
  203. end if
  204. ' Check we can access the scoped element from this scope
  205. set newInstance = scope.Get("CONTAINER000TEST=2")
  206. if err <> 0 then
  207. scriptHelper.writeErrorToLog err, "Failed to get instance from this scope"
  208. else
  209. scriptHelper.writeToLog "Successful retrieval of instance from this scope", 2
  210. end if
  211. ' Enumerate the members of the scope
  212. set objColl = scope.InstancesOf ("CONTAINER000TEST")
  213. if err <> 0 then
  214. scriptHelper.writeErrorToLog err, "Failed to enumerate instances in scope"
  215. else
  216. scriptHelper.writeToLog "Successful enumeration of instances in scope", 2
  217. end if
  218. if 1 = objColl.Count then
  219. ' Check it is the right object
  220. for each obj in objColl
  221. if 2 = obj.p0 then
  222. scriptHelper.writeToLog "Correct instance in scope enumeration", 2
  223. else
  224. scriptHelper.writeErrorToLog null, "Incorrect p0 [2]: " & obj.p0
  225. end if
  226. exit for
  227. next
  228. else
  229. scriptHelper.writeErrorToLog null, "Incorrect count [1]: " & objColl.Count
  230. end if
  231. ' Enumerate the members of the scope using the intrinsic collection
  232. firstElement = true
  233. ok = true
  234. for each obj2 in scope
  235. if err <> 0 then
  236. scriptHelper.writeErrorToLog err, "Error enumerating intrinsic collection on scope"
  237. ok = false
  238. exit for
  239. elseif 2 <> obj2.p0 then
  240. scriptHelper.writeErrorToLog null, "Incorrect p0 [2]: " & obj2.p0
  241. ok = false
  242. elseif Not(firstElement) then
  243. scriptHelper.writeErrorToLog null, "Incorrect count [0]: "
  244. ok = false
  245. else
  246. scriptHelper.writeToLog "Default enumeration of scope: " & obj2.Path_.Path, 2
  247. firstElement = false
  248. end if
  249. next
  250. if ok then scriptHelper.writeToLog "Successful instance enumeration using scope default collection", 2
  251. ' Set up a filter and try it again
  252. scope.Filter_ = Array ("CONTAINER000TEST", "CONTAINER001TEST")
  253. if err <> 0 then
  254. scriptHelper.writeErrorToLog err, "Failed to set filter on scope"
  255. else
  256. scriptHelper.writeToLog "Successful set of filter on scope", 2
  257. end if
  258. firstElement = true
  259. ok = true
  260. for each obj in scope
  261. if err <> 0 then
  262. scriptHelper.writeErrorToLog err, "Error enumerating intrinsic filtered collection on scope"
  263. ok = false
  264. exit for
  265. elseif 2 <> obj.p0 then
  266. scriptHelper.writeErrorToLog null, "Incorrect p0 [2]: " & obj.p0
  267. ok = false
  268. elseif Not(firstElement) then
  269. scriptHelper.writeErrorToLog null, "Incorrect count [0]: "
  270. ok = false
  271. else
  272. scriptHelper.writeToLog "Default filtered enumeration: " & obj.Path_.Path, 2
  273. firstElement = false
  274. end if
  275. next
  276. if ok then scriptHelper.writeToLog "Successful instance enumeration using scope default collection", 2
  277. ' Now set the filter to match 0 elements in the scope
  278. scope.Filter_ = Array ("CONTAINER001TEST")
  279. if err <> 0 then
  280. scriptHelper.writeErrorToLog err, "Failed to set filter on scope"
  281. else
  282. scriptHelper.writeToLog "Successful set of filter on scope", 2
  283. end if
  284. ok = true
  285. for each obj in scope
  286. scriptHelper.writeErrorToLog null, "Incorrect count [0]: "
  287. ok = false
  288. exit for
  289. next
  290. if ok then scriptHelper.writeToLog "Successful instance enumeration using scope default collection", 2
  291. ' Delete the item from the scope
  292. scope.Delete "CONTAINER000TEST=2"
  293. if err <> 0 then
  294. scriptHelper.writeErrorToLog err, "Failed to delete instances in scope"
  295. else
  296. scriptHelper.writeToLog "Successful delete of instances in scope", 2
  297. end if
  298. ' Check it's gone
  299. set objColl = scope.InstancesOf ("CONTAINER000TEST")
  300. if err <> 0 then
  301. scriptHelper.writeErrorToLog err, "Failed to enumerate instances in scope"
  302. else
  303. scriptHelper.writeToLog "Successful enumeration of instances in scope", 2
  304. end if
  305. if 0 = objColl.Count then
  306. scriptHelper.writeToLog "Correct instance count in scope enumeration [0]", 2
  307. else
  308. scriptHelper.writeErrorToLog null, "Incorrect count [0]: " & objColl.Count
  309. end if
  310. scriptHelper.writeToLog "<<<", 2
  311. scriptHelper.writeToLog "<<< TestScope", 2
  312. scriptHelper.writeToLog "<<<", 2
  313. End Sub
  314. '******************************************************************
  315. '
  316. ' TestServicesOpen
  317. '
  318. ' Purpose: test SWbemServicesEx scope functionality
  319. '
  320. '*****************************************************************
  321. Sub TestServicesOpen
  322. on error resume next
  323. scriptHelper.writeToLog ">>>", 2
  324. scriptHelper.writeToLog ">>> TestServicesOpen", 2
  325. scriptHelper.writeToLog ">>>", 2
  326. ' Open the instance as a scope
  327. set scope = ns.Open ("CONTAINER000TEST=1", wbemConnectionFlagOpenScope _
  328. OR wbemConnectionFlagAllowNamespaceTraversal OR wbemConnectionFlagAllowMachineTraversal)
  329. if err <> 0 then
  330. scriptHelper.writeErrorToLog err, "Failed to open instance as scope"
  331. else
  332. scriptHelper.writeToLog "Successful opening of instance as scope", 2
  333. TestScope scope
  334. end if
  335. scriptHelper.writeToLog "<<<", 2
  336. scriptHelper.writeToLog "<<< TestServicesOpen", 2
  337. scriptHelper.writeToLog "<<<", 2
  338. End Sub
  339. '******************************************************************
  340. '
  341. ' TestScopeOnObject
  342. '
  343. ' Purpose: test SWbemObjectEx scope functionality
  344. '
  345. '*****************************************************************
  346. Sub TestScopeOnObject
  347. scriptHelper.writeToLog ">>>", 2
  348. scriptHelper.writeToLog ">>> TestScopeOnObject", 2
  349. scriptHelper.writeToLog ">>>", 2
  350. on error resume next
  351. ' Open the instance as an object
  352. set instance = ns.Get ("CONTAINER000TEST=1")
  353. if err <> 0 then
  354. scriptHelper.writeErrorToLog err, "Failed to open instance as object"
  355. else
  356. scriptHelper.writeToLog "Successful opening of instance as object", 2
  357. end if
  358. ' Add an object to the scope (note class retrieval is from scope!)
  359. set newInstance = instance.CreateInstance_ ("CONTAINER001TEST=1")
  360. newInstance.Put_
  361. if err <> 0 then
  362. scriptHelper.writeErrorToLog err, "Failed to save instance in object"
  363. else
  364. scriptHelper.writeToLog "Successful saving of instance in object", 2
  365. end if
  366. ' Check we can access the scoped element from the parent namespace
  367. set newInstance = ns.Get("CONTAINER000TEST=1:CONTAINER001TEST=1")
  368. if err <> 0 then
  369. scriptHelper.writeErrorToLog err, "Failed to get instance from parent namespace"
  370. else
  371. scriptHelper.writeToLog "Successful retrieval of instance from parent namespace", 2
  372. end if
  373. ' Check we can access the scoped element from this object
  374. set newInstance = instance.GetInstance_ ("CONTAINER001TEST=1")
  375. if err <> 0 then
  376. scriptHelper.writeErrorToLog err, "Failed to get instance from this object"
  377. else
  378. scriptHelper.writeToLog "Successful retrieval of instance from this object", 2
  379. end if
  380. ' Enumerate the members of the scope
  381. set objColl = instance.ExecQuery ("select * from CONTAINER001TEST")
  382. if err <> 0 then
  383. scriptHelper.writeErrorToLog err, "Failed to enumerate instances in object"
  384. else
  385. scriptHelper.writeToLog "Successful enumeration of instances in object", 2
  386. end if
  387. if 1 = objColl.Count then
  388. ' Check it is the right object
  389. for each obj in objColl
  390. if 1 = obj.p0 then
  391. scriptHelper.writeToLog "Correct instance in scope enumeration", 2
  392. else
  393. scriptHelper.writeErrorToLog null, "Incorrect p0 [1]: " & obj.p0
  394. end if
  395. exit for
  396. next
  397. else
  398. scriptHelper.writeErrorToLog null, "Incorrect count [1]: " & objColl.Count
  399. end if
  400. ' Enumerate the members of the scope using the intrinsic collection
  401. firstElement = true
  402. ok = true
  403. for each obj in instance
  404. if 1 <> obj.p0 then
  405. scriptHelper.writeErrorToLog null, "Incorrect p0 [1]: " & obj.p0
  406. ok = false
  407. elseif Not(firstElement) then
  408. scriptHelper.writeErrorToLog null, "Incorrect count [1]: "
  409. ok = false
  410. else
  411. scriptHelper.writeToLog "Default enumeration: " & obj.Path_.Path, 2
  412. firstElement = false
  413. end if
  414. next
  415. if ok then scriptHelper.writeToLog "Successful instance enumeration using object default collection", 2
  416. ' Set up a filter and try it again
  417. instance.Filter_ = Array ("CONTAINER000TEST", "CONTAINER001TEST")
  418. if err <> 0 then
  419. scriptHelper.writeErrorToLog err, "Failed to set filter on object"
  420. else
  421. scriptHelper.writeToLog "Successful set of filter on object", 2
  422. end if
  423. firstElement = true
  424. ok = true
  425. for each obj in instance
  426. if 1 <> obj.p0 then
  427. scriptHelper.writeErrorToLog null, "Incorrect p0 [1]: " & obj.p0
  428. ok = false
  429. elseif Not(firstElement) then
  430. scriptHelper.writeErrorToLog null, "Incorrect count [1]: "
  431. ok = false
  432. else
  433. scriptHelper.writeToLog "Default enumeration: " & obj.Path_.Path, 2
  434. firstElement = false
  435. end if
  436. next
  437. if ok then scriptHelper.writeToLog "Successful instance enumeration using object default collection", 2
  438. ' Now set the filter to match 0 elements in the scope
  439. instance.Filter_ = Array ("CONTAINER000TEST")
  440. if err <> 0 then
  441. scriptHelper.writeErrorToLog err, "Failed to set filter on object"
  442. else
  443. scriptHelper.writeToLog "Successful set of filter on object", 2
  444. end if
  445. ok = true
  446. for each obj in instance
  447. scriptHelper.writeErrorToLog null, "Incorrect count [0]: "
  448. ok = false
  449. exit for
  450. next
  451. if ok then scriptHelper.writeToLog "Successful instance enumeration using object default collection", 2
  452. ' Delete the item from the scope
  453. instance.DeleteInstance_ "CONTAINER001TEST=1"
  454. if err <> 0 then
  455. scriptHelper.writeErrorToLog err, "Failed to delete instances in object"
  456. else
  457. scriptHelper.writeToLog "Successful delete of instances in object", 2
  458. end if
  459. ' Check it's gone
  460. set objColl = instance.ExecQuery_ ("select * from CONTAINER001TEST")
  461. if err <> 0 then
  462. scriptHelper.writeErrorToLog err, "Failed to enumerate instances in object"
  463. else
  464. scriptHelper.writeToLog "Successful enumeration of instances in object", 2
  465. end if
  466. if 0 = objColl.Count then
  467. scriptHelper.writeToLog "Correct instance count in object instance enumeration [0]", 2
  468. else
  469. scriptHelper.writeErrorToLog null, "Incorrect count [0]: " & objColl.Count
  470. end if
  471. scriptHelper.writeToLog "<<<", 2
  472. scriptHelper.writeToLog "<<< TestScopeOnObject", 2
  473. scriptHelper.writeToLog "<<<", 2
  474. End Sub
  475. '******************************************************************
  476. '
  477. ' TestCollection
  478. '
  479. ' Purpose: test SWbemServicesEx collection functionality
  480. '
  481. '*****************************************************************
  482. Sub TestCollection
  483. on error resume next
  484. scriptHelper.writeToLog ">>>", 2
  485. scriptHelper.writeToLog ">>> TestCollection", 2
  486. scriptHelper.writeToLog ">>>", 2
  487. ' Open the instance as a collection based on our assoc class
  488. set collection = ns.Open ("CONTAINER000TEST=1", wbemConnectionFlagOpenCollection, "CONTAINER000TESTASSOC")
  489. if err <> 0 then
  490. scriptHelper.writeErrorToLog err, "Failed to open instance as collection"
  491. else
  492. scriptHelper.writeToLog "Successful opening of instance as collection", 2
  493. end if
  494. ' Make a new instance in the same namespace
  495. set newInstance = ns.Get("CONTAINER001TEST").SpawnInstance_
  496. newInstance.p0 = 23
  497. newInstance.Put_
  498. if err <> 0 then
  499. scriptHelper.writeErrorToLog err, "Failed to create new instance in namespace"
  500. else
  501. scriptHelper.writeToLog "Successful creation of instance in namespace", 2
  502. end if
  503. ' Add the new instance to this collection
  504. collection.Add "CONTAINER001TEST=23"
  505. if err <> 0 then
  506. scriptHelper.writeErrorToLog err, "Failed to add instance to collection"
  507. else
  508. scriptHelper.writeToLog "Successful addition of instance to collection", 2
  509. end if
  510. ' Do we have a new association instance?
  511. set assocInstance = ns.Get ("CONTAINERTEST000ASSOC.p000=1,p001=23")
  512. if err <> 0 then
  513. scriptHelper.writeErrorToLog err, "Failed to get assoc instance from parent namespace"
  514. else
  515. scriptHelper.writeToLog "Successful retrieval of assoc instance from parent namespace", 2
  516. end if
  517. ' Check we can access the new instance as a member of this collection
  518. set newInstance = collection.Get("CONTAINER001TEST=23")
  519. if err <> 0 then
  520. scriptHelper.writeErrorToLog err, "Failed to get instance from this collection"
  521. else
  522. scriptHelper.writeToLog "Successful retrieval of instance from this collection", 2
  523. end if
  524. ' Enumerate the members of the collection
  525. set objColl = collection.InstancesOf ("CONTAINER001TEST")
  526. if err <> 0 then
  527. scriptHelper.writeErrorToLog err, "Failed to enumerate instances in collection"
  528. else
  529. scriptHelper.writeToLog "Successful enumeration of instances in collection", 2
  530. end if
  531. if 1 = objColl.Count then
  532. ' Check it is the right object
  533. for each obj in objColl
  534. if 23 = obj.p0 then
  535. scriptHelper.writeToLog "Correct instance in collection enumeration", 2
  536. else
  537. scriptHelper.writeErrorToLog null, "Incorrect p0 [23]: " & obj.p0
  538. end if
  539. exit for
  540. next
  541. else
  542. scriptHelper.writeErrorToLog null, "Incorrect count [1]: " & objColl.Count
  543. end if
  544. ' Remove the item from the container
  545. container.Remove "CONTAINER001TEST=23"
  546. if err <> 0 then
  547. scriptHelper.writeErrorToLog err, "Failed to remove instance from container"
  548. else
  549. scriptHelper.writeToLog "Successful removal of instance from container", 2
  550. end if
  551. ' Check it's gone
  552. set objColl = container.InstancesOf ("CONTAINER001TEST")
  553. if err <> 0 then
  554. scriptHelper.writeErrorToLog err, "Failed to enumerate instances in collection"
  555. else
  556. scriptHelper.writeToLog "Successful enumeration of instances in collection", 2
  557. end if
  558. if 0 = objColl.Count then
  559. scriptHelper.writeToLog "Correct instance count in collection enumeration [0]", 2
  560. else
  561. scriptHelper.writeErrorToLog null, "Incorrect count [0]: " & objColl.Count
  562. end if
  563. scriptHelper.writeToLog "<<<", 2
  564. scriptHelper.writeToLog "<<< TestCollection", 2
  565. scriptHelper.writeToLog "<<<", 2
  566. End Sub
  567. '******************************************************************
  568. '
  569. ' TestCollectionOnObject
  570. '
  571. ' Purpose: test SWbemObjectEx collection functionality
  572. '
  573. '*****************************************************************
  574. Sub TestCollectionOnObject
  575. on error resume next
  576. scriptHelper.writeToLog ">>>", 2
  577. scriptHelper.writeToLog ">>> TestCollectionOnObject", 2
  578. scriptHelper.writeToLog ">>>", 2
  579. ' Open the instance as an object
  580. set instance = ns.Get ("CONTAINER000TEST=1")
  581. if err <> 0 then
  582. scriptHelper.writeErrorToLog err, "Failed to open instance"
  583. else
  584. scriptHelper.writeToLog "Successful opening of instance", 2
  585. end if
  586. ' Make a new instance in the same namespace
  587. set newInstance = ns.Get("CONTAINER001TEST").SpawnInstance_
  588. newInstance.p0 = 23
  589. newInstance.Put_
  590. if err <> 0 then
  591. scriptHelper.writeErrorToLog err, "Failed to create new instance in namespace"
  592. else
  593. scriptHelper.writeToLog "Successful creation of instance in namespace", 2
  594. end if
  595. ' Add the new instance to this collection
  596. instance.Add_ "CONTAINER001TEST=23", "CONTAINER000TESTASSOC"
  597. if err <> 0 then
  598. scriptHelper.writeErrorToLog err, "Failed to add instance to object collection"
  599. else
  600. scriptHelper.writeToLog "Successful addition of instance to object collection", 2
  601. end if
  602. ' Do we have a new association instance?
  603. set assocInstance = ns.Get ("CONTAINERTEST000ASSOC.p000=1,p001=23")
  604. if err <> 0 then
  605. scriptHelper.writeErrorToLog err, "Failed to get assoc instance from parent namespace"
  606. else
  607. scriptHelper.writeToLog "Successful retrieval of assoc instance from parent namespace", 2
  608. end if
  609. ' Check we can access the new instance as a member of this collection
  610. set newInstance = instance.GetMember_("CONTAINER001TEST=23", "CONTAINER000TESTASSOC")
  611. if err <> 0 then
  612. scriptHelper.writeErrorToLog err, "Failed to get member from this object collection"
  613. else
  614. scriptHelper.writeToLog "Successful retrieval of member from this object collection", 2
  615. end if
  616. ' Enumerate the members of the collection
  617. set objColl = instance.Members_ ("CONTAINER000TESTASSOC")
  618. if err <> 0 then
  619. scriptHelper.writeErrorToLog err, "Failed to enumerate members in object collection"
  620. else
  621. scriptHelper.writeToLog "Successful enumeration of members in object collection", 2
  622. end if
  623. if 1 = objColl.Count then
  624. ' Check it is the right object
  625. for each obj in objColl
  626. if 23 = obj.p0 then
  627. scriptHelper.writeToLog "Correct instance in member enumeration", 2
  628. else
  629. scriptHelper.writeErrorToLog null, "Incorrect p0 [23]: " & obj.p0
  630. end if
  631. exit for
  632. next
  633. else
  634. scriptHelper.writeErrorToLog null, "Incorrect count [1]: " & objColl.Count
  635. end if
  636. ' Remove the item from the collection
  637. instance.Remove "CONTAINER001TEST=23", "CONTAINER000TESTASSOC"
  638. if err <> 0 then
  639. scriptHelper.writeErrorToLog err, "Failed to remove member from object collection"
  640. else
  641. scriptHelper.writeToLog "Successful removal of member from object collection", 2
  642. end if
  643. ' Check it's gone
  644. set objColl = instance.Members_ ("CONTAINER000TESTASSOC")
  645. if err <> 0 then
  646. scriptHelper.writeErrorToLog err, "Failed to enumerate members in object collection"
  647. else
  648. scriptHelper.writeToLog "Successful enumeration of members in object collection", 2
  649. end if
  650. if 0 = objColl.Count then
  651. scriptHelper.writeToLog "Correct member count in object collection [0]", 2
  652. else
  653. scriptHelper.writeErrorToLog null, "Incorrect member count [0]: " & objColl.Count
  654. end if
  655. scriptHelper.writeToLog "<<<", 2
  656. scriptHelper.writeToLog "<<< TestCollectionOnObject", 2
  657. scriptHelper.writeToLog "<<<", 2
  658. End Sub
  659. </script>
  660. </job>