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' 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' Be sure that all variables are dimensioned:
38option explicit
39
40
41
42Sub RunTest()
43
44'*************************************************************************
45' INTERFACE:
46' com.sun.star.i18n.XCharacterClassification
47'*************************************************************************
48On Error Goto ErrHndl
49    Dim bOK As Boolean
50    Dim sType As Variant
51    Dim cString1 As String, cString2 As String
52    Dim cRes As Variant, sDir As Variant
53
54    Const cString = "TestString1"
55
56    Dim Locale As New com.sun.star.lang.Locale
57
58    Locale.Language = "DE"
59    Locale.Country = "GERMANY"
60    Locale.Variant = ""
61
62    Test.StartMethod("toUpper()")
63    bOK = true
64    cRes = oObj.toUpper(cString, 2, 3, Locale)
65    bOK = bOK AND Comp(cRes, "STS")
66    Test.MethodTested("toUpper()", bOK)
67
68    Test.StartMethod("toLower()")
69    bOK = true
70    cRes = oObj.toLower(cString, 2, 3, Locale)
71    bOK = bOK AND Comp(cRes, "sts")
72    Test.MethodTested("toLower()", bOK)
73
74    Test.StartMethod("toTitle()")
75    bOK = true
76    cRes = oObj.toTitle(cString, 2, 3, Locale)
77    bOK = bOK AND Comp(cRes, "STS")
78    Test.MethodTested("toTitle()", bOK)
79
80    Test.StartMethod("getType()")
81    bOK = true
82    bOK = bOK AND oObj.getType(cString, 0) &lt;&gt; oObj.getType(cString, 2)
83    Test.MethodTested("getType()", bOK)
84
85    Test.StartMethod("getCharacterDirection()")
86    bOK = true
87    sDir = oObj.getCharacterDirection(cString, 1)
88    bOK = bOK AND isNumeric(sDir)
89    Test.MethodTested("getCharacterDirection()", bOK)
90
91    Test.StartMethod("getScript()")
92    bOK = true
93    bOK = bOK AND isNUmeric(oObj.getScript(cString, 0))
94    Test.MethodTested("getScript()", bOK)
95
96    Test.StartMethod("getCharacterType()")
97    bOK = true
98    sType = oObj.getCharacterType(cString,  0, Locale)
99    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
100    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
101    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
102    sType = oObj.getCharacterType(cString,  1, Locale)
103    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
104    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
105    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
106    sType = oObj.getCharacterType(cString, 10, Locale)
107    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.UPPER)
108    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
109    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
110    Test.MethodTested("getCharacterType()", bOK)
111
112    Test.StartMethod("getStringType()")
113    bOK = true
114    sType = oObj.getStringType(cString, 0, 10, Locale)
115    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
116    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
117    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
118    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
119    sType = oObj.getStringType(cString, 0, 11, Locale)
120    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
121    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
122    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
123    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
124    Test.MethodTested("getStringType()", bOK)
125
126    Test.StartMethod("parseAnyToken()")
127    bOK = true
128
129    cString1 = "int _ind1 = 1234;"
130    Out.Log ("Parsing string: " + cString1)
131    Dim tTypes(10) As Integer
132    Dim tVals(10) As String
133    Dim nStartChartFlags As Variant, userDefinedCharactersStart As Variant
134    Dim nContCharFlags As Variant, userDefinedCharactersCont As Variant, nTokenType As Variant
135
136   	with com.sun.star.i18n.KParseType
137        tTypes(0) = .IDENTNAME: tVals(0) = "int"
138        tTypes(1) = .IDENTNAME: tVals(1) = "_ind1"
139        tTypes(2) = .ONE_SINGLE_CHAR: tVals(2) = "="
140        tTypes(3) = .ANY_NUMBER: tVals(3) = "1234"
141    end with
142
143    with com.sun.star.i18n.KParseTokens
144        nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
145        userDefinedCharactersStart = "_"
146        nContCharFlags = nStartChartFlags OR .ANY_ALNUM
147        userDefinedCharactersCont = ""
148    end with
149
150    Dim nStart As Integer, idx As Integer, nPos As Integer
151    Dim pRes As Variant
152    Dim cActStr As String
153
154    nStart = 1
155    idx = 0
156
157    while nStart &lt; Len(cString1)
158       	pRes = oObj.parseAnyToken(cString1, nStart - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
159   	        nContCharFlags, userDefinedCharactersCont)
160
161      Out.Log("Type is " + pRes.TokenType)
162   		if (pRes.TokenType = 0) then
163          nStart = nStart + 1
164   		else
165          Out.Log("Type is as expexted - " + ((pRes.TokenType AND tTypes(idx)) &gt; 0))
166          bOK = bOK AND (pRes.TokenType AND tTypes(idx))
167          cActStr = mid(cString1, (nStart + pRes.LeadingWhiteSpace), pRes.EndPos - (nStart + pRes.LeadingWhiteSpace) + 1)
168          Out.Log("Expected: '" + tVals(idx) + "'; actual is: '" + cActStr + "'")
169          bOK = bOK AND (cActStr = tVals(idx))
170          nStart = pRes.EndPos + 1
171      end if
172      idx = idx + 1
173    wend
174    Test.MethodTested("parseAnyToken()", bOK)
175
176    Test.StartMethod("parsePredefinedToken()")
177    bOK = true
178
179    cString2 = "1a, _a1$5"
180   	with com.sun.star.i18n.KParseType
181        nTokenType = .IDENTNAME
182    end with
183    with com.sun.star.i18n.KParseTokens
184        nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
185        userDefinedCharactersStart = "_"
186        nContCharFlags = nStartChartFlags OR .ANY_ALNUM
187        userDefinedCharactersCont = ""
188    end with
189
190    tVals(0) = "a"
191    tVals(1) = "_a1"
192
193    nPos = 1
194    idx = 0
195    while nPos &lt; Len(cString2)
196       	pRes = oObj.parsePredefinedToken(nTokenType, cString2, nPos - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
197   	        nContCharFlags, userDefinedCharactersCont)
198
199        Out.Log("Type is " + pRes.TokenType)
200        if (pRes.TokenType = 0) then
201            nPos = nPos + 1
202        else
203            bOK = bOK AND (pRes.TokenType AND tTypes(idx))
204            cActStr = mid(cString2, (nPos + pRes.LeadingWhiteSpace), pRes.EndPos - (nPos + pRes.LeadingWhiteSpace) + 1)
205            bOK = bOK AND Comp(cActStr, tVals(idx))
206            nPos = pRes.EndPos + 1
207            idx = idx + 1
208        end if
209    wend
210
211    bOK = bOK AND true
212    Test.MethodTested("parsePredefinedToken()", bOK)
213
214Exit Sub
215ErrHndl:
216    Test.Exception()
217    bOK = false
218    resume next
219End Sub
220Function Comp(cS1 As String, cS2 As String) As Boolean
221    Out.Log("Expected : '" + cS2 + "', actual : '" + cS1 + "'")
222    Comp = cS1 = cS2
223End Function
224</script:module>
225