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.MarkableOutputStream</code>. <p>
38 * Object implements the following interfaces :
40 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
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::XConnectable</code></li>
45 * @see com.sun.star.io.MarkableOutputStream
46 * @see com.sun.star.io.XMarkableStream
47 * @see com.sun.star.io.XActiveDataSource
48 * @see com.sun.star.io.XOutputStream
49 * @see com.sun.star.io.XConnectable
50 * @see ifc.io._XMarkableStream
51 * @see ifc.io._XActiveDataSource
52 * @see ifc.io._XOutputStream
53 * @see ifc.io._XConnectable
55 public class MarkableOutputStream
extends TestCase
{
58 * Creating a Testenvironment for the interfaces to be tested.
59 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
60 * <code>com.sun.star.io.MarkableInputStream</code> and
61 * <code>com.sun.star.io.MarkableOutputStream</code>.
62 * Plugs the created pipe as output stream for the created
63 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
64 * for the created <code>MarkableInputStream</code>.
65 * Object relations created :
67 * <li> <code>'ByteData'</code> for
68 * {@link ifc.io._XOutputStream}(the data that should be written into
70 * <li> <code>'StreamData'</code> for
71 * {@link ifc.io._XDataOutputStream}(the data that should be
72 * written into the stream) </li>
73 * <li> <code>'Connectable'</code> for
74 * {@link ifc.io._XConnectable}
75 * (another object that can be connected) </li>
76 * <li> <code>'OutputStream'</code> for
77 * {@link ifc.io._XActiveDataSource}
78 * (an input stream to set and get) </li>
79 * <li> <code>'XOutputStream.StreamChecker'</code> for
80 * {@link ifc.io._XOutputStream}( implementation of the interface
81 * ifc.io._XOutputStream.StreamChecker ) </li>
83 * @see com.sun.star.io.Pipe
84 * @see com.sun.star.io.MarkableInputStream
85 * @see com.sun.star.io.MarkableOutputStream
88 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
90 XInterface oObj
= null;
92 XMultiServiceFactory xMSF
= Param
.getMSF();
94 Object mostream
= null;
95 Object mistream
= null;
99 aPipe
= xMSF
.createInstance("com.sun.star.io.Pipe");
100 mistream
= xMSF
.createInstance
101 ("com.sun.star.io.MarkableInputStream");
102 mostream
= xMSF
.createInstance
103 ("com.sun.star.io.MarkableOutputStream");
104 aConnect
= (XInterface
)xMSF
.createInstance
105 ("com.sun.star.io.DataOutputStream");
106 } catch(com
.sun
.star
.uno
.Exception e
) {
107 e
.printStackTrace(log
);
108 throw new StatusException("Couldn't create instance", e
) ;
111 // Creating construction :
112 // MarkableOutputStream -> Pipe -> MarkableInputStream
113 XActiveDataSource xdSmo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
115 final XOutputStream PipeOut
= UnoRuntime
.queryInterface(XOutputStream
.class,aPipe
);
116 final XInputStream PipeIn
= UnoRuntime
.queryInterface(XInputStream
.class,aPipe
);
118 xdSmo
.setOutputStream(PipeOut
);
120 XActiveDataSink xmSi
= UnoRuntime
.queryInterface(XActiveDataSink
.class, mistream
);
122 xmSi
.setInputStream(PipeIn
) ;
124 oObj
= (XInterface
) mostream
;
126 // all data types for writing to an XDataInputStream
127 ArrayList
<Object
> data
= new ArrayList
<Object
>() ;
128 data
.add(Boolean
.TRUE
) ;
129 data
.add(Byte
.valueOf((byte)123)) ;
130 data
.add(new Character((char)1234)) ;
131 data
.add(Short
.valueOf((short)1234)) ;
132 data
.add(Integer
.valueOf(123456)) ;
133 data
.add(new Float(1.234)) ;
134 data
.add(new Double(1.23456)) ;
135 data
.add("DataInputStream") ;
136 // information for writing to the pipe
137 byte[] byteData
= new byte[] {
138 1, 2, 3, 4, 5, 6, 7, 8 } ;
140 log
.println( "creating a new environment for object" );
141 TestEnvironment tEnv
= new TestEnvironment( oObj
);
143 tEnv
.addObjRelation("StreamData", data
);
144 tEnv
.addObjRelation("ByteData", byteData
);
145 tEnv
.addObjRelation("OutputStream", aPipe
);
146 tEnv
.addObjRelation("Connectable", aConnect
);
148 //add relation for io.XOutputStream
149 final XMultiServiceFactory msf
= xMSF
;
150 tEnv
.addObjRelation("XOutputStream.StreamChecker",
151 new ifc
.io
._XOutputStream
.StreamChecker() {
152 XInputStream xInStream
= null;
153 public void resetStreams() {
154 if (xInStream
!= null) {
156 xInStream
.closeInput();
158 } catch(com
.sun
.star
.io
.IOException e
) {
162 PipeOut
.closeOutput();
163 } catch(com
.sun
.star
.io
.IOException e
) {
168 public XInputStream
getInStream() {
171 Object oInStream
= msf
.createInstance(
172 "com.sun.star.io.MarkableInputStream");
173 xInStream
= UnoRuntime
.queryInterface
174 (XInputStream
.class, oInStream
);
175 } catch(com
.sun
.star
.uno
.Exception e
) {
179 XActiveDataSink xDataSink
= UnoRuntime
.queryInterface(
180 XActiveDataSink
.class, xInStream
);
181 xDataSink
.setInputStream(PipeIn
);
188 } // finish method getTestEnvironment