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