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.

518 lines
17 KiB

  1. FUNCTION fCheckLocale (ByVal strLine, iLcid)
  2. iNewLCID = Util.ISOToLocaleID(strLine)
  3. if iNewLCID <> iLcid then
  4. strEcho = "Error - Locale " & strLine & " not LCID " & iLcid
  5. wscript.Echo strEcho
  6. strEcho = " mapped LCID is " & iNewLCID
  7. wscript.Echo strEcho
  8. fCheckLocale = 1
  9. else
  10. strNewName = Util.LocaleIDToISO( iLcid )
  11. strCmpLine = UCASE(strLine)
  12. if strNewName <> strCmpLine then
  13. ' The looked-up name did not match. It might be one of several
  14. ' special cases
  15. if strNewName = LEFT(strCmpLine, 2) or strNewName = LEFT(strCmpLine, 5) then
  16. ' Might be part of a longer Accept-Language string, or
  17. ' just matched the primary language part
  18. fCheckLocale = 0
  19. elseif strNewName = Right(strCmpLine, 2) then
  20. ' Might be part of a longer Accept-Language string, or
  21. ' preceeded by spaces
  22. fCheckLocale = 0
  23. elseif iLcid = -1 then
  24. ' Unrecognized name, like 'IY' or 'YI'
  25. fCheckLocale = 0
  26. elseif (iLcid = 1037 or iLcid = 1057) and LEFT(strLine,1) = "i" then
  27. ' special case for alias names 'in' and 'iw'
  28. fCheckLocale = 0
  29. elseif iLcid = 1050 and strLine = "SR" then
  30. ' Serbian = Croatian ???
  31. fCheckLocale = 0
  32. else
  33. strEcho = "Error - Locale " & strLine & " not " & strNewName
  34. wscript.Echo strEcho
  35. strEcho = "&nbsp;&nbsp;LCID is " & iLcid
  36. wscript.Echo strEcho
  37. fCheckLocale = 1
  38. end if
  39. else
  40. fCheckLocale = 0
  41. end if
  42. end if
  43. END FUNCTION
  44. FUNCTION fCheckSupports ( eFlag, fShouldSupport, ByVal strFlagName )
  45. if fShouldSupport then
  46. if RecordSet.Supports( eFlag ) then
  47. fCheckSupports = 0
  48. else
  49. strEcho = "Error - Recordset should support " & strFlagName & ", but does not."
  50. wscript.Echo strEcho
  51. fCheckSupports = 1
  52. end if
  53. else
  54. if RecordSet.Supports( eFlag ) <> fShouldSupport then
  55. strEcho = "Error - Recordset should support " & strFlagName & ", but does not."
  56. wscript.Echo strEcho
  57. fCheckSupports = 1
  58. else
  59. fCheckSupports = 0
  60. end if
  61. end if
  62. END FUNCTION
  63. FUNCTION fCompareObjects (Q1, Q2)
  64. cErrors = 0
  65. if Q1.Query <> Q2.Query then
  66. wscript.Echo "Error - Query property mismatch"
  67. cErrors = cErrors + 1
  68. end if
  69. if Q1.SortBy <> Q2.SortBy then
  70. wscript.Echo "Error - SortBy property mismatch"
  71. cErrors = cErrors + 1
  72. end if
  73. ' if Q1.GroupBy <> Q2.GroupBy then
  74. ' wscript.Echo "Error - GroupBy property mismatch"
  75. ' cErrors = cErrors + 1
  76. ' end if
  77. if Q1.Catalog <> Q2.Catalog then
  78. wscript.Echo "Error - Catalog property mismatch"
  79. cErrors = cErrors + 1
  80. end if
  81. if Q1.MaxRecords <> Q2.MaxRecords then
  82. wscript.Echo "Error - MaxRecords property mismatch"
  83. cErrors = cErrors + 1
  84. end if
  85. if Q1.AllowEnumeration <> Q2.AllowEnumeration then
  86. wscript.Echo "Error - AllowEnumeration property mismatch"
  87. cErrors = cErrors + 1
  88. end if
  89. if cErrors <> 0 then
  90. fCompareObjects = 1
  91. else
  92. fCompareObjects = 0
  93. end if
  94. END FUNCTION
  95. '--------------------------------------------------------------------
  96. '
  97. ' ADO constants for VBScript
  98. '
  99. '--------------------------------------------------------------------
  100. '---- CursorTypeEnum Values ----
  101. Const adOpenForwardOnly = 0
  102. Const adOpenKeyset = 1
  103. Const adOpenDynamic = 2
  104. Const adOpenStatic = 3
  105. '---- CursorOptionEnum Values ----
  106. Const adHoldRecords = &H00000100
  107. Const adMovePrevious = &H00000200
  108. Const adAddNew = &H01000400
  109. Const adDelete = &H01000800
  110. Const adUpdate = &H01008000
  111. Const adBookmark = &H00002000
  112. Const adApproxPosition = &H00004000
  113. Const adUpdateBatch = &H00010000
  114. Const adResync = &H00020000
  115. '--------------------------------------------
  116. '
  117. ' String constants used in script
  118. '
  119. '--------------------------------------------
  120. strPASS = " PASS"
  121. strFAIL = " FAIL"
  122. wscript.Echo "Test 1 -- null Query "
  123. ' Create a new query SSO
  124. Set Query = CreateObject("ixsso.Query")
  125. Query.Query = ""
  126. Query.Catalog = "web"
  127. Query.Columns = "path,size,attrib,rank,write"
  128. Query.MaxRecords = 150
  129. Query.SortBy = "rank[d]"
  130. ' Execute Query
  131. on error resume next
  132. Set RecordSet = Query.CreateRecordSet("nonsequential")
  133. on error goto 0
  134. if isobject( RecordSet ) then
  135. wscript.Echo "Error - CreateRecordSet failed, " & Err.Number & Err.Description
  136. wscript.Echo strFAIL
  137. set RecordSet = Nothing
  138. else
  139. wscript.Echo strPASS
  140. end if
  141. set Query = Nothing
  142. wscript.Echo "Test 2 -- null Catalog "
  143. ' Create a new query SSO
  144. Set Query = CreateObject("ixsso.Query")
  145. Query.Query = "ixsso and test"
  146. Query.Columns = "path,size,attrib,rank,write"
  147. Query.MaxRecords = 150
  148. Query.SortBy = "rank[d]"
  149. ' Execute Query
  150. on error resume next
  151. Set RecordSet = Query.CreateRecordSet("nonsequential")
  152. ErrNum = Hex( Err.Number ) & " "
  153. ErrDesc = Err.Description
  154. on error goto 0
  155. if isobject( RecordSet ) <> TRUE then
  156. wscript.Echo "Error - CreateRecordSet failed, " & ErrNum & ErrDesc
  157. wscript.Echo strFAIL
  158. else
  159. wscript.Echo strPASS
  160. end if
  161. set RecordSet = Nothing
  162. set Query = Nothing
  163. wscript.Echo "Test 3 -- Verify LocaleID handling "
  164. set Util=CreateObject("IXSSO.Util")
  165. cErrors = 0
  166. cErrors = cErrors + fCheckLocale( "BG", 1026 ) ' Bulgarian
  167. cErrors = cErrors + fCheckLocale( "ZH", 2052 ) ' Chinese
  168. cErrors = cErrors + fCheckLocale( "ZH-CN", 2052 ) ' Chinese-China
  169. cErrors = cErrors + fCheckLocale( "ZH-TW", 1028 ) ' Chinese-Taiwan
  170. cErrors = cErrors + fCheckLocale( "HR", 1050 ) ' Hungarian
  171. cErrors = cErrors + fCheckLocale( "CS", 1029 ) ' Czech
  172. cErrors = cErrors + fCheckLocale( "DA", 1030 ) ' Danish
  173. cErrors = cErrors + fCheckLocale( "NL", 1043 ) ' Dutch
  174. cErrors = cErrors + fCheckLocale( "EN", 1033 ) ' English
  175. cErrors = cErrors + fCheckLocale( "EN-GB", 2057 ) ' English-United Kingdom
  176. cErrors = cErrors + fCheckLocale( "EN-US", 1033 ) ' English-United States
  177. cErrors = cErrors + fCheckLocale( "FI", 1035 ) ' Finnish
  178. cErrors = cErrors + fCheckLocale( "FR", 1036 ) ' French
  179. cErrors = cErrors + fCheckLocale( "FR-CA", 3084 ) ' French-Canada
  180. cErrors = cErrors + fCheckLocale( "FR-FR", 1036 ) ' French-France
  181. cErrors = cErrors + fCheckLocale( "DE", 1031 ) ' German
  182. cErrors = cErrors + fCheckLocale( "EL", 1032 ) ' Greek
  183. cErrors = cErrors + fCheckLocale( "IS", 1039 ) ' Icelandic
  184. cErrors = cErrors + fCheckLocale( "IT", 1040 ) ' Italian
  185. cErrors = cErrors + fCheckLocale( "JA", 1041 ) ' Japanese
  186. cErrors = cErrors + fCheckLocale( "KO", 1042 ) ' Korean
  187. cErrors = cErrors + fCheckLocale( "NO", 1044 ) ' Norwegian
  188. cErrors = cErrors + fCheckLocale( "PL", 1045 ) ' Polish
  189. cErrors = cErrors + fCheckLocale( "PT", 1046 ) ' Portuguese
  190. cErrors = cErrors + fCheckLocale( "PT-BR", 1046 ) ' Portuguese-Brazil
  191. cErrors = cErrors + fCheckLocale( "RO", 1048 ) ' Romanian
  192. cErrors = cErrors + fCheckLocale( "RU", 1049 ) ' Russian
  193. cErrors = cErrors + fCheckLocale( "SK", 1051 ) ' Slovak
  194. cErrors = cErrors + fCheckLocale( "SL", 1060 ) ' Slovenian
  195. cErrors = cErrors + fCheckLocale( "ES", 1034 ) ' Spanish
  196. cErrors = cErrors + fCheckLocale( "ES-ES", 1034 ) ' Spanish-Spain
  197. cErrors = cErrors + fCheckLocale( "SV", 1053 ) ' Sweedish
  198. cErrors = cErrors + fCheckLocale( "TR", 1055 ) ' Turkish
  199. cErrors = cErrors + fCheckLocale( "AF", 1078 ) ' Afrikaans
  200. cErrors = cErrors + fCheckLocale( "AR", 1025 ) ' Arabic
  201. cErrors = cErrors + fCheckLocale( "EU", 1069 ) ' Basque
  202. cErrors = cErrors + fCheckLocale( "BE", 1059 ) ' Byelorussian
  203. cErrors = cErrors + fCheckLocale( "CA", 1027 ) ' Catalan
  204. cErrors = cErrors + fCheckLocale( "HR", 1050 ) ' Croatian
  205. cErrors = cErrors + fCheckLocale( "ET", 1061 ) ' Estonian
  206. cErrors = cErrors + fCheckLocale( "FO", 1080 ) ' Faeronese
  207. cErrors = cErrors + fCheckLocale( "EL", 1032 ) ' Greek
  208. cErrors = cErrors + fCheckLocale( "HE", 1037 ) ' Hebrew
  209. cErrors = cErrors + fCheckLocale( "iw", 1037 ) ' Hebrew
  210. cErrors = cErrors + fCheckLocale( "ID", 1057 ) ' Indonesian
  211. cErrors = cErrors + fCheckLocale( "in", 1057 ) ' Indonesian
  212. cErrors = cErrors + fCheckLocale( "LV", 1062 ) ' Latvian
  213. cErrors = cErrors + fCheckLocale( "LT", 1063 ) ' Lithuanian
  214. cErrors = cErrors + fCheckLocale( "SR", 1050 ) ' Serbian
  215. cErrors = cErrors + fCheckLocale( "TH", 1054 ) ' Thai
  216. cErrors = cErrors + fCheckLocale( "UK", 1058 ) ' Ukrainian
  217. cErrors = cErrors + fCheckLocale( "VI", 1066 ) ' Vietnamese
  218. cErrors = cErrors + fCheckLocale( "NEUTRAL", 0 )
  219. ' The following are language or country codes we don't recognize
  220. cErrors = cErrors + fCheckLocale( "PT-PT", 1046 ) ' Portuguese-Portugal
  221. cErrors = cErrors + fCheckLocale( "ES-CO", 1034 ) ' Spanish-Columbia
  222. cErrors = cErrors + fCheckLocale( "FR-BE", 1036 ) ' French-Belgium
  223. cErrors = cErrors + fCheckLocale( "IU", -1 ) ' Inuktitut (Eskimo)
  224. cErrors = cErrors + fCheckLocale( "YI", -1 ) ' Yiddish
  225. ' Check some language combinations, leading and trailing spaces, etc.
  226. cErrors = cErrors + fCheckLocale( " EN", 1033 )
  227. cErrors = cErrors + fCheckLocale( "EN ", 1033 )
  228. cErrors = cErrors + fCheckLocale( "EN-US", 1033 )
  229. cErrors = cErrors + fCheckLocale( "en-us", &H409 )
  230. cErrors = cErrors + fCheckLocale( "en-gb", &H809 )
  231. cErrors = cErrors + fCheckLocale( "PT-PT,PT", 1046 )
  232. ' We ignore quality
  233. cErrors = cErrors + fCheckLocale( "fr-ca;q=0.3,fr;q=0.7,en", 3084 )
  234. ' We don't do IANA extensions or private use tags
  235. cErrors = cErrors + fCheckLocale( "x.klingon, i.cherokee, en", 1033 )
  236. if 0 = cErrors then
  237. wscript.Echo strPASS
  238. else
  239. wscript.Echo strFAIL
  240. end if
  241. set Query = Nothing
  242. wscript.Echo "Test 4 -- Verify recordset Supports and CursorType "
  243. '--------------------------- Create and Execute the Query ---------------------
  244. '---- Create a new query SSO
  245. Set Query = CreateObject("ixsso.Query")
  246. Query.Query = "HTML"
  247. Query.CiScope = "/"
  248. Query.CiFlags = "DEEP"
  249. Query.Columns = "vpath"
  250. Query.MaxRecords = 150
  251. Query.SortBy = "vpath[a]"
  252. '--------- Execute Query
  253. Set RecordSet = Query.CreateRecordSet("nonsequential")
  254. cErrors1 = 0
  255. if RecordSet.CursorType = adOpenForwardOnly then
  256. wscript.Echo "Error - non-sequential recordset's cursor type is forward-only"
  257. cErrors1 = cErrors1 + 1
  258. end if
  259. ' cErrors1 = cErrors1 + fCheckSupports( adHoldRecords, TRUE, "adHoldRecords" )
  260. cErrors1 = cErrors1 + fCheckSupports( adMovePrevious, TRUE, "adMovePrevious" )
  261. cErrors1 = cErrors1 + fCheckSupports( adAddNew, FALSE, "adAddNew" )
  262. cErrors1 = cErrors1 + fCheckSupports( adDelete, FALSE, "adDelete" )
  263. cErrors1 = cErrors1 + fCheckSupports( adUpdate, FALSE, "adUpdate" )
  264. cErrors1 = cErrors1 + fCheckSupports( adBookmark, TRUE, "adBookmark" )
  265. cErrors1 = cErrors1 + fCheckSupports( adApproxPosition, TRUE, "adApproxPosition" )
  266. cErrors1 = cErrors1 + fCheckSupports( adUpdateBatch, FALSE, "adUpdateBatch" )
  267. cErrors1 = cErrors1 + fCheckSupports( adResync, FALSE, "adResync" )
  268. Set Query = nothing
  269. Set Recordset = nothing
  270. '---- Create a new query SSO
  271. Set Query = CreateObject("ixsso.Query")
  272. Query.Query = "HTML"
  273. Query.CiScope = "/"
  274. Query.CiFlags = "DEEP"
  275. Query.Columns = "vpath"
  276. Query.MaxRecords = 150
  277. Query.SortBy = "vpath[a]"
  278. '--------- Execute Query
  279. Set RecordSet = Query.CreateRecordSet("sequential")
  280. cErrors2 = 0
  281. if RecordSet.CursorType <> adOpenForwardOnly then
  282. strEcho = "Error - sequential recordset's cursor type is not forward-only(" & RecordSet.CursorType & ")"
  283. wscript.Echo strEcho
  284. cErrors2 = cErrors2 + 1
  285. end if
  286. cErrors2 = cErrors2 + fCheckSupports( adHoldRecords, FALSE, "adHoldRecords" )
  287. cErrors2 = cErrors2 + fCheckSupports( adMovePrevious, FALSE, "adMovePrevious" )
  288. cErrors2 = cErrors2 + fCheckSupports( adAddNew, FALSE, "adAddNew" )
  289. cErrors2 = cErrors2 + fCheckSupports( adDelete, FALSE, "adDelete" )
  290. cErrors2 = cErrors2 + fCheckSupports( adUpdate, FALSE, "adUpdate" )
  291. cErrors2 = cErrors2 + fCheckSupports( adBookmark, FALSE, "adBookmark" )
  292. cErrors2 = cErrors2 + fCheckSupports( adApproxPosition, FALSE, "adApproxPosition" )
  293. cErrors2 = cErrors2 + fCheckSupports( adUpdateBatch, FALSE, "adUpdateBatch" )
  294. cErrors2 = cErrors2 + fCheckSupports( adResync, FALSE, "adResync" )
  295. Set Query = nothing
  296. Set Recordset = nothing
  297. if 0 = cErrors1+cErrors2 then
  298. wscript.Echo strPASS
  299. else
  300. wscript.Echo strFAIL & cErrors1 & cErrors2
  301. end if
  302. wscript.Echo "Test 5 -- Test SetQueryFromURL and QueryToURL methods "
  303. '---- Create a new query object
  304. Set Q1 = CreateObject("ixsso.Query")
  305. Q1.Query = "HTML"
  306. Q1.CiScope = "/"
  307. Q1.CiFlags = "DEEP"
  308. Q1.Columns = "vpath"
  309. Q1.MaxRecords = 150
  310. Q1.SortBy = "vpath[a]"
  311. Q1.Catalog = "query://localhost/web"
  312. ' wscript.Echo "QueryString is: " & Q1.QueryToURL
  313. '---- Create a second query object and set its state from the first object
  314. Set Q2 = CreateObject("ixsso.Query")
  315. Q2.SetQueryFromURL( Q1.QueryToURL )
  316. cErrors1 = fCompareObjects( Q1, Q2 )
  317. Q1.Reset
  318. Q2.Reset
  319. Q1.Query = "Full text query & ( c1 q1 ) & ( c2 o2 q2 ) & ( q3b )"
  320. Q2.SetQueryFromURL("qu=Full+text+query&c1=c1&q3=q3a&q1=q1&c2=c2&q2=q2&o2=o2&q3=q3b&c4=col4&o4=oper4")
  321. Q1.SortBy = "path,size,rank[d]"
  322. Q2.SetQueryFromURL("so=path&so=size&sd=rank")
  323. Q1.AllowEnumeration=TRUE
  324. Q1.OptimizeFor="performance"
  325. Q2.SetQueryFromURL("ae=1&op=x")
  326. cErrors2 = fCompareObjects( Q1, Q2 )
  327. Q1.Reset
  328. Q1.SetQueryFromURL( Q2.QueryToURL )
  329. cErrors3 = fCompareObjects( Q1, Q2 )
  330. ' regression test for NTRAID 221992
  331. Q1.Reset
  332. Q2.Reset
  333. QueryString = "geld" + chr(225) + " verzekeringen"
  334. Q1.SetQueryFromURL( "qu=" + QueryString )
  335. Q2.Query = QueryString
  336. cErrors4 = fCompareObjects( Q1, Q2 )
  337. QueryString = "geld" + chr(225) + "+verz%u0065keringen"
  338. Q1.SetQueryFromURL( "qu=" + QueryString )
  339. cErrors4 = cErrors4 + fCompareObjects( Q1, Q2 )
  340. set Q1 = nothing
  341. set Q2 = nothing
  342. if 0 = cErrors1+cErrors2+cErrors3+cErrors4 then
  343. wscript.Echo strPASS
  344. else
  345. wscript.Echo strFAIL
  346. end if
  347. wscript.Echo "Test 6 -- Test multi-scoped queries "
  348. set Util=CreateObject("IXSSO.Util")
  349. set Q=CreateObject("IXSSO.Query")
  350. Q.Columns = "Filename, Rank, vpath, Size, Write"
  351. Q.Query = "#filename *.*"
  352. Q.SortBy = "rank[d]"
  353. Util.AddScopeToQuery Q, "E:\nt", "SHALLOW"
  354. Q.OptimizeFor = "recall"
  355. Q.AllowEnumeration = TRUE
  356. Q.MaxRecords = 20000
  357. set RS=Q.CreateRecordSet( "nonsequential" )
  358. RecordCount1 = RS.RecordCount
  359. if RecordCount1 = 0 then
  360. wscript.Echo "Warning - no records returned from first query"
  361. end if
  362. RS.close
  363. Set RS = Nothing
  364. Q.Reset
  365. Q.Columns = "Filename, Rank, vpath, Size, Write"
  366. Q.Query = "#filename *.*"
  367. Q.SortBy = "rank[d]"
  368. Util.AddScopeToQuery Q, "e:\nt\private\query"
  369. Q.OptimizeFor = "recall"
  370. Q.AllowEnumeration = TRUE
  371. Q.MaxRecords = 20000
  372. set RS=Q.CreateRecordSet( "nonsequential" )
  373. RecordCount2 = RS.RecordCount
  374. if RecordCount2 = 0 then
  375. wscript.Echo "Warning - no records returned from second query"
  376. end if
  377. RS.close
  378. Set RS = Nothing
  379. Q.Reset
  380. Q.Columns = "Filename, Rank, vpath, Size, Write"
  381. Q.Query = "#filename *.*"
  382. Q.SortBy = "rank[d]"
  383. Util.AddScopeToQuery Q, "E:\nt", "SHALLOW"
  384. Util.AddScopeToQuery Q, "e:\nt\private\query"
  385. Q.OptimizeFor = "recall"
  386. Q.AllowEnumeration = TRUE
  387. Q.MaxRecords = 40000
  388. set RS=Q.CreateRecordSet( "nonsequential" )
  389. RecordCount3 = RS.RecordCount
  390. if RecordCount3 <> RecordCount1+RecordCount2 then
  391. wscript.Echo "Error - third query is not union of first and second queries"
  392. wscript.Echo "RecordCount1 = " & RecordCount1
  393. wscript.Echo "RecordCount2 = " & RecordCount2
  394. wscript.Echo "RecordCount3 = " & RecordCount3
  395. end if
  396. RS.close
  397. Set RS = Nothing
  398. Set Q = Nothing
  399. Set Util = Nothing
  400. if RecordCount3 = RecordCount1+RecordCount2 and RecordCount3 <> 0 then
  401. wscript.Echo strPASS
  402. else
  403. wscript.Echo strFAIL
  404. end if
  405. wscript.Echo "Test 7 -- Test TruncateToWhitespace "
  406. set Util=CreateObject("IXSSO.Util")
  407. strTest = "123 abc" & chr(10) & "!@#" & chr(11) & "({["
  408. cErrors = 0
  409. for i = 1 to 19
  410. cchExp = (int ((i+1)/4)) * 4 - 1
  411. if i <= 3 then
  412. cchExp = i
  413. end if
  414. if Util.TruncateToWhitespace(strTest, i) <> Left(strTest, cchExp) then
  415. strEcho = "Error - trunc " & CStr(i)
  416. wscript.Echo strEcho
  417. strEcho " " & Util.TruncateToWhitespace(strTest, i)
  418. wscript.Echo strEcho
  419. cErrors = cErrors + 1
  420. end if
  421. next
  422. Set Util = Nothing
  423. if cErrors = 0 then
  424. wscript.Echo strPASS
  425. else
  426. wscript.Echo strFAIL
  427. end if
  428. ' <!-- TODO:
  429. ' Add read-only MaxRecords test from ixtst7.asp
  430. ' Encapsulate 'On Error' handling inside subroutines
  431. ' -->
  432. wscript.Echo "Done!"