1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.io; 25 26 import lib.MultiMethodTest; 27 import lib.Status; 28 import lib.StatusException; 29 30 import com.sun.star.beans.XPropertySet; 31 import com.sun.star.io.XObjectInputStream; 32 import com.sun.star.io.XObjectOutputStream; 33 import com.sun.star.io.XPersistObject; 34 import com.sun.star.uno.UnoRuntime; 35 36 /** 37 * Testing <code>com.sun.star.io.XObjectOutputStream</code> 38 * interface methods: 39 * <ul> 40 * <li><code>writeObject()</code></li> 41 * </ul> <p> 42 * This test needs the following object relations : 43 * <ul> 44 * <li> <code>'InputStream'</code> (of type <code>XObjectInputStream</code>)</li> 45 * persist object for testing of write to stream</ul> 46 * @see com.sun.star.io.XObjectInputStream 47 * @see com.sun.star.io.XObjectOutputStream 48 * @see com.sun.star.io.XPersistObject 49 */ 50 public class _XObjectOutputStream extends MultiMethodTest { 51 52 public XObjectOutputStream oObj = null; 53 54 /** 55 * Test creates persist object, sets label of object, 56 * calls the method for created persist object 57 * and checks label of object that was read from input stream. <p> 58 * Has <b> OK </b> status if the method successfully returns 59 * and labels are equals. <p> 60 */ _writeObject()61 public void _writeObject() throws Exception { 62 XObjectInputStream oInStream = (XObjectInputStream) 63 tEnv.getObjRelation("InputStream"); 64 if (oInStream == null) throw 65 new StatusException(Status.failed("Relation 'InputStream' failed")); 66 67 // use own implementation of XPersistObject, so test runs 68 // without an office 69 XPersistObject objWrite = (XPersistObject) 70 tEnv.getObjRelation("PersistObject"); 71 if (objWrite == null) throw 72 new StatusException(Status.failed("Relation 'PersistObject' failed")); 73 74 XPropertySet propObjWrite = (XPropertySet) 75 UnoRuntime.queryInterface(XPropertySet.class, objWrite); 76 77 // This XPersistObject has a property called 'String' 78 propObjWrite.setPropertyValue("String", "XObjectOutputStream"); 79 80 log.println("Writing object with label 'XObjectOutputStream'"); 81 oObj.writeObject(objWrite); 82 XPersistObject readObj = oInStream.readObject(); 83 XPropertySet propSet = (XPropertySet) 84 UnoRuntime.queryInterface(XPropertySet.class, readObj); 85 String label = (String)propSet.getPropertyValue("String"); 86 log.println("Object with label '" + label + "' was read"); 87 88 tRes.tested("writeObject()", label.equals("XObjectOutputStream")) ; 89 } 90 } 91 92