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
;
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
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.io.ObjectOutputStream</code>. <p>
44 * Object implements the following interfaces :
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>
52 * The following files used by this test :
54 * <li><b> MyPersistObjectImpl.jar </b> : the implementation of the persist
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
{
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
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
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 :
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
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>
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
148 public TestEnvironment
createTestEnvironment(
149 TestParameters Param
, PrintWriter log
) throws Exception
{
151 XInterface oObj
= null;
153 XObjectOutputStream oStream
= null;
155 XMultiServiceFactory xMSF
= Param
.getMSF();
156 Object ostream
= null, istream
= null;
158 Object mostream
= null;
159 XInterface aConnect
= null;
160 Object minstream
= null;
162 ostream
= xMSF
.createInstance
163 ( "com.sun.star.io.ObjectOutputStream" );
164 istream
= xMSF
.createInstance
165 ("com.sun.star.io.ObjectInputStream");
166 aPipe
= xMSF
.createInstance("com.sun.star.io.Pipe");
167 mostream
= xMSF
.createInstance
168 ("com.sun.star.io.MarkableOutputStream");
169 aConnect
= (XInterface
)xMSF
.createInstance
170 ("com.sun.star.io.DataInputStream");
171 minstream
= xMSF
.createInstance
172 ("com.sun.star.io.MarkableInputStream");
174 // creating the pipe where object has to be written to
175 XActiveDataSource xdSo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, ostream
);
177 XActiveDataSource xdSmo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
179 XOutputStream moStream
= UnoRuntime
.queryInterface(XOutputStream
.class, mostream
);
181 XActiveDataSink markIn
= UnoRuntime
.queryInterface(XActiveDataSink
.class, minstream
);
182 XActiveDataSink inStream
= UnoRuntime
.queryInterface(XActiveDataSink
.class, istream
);
183 XInputStream markInStream
= UnoRuntime
.queryInterface(XInputStream
.class, minstream
);
185 final XOutputStream PipeOut
= UnoRuntime
.queryInterface(XOutputStream
.class,aPipe
);
186 final XInputStream PipeIn
= UnoRuntime
.queryInterface(XInputStream
.class,aPipe
);
188 markIn
.setInputStream(PipeIn
);
189 inStream
.setInputStream(markInStream
);
190 XObjectInputStream objInputStream
= UnoRuntime
.queryInterface(XObjectInputStream
.class, istream
);
191 xdSo
.setOutputStream(moStream
);
192 xdSmo
.setOutputStream(PipeOut
);
194 oStream
= UnoRuntime
.queryInterface(XObjectOutputStream
.class, ostream
);
196 // creating Persistent object which has to be written
197 XPersistObject xPersObj
= null ;
198 Object oPersObj
= xMSF
.createInstance
199 ("com.sun.star.cmp.PersistObject");
200 xPersObj
= UnoRuntime
.queryInterface(XPersistObject
.class, oPersObj
);
204 // all data types for writing to an XDataInputStream
205 ArrayList
<Object
> data
= new ArrayList
<Object
>() ;
206 data
.add(Boolean
.TRUE
) ;
207 data
.add(Byte
.valueOf((byte)123)) ;
208 data
.add(Character
.valueOf((char)1234)) ;
209 data
.add(Short
.valueOf((short)1234)) ;
210 data
.add(Integer
.valueOf(123456)) ;
211 data
.add(Float
.valueOf(1.234f
)) ;
212 data
.add(Double
.valueOf(1.23456)) ;
213 data
.add("DataInputStream") ;
214 // information for writing to the pipe
215 byte[] byteData
= new byte[] {
216 1, 2, 3, 4, 5, 6, 7, 8 } ;
218 log
.println("creating a new environment for object");
219 TestEnvironment tEnv
= new TestEnvironment( oObj
);
221 tEnv
.addObjRelation("PersistObject", xPersObj
);
222 tEnv
.addObjRelation("StreamData", data
);
223 tEnv
.addObjRelation("ByteData", byteData
);
224 tEnv
.addObjRelation("OutputStream", aPipe
);
225 tEnv
.addObjRelation("Connectable", aConnect
);
227 tEnv
.addObjRelation("InputStream", objInputStream
);
229 //add relation for io.XOutputStream
230 final XMultiServiceFactory msf
= xMSF
;
231 tEnv
.addObjRelation("XOutputStream.StreamChecker",
232 new ifc
.io
._XOutputStream
.StreamChecker() {
233 XInputStream xInStream
= null;
234 public void resetStreams() {
235 if (xInStream
!= null) {
237 xInStream
.closeInput();
239 } catch(com
.sun
.star
.io
.IOException e
) {
243 PipeOut
.closeOutput();
244 } catch(com
.sun
.star
.io
.IOException e
) {
249 public XInputStream
getInStream() {
252 Object oInStream
= msf
.createInstance(
253 "com.sun.star.io.ObjectInputStream");
254 xInStream
= UnoRuntime
.queryInterface
255 (XInputStream
.class, oInStream
);
256 } catch(com
.sun
.star
.uno
.Exception e
) {
260 XActiveDataSink xDataSink
= UnoRuntime
.queryInterface(
261 XActiveDataSink
.class, xInStream
);
262 xDataSink
.setInputStream(PipeIn
);
269 } // finish method getTestEnvironment