'************************************************************************* ' ' Licensed to the Apache Software Foundation (ASF) under one ' or more contributor license agreements. See the NOTICE file ' distributed with this work for additional information ' regarding copyright ownership. The ASF licenses this file ' to you under the Apache License, Version 2.0 (the ' "License"); you may not use this file except in compliance ' with the License. You may obtain a copy of the License at ' ' http://www.apache.org/licenses/LICENSE-2.0 ' ' Unless required by applicable law or agreed to in writing, ' software distributed under the License is distributed on an ' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ' KIND, either express or implied. See the License for the ' specific language governing permissions and limitations ' under the License. ' '************************************************************************* ' Be sure that all variables are dimensioned: option explicit Sub RunTest() '************************************************************************* ' INTERFACE: ' com.sun.star.i18n.XCharacterClassification '************************************************************************* On Error Goto ErrHndl Dim bOK As Boolean Dim sType As Variant Dim cString1 As String, cString2 As String Dim cRes As Variant, sDir As Variant Const cString = "TestString1" Dim Locale As New com.sun.star.lang.Locale Locale.Language = "DE" Locale.Country = "GERMANY" Locale.Variant = "" Test.StartMethod("toUpper()") bOK = true cRes = oObj.toUpper(cString, 2, 3, Locale) bOK = bOK AND Comp(cRes, "STS") Test.MethodTested("toUpper()", bOK) Test.StartMethod("toLower()") bOK = true cRes = oObj.toLower(cString, 2, 3, Locale) bOK = bOK AND Comp(cRes, "sts") Test.MethodTested("toLower()", bOK) Test.StartMethod("toTitle()") bOK = true cRes = oObj.toTitle(cString, 2, 3, Locale) bOK = bOK AND Comp(cRes, "STS") Test.MethodTested("toTitle()", bOK) Test.StartMethod("getType()") bOK = true bOK = bOK AND oObj.getType(cString, 0) <> oObj.getType(cString, 2) Test.MethodTested("getType()", bOK) Test.StartMethod("getCharacterDirection()") bOK = true sDir = oObj.getCharacterDirection(cString, 1) bOK = bOK AND isNumeric(sDir) Test.MethodTested("getCharacterDirection()", bOK) Test.StartMethod("getScript()") bOK = true bOK = bOK AND isNUmeric(oObj.getScript(cString, 0)) Test.MethodTested("getScript()", bOK) Test.StartMethod("getCharacterType()") bOK = true sType = oObj.getCharacterType(cString, 0, Locale) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER) bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM) sType = oObj.getCharacterType(cString, 1, Locale) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER) bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM) sType = oObj.getCharacterType(cString, 10, Locale) bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.UPPER) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM) Test.MethodTested("getCharacterType()", bOK) Test.StartMethod("getStringType()") bOK = true sType = oObj.getStringType(cString, 0, 10, Locale) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM) bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT) sType = oObj.getStringType(cString, 0, 11, Locale) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM) bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT) Test.MethodTested("getStringType()", bOK) Test.StartMethod("parseAnyToken()") bOK = true cString1 = "int _ind1 = 1234;" Out.Log ("Parsing string: " + cString1) Dim tTypes(10) As Integer Dim tVals(10) As String Dim nStartChartFlags As Variant, userDefinedCharactersStart As Variant Dim nContCharFlags As Variant, userDefinedCharactersCont As Variant, nTokenType As Variant with com.sun.star.i18n.KParseType tTypes(0) = .IDENTNAME: tVals(0) = "int" tTypes(1) = .IDENTNAME: tVals(1) = "_ind1" tTypes(2) = .ONE_SINGLE_CHAR: tVals(2) = "=" tTypes(3) = .ANY_NUMBER: tVals(3) = "1234" end with with com.sun.star.i18n.KParseTokens nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS userDefinedCharactersStart = "_" nContCharFlags = nStartChartFlags OR .ANY_ALNUM userDefinedCharactersCont = "" end with Dim nStart As Integer, idx As Integer, nPos As Integer Dim pRes As Variant Dim cActStr As String nStart = 1 idx = 0 while nStart < Len(cString1) pRes = oObj.parseAnyToken(cString1, nStart - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _ nContCharFlags, userDefinedCharactersCont) Out.Log("Type is " + pRes.TokenType) if (pRes.TokenType = 0) then nStart = nStart + 1 else Out.Log("Type is as expexted - " + ((pRes.TokenType AND tTypes(idx)) > 0)) bOK = bOK AND (pRes.TokenType AND tTypes(idx)) cActStr = mid(cString1, (nStart + pRes.LeadingWhiteSpace), pRes.EndPos - (nStart + pRes.LeadingWhiteSpace) + 1) Out.Log("Expected: '" + tVals(idx) + "'; actual is: '" + cActStr + "'") bOK = bOK AND (cActStr = tVals(idx)) nStart = pRes.EndPos + 1 end if idx = idx + 1 wend Test.MethodTested("parseAnyToken()", bOK) Test.StartMethod("parsePredefinedToken()") bOK = true cString2 = "1a, _a1$5" with com.sun.star.i18n.KParseType nTokenType = .IDENTNAME end with with com.sun.star.i18n.KParseTokens nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS userDefinedCharactersStart = "_" nContCharFlags = nStartChartFlags OR .ANY_ALNUM userDefinedCharactersCont = "" end with tVals(0) = "a" tVals(1) = "_a1" nPos = 1 idx = 0 while nPos < Len(cString2) pRes = oObj.parsePredefinedToken(nTokenType, cString2, nPos - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _ nContCharFlags, userDefinedCharactersCont) Out.Log("Type is " + pRes.TokenType) if (pRes.TokenType = 0) then nPos = nPos + 1 else bOK = bOK AND (pRes.TokenType AND tTypes(idx)) cActStr = mid(cString2, (nPos + pRes.LeadingWhiteSpace), pRes.EndPos - (nPos + pRes.LeadingWhiteSpace) + 1) bOK = bOK AND Comp(cActStr, tVals(idx)) nPos = pRes.EndPos + 1 idx = idx + 1 end if wend bOK = bOK AND true Test.MethodTested("parsePredefinedToken()", bOK) Exit Sub ErrHndl: Test.Exception() bOK = false resume next End Sub Function Comp(cS1 As String, cS2 As String) As Boolean Out.Log("Expected : '" + cS2 + "', actual : '" + cS1 + "'") Comp = cS1 = cS2 End Function