1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._streams.uno;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.io.XActiveDataSink;
27cdf0e10cSrcweir import com.sun.star.io.XActiveDataSource;
28cdf0e10cSrcweir import com.sun.star.io.XDataOutputStream;
29cdf0e10cSrcweir import com.sun.star.io.XInputStream;
30cdf0e10cSrcweir import com.sun.star.io.XOutputStream;
31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
32cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
33cdf0e10cSrcweir import com.sun.star.uno.XInterface;
34cdf0e10cSrcweir import java.io.PrintWriter;
35cdf0e10cSrcweir import java.util.Vector;
36cdf0e10cSrcweir import lib.StatusException;
37cdf0e10cSrcweir import lib.TestCase;
38cdf0e10cSrcweir import lib.TestEnvironment;
39cdf0e10cSrcweir import lib.TestParameters;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir /**
42cdf0e10cSrcweir * Test for object which is represented by service
43cdf0e10cSrcweir * <code>com.sun.star.io.DataInputStream</code>.
44cdf0e10cSrcweir * <ul>
45cdf0e10cSrcweir *  <li> <code>com::sun::star::io::XInputStream</code></li>
46cdf0e10cSrcweir *  <li> <code>com::sun::star::io::XDataInputStream</code></li>
47cdf0e10cSrcweir *  <li> <code>com::sun::star::io::XConnectable</code></li>
48cdf0e10cSrcweir *  <li> <code>com::sun::star::io::XActiveDataSink</code></li>
49cdf0e10cSrcweir * </ul>
50cdf0e10cSrcweir * @see com.sun.star.io.DataInputStream
51cdf0e10cSrcweir * @see com.sun.star.io.XInputStream
52cdf0e10cSrcweir * @see com.sun.star.io.XDataInputStream
53cdf0e10cSrcweir * @see com.sun.star.io.XConnectable
54cdf0e10cSrcweir * @see com.sun.star.io.XActiveDataSink
55cdf0e10cSrcweir * @see ifc.io._XInputStream
56cdf0e10cSrcweir * @see ifc.io._XDataInputStream
57cdf0e10cSrcweir * @see ifc.io._XConnectable
58cdf0e10cSrcweir * @see ifc.io._XActiveDataSink
59cdf0e10cSrcweir */
60cdf0e10cSrcweir public class DataInputStream extends TestCase {
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     /**
63cdf0e10cSrcweir     * Creates a Testenvironment for the interfaces to be tested.
64cdf0e10cSrcweir     * Creates <code>com.sun.star.io.DataInputStream</code> object,
65cdf0e10cSrcweir     * connects it to <code>com.sun.star.io.DataOutputStream</code>
66cdf0e10cSrcweir     * through <code>com.sun.star.io.Pipe</code>. All of possible data
67cdf0e10cSrcweir     * types are written into <code>DataOutputStream</code>.
68cdf0e10cSrcweir     * Object relations created :
69cdf0e10cSrcweir     * <ul>
70cdf0e10cSrcweir     *  <li> <code>'StreamData'</code> for
71cdf0e10cSrcweir     *      {@link ifc.io._XDataInputStream}(the data that should be written into
72cdf0e10cSrcweir     *      the stream) </li>
73cdf0e10cSrcweir     *  <li> <code>'ByteData'</code> for
74cdf0e10cSrcweir     *      {@link ifc.io._XInputStream}(the data that should be written into
75cdf0e10cSrcweir     *      the stream) </li>
76cdf0e10cSrcweir     *  <li> <code>'StreamWriter'</code> for
77cdf0e10cSrcweir     *      {@link ifc.io._XDataInputStream}
78cdf0e10cSrcweir     *      {@link ifc.io._XInputStream}(a stream to write data to) </li>
79cdf0e10cSrcweir     *  <li> <code>'Connectable'</code> for
80cdf0e10cSrcweir     *      {@link ifc.io._XConnectable}(another object that can be connected) </li>
81cdf0e10cSrcweir     *  <li> <code>'InputStream'</code> for
82cdf0e10cSrcweir     *      {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
83cdf0e10cSrcweir     * </ul>
84cdf0e10cSrcweir     */
85cdf0e10cSrcweir     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         Object oInterface = null;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();;
90cdf0e10cSrcweir         try {
91cdf0e10cSrcweir             oInterface = xMSF.createInstance("com.sun.star.io.DataInputStream");
92cdf0e10cSrcweir         } catch(com.sun.star.uno.Exception e) {
93cdf0e10cSrcweir             e.printStackTrace(log);
94cdf0e10cSrcweir             throw new StatusException("Couldn't create instance", e);
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         XInterface oObj = (XInterface) oInterface;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         // creating and connecting DataOutputStream to the
100cdf0e10cSrcweir         // DataInputStream created through the Pipe
101cdf0e10cSrcweir         XActiveDataSink xDataSink = (XActiveDataSink)
102cdf0e10cSrcweir             UnoRuntime.queryInterface(XActiveDataSink.class, oObj);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         XInterface oPipe = null;
105cdf0e10cSrcweir         try {
106cdf0e10cSrcweir             oPipe = (XInterface)
107cdf0e10cSrcweir                 xMSF.createInstance("com.sun.star.io.Pipe");
108cdf0e10cSrcweir         } catch(com.sun.star.uno.Exception e) {
109cdf0e10cSrcweir             e.printStackTrace(log);
110cdf0e10cSrcweir             throw new StatusException("Couldn't create instance", e);
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         XInputStream xPipeInput = (XInputStream)
114cdf0e10cSrcweir             UnoRuntime.queryInterface(XInputStream.class, oPipe);
115cdf0e10cSrcweir         XOutputStream xPipeOutput = (XOutputStream)
116cdf0e10cSrcweir             UnoRuntime.queryInterface(XOutputStream.class, oPipe);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         XInterface oDataOutput = null;
119cdf0e10cSrcweir         try {
120cdf0e10cSrcweir             oDataOutput = (XInterface)
121cdf0e10cSrcweir                 xMSF.createInstance("com.sun.star.io.DataOutputStream");
122cdf0e10cSrcweir         } catch(com.sun.star.uno.Exception e) {
123cdf0e10cSrcweir             e.printStackTrace(log);
124cdf0e10cSrcweir             throw new StatusException("Couldn't create instance", e);
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         XDataOutputStream xDataOutput = (XDataOutputStream)
128cdf0e10cSrcweir             UnoRuntime.queryInterface(XDataOutputStream.class, oDataOutput) ;
129cdf0e10cSrcweir         XActiveDataSource xDataSource = (XActiveDataSource)
130cdf0e10cSrcweir             UnoRuntime.queryInterface(XActiveDataSource.class, oDataOutput) ;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         xDataSource.setOutputStream(xPipeOutput) ;
133cdf0e10cSrcweir         xDataSink.setInputStream(xPipeInput) ;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         // all data types for writing to an XDataInputStream
136cdf0e10cSrcweir         Vector data = new Vector() ;
137cdf0e10cSrcweir         data.add(new Boolean(true)) ;
138cdf0e10cSrcweir         data.add(new Byte((byte)123)) ;
139cdf0e10cSrcweir         data.add(new Character((char)1234)) ;
140cdf0e10cSrcweir         data.add(new Short((short)1234)) ;
141cdf0e10cSrcweir         data.add(new Integer(123456)) ;
142cdf0e10cSrcweir         data.add(new Float(1.234)) ;
143cdf0e10cSrcweir         data.add(new Double(1.23456)) ;
144cdf0e10cSrcweir         data.add("DataInputStream") ;
145cdf0e10cSrcweir         // information for writing to the pipe
146cdf0e10cSrcweir         byte[] byteData = new byte[] {
147cdf0e10cSrcweir             1, 2, 3, 4, 5, 6, 7, 8 } ;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         // createing a connectable object for XConnectable interface
150cdf0e10cSrcweir         XInterface xConnect = null;
151cdf0e10cSrcweir         try {
152cdf0e10cSrcweir             xConnect = (XInterface)xMSF.createInstance(
153cdf0e10cSrcweir                                     "com.sun.star.io.DataInputStream") ;
154cdf0e10cSrcweir         } catch (Exception e) {
155cdf0e10cSrcweir             log.println("Can't create DataInputStream");
156cdf0e10cSrcweir             e.printStackTrace(log);
157cdf0e10cSrcweir             throw new StatusException("Can't create DataInputStream", e);
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         // creating an input stream to set in XActiveDataSink
161cdf0e10cSrcweir         XInterface oDataInput = null;
162cdf0e10cSrcweir         try {
163cdf0e10cSrcweir             oDataInput = (XInterface) xMSF.createInstance(
164cdf0e10cSrcweir                                         "com.sun.star.io.Pipe" );
165cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
166cdf0e10cSrcweir             log.println("Can't create new in stream") ;
167cdf0e10cSrcweir             e.printStackTrace(log) ;
168cdf0e10cSrcweir             throw new StatusException("Can't create input stream", e) ;
169cdf0e10cSrcweir         }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         log.println("creating a new environment for object");
173cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         // adding sequence of data that must be read
176cdf0e10cSrcweir         // by XDataInputStream interface methods
177cdf0e10cSrcweir         tEnv.addObjRelation("StreamData", data) ;
178cdf0e10cSrcweir         // add a writer
179cdf0e10cSrcweir         tEnv.addObjRelation("StreamWriter", xDataOutput);
180cdf0e10cSrcweir         // add a connectable
181cdf0e10cSrcweir         tEnv.addObjRelation("Connectable", xConnect);
182cdf0e10cSrcweir         // add an inputStream
183cdf0e10cSrcweir         tEnv.addObjRelation("InputStream", oDataInput);
184cdf0e10cSrcweir         tEnv.addObjRelation("ByteData", byteData);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         return tEnv;
187cdf0e10cSrcweir     } // finish method getTestEnvironment
188cdf0e10cSrcweir 
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
191