bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _stm / DataOutputStream.java
blob281d530920bce4dfa513ca49973b34223fb6283e
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.XInputStream;
32 import com.sun.star.io.XOutputStream;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.io.DataOutputStream</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
43 * <li> <code>com::sun::star::io::XOutputStream</code></li>
44 * <li> <code>com::sun::star::io::XDataOutputStream</code></li>
45 * </ul>
46 * @see com.sun.star.io.DataOutputStream
47 * @see com.sun.star.io.XActiveDataSource
48 * @see com.sun.star.io.XOutputStream
49 * @see com.sun.star.io.XDataOutputStream
50 * @see ifc.io._XActiveDataSource
51 * @see ifc.io._XOutputStream
52 * @see ifc.io._XDataOutputStream
54 public class DataOutputStream extends TestCase {
56 /**
57 * Creating a Testenvironment for the interfaces to be tested.
58 * Creates an instance of the service
59 * <code>com.sun.star.io.DataOutputStream</code>
60 * and an instance of the service <code>com.sun.star.io.Pipe</code>.
61 * Plugs the created pipe as output stream for the created DataOutputStream.
62 * @see com.sun.star.io.DataOutputStream
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>'OutputStream'</code> for
72 * {@link ifc.io._XActiveDataSource}
73 * (an input stream to set and get) </li>
74 * <li> <code>'XOutputStream.StreamChecker'</code> for
75 * {@link ifc.io._XOutputStream}( implementation of the interface
76 * ifc.io._XOutputStream.StreamChecker ) </li>
77 * </ul>
79 @Override
80 public TestEnvironment createTestEnvironment(
81 TestParameters Param, PrintWriter log) throws StatusException {
83 XInterface oObj = null;
84 Object oInterface = null;
85 XInterface oPipe = null;
86 XMultiServiceFactory xMSF = null ;
88 try {
89 xMSF = Param.getMSF();
90 oInterface = xMSF.createInstance
91 ("com.sun.star.io.DataOutputStream");
92 oPipe = (XInterface)xMSF.createInstance("com.sun.star.io.Pipe");
93 } catch(com.sun.star.uno.Exception e) {
94 e.printStackTrace(log);
95 throw new StatusException("Couldn't create instance", e);
98 oObj = (XInterface) oInterface;
100 final XOutputStream xPipeOutput = UnoRuntime.queryInterface(XOutputStream.class, oPipe);
102 XActiveDataSource xDataSource = UnoRuntime.queryInterface(XActiveDataSource.class, oObj);
104 xDataSource.setOutputStream(xPipeOutput);
106 // all data types for writing to an XDataInputStream
107 ArrayList<Object> data = new ArrayList<Object>() ;
108 data.add(Boolean.TRUE) ;
109 data.add(Byte.valueOf((byte)123)) ;
110 data.add(new Character((char)1234)) ;
111 data.add(Short.valueOf((short)1234)) ;
112 data.add(Integer.valueOf(123456)) ;
113 data.add(new Float(1.234)) ;
114 data.add(new Double(1.23456)) ;
115 data.add("DataInputStream") ;
116 // information for writing to the pipe
117 byte[] byteData = new byte[] {
118 1, 2, 3, 4, 5, 6, 7, 8 } ;
120 log.println("creating a new environment for object");
121 TestEnvironment tEnv = new TestEnvironment( oObj );
123 tEnv.addObjRelation("StreamData", data);
124 tEnv.addObjRelation("ByteData", byteData);
125 tEnv.addObjRelation("OutputStream", oPipe);
127 //add relation for io.XOutputStream
128 final XMultiServiceFactory msf = xMSF;
129 final XInputStream xPipeInput = UnoRuntime.queryInterface(XInputStream.class, oPipe);
130 tEnv.addObjRelation("XOutputStream.StreamChecker",
131 new ifc.io._XOutputStream.StreamChecker() {
132 XInputStream xInStream = null;
133 public void resetStreams() {
134 if (xInStream != null) {
135 try {
136 xInStream.closeInput();
137 xInStream = null;
138 } catch(com.sun.star.io.IOException e) {
140 } else {
141 try {
142 xPipeOutput.closeOutput();
143 } catch(com.sun.star.io.IOException e) {
148 public XInputStream getInStream() {
149 resetStreams();
150 try {
151 Object oInStream = msf.createInstance(
152 "com.sun.star.io.DataInputStream");
153 xInStream = UnoRuntime.queryInterface
154 (XInputStream.class, oInStream);
155 } catch(com.sun.star.uno.Exception e) {
156 return null;
159 XActiveDataSink xDataSink = UnoRuntime.queryInterface(
160 XActiveDataSink.class, xInStream);
161 xDataSink.setInputStream(xPipeInput);
163 return xInStream;
167 return tEnv;
168 } // finish method getTestEnvironment