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
.XDataOutputStream
;
24 import com
.sun
.star
.io
.XInputStream
;
25 import com
.sun
.star
.io
.XOutputStream
;
26 import com
.sun
.star
.lang
.XMultiServiceFactory
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
28 import com
.sun
.star
.uno
.XInterface
;
29 import java
.io
.PrintWriter
;
30 import java
.util
.ArrayList
;
31 import lib
.StatusException
;
33 import lib
.TestEnvironment
;
34 import lib
.TestParameters
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.io.DataInputStream</code>.
40 * <li> <code>com::sun::star::io::XInputStream</code></li>
41 * <li> <code>com::sun::star::io::XDataInputStream</code></li>
42 * <li> <code>com::sun::star::io::XConnectable</code></li>
43 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
45 * @see com.sun.star.io.DataInputStream
46 * @see com.sun.star.io.XInputStream
47 * @see com.sun.star.io.XDataInputStream
48 * @see com.sun.star.io.XConnectable
49 * @see com.sun.star.io.XActiveDataSink
50 * @see ifc.io._XInputStream
51 * @see ifc.io._XDataInputStream
52 * @see ifc.io._XConnectable
53 * @see ifc.io._XActiveDataSink
55 public class DataInputStream
extends TestCase
{
58 * Creates a Testenvironment for the interfaces to be tested.
59 * Creates <code>com.sun.star.io.DataInputStream</code> object,
60 * connects it to <code>com.sun.star.io.DataOutputStream</code>
61 * through <code>com.sun.star.io.Pipe</code>. All of possible data
62 * types are written into <code>DataOutputStream</code>.
63 * Object relations created :
65 * <li> <code>'StreamData'</code> for
66 * {@link ifc.io._XDataInputStream}(the data that should be written into
68 * <li> <code>'ByteData'</code> for
69 * {@link ifc.io._XInputStream}(the data that should be written into
71 * <li> <code>'StreamWriter'</code> for
72 * {@link ifc.io._XDataInputStream}
73 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
74 * <li> <code>'Connectable'</code> for
75 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
76 * <li> <code>'InputStream'</code> for
77 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
81 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
83 Object oInterface
= null;
85 XMultiServiceFactory xMSF
= Param
.getMSF();
87 oInterface
= xMSF
.createInstance("com.sun.star.io.DataInputStream");
88 } catch(com
.sun
.star
.uno
.Exception e
) {
89 e
.printStackTrace(log
);
90 throw new StatusException("Couldn't create instance", e
);
93 XInterface oObj
= (XInterface
) oInterface
;
95 // creating and connecting DataOutputStream to the
96 // DataInputStream created through the Pipe
97 XActiveDataSink xDataSink
= UnoRuntime
.queryInterface(XActiveDataSink
.class, oObj
);
99 XInterface oPipe
= null;
102 xMSF
.createInstance("com.sun.star.io.Pipe");
103 } catch(com
.sun
.star
.uno
.Exception e
) {
104 e
.printStackTrace(log
);
105 throw new StatusException("Couldn't create instance", e
);
108 XInputStream xPipeInput
= UnoRuntime
.queryInterface(XInputStream
.class, oPipe
);
109 XOutputStream xPipeOutput
= UnoRuntime
.queryInterface(XOutputStream
.class, oPipe
);
111 XInterface oDataOutput
= null;
113 oDataOutput
= (XInterface
)
114 xMSF
.createInstance("com.sun.star.io.DataOutputStream");
115 } catch(com
.sun
.star
.uno
.Exception e
) {
116 e
.printStackTrace(log
);
117 throw new StatusException("Couldn't create instance", e
);
120 XDataOutputStream xDataOutput
= UnoRuntime
.queryInterface(XDataOutputStream
.class, oDataOutput
) ;
121 XActiveDataSource xDataSource
= UnoRuntime
.queryInterface(XActiveDataSource
.class, oDataOutput
) ;
123 xDataSource
.setOutputStream(xPipeOutput
) ;
124 xDataSink
.setInputStream(xPipeInput
) ;
126 // all data types for writing to an XDataInputStream
127 ArrayList
<Object
> data
= new ArrayList
<Object
>() ;
128 data
.add(Boolean
.TRUE
) ;
129 data
.add(Byte
.valueOf((byte)123)) ;
130 data
.add(new Character((char)1234)) ;
131 data
.add(Short
.valueOf((short)1234)) ;
132 data
.add(Integer
.valueOf(123456)) ;
133 data
.add(new Float(1.234)) ;
134 data
.add(new Double(1.23456)) ;
135 data
.add("DataInputStream") ;
136 // information for writing to the pipe
137 byte[] byteData
= new byte[] {
138 1, 2, 3, 4, 5, 6, 7, 8 } ;
140 // createing a connectable object for XConnectable interface
141 XInterface xConnect
= null;
143 xConnect
= (XInterface
)xMSF
.createInstance(
144 "com.sun.star.io.DataInputStream") ;
145 } catch (Exception e
) {
146 log
.println("Can't create DataInputStream");
147 e
.printStackTrace(log
);
148 throw new StatusException("Can't create DataInputStream", e
);
151 // creating an input stream to set in XActiveDataSink
152 XInterface oDataInput
= null;
154 oDataInput
= (XInterface
) xMSF
.createInstance(
155 "com.sun.star.io.Pipe" );
156 } catch (com
.sun
.star
.uno
.Exception e
) {
157 log
.println("Can't create new in stream") ;
158 e
.printStackTrace(log
) ;
159 throw new StatusException("Can't create input stream", e
) ;
163 log
.println("creating a new environment for object");
164 TestEnvironment tEnv
= new TestEnvironment( oObj
);
166 // adding sequence of data that must be read
167 // by XDataInputStream interface methods
168 tEnv
.addObjRelation("StreamData", data
) ;
170 tEnv
.addObjRelation("StreamWriter", xDataOutput
);
172 tEnv
.addObjRelation("Connectable", xConnect
);
173 // add an inputStream
174 tEnv
.addObjRelation("InputStream", oDataInput
);
175 tEnv
.addObjRelation("ByteData", byteData
);
178 } // finish method getTestEnvironment