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="io_XPersistObject" 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' This Interface/Service test depends on the following GLOBAL variables,
41' which must be specified in the object creation:
42
43'     - Global oPersistInstance As Object
44
45'*************************************************************************
46
47
48
49
50
51Sub RunTest()
52
53'*************************************************************************
54' INTERFACE:
55' com.sun.star.io.XPersistObject
56'*************************************************************************
57On Error Goto ErrHndl
58    Dim bOK As Boolean
59    Dim oMarkIn, oMarkOut, oOutStrm, oInStrm As Object
60    Dim oDummy, oCopy, oPipe As Object
61    Dim uuidString As String
62    Dim UUID(), UUIDnew() As Variant
63    Dim i As Integer
64
65    if isNull(oPersistInstance) Then
66        Out.Log("oPersistInstance is Empty! No oPersistInstance in main created?")
67        Exit Sub
68    end if
69
70    Test.StartMethod("getServiceName()")
71    bOK = true
72    bOK = bOK AND (VarType(oObj.getServiceName()) = 8)
73    Test.MethodTested("getServiceName()", bOK)
74
75    if (hasUnoInterfaces(oObj,"com.sun.star.lang.XTypeProvider")) then
76	    'get ImplementationID
77        Out.Log("Before writing object, rememeber it's implementation ID.")
78        uuidString = ""
79        UUID = oObj.getImplementationId()
80        for i = 0 to ubound(UUID())
81            uuidString = uuidString &amp; UUID(i) &amp; "; "
82        next i
83        Out.Log("ImplementationID: " &amp; uuidString)
84    endif
85
86    oDummy = oPersistInstance
87    oPipe = createUNOService("com.sun.star.io.Pipe")
88    oMarkOut = createUNOService("com.sun.star.io.MarkableOutputStream")
89    oMarkIn  = createUNOService("com.sun.star.io.MarkableInputStream")
90    oOutStrm = createUNOService("com.sun.star.io.ObjectOutputStream")
91    oInStrm = createUNOService("com.sun.star.io.ObjectInputStream")
92
93    'made chain
94    oOutStrm.setOutputStream(oMarkOut)
95    oMarkOut.setOutputStream(oPipe)
96    oMarkIn.setInputStream(oPipe)
97    oInStrm.setInputStream(oMarkIn)
98
99    Test.StartMethod("write()")
100    Test.StartMethod("read()")
101    bOK = true
102    'write dummy
103    oOutStrm.writeObject(oDummy)
104    oObj.write(oOutStrm)
105    'read copy
106    oCopy = oInStrm.readObject()
107    oObj.read(oInStrm)
108
109    if (hasUnoInterfaces(oObj,"com.sun.star.lang.XTypeProvider")) then
110        Out.Log("After reading object, get it's implementation ID.")
111        uuidString = ""
112        UUIDnew = oObj.getImplementationId()
113        for i = 0 to ubound(UUID())
114            bOK = bOK AND (UUID(i) = UUIDnew(i))
115            uuidString = uuidString &amp; UUIDnew(i) &amp; "; "
116        next i
117        Out.Log("ImplementationID: " &amp; uuidString)
118    endif
119
120    Test.MethodTested("write()", bOK)
121    Test.MethodTested("read()", bOK)
122
123    ReCreateObj()
124Exit Sub
125ErrHndl:
126    Test.Exception()
127    bOK = false
128    resume next
129End Sub
130</script:module>
131