1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DataOutputStream.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod
._streams
.uno
;
33 import com
.sun
.star
.io
.XActiveDataSink
;
34 import com
.sun
.star
.io
.XActiveDataSource
;
35 import com
.sun
.star
.io
.XInputStream
;
36 import com
.sun
.star
.io
.XOutputStream
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
40 import java
.io
.PrintWriter
;
41 import java
.util
.Vector
;
42 import lib
.StatusException
;
44 import lib
.TestEnvironment
;
45 import lib
.TestParameters
;
48 * Test for object which is represented by service
49 * <code>com.sun.star.io.DataOutputStream</code>. <p>
50 * Object implements the following interfaces :
52 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
53 * <li> <code>com::sun::star::io::XOutputStream</code></li>
54 * <li> <code>com::sun::star::io::XDataOutputStream</code></li>
56 * @see com.sun.star.io.DataOutputStream
57 * @see com.sun.star.io.XActiveDataSource
58 * @see com.sun.star.io.XOutputStream
59 * @see com.sun.star.io.XDataOutputStream
60 * @see ifc.io._XActiveDataSource
61 * @see ifc.io._XOutputStream
62 * @see ifc.io._XDataOutputStream
64 public class DataOutputStream
extends TestCase
{
67 * Creating a Testenvironment for the interfaces to be tested.
68 * Creates an instance of the service
69 * <code>com.sun.star.io.DataOutputStream</code>
70 * and an instance of the service <code>com.sun.star.io.Pipe</code>.
71 * Plugs the created pipe as output stream for the created DataOutputStream.
72 * @see com.sun.star.io.DataOutputStream
73 * Object relations created :
75 * <li> <code>'StreamData'</code> for
76 * {@link ifc.io._XDataInputStream}(the data that should be written into
78 * <li> <code>'ByteData'</code> for
79 * {@link ifc.io._XInputStream}(the data that should be written into
81 * <li> <code>'OutputStream'</code> for
82 * {@link ifc.io._XActiveDataSource}
83 * (an input stream to set and get) </li>
84 * <li> <code>'XOutputStream.StreamChecker'</code> for
85 * {@link ifc.io._XOutputStream}( implementation of the interface
86 * ifc.io._XOutputStream.StreamChecker ) </li>
89 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
91 XInterface oObj
= null;
92 Object oInterface
= null;
93 XInterface oPipe
= null;
94 XMultiServiceFactory xMSF
= null ;
97 xMSF
= (XMultiServiceFactory
)Param
.getMSF();
98 oInterface
= xMSF
.createInstance
99 ("com.sun.star.io.DataOutputStream");
100 oPipe
= (XInterface
)xMSF
.createInstance("com.sun.star.io.Pipe");
101 } catch(com
.sun
.star
.uno
.Exception e
) {
102 e
.printStackTrace(log
);
103 throw new StatusException("Couldn't create instance", e
);
106 oObj
= (XInterface
) oInterface
;
108 final XOutputStream xPipeOutput
= (XOutputStream
)
109 UnoRuntime
.queryInterface(XOutputStream
.class, oPipe
);
111 XActiveDataSource xDataSource
= (XActiveDataSource
)
112 UnoRuntime
.queryInterface(XActiveDataSource
.class, oObj
);
114 xDataSource
.setOutputStream(xPipeOutput
);
116 // all data types for writing to an XDataInputStream
117 Vector data
= new Vector() ;
118 data
.add(new Boolean(true)) ;
119 data
.add(new Byte((byte)123)) ;
120 data
.add(new Character((char)1234)) ;
121 data
.add(new Short((short)1234)) ;
122 data
.add(new Integer(123456)) ;
123 data
.add(new Float(1.234)) ;
124 data
.add(new Double(1.23456)) ;
125 data
.add("DataInputStream") ;
126 // information for writing to the pipe
127 byte[] byteData
= new byte[] {
128 1, 2, 3, 4, 5, 6, 7, 8 } ;
130 log
.println("creating a new environment for object");
131 TestEnvironment tEnv
= new TestEnvironment( oObj
);
133 tEnv
.addObjRelation("StreamData", data
);
134 tEnv
.addObjRelation("ByteData", byteData
);
135 tEnv
.addObjRelation("OutputStream", oPipe
);
137 //add relation for io.XOutputStream
138 final XMultiServiceFactory msf
= xMSF
;
139 final XInputStream xPipeInput
= (XInputStream
)
140 UnoRuntime
.queryInterface(XInputStream
.class, oPipe
);
141 tEnv
.addObjRelation("XOutputStream.StreamChecker",
142 new ifc
.io
._XOutputStream
.StreamChecker() {
143 XInputStream xInStream
= null;
144 public void resetStreams() {
145 if (xInStream
!= null) {
147 xInStream
.closeInput();
149 } catch(com
.sun
.star
.io
.IOException e
) {
153 xPipeOutput
.closeOutput();
154 } catch(com
.sun
.star
.io
.IOException e
) {
159 public XInputStream
getInStream() {
162 Object oInStream
= msf
.createInstance(
163 "com.sun.star.io.DataInputStream");
164 xInStream
= (XInputStream
) UnoRuntime
.queryInterface
165 (XInputStream
.class, oInStream
);
166 } catch(com
.sun
.star
.uno
.Exception e
) {
170 XActiveDataSink xDataSink
= (XActiveDataSink
)
171 UnoRuntime
.queryInterface(
172 XActiveDataSink
.class, xInStream
);
173 xDataSink
.setInputStream(xPipeInput
);
180 } // finish method getTestEnvironment