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 import java.util.Vector; 32 33 import lib.StatusException; 34 import lib.TestCase; 35 import lib.TestEnvironment; 36 import lib.TestParameters; 37 38 import com.sun.star.io.XActiveDataSink; 39 import com.sun.star.io.XActiveDataSource; 40 import com.sun.star.io.XInputStream; 41 import com.sun.star.io.XOutputStream; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 /** 47 * Test for object which is represented by service 48 * <code>com.sun.star.io.MarkableOutputStream</code>. <p> 49 * Object implements the following interfaces : 50 * <ul> 51 * <li> <code>com::sun::star::io::XMarkableStream</code></li> 52 * <li> <code>com::sun::star::io::XActiveDataSource</code></li> 53 * <li> <code>com::sun::star::io::XOutputStream</code></li> 54 * <li> <code>com::sun::star::io::XConnectable</code></li> 55 * </ul> 56 * @see com.sun.star.io.MarkableOutputStream 57 * @see com.sun.star.io.XMarkableStream 58 * @see com.sun.star.io.XActiveDataSource 59 * @see com.sun.star.io.XOutputStream 60 * @see com.sun.star.io.XConnectable 61 * @see ifc.io._XMarkableStream 62 * @see ifc.io._XActiveDataSource 63 * @see ifc.io._XOutputStream 64 * @see ifc.io._XConnectable 65 */ 66 public class MarkableOutputStream extends TestCase { 67 68 /** 69 * Creating a Testenvironment for the interfaces to be tested. 70 * Creates an instances of services <code>com.sun.star.io.Pipe</code>, 71 * <code>com.sun.star.io.MarkableInputStream</code> and 72 * <code>com.sun.star.io.MarkableOutputStream</code>. 73 * Plugs the created pipe as output stream for the created 74 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream 75 * for the created <code>MarkableInputStream</code>. 76 * Object relations created : 77 * <ul> 78 * <li> <code>'ByteData'</code> for 79 * {@link ifc.io._XOutputStream}(the data that should be written into 80 * the stream) </li> 81 * <li> <code>'StreamData'</code> for 82 * {@link ifc.io._XDataOutputStream}(the data that should be 83 * written into the stream) </li> 84 * <li> <code>'Connectable'</code> for 85 * {@link ifc.io._XConnectable} 86 * (another object that can be connected) </li> 87 * <li> <code>'OutputStream'</code> for 88 * {@link ifc.io._XActiveDataSource} 89 * (an input stream to set and get) </li> 90 * <li> <code>'XOutputStream.StreamChecker'</code> for 91 * {@link ifc.io._XOutputStream}( implementation of the interface 92 * ifc.io._XOutputStream.StreamChecker ) </li> 93 * </ul> 94 * @see com.sun.star.io.Pipe 95 * @see com.sun.star.io.MarkableInputStream 96 * @see com.sun.star.io.MarkableOutputStream 97 */ 98 public TestEnvironment createTestEnvironment( 99 TestParameters Param, PrintWriter log) throws StatusException { 100 101 XInterface oObj = null; 102 103 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF(); 104 Object aPipe = null; 105 Object mostream = null; 106 Object mistream = null; 107 XInterface aConnect; 108 109 try { 110 aPipe = xMSF.createInstance("com.sun.star.io.Pipe"); 111 mistream = xMSF.createInstance 112 ("com.sun.star.io.MarkableInputStream"); 113 mostream = xMSF.createInstance 114 ("com.sun.star.io.MarkableOutputStream"); 115 aConnect = (XInterface)xMSF.createInstance 116 ("com.sun.star.io.DataOutputStream"); 117 } catch(com.sun.star.uno.Exception e) { 118 e.printStackTrace(log); 119 throw new StatusException("Couldn't create instance", e) ; 120 } 121 122 // Creating construction : 123 // MarkableOutputStream -> Pipe -> MarkableInputStream 124 XActiveDataSource xdSmo = (XActiveDataSource) 125 UnoRuntime.queryInterface(XActiveDataSource.class, mostream); 126 127 final XOutputStream PipeOut = (XOutputStream) 128 UnoRuntime.queryInterface(XOutputStream.class,aPipe); 129 final XInputStream PipeIn = (XInputStream) 130 UnoRuntime.queryInterface(XInputStream.class,aPipe); 131 132 xdSmo.setOutputStream(PipeOut); 133 134 XActiveDataSink xmSi = (XActiveDataSink) 135 UnoRuntime.queryInterface(XActiveDataSink.class, mistream); 136 137 xmSi.setInputStream(PipeIn) ; 138 139 oObj = (XInterface) mostream; 140 141 // all data types for writing to an XDataInputStream 142 Vector data = new Vector() ; 143 data.add(new Boolean(true)) ; 144 data.add(new Byte((byte)123)) ; 145 data.add(new Character((char)1234)) ; 146 data.add(new Short((short)1234)) ; 147 data.add(new Integer(123456)) ; 148 data.add(new Float(1.234)) ; 149 data.add(new Double(1.23456)) ; 150 data.add("DataInputStream") ; 151 // information for writing to the pipe 152 byte[] byteData = new byte[] { 153 1, 2, 3, 4, 5, 6, 7, 8 } ; 154 155 log.println( "creating a new environment for object" ); 156 TestEnvironment tEnv = new TestEnvironment( oObj ); 157 158 tEnv.addObjRelation("StreamData", data); 159 tEnv.addObjRelation("ByteData", byteData); 160 tEnv.addObjRelation("OutputStream", aPipe); 161 tEnv.addObjRelation("Connectable", aConnect); 162 163 //add relation for io.XOutputStream 164 final XMultiServiceFactory msf = xMSF; 165 tEnv.addObjRelation("XOutputStream.StreamChecker", 166 new ifc.io._XOutputStream.StreamChecker() { 167 XInputStream xInStream = null; 168 public void resetStreams() { 169 if (xInStream != null) { 170 try { 171 xInStream.closeInput(); 172 xInStream = null; 173 } catch(com.sun.star.io.IOException e) { 174 } 175 } else { 176 try { 177 PipeOut.closeOutput(); 178 } catch(com.sun.star.io.IOException e) { 179 } 180 } 181 } 182 183 public XInputStream getInStream() { 184 resetStreams(); 185 try { 186 Object oInStream = msf.createInstance( 187 "com.sun.star.io.MarkableInputStream"); 188 xInStream = (XInputStream) UnoRuntime.queryInterface 189 (XInputStream.class, oInStream); 190 } catch(com.sun.star.uno.Exception e) { 191 return null; 192 } 193 194 XActiveDataSink xDataSink = (XActiveDataSink) 195 UnoRuntime.queryInterface( 196 XActiveDataSink.class, xInStream); 197 xDataSink.setInputStream(PipeIn); 198 199 return xInStream; 200 } 201 }); 202 203 return tEnv; 204 } // finish method getTestEnvironment 205 206 } 207 208