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_XTransliteration" 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'************************************************************************* 32' This Interface/Service test depends on the following GLOBAL variables, 33' which must be specified in the object creation: 34 35' - Global oLocale As Object 36 37'************************************************************************* 38 39 40 41 42 43Sub RunTest() 44 45'************************************************************************* 46' INTERFACE: 47' com.sun.star.i18n.XTransliteration 48'************************************************************************* 49On Error Goto ErrHndl 50 Dim bOK As Boolean 51 Dim availableModules As Variant 52 Dim _string As String 53 Dim i As Integer 54 55 56 Test.StartMethod("getAvailableModules()") 57 bOK = true 58 availableModules = oObj.getAvailableModules(oLocale, com.sun.star.i18n.TransliterationModules.UPPERCASE_LOWERCASE) 59 _string = "" 60 for i = 0 to ubound(availableModules) 61 _string = _string + availableModules(i) + "; " 62 next i 63 Out.Log("AvailableModules: " + _string) 64 bOK = bOK AND _string <> "" 65 Test.MethodTested("getAvailableModules()", bOK) 66 67 Test.StartMethod("loadModuleByImplName()") 68 bOK = true 69 oObj.loadModuleByImplName("LOWERCASE_UPPERCASE", oLocale) 70 Dim module_name As String 71 module_name = oObj.getName() 72 out.log("getName return: " + module_name) 73 bOK = module_name = "lower_to_upper(generic)" 74 Test.MethodTested("loadModuleByImplName()", bOK) 75 76 Test.StartMethod("getName()") 77 bOK = true 78 Out.Log("Module name is " + oObj.getName()) 79 bOK = bOK AND oObj.getName() <> "" 80 Test.MethodTested("getName()", bOK) 81 82 Test.StartMethod("getType()") 83 bOK = true 84 Out.Log("Type is " + oObj.getType()) 85 bOK = bOK AND oObj.getType() = 1 ' for UPPERCASE_LOWERCASE it is ONE_TO_ONE 86 Test.MethodTested("getType()", bOK) 87 88 Test.StartMethod("loadModule()") 89 bOK = true 90 oObj.loadModule(com.sun.star.i18n.TransliterationModules.LOWERCASE_UPPERCASE, oLocale) 91 bOK = bOK AND oObj.getType = com.sun.star.i18n.TransliterationType.ONE_TO_ONE 92 Test.MethodTested("loadModule()", bOK) 93 94 Test.StartMethod("loadModulesByImplNames()") 95 bOK = true 96 Dim Names(0) As String 97 Names(0) = "UPPERCASE_LOWERCASE" 98 oObj.loadModulesByImplNames(Names(), oLocale) 99 module_name = oObj.getName() 100 out.log("getName return: " + module_name) 101 bOK = module_name = "upper_to_lower(generic)" 102 Test.MethodTested("loadModulesByImplNames()", bOK) 103 104 Test.StartMethod("loadModuleNew()") 105 bOK = true 106 Dim ModulesNew(0) As Variant 107 ModulesNew(0) = com.sun.star.i18n.TransliterationModulesNew.LOWERCASE_UPPERCASE 108 oObj.loadModuleNew(ModulesNew(), oLocale) 109 bOK = bOK AND oObj.getType = com.sun.star.i18n.TransliterationType.ONE_TO_ONE 110 Test.MethodTested("loadModuleNew()", bOK) 111 112 Test.StartMethod("transliterate()") 113 Dim offset() As Variant 114 bOK = true 115 Out.Log("LOWERCASE_UPPERCASE-transliterate part of string 'AaBbCc'") 116 _string = oObj.transliterate("AaBbCc", 1, 4, offset()) 117 Out.Log("Result of transliteration: " + _string) 118 bOK = bOK AND "ABBC" = _string 119 bOK = bOK AND ubound(offset()) = 3 120 for i = 0 to ubound(offset()) 121 bOK = bOK AND offset(i) = i + 1 122 next i 123 Test.MethodTested("transliterate()", bOK) 124 125 Test.StartMethod("equals()") 126 bOK = true 127 Dim Match1 As Variant, Match2 As Variant 128 bOK = bOK AND oObj.equals("This is an example string to be transliterate", 2, 20, Match1, _ 129 "IS IS AN EXAMPLE STR", 0, 20, Match2) 130 Test.MethodTested("equals()", bOK) 131 132 Test.StartMethod("folding()") 133 bOK = true 134 _string = oObj.folding("AaBbCc", 1, 4, offset()) 135 Out.Log("Result of folding: " + _string) 136 bOK = bOK AND "ABBC" = _string 137 bOK = bOK AND ubound(offset()) = 3 138 for i = 0 to ubound(offset()) 139 bOK = bOK AND offset(i) = i + 1 140 next i 141 Test.MethodTested("folding()", bOK) 142 143 Test.StartMethod("transliterateRange()") 144 Dim Result As Variant 145 bOK = true 146 oObj.loadModule(com.sun.star.i18n.TransliterationModules.IGNORE_CASE, _Locale) 147 Result = oObj.transliterateRange("a", "c") 148 for i = 0 to ubound(Result) 149 Out.Log(Result(i)) 150 next i 151 bOK = bOK AND ubound(Result()) = 3 AND _ 152 ((Result(0) = "a" AND Result(1) = "c" AND Result(2) = "A" AND Result(3) = "C" ) OR _ 153 (Result(0) = "A" AND Result(1) = "C" AND Result(2) = "a" AND Result(3) = "c" )) 154 Test.MethodTested("transliterateRange()", bOK) 155 156 Test.StartMethod("compareString()") 157 oObj.loadModule(com.sun.star.i18n.TransliterationModules.LOWERCASE_UPPERCASE, _Locale) 158 bOK = true 159 bOK = bOK AND testString("", "", 0) 160 bOK = bOK AND testString("a", "", 1) 161 bOK = bOK AND testString("a", "a", 0) 162 bOK = bOK AND testString("A", "a", 1) 163 bOK = bOK AND testString("b", "a", 1) 164 bOK = bOK AND testString(chr(10), chr(10), 0) 165 bOK = bOK AND testString(chr(10), chr(9), 1) 166 bOK = bOK AND testString("aaa", "aaa", 0) 167 bOK = bOK AND testString("aaA", "aaa", 1) 168 bOK = bOK AND testString("aaa", "aa", 1) 169 bOK = bOK AND testString("ab", "aaa", 1) 170 bOK = bOK AND testString("aba", "aa", 1) 171 bOK = bOK AND testString("aaa" + chr(10) + chr(9) + "a", "aaa" + chr(10) + chr(9) + "a", 0) 172 bOK = bOK AND testString("aaa" + chr(9) + chr(10) + "b", "aaa" + chr(9) + chr(10) + "a", 1) 173 Test.MethodTested("compareString()", bOK) 174 175 Test.StartMethod("compareSubstring()") 176 bOK = true 177 ' substrings below must be equal 178 bOK = bOK AND testSubstring("", 0, 0, "", 0, 0, 0) 179 bOK = bOK AND testSubstring("aa", 1, 0, "", 0, 0, 0) 180 bOK = bOK AND testSubstring("aa", 1, 0, "aa", 2, 0, 0) 181 bOK = bOK AND testSubstring("a", 0, 1, "a", 0, 1, 0) 182 bOK = bOK AND testSubstring("ab", 0, 2, "ab", 0, 2, 0) 183 bOK = bOK AND testSubstring("abc", 1, 2, "abc", 1, 2, 0) 184 bOK = bOK AND testSubstring("abcdef", 0, 3, "123abc", 3, 3, 0) 185 bOK = bOK AND testSubstring("abcdef", 1, 1, "123abc", 4, 1, 0) 186 187 ' substrings below must NOT be equal 188 bOK = bOK AND testSubstring("a", 0, 1, "a", 0, 0, 1) 189 bOK = bOK AND testSubstring("aaa", 1, 1, "", 0, 0, 1) 190 bOK = bOK AND testSubstring("bbb", 2, 1, "aaa", 2, 1, 1) 191 bOK = bOK AND testSubstring("abc", 0, 3, "abc", 0, 2, 1) 192 bOK = bOK AND testSubstring("bbc", 1, 2, "bbc", 0, 2, 1) 193 194 Test.MethodTested("compareSubstring()", bOK) 195Exit Sub 196ErrHndl: 197 Test.Exception() 198 bOK = false 199 resume next 200End Sub 201 202Function testString(str1 As String, str2 As String, expRes As Integer) As Boolean 203 if expRes = 0 then 204 testString = testStringCommon(str1, str2, expRes, false) 205 else 206 testString = testStringCommon(str1, str2, expRes, true) 207 end if 208End Function 209 210Function testStringCommon(str1 As String, str2 As String, expRes As Integer, testReverse As Boolean) As Boolean 211 Dim res As Integer 212 213 testStringCommon = true 214 215 res = -666 216 217 res = oObj.compareString(str1, str2) 218 219 if res = expRes then 220 Out.Log("Comparing of '" + str1 + "' and '" + str2 + "' OK" ) 221 else 222 Out.Log("Comparing of '" + str1 + "' and '" + str2 + _ 223 "' FAILED; return: " + res + ", expected: " + expRes) 224 testStringCommon = false 225 end if 226 227 if NOT testReverse then 228 Exit Function 229 end if 230 231 res = -666 232 233 res = oObj.compareString(str2, str1) 234 235 if res = -expRes then 236 Out.Log("Comparing of '" + str2 + "' and '" + str1 + "' OK" ) 237 else 238 Out.Log("Comparing of '" + str2 + "' and '" + str1 + _ 239 "' FAILED; return: " + res + ", expected: " + -expRes) 240 testStringCommon = false 241 end if 242End Function 243 244Function testSubstring(str1 As String, p1 As Integer, len1 As Integer, _ 245 str2 As String, p2 As Integer, len2 As Integer, expRes As Integer) As Boolean 246 247 testSubstring = true 248 249 Dim res As Integer 250 res = -666 251 252 res = oObj.compareSubstring(str1, p1, len1, str2, p2, len2) 253 254 if res <> expRes then 255 Out.Log("Comparing FAILED; return: " + res + ", expected: " + expRes + " ") 256 testSubstring = false 257 else 258 Out.Log("Comparing OK : ") 259 end if 260 Out.Log("('" + str1 + "', " + p1 + ", " + len1 + ", '" + _ 261 str2 + "', " + p2 + ", " + len2 + ")") 262 263 res = -666 264 265 res = oObj.compareSubstring(str2, p2, len2, str1, p1, len1) 266 267 if res <> -expRes then 268 Out.Log("Comparing FAILED; return: " + res + ", expected: " + _ 269 -expRes + " ") 270 testSubstring = false 271 else 272 Out.Log("Comparing OK :") 273 end if 274 Out.Log("('" + str2 + "', " + p2 + ", " + len2 + ", '" + _ 275 str1 + "', " + p1 + ", " + len1 + ")") 276End Function 277</script:module> 278