1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package mod._streams.uno; 29 30 import com.sun.star.io.XActiveDataSink; 31 import com.sun.star.io.XActiveDataSource; 32 import com.sun.star.io.XInputStream; 33 import com.sun.star.io.XOutputStream; 34 import com.sun.star.lang.XMultiServiceFactory; 35 import com.sun.star.uno.UnoRuntime; 36 import com.sun.star.uno.XInterface; 37 import java.io.PrintWriter; 38 import lib.StatusException; 39 import lib.TestCase; 40 import lib.TestEnvironment; 41 import lib.TestParameters; 42 43 /** 44 * Test for object which is represented by service 45 * <code>com.sun.star.io.MarkableInputStream</code>. <p> 46 * Object implements the following interfaces : 47 * <ul> 48 * <li> <code>com::sun::star::io::XInputStream</code></li> 49 * <li> <code>com::sun::star::io::XMarkableStream</code></li> 50 * <li> <code>com::sun::star::io::XConnectable</code></li> 51 * <li> <code>com::sun::star::io::XActiveDataSink</code></li> 52 * </ul> 53 * @see com.sun.star.io.MarkableInputStream 54 * @see com.sun.star.io.XInputStream 55 * @see com.sun.star.io.XMarkableStream 56 * @see com.sun.star.io.XConnectable 57 * @see com.sun.star.io.XActiveDataSink 58 * @see ifc.io._XInputStream 59 * @see ifc.io._XMarkableStream 60 * @see ifc.io._XConnectable 61 * @see ifc.io._XActiveDataSink 62 */ 63 public class MarkableInputStream extends TestCase { 64 65 /** 66 * Creating a Testenvironment for the interfaces to be tested. 67 * Creates an instances of services <code>com.sun.star.io.Pipe</code>, 68 * <code>com.sun.star.io.MarkableInputStream</code> and 69 * <code>com.sun.star.io.MarkableOutputStream</code>. 70 * Plugs the created pipe as output stream for the created 71 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream 72 * for the created <code>MarkableInputStream</code>. Writes some data to the 73 * <code>MarkableOutputStream</code>. 74 * Object relations created : 75 * <ul> 76 * <li> <code>'StreamWriter'</code> for 77 * {@link ifc.io._XInputStream}(a stream to write data to) </li> 78 * <li> <code>'ByteData'</code> for 79 * {@link ifc.io._XInputStream}(the data that should be written into 80 * the stream) </li> 81 * <li> <code>'Connectable'</code> for 82 * {@link ifc.io._XConnectable}(another object that can be connected) </li> 83 * <li> <code>'InputStream'</code> for 84 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li> 85 * </ul> 86 * @see com.sun.star.io.Pipe 87 * @see com.sun.star.io.MarkableInputStream 88 * @see com.sun.star.io.MarkableOutputStream 89 */ 90 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 91 92 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();; 93 94 Object aPipe = null; 95 Object mostream = null; 96 Object mistream = null; 97 Object xConnect = null; 98 try { 99 aPipe = xMSF.createInstance("com.sun.star.io.Pipe"); 100 mistream = xMSF.createInstance("com.sun.star.io.MarkableInputStream"); 101 mostream = xMSF.createInstance("com.sun.star.io.MarkableOutputStream"); 102 xConnect = xMSF.createInstance("com.sun.star.io.DataInputStream"); 103 } catch(com.sun.star.uno.Exception e) { 104 e.printStackTrace(log); 105 throw new StatusException("Couldn't create instance", e) ; 106 } 107 108 // Creating construction : 109 // MarkableOutputStream -> Pipe -> MarkableInputStream 110 XActiveDataSource xdSmo = (XActiveDataSource) 111 UnoRuntime.queryInterface(XActiveDataSource.class, mostream); 112 113 XOutputStream PipeOut = (XOutputStream) 114 UnoRuntime.queryInterface(XOutputStream.class, aPipe); 115 XInputStream PipeIn = (XInputStream) 116 UnoRuntime.queryInterface(XInputStream.class, aPipe); 117 118 xdSmo.setOutputStream(PipeOut); 119 120 XActiveDataSink xmSi = (XActiveDataSink) 121 UnoRuntime.queryInterface(XActiveDataSink.class, mistream); 122 123 xmSi.setInputStream(PipeIn) ; 124 125 XInterface oObj = (XInterface) mistream; 126 127 byte[] byteData = new byte[] {1,2,3,4,5,6}; 128 129 log.println( "creating a new environment for object" ); 130 TestEnvironment tEnv = new TestEnvironment( oObj ); 131 132 // add a writer 133 tEnv.addObjRelation("StreamWriter", mostream); 134 // add a connectable 135 tEnv.addObjRelation("Connectable", xConnect); 136 // add an inputStream 137 tEnv.addObjRelation("InputStream", mistream); 138 tEnv.addObjRelation("ByteData", byteData); 139 140 return tEnv; 141 } // finish method getTestEnvironment 142 143 } 144 145