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.

320 lines
9.5 KiB

  1. '*********************************************************************
  2. '
  3. ' datetime.vbs
  4. '
  5. ' Purpose: test datetime functionality
  6. '
  7. ' Parameters: none
  8. '
  9. ' Returns: 0 - success
  10. ' 1 - failure
  11. '
  12. '*********************************************************************
  13. on error resume next
  14. set scriptHelper = CreateObject("WMIScriptHelper.WSC")
  15. scriptHelper.logFile = "c:\temp\datetime.txt"
  16. scriptHelper.loggingLevel = 3
  17. scriptHelper.testName = "DATETIME"
  18. scriptHelper.testStart
  19. '*****************************
  20. ' Create a datetime object
  21. '*****************************
  22. set datetime = CreateObject("WbemScripting.SWbemDatetime")
  23. if err <> 0 then
  24. scriptHelper.writeErrorToLog err, "Failed to create datetime"
  25. else
  26. scriptHelper.writeToLog "Datetime created correctly", 2
  27. end if
  28. '*****************************
  29. ' Create a Variant date
  30. '*****************************
  31. myDate = CDate ("January 20 11:56:32")
  32. '*****************************
  33. ' Test 1 - Set as local date
  34. '*****************************
  35. datetime.SetVarDate (myDate)
  36. if datetime.Value <> "20000120195632.000000-480" then
  37. scriptHelper.writeErrorToLog null, "Incorrect DMTF value"
  38. else
  39. scriptHelper.writeToLog "DMTF value reported correctly", 2
  40. end if
  41. if datetime.Year <> 2000 then
  42. scriptHelper.writeErrorToLog null, "Incorrect Year value"
  43. else
  44. scriptHelper.writeToLog "Year value reported correctly", 2
  45. end if
  46. if datetime.YearSpecified <> true then
  47. scriptHelper.writeErrorToLog null, "Incorrect YearSpecified value"
  48. else
  49. scriptHelper.writeToLog "YearSpecified value reported correctly", 2
  50. end if
  51. if datetime.Month <> 1 then
  52. scriptHelper.writeErrorToLog null, "Incorrect Month value"
  53. else
  54. scriptHelper.writeToLog "Month value reported correctly", 2
  55. end if
  56. if datetime.MonthSpecified <> true then
  57. scriptHelper.writeErrorToLog null, "Incorrect MonthSpecified value"
  58. else
  59. scriptHelper.writeToLog "MonthSpecified value reported correctly", 2
  60. end if
  61. if datetime.Day <> 20 then
  62. scriptHelper.writeErrorToLog null, "Incorrect Day value"
  63. else
  64. scriptHelper.writeToLog "Day value reported correctly", 2
  65. end if
  66. if datetime.DaySpecified <> true then
  67. scriptHelper.writeErrorToLog null, "Incorrect DaySpecified value"
  68. else
  69. scriptHelper.writeToLog "DaySpecified value reported correctly", 2
  70. end if
  71. if datetime.Hours <> 19 then
  72. scriptHelper.writeErrorToLog null, "Incorrect Hours value"
  73. else
  74. scriptHelper.writeToLog "Hours value reported correctly", 2
  75. end if
  76. if datetime.HoursSpecified <> true then
  77. scriptHelper.writeErrorToLog null, "Incorrect HoursSpecified value"
  78. else
  79. scriptHelper.writeToLog "HoursSpecified value reported correctly", 2
  80. end if
  81. if datetime.Minutes <> 56 then
  82. scriptHelper.writeErrorToLog null, "Incorrect Minutes value"
  83. else
  84. scriptHelper.writeToLog "Minutes value reported correctly", 2
  85. end if
  86. if datetime.MinutesSpecified <> true then
  87. scriptHelper.writeErrorToLog null, "Incorrect MinutesSpecified value"
  88. else
  89. scriptHelper.writeToLog "MinutesSpecified value reported correctly", 2
  90. end if
  91. if datetime.Seconds <> 32 then
  92. scriptHelper.writeErrorToLog null, "Incorrect Seconds value"
  93. else
  94. scriptHelper.writeToLog "Seconds value reported correctly", 2
  95. end if
  96. if datetime.SecondsSpecified <> true then
  97. scriptHelper.writeErrorToLog null, "Incorrect SecondsSpecified value"
  98. else
  99. scriptHelper.writeToLog "SecondsSpecified value reported correctly", 2
  100. end if
  101. if datetime.MicroSeconds <> 0 then
  102. scriptHelper.writeErrorToLog null, "Incorrect Microseconds value"
  103. else
  104. scriptHelper.writeToLog "Microseconds value reported correctly", 2
  105. end if
  106. if datetime.MicroSecondsSpecified <> true then
  107. scriptHelper.writeErrorToLog null, "Incorrect MicrosecondsSpecified value"
  108. else
  109. scriptHelper.writeToLog "MicrosecondsSpecified value reported correctly", 2
  110. end if
  111. if datetime.UTC <> -480 then
  112. scriptHelper.writeErrorToLog null, "Incorrect UTC value"
  113. else
  114. scriptHelper.writeToLog "UTC value reported correctly", 2
  115. end if
  116. if datetime.UTCSpecified <> true then
  117. scriptHelper.writeErrorToLog null, "Incorrect UTCSpecified value"
  118. else
  119. scriptHelper.writeToLog "UTCSpecified value reported correctly", 2
  120. end if
  121. if datetime.IsInterval <> false then
  122. scriptHelper.writeErrorToLog null, "Incorrect IsInterval value"
  123. else
  124. scriptHelper.writeToLog "IsInterval value reported correctly", 2
  125. end if
  126. varDate = datetime.GetVarDate
  127. if err <> 0 then
  128. scriptHelper.writeErrorToLog err, "Failed to get VarDate"
  129. else
  130. scriptHelper.writeToLog "Vardate retrieved correctly: " & VarDate, 2
  131. end if
  132. '*****************************
  133. 'Test Interval strings
  134. '*****************************
  135. dateTime.IsInterval = true
  136. dateTime.Day = 100
  137. dateTime.Hours = 1
  138. dateTime.Minutes = 0
  139. dateTime.Seconds = 3
  140. if datetime.Value <> "00000100010003.000000:000" then
  141. scriptHelper.writeErrorToLog null, "Failed to get correct interval value"
  142. else
  143. scriptHelper.writeToLog "Interval value retrieved correctly", 2
  144. end if
  145. '*****************************
  146. 'Test wildcard strings
  147. '*****************************
  148. datetime.Value = "19980416******.000000+***"
  149. if datetime.Value <> "19980416******.000000+***" then
  150. scriptHelper.writeErrorToLog null, "Failed to get correct wildcard value"
  151. else
  152. scriptHelper.writeToLog "Wildcard value retrieved correctly", 2
  153. end if
  154. '*****************************
  155. 'Test invalid strings
  156. '*****************************
  157. datetime.Value = "199*0416******.000000+***"
  158. if err <> 0 then
  159. scriptHelper.writeToLog "Invalid value correctly rejected:" & err.Description, 2
  160. err.clear
  161. else
  162. scriptHelper.writeErrorToLog null, "Invalid value erroneously accepted"
  163. end if
  164. '*****************************
  165. 'Test setting of individual properties
  166. '*****************************
  167. set datetime = CreateObject("WbemScripting.SWbemDatetime")
  168. if err <> 0 then
  169. scriptHelper.writeErrorToLog err, "Failed to create datetime"
  170. else
  171. scriptHelper.writeToLog "Datetime created correctly", 2
  172. end if
  173. datetime.Year = 2000
  174. datetime.Month = 5
  175. datetime.Day = 8
  176. datetime.Hours = 14
  177. datetime.Minutes = 20
  178. datetime.Seconds = 32
  179. datetime.Microseconds = 123456
  180. datetime.UTC = 320
  181. if datetime.Value <> "20000508142032.123456+320" then
  182. scriptHelper.writeErrorToLog null, "Failed to get correct property-set value"
  183. else
  184. scriptHelper.writeToLog "Property-set value retrieved correctly", 2
  185. end if
  186. '*****************************
  187. 'Test effects of changing IsInterval property
  188. '*****************************
  189. datetime.IsInterval = true
  190. if datetime.Value <> "00000008142032.123456:000" then
  191. scriptHelper.writeErrorToLog null, "Failed to get correct interval value"
  192. else
  193. scriptHelper.writeToLog "Interval value retrieved correctly", 2
  194. end if
  195. datetime.Day = 99999999
  196. if datetime.Value <> "99999999142032.123456:000" then
  197. scriptHelper.writeErrorToLog null, "Failed to get correct interval value"
  198. else
  199. scriptHelper.writeToLog "Interval value retrieved correctly", 2
  200. end if
  201. datetime.IsInterval = false
  202. if datetime.Day <> 31 then
  203. scriptHelper.writeErrorToLog null, "Failed to get correct Day value"
  204. else
  205. scriptHelper.writeToLog "Day value retrieved correctly", 2
  206. end if
  207. datetime.IsInterval = true
  208. datetime.Day = 0
  209. if datetime.Value <> "00000000142032.123456:000" then
  210. scriptHelper.writeErrorToLog null, "Failed to get correct interval value"
  211. else
  212. scriptHelper.writeToLog "Interval value retrieved correctly", 2
  213. end if
  214. datetime.IsInterval = false
  215. if datetime.Day <> 1 then
  216. scriptHelper.writeErrorToLog null, "Failed to get correct Day value"
  217. else
  218. scriptHelper.writeToLog "Day value retrieved correctly", 2
  219. end if
  220. '*****************************
  221. 'Test conversion between local and non-local formats
  222. '*****************************
  223. dateTime.SetVarDate (CDate ("January 20 11:56:32"))
  224. if datetime.Value <> "20000120195632.000000-480" then
  225. scriptHelper.writeErrorToLog null, "Failed to get correct datetime value " & datetime.Value
  226. else
  227. scriptHelper.writeToLog "Datetime value retrieved correctly", 2
  228. end if
  229. if dateTime.GetVarDate () <> "1/20/2000 11:56:32 AM" then
  230. scriptHelper.writeErrorToLog null, "Failed to get correct local vardate value"
  231. else
  232. scriptHelper.writeToLog "Local vardate value retrieved correctly", 2
  233. end if
  234. if dateTime.GetVarDate (false) <> "1/20/2000 7:56:32 PM" then
  235. scriptHelper.writeErrorToLog null, "Failed to get correct non-local vardate value"
  236. else
  237. scriptHelper.writeToLog "Non-Local vardate value retrieved correctly", 2
  238. end if
  239. if dateTime.GetFileTime () <> "125928429920000000" then
  240. scriptHelper.writeErrorToLog null, "Failed to get correct local filetime value"
  241. else
  242. scriptHelper.writeToLog "Local filetime value retrieved correctly", 2
  243. end if
  244. if dateTime.GetFileTime (false) <> "125928717920000000" then
  245. scriptHelper.writeErrorToLog null, "Failed to get correct non-local filetime value"
  246. else
  247. scriptHelper.writeToLog "Non-Local filetime value retrieved correctly", 2
  248. end if
  249. '*************************************************
  250. 'Test invariance of filetime down to 1ms precision
  251. '*************************************************
  252. datetime.SetFileTime "126036951652031260"
  253. if datetime.GetFileTime <> "126036951652031260" then
  254. scriptHelper.writeErrorToLog null, "Failed to preserve filetime to 1ms precision"
  255. else
  256. scriptHelper.writeToLog "Filetime value preserved to 1ms precision correctly", 2
  257. end if
  258. scriptHelper.testComplete
  259. if scriptHelper.statusOK then
  260. WScript.Echo "PASS"
  261. WScript.Quit 0
  262. else
  263. WScript.Echo "FAIL"
  264. WScript.Quit 1
  265. end if