1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._streams.uno; 25 26 import com.sun.star.io.XActiveDataSink; 27 import com.sun.star.io.XActiveDataSource; 28 import com.sun.star.io.XDataOutputStream; 29 import com.sun.star.io.XInputStream; 30 import com.sun.star.io.XOutputStream; 31 import com.sun.star.lang.XMultiServiceFactory; 32 import com.sun.star.uno.UnoRuntime; 33 import com.sun.star.uno.XInterface; 34 import java.io.PrintWriter; 35 import java.util.Vector; 36 import lib.StatusException; 37 import lib.TestCase; 38 import lib.TestEnvironment; 39 import lib.TestParameters; 40 41 /** 42 * Test for object which is represented by service 43 * <code>com.sun.star.io.DataInputStream</code>. 44 * <ul> 45 * <li> <code>com::sun::star::io::XInputStream</code></li> 46 * <li> <code>com::sun::star::io::XDataInputStream</code></li> 47 * <li> <code>com::sun::star::io::XConnectable</code></li> 48 * <li> <code>com::sun::star::io::XActiveDataSink</code></li> 49 * </ul> 50 * @see com.sun.star.io.DataInputStream 51 * @see com.sun.star.io.XInputStream 52 * @see com.sun.star.io.XDataInputStream 53 * @see com.sun.star.io.XConnectable 54 * @see com.sun.star.io.XActiveDataSink 55 * @see ifc.io._XInputStream 56 * @see ifc.io._XDataInputStream 57 * @see ifc.io._XConnectable 58 * @see ifc.io._XActiveDataSink 59 */ 60 public class DataInputStream extends TestCase { 61 62 /** 63 * Creates a Testenvironment for the interfaces to be tested. 64 * Creates <code>com.sun.star.io.DataInputStream</code> object, 65 * connects it to <code>com.sun.star.io.DataOutputStream</code> 66 * through <code>com.sun.star.io.Pipe</code>. All of possible data 67 * types are written into <code>DataOutputStream</code>. 68 * Object relations created : 69 * <ul> 70 * <li> <code>'StreamData'</code> for 71 * {@link ifc.io._XDataInputStream}(the data that should be written into 72 * the stream) </li> 73 * <li> <code>'ByteData'</code> for 74 * {@link ifc.io._XInputStream}(the data that should be written into 75 * the stream) </li> 76 * <li> <code>'StreamWriter'</code> for 77 * {@link ifc.io._XDataInputStream} 78 * {@link ifc.io._XInputStream}(a stream to write data to) </li> 79 * <li> <code>'Connectable'</code> for 80 * {@link ifc.io._XConnectable}(another object that can be connected) </li> 81 * <li> <code>'InputStream'</code> for 82 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li> 83 * </ul> 84 */ createTestEnvironment(TestParameters Param, PrintWriter log)85 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 86 87 Object oInterface = null; 88 89 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF(); 90 try { 91 oInterface = xMSF.createInstance("com.sun.star.io.DataInputStream"); 92 } catch(com.sun.star.uno.Exception e) { 93 e.printStackTrace(log); 94 throw new StatusException("Couldn't create instance", e); 95 } 96 97 XInterface oObj = (XInterface) oInterface; 98 99 // creating and connecting DataOutputStream to the 100 // DataInputStream created through the Pipe 101 XActiveDataSink xDataSink = (XActiveDataSink) 102 UnoRuntime.queryInterface(XActiveDataSink.class, oObj); 103 104 XInterface oPipe = null; 105 try { 106 oPipe = (XInterface) 107 xMSF.createInstance("com.sun.star.io.Pipe"); 108 } catch(com.sun.star.uno.Exception e) { 109 e.printStackTrace(log); 110 throw new StatusException("Couldn't create instance", e); 111 } 112 113 XInputStream xPipeInput = (XInputStream) 114 UnoRuntime.queryInterface(XInputStream.class, oPipe); 115 XOutputStream xPipeOutput = (XOutputStream) 116 UnoRuntime.queryInterface(XOutputStream.class, oPipe); 117 118 XInterface oDataOutput = null; 119 try { 120 oDataOutput = (XInterface) 121 xMSF.createInstance("com.sun.star.io.DataOutputStream"); 122 } catch(com.sun.star.uno.Exception e) { 123 e.printStackTrace(log); 124 throw new StatusException("Couldn't create instance", e); 125 } 126 127 XDataOutputStream xDataOutput = (XDataOutputStream) 128 UnoRuntime.queryInterface(XDataOutputStream.class, oDataOutput) ; 129 XActiveDataSource xDataSource = (XActiveDataSource) 130 UnoRuntime.queryInterface(XActiveDataSource.class, oDataOutput) ; 131 132 xDataSource.setOutputStream(xPipeOutput) ; 133 xDataSink.setInputStream(xPipeInput) ; 134 135 // all data types for writing to an XDataInputStream 136 Vector data = new Vector() ; 137 data.add(new Boolean(true)) ; 138 data.add(new Byte((byte)123)) ; 139 data.add(new Character((char)1234)) ; 140 data.add(new Short((short)1234)) ; 141 data.add(new Integer(123456)) ; 142 data.add(new Float(1.234)) ; 143 data.add(new Double(1.23456)) ; 144 data.add("DataInputStream") ; 145 // information for writing to the pipe 146 byte[] byteData = new byte[] { 147 1, 2, 3, 4, 5, 6, 7, 8 } ; 148 149 // createing a connectable object for XConnectable interface 150 XInterface xConnect = null; 151 try { 152 xConnect = (XInterface)xMSF.createInstance( 153 "com.sun.star.io.DataInputStream") ; 154 } catch (Exception e) { 155 log.println("Can't create DataInputStream"); 156 e.printStackTrace(log); 157 throw new StatusException("Can't create DataInputStream", e); 158 } 159 160 // creating an input stream to set in XActiveDataSink 161 XInterface oDataInput = null; 162 try { 163 oDataInput = (XInterface) xMSF.createInstance( 164 "com.sun.star.io.Pipe" ); 165 } catch (com.sun.star.uno.Exception e) { 166 log.println("Can't create new in stream") ; 167 e.printStackTrace(log) ; 168 throw new StatusException("Can't create input stream", e) ; 169 } 170 171 172 log.println("creating a new environment for object"); 173 TestEnvironment tEnv = new TestEnvironment( oObj ); 174 175 // adding sequence of data that must be read 176 // by XDataInputStream interface methods 177 tEnv.addObjRelation("StreamData", data) ; 178 // add a writer 179 tEnv.addObjRelation("StreamWriter", xDataOutput); 180 // add a connectable 181 tEnv.addObjRelation("Connectable", xConnect); 182 // add an inputStream 183 tEnv.addObjRelation("InputStream", oDataInput); 184 tEnv.addObjRelation("ByteData", byteData); 185 186 return tEnv; 187 } // finish method getTestEnvironment 188 189 } 190 191