bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _stm / MarkableOutputStream.java
blobc58a61c7403e893d3cced1421c4f54647b5d536c
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.MarkableOutputStream</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
43 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
44 * <li> <code>com::sun::star::io::XOutputStream</code></li>
45 * <li> <code>com::sun::star::io::XConnectable</code></li>
46 * </ul>
47 * @see com.sun.star.io.MarkableOutputStream
48 * @see com.sun.star.io.XMarkableStream
49 * @see com.sun.star.io.XActiveDataSource
50 * @see com.sun.star.io.XOutputStream
51 * @see com.sun.star.io.XConnectable
52 * @see ifc.io._XMarkableStream
53 * @see ifc.io._XActiveDataSource
54 * @see ifc.io._XOutputStream
55 * @see ifc.io._XConnectable
57 public class MarkableOutputStream extends TestCase {
59 /**
60 * Creating a Testenvironment for the interfaces to be tested.
61 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
62 * <code>com.sun.star.io.MarkableInputStream</code> and
63 * <code>com.sun.star.io.MarkableOutputStream</code>.
64 * Plugs the created pipe as output stream for the created
65 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
66 * for the created <code>MarkableInputStream</code>.
67 * Object relations created :
68 * <ul>
69 * <li> <code>'ByteData'</code> for
70 * {@link ifc.io._XOutputStream}(the data that should be written into
71 * the stream) </li>
72 * <li> <code>'StreamData'</code> for
73 * {@link ifc.io._XDataOutputStream}(the data that should be
74 * written into the stream) </li>
75 * <li> <code>'Connectable'</code> for
76 * {@link ifc.io._XConnectable}
77 * (another object that can be connected) </li>
78 * <li> <code>'OutputStream'</code> for
79 * {@link ifc.io._XActiveDataSource}
80 * (an input stream to set and get) </li>
81 * <li> <code>'XOutputStream.StreamChecker'</code> for
82 * {@link ifc.io._XOutputStream}( implementation of the interface
83 * ifc.io._XOutputStream.StreamChecker ) </li>
84 * </ul>
85 * @see com.sun.star.io.Pipe
86 * @see com.sun.star.io.MarkableInputStream
87 * @see com.sun.star.io.MarkableOutputStream
89 @Override
90 public TestEnvironment createTestEnvironment(
91 TestParameters Param, PrintWriter log) throws StatusException {
93 XInterface oObj = null;
95 XMultiServiceFactory xMSF = Param.getMSF();
96 Object aPipe = null;
97 Object mostream = null;
98 Object mistream = null;
99 XInterface aConnect;
101 try {
102 aPipe = xMSF.createInstance("com.sun.star.io.Pipe");
103 mistream = xMSF.createInstance
104 ("com.sun.star.io.MarkableInputStream");
105 mostream = xMSF.createInstance
106 ("com.sun.star.io.MarkableOutputStream");
107 aConnect = (XInterface)xMSF.createInstance
108 ("com.sun.star.io.DataOutputStream");
109 } catch(com.sun.star.uno.Exception e) {
110 e.printStackTrace(log);
111 throw new StatusException("Couldn't create instance", e) ;
114 // Creating construction :
115 // MarkableOutputStream -> Pipe -> MarkableInputStream
116 XActiveDataSource xdSmo = UnoRuntime.queryInterface(XActiveDataSource.class, mostream);
118 final XOutputStream PipeOut = UnoRuntime.queryInterface(XOutputStream.class,aPipe);
119 final XInputStream PipeIn = UnoRuntime.queryInterface(XInputStream.class,aPipe);
121 xdSmo.setOutputStream(PipeOut);
123 XActiveDataSink xmSi = UnoRuntime.queryInterface(XActiveDataSink.class, mistream);
125 xmSi.setInputStream(PipeIn) ;
127 oObj = (XInterface) mostream;
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 log.println( "creating a new environment for object" );
144 TestEnvironment tEnv = new TestEnvironment( oObj );
146 tEnv.addObjRelation("StreamData", data);
147 tEnv.addObjRelation("ByteData", byteData);
148 tEnv.addObjRelation("OutputStream", aPipe);
149 tEnv.addObjRelation("Connectable", aConnect);
151 //add relation for io.XOutputStream
152 final XMultiServiceFactory msf = xMSF;
153 tEnv.addObjRelation("XOutputStream.StreamChecker",
154 new ifc.io._XOutputStream.StreamChecker() {
155 XInputStream xInStream = null;
156 public void resetStreams() {
157 if (xInStream != null) {
158 try {
159 xInStream.closeInput();
160 xInStream = null;
161 } catch(com.sun.star.io.IOException e) {
163 } else {
164 try {
165 PipeOut.closeOutput();
166 } catch(com.sun.star.io.IOException e) {
171 public XInputStream getInStream() {
172 resetStreams();
173 try {
174 Object oInStream = msf.createInstance(
175 "com.sun.star.io.MarkableInputStream");
176 xInStream = UnoRuntime.queryInterface
177 (XInputStream.class, oInStream);
178 } catch(com.sun.star.uno.Exception e) {
179 return null;
182 XActiveDataSink xDataSink = UnoRuntime.queryInterface(
183 XActiveDataSink.class, xInStream);
184 xDataSink.setInputStream(PipeIn);
186 return xInStream;
190 return tEnv;
191 } // finish method getTestEnvironment