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 ************************************************************************/
33 import java
.io
.PrintWriter
;
34 import java
.util
.Vector
;
36 import lib
.StatusException
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
41 import com
.sun
.star
.io
.XActiveDataSink
;
42 import com
.sun
.star
.io
.XActiveDataSource
;
43 import com
.sun
.star
.io
.XInputStream
;
44 import com
.sun
.star
.io
.XOutputStream
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
50 * Test for object which is represented by service
51 * <code>com.sun.star.io.DataOutputStream</code>. <p>
52 * Object implements the following interfaces :
54 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
55 * <li> <code>com::sun::star::io::XOutputStream</code></li>
56 * <li> <code>com::sun::star::io::XDataOutputStream</code></li>
58 * @see com.sun.star.io.DataOutputStream
59 * @see com.sun.star.io.XActiveDataSource
60 * @see com.sun.star.io.XOutputStream
61 * @see com.sun.star.io.XDataOutputStream
62 * @see ifc.io._XActiveDataSource
63 * @see ifc.io._XOutputStream
64 * @see ifc.io._XDataOutputStream
66 public class DataOutputStream
extends TestCase
{
69 * Creating a Testenvironment for the interfaces to be tested.
70 * Creates an instance of the service
71 * <code>com.sun.star.io.DataOutputStream</code>
72 * and an instance of the service <code>com.sun.star.io.Pipe</code>.
73 * Plugs the created pipe as output stream for the created DataOutputStream.
74 * @see com.sun.star.io.DataOutputStream
75 * Object relations created :
77 * <li> <code>'StreamData'</code> for
78 * {@link ifc.io._XDataInputStream}(the data that should be written into
80 * <li> <code>'ByteData'</code> for
81 * {@link ifc.io._XInputStream}(the data that should be written into
83 * <li> <code>'OutputStream'</code> for
84 * {@link ifc.io._XActiveDataSource}
85 * (an input stream to set and get) </li>
86 * <li> <code>'XOutputStream.StreamChecker'</code> for
87 * {@link ifc.io._XOutputStream}( implementation of the interface
88 * ifc.io._XOutputStream.StreamChecker ) </li>
91 public TestEnvironment
createTestEnvironment(
92 TestParameters Param
, PrintWriter log
) throws StatusException
{
94 XInterface oObj
= null;
95 Object oInterface
= null;
96 XInterface oPipe
= null;
97 XMultiServiceFactory xMSF
= null ;
100 xMSF
= (XMultiServiceFactory
)Param
.getMSF();
101 oInterface
= xMSF
.createInstance
102 ("com.sun.star.io.DataOutputStream");
103 oPipe
= (XInterface
)xMSF
.createInstance("com.sun.star.io.Pipe");
104 } catch(com
.sun
.star
.uno
.Exception e
) {
105 e
.printStackTrace(log
);
106 throw new StatusException("Couldn't create instance", e
);
109 oObj
= (XInterface
) oInterface
;
111 final XOutputStream xPipeOutput
= (XOutputStream
)
112 UnoRuntime
.queryInterface(XOutputStream
.class, oPipe
);
114 XActiveDataSource xDataSource
= (XActiveDataSource
)
115 UnoRuntime
.queryInterface(XActiveDataSource
.class, oObj
);
117 xDataSource
.setOutputStream(xPipeOutput
);
119 // all data types for writing to an XDataInputStream
120 Vector data
= new Vector() ;
121 data
.add(new Boolean(true)) ;
122 data
.add(new Byte((byte)123)) ;
123 data
.add(new Character((char)1234)) ;
124 data
.add(new Short((short)1234)) ;
125 data
.add(new Integer(123456)) ;
126 data
.add(new Float(1.234)) ;
127 data
.add(new Double(1.23456)) ;
128 data
.add("DataInputStream") ;
129 // information for writing to the pipe
130 byte[] byteData
= new byte[] {
131 1, 2, 3, 4, 5, 6, 7, 8 } ;
133 log
.println("creating a new environment for object");
134 TestEnvironment tEnv
= new TestEnvironment( oObj
);
136 tEnv
.addObjRelation("StreamData", data
);
137 tEnv
.addObjRelation("ByteData", byteData
);
138 tEnv
.addObjRelation("OutputStream", oPipe
);
140 //add relation for io.XOutputStream
141 final XMultiServiceFactory msf
= xMSF
;
142 final XInputStream xPipeInput
= (XInputStream
)
143 UnoRuntime
.queryInterface(XInputStream
.class, oPipe
);
144 tEnv
.addObjRelation("XOutputStream.StreamChecker",
145 new ifc
.io
._XOutputStream
.StreamChecker() {
146 XInputStream xInStream
= null;
147 public void resetStreams() {
148 if (xInStream
!= null) {
150 xInStream
.closeInput();
152 } catch(com
.sun
.star
.io
.IOException e
) {
156 xPipeOutput
.closeOutput();
157 } catch(com
.sun
.star
.io
.IOException e
) {
162 public XInputStream
getInStream() {
165 Object oInStream
= msf
.createInstance(
166 "com.sun.star.io.DataInputStream");
167 xInStream
= (XInputStream
) UnoRuntime
.queryInterface
168 (XInputStream
.class, oInStream
);
169 } catch(com
.sun
.star
.uno
.Exception e
) {
173 XActiveDataSink xDataSink
= (XActiveDataSink
)
174 UnoRuntime
.queryInterface(
175 XActiveDataSink
.class, xInStream
);
176 xDataSink
.setInputStream(xPipeInput
);
183 } // finish method getTestEnvironment