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