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