Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _stm / DataInputStream.java
blobd307f9c8c5dcbe1bf76bf965c9810a3ca843f80d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DataInputStream.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._stm;
33 import java.io.PrintWriter;
34 import java.util.Vector;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
41 import com.sun.star.io.XActiveDataSink;
42 import com.sun.star.io.XActiveDataSource;
43 import com.sun.star.io.XDataOutputStream;
44 import com.sun.star.io.XInputStream;
45 import com.sun.star.io.XOutputStream;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
50 /**
51 * Test for object which is represented by service
52 * <code>com.sun.star.io.DataInputStream</code>.
53 * <ul>
54 * <li> <code>com::sun::star::io::XInputStream</code></li>
55 * <li> <code>com::sun::star::io::XDataInputStream</code></li>
56 * <li> <code>com::sun::star::io::XConnectable</code></li>
57 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
58 * </ul>
59 * @see com.sun.star.io.DataInputStream
60 * @see com.sun.star.io.XInputStream
61 * @see com.sun.star.io.XDataInputStream
62 * @see com.sun.star.io.XConnectable
63 * @see com.sun.star.io.XActiveDataSink
64 * @see ifc.io._XInputStream
65 * @see ifc.io._XDataInputStream
66 * @see ifc.io._XConnectable
67 * @see ifc.io._XActiveDataSink
69 public class DataInputStream extends TestCase {
71 /**
72 * Creates a Testenvironment for the interfaces to be tested.
73 * Creates <code>com.sun.star.io.DataInputStream</code> object,
74 * connects it to <code>com.sun.star.io.DataOutputStream</code>
75 * through <code>com.sun.star.io.Pipe</code>. All of possible data
76 * types are written into <code>DataOutputStream</code>.
77 * Object relations created :
78 * <ul>
79 * <li> <code>'StreamData'</code> for
80 * {@link ifc.io._XDataInputStream}(the data that should be written into
81 * the stream) </li>
82 * <li> <code>'ByteData'</code> for
83 * {@link ifc.io._XInputStream}(the data that should be written into
84 * the stream) </li>
85 * <li> <code>'StreamWriter'</code> for
86 * {@link ifc.io._XDataInputStream}
87 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
88 * <li> <code>'Connectable'</code> for
89 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
90 * <li> <code>'InputStream'</code> for
91 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
92 * </ul>
94 public TestEnvironment createTestEnvironment(
95 TestParameters Param, PrintWriter log) throws StatusException {
97 Object oInterface = null;
99 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();;
100 try {
101 oInterface = xMSF.createInstance("com.sun.star.io.DataInputStream");
102 } catch(com.sun.star.uno.Exception e) {
103 e.printStackTrace(log);
104 throw new StatusException("Couldn't create instance", e);
107 XInterface oObj = (XInterface) oInterface;
109 // creating and connecting DataOutputStream to the
110 // DataInputStream created through the Pipe
111 XActiveDataSink xDataSink = (XActiveDataSink)
112 UnoRuntime.queryInterface(XActiveDataSink.class, oObj);
114 XInterface oPipe = null;
115 try {
116 oPipe = (XInterface)
117 xMSF.createInstance("com.sun.star.io.Pipe");
118 } catch(com.sun.star.uno.Exception e) {
119 e.printStackTrace(log);
120 throw new StatusException("Couldn't create instance", e);
123 XInputStream xPipeInput = (XInputStream)
124 UnoRuntime.queryInterface(XInputStream.class, oPipe);
125 XOutputStream xPipeOutput = (XOutputStream)
126 UnoRuntime.queryInterface(XOutputStream.class, oPipe);
128 XInterface oDataOutput = null;
129 try {
130 oDataOutput = (XInterface)
131 xMSF.createInstance("com.sun.star.io.DataOutputStream");
132 } catch(com.sun.star.uno.Exception e) {
133 e.printStackTrace(log);
134 throw new StatusException("Couldn't create instance", e);
137 XDataOutputStream xDataOutput = (XDataOutputStream)
138 UnoRuntime.queryInterface(XDataOutputStream.class, oDataOutput) ;
139 XActiveDataSource xDataSource = (XActiveDataSource)
140 UnoRuntime.queryInterface(XActiveDataSource.class, oDataOutput) ;
142 xDataSource.setOutputStream(xPipeOutput) ;
143 xDataSink.setInputStream(xPipeInput) ;
145 // all data types for writing to an XDataInputStream
146 Vector data = new Vector() ;
147 data.add(new Boolean(true)) ;
148 data.add(new Byte((byte)123)) ;
149 data.add(new Character((char)1234)) ;
150 data.add(new Short((short)1234)) ;
151 data.add(new Integer(123456)) ;
152 data.add(new Float(1.234)) ;
153 data.add(new Double(1.23456)) ;
154 data.add("DataInputStream") ;
155 // information for writing to the pipe
156 byte[] byteData = new byte[] {
157 1, 2, 3, 4, 5, 6, 7, 8 } ;
159 // createing a connectable object for XConnectable interface
160 XInterface xConnect = null;
161 try {
162 xConnect = (XInterface)xMSF.createInstance(
163 "com.sun.star.io.DataInputStream") ;
164 } catch (Exception e) {
165 log.println("Can't create DataInputStream");
166 e.printStackTrace(log);
167 throw new StatusException("Can't create DataInputStream", e);
170 // creating an input stream to set in XActiveDataSink
171 XInterface oDataInput = null;
172 try {
173 oDataInput = (XInterface) xMSF.createInstance(
174 "com.sun.star.io.Pipe" );
175 } catch (com.sun.star.uno.Exception e) {
176 log.println("Can't create new in stream") ;
177 e.printStackTrace(log) ;
178 throw new StatusException("Can't create input stream", e) ;
182 log.println("creating a new environment for object");
183 TestEnvironment tEnv = new TestEnvironment( oObj );
185 // adding sequence of data that must be read
186 // by XDataInputStream interface methods
187 tEnv.addObjRelation("StreamData", data) ;
188 // add a writer
189 tEnv.addObjRelation("StreamWriter", xDataOutput);
190 // add a connectable
191 tEnv.addObjRelation("Connectable", xConnect);
192 // add an inputStream
193 tEnv.addObjRelation("InputStream", oDataInput);
194 tEnv.addObjRelation("ByteData", byteData);
196 return tEnv;
197 } // finish method getTestEnvironment