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 .
21 import java
.io
.PrintWriter
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
27 import com
.sun
.star
.io
.NotConnectedException
;
28 import com
.sun
.star
.io
.XActiveDataSink
;
29 import com
.sun
.star
.io
.XActiveDataSource
;
30 import com
.sun
.star
.io
.XInputStream
;
31 import com
.sun
.star
.io
.XOutputStream
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.io.Pump</code>. <p>
39 * Object implements the following interfaces :
41 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
42 * <li> <code>com::sun::star::io::XActiveDataControl</code></li>
43 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
45 * @see com.sun.star.io.Pump
46 * @see com.sun.star.io.XActiveDataSource
47 * @see com.sun.star.io.XActiveDataControl
48 * @see com.sun.star.io.XActiveDataSink
49 * @see ifc.io._XActiveDataSource
50 * @see ifc.io._XActiveDataControl
51 * @see ifc.io._XActiveDataSink
53 public class Pump
extends TestCase
{
56 * Creating a TestEnvironment for the interfaces to be tested.
57 * Creates an instance of the service <code>com.sun.star.io.Pump</code>.
58 * Settings up input and output streams for the created pump.
59 * Object relations created :
61 * <li> <code>'InputStream'</code> for
62 * {@link ifc.io._XActiveDataSource}(an input stream to set) </li>
63 * <li> <code>'OutputStream'</code> for
64 * {@link ifc.io._XActiveDataSource}(an output stream to set) </li>
66 * @see com.sun.star.io.Pump
69 public TestEnvironment
createTestEnvironment(
70 TestParameters Param
, PrintWriter log
) throws Exception
{
72 Object oInterface
= null;
73 XMultiServiceFactory xMSF
= Param
.getMSF();
76 // creating an instance of stm.Pump
77 oInterface
= xMSF
.createInstance( "com.sun.star.io.Pump" );
78 oPipe
= (XInterface
) xMSF
.createInstance( "com.sun.star.io.Pipe" );
81 XInterface oObj
= (XInterface
) oInterface
;
83 // setting up input and output streams for pump
84 XActiveDataSink xSink
= UnoRuntime
.queryInterface(XActiveDataSink
.class, oObj
);
85 XActiveDataSource xSource
= UnoRuntime
.queryInterface(XActiveDataSource
.class, oObj
);
87 XInputStream xInput
= new MyInput();
88 XOutputStream xOutput
= new MyOutput();
90 xSink
.setInputStream(xInput
);
91 xSource
.setOutputStream(xOutput
);
93 log
.println("creating a new environment for object");
94 TestEnvironment tEnv
= new TestEnvironment( oObj
);
96 // add object relations for ActiveDataSource and XActiveDataSink
97 tEnv
.addObjRelation("InputStream", oPipe
);
98 tEnv
.addObjRelation("OutputStream", oPipe
);
101 } // finish method getTestEnvironment
104 * XInputStream implementation to use with the test. It returns bytes of
105 * which a simple string consists.
107 private static class MyInput
implements XInputStream
{
108 String str
= "Pump tesing string" ;
110 public int readBytes(byte[][] bytes
, int len
)
111 throws NotConnectedException
{
114 throw new NotConnectedException("Input stream was closed");
117 if (len
<= str
.length()) {
118 String resStr
= str
.substring(0, len
-1) ;
119 bytes
[0] = resStr
.getBytes() ;
121 str
= str
.substring(len
) ;
123 bytes
[0] = str
.getBytes() ;
124 actual
= str
.length() ;
130 public int readSomeBytes(byte[][] bytes
, int len
)
131 throws NotConnectedException
{
132 return readBytes(bytes
, len
);
135 public void skipBytes(int len
) throws NotConnectedException
{
137 throw new NotConnectedException("Stream was closed.") ;
139 if (len
>= str
.length())
142 str
= str
.substring(len
) ;
145 public void closeInput() throws NotConnectedException
{
147 throw new NotConnectedException("Stream was closed.") ;
152 public int available() throws NotConnectedException
{
154 throw new NotConnectedException("Stream was closed.") ;
161 * Dummy XOutputStream implementation to use with the test. Does nothing.
163 private static class MyOutput
implements XOutputStream
{
164 public void writeBytes(byte[] bytes
) {
167 public void flush() {
170 public void closeOutput() {