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