tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _stm / DataOutputStream.java
blob63af39ee1573c3dc7c2babc4d8f8748f09700f6e
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.DataOutputStream</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::XOutputStream</code></li>
43 * <li> <code>com::sun::star::io::XDataOutputStream</code></li>
44 * </ul>
45 * @see com.sun.star.io.DataOutputStream
46 * @see com.sun.star.io.XActiveDataSource
47 * @see com.sun.star.io.XOutputStream
48 * @see com.sun.star.io.XDataOutputStream
49 * @see ifc.io._XActiveDataSource
50 * @see ifc.io._XOutputStream
51 * @see ifc.io._XDataOutputStream
53 public class DataOutputStream extends TestCase {
55 /**
56 * Creating a TestEnvironment for the interfaces to be tested.
57 * Creates an instance of the service
58 * <code>com.sun.star.io.DataOutputStream</code>
59 * and an instance of the service <code>com.sun.star.io.Pipe</code>.
60 * Plugs the created pipe as output stream for the created DataOutputStream.
61 * @see com.sun.star.io.DataOutputStream
62 * Object relations created :
63 * <ul>
64 * <li> <code>'StreamData'</code> for
65 * {@link ifc.io._XDataInputStream}(the data that should be written into
66 * the stream) </li>
67 * <li> <code>'ByteData'</code> for
68 * {@link ifc.io._XInputStream}(the data that should be written into
69 * the stream) </li>
70 * <li> <code>'OutputStream'</code> for
71 * {@link ifc.io._XActiveDataSource}
72 * (an input stream to set and get) </li>
73 * <li> <code>'XOutputStream.StreamChecker'</code> for
74 * {@link ifc.io._XOutputStream}( implementation of the interface
75 * ifc.io._XOutputStream.StreamChecker ) </li>
76 * </ul>
78 @Override
79 public TestEnvironment createTestEnvironment(
80 TestParameters Param, PrintWriter log) throws Exception {
82 XInterface oObj = null;
83 Object oInterface = null;
84 XInterface oPipe = null;
85 XMultiServiceFactory xMSF = null ;
87 xMSF = Param.getMSF();
88 oInterface = xMSF.createInstance
89 ("com.sun.star.io.DataOutputStream");
90 oPipe = (XInterface)xMSF.createInstance("com.sun.star.io.Pipe");
92 oObj = (XInterface) oInterface;
94 final XOutputStream xPipeOutput = UnoRuntime.queryInterface(XOutputStream.class, oPipe);
96 XActiveDataSource xDataSource = UnoRuntime.queryInterface(XActiveDataSource.class, oObj);
98 xDataSource.setOutputStream(xPipeOutput);
100 // all data types for writing to an XDataInputStream
101 ArrayList<Object> data = new ArrayList<Object>() ;
102 data.add(Boolean.TRUE) ;
103 data.add(Byte.valueOf((byte)123)) ;
104 data.add(Character.valueOf((char)1234)) ;
105 data.add(Short.valueOf((short)1234)) ;
106 data.add(Integer.valueOf(123456)) ;
107 data.add(Float.valueOf(1.234f)) ;
108 data.add(Double.valueOf(1.23456)) ;
109 data.add("DataInputStream") ;
110 // information for writing to the pipe
111 byte[] byteData = new byte[] {
112 1, 2, 3, 4, 5, 6, 7, 8 } ;
114 log.println("creating a new environment for object");
115 TestEnvironment tEnv = new TestEnvironment( oObj );
117 tEnv.addObjRelation("StreamData", data);
118 tEnv.addObjRelation("ByteData", byteData);
119 tEnv.addObjRelation("OutputStream", oPipe);
121 //add relation for io.XOutputStream
122 final XMultiServiceFactory msf = xMSF;
123 final XInputStream xPipeInput = UnoRuntime.queryInterface(XInputStream.class, oPipe);
124 tEnv.addObjRelation("XOutputStream.StreamChecker",
125 new ifc.io._XOutputStream.StreamChecker() {
126 XInputStream xInStream = null;
127 public void resetStreams() {
128 if (xInStream != null) {
129 try {
130 xInStream.closeInput();
131 xInStream = null;
132 } catch(com.sun.star.io.IOException e) {
134 } else {
135 try {
136 xPipeOutput.closeOutput();
137 } catch(com.sun.star.io.IOException e) {
142 public XInputStream getInStream() {
143 resetStreams();
144 try {
145 Object oInStream = msf.createInstance(
146 "com.sun.star.io.DataInputStream");
147 xInStream = UnoRuntime.queryInterface
148 (XInputStream.class, oInStream);
149 } catch(com.sun.star.uno.Exception e) {
150 return null;
153 XActiveDataSink xDataSink = UnoRuntime.queryInterface(
154 XActiveDataSink.class, xInStream);
155 xDataSink.setInputStream(xPipeInput);
157 return xInStream;
161 return tEnv;
162 } // finish method getTestEnvironment