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 .
21 import java
.io
.PrintWriter
;
22 import java
.util
.ArrayList
;
24 import lib
.StatusException
;
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
.XObjectInputStream
;
33 import com
.sun
.star
.io
.XObjectOutputStream
;
34 import com
.sun
.star
.io
.XOutputStream
;
35 import com
.sun
.star
.io
.XPersistObject
;
36 import com
.sun
.star
.lang
.XMultiServiceFactory
;
37 import com
.sun
.star
.registry
.CannotRegisterImplementationException
;
38 import com
.sun
.star
.registry
.XImplementationRegistration
;
39 import com
.sun
.star
.registry
.XSimpleRegistry
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
44 * Test for object which is represented by service
45 * <code>com.sun.star.io.ObjectInputStream</code>. <p>
46 * Object implements the following interfaces :
48 * <li> <code>com::sun::star::io::XInputStream</code></li>
49 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
50 * <li> <code>com::sun::star::io::XDataInputStream</code></li>
51 * <li> <code>com::sun::star::io::XConnectable</code></li>
52 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
53 * <li> <code>com::sun::star::io::XObjectInputStream</code></li>
55 * The following files used by this test :
57 * <li><b> MyPersistObjectImpl.jar </b> : the implementation of the persist
60 * @see com.sun.star.io.ObjectInputStream
61 * @see com.sun.star.io.XInputStream
62 * @see com.sun.star.io.XMarkableStream
63 * @see com.sun.star.io.XDataInputStream
64 * @see com.sun.star.io.XConnectable
65 * @see com.sun.star.io.XActiveDataSink
66 * @see com.sun.star.io.XObjectInputStream
67 * @see ifc.io._XInputStream
68 * @see ifc.io._XMarkableStream
69 * @see ifc.io._XDataInputStream
70 * @see ifc.io._XConnectable
71 * @see ifc.io._XActiveDataSink
72 * @see ifc.io._XObjectInputStream
74 public class ObjectInputStream
extends TestCase
{
77 * Register the implementation of service
78 * <code>com.sun.star.cmp.PersistObject</code> if not yet registered.
79 * @see com.sun.star.cmp.PersistObject
81 public void initialize(TestParameters tParam
, PrintWriter log
) {
82 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF();
83 Object oPersObj
= null;
84 // test first if object is already registered
86 oPersObj
= xMSF
.createInstance("com.sun.star.cmp.PersistObject");
88 catch( com
.sun
.star
.uno
.Exception e
) {
89 log
.println("Could not create instance of PersistObject");
90 e
.printStackTrace(log
);
91 log
.println("Going on with test...");
93 if ( oPersObj
== null ) {
94 // object is not available: it has to be registered
95 String url
= util
.utils
.getFullTestURL
96 ("qadevlibs/MyPersistObjectImpl.jar");
97 XImplementationRegistration xir
;
99 Object o
= xMSF
.createInstance(
100 "com.sun.star.registry.ImplementationRegistration");
101 xir
= UnoRuntime
.queryInterface(
102 XImplementationRegistration
.class, o
);
105 catch (com
.sun
.star
.uno
.Exception e
) {
107 "Couldn't create implementation registration");
109 throw new StatusException("Couldn't create ImplReg", e
);
112 XSimpleRegistry xReg
= null;
114 System
.out
.println("Register library: " + url
);
115 xir
.registerImplementation(
116 "com.sun.star.loader.Java2", url
, xReg
);
117 System
.out
.println("...done");
118 } catch (CannotRegisterImplementationException e
) {
119 System
.err
.println("Name: " + url
+ " msg: " +
122 throw new StatusException(
123 "Couldn't register MyPersistObject", e
);
129 * Creating a Testenvironment for the interfaces to be tested.
130 * Creates an instances of services
131 * <code>com.sun.star.io.ObjectInputStream</code>,
132 * <code>com.sun.star.io.ObjectOutputStream</code>,
133 * <code>com.sun.star.io.Pipe</code>,
134 * <code>com.sun.star.io.MarkableInputStream</code> and
135 * <code>com.sun.star.io.MarkableOutputStream</code>. Plugs the created
136 * markable output stream as output stream for the created
137 * <code>ObjectOutputStream</code>. Plugs the created pipe as output stream
138 * for the created <code>MarkableOutputStream</code>. Plugs the created
139 * markable input stream as input stream for the created
140 * <code>ObjectInputStream</code>. Plugs the created pipe as input stream
141 * for the created <code>MarkableInputStream</code>. Creates an instance
142 * of the service <code>com.sun.star.cmp.PersistObject</code> and writes
143 * the created object to the object output stream.
144 * Object relations created :
146 * <li> <code>'PersistObject'</code> for
147 * {@link ifc.io._XObjectInputStream}(the created instance of the
148 * persist object ) </li>
149 * <li> <code>'StreamData'</code> for
150 * {@link ifc.io._XDataInputStream}(the data that should be written into
152 * <li> <code>'ByteData'</code> for
153 * {@link ifc.io._XInputStream}(the data that should be written into
155 * <li> <code>'StreamWriter'</code> for
156 * {@link ifc.io._XDataInputStream}
157 * {@link ifc.io._XObjectInputStream}
158 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
159 * <li> <code>'Connectable'</code> for
160 * {@link ifc.io._XConnectable}
161 * (another object that can be connected) </li>
162 * <li> <code>'InputStream'</code> for
163 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
165 * @see com.sun.star.io.ObjectInputStream
166 * @see com.sun.star.io.ObjectOutputStream
167 * @see com.sun.star.io.Pipe
168 * @see com.sun.star.io.MarkableInputStream
169 * @see com.sun.star.io.MarkableOutputStream
170 * @see com.sun.star.cmp.PersistObject
172 public TestEnvironment
createTestEnvironment(
173 TestParameters Param
, PrintWriter log
) throws StatusException
{
175 System
.out
.println("create TestEnvironment started.");
176 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();
177 Object ostream
= null;
179 Object mostream
= null;
180 Object mistream
= null;
181 Object istream
= null;
182 Object xConnect
= null;
184 istream
= xMSF
.createInstance
185 ("com.sun.star.io.ObjectInputStream");
186 ostream
= xMSF
.createInstance
187 ("com.sun.star.io.ObjectOutputStream");
188 aPipe
= xMSF
.createInstance
189 ("com.sun.star.io.Pipe");
190 mistream
= xMSF
.createInstance
191 ("com.sun.star.io.MarkableInputStream");
192 mostream
= xMSF
.createInstance
193 ("com.sun.star.io.MarkableOutputStream");
194 xConnect
= xMSF
.createInstance
195 ("com.sun.star.io.DataInputStream") ;
197 } catch( com
.sun
.star
.uno
.Exception e
) {
198 e
.printStackTrace(log
);
199 throw new StatusException("Couldn't create instance", e
);
201 // Creating construction :
202 // ObjectOutputStream -> MarkableOutputStream -> Pipe ->
203 // -> MarkableInputStream -> ObjectInputStream
204 XActiveDataSource xdSo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, ostream
);
206 XActiveDataSource xdSmo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
208 XOutputStream moStream
= UnoRuntime
.queryInterface(XOutputStream
.class, mostream
);
210 XOutputStream PipeOut
= UnoRuntime
.queryInterface(XOutputStream
.class, aPipe
);
211 XInputStream PipeIn
= UnoRuntime
.queryInterface(XInputStream
.class, aPipe
);
213 xdSo
.setOutputStream(moStream
);
214 xdSmo
.setOutputStream(PipeOut
);
216 XObjectInputStream iStream
= UnoRuntime
.queryInterface(XObjectInputStream
.class, istream
);
217 XObjectOutputStream oStream
= null;
218 oStream
= UnoRuntime
.queryInterface(XObjectOutputStream
.class, ostream
);
220 XActiveDataSink xmSi
= UnoRuntime
.queryInterface(XActiveDataSink
.class, mistream
);
221 XInputStream xmIstream
= UnoRuntime
.queryInterface(XInputStream
.class, mistream
);
223 XActiveDataSink xdSi
= UnoRuntime
.queryInterface
224 (XActiveDataSink
.class, istream
);
225 xdSi
.setInputStream(xmIstream
);
226 xmSi
.setInputStream(PipeIn
);
228 // creating Persist object which has to be written
229 XPersistObject xPersObj
= null;
231 Object oPersObj
= xMSF
.createInstance
232 ("com.sun.star.cmp.PersistObject");
233 xPersObj
= UnoRuntime
.queryInterface(XPersistObject
.class, oPersObj
);
234 } catch (com
.sun
.star
.uno
.Exception e
) {
235 e
.printStackTrace(log
);
236 throw new StatusException("Can't write persist object.", e
);
241 // all data types for writing to an XDataInputStream
242 ArrayList
<Object
> data
= new ArrayList
<Object
>() ;
243 data
.add(new Boolean(true)) ;
244 data
.add(new Byte((byte)123)) ;
245 data
.add(new Character((char)1234)) ;
246 data
.add(new Short((short)1234)) ;
247 data
.add(new Integer(123456)) ;
248 data
.add(new Float(1.234)) ;
249 data
.add(new Double(1.23456)) ;
250 data
.add("DataInputStream") ;
251 // information for writing to the pipe
252 byte[] byteData
= new byte[] {
253 1, 2, 3, 4, 5, 6, 7, 8 } ;
256 System
.out
.println("create environment");
257 XInterface oObj
= iStream
;
258 log
.println( "creating a new environment for object" );
259 TestEnvironment tEnv
= new TestEnvironment( oObj
);
261 // adding persistent object
262 tEnv
.addObjRelation("PersistObject", xPersObj
);
264 tEnv
.addObjRelation("Connectable", xConnect
);
265 tEnv
.addObjRelation("StreamWriter", oStream
);
266 // for XActiveDataSink
267 tEnv
.addObjRelation("InputStream", aPipe
);
268 // adding sequence of data that must be read
269 // by XDataInputStream interface methods
270 tEnv
.addObjRelation("StreamData", data
) ;
271 // and by XInputStream interface methods
272 tEnv
.addObjRelation("ByteData", byteData
) ;
274 System
.out
.println("create TestEnvironment finished.");
276 } // finish method getTestEnvironment