tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _stm / MarkableOutputStream.java
blob9de6a9a0733cb36ba43c653331e111718c0d134d
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._stm;
21 import java.io.PrintWriter;
22 import java.util.ArrayList;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
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;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.io.MarkableOutputStream</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
42 * <li> <code>com::sun::star::io::XActiveDataSource</code></li>
43 * <li> <code>com::sun::star::io::XOutputStream</code></li>
44 * <li> <code>com::sun::star::io::XConnectable</code></li>
45 * </ul>
46 * @see com.sun.star.io.MarkableOutputStream
47 * @see com.sun.star.io.XMarkableStream
48 * @see com.sun.star.io.XActiveDataSource
49 * @see com.sun.star.io.XOutputStream
50 * @see com.sun.star.io.XConnectable
51 * @see ifc.io._XMarkableStream
52 * @see ifc.io._XActiveDataSource
53 * @see ifc.io._XOutputStream
54 * @see ifc.io._XConnectable
56 public class MarkableOutputStream extends TestCase {
58 /**
59 * Creating a TestEnvironment for the interfaces to be tested.
60 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
61 * <code>com.sun.star.io.MarkableInputStream</code> and
62 * <code>com.sun.star.io.MarkableOutputStream</code>.
63 * Plugs the created pipe as output stream for the created
64 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
65 * for the created <code>MarkableInputStream</code>.
66 * Object relations created :
67 * <ul>
68 * <li> <code>'ByteData'</code> for
69 * {@link ifc.io._XOutputStream}(the data that should be written into
70 * the stream) </li>
71 * <li> <code>'StreamData'</code> for
72 * {@link ifc.io._XDataOutputStream}(the data that should be
73 * written into the stream) </li>
74 * <li> <code>'Connectable'</code> for
75 * {@link ifc.io._XConnectable}
76 * (another object that can be connected) </li>
77 * <li> <code>'OutputStream'</code> for
78 * {@link ifc.io._XActiveDataSource}
79 * (an input stream to set and get) </li>
80 * <li> <code>'XOutputStream.StreamChecker'</code> for
81 * {@link ifc.io._XOutputStream}( implementation of the interface
82 * ifc.io._XOutputStream.StreamChecker ) </li>
83 * </ul>
84 * @see com.sun.star.io.Pipe
85 * @see com.sun.star.io.MarkableInputStream
86 * @see com.sun.star.io.MarkableOutputStream
88 @Override
89 public TestEnvironment createTestEnvironment(
90 TestParameters Param, PrintWriter log) throws Exception {
92 XInterface oObj = null;
94 XMultiServiceFactory xMSF = Param.getMSF();
95 Object aPipe = null;
96 Object mostream = null;
97 Object mistream = null;
98 XInterface aConnect;
100 aPipe = xMSF.createInstance("com.sun.star.io.Pipe");
101 mistream = xMSF.createInstance
102 ("com.sun.star.io.MarkableInputStream");
103 mostream = xMSF.createInstance
104 ("com.sun.star.io.MarkableOutputStream");
105 aConnect = (XInterface)xMSF.createInstance
106 ("com.sun.star.io.DataOutputStream");
108 // Creating construction :
109 // MarkableOutputStream -> Pipe -> MarkableInputStream
110 XActiveDataSource xdSmo = UnoRuntime.queryInterface(XActiveDataSource.class, mostream);
112 final XOutputStream PipeOut = UnoRuntime.queryInterface(XOutputStream.class,aPipe);
113 final XInputStream PipeIn = UnoRuntime.queryInterface(XInputStream.class,aPipe);
115 xdSmo.setOutputStream(PipeOut);
117 XActiveDataSink xmSi = UnoRuntime.queryInterface(XActiveDataSink.class, mistream);
119 xmSi.setInputStream(PipeIn) ;
121 oObj = (XInterface) mostream;
123 // all data types for writing to an XDataInputStream
124 ArrayList<Object> data = new ArrayList<Object>() ;
125 data.add(Boolean.TRUE) ;
126 data.add(Byte.valueOf((byte)123)) ;
127 data.add(Character.valueOf((char)1234)) ;
128 data.add(Short.valueOf((short)1234)) ;
129 data.add(Integer.valueOf(123456)) ;
130 data.add(Float.valueOf(1.234f)) ;
131 data.add(Double.valueOf(1.23456)) ;
132 data.add("DataInputStream") ;
133 // information for writing to the pipe
134 byte[] byteData = new byte[] {
135 1, 2, 3, 4, 5, 6, 7, 8 } ;
137 log.println( "creating a new environment for object" );
138 TestEnvironment tEnv = new TestEnvironment( oObj );
140 tEnv.addObjRelation("StreamData", data);
141 tEnv.addObjRelation("ByteData", byteData);
142 tEnv.addObjRelation("OutputStream", aPipe);
143 tEnv.addObjRelation("Connectable", aConnect);
145 //add relation for io.XOutputStream
146 final XMultiServiceFactory msf = xMSF;
147 tEnv.addObjRelation("XOutputStream.StreamChecker",
148 new ifc.io._XOutputStream.StreamChecker() {
149 XInputStream xInStream = null;
150 public void resetStreams() {
151 if (xInStream != null) {
152 try {
153 xInStream.closeInput();
154 xInStream = null;
155 } catch(com.sun.star.io.IOException e) {
157 } else {
158 try {
159 PipeOut.closeOutput();
160 } catch(com.sun.star.io.IOException e) {
165 public XInputStream getInStream() {
166 resetStreams();
167 try {
168 Object oInStream = msf.createInstance(
169 "com.sun.star.io.MarkableInputStream");
170 xInStream = UnoRuntime.queryInterface
171 (XInputStream.class, oInStream);
172 } catch(com.sun.star.uno.Exception e) {
173 return null;
176 XActiveDataSink xDataSink = UnoRuntime.queryInterface(
177 XActiveDataSink.class, xInStream);
178 xDataSink.setInputStream(PipeIn);
180 return xInStream;
184 return tEnv;
185 } // finish method getTestEnvironment