merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _streams.uno / MarkableOutputStream.java
blobe0472a5a08418679110de21ef3f0fc65135c852d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MarkableOutputStream.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._streams.uno;
33 import com.sun.star.io.XActiveDataSink;
34 import com.sun.star.io.XActiveDataSource;
35 import com.sun.star.io.XInputStream;
36 import com.sun.star.io.XOutputStream;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 import java.io.PrintWriter;
41 import java.util.Vector;
42 import lib.StatusException;
43 import lib.TestCase;
44 import lib.TestEnvironment;
45 import lib.TestParameters;
47 /**
48 * Test for object which is represented by service
49 * <code>com.sun.star.io.MarkableOutputStream</code>. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
53 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
54 * <li> <code>com::sun::star::io::XOutputStream</code></li>
55 * <li> <code>com::sun::star::io::XConnectable</code></li>
56 * </ul>
57 * @see com.sun.star.io.MarkableOutputStream
58 * @see com.sun.star.io.XMarkableStream
59 * @see com.sun.star.io.XActiveDataSource
60 * @see com.sun.star.io.XOutputStream
61 * @see com.sun.star.io.XConnectable
62 * @see ifc.io._XMarkableStream
63 * @see ifc.io._XActiveDataSource
64 * @see ifc.io._XOutputStream
65 * @see ifc.io._XConnectable
67 public class MarkableOutputStream extends TestCase {
69 /**
70 * Creating a Testenvironment for the interfaces to be tested.
71 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
72 * <code>com.sun.star.io.MarkableInputStream</code> and
73 * <code>com.sun.star.io.MarkableOutputStream</code>.
74 * Plugs the created pipe as output stream for the created
75 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
76 * for the created <code>MarkableInputStream</code>.
77 * Object relations created :
78 * <ul>
79 * <li> <code>'ByteData'</code> for
80 * {@link ifc.io._XOutputStream}(the data that should be written into
81 * the stream) </li>
82 * <li> <code>'StreamData'</code> for
83 * {@link ifc.io._XDataOutputStream}(the data that should be
84 * written into the stream) </li>
85 * <li> <code>'Connectable'</code> for
86 * {@link ifc.io._XConnectable}
87 * (another object that can be connected) </li>
88 * <li> <code>'OutputStream'</code> for
89 * {@link ifc.io._XActiveDataSource}
90 * (an input stream to set and get) </li>
91 * <li> <code>'XOutputStream.StreamChecker'</code> for
92 * {@link ifc.io._XOutputStream}( implementation of the interface
93 * ifc.io._XOutputStream.StreamChecker ) </li>
94 * </ul>
95 * @see com.sun.star.io.Pipe
96 * @see com.sun.star.io.MarkableInputStream
97 * @see com.sun.star.io.MarkableOutputStream
99 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
101 XInterface oObj = null;
102 Object ostream = null;
104 Object istream = null ;
105 XOutputStream moStream = null ;
107 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
108 Object aPipe = null;
109 Object mostream = null;
110 Object mistream = null;
111 XInterface aConnect;
113 try {
114 aPipe = xMSF.createInstance("com.sun.star.io.Pipe");
115 mistream = xMSF.createInstance
116 ("com.sun.star.io.MarkableInputStream");
117 mostream = xMSF.createInstance
118 ("com.sun.star.io.MarkableOutputStream");
119 aConnect = (XInterface)xMSF.createInstance
120 ("com.sun.star.io.DataOutputStream");
121 } catch(com.sun.star.uno.Exception e) {
122 e.printStackTrace(log);
123 throw new StatusException("Couldn't create instance", e) ;
126 // Creating construction :
127 // MarkableOutputStream -> Pipe -> MarkableInputStream
128 XActiveDataSource xdSmo = (XActiveDataSource)
129 UnoRuntime.queryInterface(XActiveDataSource.class, mostream);
131 final XOutputStream PipeOut = (XOutputStream)
132 UnoRuntime.queryInterface(XOutputStream.class,aPipe);
133 final XInputStream PipeIn = (XInputStream)
134 UnoRuntime.queryInterface(XInputStream.class,aPipe);
136 xdSmo.setOutputStream(PipeOut);
138 XActiveDataSink xmSi = (XActiveDataSink)
139 UnoRuntime.queryInterface(XActiveDataSink.class, mistream);
141 xmSi.setInputStream(PipeIn) ;
143 oObj = (XInterface) mostream;
145 // all data types for writing to an XDataInputStream
146 Vector data = new Vector() ;
147 data.add(new Boolean(true)) ;
148 data.add(new Byte((byte)123)) ;
149 data.add(new Character((char)1234)) ;
150 data.add(new Short((short)1234)) ;
151 data.add(new Integer(123456)) ;
152 data.add(new Float(1.234)) ;
153 data.add(new Double(1.23456)) ;
154 data.add("DataInputStream") ;
155 // information for writing to the pipe
156 byte[] byteData = new byte[] {
157 1, 2, 3, 4, 5, 6, 7, 8 } ;
159 log.println( "creating a new environment for object" );
160 TestEnvironment tEnv = new TestEnvironment( oObj );
162 tEnv.addObjRelation("StreamData", data);
163 tEnv.addObjRelation("ByteData", byteData);
164 tEnv.addObjRelation("OutputStream", aPipe);
165 tEnv.addObjRelation("Connectable", aConnect);
167 //add relation for io.XOutputStream
168 final XMultiServiceFactory msf = xMSF;
169 tEnv.addObjRelation("XOutputStream.StreamChecker",
170 new ifc.io._XOutputStream.StreamChecker() {
171 XInputStream xInStream = null;
172 public void resetStreams() {
173 if (xInStream != null) {
174 try {
175 xInStream.closeInput();
176 xInStream = null;
177 } catch(com.sun.star.io.IOException e) {
179 } else {
180 try {
181 PipeOut.closeOutput();
182 } catch(com.sun.star.io.IOException e) {
187 public XInputStream getInStream() {
188 resetStreams();
189 try {
190 Object oInStream = msf.createInstance(
191 "com.sun.star.io.MarkableInputStream");
192 xInStream = (XInputStream) UnoRuntime.queryInterface
193 (XInputStream.class, oInStream);
194 } catch(com.sun.star.uno.Exception e) {
195 return null;
198 XActiveDataSink xDataSink = (XActiveDataSink)
199 UnoRuntime.queryInterface(
200 XActiveDataSink.class, xInStream);
201 xDataSink.setInputStream(PipeIn);
203 return xInStream;
207 return tEnv;
208 } // finish method getTestEnvironment