1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="i18n_XCollator" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' Licensed to the Apache Software Foundation (ASF) under one 9' or more contributor license agreements. See the NOTICE file 10' distributed with this work for additional information 11' regarding copyright ownership. The ASF licenses this file 12' to you under the Apache License, Version 2.0 (the 13' "License"); you may not use this file except in compliance 14' with the License. You may obtain a copy of the License at 15' 16' http://www.apache.org/licenses/LICENSE-2.0 17' 18' Unless required by applicable law or agreed to in writing, 19' software distributed under the License is distributed on an 20' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21' KIND, either express or implied. See the License for the 22' specific language governing permissions and limitations 23' under the License. 24' 25'************************************************************************* 26 27 28 29 30 31' Be sure that all variables are dimensioned: 32option explicit 33 34'************************************************************************* 35' This Interface/Service test depends on the following GLOBAL variables, 36' which must be specified in the object creation: 37 38' - Global oLocal As Object 39 40'************************************************************************* 41 42 43 44 45 46 47Sub RunTest() 48 49'************************************************************************* 50' INTERFACE: 51' com.sun.star.i18n.XCollator 52'************************************************************************* 53On Error Goto ErrHndl 54 Dim bOK As Boolean 55 Dim Algorithms As Variant 56 Dim options As Variant 57 58 Test.StartMethod("listCollatorAlgorithms()") 59 bOK = true 60 Algorithms = oObj.listCollatorAlgorithms(oLocale) 61 Out.Log("Found " + (ubound(Algorithms) + 1) + " algorithms.") 62 bOK = bOK AND ubound(Algorithms) >= 0 63 Test.MethodTested("listCollatorAlgorithms()", bOK) 64 65 Test.StartMethod("loadCollatorAlgorithm()") 66 bOK = true 67 options = com.sun.star.i18n.CollatorOptions.CollatorOptions_IGNORE_CASE 68 oObj.loadCollatorAlgorithm(Algorithms(0), oLocale, options) 69 bOK = bOK AND oObj.compareString("A", "a") = 0 70 oObj.loadCollatorAlgorithm(Algorithms(0), oLocale, 0) 71 bOK = bOK AND oObj.compareString("A", "a") <> 0 72 Test.MethodTested("loadCollatorAlgorithm()", bOK) 73 74 Test.StartMethod("loadDefaultCollator()") 75 bOK = true 76 oObj.loadDefaultCollator(oLocale, 0) 77 bOK = bOK AND oObj.compareString("A", "a") <> 0 78 oObj.loadDefaultCollator(oLocale, options) 79 bOK = bOK AND oObj.compareString("A", "a") = 0 80 Test.MethodTested("loadDefaultCollator()", bOK) 81 82 Test.StartMethod("listCollatorOptions()") 83 bOK = true 84 options = oObj.listCollatorOptions(Algorithms(0)) 85 Out.Log("Found " + (ubound(options) + 1) + " options.") 86 bOK = bOK AND ubound(options) >= 0 87 Test.MethodTested("listCollatorOptions()", bOK) 88 89 Test.StartMethod("compareSubstring()") 90 bOK = true 91 bOK = bOK AND oObj.compareSubstring("a", 0, 1, "B", 0, 1) = -1 92 bOK = bOK AND oObj.compareSubstring("A", 0, 1, "b", 0, 1) = -1 93 bOK = bOK AND oObj.compareSubstring("A", 0, 1, "a", 0, 1) = 0 94 Test.MethodTested("compareSubstring()", bOK) 95 96 Test.StartMethod("compareString()") 97 bOK = true 98 bOK = bOK AND oObj.compareString("a", "B") = -1 99 bOK = bOK AND oObj.compareString("A", "b") = -1 100 bOK = bOK AND oObj.compareString("A", "a") = 0 101 Test.MethodTested("compareString()", bOK) 102 103 Test.StartMethod("loadCollatorAlgorithmWithEndUserOption()") 104 bOK = true 105 Dim noOptions() As Integer 106 Dim optionsArray(0) As Integer 107 Dim ColAlgorithm As String 108 109 colAlgorithm = "alphanumeric" 110 Out.Log("Used collation algorithm: "+colAlgorithm) 111 optionsArray(0) = com.sun.star.i18n.CollatorOptions.CollatorOptions_IGNORE_CASE 112 oObj.loadCollatorAlgorithmWithEndUserOption(colAlgorithm, oLocale, noOptions()) 113 bOK = bOK AND oObj.compareString("A", "a") = 1 114 bOK = bOK AND oObj.compareString("a", "A") = -1 115 bOK = bOK AND oObj.compareString("a", "a") = 0 116 oObj.loadCollatorAlgorithmWithEndUserOption(colAlgorithm, oLocale, optionsArray()) 117 bOK = bOK AND oObj.compareString("A", "a") = 0 118 bOK = bOK AND oObj.compareString("a", "A") = 0 119 bOK = bOK AND oObj.compareString("a", "a") = 0 120 Test.MethodTested("loadCollatorAlgorithmWithEndUserOption()", bOK) 121 122Exit Sub 123ErrHndl: 124 Test.Exception() 125 bOK = false 126 resume next 127End Sub 128</script:module> 129