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