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
.XDataOutputStream
;
32 import com
.sun
.star
.io
.XInputStream
;
33 import com
.sun
.star
.io
.XOutputStream
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
39 * Test for object which is represented by service
40 * <code>com.sun.star.io.DataInputStream</code>.
42 * <li> <code>com::sun::star::io::XInputStream</code></li>
43 * <li> <code>com::sun::star::io::XDataInputStream</code></li>
44 * <li> <code>com::sun::star::io::XConnectable</code></li>
45 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
47 * @see com.sun.star.io.DataInputStream
48 * @see com.sun.star.io.XInputStream
49 * @see com.sun.star.io.XDataInputStream
50 * @see com.sun.star.io.XConnectable
51 * @see com.sun.star.io.XActiveDataSink
52 * @see ifc.io._XInputStream
53 * @see ifc.io._XDataInputStream
54 * @see ifc.io._XConnectable
55 * @see ifc.io._XActiveDataSink
57 public class DataInputStream
extends TestCase
{
60 * Creates a Testenvironment for the interfaces to be tested.
61 * Creates <code>com.sun.star.io.DataInputStream</code> object,
62 * connects it to <code>com.sun.star.io.DataOutputStream</code>
63 * through <code>com.sun.star.io.Pipe</code>. All of possible data
64 * types are written into <code>DataOutputStream</code>.
65 * Object relations created :
67 * <li> <code>'StreamData'</code> for
68 * {@link ifc.io._XDataInputStream}(the data that should be written into
70 * <li> <code>'ByteData'</code> for
71 * {@link ifc.io._XInputStream}(the data that should be written into
73 * <li> <code>'StreamWriter'</code> for
74 * {@link ifc.io._XDataInputStream}
75 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
76 * <li> <code>'Connectable'</code> for
77 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
78 * <li> <code>'InputStream'</code> for
79 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
82 public TestEnvironment
createTestEnvironment(
83 TestParameters Param
, PrintWriter log
) throws StatusException
{
85 Object oInterface
= null;
87 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();
89 oInterface
= xMSF
.createInstance("com.sun.star.io.DataInputStream");
90 } catch(com
.sun
.star
.uno
.Exception e
) {
91 e
.printStackTrace(log
);
92 throw new StatusException("Couldn't create instance", e
);
95 XInterface oObj
= (XInterface
) oInterface
;
97 // creating and connecting DataOutputStream to the
98 // DataInputStream created through the Pipe
99 XActiveDataSink xDataSink
= UnoRuntime
.queryInterface(XActiveDataSink
.class, oObj
);
101 XInterface oPipe
= null;
104 xMSF
.createInstance("com.sun.star.io.Pipe");
105 } catch(com
.sun
.star
.uno
.Exception e
) {
106 e
.printStackTrace(log
);
107 throw new StatusException("Couldn't create instance", e
);
110 XInputStream xPipeInput
= UnoRuntime
.queryInterface(XInputStream
.class, oPipe
);
111 XOutputStream xPipeOutput
= UnoRuntime
.queryInterface(XOutputStream
.class, oPipe
);
113 XInterface oDataOutput
= null;
115 oDataOutput
= (XInterface
)
116 xMSF
.createInstance("com.sun.star.io.DataOutputStream");
117 } catch(com
.sun
.star
.uno
.Exception e
) {
118 e
.printStackTrace(log
);
119 throw new StatusException("Couldn't create instance", e
);
122 XDataOutputStream xDataOutput
= UnoRuntime
.queryInterface(XDataOutputStream
.class, oDataOutput
) ;
123 XActiveDataSource xDataSource
= UnoRuntime
.queryInterface(XActiveDataSource
.class, oDataOutput
) ;
125 xDataSource
.setOutputStream(xPipeOutput
) ;
126 xDataSink
.setInputStream(xPipeInput
) ;
128 // all data types for writing to an XDataInputStream
129 ArrayList
<Object
> data
= new ArrayList
<Object
>();
130 data
.add(new Boolean(true)) ;
131 data
.add(new Byte((byte)123)) ;
132 data
.add(new Character((char)1234)) ;
133 data
.add(new Short((short)1234)) ;
134 data
.add(new Integer(123456)) ;
135 data
.add(new Float(1.234)) ;
136 data
.add(new Double(1.23456)) ;
137 data
.add("DataInputStream") ;
138 // information for writing to the pipe
139 byte[] byteData
= new byte[] {
140 1, 2, 3, 4, 5, 6, 7, 8 } ;
142 // createing a connectable object for XConnectable interface
143 XInterface xConnect
= null;
145 xConnect
= (XInterface
)xMSF
.createInstance(
146 "com.sun.star.io.DataInputStream") ;
147 } catch (Exception e
) {
148 log
.println("Can't create DataInputStream");
149 e
.printStackTrace(log
);
150 throw new StatusException("Can't create DataInputStream", e
);
153 // creating an input stream to set in XActiveDataSink
154 XInterface oDataInput
= null;
156 oDataInput
= (XInterface
) xMSF
.createInstance(
157 "com.sun.star.io.Pipe" );
158 } catch (com
.sun
.star
.uno
.Exception e
) {
159 log
.println("Can't create new in stream") ;
160 e
.printStackTrace(log
) ;
161 throw new StatusException("Can't create input stream", e
) ;
165 log
.println("creating a new environment for object");
166 TestEnvironment tEnv
= new TestEnvironment( oObj
);
168 // adding sequence of data that must be read
169 // by XDataInputStream interface methods
170 tEnv
.addObjRelation("StreamData", data
) ;
172 tEnv
.addObjRelation("StreamWriter", xDataOutput
);
174 tEnv
.addObjRelation("Connectable", xConnect
);
175 // add an inputStream
176 tEnv
.addObjRelation("InputStream", oDataInput
);
177 tEnv
.addObjRelation("ByteData", byteData
);
180 } // finish method getTestEnvironment