tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _stm / ObjectInputStream.java
blob5db84e3ae3d57025b1695ce741679dfd40c22628
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.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
28 import com.sun.star.io.XActiveDataSink;
29 import com.sun.star.io.XActiveDataSource;
30 import com.sun.star.io.XInputStream;
31 import com.sun.star.io.XObjectInputStream;
32 import com.sun.star.io.XObjectOutputStream;
33 import com.sun.star.io.XOutputStream;
34 import com.sun.star.io.XPersistObject;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.registry.XImplementationRegistration;
37 import com.sun.star.registry.XSimpleRegistry;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.io.ObjectInputStream</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li> <code>com::sun::star::io::XInputStream</code></li>
47 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
48 * <li> <code>com::sun::star::io::XDataInputStream</code></li>
49 * <li> <code>com::sun::star::io::XConnectable</code></li>
50 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
51 * <li> <code>com::sun::star::io::XObjectInputStream</code></li>
52 * </ul>
53 * The following files used by this test :
54 * <ul>
55 * <li><b> MyPersistObjectImpl.jar </b> : the implementation of the persist
56 * object</li>
57 * </ul> <p>
58 * @see com.sun.star.io.ObjectInputStream
59 * @see com.sun.star.io.XInputStream
60 * @see com.sun.star.io.XMarkableStream
61 * @see com.sun.star.io.XDataInputStream
62 * @see com.sun.star.io.XConnectable
63 * @see com.sun.star.io.XActiveDataSink
64 * @see com.sun.star.io.XObjectInputStream
65 * @see ifc.io._XInputStream
66 * @see ifc.io._XMarkableStream
67 * @see ifc.io._XDataInputStream
68 * @see ifc.io._XConnectable
69 * @see ifc.io._XActiveDataSink
70 * @see ifc.io._XObjectInputStream
72 public class ObjectInputStream extends TestCase {
74 /**
75 * Register the implementation of service
76 * <code>com.sun.star.cmp.PersistObject</code> if not yet registered.
77 * @see com.sun.star.cmp.PersistObject
79 @Override
80 public void initialize(TestParameters tParam, PrintWriter log) throws Exception {
81 XMultiServiceFactory xMSF = tParam.getMSF();
82 Object oPersObj = null;
83 // test first if object is already registered
84 try {
85 oPersObj = xMSF.createInstance("com.sun.star.cmp.PersistObject");
87 catch( com.sun.star.uno.Exception e ) {
88 log.println("Could not create instance of PersistObject");
89 e.printStackTrace(log);
90 log.println("Going on with test...");
92 if ( oPersObj == null ) {
93 // object is not available: it has to be registered
94 String url = util.utils.getFullTestURL
95 ("qadevlibs/MyPersistObjectImpl.jar");
96 XImplementationRegistration xir;
97 Object o = xMSF.createInstance(
98 "com.sun.star.registry.ImplementationRegistration");
99 xir = UnoRuntime.queryInterface(
100 XImplementationRegistration.class, o);
102 XSimpleRegistry xReg = null;
103 System.out.println("Register library: " + url);
104 xir.registerImplementation(
105 "com.sun.star.loader.Java2", url, xReg);
106 System.out.println("...done");
111 * Creating a TestEnvironment for the interfaces to be tested.
112 * Creates an instances of services
113 * <code>com.sun.star.io.ObjectInputStream</code>,
114 * <code>com.sun.star.io.ObjectOutputStream</code>,
115 * <code>com.sun.star.io.Pipe</code>,
116 * <code>com.sun.star.io.MarkableInputStream</code> and
117 * <code>com.sun.star.io.MarkableOutputStream</code>. Plugs the created
118 * markable output stream as output stream for the created
119 * <code>ObjectOutputStream</code>. Plugs the created pipe as output stream
120 * for the created <code>MarkableOutputStream</code>. Plugs the created
121 * markable input stream as input stream for the created
122 * <code>ObjectInputStream</code>. Plugs the created pipe as input stream
123 * for the created <code>MarkableInputStream</code>. Creates an instance
124 * of the service <code>com.sun.star.cmp.PersistObject</code> and writes
125 * the created object to the object output stream.
126 * Object relations created :
127 * <ul>
128 * <li> <code>'PersistObject'</code> for
129 * {@link ifc.io._XObjectInputStream}(the created instance of the
130 * persist object ) </li>
131 * <li> <code>'StreamData'</code> for
132 * {@link ifc.io._XDataInputStream}(the data that should be written into
133 * the stream) </li>
134 * <li> <code>'ByteData'</code> for
135 * {@link ifc.io._XInputStream}(the data that should be written into
136 * the stream) </li>
137 * <li> <code>'StreamWriter'</code> for
138 * {@link ifc.io._XDataInputStream}
139 * {@link ifc.io._XObjectInputStream}
140 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
141 * <li> <code>'Connectable'</code> for
142 * {@link ifc.io._XConnectable}
143 * (another object that can be connected) </li>
144 * <li> <code>'InputStream'</code> for
145 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
146 * </ul>
147 * @see com.sun.star.io.ObjectInputStream
148 * @see com.sun.star.io.ObjectOutputStream
149 * @see com.sun.star.io.Pipe
150 * @see com.sun.star.io.MarkableInputStream
151 * @see com.sun.star.io.MarkableOutputStream
152 * @see com.sun.star.cmp.PersistObject
154 @Override
155 public TestEnvironment createTestEnvironment(
156 TestParameters Param, PrintWriter log) throws Exception {
158 System.out.println("create TestEnvironment started.");
159 XMultiServiceFactory xMSF = Param.getMSF();
160 Object ostream = null;
161 Object aPipe = null;
162 Object mostream = null;
163 Object mistream = null;
164 Object istream = null;
165 Object xConnect = null;
166 istream = xMSF.createInstance
167 ("com.sun.star.io.ObjectInputStream");
168 ostream = xMSF.createInstance
169 ("com.sun.star.io.ObjectOutputStream");
170 aPipe = xMSF.createInstance
171 ("com.sun.star.io.Pipe");
172 mistream = xMSF.createInstance
173 ("com.sun.star.io.MarkableInputStream");
174 mostream = xMSF.createInstance
175 ("com.sun.star.io.MarkableOutputStream");
176 xConnect = xMSF.createInstance
177 ("com.sun.star.io.DataInputStream") ;
179 // Creating construction :
180 // ObjectOutputStream -> MarkableOutputStream -> Pipe ->
181 // -> MarkableInputStream -> ObjectInputStream
182 XActiveDataSource xdSo = UnoRuntime.queryInterface(XActiveDataSource.class, ostream);
184 XActiveDataSource xdSmo = UnoRuntime.queryInterface(XActiveDataSource.class, mostream);
186 XOutputStream moStream = UnoRuntime.queryInterface(XOutputStream.class, mostream);
188 XOutputStream PipeOut = UnoRuntime.queryInterface(XOutputStream.class, aPipe);
189 XInputStream PipeIn = UnoRuntime.queryInterface(XInputStream.class, aPipe);
191 xdSo.setOutputStream(moStream);
192 xdSmo.setOutputStream(PipeOut);
194 XObjectInputStream iStream = UnoRuntime.queryInterface(XObjectInputStream.class, istream);
195 XObjectOutputStream oStream = null;
196 oStream = UnoRuntime.queryInterface(XObjectOutputStream.class, ostream);
198 XActiveDataSink xmSi = UnoRuntime.queryInterface(XActiveDataSink.class, mistream);
199 XInputStream xmIstream = UnoRuntime.queryInterface(XInputStream.class, mistream);
201 XActiveDataSink xdSi = UnoRuntime.queryInterface
202 (XActiveDataSink.class, istream);
203 xdSi.setInputStream(xmIstream);
204 xmSi.setInputStream(PipeIn);
206 // creating Persist object which has to be written
207 XPersistObject xPersObj = null;
208 Object oPersObj = xMSF.createInstance
209 ("com.sun.star.cmp.PersistObject");
210 xPersObj = UnoRuntime.queryInterface(XPersistObject.class, oPersObj);
212 // all data types for writing to an XDataInputStream
213 ArrayList<Object> data = new ArrayList<Object>() ;
214 data.add(Boolean.TRUE) ;
215 data.add(Byte.valueOf((byte)123)) ;
216 data.add(Character.valueOf((char)1234)) ;
217 data.add(Short.valueOf((short)1234)) ;
218 data.add(Integer.valueOf(123456)) ;
219 data.add(Float.valueOf(1.234f)) ;
220 data.add(Double.valueOf(1.23456)) ;
221 data.add("DataInputStream") ;
222 // information for writing to the pipe
223 byte[] byteData = new byte[] {
224 1, 2, 3, 4, 5, 6, 7, 8 } ;
227 System.out.println("create environment");
228 XInterface oObj = iStream;
229 log.println( "creating a new environment for object" );
230 TestEnvironment tEnv = new TestEnvironment( oObj );
232 // adding persistent object
233 tEnv.addObjRelation("PersistObject", xPersObj);
234 // add a connectable
235 tEnv.addObjRelation("Connectable", xConnect);
236 tEnv.addObjRelation("StreamWriter", oStream);
237 // for XActiveDataSink
238 tEnv.addObjRelation("InputStream", aPipe);
239 // adding sequence of data that must be read
240 // by XDataInputStream interface methods
241 tEnv.addObjRelation("StreamData", data) ;
242 // and by XInputStream interface methods
243 tEnv.addObjRelation("ByteData", byteData) ;
245 System.out.println("create TestEnvironment finished.");
246 return tEnv;
247 } // finish method getTestEnvironment