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
.NotConnectedException
;
22 import com
.sun
.star
.io
.XActiveDataSink
;
23 import com
.sun
.star
.io
.XActiveDataSource
;
24 import com
.sun
.star
.io
.XInputStream
;
25 import com
.sun
.star
.io
.XOutputStream
;
26 import com
.sun
.star
.lang
.XMultiServiceFactory
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
28 import com
.sun
.star
.uno
.XInterface
;
29 import java
.io
.PrintWriter
;
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.Pump</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::XActiveDataControl</code></li>
42 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
44 * @see com.sun.star.io.Pump
45 * @see com.sun.star.io.XActiveDataSource
46 * @see com.sun.star.io.XActiveDataControl
47 * @see com.sun.star.io.XActiveDataSink
48 * @see ifc.io._XActiveDataSource
49 * @see ifc.io._XActiveDataControl
50 * @see ifc.io._XActiveDataSink
52 public class Pump
extends TestCase
{
55 * Creating a Testenvironment for the interfaces to be tested.
56 * Creates an instance of the service <code>com.sun.star.io.Pump</code>.
57 * Settings up input and output streams for the created pump.
58 * Object relations created :
60 * <li> <code>'InputStream'</code> for
61 * {@link ifc.io._XActiveDataSource}(an input stream to set) </li>
62 * <li> <code>'OutputStream'</code> for
63 * {@link ifc.io._XActiveDataSource}(an output stream to set) </li>
65 * @see com.sun.star.io.Pump
68 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
70 Object oInterface
= null;
71 XMultiServiceFactory xMSF
= Param
.getMSF();
74 // creating an instance of stm.Pump
76 oInterface
= xMSF
.createInstance( "com.sun.star.io.Pump" );
77 oPipe
= (XInterface
) xMSF
.createInstance( "com.sun.star.io.Pipe" );
78 } catch (com
.sun
.star
.uno
.Exception e
) {
79 e
.printStackTrace(log
);
80 throw new StatusException("Can't create the needed objects.", e
) ;
84 XInterface oObj
= (XInterface
) oInterface
;
86 // setting up input and output streams for pump
87 XActiveDataSink xSink
= UnoRuntime
.queryInterface(XActiveDataSink
.class, oObj
);
88 XActiveDataSource xSource
= UnoRuntime
.queryInterface(XActiveDataSource
.class, oObj
);
90 XInputStream xInput
= new MyInput();
91 XOutputStream xOutput
= new MyOutput();
93 xSink
.setInputStream(xInput
);
94 xSource
.setOutputStream(xOutput
);
96 log
.println("creating a new environment for object");
97 TestEnvironment tEnv
= new TestEnvironment( oObj
);
99 // add object relations for ActiveDataSource and XActiveDataSink
100 tEnv
.addObjRelation("InputStream", oPipe
);
101 tEnv
.addObjRelation("OutputStream", oPipe
);
104 } // finish method getTestEnvironment
107 * XInputStream implementation to use with the test. It returns bytes of
108 * which a simple string consists.
110 private static class MyInput
implements XInputStream
{
111 String str
= "Pump tesing string" ;
113 public int readBytes(byte[][] bytes
, int len
)
114 throws NotConnectedException
{
117 throw new NotConnectedException("Input stream was closed");
120 if (len
<= str
.length()) {
121 String resStr
= str
.substring(0, len
-1) ;
122 bytes
[0] = resStr
.getBytes() ;
124 str
= str
.substring(len
) ;
126 bytes
[0] = str
.getBytes() ;
127 actual
= str
.length() ;
133 public int readSomeBytes(byte[][] bytes
, int len
)
134 throws NotConnectedException
{
135 return readBytes(bytes
, len
);
138 public void skipBytes(int len
) throws NotConnectedException
{
140 throw new NotConnectedException("Stream was closed.") ;
142 if (len
>= str
.length())
145 str
= str
.substring(len
) ;
148 public void closeInput() throws NotConnectedException
{
150 throw new NotConnectedException("Stream was closed.") ;
155 public int available() throws NotConnectedException
{
157 throw new NotConnectedException("Stream was closed.") ;
164 * Dummy XOutputStream implementation to use with the test. Does nothing.
166 private static class MyOutput
implements XOutputStream
{
167 public void writeBytes(byte[] bytes
) {
170 public void flush() {
173 public void closeOutput() {