tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _streams / uno / Pump.java
blob85669fbcc3fdcc4d6dcf961e17d1f13005e76a2f
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;
30 import java.io.PrintWriter;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.io.Pump</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
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>
44 * </ul>
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 {
55 /**
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 :
60 * <ul>
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>
65 * </ul>
66 * @see com.sun.star.io.Pump
68 @Override
69 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
71 Object oInterface = null;
72 XMultiServiceFactory xMSF = Param.getMSF();
73 XInterface oPipe;
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);
98 return tEnv;
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{
111 if (str == null)
112 throw new NotConnectedException("Input stream was closed");
114 int actual = 0 ;
115 if (len <= str.length()) {
116 String resStr = str.substring(0, len-1) ;
117 bytes[0] = resStr.getBytes() ;
118 actual = len ;
119 str = str.substring(len) ;
120 } else {
121 bytes[0] = str.getBytes() ;
122 actual = str.length() ;
125 return actual;
128 public int readSomeBytes(byte[][] bytes, int len)
129 throws NotConnectedException{
130 return readBytes(bytes, len);
133 public void skipBytes(int len) throws NotConnectedException {
134 if (str == null)
135 throw new NotConnectedException("Stream was closed.") ;
137 if (len >= str.length())
138 str = "" ;
139 else
140 str = str.substring(len) ;
143 public void closeInput() throws NotConnectedException {
144 if (str == null)
145 throw new NotConnectedException("Stream was closed.") ;
147 str = null ;
150 public int available() throws NotConnectedException {
151 if (str == null)
152 throw new NotConnectedException("Stream was closed.") ;
154 return str.length();
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() {