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
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
28 import com
.sun
.star
.io
.NotConnectedException
;
29 import com
.sun
.star
.io
.XActiveDataSink
;
30 import com
.sun
.star
.io
.XActiveDataSource
;
31 import com
.sun
.star
.io
.XInputStream
;
32 import com
.sun
.star
.io
.XOutputStream
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.io.Pump</code>. <p>
40 * Object implements the following interfaces :
42 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
43 * <li> <code>com::sun::star::io::XActiveDataControl</code></li>
44 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
46 * @see com.sun.star.io.Pump
47 * @see com.sun.star.io.XActiveDataSource
48 * @see com.sun.star.io.XActiveDataControl
49 * @see com.sun.star.io.XActiveDataSink
50 * @see ifc.io._XActiveDataSource
51 * @see ifc.io._XActiveDataControl
52 * @see ifc.io._XActiveDataSink
54 public class Pump
extends TestCase
{
57 * Creating a Testenvironment for the interfaces to be tested.
58 * Creates an instance of the service <code>com.sun.star.io.Pump</code>.
59 * Settings up input and output streams for the created pump.
60 * Object relations created :
62 * <li> <code>'InputStream'</code> for
63 * {@link ifc.io._XActiveDataSource}(an input stream to set) </li>
64 * <li> <code>'OutputStream'</code> for
65 * {@link ifc.io._XActiveDataSource}(an output stream to set) </li>
67 * @see com.sun.star.io.Pump
70 public TestEnvironment
createTestEnvironment(
71 TestParameters Param
, PrintWriter log
) throws StatusException
{
73 Object oInterface
= null;
74 XMultiServiceFactory xMSF
= Param
.getMSF();
77 // creating an instance of stm.Pump
79 oInterface
= xMSF
.createInstance( "com.sun.star.io.Pump" );
80 oPipe
= (XInterface
) xMSF
.createInstance( "com.sun.star.io.Pipe" );
81 } catch (com
.sun
.star
.uno
.Exception e
) {
82 e
.printStackTrace(log
);
83 throw new StatusException("Can't create the needed objects.", e
) ;
87 XInterface oObj
= (XInterface
) oInterface
;
89 // setting up input and output streams for pump
90 XActiveDataSink xSink
= UnoRuntime
.queryInterface(XActiveDataSink
.class, oObj
);
91 XActiveDataSource xSource
= UnoRuntime
.queryInterface(XActiveDataSource
.class, oObj
);
93 XInputStream xInput
= new MyInput();
94 XOutputStream xOutput
= new MyOutput();
96 xSink
.setInputStream(xInput
);
97 xSource
.setOutputStream(xOutput
);
99 log
.println("creating a new environment for object");
100 TestEnvironment tEnv
= new TestEnvironment( oObj
);
102 // add object relations for ActiveDataSource and XActiveDataSink
103 tEnv
.addObjRelation("InputStream", oPipe
);
104 tEnv
.addObjRelation("OutputStream", oPipe
);
107 } // finish method getTestEnvironment
110 * XInputStream implementation to use with the test. It returns bytes of
111 * which a simple string consists.
113 private static class MyInput
implements XInputStream
{
114 String str
= "Pump tesing string" ;
116 public int readBytes(byte[][] bytes
, int len
)
117 throws NotConnectedException
{
120 throw new NotConnectedException("Input stream was closed");
123 if (len
<= str
.length()) {
124 String resStr
= str
.substring(0, len
-1) ;
125 bytes
[0] = resStr
.getBytes() ;
127 str
= str
.substring(len
) ;
129 bytes
[0] = str
.getBytes() ;
130 actual
= str
.length() ;
136 public int readSomeBytes(byte[][] bytes
, int len
)
137 throws NotConnectedException
{
138 return readBytes(bytes
, len
);
141 public void skipBytes(int len
) throws NotConnectedException
{
143 throw new NotConnectedException("Stream was closed.") ;
145 if (len
>= str
.length())
148 str
= str
.substring(len
) ;
151 public void closeInput() throws NotConnectedException
{
153 throw new NotConnectedException("Stream was closed.") ;
158 public int available() throws NotConnectedException
{
160 throw new NotConnectedException("Stream was closed.") ;
167 * Dummy XOutputStream implementation to use with the test. Does nothing.
169 private static class MyOutput
implements XOutputStream
{
170 public void writeBytes(byte[] bytes
) {
173 public void flush() {
176 public void closeOutput() {