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.MarkableOutputStream</code>. <p>
39 * Object implements the following interfaces :
41 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
42 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
43 * <li> <code>com::sun::star::io::XOutputStream</code></li>
44 * <li> <code>com::sun::star::io::XConnectable</code></li>
46 * @see com.sun.star.io.MarkableOutputStream
47 * @see com.sun.star.io.XMarkableStream
48 * @see com.sun.star.io.XActiveDataSource
49 * @see com.sun.star.io.XOutputStream
50 * @see com.sun.star.io.XConnectable
51 * @see ifc.io._XMarkableStream
52 * @see ifc.io._XActiveDataSource
53 * @see ifc.io._XOutputStream
54 * @see ifc.io._XConnectable
56 public class MarkableOutputStream
extends TestCase
{
59 * Creating a TestEnvironment for the interfaces to be tested.
60 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
61 * <code>com.sun.star.io.MarkableInputStream</code> and
62 * <code>com.sun.star.io.MarkableOutputStream</code>.
63 * Plugs the created pipe as output stream for the created
64 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
65 * for the created <code>MarkableInputStream</code>.
66 * Object relations created :
68 * <li> <code>'ByteData'</code> for
69 * {@link ifc.io._XOutputStream}(the data that should be written into
71 * <li> <code>'StreamData'</code> for
72 * {@link ifc.io._XDataOutputStream}(the data that should be
73 * written into the stream) </li>
74 * <li> <code>'Connectable'</code> for
75 * {@link ifc.io._XConnectable}
76 * (another object that can be connected) </li>
77 * <li> <code>'OutputStream'</code> for
78 * {@link ifc.io._XActiveDataSource}
79 * (an input stream to set and get) </li>
80 * <li> <code>'XOutputStream.StreamChecker'</code> for
81 * {@link ifc.io._XOutputStream}( implementation of the interface
82 * ifc.io._XOutputStream.StreamChecker ) </li>
84 * @see com.sun.star.io.Pipe
85 * @see com.sun.star.io.MarkableInputStream
86 * @see com.sun.star.io.MarkableOutputStream
89 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
91 XInterface oObj
= null;
93 XMultiServiceFactory xMSF
= Param
.getMSF();
95 Object mostream
= null;
96 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");
107 // Creating construction :
108 // MarkableOutputStream -> Pipe -> MarkableInputStream
109 XActiveDataSource xdSmo
= UnoRuntime
.queryInterface(XActiveDataSource
.class, mostream
);
111 final XOutputStream PipeOut
= UnoRuntime
.queryInterface(XOutputStream
.class,aPipe
);
112 final XInputStream PipeIn
= UnoRuntime
.queryInterface(XInputStream
.class,aPipe
);
114 xdSmo
.setOutputStream(PipeOut
);
116 XActiveDataSink xmSi
= UnoRuntime
.queryInterface(XActiveDataSink
.class, mistream
);
118 xmSi
.setInputStream(PipeIn
) ;
120 oObj
= (XInterface
) mostream
;
122 // all data types for writing to an XDataInputStream
123 ArrayList
<Object
> data
= new ArrayList
<Object
>() ;
124 data
.add(Boolean
.TRUE
) ;
125 data
.add(Byte
.valueOf((byte)123)) ;
126 data
.add(Character
.valueOf((char)1234)) ;
127 data
.add(Short
.valueOf((short)1234)) ;
128 data
.add(Integer
.valueOf(123456)) ;
129 data
.add(Float
.valueOf(1.234f
)) ;
130 data
.add(Double
.valueOf(1.23456)) ;
131 data
.add("DataInputStream") ;
132 // information for writing to the pipe
133 byte[] byteData
= new byte[] {
134 1, 2, 3, 4, 5, 6, 7, 8 } ;
136 log
.println( "creating a new environment for object" );
137 TestEnvironment tEnv
= new TestEnvironment( oObj
);
139 tEnv
.addObjRelation("StreamData", data
);
140 tEnv
.addObjRelation("ByteData", byteData
);
141 tEnv
.addObjRelation("OutputStream", aPipe
);
142 tEnv
.addObjRelation("Connectable", aConnect
);
144 //add relation for io.XOutputStream
145 final XMultiServiceFactory msf
= xMSF
;
146 tEnv
.addObjRelation("XOutputStream.StreamChecker",
147 new ifc
.io
._XOutputStream
.StreamChecker() {
148 XInputStream xInStream
= null;
149 public void resetStreams() {
150 if (xInStream
!= null) {
152 xInStream
.closeInput();
154 } catch(com
.sun
.star
.io
.IOException e
) {
158 PipeOut
.closeOutput();
159 } catch(com
.sun
.star
.io
.IOException e
) {
164 public XInputStream
getInStream() {
167 Object oInStream
= msf
.createInstance(
168 "com.sun.star.io.MarkableInputStream");
169 xInStream
= UnoRuntime
.queryInterface
170 (XInputStream
.class, oInStream
);
171 } catch(com
.sun
.star
.uno
.Exception e
) {
175 XActiveDataSink xDataSink
= UnoRuntime
.queryInterface(
176 XActiveDataSink
.class, xInStream
);
177 xDataSink
.setInputStream(PipeIn
);
184 } // finish method getTestEnvironment