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
.StatusException
;
39 import lib
.TestEnvironment
;
40 import lib
.TestParameters
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.io.ObjectInputStream</code>. <p>
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::io::XInputStream</code></li>
48 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
49 * <li> <code>com::sun::star::io::XDataInputStream</code></li>
50 * <li> <code>com::sun::star::io::XConnectable</code></li>
51 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
52 * <li> <code>com::sun::star::io::XObjectInputStream</code></li>
54 * The following files used by this test :
56 * <li><b> MyPersistObjectImpl.jar </b> : the implementation of the persist
59 * @see com.sun.star.io.ObjectInputStream
60 * @see com.sun.star.io.XInputStream
61 * @see com.sun.star.io.XMarkableStream
62 * @see com.sun.star.io.XDataInputStream
63 * @see com.sun.star.io.XConnectable
64 * @see com.sun.star.io.XActiveDataSink
65 * @see com.sun.star.io.XObjectInputStream
66 * @see ifc.io._XInputStream
67 * @see ifc.io._XMarkableStream
68 * @see ifc.io._XDataInputStream
69 * @see ifc.io._XConnectable
70 * @see ifc.io._XActiveDataSink
71 * @see ifc.io._XObjectInputStream
73 public class ObjectInputStream
extends TestCase
{
76 * Register the implementation of service
77 * <code>com.sun.star.cmp.PersistObject</code> if not yet registered.
78 * @see com.sun.star.cmp.PersistObject
81 public void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
82 XMultiServiceFactory xMSF
= 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
;
98 Object o
= xMSF
.createInstance(
99 "com.sun.star.registry.ImplementationRegistration");
100 xir
= UnoRuntime
.queryInterface(
101 XImplementationRegistration
.class, o
);
103 XSimpleRegistry xReg
= null;
104 System
.out
.println("Register library: " + url
);
105 xir
.registerImplementation(
106 "com.sun.star.loader.Java2", url
, xReg
);
107 System
.out
.println("...done");
112 * Creating a TestEnvironment for the interfaces to be tested.
113 * Creates an instances of services
114 * <code>com.sun.star.io.ObjectInputStream</code>,
115 * <code>com.sun.star.io.ObjectOutputStream</code>,
116 * <code>com.sun.star.io.Pipe</code>,
117 * <code>com.sun.star.io.MarkableInputStream</code> and
118 * <code>com.sun.star.io.MarkableOutputStream</code>. Plugs the created
119 * markable output stream as output stream for the created
120 * <code>ObjectOutputStream</code>. Plugs the created pipe as output stream
121 * for the created <code>MarkableOutputStream</code>. Plugs the created
122 * markable input stream as input stream for the created
123 * <code>ObjectInputStream</code>. Plugs the created pipe as input stream
124 * for the created <code>MarkableInputStream</code>. Creates an instance
125 * of the service <code>com.sun.star.cmp.PersistObject</code> and writes
126 * the created object to the object output stream.
127 * Object relations created :
129 * <li> <code>'PersistObject'</code> for
130 * {@link ifc.io._XObjectInputStream}(the created instance of the
131 * persist object ) </li>
132 * <li> <code>'StreamData'</code> for
133 * {@link ifc.io._XDataInputStream}(the data that should be written into
135 * <li> <code>'ByteData'</code> for
136 * {@link ifc.io._XInputStream}(the data that should be written into
138 * <li> <code>'StreamWriter'</code> for
139 * {@link ifc.io._XDataInputStream}
140 * {@link ifc.io._XObjectInputStream}
141 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
142 * <li> <code>'Connectable'</code> for
143 * {@link ifc.io._XConnectable}
144 * (another object that can be connected) </li>
145 * <li> <code>'InputStream'</code> for
146 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
148 * @see com.sun.star.io.ObjectInputStream
149 * @see com.sun.star.io.ObjectOutputStream
150 * @see com.sun.star.io.Pipe
151 * @see com.sun.star.io.MarkableInputStream
152 * @see com.sun.star.io.MarkableOutputStream
153 * @see com.sun.star.cmp.PersistObject
156 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
158 System
.out
.println("create TestEnvironment started.");
159 XMultiServiceFactory xMSF
= Param
.getMSF();
160 Object ostream
= 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") ;
178 // Creating construction :
179 // ObjectOutputStream -> MarkableOutputStream -> Pipe ->
180 // -> MarkableInputStream -> ObjectInputStream
181 XActiveDataSource xdSo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, ostream
);
183 XActiveDataSource xdSmo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
185 XOutputStream moStream
= UnoRuntime
.queryInterface(XOutputStream
.class, mostream
);
187 XOutputStream PipeOut
= UnoRuntime
.queryInterface(XOutputStream
.class, aPipe
);
188 XInputStream PipeIn
= UnoRuntime
.queryInterface(XInputStream
.class, aPipe
);
190 xdSo
.setOutputStream(moStream
);
191 xdSmo
.setOutputStream(PipeOut
);
193 XObjectInputStream iStream
= UnoRuntime
.queryInterface(XObjectInputStream
.class, istream
);
194 XObjectOutputStream oStream
= null;
195 oStream
= UnoRuntime
.queryInterface(XObjectOutputStream
.class, ostream
);
197 XActiveDataSink xmSi
= UnoRuntime
.queryInterface(XActiveDataSink
.class, mistream
);
198 XInputStream xmIstream
= UnoRuntime
.queryInterface(XInputStream
.class, mistream
);
200 XActiveDataSink xdSi
= UnoRuntime
.queryInterface
201 (XActiveDataSink
.class, istream
);
202 xdSi
.setInputStream(xmIstream
);
203 xmSi
.setInputStream(PipeIn
);
205 // creating Persist object which has to be written
206 XPersistObject xPersObj
= null;
208 Object oPersObj
= xMSF
.createInstance
209 ("com.sun.star.cmp.PersistObject");
210 xPersObj
= UnoRuntime
.queryInterface(XPersistObject
.class, oPersObj
);
211 } catch (com
.sun
.star
.uno
.Exception e
) {
212 e
.printStackTrace(log
);
213 throw new StatusException("Can't write persist object.", e
);
218 // all data types for writing to an XDataInputStream
219 ArrayList
<Object
> data
= new ArrayList
<Object
>() ;
220 data
.add(Boolean
.TRUE
) ;
221 data
.add(Byte
.valueOf((byte)123)) ;
222 data
.add(Character
.valueOf((char)1234)) ;
223 data
.add(Short
.valueOf((short)1234)) ;
224 data
.add(Integer
.valueOf(123456)) ;
225 data
.add(Float
.valueOf(1.234f
)) ;
226 data
.add(Double
.valueOf(1.23456)) ;
227 data
.add("DataInputStream") ;
228 // information for writing to the pipe
229 byte[] byteData
= new byte[] {
230 1, 2, 3, 4, 5, 6, 7, 8 } ;
233 System
.out
.println("create environment");
234 XInterface oObj
= iStream
;
235 log
.println( "creating a new environment for object" );
236 TestEnvironment tEnv
= new TestEnvironment( oObj
);
238 // adding persistent object
239 tEnv
.addObjRelation("PersistObject", xPersObj
);
241 tEnv
.addObjRelation("Connectable", xConnect
);
242 tEnv
.addObjRelation("StreamWriter", oStream
);
243 // for XActiveDataSink
244 tEnv
.addObjRelation("InputStream", aPipe
);
245 // adding sequence of data that must be read
246 // by XDataInputStream interface methods
247 tEnv
.addObjRelation("StreamData", data
) ;
248 // and by XInputStream interface methods
249 tEnv
.addObjRelation("ByteData", byteData
) ;
251 System
.out
.println("create TestEnvironment finished.");
253 } // finish method getTestEnvironment