blob: d1d8c561e101d18a11dc07de7e9ab60bb7fd0fc4 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="script_XTypeConverter" script:language="StarBasic">
'*************************************************************************
'
' 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.script.XTypeConverter
'*************************************************************************
On Error Goto ErrHndl
Dim bOK As Boolean
Dim oCoreRefl As Object
oCoreRefl = createUNOService("com.sun.star.reflection.CoreReflection")
Test.StartMethod("convertTo()")
bOK = true
Dim tXInterface As Variant
Dim tXInterfaceObject As Variant
Dim cObjTypeName As String
Dim oObjToConv As Object
Out.Log("Creating a Type object for XInterface")
tXInterface = oCoreRefl.forName("com.sun.star.io.XInputStream")
Out.Log("Created " + tXInterface.Name)
oObjToConv = createUnoService("com.sun.star.io.Pipe")
Out.Log("Converting object of type " + oCoreRefl.getType(oObjToConv).Name + " to " + tXInterface.Name)
tXInterfaceObject = oObj.convertTo(oObjToConv, tXInterface)
if (isNULL(tXInterfaceObject)) then
Out.Log("Returned object is NULL!!!")
bOK = false
elseif (isEmpty(tXInterfaceObject)) then
cObjTypeName = "Empty"
else
cObjTypeName = oCoreRefl.getType(tXInterfaceObject).Name
end if
Out.Log("New object is of type " + cObjTypeName + ".")
bOK = bOK AND NOT isNULL(tXInterfaceObject)
bOK = bOK AND inStr(1, cObjTypeName, "XInterface")
Test.MethodTested("convertTo()", bOK)
Test.StartMethod("convertToSimpleType()")
Dim oldType As String
Dim newType As String
Dim oldVal As Integer
Dim newVal
bOK = true
oldVal = 65
oldType = oCoreRefl.getType(oldVal).Name
newVal = oObj.convertToSimpleType(oldVal, com.sun.star.uno.TypeClass.STRING)
newType = oCoreRefl.getType(newVal).Name
bOK = bOK AND newType &lt;&gt; oldType
bOK = bOK AND inStr(1, newVal, "65")
Out.Log("Old value is " + oldVal + " of type " + oldType + ", new value is " + _
newVal + " of type " + newType + ".")
Test.MethodTested("convertToSimpleType()", bOK)
Exit Sub
ErrHndl:
Test.Exception()
bOK = false
resume next
End Sub
</script:module>