Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _stm / DataInputStream.java
blob1922f1ef277f2a6cc65b3f5685090f28ba88f6f7
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._stm;
21 import java.io.PrintWriter;
22 import java.util.ArrayList;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
29 import com.sun.star.io.XActiveDataSink;
30 import com.sun.star.io.XActiveDataSource;
31 import com.sun.star.io.XDataOutputStream;
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;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.io.DataInputStream</code>.
41 * <ul>
42 * <li> <code>com::sun::star::io::XInputStream</code></li>
43 * <li> <code>com::sun::star::io::XDataInputStream</code></li>
44 * <li> <code>com::sun::star::io::XConnectable</code></li>
45 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
46 * </ul>
47 * @see com.sun.star.io.DataInputStream
48 * @see com.sun.star.io.XInputStream
49 * @see com.sun.star.io.XDataInputStream
50 * @see com.sun.star.io.XConnectable
51 * @see com.sun.star.io.XActiveDataSink
52 * @see ifc.io._XInputStream
53 * @see ifc.io._XDataInputStream
54 * @see ifc.io._XConnectable
55 * @see ifc.io._XActiveDataSink
57 public class DataInputStream extends TestCase {
59 /**
60 * Creates a Testenvironment for the interfaces to be tested.
61 * Creates <code>com.sun.star.io.DataInputStream</code> object,
62 * connects it to <code>com.sun.star.io.DataOutputStream</code>
63 * through <code>com.sun.star.io.Pipe</code>. All of possible data
64 * types are written into <code>DataOutputStream</code>.
65 * Object relations created :
66 * <ul>
67 * <li> <code>'StreamData'</code> for
68 * {@link ifc.io._XDataInputStream}(the data that should be written into
69 * the stream) </li>
70 * <li> <code>'ByteData'</code> for
71 * {@link ifc.io._XInputStream}(the data that should be written into
72 * the stream) </li>
73 * <li> <code>'StreamWriter'</code> for
74 * {@link ifc.io._XDataInputStream}
75 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
76 * <li> <code>'Connectable'</code> for
77 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
78 * <li> <code>'InputStream'</code> for
79 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
80 * </ul>
82 @Override
83 public TestEnvironment createTestEnvironment(
84 TestParameters Param, PrintWriter log) throws StatusException {
86 Object oInterface = null;
88 XMultiServiceFactory xMSF = Param.getMSF();
89 try {
90 oInterface = xMSF.createInstance("com.sun.star.io.DataInputStream");
91 } catch(com.sun.star.uno.Exception e) {
92 e.printStackTrace(log);
93 throw new StatusException("Couldn't create instance", e);
96 XInterface oObj = (XInterface) oInterface;
98 // creating and connecting DataOutputStream to the
99 // DataInputStream created through the Pipe
100 XActiveDataSink xDataSink = UnoRuntime.queryInterface(XActiveDataSink.class, oObj);
102 XInterface oPipe = null;
103 try {
104 oPipe = (XInterface)
105 xMSF.createInstance("com.sun.star.io.Pipe");
106 } catch(com.sun.star.uno.Exception e) {
107 e.printStackTrace(log);
108 throw new StatusException("Couldn't create instance", e);
111 XInputStream xPipeInput = UnoRuntime.queryInterface(XInputStream.class, oPipe);
112 XOutputStream xPipeOutput = UnoRuntime.queryInterface(XOutputStream.class, oPipe);
114 XInterface oDataOutput = null;
115 try {
116 oDataOutput = (XInterface)
117 xMSF.createInstance("com.sun.star.io.DataOutputStream");
118 } catch(com.sun.star.uno.Exception e) {
119 e.printStackTrace(log);
120 throw new StatusException("Couldn't create instance", e);
123 XDataOutputStream xDataOutput = UnoRuntime.queryInterface(XDataOutputStream.class, oDataOutput) ;
124 XActiveDataSource xDataSource = UnoRuntime.queryInterface(XActiveDataSource.class, oDataOutput) ;
126 xDataSource.setOutputStream(xPipeOutput) ;
127 xDataSink.setInputStream(xPipeInput) ;
129 // all data types for writing to an XDataInputStream
130 ArrayList<Object> data = new ArrayList<Object>();
131 data.add(Boolean.TRUE) ;
132 data.add(Byte.valueOf((byte)123)) ;
133 data.add(new Character((char)1234)) ;
134 data.add(Short.valueOf((short)1234)) ;
135 data.add(Integer.valueOf(123456)) ;
136 data.add(new Float(1.234)) ;
137 data.add(new Double(1.23456)) ;
138 data.add("DataInputStream") ;
139 // information for writing to the pipe
140 byte[] byteData = new byte[] {
141 1, 2, 3, 4, 5, 6, 7, 8 } ;
143 // createing a connectable object for XConnectable interface
144 XInterface xConnect = null;
145 try {
146 xConnect = (XInterface)xMSF.createInstance(
147 "com.sun.star.io.DataInputStream") ;
148 } catch (Exception e) {
149 log.println("Can't create DataInputStream");
150 e.printStackTrace(log);
151 throw new StatusException("Can't create DataInputStream", e);
154 // creating an input stream to set in XActiveDataSink
155 XInterface oDataInput = null;
156 try {
157 oDataInput = (XInterface) xMSF.createInstance(
158 "com.sun.star.io.Pipe" );
159 } catch (com.sun.star.uno.Exception e) {
160 log.println("Can't create new in stream") ;
161 e.printStackTrace(log) ;
162 throw new StatusException("Can't create input stream", e) ;
166 log.println("creating a new environment for object");
167 TestEnvironment tEnv = new TestEnvironment( oObj );
169 // adding sequence of data that must be read
170 // by XDataInputStream interface methods
171 tEnv.addObjRelation("StreamData", data) ;
172 // add a writer
173 tEnv.addObjRelation("StreamWriter", xDataOutput);
174 // add a connectable
175 tEnv.addObjRelation("Connectable", xConnect);
176 // add an inputStream
177 tEnv.addObjRelation("InputStream", oDataInput);
178 tEnv.addObjRelation("ByteData", byteData);
180 return tEnv;
181 } // finish method getTestEnvironment