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