bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _streams / uno / DataInputStream.java
blob63eef1a645b1ed02c4175234251f208f18003894
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._streams.uno;
21 import com.sun.star.io.XActiveDataSink;
22 import com.sun.star.io.XActiveDataSource;
23 import com.sun.star.io.XDataOutputStream;
24 import com.sun.star.io.XInputStream;
25 import com.sun.star.io.XOutputStream;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XInterface;
29 import java.io.PrintWriter;
30 import java.util.ArrayList;
31 import lib.StatusException;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.io.DataInputStream</code>.
39 * <ul>
40 * <li> <code>com::sun::star::io::XInputStream</code></li>
41 * <li> <code>com::sun::star::io::XDataInputStream</code></li>
42 * <li> <code>com::sun::star::io::XConnectable</code></li>
43 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
44 * </ul>
45 * @see com.sun.star.io.DataInputStream
46 * @see com.sun.star.io.XInputStream
47 * @see com.sun.star.io.XDataInputStream
48 * @see com.sun.star.io.XConnectable
49 * @see com.sun.star.io.XActiveDataSink
50 * @see ifc.io._XInputStream
51 * @see ifc.io._XDataInputStream
52 * @see ifc.io._XConnectable
53 * @see ifc.io._XActiveDataSink
55 public class DataInputStream extends TestCase {
57 /**
58 * Creates a Testenvironment for the interfaces to be tested.
59 * Creates <code>com.sun.star.io.DataInputStream</code> object,
60 * connects it to <code>com.sun.star.io.DataOutputStream</code>
61 * through <code>com.sun.star.io.Pipe</code>. All of possible data
62 * types are written into <code>DataOutputStream</code>.
63 * Object relations created :
64 * <ul>
65 * <li> <code>'StreamData'</code> for
66 * {@link ifc.io._XDataInputStream}(the data that should be written into
67 * the stream) </li>
68 * <li> <code>'ByteData'</code> for
69 * {@link ifc.io._XInputStream}(the data that should be written into
70 * the stream) </li>
71 * <li> <code>'StreamWriter'</code> for
72 * {@link ifc.io._XDataInputStream}
73 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
74 * <li> <code>'Connectable'</code> for
75 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
76 * <li> <code>'InputStream'</code> for
77 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
78 * </ul>
80 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
82 Object oInterface = null;
84 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
85 try {
86 oInterface = xMSF.createInstance("com.sun.star.io.DataInputStream");
87 } catch(com.sun.star.uno.Exception e) {
88 e.printStackTrace(log);
89 throw new StatusException("Couldn't create instance", e);
92 XInterface oObj = (XInterface) oInterface;
94 // creating and connecting DataOutputStream to the
95 // DataInputStream created through the Pipe
96 XActiveDataSink xDataSink = UnoRuntime.queryInterface(XActiveDataSink.class, oObj);
98 XInterface oPipe = null;
99 try {
100 oPipe = (XInterface)
101 xMSF.createInstance("com.sun.star.io.Pipe");
102 } catch(com.sun.star.uno.Exception e) {
103 e.printStackTrace(log);
104 throw new StatusException("Couldn't create instance", e);
107 XInputStream xPipeInput = UnoRuntime.queryInterface(XInputStream.class, oPipe);
108 XOutputStream xPipeOutput = UnoRuntime.queryInterface(XOutputStream.class, oPipe);
110 XInterface oDataOutput = null;
111 try {
112 oDataOutput = (XInterface)
113 xMSF.createInstance("com.sun.star.io.DataOutputStream");
114 } catch(com.sun.star.uno.Exception e) {
115 e.printStackTrace(log);
116 throw new StatusException("Couldn't create instance", e);
119 XDataOutputStream xDataOutput = UnoRuntime.queryInterface(XDataOutputStream.class, oDataOutput) ;
120 XActiveDataSource xDataSource = UnoRuntime.queryInterface(XActiveDataSource.class, oDataOutput) ;
122 xDataSource.setOutputStream(xPipeOutput) ;
123 xDataSink.setInputStream(xPipeInput) ;
125 // all data types for writing to an XDataInputStream
126 ArrayList<Object> data = new ArrayList<Object>() ;
127 data.add(new Boolean(true)) ;
128 data.add(new Byte((byte)123)) ;
129 data.add(new Character((char)1234)) ;
130 data.add(new Short((short)1234)) ;
131 data.add(new Integer(123456)) ;
132 data.add(new Float(1.234)) ;
133 data.add(new Double(1.23456)) ;
134 data.add("DataInputStream") ;
135 // information for writing to the pipe
136 byte[] byteData = new byte[] {
137 1, 2, 3, 4, 5, 6, 7, 8 } ;
139 // createing a connectable object for XConnectable interface
140 XInterface xConnect = null;
141 try {
142 xConnect = (XInterface)xMSF.createInstance(
143 "com.sun.star.io.DataInputStream") ;
144 } catch (Exception e) {
145 log.println("Can't create DataInputStream");
146 e.printStackTrace(log);
147 throw new StatusException("Can't create DataInputStream", e);
150 // creating an input stream to set in XActiveDataSink
151 XInterface oDataInput = null;
152 try {
153 oDataInput = (XInterface) xMSF.createInstance(
154 "com.sun.star.io.Pipe" );
155 } catch (com.sun.star.uno.Exception e) {
156 log.println("Can't create new in stream") ;
157 e.printStackTrace(log) ;
158 throw new StatusException("Can't create input stream", e) ;
162 log.println("creating a new environment for object");
163 TestEnvironment tEnv = new TestEnvironment( oObj );
165 // adding sequence of data that must be read
166 // by XDataInputStream interface methods
167 tEnv.addObjRelation("StreamData", data) ;
168 // add a writer
169 tEnv.addObjRelation("StreamWriter", xDataOutput);
170 // add a connectable
171 tEnv.addObjRelation("Connectable", xConnect);
172 // add an inputStream
173 tEnv.addObjRelation("InputStream", oDataInput);
174 tEnv.addObjRelation("ByteData", byteData);
176 return tEnv;
177 } // finish method getTestEnvironment