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
.CannotRegisterImplementationException
;
30 import com
.sun
.star
.registry
.XImplementationRegistration
;
31 import com
.sun
.star
.registry
.XSimpleRegistry
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import java
.io
.PrintWriter
;
35 import java
.util
.ArrayList
;
36 import lib
.StatusException
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.io.ObjectInputStream</code>. <p>
44 * Object implements the following interfaces :
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>
53 * The following files used by this test :
55 * <li><b> MyPersistObjectImpl.jar </b> : the implementation of the persist
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
{
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
80 public void initialize(TestParameters tParam
, PrintWriter log
) {
81 XMultiServiceFactory xMSF
= tParam
.getMSF();
82 Object oPersObj
= null;
83 // test first if object is already registered
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
;
98 Object o
= xMSF
.createInstance(
99 "com.sun.star.registry.ImplementationRegistration");
100 xir
= UnoRuntime
.queryInterface(
101 XImplementationRegistration
.class, o
);
104 catch (com
.sun
.star
.uno
.Exception e
) {
106 "Couldn't create implementation registration");
108 throw new StatusException("Couldn't create ImplReg", e
);
111 XSimpleRegistry xReg
= null;
113 System
.out
.println("Register library: " + url
);
114 xir
.registerImplementation(
115 "com.sun.star.loader.Java2", url
, xReg
);
116 System
.out
.println("...done");
117 } catch (CannotRegisterImplementationException e
) {
118 System
.err
.println("Name: " + url
+ " msg: " +
121 throw new StatusException(
122 "Couldn't register MyPersistObject", e
);
128 * Creating a Testenvironment for the interfaces to be tested.
129 * Creates an instances of services
130 * <code>com.sun.star.io.ObjectInputStream</code>,
131 * <code>com.sun.star.io.ObjectOutputStream</code>,
132 * <code>com.sun.star.io.Pipe</code>,
133 * <code>com.sun.star.io.MarkableInputStream</code> and
134 * <code>com.sun.star.io.MarkableOutputStream</code>. Plugs the created
135 * markable output stream as output stream for the created
136 * <code>ObjectOutputStream</code>. Plugs the created pipe as output stream
137 * for the created <code>MarkableOutputStream</code>. Plugs the created
138 * markable input stream as input stream for the created
139 * <code>ObjectInputStream</code>. Plugs the created pipe as input stream
140 * for the created <code>MarkableInputStream</code>. Creates an instance
141 * of the service <code>com.sun.star.cmp.PersistObject</code> and writes
142 * the created object to the object output stream.
143 * Object relations created :
145 * <li> <code>'PersistObject'</code> for
146 * {@link ifc.io._XObjectInputStream}(the created instance of the
147 * persist object ) </li>
148 * <li> <code>'StreamData'</code> for
149 * {@link ifc.io._XDataInputStream}(the data that should be written into
151 * <li> <code>'ByteData'</code> for
152 * {@link ifc.io._XInputStream}(the data that should be written into
154 * <li> <code>'StreamWriter'</code> for
155 * {@link ifc.io._XDataInputStream}
156 * {@link ifc.io._XObjectInputStream}
157 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
158 * <li> <code>'Connectable'</code> for
159 * {@link ifc.io._XConnectable}
160 * (another object that can be connected) </li>
161 * <li> <code>'InputStream'</code> for
162 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
164 * @see com.sun.star.io.ObjectInputStream
165 * @see com.sun.star.io.ObjectOutputStream
166 * @see com.sun.star.io.Pipe
167 * @see com.sun.star.io.MarkableInputStream
168 * @see com.sun.star.io.MarkableOutputStream
169 * @see com.sun.star.cmp.PersistObject
172 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
174 System
.out
.println("create TestEnvironment started.");
175 XMultiServiceFactory xMSF
= Param
.getMSF();
176 Object ostream
= null;
178 Object mostream
= null;
179 Object mistream
= null;
180 Object istream
= null;
181 Object xConnect
= null;
183 istream
= xMSF
.createInstance
184 ("com.sun.star.io.ObjectInputStream");
185 ostream
= xMSF
.createInstance
186 ("com.sun.star.io.ObjectOutputStream");
187 aPipe
= xMSF
.createInstance
188 ("com.sun.star.io.Pipe");
189 mistream
= xMSF
.createInstance
190 ("com.sun.star.io.MarkableInputStream");
191 mostream
= xMSF
.createInstance
192 ("com.sun.star.io.MarkableOutputStream");
193 xConnect
= xMSF
.createInstance
194 ("com.sun.star.io.DataInputStream") ;
196 } catch( com
.sun
.star
.uno
.Exception e
) {
197 e
.printStackTrace(log
);
198 throw new StatusException("Couldn't create instance", e
);
200 // Creating construction :
201 // ObjectOutputStream -> MarkableOutputStream -> Pipe ->
202 // -> MarkableInputStream -> ObjectInputStream
203 XActiveDataSource xdSo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, ostream
);
205 XActiveDataSource xdSmo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
207 XOutputStream moStream
= UnoRuntime
.queryInterface(XOutputStream
.class, mostream
);
209 XOutputStream PipeOut
= UnoRuntime
.queryInterface(XOutputStream
.class, aPipe
);
210 XInputStream PipeIn
= UnoRuntime
.queryInterface(XInputStream
.class, aPipe
);
212 xdSo
.setOutputStream(moStream
);
213 xdSmo
.setOutputStream(PipeOut
);
215 XObjectInputStream iStream
= UnoRuntime
.queryInterface(XObjectInputStream
.class, istream
);
216 XObjectOutputStream oStream
= null;
217 oStream
= UnoRuntime
.queryInterface(XObjectOutputStream
.class, ostream
);
219 XActiveDataSink xmSi
= UnoRuntime
.queryInterface(XActiveDataSink
.class, mistream
);
220 XInputStream xmIstream
= UnoRuntime
.queryInterface(XInputStream
.class, mistream
);
222 XActiveDataSink xdSi
= UnoRuntime
.queryInterface
223 (XActiveDataSink
.class, istream
);
224 xdSi
.setInputStream(xmIstream
);
225 xmSi
.setInputStream(PipeIn
);
227 // creating Persist object which has to be written
228 XPersistObject xPersObj
= null;
230 Object oPersObj
= xMSF
.createInstance
231 ("com.sun.star.cmp.PersistObject");
232 xPersObj
= UnoRuntime
.queryInterface(XPersistObject
.class, oPersObj
);
233 } catch (com
.sun
.star
.uno
.Exception e
) {
234 e
.printStackTrace(log
);
235 throw new StatusException("Can't write persist object.", e
);
240 // all data types for writing to an XDataInputStream
241 ArrayList
<Object
> data
= new ArrayList
<Object
>() ;
242 data
.add(Boolean
.TRUE
) ;
243 data
.add(Byte
.valueOf((byte)123)) ;
244 data
.add(new Character((char)1234)) ;
245 data
.add(Short
.valueOf((short)1234)) ;
246 data
.add(Integer
.valueOf(123456)) ;
247 data
.add(new Float(1.234)) ;
248 data
.add(new Double(1.23456)) ;
249 data
.add("DataInputStream") ;
250 // information for writing to the pipe
251 byte[] byteData
= new byte[] {
252 1, 2, 3, 4, 5, 6, 7, 8 } ;
255 System
.out
.println("create environment");
256 XInterface oObj
= iStream
;
257 log
.println( "creating a new environment for object" );
258 TestEnvironment tEnv
= new TestEnvironment( oObj
);
260 // adding persistent object
261 tEnv
.addObjRelation("PersistObject", xPersObj
);
263 tEnv
.addObjRelation("Connectable", xConnect
);
264 tEnv
.addObjRelation("StreamWriter", oStream
);
265 // for XActiveDataSink
266 tEnv
.addObjRelation("InputStream", aPipe
);
267 // adding sequence of data that must be read
268 // by XDataInputStream interface methods
269 tEnv
.addObjRelation("StreamData", data
) ;
270 // and by XInputStream interface methods
271 tEnv
.addObjRelation("ByteData", byteData
) ;
273 System
.out
.println("create TestEnvironment finished.");
275 } // finish method getTestEnvironment