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' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9'
10' Copyright 2000, 2010 Oracle and/or its affiliates.
11'
12' OpenOffice.org - a multi-platform office productivity suite
13'
14' This file is part of OpenOffice.org.
15'
16' OpenOffice.org is free software: you can redistribute it and/or modify
17' it under the terms of the GNU Lesser General Public License version 3
18' only, as published by the Free Software Foundation.
19'
20' OpenOffice.org is distributed in the hope that it will be useful,
21' but WITHOUT ANY WARRANTY; without even the implied warranty of
22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23' GNU Lesser General Public License version 3 for more details
24' (a copy is included in the LICENSE file that accompanied this code).
25'
26' You should have received a copy of the GNU Lesser General Public License
27' version 3 along with OpenOffice.org.  If not, see
28' <http://www.openoffice.org/license.html>
29' for a copy of the LGPLv3 License.
30'
31'*************************************************************************
32*****
33'*************************************************************************
34
35
36
37'*************************************************************************
38' This Interface/Service test depends on the following GLOBAL variables,
39' which must be specified in the object creation:
40
41'     - Global oLocale As Object
42
43'*************************************************************************
44
45
46
47
48
49Sub RunTest()
50
51'*************************************************************************
52' INTERFACE:
53' com.sun.star.i18n.XTransliteration
54'*************************************************************************
55On Error Goto ErrHndl
56    Dim bOK As Boolean
57    Dim availableModules As Variant
58    Dim _string As String
59    Dim i As Integer
60
61
62    Test.StartMethod("getAvailableModules()")
63    bOK = true
64    availableModules = oObj.getAvailableModules(oLocale, com.sun.star.i18n.TransliterationModules.UPPERCASE_LOWERCASE)
65    _string = ""
66    for i = 0 to ubound(availableModules)
67        _string = _string + availableModules(i) + "; "
68    next i
69    Out.Log("AvailableModules: " + _string)
70    bOK = bOK AND _string &lt;&gt; ""
71    Test.MethodTested("getAvailableModules()", bOK)
72
73    Test.StartMethod("loadModuleByImplName()")
74    bOK = true
75    oObj.loadModuleByImplName("LOWERCASE_UPPERCASE", oLocale)
76    Dim module_name As String
77    module_name = oObj.getName()
78    out.log("getName return: " + module_name)
79    bOK = module_name = "lower_to_upper(generic)"
80    Test.MethodTested("loadModuleByImplName()", bOK)
81
82    Test.StartMethod("getName()")
83    bOK = true
84    Out.Log("Module name is " + oObj.getName())
85    bOK = bOK AND oObj.getName() &lt;&gt; ""
86    Test.MethodTested("getName()", bOK)
87
88    Test.StartMethod("getType()")
89    bOK = true
90    Out.Log("Type is " + oObj.getType())
91    bOK = bOK AND oObj.getType() = 1 ' for UPPERCASE_LOWERCASE it is ONE_TO_ONE
92    Test.MethodTested("getType()", bOK)
93
94    Test.StartMethod("loadModule()")
95    bOK = true
96    oObj.loadModule(com.sun.star.i18n.TransliterationModules.LOWERCASE_UPPERCASE, oLocale)
97    bOK = bOK AND oObj.getType = com.sun.star.i18n.TransliterationType.ONE_TO_ONE
98    Test.MethodTested("loadModule()", bOK)
99
100    Test.StartMethod("loadModulesByImplNames()")
101    bOK = true
102    Dim Names(0) As String
103    Names(0) = "UPPERCASE_LOWERCASE"
104    oObj.loadModulesByImplNames(Names(), oLocale)
105    module_name = oObj.getName()
106    out.log("getName return: " + module_name)
107    bOK = module_name = "upper_to_lower(generic)"
108    Test.MethodTested("loadModulesByImplNames()", bOK)
109
110    Test.StartMethod("loadModuleNew()")
111    bOK = true
112    Dim ModulesNew(0) As Variant
113    ModulesNew(0) = com.sun.star.i18n.TransliterationModulesNew.LOWERCASE_UPPERCASE
114    oObj.loadModuleNew(ModulesNew(), oLocale)
115    bOK = bOK AND oObj.getType = com.sun.star.i18n.TransliterationType.ONE_TO_ONE
116    Test.MethodTested("loadModuleNew()", bOK)
117
118    Test.StartMethod("transliterate()")
119    Dim offset() As Variant
120    bOK = true
121    Out.Log("LOWERCASE_UPPERCASE-transliterate part of string 'AaBbCc'")
122    _string = oObj.transliterate("AaBbCc", 1, 4, offset())
123    Out.Log("Result of transliteration: " + _string)
124    bOK = bOK AND "ABBC" = _string
125    bOK = bOK AND ubound(offset()) = 3
126    for i = 0 to ubound(offset())
127        bOK = bOK AND offset(i) = i + 1
128    next i
129    Test.MethodTested("transliterate()", bOK)
130
131    Test.StartMethod("equals()")
132    bOK = true
133    Dim Match1 As Variant, Match2 As Variant
134    bOK = bOK AND oObj.equals("This is an example string to be transliterate", 2, 20, Match1, _
135                              "IS IS AN EXAMPLE STR", 0, 20, Match2)
136    Test.MethodTested("equals()", bOK)
137
138    Test.StartMethod("folding()")
139    bOK = true
140    _string = oObj.folding("AaBbCc", 1, 4, offset())
141    Out.Log("Result of folding: " + _string)
142    bOK = bOK AND "ABBC" = _string
143    bOK = bOK AND ubound(offset()) = 3
144    for i = 0 to ubound(offset())
145        bOK = bOK AND offset(i) = i + 1
146    next i
147    Test.MethodTested("folding()", bOK)
148
149    Test.StartMethod("transliterateRange()")
150    Dim Result As Variant
151    bOK = true
152    oObj.loadModule(com.sun.star.i18n.TransliterationModules.IGNORE_CASE, _Locale)
153    Result = oObj.transliterateRange("a", "c")
154    for i = 0 to ubound(Result)
155        Out.Log(Result(i))
156    next i
157    bOK = bOK AND ubound(Result()) = 3 AND _
158        ((Result(0) = "a" AND Result(1) = "c" AND Result(2) = "A" AND Result(3) = "C" ) OR _
159         (Result(0) = "A" AND Result(1) = "C" AND Result(2) = "a" AND Result(3) = "c" ))
160    Test.MethodTested("transliterateRange()", bOK)
161
162    Test.StartMethod("compareString()")
163    oObj.loadModule(com.sun.star.i18n.TransliterationModules.LOWERCASE_UPPERCASE, _Locale)
164    bOK = true
165    bOK = bOK AND testString("", "", 0)
166    bOK = bOK AND testString("a", "", 1)
167    bOK = bOK AND testString("a", "a", 0)
168    bOK = bOK AND testString("A", "a", 1)
169    bOK = bOK AND testString("b", "a", 1)
170    bOK = bOK AND testString(chr(10), chr(10), 0)
171    bOK = bOK AND testString(chr(10), chr(9), 1)
172    bOK = bOK AND testString("aaa", "aaa", 0)
173    bOK = bOK AND testString("aaA", "aaa", 1)
174    bOK = bOK AND testString("aaa", "aa", 1)
175    bOK = bOK AND testString("ab", "aaa", 1)
176    bOK = bOK AND testString("aba", "aa", 1)
177    bOK = bOK AND testString("aaa" + chr(10) + chr(9) + "a", "aaa" + chr(10) + chr(9) + "a", 0)
178    bOK = bOK AND testString("aaa" + chr(9) + chr(10) + "b", "aaa" + chr(9) + chr(10) + "a", 1)
179    Test.MethodTested("compareString()", bOK)
180
181    Test.StartMethod("compareSubstring()")
182    bOK = true
183    ' substrings below must be equal
184    bOK = bOK AND testSubstring("", 0, 0, "", 0, 0, 0)
185    bOK = bOK AND testSubstring("aa", 1, 0, "", 0, 0, 0)
186    bOK = bOK AND testSubstring("aa", 1, 0, "aa", 2, 0, 0)
187    bOK = bOK AND testSubstring("a", 0, 1, "a", 0, 1, 0)
188    bOK = bOK AND testSubstring("ab", 0, 2, "ab", 0, 2, 0)
189    bOK = bOK AND testSubstring("abc", 1, 2, "abc", 1, 2, 0)
190    bOK = bOK AND testSubstring("abcdef", 0, 3, "123abc", 3, 3, 0)
191    bOK = bOK AND testSubstring("abcdef", 1, 1, "123abc", 4, 1, 0)
192
193    ' substrings below must NOT be equal
194    bOK = bOK AND testSubstring("a", 0, 1, "a", 0, 0, 1)
195    bOK = bOK AND testSubstring("aaa", 1, 1, "", 0, 0, 1)
196    bOK = bOK AND testSubstring("bbb", 2, 1, "aaa", 2, 1, 1)
197    bOK = bOK AND testSubstring("abc", 0, 3, "abc", 0, 2, 1)
198    bOK = bOK AND testSubstring("bbc", 1, 2, "bbc", 0, 2, 1)
199
200    Test.MethodTested("compareSubstring()", bOK)
201Exit Sub
202ErrHndl:
203    Test.Exception()
204    bOK = false
205    resume next
206End Sub
207
208Function testString(str1 As String, str2 As String, expRes As Integer) As Boolean
209    if expRes = 0 then
210        testString = testStringCommon(str1, str2, expRes, false)
211    else
212        testString = testStringCommon(str1, str2, expRes, true)
213    end if
214End Function
215
216Function testStringCommon(str1 As String, str2 As String, expRes As Integer, testReverse As Boolean) As Boolean
217        Dim res As Integer
218
219        testStringCommon = true
220
221        res = -666
222
223        res = oObj.compareString(str1, str2)
224
225        if res = expRes then
226            Out.Log("Comparing of '" + str1 + "' and '" + str2 + "' OK" )
227        else
228            Out.Log("Comparing of '" + str1 + "' and '" + str2 + _
229                "' FAILED; return: " + res + ", expected: " + expRes)
230            testStringCommon = false
231        end if
232
233        if NOT testReverse then
234            Exit Function
235        end if
236
237        res = -666
238
239        res = oObj.compareString(str2, str1)
240
241        if res = -expRes then
242            Out.Log("Comparing of '" + str2 + "' and '" + str1 + "' OK" )
243        else
244            Out.Log("Comparing of '" + str2 + "' and '" + str1 + _
245                "' FAILED; return: " + res + ", expected: " + -expRes)
246            testStringCommon = false
247        end if
248End Function
249
250Function testSubstring(str1 As String, p1 As Integer, len1 As Integer, _
251        str2 As String, p2 As Integer, len2 As Integer, expRes As Integer) As Boolean
252
253        testSubstring = true
254
255        Dim res As Integer
256        res = -666
257
258        res = oObj.compareSubstring(str1, p1, len1, str2, p2, len2)
259
260        if res &lt;&gt; expRes then
261            Out.Log("Comparing FAILED; return: " + res + ", expected: " + expRes + " ")
262            testSubstring = false
263        else
264            Out.Log("Comparing OK : ")
265        end if
266        Out.Log("('" + str1 + "', " + p1 + ", " + len1 + ", '" + _
267            str2 + "', " + p2 + ", " + len2 + ")")
268
269        res = -666
270
271        res = oObj.compareSubstring(str2, p2, len2, str1, p1, len1)
272
273        if res &lt;&gt; -expRes then
274            Out.Log("Comparing FAILED; return: " + res + ", expected: " + _
275                -expRes  + " ")
276            testSubstring = false
277        else
278            Out.Log("Comparing OK :")
279        end if
280        Out.Log("('" + str2 + "', " + p2 + ", " + len2 + ", '" + _
281            str1 + "', " + p1 + ", " + len1 + ")")
282End Function
283</script:module>
284