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