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
;
28 import java
.io
.PrintWriter
;
29 import java
.util
.ArrayList
;
30 import lib
.StatusException
;
32 import lib
.TestEnvironment
;
33 import lib
.TestParameters
;
36 * Test for object which is represented by service
37 * <code>com.sun.star.io.DataOutputStream</code>. <p>
38 * Object implements the following interfaces :
40 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
41 * <li> <code>com::sun::star::io::XOutputStream</code></li>
42 * <li> <code>com::sun::star::io::XDataOutputStream</code></li>
44 * @see com.sun.star.io.DataOutputStream
45 * @see com.sun.star.io.XActiveDataSource
46 * @see com.sun.star.io.XOutputStream
47 * @see com.sun.star.io.XDataOutputStream
48 * @see ifc.io._XActiveDataSource
49 * @see ifc.io._XOutputStream
50 * @see ifc.io._XDataOutputStream
52 public class DataOutputStream
extends TestCase
{
55 * Creating a Testenvironment for the interfaces to be tested.
56 * Creates an instance of the service
57 * <code>com.sun.star.io.DataOutputStream</code>
58 * and an instance of the service <code>com.sun.star.io.Pipe</code>.
59 * Plugs the created pipe as output stream for the created DataOutputStream.
60 * @see com.sun.star.io.DataOutputStream
61 * Object relations created :
63 * <li> <code>'StreamData'</code> for
64 * {@link ifc.io._XDataInputStream}(the data that should be written into
66 * <li> <code>'ByteData'</code> for
67 * {@link ifc.io._XInputStream}(the data that should be written into
69 * <li> <code>'OutputStream'</code> for
70 * {@link ifc.io._XActiveDataSource}
71 * (an input stream to set and get) </li>
72 * <li> <code>'XOutputStream.StreamChecker'</code> for
73 * {@link ifc.io._XOutputStream}( implementation of the interface
74 * ifc.io._XOutputStream.StreamChecker ) </li>
78 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
80 XInterface oObj
= null;
81 Object oInterface
= null;
82 XInterface oPipe
= null;
83 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");
90 } catch(com
.sun
.star
.uno
.Exception e
) {
91 e
.printStackTrace(log
);
92 throw new StatusException("Couldn't create instance", e
);
95 oObj
= (XInterface
) oInterface
;
97 final XOutputStream xPipeOutput
= UnoRuntime
.queryInterface(XOutputStream
.class, oPipe
);
99 XActiveDataSource xDataSource
= UnoRuntime
.queryInterface(XActiveDataSource
.class, oObj
);
101 xDataSource
.setOutputStream(xPipeOutput
);
103 // all data types for writing to an XDataInputStream
104 ArrayList
<Object
> data
= new ArrayList
<Object
>() ;
105 data
.add(Boolean
.TRUE
) ;
106 data
.add(Byte
.valueOf((byte)123)) ;
107 data
.add(new Character((char)1234)) ;
108 data
.add(Short
.valueOf((short)1234)) ;
109 data
.add(Integer
.valueOf(123456)) ;
110 data
.add(new Float(1.234)) ;
111 data
.add(new Double(1.23456)) ;
112 data
.add("DataInputStream") ;
113 // information for writing to the pipe
114 byte[] byteData
= new byte[] {
115 1, 2, 3, 4, 5, 6, 7, 8 } ;
117 log
.println("creating a new environment for object");
118 TestEnvironment tEnv
= new TestEnvironment( oObj
);
120 tEnv
.addObjRelation("StreamData", data
);
121 tEnv
.addObjRelation("ByteData", byteData
);
122 tEnv
.addObjRelation("OutputStream", oPipe
);
124 //add relation for io.XOutputStream
125 final XMultiServiceFactory msf
= xMSF
;
126 final XInputStream xPipeInput
= UnoRuntime
.queryInterface(XInputStream
.class, oPipe
);
127 tEnv
.addObjRelation("XOutputStream.StreamChecker",
128 new ifc
.io
._XOutputStream
.StreamChecker() {
129 XInputStream xInStream
= null;
130 public void resetStreams() {
131 if (xInStream
!= null) {
133 xInStream
.closeInput();
135 } catch(com
.sun
.star
.io
.IOException e
) {
139 xPipeOutput
.closeOutput();
140 } catch(com
.sun
.star
.io
.IOException e
) {
145 public XInputStream
getInStream() {
148 Object oInStream
= msf
.createInstance(
149 "com.sun.star.io.DataInputStream");
150 xInStream
= UnoRuntime
.queryInterface
151 (XInputStream
.class, oInStream
);
152 } catch(com
.sun
.star
.uno
.Exception e
) {
156 XActiveDataSink xDataSink
= UnoRuntime
.queryInterface(
157 XActiveDataSink
.class, xInStream
);
158 xDataSink
.setInputStream(xPipeInput
);
165 } // finish method getTestEnvironment