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
.XDataOutputStream
;
31 import com
.sun
.star
.io
.XInputStream
;
32 import com
.sun
.star
.io
.XOutputStream
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.io.DataInputStream</code>.
41 * <li> <code>com::sun::star::io::XInputStream</code></li>
42 * <li> <code>com::sun::star::io::XDataInputStream</code></li>
43 * <li> <code>com::sun::star::io::XConnectable</code></li>
44 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
46 * @see com.sun.star.io.DataInputStream
47 * @see com.sun.star.io.XInputStream
48 * @see com.sun.star.io.XDataInputStream
49 * @see com.sun.star.io.XConnectable
50 * @see com.sun.star.io.XActiveDataSink
51 * @see ifc.io._XInputStream
52 * @see ifc.io._XDataInputStream
53 * @see ifc.io._XConnectable
54 * @see ifc.io._XActiveDataSink
56 public class DataInputStream
extends TestCase
{
59 * Creates a TestEnvironment for the interfaces to be tested.
60 * Creates <code>com.sun.star.io.DataInputStream</code> object,
61 * connects it to <code>com.sun.star.io.DataOutputStream</code>
62 * through <code>com.sun.star.io.Pipe</code>. All of possible data
63 * types are written into <code>DataOutputStream</code>.
64 * Object relations created :
66 * <li> <code>'StreamData'</code> for
67 * {@link ifc.io._XDataInputStream}(the data that should be written into
69 * <li> <code>'ByteData'</code> for
70 * {@link ifc.io._XInputStream}(the data that should be written into
72 * <li> <code>'StreamWriter'</code> for
73 * {@link ifc.io._XDataInputStream}
74 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
75 * <li> <code>'Connectable'</code> for
76 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
77 * <li> <code>'InputStream'</code> for
78 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
82 public TestEnvironment
createTestEnvironment(
83 TestParameters Param
, PrintWriter log
) throws Exception
{
85 Object oInterface
= null;
87 XMultiServiceFactory xMSF
= Param
.getMSF();
88 oInterface
= xMSF
.createInstance("com.sun.star.io.DataInputStream");
90 XInterface oObj
= (XInterface
) oInterface
;
92 // creating and connecting DataOutputStream to the
93 // DataInputStream created through the Pipe
94 XActiveDataSink xDataSink
= UnoRuntime
.queryInterface(XActiveDataSink
.class, oObj
);
96 XInterface oPipe
= (XInterface
)
97 xMSF
.createInstance("com.sun.star.io.Pipe");
99 XInputStream xPipeInput
= UnoRuntime
.queryInterface(XInputStream
.class, oPipe
);
100 XOutputStream xPipeOutput
= UnoRuntime
.queryInterface(XOutputStream
.class, oPipe
);
102 XInterface oDataOutput
= (XInterface
)
103 xMSF
.createInstance("com.sun.star.io.DataOutputStream");
105 XDataOutputStream xDataOutput
= UnoRuntime
.queryInterface(XDataOutputStream
.class, oDataOutput
) ;
106 XActiveDataSource xDataSource
= UnoRuntime
.queryInterface(XActiveDataSource
.class, oDataOutput
) ;
108 xDataSource
.setOutputStream(xPipeOutput
) ;
109 xDataSink
.setInputStream(xPipeInput
) ;
111 // all data types for writing to an XDataInputStream
112 ArrayList
<Object
> data
= new ArrayList
<Object
>();
113 data
.add(Boolean
.TRUE
) ;
114 data
.add(Byte
.valueOf((byte)123)) ;
115 data
.add(Character
.valueOf((char)1234)) ;
116 data
.add(Short
.valueOf((short)1234)) ;
117 data
.add(Integer
.valueOf(123456)) ;
118 data
.add(Float
.valueOf(1.234f
)) ;
119 data
.add(Double
.valueOf(1.23456)) ;
120 data
.add("DataInputStream") ;
121 // information for writing to the pipe
122 byte[] byteData
= new byte[] {
123 1, 2, 3, 4, 5, 6, 7, 8 } ;
125 // creating a connectable object for XConnectable interface
126 XInterface xConnect
= (XInterface
)xMSF
.createInstance(
127 "com.sun.star.io.DataInputStream") ;
129 // creating an input stream to set in XActiveDataSink
130 XInterface oDataInput
= (XInterface
) xMSF
.createInstance(
131 "com.sun.star.io.Pipe" );
134 log
.println("creating a new environment for object");
135 TestEnvironment tEnv
= new TestEnvironment( oObj
);
137 // adding sequence of data that must be read
138 // by XDataInputStream interface methods
139 tEnv
.addObjRelation("StreamData", data
) ;
141 tEnv
.addObjRelation("StreamWriter", xDataOutput
);
143 tEnv
.addObjRelation("Connectable", xConnect
);
144 // add an inputStream
145 tEnv
.addObjRelation("InputStream", oDataInput
);
146 tEnv
.addObjRelation("ByteData", byteData
);
149 } // finish method getTestEnvironment