update dev300-m58
[ooovba.git] / qadevOOo / tests / basic / ifc / i18n / XCharacterClassification / i18n_XCharacterClassification.xba
blobd284fd67d80a406cc7b52d60a4e7136dc2c0af38
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">
6 '*************************************************************************
8 ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 '
10 ' Copyright 2008 by Sun Microsystems, Inc.
12 ' OpenOffice.org - a multi-platform office productivity suite
14 ' $RCSfile: i18n_XCharacterClassification.xba,v $
16 ' $Revision: 1.3 $
18 ' This file is part of OpenOffice.org.
20 ' OpenOffice.org is free software: you can redistribute it and/or modify
21 ' it under the terms of the GNU Lesser General Public License version 3
22 ' only, as published by the Free Software Foundation.
24 ' OpenOffice.org is distributed in the hope that it will be useful,
25 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ' GNU Lesser General Public License version 3 for more details
28 ' (a copy is included in the LICENSE file that accompanied this code).
30 ' You should have received a copy of the GNU Lesser General Public License
31 ' version 3 along with OpenOffice.org. If not, see
32 ' <http://www.openoffice.org/license.html>
33 ' for a copy of the LGPLv3 License.
35 '*************************************************************************
36 '*************************************************************************
40 ' Be sure that all variables are dimensioned:
41 option explicit
45 Sub RunTest()
47 '*************************************************************************
48 ' INTERFACE:
49 ' com.sun.star.i18n.XCharacterClassification
50 '*************************************************************************
51 On Error Goto ErrHndl
52 Dim bOK As Boolean
53 Dim sType As Variant
54 Dim cString1 As String, cString2 As String
55 Dim cRes As Variant, sDir As Variant
57 Const cString = "TestString1"
59 Dim Locale As New com.sun.star.lang.Locale
61 Locale.Language = "DE"
62 Locale.Country = "GERMANY"
63 Locale.Variant = ""
65 Test.StartMethod("toUpper()")
66 bOK = true
67 cRes = oObj.toUpper(cString, 2, 3, Locale)
68 bOK = bOK AND Comp(cRes, "STS")
69 Test.MethodTested("toUpper()", bOK)
71 Test.StartMethod("toLower()")
72 bOK = true
73 cRes = oObj.toLower(cString, 2, 3, Locale)
74 bOK = bOK AND Comp(cRes, "sts")
75 Test.MethodTested("toLower()", bOK)
77 Test.StartMethod("toTitle()")
78 bOK = true
79 cRes = oObj.toTitle(cString, 2, 3, Locale)
80 bOK = bOK AND Comp(cRes, "STS")
81 Test.MethodTested("toTitle()", bOK)
83 Test.StartMethod("getType()")
84 bOK = true
85 bOK = bOK AND oObj.getType(cString, 0) &lt;&gt; oObj.getType(cString, 2)
86 Test.MethodTested("getType()", bOK)
88 Test.StartMethod("getCharacterDirection()")
89 bOK = true
90 sDir = oObj.getCharacterDirection(cString, 1)
91 bOK = bOK AND isNumeric(sDir)
92 Test.MethodTested("getCharacterDirection()", bOK)
94 Test.StartMethod("getScript()")
95 bOK = true
96 bOK = bOK AND isNUmeric(oObj.getScript(cString, 0))
97 Test.MethodTested("getScript()", bOK)
99 Test.StartMethod("getCharacterType()")
100 bOK = true
101 sType = oObj.getCharacterType(cString, 0, Locale)
102 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
103 bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
104 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
105 sType = oObj.getCharacterType(cString, 1, Locale)
106 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
107 bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
108 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
109 sType = oObj.getCharacterType(cString, 10, Locale)
110 bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.UPPER)
111 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
112 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
113 Test.MethodTested("getCharacterType()", bOK)
115 Test.StartMethod("getStringType()")
116 bOK = true
117 sType = oObj.getStringType(cString, 0, 10, Locale)
118 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
119 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
120 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
121 bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
122 sType = oObj.getStringType(cString, 0, 11, Locale)
123 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
124 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
125 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
126 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
127 Test.MethodTested("getStringType()", bOK)
129 Test.StartMethod("parseAnyToken()")
130 bOK = true
132 cString1 = "int _ind1 = 1234;"
133 Out.Log ("Parsing string: " + cString1)
134 Dim tTypes(10) As Integer
135 Dim tVals(10) As String
136 Dim nStartChartFlags As Variant, userDefinedCharactersStart As Variant
137 Dim nContCharFlags As Variant, userDefinedCharactersCont As Variant, nTokenType As Variant
139 with com.sun.star.i18n.KParseType
140 tTypes(0) = .IDENTNAME: tVals(0) = "int"
141 tTypes(1) = .IDENTNAME: tVals(1) = "_ind1"
142 tTypes(2) = .ONE_SINGLE_CHAR: tVals(2) = "="
143 tTypes(3) = .ANY_NUMBER: tVals(3) = "1234"
144 end with
146 with com.sun.star.i18n.KParseTokens
147 nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
148 userDefinedCharactersStart = "_"
149 nContCharFlags = nStartChartFlags OR .ANY_ALNUM
150 userDefinedCharactersCont = ""
151 end with
153 Dim nStart As Integer, idx As Integer, nPos As Integer
154 Dim pRes As Variant
155 Dim cActStr As String
157 nStart = 1
158 idx = 0
160 while nStart &lt; Len(cString1)
161 pRes = oObj.parseAnyToken(cString1, nStart - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
162 nContCharFlags, userDefinedCharactersCont)
164 Out.Log("Type is " + pRes.TokenType)
165 if (pRes.TokenType = 0) then
166 nStart = nStart + 1
167 else
168 Out.Log("Type is as expexted - " + ((pRes.TokenType AND tTypes(idx)) &gt; 0))
169 bOK = bOK AND (pRes.TokenType AND tTypes(idx))
170 cActStr = mid(cString1, (nStart + pRes.LeadingWhiteSpace), pRes.EndPos - (nStart + pRes.LeadingWhiteSpace) + 1)
171 Out.Log("Expected: '" + tVals(idx) + "'; actual is: '" + cActStr + "'")
172 bOK = bOK AND (cActStr = tVals(idx))
173 nStart = pRes.EndPos + 1
174 end if
175 idx = idx + 1
176 wend
177 Test.MethodTested("parseAnyToken()", bOK)
179 Test.StartMethod("parsePredefinedToken()")
180 bOK = true
182 cString2 = "1a, _a1$5"
183 with com.sun.star.i18n.KParseType
184 nTokenType = .IDENTNAME
185 end with
186 with com.sun.star.i18n.KParseTokens
187 nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
188 userDefinedCharactersStart = "_"
189 nContCharFlags = nStartChartFlags OR .ANY_ALNUM
190 userDefinedCharactersCont = ""
191 end with
193 tVals(0) = "a"
194 tVals(1) = "_a1"
196 nPos = 1
197 idx = 0
198 while nPos &lt; Len(cString2)
199 pRes = oObj.parsePredefinedToken(nTokenType, cString2, nPos - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
200 nContCharFlags, userDefinedCharactersCont)
202 Out.Log("Type is " + pRes.TokenType)
203 if (pRes.TokenType = 0) then
204 nPos = nPos + 1
205 else
206 bOK = bOK AND (pRes.TokenType AND tTypes(idx))
207 cActStr = mid(cString2, (nPos + pRes.LeadingWhiteSpace), pRes.EndPos - (nPos + pRes.LeadingWhiteSpace) + 1)
208 bOK = bOK AND Comp(cActStr, tVals(idx))
209 nPos = pRes.EndPos + 1
210 idx = idx + 1
211 end if
212 wend
214 bOK = bOK AND true
215 Test.MethodTested("parsePredefinedToken()", bOK)
217 Exit Sub
218 ErrHndl:
219 Test.Exception()
220 bOK = false
221 resume next
222 End Sub
223 Function Comp(cS1 As String, cS2 As String) As Boolean
224 Out.Log("Expected : '" + cS2 + "', actual : '" + cS1 + "'")
225 Comp = cS1 = cS2
226 End Function
227 </script:module>