summaryrefslogtreecommitdiff
path: root/qadevOOo/tests/basic/ifc/i18n/XTransliteration/i18n_XTransliteration.xba
blob: faaf0bab69f49aab18d7a9b81d4f0756caac7939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="i18n_XTransliteration" script:language="StarBasic">


'*************************************************************************
'
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
' 
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'*************************************************************************
'*************************************************************************



'*************************************************************************
' This Interface/Service test depends on the following GLOBAL variables,
' which must be specified in the object creation:

'     - Global oLocale As Object

'*************************************************************************





Sub RunTest()

'*************************************************************************
' INTERFACE: 
' com.sun.star.i18n.XTransliteration
'*************************************************************************
On Error Goto ErrHndl
    Dim bOK As Boolean
    Dim availableModules As Variant
    Dim _string As String
    Dim i As Integer


    Test.StartMethod("getAvailableModules()")
    bOK = true
    availableModules = oObj.getAvailableModules(oLocale, com.sun.star.i18n.TransliterationModules.UPPERCASE_LOWERCASE)
    _string = ""
    for i = 0 to ubound(availableModules)
        _string = _string + availableModules(i) + "; "
    next i
    Out.Log("AvailableModules: " + _string)
    bOK = bOK AND _string &lt;&gt; ""
    Test.MethodTested("getAvailableModules()", bOK)

    Test.StartMethod("loadModuleByImplName()")
    bOK = true
    oObj.loadModuleByImplName("LOWERCASE_UPPERCASE", oLocale)
    Dim module_name As String
    module_name = oObj.getName()
    out.log("getName return: " + module_name)
    bOK = module_name = "lower_to_upper(generic)"
    Test.MethodTested("loadModuleByImplName()", bOK)

    Test.StartMethod("getName()")
    bOK = true
    Out.Log("Module name is " + oObj.getName())
    bOK = bOK AND oObj.getName() &lt;&gt; ""
    Test.MethodTested("getName()", bOK)

    Test.StartMethod("getType()")
    bOK = true
    Out.Log("Type is " + oObj.getType())
    bOK = bOK AND oObj.getType() = 1 ' for UPPERCASE_LOWERCASE it is ONE_TO_ONE
    Test.MethodTested("getType()", bOK)

    Test.StartMethod("loadModule()")
    bOK = true
    oObj.loadModule(com.sun.star.i18n.TransliterationModules.LOWERCASE_UPPERCASE, oLocale)
    bOK = bOK AND oObj.getType = com.sun.star.i18n.TransliterationType.ONE_TO_ONE
    Test.MethodTested("loadModule()", bOK)

    Test.StartMethod("loadModulesByImplNames()")
    bOK = true
    Dim Names(0) As String
    Names(0) = "UPPERCASE_LOWERCASE"
    oObj.loadModulesByImplNames(Names(), oLocale)
    module_name = oObj.getName()
    out.log("getName return: " + module_name)
    bOK = module_name = "upper_to_lower(generic)"
    Test.MethodTested("loadModulesByImplNames()", bOK)

    Test.StartMethod("loadModuleNew()")
    bOK = true
    Dim ModulesNew(0) As Variant
    ModulesNew(0) = com.sun.star.i18n.TransliterationModulesNew.LOWERCASE_UPPERCASE
    oObj.loadModuleNew(ModulesNew(), oLocale)
    bOK = bOK AND oObj.getType = com.sun.star.i18n.TransliterationType.ONE_TO_ONE
    Test.MethodTested("loadModuleNew()", bOK)

    Test.StartMethod("transliterate()")
    Dim offset() As Variant
    bOK = true
    Out.Log("LOWERCASE_UPPERCASE-transliterate part of string 'AaBbCc'")
    _string = oObj.transliterate("AaBbCc", 1, 4, offset())
    Out.Log("Result of transliteration: " + _string)
    bOK = bOK AND "ABBC" = _string
    bOK = bOK AND ubound(offset()) = 3
    for i = 0 to ubound(offset())
        bOK = bOK AND offset(i) = i + 1
    next i
    Test.MethodTested("transliterate()", bOK)

    Test.StartMethod("equals()")
    bOK = true
    Dim Match1 As Variant, Match2 As Variant
    bOK = bOK AND oObj.equals("This is an example string to be transliterate", 2, 20, Match1, _
                              "IS IS AN EXAMPLE STR", 0, 20, Match2)
    Test.MethodTested("equals()", bOK)

    Test.StartMethod("folding()")
    bOK = true
    _string = oObj.folding("AaBbCc", 1, 4, offset())
    Out.Log("Result of folding: " + _string)
    bOK = bOK AND "ABBC" = _string
    bOK = bOK AND ubound(offset()) = 3
    for i = 0 to ubound(offset())
        bOK = bOK AND offset(i) = i + 1
    next i
    Test.MethodTested("folding()", bOK)

    Test.StartMethod("transliterateRange()")
    Dim Result As Variant
    bOK = true
    oObj.loadModule(com.sun.star.i18n.TransliterationModules.IGNORE_CASE, _Locale)
    Result = oObj.transliterateRange("a", "c")
    for i = 0 to ubound(Result)
        Out.Log(Result(i))
    next i
    bOK = bOK AND ubound(Result()) = 3 AND _
        ((Result(0) = "a" AND Result(1) = "c" AND Result(2) = "A" AND Result(3) = "C" ) OR _
         (Result(0) = "A" AND Result(1) = "C" AND Result(2) = "a" AND Result(3) = "c" ))
    Test.MethodTested("transliterateRange()", bOK)

    Test.StartMethod("compareString()")
    oObj.loadModule(com.sun.star.i18n.TransliterationModules.LOWERCASE_UPPERCASE, _Locale)
    bOK = true
    bOK = bOK AND testString("", "", 0)
    bOK = bOK AND testString("a", "", 1)
    bOK = bOK AND testString("a", "a", 0)
    bOK = bOK AND testString("A", "a", 1)
    bOK = bOK AND testString("b", "a", 1)
    bOK = bOK AND testString(chr(10), chr(10), 0)
    bOK = bOK AND testString(chr(10), chr(9), 1)
    bOK = bOK AND testString("aaa", "aaa", 0)
    bOK = bOK AND testString("aaA", "aaa", 1)
    bOK = bOK AND testString("aaa", "aa", 1)
    bOK = bOK AND testString("ab", "aaa", 1)
    bOK = bOK AND testString("aba", "aa", 1)
    bOK = bOK AND testString("aaa" + chr(10) + chr(9) + "a", "aaa" + chr(10) + chr(9) + "a", 0)
    bOK = bOK AND testString("aaa" + chr(9) + chr(10) + "b", "aaa" + chr(9) + chr(10) + "a", 1)
    Test.MethodTested("compareString()", bOK)

    Test.StartMethod("compareSubstring()")
    bOK = true
    ' substrings below must be equal
    bOK = bOK AND testSubstring("", 0, 0, "", 0, 0, 0)
    bOK = bOK AND testSubstring("aa", 1, 0, "", 0, 0, 0)
    bOK = bOK AND testSubstring("aa", 1, 0, "aa", 2, 0, 0)
    bOK = bOK AND testSubstring("a", 0, 1, "a", 0, 1, 0)
    bOK = bOK AND testSubstring("ab", 0, 2, "ab", 0, 2, 0)
    bOK = bOK AND testSubstring("abc", 1, 2, "abc", 1, 2, 0)
    bOK = bOK AND testSubstring("abcdef", 0, 3, "123abc", 3, 3, 0)
    bOK = bOK AND testSubstring("abcdef", 1, 1, "123abc", 4, 1, 0)

    ' substrings below must NOT be equal
    bOK = bOK AND testSubstring("a", 0, 1, "a", 0, 0, 1)
    bOK = bOK AND testSubstring("aaa", 1, 1, "", 0, 0, 1)
    bOK = bOK AND testSubstring("bbb", 2, 1, "aaa", 2, 1, 1)
    bOK = bOK AND testSubstring("abc", 0, 3, "abc", 0, 2, 1)
    bOK = bOK AND testSubstring("bbc", 1, 2, "bbc", 0, 2, 1)

    Test.MethodTested("compareSubstring()", bOK)
Exit Sub
ErrHndl:
    Test.Exception()
    bOK = false
    resume next
End Sub

Function testString(str1 As String, str2 As String, expRes As Integer) As Boolean
    if expRes = 0 then
        testString = testStringCommon(str1, str2, expRes, false)
    else
        testString = testStringCommon(str1, str2, expRes, true)
    end if
End Function

Function testStringCommon(str1 As String, str2 As String, expRes As Integer, testReverse As Boolean) As Boolean
        Dim res As Integer

        testStringCommon = true

        res = -666

        res = oObj.compareString(str1, str2)

        if res = expRes then
            Out.Log("Comparing of '" + str1 + "' and '" + str2 + "' OK" )
        else
            Out.Log("Comparing of '" + str1 + "' and '" + str2 + _
                "' FAILED; return: " + res + ", expected: " + expRes)
            testStringCommon = false
        end if

        if NOT testReverse then
            Exit Function
        end if

        res = -666

        res = oObj.compareString(str2, str1)

        if res = -expRes then
            Out.Log("Comparing of '" + str2 + "' and '" + str1 + "' OK" )
        else
            Out.Log("Comparing of '" + str2 + "' and '" + str1 + _
                "' FAILED; return: " + res + ", expected: " + -expRes)
            testStringCommon = false
        end if
End Function

Function testSubstring(str1 As String, p1 As Integer, len1 As Integer, _
        str2 As String, p2 As Integer, len2 As Integer, expRes As Integer) As Boolean

        testSubstring = true

        Dim res As Integer
        res = -666

        res = oObj.compareSubstring(str1, p1, len1, str2, p2, len2)

        if res &lt;&gt; expRes then
            Out.Log("Comparing FAILED; return: " + res + ", expected: " + expRes + " ")
            testSubstring = false
        else
            Out.Log("Comparing OK : ")
        end if
        Out.Log("('" + str1 + "', " + p1 + ", " + len1 + ", '" + _
            str2 + "', " + p2 + ", " + len2 + ")")

        res = -666

        res = oObj.compareSubstring(str2, p2, len2, str1, p1, len1)

        if res &lt;&gt; -expRes then
            Out.Log("Comparing FAILED; return: " + res + ", expected: " + _
                -expRes  + " ")
            testSubstring = false
        else
            Out.Log("Comparing OK :")
        end if
        Out.Log("('" + str2 + "', " + p2 + ", " + len2 + ", '" + _
            str1 + "', " + p1 + ", " + len1 + ")")
End Function
</script:module>