bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _stm / MarkableOutputStream.java
blob8203db02c8bab8c10710aefd9b7e26a7ccebcc3d
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 public TestEnvironment createTestEnvironment(
90 TestParameters Param, PrintWriter log) throws StatusException {
92 XInterface oObj = null;
94 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
95 Object aPipe = null;
96 Object mostream = null;
97 Object mistream = null;
98 XInterface aConnect;
100 try {
101 aPipe = xMSF.createInstance("com.sun.star.io.Pipe");
102 mistream = xMSF.createInstance
103 ("com.sun.star.io.MarkableInputStream");
104 mostream = xMSF.createInstance
105 ("com.sun.star.io.MarkableOutputStream");
106 aConnect = (XInterface)xMSF.createInstance
107 ("com.sun.star.io.DataOutputStream");
108 } catch(com.sun.star.uno.Exception e) {
109 e.printStackTrace(log);
110 throw new StatusException("Couldn't create instance", e) ;
113 // Creating construction :
114 // MarkableOutputStream -> Pipe -> MarkableInputStream
115 XActiveDataSource xdSmo = UnoRuntime.queryInterface(XActiveDataSource.class, mostream);
117 final XOutputStream PipeOut = UnoRuntime.queryInterface(XOutputStream.class,aPipe);
118 final XInputStream PipeIn = UnoRuntime.queryInterface(XInputStream.class,aPipe);
120 xdSmo.setOutputStream(PipeOut);
122 XActiveDataSink xmSi = UnoRuntime.queryInterface(XActiveDataSink.class, mistream);
124 xmSi.setInputStream(PipeIn) ;
126 oObj = (XInterface) mostream;
128 // all data types for writing to an XDataInputStream
129 ArrayList<Object> data = new ArrayList<Object>() ;
130 data.add(new Boolean(true)) ;
131 data.add(new Byte((byte)123)) ;
132 data.add(new Character((char)1234)) ;
133 data.add(new Short((short)1234)) ;
134 data.add(new Integer(123456)) ;
135 data.add(new Float(1.234)) ;
136 data.add(new Double(1.23456)) ;
137 data.add("DataInputStream") ;
138 // information for writing to the pipe
139 byte[] byteData = new byte[] {
140 1, 2, 3, 4, 5, 6, 7, 8 } ;
142 log.println( "creating a new environment for object" );
143 TestEnvironment tEnv = new TestEnvironment( oObj );
145 tEnv.addObjRelation("StreamData", data);
146 tEnv.addObjRelation("ByteData", byteData);
147 tEnv.addObjRelation("OutputStream", aPipe);
148 tEnv.addObjRelation("Connectable", aConnect);
150 //add relation for io.XOutputStream
151 final XMultiServiceFactory msf = xMSF;
152 tEnv.addObjRelation("XOutputStream.StreamChecker",
153 new ifc.io._XOutputStream.StreamChecker() {
154 XInputStream xInStream = null;
155 public void resetStreams() {
156 if (xInStream != null) {
157 try {
158 xInStream.closeInput();
159 xInStream = null;
160 } catch(com.sun.star.io.IOException e) {
162 } else {
163 try {
164 PipeOut.closeOutput();
165 } catch(com.sun.star.io.IOException e) {
170 public XInputStream getInStream() {
171 resetStreams();
172 try {
173 Object oInStream = msf.createInstance(
174 "com.sun.star.io.MarkableInputStream");
175 xInStream = UnoRuntime.queryInterface
176 (XInputStream.class, oInStream);
177 } catch(com.sun.star.uno.Exception e) {
178 return null;
181 XActiveDataSink xDataSink = UnoRuntime.queryInterface(
182 XActiveDataSink.class, xInStream);
183 xDataSink.setInputStream(PipeIn);
185 return xInStream;
189 return tEnv;
190 } // finish method getTestEnvironment