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.XDataOutputStream; 41 import com.sun.star.io.XInputStream; 42 import com.sun.star.io.XOutputStream; 43 import com.sun.star.lang.XMultiServiceFactory; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.uno.XInterface; 46 47 /** 48 * Test for object which is represented by service 49 * <code>com.sun.star.io.DataInputStream</code>. 50 * <ul> 51 * <li> <code>com::sun::star::io::XInputStream</code></li> 52 * <li> <code>com::sun::star::io::XDataInputStream</code></li> 53 * <li> <code>com::sun::star::io::XConnectable</code></li> 54 * <li> <code>com::sun::star::io::XActiveDataSink</code></li> 55 * </ul> 56 * @see com.sun.star.io.DataInputStream 57 * @see com.sun.star.io.XInputStream 58 * @see com.sun.star.io.XDataInputStream 59 * @see com.sun.star.io.XConnectable 60 * @see com.sun.star.io.XActiveDataSink 61 * @see ifc.io._XInputStream 62 * @see ifc.io._XDataInputStream 63 * @see ifc.io._XConnectable 64 * @see ifc.io._XActiveDataSink 65 */ 66 public class DataInputStream extends TestCase { 67 68 /** 69 * Creates a Testenvironment for the interfaces to be tested. 70 * Creates <code>com.sun.star.io.DataInputStream</code> object, 71 * connects it to <code>com.sun.star.io.DataOutputStream</code> 72 * through <code>com.sun.star.io.Pipe</code>. All of possible data 73 * types are written into <code>DataOutputStream</code>. 74 * Object relations created : 75 * <ul> 76 * <li> <code>'StreamData'</code> for 77 * {@link ifc.io._XDataInputStream}(the data that should be written into 78 * the stream) </li> 79 * <li> <code>'ByteData'</code> for 80 * {@link ifc.io._XInputStream}(the data that should be written into 81 * the stream) </li> 82 * <li> <code>'StreamWriter'</code> for 83 * {@link ifc.io._XDataInputStream} 84 * {@link ifc.io._XInputStream}(a stream to write data to) </li> 85 * <li> <code>'Connectable'</code> for 86 * {@link ifc.io._XConnectable}(another object that can be connected) </li> 87 * <li> <code>'InputStream'</code> for 88 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li> 89 * </ul> 90 */ 91 public TestEnvironment createTestEnvironment( 92 TestParameters Param, PrintWriter log) throws StatusException { 93 94 Object oInterface = null; 95 96 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();; 97 try { 98 oInterface = xMSF.createInstance("com.sun.star.io.DataInputStream"); 99 } catch(com.sun.star.uno.Exception e) { 100 e.printStackTrace(log); 101 throw new StatusException("Couldn't create instance", e); 102 } 103 104 XInterface oObj = (XInterface) oInterface; 105 106 // creating and connecting DataOutputStream to the 107 // DataInputStream created through the Pipe 108 XActiveDataSink xDataSink = (XActiveDataSink) 109 UnoRuntime.queryInterface(XActiveDataSink.class, oObj); 110 111 XInterface oPipe = null; 112 try { 113 oPipe = (XInterface) 114 xMSF.createInstance("com.sun.star.io.Pipe"); 115 } catch(com.sun.star.uno.Exception e) { 116 e.printStackTrace(log); 117 throw new StatusException("Couldn't create instance", e); 118 } 119 120 XInputStream xPipeInput = (XInputStream) 121 UnoRuntime.queryInterface(XInputStream.class, oPipe); 122 XOutputStream xPipeOutput = (XOutputStream) 123 UnoRuntime.queryInterface(XOutputStream.class, oPipe); 124 125 XInterface oDataOutput = null; 126 try { 127 oDataOutput = (XInterface) 128 xMSF.createInstance("com.sun.star.io.DataOutputStream"); 129 } catch(com.sun.star.uno.Exception e) { 130 e.printStackTrace(log); 131 throw new StatusException("Couldn't create instance", e); 132 } 133 134 XDataOutputStream xDataOutput = (XDataOutputStream) 135 UnoRuntime.queryInterface(XDataOutputStream.class, oDataOutput) ; 136 XActiveDataSource xDataSource = (XActiveDataSource) 137 UnoRuntime.queryInterface(XActiveDataSource.class, oDataOutput) ; 138 139 xDataSource.setOutputStream(xPipeOutput) ; 140 xDataSink.setInputStream(xPipeInput) ; 141 142 // all data types for writing to an XDataInputStream 143 Vector data = new Vector() ; 144 data.add(new Boolean(true)) ; 145 data.add(new Byte((byte)123)) ; 146 data.add(new Character((char)1234)) ; 147 data.add(new Short((short)1234)) ; 148 data.add(new Integer(123456)) ; 149 data.add(new Float(1.234)) ; 150 data.add(new Double(1.23456)) ; 151 data.add("DataInputStream") ; 152 // information for writing to the pipe 153 byte[] byteData = new byte[] { 154 1, 2, 3, 4, 5, 6, 7, 8 } ; 155 156 // createing a connectable object for XConnectable interface 157 XInterface xConnect = null; 158 try { 159 xConnect = (XInterface)xMSF.createInstance( 160 "com.sun.star.io.DataInputStream") ; 161 } catch (Exception e) { 162 log.println("Can't create DataInputStream"); 163 e.printStackTrace(log); 164 throw new StatusException("Can't create DataInputStream", e); 165 } 166 167 // creating an input stream to set in XActiveDataSink 168 XInterface oDataInput = null; 169 try { 170 oDataInput = (XInterface) xMSF.createInstance( 171 "com.sun.star.io.Pipe" ); 172 } catch (com.sun.star.uno.Exception e) { 173 log.println("Can't create new in stream") ; 174 e.printStackTrace(log) ; 175 throw new StatusException("Can't create input stream", e) ; 176 } 177 178 179 log.println("creating a new environment for object"); 180 TestEnvironment tEnv = new TestEnvironment( oObj ); 181 182 // adding sequence of data that must be read 183 // by XDataInputStream interface methods 184 tEnv.addObjRelation("StreamData", data) ; 185 // add a writer 186 tEnv.addObjRelation("StreamWriter", xDataOutput); 187 // add a connectable 188 tEnv.addObjRelation("Connectable", xConnect); 189 // add an inputStream 190 tEnv.addObjRelation("InputStream", oDataInput); 191 tEnv.addObjRelation("ByteData", byteData); 192 193 return tEnv; 194 } // finish method getTestEnvironment 195 196 } 197 198