1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import util
.ValueComparer
;
34 import com
.sun
.star
.beans
.Property
;
35 import com
.sun
.star
.beans
.XPropertySet
;
36 import com
.sun
.star
.io
.XObjectInputStream
;
37 import com
.sun
.star
.io
.XObjectOutputStream
;
38 import com
.sun
.star
.io
.XPersistObject
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
42 * Testing <code>com.sun.star.io.XObjectInputStream</code>
45 * <li><code>readObject()</code></li>
47 * This test needs the following object relations :
49 * <li> <code>'PersistObject'</code> (of type <code>Object</code>):
50 * object that supports interface <code>XPersistObject</code> </li>
52 * After test completion object environment has to be recreated.
53 * @see com.sun.star.io.XObjectInputStream
54 * @see com.sun.star.io.XPersistObject
56 public class _XObjectInputStream
extends MultiMethodTest
{
58 public XObjectInputStream oObj
= null;
59 private Object objRead
= null ;
60 private Object objWrite
= null ;
63 * Test reads perisist object from stream and compares properties
64 * of the object with properties of persist object obtained
65 * from relation <code>'PersistObject'</code> <p>
66 * Has <b> OK </b> status if returned value isn't null and values
67 * of objects properties are equal. <p>
69 public void _readObject() {
70 objWrite
= tEnv
.getObjRelation("PersistObject") ;
71 if (objWrite
== null) {
72 log
.println("PersistObject not found in relations") ;
73 tRes
.tested("readObject()", false) ;
79 XObjectOutputStream oStream
= (XObjectOutputStream
)
80 tEnv
.getObjRelation("StreamWriter");
81 oStream
.writeObject((XPersistObject
)objWrite
);
82 } catch(com
.sun
.star
.io
.IOException e
) {
83 log
.println("Couldn't write object to stream");
84 e
.printStackTrace(log
);
85 tRes
.tested("readObject()", Status
.skipped(false));
90 objRead
= oObj
.readObject() ;
91 } catch(com
.sun
.star
.io
.IOException e
) {
92 log
.println("Couldn't read object from stream");
93 e
.printStackTrace(log
);
94 tRes
.tested("readObject()", false) ;
98 if (objRead
== null) {
99 log
.println("No object was read.") ;
100 tRes
.tested("readObject()", false) ;
104 XPropertySet props1
= null ;
105 XPropertySet props2
= null ;
107 props1
= (XPropertySet
) UnoRuntime
.queryInterface
108 (XPropertySet
.class, objRead
) ;
110 props2
= (XPropertySet
) UnoRuntime
.queryInterface
111 (XPropertySet
.class, objWrite
) ;
113 if (props1
== null) {
114 log
.println("Object read doesn't implement XPropertySet") ;
115 tRes
.tested("readObject()", false) ;
118 if (props2
== null) {
119 log
.println("Object written doesn't implement XPropertySet") ;
120 tRes
.tested("readObject()", false) ;
124 tRes
.tested("readObject()",
125 compareProperties(props1
, props2
)) ;
128 protected boolean compareProperties(XPropertySet props1
,
129 XPropertySet props2
) {
131 Property
[] p1
= props1
.getPropertySetInfo().getProperties() ;
132 Property
[] p2
= props2
.getPropertySetInfo().getProperties() ;
134 if (p1
.length
!= p2
.length
) {
135 log
.println("Number of properties differs") ;
139 boolean result
= true ;
141 for (int i
= 0; i
< p1
.length
; i
++) {
142 String propName
= p1
[i
].Name
;
144 log
.print("Comparing property '" + propName
+ "' ...") ;
145 boolean res
= false ;
147 res
= ValueComparer
.equalValue
148 (props1
.getPropertyValue(propName
),
149 props2
.getPropertyValue(propName
)) ;
150 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
151 log
.println("Not found !") ;
152 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
159 log
.println("Different !") ;
168 * Forces object environment recreation.
170 public void after() {
171 this.disposeEnvironment() ;