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