Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / io / _XObjectInputStream.java
blob31599567495209712869703c1dbbc105da3ea734
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XObjectInputStream.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.io;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import util.ValueComparer;
37 import com.sun.star.beans.Property;
38 import com.sun.star.beans.XPropertySet;
39 import com.sun.star.io.XObjectInputStream;
40 import com.sun.star.io.XObjectOutputStream;
41 import com.sun.star.io.XPersistObject;
42 import com.sun.star.uno.UnoRuntime;
44 /**
45 * Testing <code>com.sun.star.io.XObjectInputStream</code>
46 * interface methods:
47 * <ul>
48 * <li><code>readObject()</code></li>
49 * </ul> <p>
50 * This test needs the following object relations :
51 * <ul>
52 * <li> <code>'PersistObject'</code> (of type <code>Object</code>):
53 * object that supports interface <code>XPersistObject</code> </li>
54 * <ul> <p>
55 * After test completion object environment has to be recreated.
56 * @see com.sun.star.io.XObjectInputStream
57 * @see com.sun.star.io.XPersistObject
59 public class _XObjectInputStream extends MultiMethodTest {
61 public XObjectInputStream oObj = null;
62 private Object objRead = null ;
63 private Object objWrite = null ;
65 /**
66 * Test reads perisist object from stream and compares properties
67 * of the object with properties of persist object obtained
68 * from relation <code>'PersistObject'</code> <p>
69 * Has <b> OK </b> status if returned value isn't null and values
70 * of objects properties are equal. <p>
72 public void _readObject() {
73 objWrite = tEnv.getObjRelation("PersistObject") ;
74 if (objWrite == null) {
75 log.println("PersistObject not found in relations") ;
76 tRes.tested("readObject()", false) ;
77 return ;
80 // write the object
81 try {
82 XObjectOutputStream oStream = (XObjectOutputStream)
83 tEnv.getObjRelation("StreamWriter");
84 oStream.writeObject((XPersistObject)objWrite);
85 } catch(com.sun.star.io.IOException e) {
86 log.println("Couldn't write object to stream");
87 e.printStackTrace(log);
88 tRes.tested("readObject()", Status.skipped(false));
89 return;
92 try {
93 objRead = oObj.readObject() ;
94 } catch(com.sun.star.io.IOException e) {
95 log.println("Couldn't read object from stream");
96 e.printStackTrace(log);
97 tRes.tested("readObject()", false) ;
98 return ;
101 if (objRead == null) {
102 log.println("No object was read.") ;
103 tRes.tested("readObject()", false) ;
104 return ;
107 XPropertySet props1 = null ;
108 XPropertySet props2 = null ;
110 props1 = (XPropertySet) UnoRuntime.queryInterface
111 (XPropertySet.class, objRead) ;
113 props2 = (XPropertySet) UnoRuntime.queryInterface
114 (XPropertySet.class, objWrite) ;
116 if (props1 == null) {
117 log.println("Object read doesn't implement XPropertySet") ;
118 tRes.tested("readObject()", false) ;
119 return ;
121 if (props2 == null) {
122 log.println("Object written doesn't implement XPropertySet") ;
123 tRes.tested("readObject()", false) ;
124 return ;
127 tRes.tested("readObject()",
128 compareProperties(props1, props2)) ;
131 protected boolean compareProperties(XPropertySet props1,
132 XPropertySet props2) {
134 Property[] p1 = props1.getPropertySetInfo().getProperties() ;
135 Property[] p2 = props2.getPropertySetInfo().getProperties() ;
137 if (p1.length != p2.length) {
138 log.println("Number of properties differs") ;
139 return false ;
142 boolean result = true ;
144 for (int i = 0; i < p1.length; i++) {
145 String propName = p1[i].Name ;
147 log.print("Comparing property '" + propName + "' ...") ;
148 boolean res = false ;
149 try {
150 res = ValueComparer.equalValue
151 (props1.getPropertyValue(propName),
152 props2.getPropertyValue(propName)) ;
153 } catch (com.sun.star.beans.UnknownPropertyException e) {
154 log.println("Not found !") ;
155 } catch (com.sun.star.lang.WrappedTargetException e) {
156 log.println(e) ;
159 if (res)
160 log.println("OK.") ;
161 else
162 log.println("Different !") ;
164 result &= res ;
167 return result ;
171 * Forces object environment recreation.
173 public void after() {
174 this.disposeEnvironment() ;