tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _streams / uno / ObjectOutputStream.java
blobe683baa3f6e1f4056cfcb1711d691ef3ea59f0bb
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._streams.uno;
21 import com.sun.star.io.XActiveDataSink;
22 import com.sun.star.io.XActiveDataSource;
23 import com.sun.star.io.XInputStream;
24 import com.sun.star.io.XObjectInputStream;
25 import com.sun.star.io.XObjectOutputStream;
26 import com.sun.star.io.XOutputStream;
27 import com.sun.star.io.XPersistObject;
28 import com.sun.star.lang.XMultiServiceFactory;
29 import com.sun.star.registry.XImplementationRegistration;
30 import com.sun.star.registry.XSimpleRegistry;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
34 import java.io.PrintWriter;
35 import java.util.ArrayList;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.io.ObjectOutputStream</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
47 * <li> <code>com::sun::star::io::XOutputStream</code></li>
48 * <li> <code>com::sun::star::io::XConnectable</code></li>
49 * <li> <code>com::sun::star::io::XDataOutputStream</code></li>
50 * <li> <code>com::sun::star::io::XObjectOutputStream</code></li>
51 * </ul>
52 * The following files used by this test :
53 * <ul>
54 * <li><b> MyPersistObjectImpl.jar </b> : the implementation of the persist
55 * object</li>
56 * </ul> <p>
57 * @see com.sun.star.io.ObjectOutputStream
58 * @see com.sun.star.io.XActiveDataSource
59 * @see com.sun.star.io.XOutputStream
60 * @see com.sun.star.io.XConnectable
61 * @see com.sun.star.io.XDataOutputStream
62 * @see com.sun.star.io.XObjectOutputStream
63 * @see ifc.io._XActiveDataSource
64 * @see ifc.io._XOutputStream
65 * @see ifc.io._XConnectable
66 * @see ifc.io._XDataOutputStream
67 * @see ifc.io._XObjectOutputStream
69 public class ObjectOutputStream extends TestCase {
71 /**
72 * Register the implementation of service
73 * <code>com.sun.star.cmp.PersistObject</code> if not yet registered.
74 * @see com.sun.star.cmp.PersistObject
76 @Override
77 public void initialize(TestParameters tParam, PrintWriter log) throws Exception {
78 XMultiServiceFactory xMSF = tParam.getMSF();
79 Object oPersObj = null;
80 // test first if object is already registered
81 try {
82 oPersObj = xMSF.createInstance("com.sun.star.cmp.PersistObject");
84 catch( com.sun.star.uno.Exception e ) {
85 log.println("Could not create instance of PersistObject");
86 e.printStackTrace(log);
87 log.println("Going on with test...");
89 if ( oPersObj == null ) {
90 // object is not available: it has to be registered
91 String url = util.utils.getFullTestURL
92 ("qadevlibs/MyPersistObjectImpl.jar");
93 XImplementationRegistration xir;
94 Object o = xMSF.createInstance(
95 "com.sun.star.registry.ImplementationRegistration");
96 xir = UnoRuntime.queryInterface(
97 XImplementationRegistration.class, o);
99 XSimpleRegistry xReg = null;
100 System.out.println("Register library: " + url);
101 xir.registerImplementation(
102 "com.sun.star.loader.Java2", url, xReg);
103 System.out.println("...done");
108 * Creating a TestEnvironment for the interfaces to be tested.
109 * Creates an instances of services
110 * <code>com.sun.star.io.ObjectOutputStream</code>,
111 * <code>com.sun.star.io.Pipe</code> and
112 * <code>com.sun.star.io.MarkableOutputStream</code>. Plugs the created
113 * markable output stream as output stream for the created
114 * <code>ObjectOutputStream</code>. Plugs the created pipe as output stream
115 * for the created <code>MarkableOutputStream</code>. Creates an instance
116 * of the service <code>com.sun.star.cmp.PersistObject</code>.
117 * Object relations created :
118 * <ul>
119 * <li> <code>'StreamData'</code> for
120 * {@link ifc.io._XDataOutputStream}(the data that should
121 * be written into the stream) </li>
122 * <li> <code>'ByteData'</code> for
123 * {@link ifc.io._XOutputStream}(the data that should be written into
124 * the stream) </li>
125 * <li> <code>'Connectable'</code> for
126 * {@link ifc.io._XConnectable}
127 * (another object that can be connected) </li>
128 * <li> <code>'OutputStream'</code> for
129 * {@link ifc.io._XActiveDataSource}
130 * (an input stream to set and get) </li>
131 * <li> <code>'PersistObject'</code> for
132 * {@link ifc.io._XObjectOutputStream}(the created instance of the
133 * <li> <code>'InputStream'</code> for
134 * {@link ifc.io._XObjectInputStream}(the created instance of the
135 * persist object ) </li>
136 * <li> <code>'XOutputStream.StreamChecker'</code> for
137 * {@link ifc.io._XOutputStream}( implementation of the interface
138 * ifc.io._XOutputStream.StreamChecker ) </li>
139 * </ul>
140 * @see com.sun.star.io.ObjectInputStream
141 * @see com.sun.star.io.ObjectOutputStream
142 * @see com.sun.star.io.Pipe
143 * @see com.sun.star.io.MarkableInputStream
144 * @see com.sun.star.io.MarkableOutputStream
145 * @see com.sun.star.cmp.PersistObject
147 @Override
148 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
150 XInterface oObj = null;
152 XObjectOutputStream oStream = null;
154 XMultiServiceFactory xMSF = Param.getMSF();
155 Object ostream = null, istream = null;
156 Object aPipe = null;
157 Object mostream = null;
158 XInterface aConnect = null;
159 Object minstream = null;
161 ostream = xMSF.createInstance
162 ( "com.sun.star.io.ObjectOutputStream" );
163 istream = xMSF.createInstance
164 ("com.sun.star.io.ObjectInputStream");
165 aPipe = xMSF.createInstance("com.sun.star.io.Pipe");
166 mostream = xMSF.createInstance
167 ("com.sun.star.io.MarkableOutputStream");
168 aConnect = (XInterface)xMSF.createInstance
169 ("com.sun.star.io.DataInputStream");
170 minstream = xMSF.createInstance
171 ("com.sun.star.io.MarkableInputStream");
173 // creating the pipe where object has to be written to
174 XActiveDataSource xdSo = UnoRuntime.queryInterface(XActiveDataSource.class, ostream);
176 XActiveDataSource xdSmo = UnoRuntime.queryInterface(XActiveDataSource.class, mostream);
178 XOutputStream moStream = UnoRuntime.queryInterface(XOutputStream.class, mostream);
180 XActiveDataSink markIn = UnoRuntime.queryInterface(XActiveDataSink.class, minstream);
181 XActiveDataSink inStream = UnoRuntime.queryInterface(XActiveDataSink.class, istream);
182 XInputStream markInStream = UnoRuntime.queryInterface(XInputStream.class, minstream);
184 final XOutputStream PipeOut = UnoRuntime.queryInterface(XOutputStream.class,aPipe);
185 final XInputStream PipeIn = UnoRuntime.queryInterface(XInputStream.class,aPipe);
187 markIn.setInputStream(PipeIn);
188 inStream.setInputStream(markInStream);
189 XObjectInputStream objInputStream = UnoRuntime.queryInterface(XObjectInputStream.class, istream);
190 xdSo.setOutputStream(moStream);
191 xdSmo.setOutputStream(PipeOut);
193 oStream = UnoRuntime.queryInterface(XObjectOutputStream.class, ostream);
195 // creating Persistent object which has to be written
196 XPersistObject xPersObj = null ;
197 Object oPersObj = xMSF.createInstance
198 ("com.sun.star.cmp.PersistObject");
199 xPersObj = UnoRuntime.queryInterface(XPersistObject.class, oPersObj);
201 oObj = oStream;
203 // all data types for writing to an XDataInputStream
204 ArrayList<Object> data = new ArrayList<Object>() ;
205 data.add(Boolean.TRUE) ;
206 data.add(Byte.valueOf((byte)123)) ;
207 data.add(Character.valueOf((char)1234)) ;
208 data.add(Short.valueOf((short)1234)) ;
209 data.add(Integer.valueOf(123456)) ;
210 data.add(Float.valueOf(1.234f)) ;
211 data.add(Double.valueOf(1.23456)) ;
212 data.add("DataInputStream") ;
213 // information for writing to the pipe
214 byte[] byteData = new byte[] {
215 1, 2, 3, 4, 5, 6, 7, 8 } ;
217 log.println("creating a new environment for object");
218 TestEnvironment tEnv = new TestEnvironment( oObj );
220 tEnv.addObjRelation("PersistObject", xPersObj);
221 tEnv.addObjRelation("StreamData", data);
222 tEnv.addObjRelation("ByteData", byteData);
223 tEnv.addObjRelation("OutputStream", aPipe);
224 tEnv.addObjRelation("Connectable", aConnect);
226 tEnv.addObjRelation("InputStream", objInputStream);
228 //add relation for io.XOutputStream
229 final XMultiServiceFactory msf = xMSF;
230 tEnv.addObjRelation("XOutputStream.StreamChecker",
231 new ifc.io._XOutputStream.StreamChecker() {
232 XInputStream xInStream = null;
233 public void resetStreams() {
234 if (xInStream != null) {
235 try {
236 xInStream.closeInput();
237 xInStream = null;
238 } catch(com.sun.star.io.IOException e) {
240 } else {
241 try {
242 PipeOut.closeOutput();
243 } catch(com.sun.star.io.IOException e) {
248 public XInputStream getInStream() {
249 resetStreams();
250 try {
251 Object oInStream = msf.createInstance(
252 "com.sun.star.io.ObjectInputStream");
253 xInStream = UnoRuntime.queryInterface
254 (XInputStream.class, oInStream);
255 } catch(com.sun.star.uno.Exception e) {
256 return null;
259 XActiveDataSink xDataSink = UnoRuntime.queryInterface(
260 XActiveDataSink.class, xInStream);
261 xDataSink.setInputStream(PipeIn);
263 return xInStream;
267 return tEnv;
268 } // finish method getTestEnvironment