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
.XOutputStream
;
25 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
27 import com
.sun
.star
.uno
.XInterface
;
29 import java
.io
.PrintWriter
;
30 import java
.util
.ArrayList
;
33 import lib
.TestEnvironment
;
34 import lib
.TestParameters
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.io.DataOutputStream</code>. <p>
39 * Object implements the following interfaces :
41 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
42 * <li> <code>com::sun::star::io::XOutputStream</code></li>
43 * <li> <code>com::sun::star::io::XDataOutputStream</code></li>
45 * @see com.sun.star.io.DataOutputStream
46 * @see com.sun.star.io.XActiveDataSource
47 * @see com.sun.star.io.XOutputStream
48 * @see com.sun.star.io.XDataOutputStream
49 * @see ifc.io._XActiveDataSource
50 * @see ifc.io._XOutputStream
51 * @see ifc.io._XDataOutputStream
53 public class DataOutputStream
extends TestCase
{
56 * Creating a TestEnvironment for the interfaces to be tested.
57 * Creates an instance of the service
58 * <code>com.sun.star.io.DataOutputStream</code>
59 * and an instance of the service <code>com.sun.star.io.Pipe</code>.
60 * Plugs the created pipe as output stream for the created DataOutputStream.
61 * @see com.sun.star.io.DataOutputStream
62 * Object relations created :
64 * <li> <code>'StreamData'</code> for
65 * {@link ifc.io._XDataInputStream}(the data that should be written into
67 * <li> <code>'ByteData'</code> for
68 * {@link ifc.io._XInputStream}(the data that should be written into
70 * <li> <code>'OutputStream'</code> for
71 * {@link ifc.io._XActiveDataSource}
72 * (an input stream to set and get) </li>
73 * <li> <code>'XOutputStream.StreamChecker'</code> for
74 * {@link ifc.io._XOutputStream}( implementation of the interface
75 * ifc.io._XOutputStream.StreamChecker ) </li>
79 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
81 XInterface oObj
= null;
82 Object oInterface
= null;
83 XInterface oPipe
= null;
84 XMultiServiceFactory xMSF
= null ;
86 xMSF
= Param
.getMSF();
87 oInterface
= xMSF
.createInstance
88 ("com.sun.star.io.DataOutputStream");
89 oPipe
= (XInterface
)xMSF
.createInstance("com.sun.star.io.Pipe");
91 oObj
= (XInterface
) oInterface
;
93 final XOutputStream xPipeOutput
= UnoRuntime
.queryInterface(XOutputStream
.class, oPipe
);
95 XActiveDataSource xDataSource
= UnoRuntime
.queryInterface(XActiveDataSource
.class, oObj
);
97 xDataSource
.setOutputStream(xPipeOutput
);
99 // all data types for writing to an XDataInputStream
100 ArrayList
<Object
> data
= new ArrayList
<Object
>() ;
101 data
.add(Boolean
.TRUE
) ;
102 data
.add(Byte
.valueOf((byte)123)) ;
103 data
.add(Character
.valueOf((char)1234)) ;
104 data
.add(Short
.valueOf((short)1234)) ;
105 data
.add(Integer
.valueOf(123456)) ;
106 data
.add(Float
.valueOf(1.234f
)) ;
107 data
.add(Double
.valueOf(1.23456)) ;
108 data
.add("DataInputStream") ;
109 // information for writing to the pipe
110 byte[] byteData
= new byte[] {
111 1, 2, 3, 4, 5, 6, 7, 8 } ;
113 log
.println("creating a new environment for object");
114 TestEnvironment tEnv
= new TestEnvironment( oObj
);
116 tEnv
.addObjRelation("StreamData", data
);
117 tEnv
.addObjRelation("ByteData", byteData
);
118 tEnv
.addObjRelation("OutputStream", oPipe
);
120 //add relation for io.XOutputStream
121 final XMultiServiceFactory msf
= xMSF
;
122 final XInputStream xPipeInput
= UnoRuntime
.queryInterface(XInputStream
.class, oPipe
);
123 tEnv
.addObjRelation("XOutputStream.StreamChecker",
124 new ifc
.io
._XOutputStream
.StreamChecker() {
125 XInputStream xInStream
= null;
126 public void resetStreams() {
127 if (xInStream
!= null) {
129 xInStream
.closeInput();
131 } catch(com
.sun
.star
.io
.IOException e
) {
135 xPipeOutput
.closeOutput();
136 } catch(com
.sun
.star
.io
.IOException e
) {
141 public XInputStream
getInStream() {
144 Object oInStream
= msf
.createInstance(
145 "com.sun.star.io.DataInputStream");
146 xInStream
= UnoRuntime
.queryInterface
147 (XInputStream
.class, oInStream
);
148 } catch(com
.sun
.star
.uno
.Exception e
) {
152 XActiveDataSink xDataSink
= UnoRuntime
.queryInterface(
153 XActiveDataSink
.class, xInStream
);
154 xDataSink
.setInputStream(xPipeInput
);
161 } // finish method getTestEnvironment