bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _streams / uno / Pump.java
blob51c2d4dd670f72f350c000c3e278499d873b5c71
1 /*
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;
31 import lib.TestCase;
32 import lib.TestEnvironment;
33 import lib.TestParameters;
35 /**
36 * Test for object which is represented by service
37 * <code>com.sun.star.io.Pump</code>. <p>
38 * Object implements the following interfaces :
39 * <ul>
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>
43 * </ul>
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 {
54 /**
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 :
59 * <ul>
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>
64 * </ul>
65 * @see com.sun.star.io.Pump
67 @Override
68 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
70 Object oInterface = null;
71 XMultiServiceFactory xMSF = Param.getMSF();
72 XInterface oPipe;
74 // creating an instance of stm.Pump
75 try {
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);
103 return tEnv;
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{
116 if (str == null)
117 throw new NotConnectedException("Input stream was closed");
119 int actual = 0 ;
120 if (len <= str.length()) {
121 String resStr = str.substring(0, len-1) ;
122 bytes[0] = resStr.getBytes() ;
123 actual = len ;
124 str = str.substring(len) ;
125 } else {
126 bytes[0] = str.getBytes() ;
127 actual = str.length() ;
130 return actual;
133 public int readSomeBytes(byte[][] bytes, int len)
134 throws NotConnectedException{
135 return readBytes(bytes, len);
138 public void skipBytes(int len) throws NotConnectedException {
139 if (str == null)
140 throw new NotConnectedException("Stream was closed.") ;
142 if (len >= str.length())
143 str = "" ;
144 else
145 str = str.substring(len) ;
148 public void closeInput() throws NotConnectedException {
149 if (str == null)
150 throw new NotConnectedException("Stream was closed.") ;
152 str = null ;
155 public int available() throws NotConnectedException {
156 if (str == null)
157 throw new NotConnectedException("Stream was closed.") ;
159 return str.length();
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() {