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="script_XTypeConverter" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34
35
36Sub RunTest()
37
38'*************************************************************************
39' INTERFACE:
40' com.sun.star.script.XTypeConverter
41'*************************************************************************
42On Error Goto ErrHndl
43    Dim bOK As Boolean
44    Dim oCoreRefl As Object
45
46    oCoreRefl = createUNOService("com.sun.star.reflection.CoreReflection")
47
48    Test.StartMethod("convertTo()")
49    bOK = true
50    Dim tXInterface As Variant
51    Dim tXInterfaceObject As Variant
52    Dim cObjTypeName As String
53    Dim oObjToConv As Object
54
55    Out.Log("Creating a Type object for XInterface")
56    tXInterface = oCoreRefl.forName("com.sun.star.io.XInputStream")
57    Out.Log("Created " + tXInterface.Name)
58
59    oObjToConv = createUnoService("com.sun.star.io.Pipe")
60    Out.Log("Converting object of type " + oCoreRefl.getType(oObjToConv).Name + " to " + tXInterface.Name)
61    tXInterfaceObject = oObj.convertTo(oObjToConv, tXInterface)
62
63    if (isNULL(tXInterfaceObject)) then
64        Out.Log("Returned object is NULL!!!")
65        bOK = false
66    elseif (isEmpty(tXInterfaceObject)) then
67        cObjTypeName = "Empty"
68    else
69        cObjTypeName = oCoreRefl.getType(tXInterfaceObject).Name
70    end if
71
72    Out.Log("New object is of type " + cObjTypeName + ".")
73
74    bOK = bOK AND NOT isNULL(tXInterfaceObject)
75    bOK = bOK AND inStr(1, cObjTypeName, "XInterface")
76    Test.MethodTested("convertTo()", bOK)
77
78
79    Test.StartMethod("convertToSimpleType()")
80    Dim oldType As String
81    Dim newType As String
82    Dim oldVal As Integer
83    Dim newVal
84
85    bOK = true
86
87    oldVal = 65
88    oldType = oCoreRefl.getType(oldVal).Name
89    newVal = oObj.convertToSimpleType(oldVal, com.sun.star.uno.TypeClass.STRING)
90    newType = oCoreRefl.getType(newVal).Name
91
92    bOK = bOK AND newType &lt;&gt; oldType
93    bOK = bOK AND inStr(1, newVal, "65")
94    Out.Log("Old value is " + oldVal + " of type " + oldType + ", new value is " + _
95                             newVal + " of type " + newType + ".")
96    Test.MethodTested("convertToSimpleType()", bOK)
97
98Exit Sub
99ErrHndl:
100    Test.Exception()
101    bOK = false
102    resume next
103End Sub
104</script:module>
105