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.

560 lines
13 KiB

  1. <!--
  2. ******************************************************************
  3. '
  4. ' objpath.wsf
  5. '
  6. ' Purpose: test SWbemObjectPath
  7. '
  8. ' Parameters: none
  9. '
  10. ' Returns: 0 - success
  11. ' 1 - failure
  12. '
  13. '*****************************************************************
  14. -->
  15. <job id="WMI ObjectPath 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\objpath.txt"
  21. scriptHelper.loggingLevel = 3
  22. scriptHelper.testName = "WMI ObjectPath"
  23. scriptHelper.testStart
  24. dim path
  25. TestPreamble
  26. TestServer
  27. TestNamespace
  28. TestClass
  29. TestIsClass
  30. TestRelPath
  31. TestKeys
  32. TestSecurity
  33. TestLocale
  34. TestAuthority
  35. TestPath
  36. TestDisplayName
  37. TestComponents
  38. TestParent
  39. TestSecurityDescriptor
  40. scriptHelper.testComplete
  41. if scriptHelper.statusOK then
  42. WScript.Echo "PASS"
  43. WScript.Quit 0
  44. else
  45. WScript.Echo "FAIL"
  46. WScript.Quit 1
  47. end if
  48. '****************************************************************
  49. '*
  50. '* TestPreamble
  51. '* ============
  52. '*
  53. '****************************************************************
  54. Sub TestPreamble
  55. on error resume next
  56. ' Try to create a new path object
  57. set path = CreateObject("WbemScripting.SWbemObjectPath")
  58. if err <> 0 then
  59. scriptHelper.writeErrorToLog err, "Failed to create SWbemObjectPath"
  60. else
  61. scriptHelper.writeToLog "Successful creation of SWbemObjectPath", 2
  62. end if
  63. ' Check the typename
  64. if typename(path) = "SWbemObjectPathEx" then
  65. scriptHelper.writeToLog "Object has correct type", 2
  66. else
  67. scriptHelper.writeErrorToLog , "Object has incorrect type:", typename(path)
  68. end if
  69. End Sub
  70. '****************************************************************
  71. '*
  72. '* TestServer
  73. '* ==========
  74. '*
  75. '* Test Server component
  76. '*
  77. '****************************************************************
  78. Sub TestServer
  79. on error resume next
  80. scriptHelper.writeToLog "", 2
  81. scriptHelper.writeToLog ">> TestServer", 2
  82. ' What is the default value of the server
  83. server = path.Server
  84. if err <> 0 then
  85. scriptHelper.writeErrorToLog err, "Failed to get Server"
  86. elseif server <> "" then
  87. scriptHelper.writeErrorToLog err, "Unexpected server value"
  88. else
  89. scriptHelper.writeToLog "Successful retrieval of Server", 2
  90. end if
  91. ' Try and set it
  92. path.Server = "erewhon"
  93. if err <> 0 then
  94. scriptHelper.writeErrorToLog err, "Failed to set Server"
  95. elseif path.Server <> "erewhon" then
  96. scriptHelper.writeErrorToLog err, "Unexpected server value"
  97. else
  98. scriptHelper.writeToLog "Successful set of Server:[" & path.Server & "]", 2
  99. end if
  100. scriptHelper.writeToLog "<< TestServer", 2
  101. scriptHelper.writeToLog "", 2
  102. End Sub
  103. '****************************************************************
  104. '*
  105. '* TestNamespace
  106. '* =============
  107. '*
  108. '* Test Namespace component
  109. '*
  110. '****************************************************************
  111. Sub TestNamespace
  112. on error resume next
  113. scriptHelper.writeToLog "", 2
  114. scriptHelper.writeToLog ">> TestNamespace", 2
  115. ' What is the default value of the namespace
  116. namespace = path.Namespace
  117. if err <> 0 then
  118. scriptHelper.writeErrorToLog err, "Failed to get Namespace"
  119. elseif namespace <> "" then
  120. scriptHelper.writeErrorToLog err, "Unexpected namespace value"
  121. else
  122. scriptHelper.writeToLog "Successful retrieval of Namespace", 2
  123. end if
  124. ' Try and set it
  125. path.Namespace = "root\cimv2"
  126. if err <> 0 then
  127. scriptHelper.writeErrorToLog err, "Failed to set Namespace"
  128. elseif path.Namespace <> "root\cimv2" then
  129. scriptHelper.writeErrorToLog err, "Unexpected namespace value"
  130. else
  131. scriptHelper.writeToLog "Successful set of Namespace:[" & path.Namespace & "]", 2
  132. end if
  133. scriptHelper.writeToLog "<< TestNamespace", 2
  134. scriptHelper.writeToLog "", 2
  135. End Sub
  136. '****************************************************************
  137. '*
  138. '* TestClass
  139. '* =========
  140. '*
  141. '* Test Class component
  142. '*
  143. '****************************************************************
  144. Sub TestClass
  145. on error resume next
  146. scriptHelper.writeToLog "", 2
  147. scriptHelper.writeToLog ">> TestClass", 2
  148. ' What is the default value of the class
  149. sClass = path.Class
  150. if err <> 0 then
  151. scriptHelper.writeErrorToLog err, "Failed to get Class"
  152. elseif sClass <> "" then
  153. scriptHelper.writeErrorToLog err, "Unexpected class value"
  154. else
  155. scriptHelper.writeToLog "Successful retrieval of Class", 2
  156. end if
  157. ' Try and set it
  158. path.Class = "rocco"
  159. if err <> 0 then
  160. scriptHelper.writeErrorToLog err, "Failed to set Class"
  161. elseif path.Class <> "rocco" then
  162. scriptHelper.writeErrorToLog err, "Unexpected Class value"
  163. else
  164. scriptHelper.writeToLog "Successful set of Class:[" & path.Class & "]", 2
  165. end if
  166. scriptHelper.writeToLog "<< TestClass", 2
  167. scriptHelper.writeToLog "", 2
  168. End Sub
  169. '****************************************************************
  170. '*
  171. '* TestIsClass
  172. '* ============
  173. '*
  174. '* Test SetIsClass component
  175. '*
  176. '****************************************************************
  177. Sub TestIsClass
  178. on error resume next
  179. scriptHelper.writeToLog "", 2
  180. scriptHelper.writeToLog ">> TestIsClass", 2
  181. ' Set an non-class path
  182. path.Path = "\\flatland\root\shapes"
  183. if Not(path.IsClass) then
  184. scriptHelper.writeToLog "Non-Class successfully detected", 2
  185. else
  186. scriptHelper.writeErrorToLog err, "Unexpected IsClass value"
  187. end if
  188. ' Set the class value
  189. path.Class = "orphee"
  190. if path.IsClass then
  191. scriptHelper.writeToLog "Class successfully detected", 2
  192. else
  193. scriptHelper.writeErrorToLog err, "Unexpected IsClass value"
  194. end if
  195. ' Try and set as a singleton
  196. path.SetAsSingleton
  197. if err <> 0 then
  198. scriptHelper.writeErrorToLog err, "Failed to set as singleton"
  199. elseif path.IsClass then
  200. scriptHelper.writeErrorToLog , "Incorrectly marked as class"
  201. elseif Not(path.IsSingleton) then
  202. scriptHelper.writeErrorToLog , "Incorrectly marked as not a singleton"
  203. elseif path.Relpath <> "orphee=@" then
  204. scriptHelper.writeErrorToLog err, "Unexpected relpath value"
  205. else
  206. scriptHelper.writeToLog "Successful set as singleton:[" & path.Path & "]", 2
  207. end if
  208. ' Set back to a class
  209. path.SetAsClass
  210. if err <> 0 then
  211. scriptHelper.writeErrorToLog err, "Failed to set as class"
  212. elseif Not(path.IsClass) then
  213. scriptHelper.writeErrorToLog , "Incorrectly marked as not a class"
  214. elseif path.IsSingleton then
  215. scriptHelper.writeErrorToLog , "Incorrectly marked as a singleton"
  216. elseif path.Relpath <> "orphee" then
  217. scriptHelper.writeErrorToLog err, "Unexpected relpath value"
  218. else
  219. scriptHelper.writeToLog "Successful set as class:[" & path.Path & "]", 2
  220. end if
  221. ' Set as an instance
  222. path.RelPath = "orphee=1"
  223. if err <> 0 then
  224. scriptHelper.writeErrorToLog err, "Failed to set relpath"
  225. elseif path.IsClass then
  226. scriptHelper.writeErrorToLog , "Incorrectly marked as a class"
  227. elseif path.IsSingleton then
  228. scriptHelper.writeErrorToLog , "Incorrectly marked as a singleton"
  229. elseif path.Relpath <> "orphee=1" then
  230. scriptHelper.writeErrorToLog err, "Unexpected relpath value :[" & path.Relpath & "]"
  231. else
  232. scriptHelper.writeToLog "Successful set as instance:[" & path.Path & "]", 2
  233. end if
  234. scriptHelper.writeToLog "<< TestIsClass", 2
  235. scriptHelper.writeToLog "", 2
  236. End Sub
  237. '****************************************************************
  238. '*
  239. '* TestKeys
  240. '* ========
  241. '*
  242. '* Test SetKeys component
  243. '*
  244. '****************************************************************
  245. Sub TestKeys
  246. on error resume next
  247. scriptHelper.writeToLog "", 2
  248. scriptHelper.writeToLog ">> TestKeys", 2
  249. path.Path = "\\.\root\default:orphee"
  250. ' What is the default value of the keys
  251. set keys = path.Keys
  252. if err <> 0 then
  253. scriptHelper.writeErrorToLog err, "Failed to get Keys"
  254. elseif Keys.Count <> 0 then
  255. scriptHelper.writeErrorToLog err, "Unexpected keys"
  256. else
  257. scriptHelper.writeToLog "Successful retrieval of keys", 2
  258. end if
  259. ' Set as an instance
  260. path.Path = "\\.\root\default:orphee.Name='Jean'"
  261. if err <> 0 then
  262. scriptHelper.writeErrorToLog err, "Failed to set relpath"
  263. elseif path.Keys.Count <> 1 then
  264. scriptHelper.writeErrorToLog , "Incorrect number of keys: [" & path.Keys.Count & "] " & path.RelPath
  265. elseif path.Keys("Name") <> "Jean" then
  266. scriptHelper.writeErrorToLog , "Incorrect key value"
  267. else
  268. scriptHelper.writeToLog "Successful set of keys", 2
  269. end if
  270. ' Add a key
  271. path.Keys.Add "Surname", "Cocteau"
  272. if err <> 0 then
  273. scriptHelper.writeErrorToLog err, "Failed to add keys"
  274. elseif path.Keys.Count <> 2 then
  275. scriptHelper.writeErrorToLog , "Incorrect number of keys: [" & path.Keys.Count & "] " & path.RelPath
  276. elseif path.Keys("Surname") <> "Cocteau" then
  277. scriptHelper.writeErrorToLog , "Incorrect key value"
  278. else
  279. scriptHelper.writeToLog "Successful add of keys", 2
  280. end if
  281. ' Remove a key
  282. path.Keys.Remove "Name"
  283. if err <> 0 then
  284. scriptHelper.writeErrorToLog err, "Failed to remove keys"
  285. elseif path.Keys.Count <> 1 then
  286. scriptHelper.writeErrorToLog , "Incorrect number of keys: [" & path.Keys.Count & "] " & path.RelPath
  287. elseif path.Keys("Surname") <> "Cocteau" then
  288. scriptHelper.writeErrorToLog , "Incorrect key value"
  289. else
  290. scriptHelper.writeToLog "Successful remove of keys", 2
  291. end if
  292. scriptHelper.writeToLog "<< TestKeys", 2
  293. scriptHelper.writeToLog "", 2
  294. End Sub
  295. '****************************************************************
  296. '*
  297. '* TestRelpath
  298. '* ===========
  299. '*
  300. '* Test Relpath component
  301. '*
  302. '****************************************************************
  303. Sub TestRelPath
  304. on error resume next
  305. scriptHelper.writeToLog ">> TestRelpath", 2
  306. scriptHelper.writeToLog "", 2
  307. ' reset the path
  308. path.Path = ""
  309. if err <> 0 then
  310. scriptHelper.writeErrorToLog err, "Failed to clear path"
  311. else
  312. scriptHelper.writeToLog "Successful clear of path", 2
  313. end if
  314. ' What is the default value of the keys
  315. relpath = path.RelPath
  316. if err <> 0 then
  317. scriptHelper.writeErrorToLog err, "Failed to get RelPath"
  318. elseif RelPath <> "" then
  319. scriptHelper.writeErrorToLog , "Unexpected RelPath"
  320. else
  321. scriptHelper.writeToLog "Successful retrieval of RelPath", 2
  322. end if
  323. ' Try and set it
  324. path.RelPath = "orphee.Name=11"
  325. if err <> 0 then
  326. scriptHelper.writeErrorToLog err, "Failed to set Relpath"
  327. elseif path.RelPath <> "orphee.Name=11" then
  328. scriptHelper.writeErrorToLog , "Unexpected RelPath value:[" & path.RelPath & "]"
  329. else
  330. scriptHelper.writeToLog "Successful set of RelPath:[" & path.RelPath & "]", 2
  331. end if
  332. scriptHelper.writeToLog "<< TestRelpath", 2
  333. scriptHelper.writeToLog "", 2
  334. End Sub
  335. '****************************************************************
  336. '*
  337. '* TestPath
  338. '* ========
  339. '*
  340. '* Test Path component
  341. '*
  342. '****************************************************************
  343. Sub TestPath
  344. on error resume next
  345. End Sub
  346. '****************************************************************
  347. '*
  348. '* TestDisplayName
  349. '* ===============
  350. '*
  351. '* Test DisplayName component
  352. '*
  353. '****************************************************************
  354. Sub TestDisplayName
  355. on error resume next
  356. End Sub
  357. '****************************************************************
  358. '*
  359. '* TestSingleton
  360. '* =============
  361. '*
  362. '* Test Singleton
  363. '*
  364. '****************************************************************
  365. Sub TestSingleton
  366. on error resume next
  367. End Sub
  368. '****************************************************************
  369. '*
  370. '* TestSecurity
  371. '* ============
  372. '*
  373. '* Test Security
  374. '*
  375. '****************************************************************
  376. Sub TestSecurity
  377. on error resume next
  378. End Sub
  379. '****************************************************************
  380. '*
  381. '* TestLocale
  382. '* ==========
  383. '*
  384. '* Test Locale
  385. '*
  386. '****************************************************************
  387. Sub TestLocale
  388. on error resume next
  389. End Sub
  390. '****************************************************************
  391. '*
  392. '* TestAuthority
  393. '* ==========
  394. '*
  395. '* Test Authority
  396. '*
  397. '****************************************************************
  398. Sub TestAuthority
  399. on error resume next
  400. End Sub
  401. '****************************************************************
  402. '*
  403. '* TestComponents
  404. '* ==============
  405. '*
  406. '* Test Components
  407. '*
  408. '****************************************************************
  409. Sub TestComponents
  410. on error resume next
  411. End Sub
  412. '****************************************************************
  413. '*
  414. '* TestParent
  415. '* ==========
  416. '*
  417. '* Test Parent
  418. '*
  419. '****************************************************************
  420. Sub TestParent
  421. on error resume next
  422. End Sub
  423. '****************************************************************
  424. '*
  425. '* TestSecurityDescriptor
  426. '* ======================
  427. '*
  428. '* Test SD
  429. '*
  430. '****************************************************************
  431. Sub TestSecurityDescriptor
  432. on error resume next
  433. End Sub
  434. </script>
  435. </job>