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