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