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_XCharacterClassification" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34
35
36Sub RunTest()
37
38'*************************************************************************
39' INTERFACE:
40' com.sun.star.i18n.XCharacterClassification
41'*************************************************************************
42On Error Goto ErrHndl
43    Dim bOK As Boolean
44    Dim sType As Variant
45    Dim cString1 As String, cString2 As String
46    Dim cRes As Variant, sDir As Variant
47
48    Const cString = "TestString1"
49
50    Dim Locale As New com.sun.star.lang.Locale
51
52    Locale.Language = "DE"
53    Locale.Country = "GERMANY"
54    Locale.Variant = ""
55
56    Test.StartMethod("toUpper()")
57    bOK = true
58    cRes = oObj.toUpper(cString, 2, 3, Locale)
59    bOK = bOK AND Comp(cRes, "STS")
60    Test.MethodTested("toUpper()", bOK)
61
62    Test.StartMethod("toLower()")
63    bOK = true
64    cRes = oObj.toLower(cString, 2, 3, Locale)
65    bOK = bOK AND Comp(cRes, "sts")
66    Test.MethodTested("toLower()", bOK)
67
68    Test.StartMethod("toTitle()")
69    bOK = true
70    cRes = oObj.toTitle(cString, 2, 3, Locale)
71    bOK = bOK AND Comp(cRes, "STS")
72    Test.MethodTested("toTitle()", bOK)
73
74    Test.StartMethod("getType()")
75    bOK = true
76    bOK = bOK AND oObj.getType(cString, 0) &lt;&gt; oObj.getType(cString, 2)
77    Test.MethodTested("getType()", bOK)
78
79    Test.StartMethod("getCharacterDirection()")
80    bOK = true
81    sDir = oObj.getCharacterDirection(cString, 1)
82    bOK = bOK AND isNumeric(sDir)
83    Test.MethodTested("getCharacterDirection()", bOK)
84
85    Test.StartMethod("getScript()")
86    bOK = true
87    bOK = bOK AND isNUmeric(oObj.getScript(cString, 0))
88    Test.MethodTested("getScript()", bOK)
89
90    Test.StartMethod("getCharacterType()")
91    bOK = true
92    sType = oObj.getCharacterType(cString,  0, Locale)
93    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
94    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
95    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
96    sType = oObj.getCharacterType(cString,  1, Locale)
97    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
98    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
99    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
100    sType = oObj.getCharacterType(cString, 10, Locale)
101    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.UPPER)
102    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
103    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
104    Test.MethodTested("getCharacterType()", bOK)
105
106    Test.StartMethod("getStringType()")
107    bOK = true
108    sType = oObj.getStringType(cString, 0, 10, Locale)
109    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
110    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
111    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
112    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
113    sType = oObj.getStringType(cString, 0, 11, Locale)
114    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
115    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
116    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
117    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
118    Test.MethodTested("getStringType()", bOK)
119
120    Test.StartMethod("parseAnyToken()")
121    bOK = true
122
123    cString1 = "int _ind1 = 1234;"
124    Out.Log ("Parsing string: " + cString1)
125    Dim tTypes(10) As Integer
126    Dim tVals(10) As String
127    Dim nStartChartFlags As Variant, userDefinedCharactersStart As Variant
128    Dim nContCharFlags As Variant, userDefinedCharactersCont As Variant, nTokenType As Variant
129
130   	with com.sun.star.i18n.KParseType
131        tTypes(0) = .IDENTNAME: tVals(0) = "int"
132        tTypes(1) = .IDENTNAME: tVals(1) = "_ind1"
133        tTypes(2) = .ONE_SINGLE_CHAR: tVals(2) = "="
134        tTypes(3) = .ANY_NUMBER: tVals(3) = "1234"
135    end with
136
137    with com.sun.star.i18n.KParseTokens
138        nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
139        userDefinedCharactersStart = "_"
140        nContCharFlags = nStartChartFlags OR .ANY_ALNUM
141        userDefinedCharactersCont = ""
142    end with
143
144    Dim nStart As Integer, idx As Integer, nPos As Integer
145    Dim pRes As Variant
146    Dim cActStr As String
147
148    nStart = 1
149    idx = 0
150
151    while nStart &lt; Len(cString1)
152       	pRes = oObj.parseAnyToken(cString1, nStart - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
153   	        nContCharFlags, userDefinedCharactersCont)
154
155      Out.Log("Type is " + pRes.TokenType)
156   		if (pRes.TokenType = 0) then
157          nStart = nStart + 1
158   		else
159          Out.Log("Type is as expexted - " + ((pRes.TokenType AND tTypes(idx)) &gt; 0))
160          bOK = bOK AND (pRes.TokenType AND tTypes(idx))
161          cActStr = mid(cString1, (nStart + pRes.LeadingWhiteSpace), pRes.EndPos - (nStart + pRes.LeadingWhiteSpace) + 1)
162          Out.Log("Expected: '" + tVals(idx) + "'; actual is: '" + cActStr + "'")
163          bOK = bOK AND (cActStr = tVals(idx))
164          nStart = pRes.EndPos + 1
165      end if
166      idx = idx + 1
167    wend
168    Test.MethodTested("parseAnyToken()", bOK)
169
170    Test.StartMethod("parsePredefinedToken()")
171    bOK = true
172
173    cString2 = "1a, _a1$5"
174   	with com.sun.star.i18n.KParseType
175        nTokenType = .IDENTNAME
176    end with
177    with com.sun.star.i18n.KParseTokens
178        nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
179        userDefinedCharactersStart = "_"
180        nContCharFlags = nStartChartFlags OR .ANY_ALNUM
181        userDefinedCharactersCont = ""
182    end with
183
184    tVals(0) = "a"
185    tVals(1) = "_a1"
186
187    nPos = 1
188    idx = 0
189    while nPos &lt; Len(cString2)
190       	pRes = oObj.parsePredefinedToken(nTokenType, cString2, nPos - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
191   	        nContCharFlags, userDefinedCharactersCont)
192
193        Out.Log("Type is " + pRes.TokenType)
194        if (pRes.TokenType = 0) then
195            nPos = nPos + 1
196        else
197            bOK = bOK AND (pRes.TokenType AND tTypes(idx))
198            cActStr = mid(cString2, (nPos + pRes.LeadingWhiteSpace), pRes.EndPos - (nPos + pRes.LeadingWhiteSpace) + 1)
199            bOK = bOK AND Comp(cActStr, tVals(idx))
200            nPos = pRes.EndPos + 1
201            idx = idx + 1
202        end if
203    wend
204
205    bOK = bOK AND true
206    Test.MethodTested("parsePredefinedToken()", bOK)
207
208Exit Sub
209ErrHndl:
210    Test.Exception()
211    bOK = false
212    resume next
213End Sub
214Function Comp(cS1 As String, cS2 As String) As Boolean
215    Out.Log("Expected : '" + cS2 + "', actual : '" + cS1 + "'")
216    Comp = cS1 = cS2
217End Function
218</script:module>
219