tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _streams / uno / DataOutputStream.java
blob7340ba6a9134ca3448d573463ffb320bd78c5401
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.XActiveDataSink;
22 import com.sun.star.io.XActiveDataSource;
23 import com.sun.star.io.XInputStream;
24 import com.sun.star.io.XOutputStream;
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.XInterface;
29 import java.io.PrintWriter;
30 import java.util.ArrayList;
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.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 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
81 XInterface oObj = null;
82 Object oInterface = null;
83 XInterface oPipe = null;
84 XMultiServiceFactory xMSF = null ;
86 xMSF = Param.getMSF();
87 oInterface = xMSF.createInstance
88 ("com.sun.star.io.DataOutputStream");
89 oPipe = (XInterface)xMSF.createInstance("com.sun.star.io.Pipe");
91 oObj = (XInterface) oInterface;
93 final XOutputStream xPipeOutput = UnoRuntime.queryInterface(XOutputStream.class, oPipe);
95 XActiveDataSource xDataSource = UnoRuntime.queryInterface(XActiveDataSource.class, oObj);
97 xDataSource.setOutputStream(xPipeOutput);
99 // all data types for writing to an XDataInputStream
100 ArrayList<Object> data = new ArrayList<Object>() ;
101 data.add(Boolean.TRUE) ;
102 data.add(Byte.valueOf((byte)123)) ;
103 data.add(Character.valueOf((char)1234)) ;
104 data.add(Short.valueOf((short)1234)) ;
105 data.add(Integer.valueOf(123456)) ;
106 data.add(Float.valueOf(1.234f)) ;
107 data.add(Double.valueOf(1.23456)) ;
108 data.add("DataInputStream") ;
109 // information for writing to the pipe
110 byte[] byteData = new byte[] {
111 1, 2, 3, 4, 5, 6, 7, 8 } ;
113 log.println("creating a new environment for object");
114 TestEnvironment tEnv = new TestEnvironment( oObj );
116 tEnv.addObjRelation("StreamData", data);
117 tEnv.addObjRelation("ByteData", byteData);
118 tEnv.addObjRelation("OutputStream", oPipe);
120 //add relation for io.XOutputStream
121 final XMultiServiceFactory msf = xMSF;
122 final XInputStream xPipeInput = UnoRuntime.queryInterface(XInputStream.class, oPipe);
123 tEnv.addObjRelation("XOutputStream.StreamChecker",
124 new ifc.io._XOutputStream.StreamChecker() {
125 XInputStream xInStream = null;
126 public void resetStreams() {
127 if (xInStream != null) {
128 try {
129 xInStream.closeInput();
130 xInStream = null;
131 } catch(com.sun.star.io.IOException e) {
133 } else {
134 try {
135 xPipeOutput.closeOutput();
136 } catch(com.sun.star.io.IOException e) {
141 public XInputStream getInStream() {
142 resetStreams();
143 try {
144 Object oInStream = msf.createInstance(
145 "com.sun.star.io.DataInputStream");
146 xInStream = UnoRuntime.queryInterface
147 (XInputStream.class, oInStream);
148 } catch(com.sun.star.uno.Exception e) {
149 return null;
152 XActiveDataSink xDataSink = UnoRuntime.queryInterface(
153 XActiveDataSink.class, xInStream);
154 xDataSink.setInputStream(xPipeInput);
156 return xInStream;
160 return tEnv;
161 } // finish method getTestEnvironment