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