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.

286 lines
7.3 KiB

  1. <!--
  2. ******************************************************************
  3. '
  4. ' put.wsf
  5. '
  6. ' Purpose: test Put functionality
  7. '
  8. ' Parameters: none
  9. '
  10. ' Returns: 0 - success
  11. ' 1 - failure
  12. '
  13. '*****************************************************************
  14. -->
  15. <job id="WMI Put 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\put.txt"
  21. scriptHelper.loggingLevel = 3
  22. scriptHelper.testName = "WMI Put"
  23. scriptHelper.testStart
  24. dim l
  25. dim nsDefault
  26. dim nsCimv2
  27. dim nsRemote
  28. TestPreamble
  29. TestCreation
  30. TestPostamble
  31. scriptHelper.testComplete
  32. if scriptHelper.statusOK then
  33. WScript.Echo "PASS"
  34. WScript.Quit 0
  35. else
  36. WScript.Echo "FAIL"
  37. WScript.Quit 1
  38. end if
  39. '******************************************************************
  40. '
  41. ' TestPreamble
  42. '
  43. ' Purpose: Create some objects for this test
  44. '
  45. '*****************************************************************
  46. Sub TestPreamble
  47. on error resume next
  48. ' Create a locator
  49. set l = CreateObject("WbemScripting.SWbemLocator")
  50. if err <> 0 then
  51. scriptHelper.writeErrorToLog err, "Failed to create locator"
  52. else
  53. scriptHelper.writeToLog "Successful creation of locator", 2
  54. end if
  55. ' Connect to the namespace
  56. set nsDefault = l.ConnectServer (,"root\default")
  57. if err <> 0 then
  58. scriptHelper.writeErrorToLog err, "Failed to connect to root\default"
  59. else
  60. scriptHelper.writeToLog "Successful connection to root\default", 2
  61. end if
  62. 'Make a new class
  63. set newClass = nsDefault.Get
  64. if err <> 0 then
  65. scriptHelper.writeErrorToLog err, "Failed to get empty class"
  66. else
  67. scriptHelper.writeToLog "Successful retrieval of empty class", 2
  68. end if
  69. newClass.Path_.Class = "PUT000TEST"
  70. ' Add a key property (uint32)
  71. set p0 = newClass.Properties_.Add ("p0", wbemCimtypeUint32)
  72. p0.Qualifiers_.Add "key", true
  73. if err <> 0 then
  74. scriptHelper.writeErrorToLog err, "Failed to define class"
  75. else
  76. scriptHelper.writeToLog "Successful definition of class", 2
  77. end if
  78. ' Save the class
  79. set path = newClass.Put_
  80. if err <> 0 then
  81. scriptHelper.writeErrorToLog err, "Failed to save class"
  82. else
  83. scriptHelper.writeToLog "Successful save of class", 2
  84. end if
  85. if path.Path <> "\\.\root\default:PUT000TEST" then
  86. scriptHelper.writeErrorToLog null, "Unexpected path returned"
  87. else
  88. scriptHelper.writeToLog "Path returned from class put is OK", 2
  89. end if
  90. ' Save the class in another namespace
  91. set nsCimv2 = l.ConnectServer (,"root\cimv2")
  92. if err <> 0 then
  93. scriptHelper.writeErrorToLog err, "Failed to connect to root\cimv2"
  94. else
  95. scriptHelper.writeToLog "Successful connection to root\cimv2", 2
  96. end if
  97. set path = nsCimv2.Put (newClass)
  98. if err <> 0 then
  99. scriptHelper.writeErrorToLog err, "Failed to save class"
  100. else
  101. scriptHelper.writeToLog "Successful save of class", 2
  102. end if
  103. if path.Path <> "\\.\root\cimv2:PUT000TEST" then
  104. scriptHelper.writeErrorToLog null, "Unexpected path returned"
  105. else
  106. scriptHelper.writeToLog "Path returned from class put is OK", 2
  107. end if
  108. ' Save the class in a remote namespace
  109. set nsRemote = l.ConnectServer ("alanbos2", "root\default")
  110. if err <> 0 then
  111. scriptHelper.writeErrorToLog err, "Failed to connect to \\alanbos2\root\default"
  112. else
  113. scriptHelper.writeToLog "Successful connection to \\alanbos2\root\default", 2
  114. end if
  115. ' Save the class in a remote namespace
  116. set path = nsRemote.Put (newClass)
  117. if err <> 0 then
  118. scriptHelper.writeErrorToLog err, "Failed to save class"
  119. else
  120. scriptHelper.writeToLog "Successful save of class", 2
  121. end if
  122. if path.Path <> "\\alanbos2\root\default:PUT000TEST" then
  123. scriptHelper.writeErrorToLog null, "Unexpected path returned"
  124. else
  125. scriptHelper.writeToLog "Path returned from class put is OK", 2
  126. end if
  127. End Sub
  128. '******************************************************************
  129. '
  130. ' TestCreation
  131. '
  132. ' Purpose: Check paths of new instances are OK
  133. '
  134. '*****************************************************************
  135. Sub TestCreation
  136. on error resume next
  137. ' Regular SpawnInstance
  138. set myInstance = nsDefault.Get ("PUT000TEST").SpawnInstance_
  139. if err <> 0 then
  140. scriptHelper.writeErrorToLog err, "Failed to create instance "
  141. else
  142. scriptHelper.writeToLog "Successful creation of instance", 2
  143. end if
  144. myInstance.p0 = 1
  145. set path = myInstance.Put_
  146. if err <> 0 then
  147. scriptHelper.writeErrorToLog err, "Failed to save instance"
  148. else
  149. scriptHelper.writeToLog "Successful save of instance", 2
  150. end if
  151. if (0 = StrComp(path.Path, "\\.\root\default:PUT000TEST.p0=1", vbTextCompare)) Or _
  152. (0 = StrComp(path.Path, "\\alanbos4\root\default:PUT000TEST.p0=1", vbTextCompare)) then
  153. scriptHelper.writeToLog "Path returned on instance put to root\default is OK", 2
  154. else
  155. scriptHelper.writeErrorToLog null, "Unexpected path returned on instance put to root\default"
  156. end if
  157. ' Open an object
  158. set myInstance = l.ConnectServer (,"root\cimv2").Get("PUT000TEST").SpawnInstance_
  159. if err <> 0 then
  160. scriptHelper.writeErrorToLog err, "Failed to create instance"
  161. else
  162. scriptHelper.writeToLog "Successful creation of instance", 2
  163. end if
  164. myInstance.p0 = 23
  165. set path = myInstance.Put_
  166. if err <> 0 then
  167. scriptHelper.writeErrorToLog err, "Failed to save instance"
  168. else
  169. scriptHelper.writeToLog "Successful save of instance", 2
  170. end if
  171. if (0 = StrComp(path.Path, "\\.\root\cimv2:PUT000TEST.p0=23", vbTextCompare)) Or _
  172. (0 = StrComp(path.Path, "\\alanbos4\root\cimv2:PUT000TEST.p0=23", vbTextCompare)) then
  173. scriptHelper.writeToLog "Path returned on instance put to \\.\root\cimv2 is OK", 2
  174. else
  175. scriptHelper.writeErrorToLog null, "Unexpected path returned on instance put to \\.\root\cimv2 [" & path.Path & "]"
  176. end if
  177. ' Save to a different namespace
  178. set myInstance = nsRemote.Get("PUT000TEST").SpawnInstance_
  179. if err <> 0 then
  180. scriptHelper.writeErrorToLog err, "Failed to get instance"
  181. else
  182. scriptHelper.writeToLog "Successful get of instance", 2
  183. end if
  184. myInstance.p0 = 77
  185. set path = nsRemote.Put (myInstance)
  186. if err <> 0 then
  187. scriptHelper.writeErrorToLog err, "Failed to save instance"
  188. else
  189. scriptHelper.writeToLog "Successful save of instance", 2
  190. end if
  191. if (0 = StrComp(path.Path, "\\alanbos2\root\default:PUT000TEST.p0=77", vbTextCompare)) then
  192. scriptHelper.writeToLog "Path returned on instance put to \\alanbos2\root\default is OK", 2
  193. else
  194. scriptHelper.writeErrorToLog null, "Unexpected path returned on instance put to \\alanbos2\root\default [" & path.Path & "]"
  195. end if
  196. End Sub
  197. '******************************************************************
  198. '
  199. ' TestPostamble
  200. '
  201. ' Purpose: Create some objects for this test
  202. '
  203. '*****************************************************************
  204. Sub TestPostamble
  205. on error resume next
  206. ' Clean up
  207. nsDefault.Delete ("PUT000TEST")
  208. if err <> 0 then
  209. scriptHelper.writeErrorToLog err, "Failed to delete class in root\default"
  210. else
  211. scriptHelper.writeToLog "Successful delete of class in root\default", 2
  212. end if
  213. nsCimv2.Delete ("PUT000TEST")
  214. if err <> 0 then
  215. scriptHelper.writeErrorToLog err, "Failed to delete class in root\cimv2"
  216. else
  217. scriptHelper.writeToLog "Successful delete of class in root\cimv2", 2
  218. end if
  219. nsRemote.Delete ("PUT000TEST")
  220. End Sub
  221. </script>
  222. </job>