2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import util
.ValueComparer
;
25 import com
.sun
.star
.beans
.Property
;
26 import com
.sun
.star
.beans
.XPropertySet
;
27 import com
.sun
.star
.io
.XObjectInputStream
;
28 import com
.sun
.star
.io
.XObjectOutputStream
;
29 import com
.sun
.star
.io
.XPersistObject
;
30 import com
.sun
.star
.uno
.UnoRuntime
;
33 * Testing <code>com.sun.star.io.XObjectInputStream</code>
36 * <li><code>readObject()</code></li>
38 * This test needs the following object relations :
40 * <li> <code>'PersistObject'</code> (of type <code>Object</code>):
41 * object that supports interface <code>XPersistObject</code> </li>
43 * After test completion object environment has to be recreated.
44 * @see com.sun.star.io.XObjectInputStream
45 * @see com.sun.star.io.XPersistObject
47 public class _XObjectInputStream
extends MultiMethodTest
{
49 public XObjectInputStream oObj
= null;
52 * Test reads persist object from stream and compares properties
53 * of the object with properties of persist object obtained
54 * from relation <code>'PersistObject'</code> <p>
55 * Has <b> OK </b> status if returned value isn't null and values
56 * of objects properties are equal. <p>
58 public void _readObject() {
59 Object objWrite
= tEnv
.getObjRelation("PersistObject") ;
60 if (objWrite
== null) {
61 log
.println("PersistObject not found in relations") ;
62 tRes
.tested("readObject()", false) ;
68 XObjectOutputStream oStream
= (XObjectOutputStream
)
69 tEnv
.getObjRelation("StreamWriter");
70 oStream
.writeObject((XPersistObject
)objWrite
);
71 } catch(com
.sun
.star
.io
.IOException e
) {
72 log
.println("Couldn't write object to stream");
73 e
.printStackTrace(log
);
74 tRes
.tested("readObject()", Status
.skipped(false));
78 Object objRead
= null ;
80 objRead
= oObj
.readObject() ;
81 } catch(com
.sun
.star
.io
.IOException e
) {
82 log
.println("Couldn't read object from stream");
83 e
.printStackTrace(log
);
84 tRes
.tested("readObject()", false) ;
88 if (objRead
== null) {
89 log
.println("No object was read.") ;
90 tRes
.tested("readObject()", false) ;
94 XPropertySet props1
= null ;
95 XPropertySet props2
= null ;
97 props1
= UnoRuntime
.queryInterface
98 (XPropertySet
.class, objRead
) ;
100 props2
= UnoRuntime
.queryInterface
101 (XPropertySet
.class, objWrite
) ;
103 if (props1
== null) {
104 log
.println("Object read doesn't implement XPropertySet") ;
105 tRes
.tested("readObject()", false) ;
108 if (props2
== null) {
109 log
.println("Object written doesn't implement XPropertySet") ;
110 tRes
.tested("readObject()", false) ;
114 tRes
.tested("readObject()",
115 compareProperties(props1
, props2
)) ;
118 protected boolean compareProperties(XPropertySet props1
,
119 XPropertySet props2
) {
121 Property
[] p1
= props1
.getPropertySetInfo().getProperties() ;
122 Property
[] p2
= props2
.getPropertySetInfo().getProperties() ;
124 if (p1
.length
!= p2
.length
) {
125 log
.println("Number of properties differs") ;
129 boolean result
= true ;
131 for (int i
= 0; i
< p1
.length
; i
++) {
132 String propName
= p1
[i
].Name
;
134 log
.print("Comparing property '" + propName
+ "' ...") ;
135 boolean res
= false ;
137 res
= ValueComparer
.equalValue
138 (props1
.getPropertyValue(propName
),
139 props2
.getPropertyValue(propName
)) ;
140 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
141 log
.println("Not found !") ;
142 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
149 log
.println("Different !") ;
158 * Forces object environment recreation.
161 public void after() {
162 this.disposeEnvironment() ;