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
;
30 import java
.io
.PrintWriter
;
33 import lib
.TestEnvironment
;
34 import lib
.TestParameters
;
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 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
71 Object oInterface
= null;
72 XMultiServiceFactory xMSF
= Param
.getMSF();
75 // 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" );
79 XInterface oObj
= (XInterface
) oInterface
;
81 // setting up input and output streams for pump
82 XActiveDataSink xSink
= UnoRuntime
.queryInterface(XActiveDataSink
.class, oObj
);
83 XActiveDataSource xSource
= UnoRuntime
.queryInterface(XActiveDataSource
.class, oObj
);
85 XInputStream xInput
= new MyInput();
86 XOutputStream xOutput
= new MyOutput();
88 xSink
.setInputStream(xInput
);
89 xSource
.setOutputStream(xOutput
);
91 log
.println("creating a new environment for object");
92 TestEnvironment tEnv
= new TestEnvironment( oObj
);
94 // add object relations for ActiveDataSource and XActiveDataSink
95 tEnv
.addObjRelation("InputStream", oPipe
);
96 tEnv
.addObjRelation("OutputStream", oPipe
);
99 } // finish method getTestEnvironment
102 * XInputStream implementation to use with the test. It returns bytes of
103 * which a simple string consists.
105 private static class MyInput
implements XInputStream
{
106 String str
= "Pump tesing string" ;
108 public int readBytes(byte[][] bytes
, int len
)
109 throws NotConnectedException
{
112 throw new NotConnectedException("Input stream was closed");
115 if (len
<= str
.length()) {
116 String resStr
= str
.substring(0, len
-1) ;
117 bytes
[0] = resStr
.getBytes() ;
119 str
= str
.substring(len
) ;
121 bytes
[0] = str
.getBytes() ;
122 actual
= str
.length() ;
128 public int readSomeBytes(byte[][] bytes
, int len
)
129 throws NotConnectedException
{
130 return readBytes(bytes
, len
);
133 public void skipBytes(int len
) throws NotConnectedException
{
135 throw new NotConnectedException("Stream was closed.") ;
137 if (len
>= str
.length())
140 str
= str
.substring(len
) ;
143 public void closeInput() throws NotConnectedException
{
145 throw new NotConnectedException("Stream was closed.") ;
150 public int available() throws NotConnectedException
{
152 throw new NotConnectedException("Stream was closed.") ;
159 * Dummy XOutputStream implementation to use with the test. Does nothing.
161 private static class MyOutput
implements XOutputStream
{
162 public void writeBytes(byte[] bytes
) {
165 public void flush() {
168 public void closeOutput() {