1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="i18n_XTransliteration" script:language="StarBasic">
4*b1cdbd2cSJim Jagielski
5*b1cdbd2cSJim Jagielski
6*b1cdbd2cSJim Jagielski'*************************************************************************
7*b1cdbd2cSJim Jagielski'
8*b1cdbd2cSJim Jagielski'  Licensed to the Apache Software Foundation (ASF) under one
9*b1cdbd2cSJim Jagielski'  or more contributor license agreements.  See the NOTICE file
10*b1cdbd2cSJim Jagielski'  distributed with this work for additional information
11*b1cdbd2cSJim Jagielski'  regarding copyright ownership.  The ASF licenses this file
12*b1cdbd2cSJim Jagielski'  to you under the Apache License, Version 2.0 (the
13*b1cdbd2cSJim Jagielski'  "License"); you may not use this file except in compliance
14*b1cdbd2cSJim Jagielski'  with the License.  You may obtain a copy of the License at
15*b1cdbd2cSJim Jagielski'
16*b1cdbd2cSJim Jagielski'    http://www.apache.org/licenses/LICENSE-2.0
17*b1cdbd2cSJim Jagielski'
18*b1cdbd2cSJim Jagielski'  Unless required by applicable law or agreed to in writing,
19*b1cdbd2cSJim Jagielski'  software distributed under the License is distributed on an
20*b1cdbd2cSJim Jagielski'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*b1cdbd2cSJim Jagielski'  KIND, either express or implied.  See the License for the
22*b1cdbd2cSJim Jagielski'  specific language governing permissions and limitations
23*b1cdbd2cSJim Jagielski'  under the License.
24*b1cdbd2cSJim Jagielski'
25*b1cdbd2cSJim Jagielski'*************************************************************************
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski'*************************************************************************
32*b1cdbd2cSJim Jagielski' This Interface/Service test depends on the following GLOBAL variables,
33*b1cdbd2cSJim Jagielski' which must be specified in the object creation:
34*b1cdbd2cSJim Jagielski
35*b1cdbd2cSJim Jagielski'     - Global oLocale As Object
36*b1cdbd2cSJim Jagielski
37*b1cdbd2cSJim Jagielski'*************************************************************************
38*b1cdbd2cSJim Jagielski
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim Jagielski
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski
43*b1cdbd2cSJim JagielskiSub RunTest()
44*b1cdbd2cSJim Jagielski
45*b1cdbd2cSJim Jagielski'*************************************************************************
46*b1cdbd2cSJim Jagielski' INTERFACE:
47*b1cdbd2cSJim Jagielski' com.sun.star.i18n.XTransliteration
48*b1cdbd2cSJim Jagielski'*************************************************************************
49*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl
50*b1cdbd2cSJim Jagielski    Dim bOK As Boolean
51*b1cdbd2cSJim Jagielski    Dim availableModules As Variant
52*b1cdbd2cSJim Jagielski    Dim _string As String
53*b1cdbd2cSJim Jagielski    Dim i As Integer
54*b1cdbd2cSJim Jagielski
55*b1cdbd2cSJim Jagielski
56*b1cdbd2cSJim Jagielski    Test.StartMethod("getAvailableModules()")
57*b1cdbd2cSJim Jagielski    bOK = true
58*b1cdbd2cSJim Jagielski    availableModules = oObj.getAvailableModules(oLocale, com.sun.star.i18n.TransliterationModules.UPPERCASE_LOWERCASE)
59*b1cdbd2cSJim Jagielski    _string = ""
60*b1cdbd2cSJim Jagielski    for i = 0 to ubound(availableModules)
61*b1cdbd2cSJim Jagielski        _string = _string + availableModules(i) + "; "
62*b1cdbd2cSJim Jagielski    next i
63*b1cdbd2cSJim Jagielski    Out.Log("AvailableModules: " + _string)
64*b1cdbd2cSJim Jagielski    bOK = bOK AND _string &lt;&gt; ""
65*b1cdbd2cSJim Jagielski    Test.MethodTested("getAvailableModules()", bOK)
66*b1cdbd2cSJim Jagielski
67*b1cdbd2cSJim Jagielski    Test.StartMethod("loadModuleByImplName()")
68*b1cdbd2cSJim Jagielski    bOK = true
69*b1cdbd2cSJim Jagielski    oObj.loadModuleByImplName("LOWERCASE_UPPERCASE", oLocale)
70*b1cdbd2cSJim Jagielski    Dim module_name As String
71*b1cdbd2cSJim Jagielski    module_name = oObj.getName()
72*b1cdbd2cSJim Jagielski    out.log("getName return: " + module_name)
73*b1cdbd2cSJim Jagielski    bOK = module_name = "lower_to_upper(generic)"
74*b1cdbd2cSJim Jagielski    Test.MethodTested("loadModuleByImplName()", bOK)
75*b1cdbd2cSJim Jagielski
76*b1cdbd2cSJim Jagielski    Test.StartMethod("getName()")
77*b1cdbd2cSJim Jagielski    bOK = true
78*b1cdbd2cSJim Jagielski    Out.Log("Module name is " + oObj.getName())
79*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.getName() &lt;&gt; ""
80*b1cdbd2cSJim Jagielski    Test.MethodTested("getName()", bOK)
81*b1cdbd2cSJim Jagielski
82*b1cdbd2cSJim Jagielski    Test.StartMethod("getType()")
83*b1cdbd2cSJim Jagielski    bOK = true
84*b1cdbd2cSJim Jagielski    Out.Log("Type is " + oObj.getType())
85*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.getType() = 1 ' for UPPERCASE_LOWERCASE it is ONE_TO_ONE
86*b1cdbd2cSJim Jagielski    Test.MethodTested("getType()", bOK)
87*b1cdbd2cSJim Jagielski
88*b1cdbd2cSJim Jagielski    Test.StartMethod("loadModule()")
89*b1cdbd2cSJim Jagielski    bOK = true
90*b1cdbd2cSJim Jagielski    oObj.loadModule(com.sun.star.i18n.TransliterationModules.LOWERCASE_UPPERCASE, oLocale)
91*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.getType = com.sun.star.i18n.TransliterationType.ONE_TO_ONE
92*b1cdbd2cSJim Jagielski    Test.MethodTested("loadModule()", bOK)
93*b1cdbd2cSJim Jagielski
94*b1cdbd2cSJim Jagielski    Test.StartMethod("loadModulesByImplNames()")
95*b1cdbd2cSJim Jagielski    bOK = true
96*b1cdbd2cSJim Jagielski    Dim Names(0) As String
97*b1cdbd2cSJim Jagielski    Names(0) = "UPPERCASE_LOWERCASE"
98*b1cdbd2cSJim Jagielski    oObj.loadModulesByImplNames(Names(), oLocale)
99*b1cdbd2cSJim Jagielski    module_name = oObj.getName()
100*b1cdbd2cSJim Jagielski    out.log("getName return: " + module_name)
101*b1cdbd2cSJim Jagielski    bOK = module_name = "upper_to_lower(generic)"
102*b1cdbd2cSJim Jagielski    Test.MethodTested("loadModulesByImplNames()", bOK)
103*b1cdbd2cSJim Jagielski
104*b1cdbd2cSJim Jagielski    Test.StartMethod("loadModuleNew()")
105*b1cdbd2cSJim Jagielski    bOK = true
106*b1cdbd2cSJim Jagielski    Dim ModulesNew(0) As Variant
107*b1cdbd2cSJim Jagielski    ModulesNew(0) = com.sun.star.i18n.TransliterationModulesNew.LOWERCASE_UPPERCASE
108*b1cdbd2cSJim Jagielski    oObj.loadModuleNew(ModulesNew(), oLocale)
109*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.getType = com.sun.star.i18n.TransliterationType.ONE_TO_ONE
110*b1cdbd2cSJim Jagielski    Test.MethodTested("loadModuleNew()", bOK)
111*b1cdbd2cSJim Jagielski
112*b1cdbd2cSJim Jagielski    Test.StartMethod("transliterate()")
113*b1cdbd2cSJim Jagielski    Dim offset() As Variant
114*b1cdbd2cSJim Jagielski    bOK = true
115*b1cdbd2cSJim Jagielski    Out.Log("LOWERCASE_UPPERCASE-transliterate part of string 'AaBbCc'")
116*b1cdbd2cSJim Jagielski    _string = oObj.transliterate("AaBbCc", 1, 4, offset())
117*b1cdbd2cSJim Jagielski    Out.Log("Result of transliteration: " + _string)
118*b1cdbd2cSJim Jagielski    bOK = bOK AND "ABBC" = _string
119*b1cdbd2cSJim Jagielski    bOK = bOK AND ubound(offset()) = 3
120*b1cdbd2cSJim Jagielski    for i = 0 to ubound(offset())
121*b1cdbd2cSJim Jagielski        bOK = bOK AND offset(i) = i + 1
122*b1cdbd2cSJim Jagielski    next i
123*b1cdbd2cSJim Jagielski    Test.MethodTested("transliterate()", bOK)
124*b1cdbd2cSJim Jagielski
125*b1cdbd2cSJim Jagielski    Test.StartMethod("equals()")
126*b1cdbd2cSJim Jagielski    bOK = true
127*b1cdbd2cSJim Jagielski    Dim Match1 As Variant, Match2 As Variant
128*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.equals("This is an example string to be transliterate", 2, 20, Match1, _
129*b1cdbd2cSJim Jagielski                              "IS IS AN EXAMPLE STR", 0, 20, Match2)
130*b1cdbd2cSJim Jagielski    Test.MethodTested("equals()", bOK)
131*b1cdbd2cSJim Jagielski
132*b1cdbd2cSJim Jagielski    Test.StartMethod("folding()")
133*b1cdbd2cSJim Jagielski    bOK = true
134*b1cdbd2cSJim Jagielski    _string = oObj.folding("AaBbCc", 1, 4, offset())
135*b1cdbd2cSJim Jagielski    Out.Log("Result of folding: " + _string)
136*b1cdbd2cSJim Jagielski    bOK = bOK AND "ABBC" = _string
137*b1cdbd2cSJim Jagielski    bOK = bOK AND ubound(offset()) = 3
138*b1cdbd2cSJim Jagielski    for i = 0 to ubound(offset())
139*b1cdbd2cSJim Jagielski        bOK = bOK AND offset(i) = i + 1
140*b1cdbd2cSJim Jagielski    next i
141*b1cdbd2cSJim Jagielski    Test.MethodTested("folding()", bOK)
142*b1cdbd2cSJim Jagielski
143*b1cdbd2cSJim Jagielski    Test.StartMethod("transliterateRange()")
144*b1cdbd2cSJim Jagielski    Dim Result As Variant
145*b1cdbd2cSJim Jagielski    bOK = true
146*b1cdbd2cSJim Jagielski    oObj.loadModule(com.sun.star.i18n.TransliterationModules.IGNORE_CASE, _Locale)
147*b1cdbd2cSJim Jagielski    Result = oObj.transliterateRange("a", "c")
148*b1cdbd2cSJim Jagielski    for i = 0 to ubound(Result)
149*b1cdbd2cSJim Jagielski        Out.Log(Result(i))
150*b1cdbd2cSJim Jagielski    next i
151*b1cdbd2cSJim Jagielski    bOK = bOK AND ubound(Result()) = 3 AND _
152*b1cdbd2cSJim Jagielski        ((Result(0) = "a" AND Result(1) = "c" AND Result(2) = "A" AND Result(3) = "C" ) OR _
153*b1cdbd2cSJim Jagielski         (Result(0) = "A" AND Result(1) = "C" AND Result(2) = "a" AND Result(3) = "c" ))
154*b1cdbd2cSJim Jagielski    Test.MethodTested("transliterateRange()", bOK)
155*b1cdbd2cSJim Jagielski
156*b1cdbd2cSJim Jagielski    Test.StartMethod("compareString()")
157*b1cdbd2cSJim Jagielski    oObj.loadModule(com.sun.star.i18n.TransliterationModules.LOWERCASE_UPPERCASE, _Locale)
158*b1cdbd2cSJim Jagielski    bOK = true
159*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("", "", 0)
160*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("a", "", 1)
161*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("a", "a", 0)
162*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("A", "a", 1)
163*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("b", "a", 1)
164*b1cdbd2cSJim Jagielski    bOK = bOK AND testString(chr(10), chr(10), 0)
165*b1cdbd2cSJim Jagielski    bOK = bOK AND testString(chr(10), chr(9), 1)
166*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("aaa", "aaa", 0)
167*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("aaA", "aaa", 1)
168*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("aaa", "aa", 1)
169*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("ab", "aaa", 1)
170*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("aba", "aa", 1)
171*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("aaa" + chr(10) + chr(9) + "a", "aaa" + chr(10) + chr(9) + "a", 0)
172*b1cdbd2cSJim Jagielski    bOK = bOK AND testString("aaa" + chr(9) + chr(10) + "b", "aaa" + chr(9) + chr(10) + "a", 1)
173*b1cdbd2cSJim Jagielski    Test.MethodTested("compareString()", bOK)
174*b1cdbd2cSJim Jagielski
175*b1cdbd2cSJim Jagielski    Test.StartMethod("compareSubstring()")
176*b1cdbd2cSJim Jagielski    bOK = true
177*b1cdbd2cSJim Jagielski    ' substrings below must be equal
178*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("", 0, 0, "", 0, 0, 0)
179*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("aa", 1, 0, "", 0, 0, 0)
180*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("aa", 1, 0, "aa", 2, 0, 0)
181*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("a", 0, 1, "a", 0, 1, 0)
182*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("ab", 0, 2, "ab", 0, 2, 0)
183*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("abc", 1, 2, "abc", 1, 2, 0)
184*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("abcdef", 0, 3, "123abc", 3, 3, 0)
185*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("abcdef", 1, 1, "123abc", 4, 1, 0)
186*b1cdbd2cSJim Jagielski
187*b1cdbd2cSJim Jagielski    ' substrings below must NOT be equal
188*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("a", 0, 1, "a", 0, 0, 1)
189*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("aaa", 1, 1, "", 0, 0, 1)
190*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("bbb", 2, 1, "aaa", 2, 1, 1)
191*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("abc", 0, 3, "abc", 0, 2, 1)
192*b1cdbd2cSJim Jagielski    bOK = bOK AND testSubstring("bbc", 1, 2, "bbc", 0, 2, 1)
193*b1cdbd2cSJim Jagielski
194*b1cdbd2cSJim Jagielski    Test.MethodTested("compareSubstring()", bOK)
195*b1cdbd2cSJim JagielskiExit Sub
196*b1cdbd2cSJim JagielskiErrHndl:
197*b1cdbd2cSJim Jagielski    Test.Exception()
198*b1cdbd2cSJim Jagielski    bOK = false
199*b1cdbd2cSJim Jagielski    resume next
200*b1cdbd2cSJim JagielskiEnd Sub
201*b1cdbd2cSJim Jagielski
202*b1cdbd2cSJim JagielskiFunction testString(str1 As String, str2 As String, expRes As Integer) As Boolean
203*b1cdbd2cSJim Jagielski    if expRes = 0 then
204*b1cdbd2cSJim Jagielski        testString = testStringCommon(str1, str2, expRes, false)
205*b1cdbd2cSJim Jagielski    else
206*b1cdbd2cSJim Jagielski        testString = testStringCommon(str1, str2, expRes, true)
207*b1cdbd2cSJim Jagielski    end if
208*b1cdbd2cSJim JagielskiEnd Function
209*b1cdbd2cSJim Jagielski
210*b1cdbd2cSJim JagielskiFunction testStringCommon(str1 As String, str2 As String, expRes As Integer, testReverse As Boolean) As Boolean
211*b1cdbd2cSJim Jagielski        Dim res As Integer
212*b1cdbd2cSJim Jagielski
213*b1cdbd2cSJim Jagielski        testStringCommon = true
214*b1cdbd2cSJim Jagielski
215*b1cdbd2cSJim Jagielski        res = -666
216*b1cdbd2cSJim Jagielski
217*b1cdbd2cSJim Jagielski        res = oObj.compareString(str1, str2)
218*b1cdbd2cSJim Jagielski
219*b1cdbd2cSJim Jagielski        if res = expRes then
220*b1cdbd2cSJim Jagielski            Out.Log("Comparing of '" + str1 + "' and '" + str2 + "' OK" )
221*b1cdbd2cSJim Jagielski        else
222*b1cdbd2cSJim Jagielski            Out.Log("Comparing of '" + str1 + "' and '" + str2 + _
223*b1cdbd2cSJim Jagielski                "' FAILED; return: " + res + ", expected: " + expRes)
224*b1cdbd2cSJim Jagielski            testStringCommon = false
225*b1cdbd2cSJim Jagielski        end if
226*b1cdbd2cSJim Jagielski
227*b1cdbd2cSJim Jagielski        if NOT testReverse then
228*b1cdbd2cSJim Jagielski            Exit Function
229*b1cdbd2cSJim Jagielski        end if
230*b1cdbd2cSJim Jagielski
231*b1cdbd2cSJim Jagielski        res = -666
232*b1cdbd2cSJim Jagielski
233*b1cdbd2cSJim Jagielski        res = oObj.compareString(str2, str1)
234*b1cdbd2cSJim Jagielski
235*b1cdbd2cSJim Jagielski        if res = -expRes then
236*b1cdbd2cSJim Jagielski            Out.Log("Comparing of '" + str2 + "' and '" + str1 + "' OK" )
237*b1cdbd2cSJim Jagielski        else
238*b1cdbd2cSJim Jagielski            Out.Log("Comparing of '" + str2 + "' and '" + str1 + _
239*b1cdbd2cSJim Jagielski                "' FAILED; return: " + res + ", expected: " + -expRes)
240*b1cdbd2cSJim Jagielski            testStringCommon = false
241*b1cdbd2cSJim Jagielski        end if
242*b1cdbd2cSJim JagielskiEnd Function
243*b1cdbd2cSJim Jagielski
244*b1cdbd2cSJim JagielskiFunction testSubstring(str1 As String, p1 As Integer, len1 As Integer, _
245*b1cdbd2cSJim Jagielski        str2 As String, p2 As Integer, len2 As Integer, expRes As Integer) As Boolean
246*b1cdbd2cSJim Jagielski
247*b1cdbd2cSJim Jagielski        testSubstring = true
248*b1cdbd2cSJim Jagielski
249*b1cdbd2cSJim Jagielski        Dim res As Integer
250*b1cdbd2cSJim Jagielski        res = -666
251*b1cdbd2cSJim Jagielski
252*b1cdbd2cSJim Jagielski        res = oObj.compareSubstring(str1, p1, len1, str2, p2, len2)
253*b1cdbd2cSJim Jagielski
254*b1cdbd2cSJim Jagielski        if res &lt;&gt; expRes then
255*b1cdbd2cSJim Jagielski            Out.Log("Comparing FAILED; return: " + res + ", expected: " + expRes + " ")
256*b1cdbd2cSJim Jagielski            testSubstring = false
257*b1cdbd2cSJim Jagielski        else
258*b1cdbd2cSJim Jagielski            Out.Log("Comparing OK : ")
259*b1cdbd2cSJim Jagielski        end if
260*b1cdbd2cSJim Jagielski        Out.Log("('" + str1 + "', " + p1 + ", " + len1 + ", '" + _
261*b1cdbd2cSJim Jagielski            str2 + "', " + p2 + ", " + len2 + ")")
262*b1cdbd2cSJim Jagielski
263*b1cdbd2cSJim Jagielski        res = -666
264*b1cdbd2cSJim Jagielski
265*b1cdbd2cSJim Jagielski        res = oObj.compareSubstring(str2, p2, len2, str1, p1, len1)
266*b1cdbd2cSJim Jagielski
267*b1cdbd2cSJim Jagielski        if res &lt;&gt; -expRes then
268*b1cdbd2cSJim Jagielski            Out.Log("Comparing FAILED; return: " + res + ", expected: " + _
269*b1cdbd2cSJim Jagielski                -expRes  + " ")
270*b1cdbd2cSJim Jagielski            testSubstring = false
271*b1cdbd2cSJim Jagielski        else
272*b1cdbd2cSJim Jagielski            Out.Log("Comparing OK :")
273*b1cdbd2cSJim Jagielski        end if
274*b1cdbd2cSJim Jagielski        Out.Log("('" + str2 + "', " + p2 + ", " + len2 + ", '" + _
275*b1cdbd2cSJim Jagielski            str1 + "', " + p1 + ", " + len1 + ")")
276*b1cdbd2cSJim JagielskiEnd Function
277*b1cdbd2cSJim Jagielski</script:module>
278