bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _streams / uno / DataOutputStream.java
blob85cc334414cc6ee5582ee760e1710a14fd9aa98f
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;
28 import java.io.PrintWriter;
29 import java.util.ArrayList;
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.DataOutputStream</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::XOutputStream</code></li>
42 * <li> <code>com::sun::star::io::XDataOutputStream</code></li>
43 * </ul>
44 * @see com.sun.star.io.DataOutputStream
45 * @see com.sun.star.io.XActiveDataSource
46 * @see com.sun.star.io.XOutputStream
47 * @see com.sun.star.io.XDataOutputStream
48 * @see ifc.io._XActiveDataSource
49 * @see ifc.io._XOutputStream
50 * @see ifc.io._XDataOutputStream
52 public class DataOutputStream extends TestCase {
54 /**
55 * Creating a Testenvironment for the interfaces to be tested.
56 * Creates an instance of the service
57 * <code>com.sun.star.io.DataOutputStream</code>
58 * and an instance of the service <code>com.sun.star.io.Pipe</code>.
59 * Plugs the created pipe as output stream for the created DataOutputStream.
60 * @see com.sun.star.io.DataOutputStream
61 * Object relations created :
62 * <ul>
63 * <li> <code>'StreamData'</code> for
64 * {@link ifc.io._XDataInputStream}(the data that should be written into
65 * the stream) </li>
66 * <li> <code>'ByteData'</code> for
67 * {@link ifc.io._XInputStream}(the data that should be written into
68 * the stream) </li>
69 * <li> <code>'OutputStream'</code> for
70 * {@link ifc.io._XActiveDataSource}
71 * (an input stream to set and get) </li>
72 * <li> <code>'XOutputStream.StreamChecker'</code> for
73 * {@link ifc.io._XOutputStream}( implementation of the interface
74 * ifc.io._XOutputStream.StreamChecker ) </li>
75 * </ul>
77 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
79 XInterface oObj = null;
80 Object oInterface = null;
81 XInterface oPipe = null;
82 XMultiServiceFactory xMSF = null ;
84 try {
85 xMSF = (XMultiServiceFactory)Param.getMSF();
86 oInterface = xMSF.createInstance
87 ("com.sun.star.io.DataOutputStream");
88 oPipe = (XInterface)xMSF.createInstance("com.sun.star.io.Pipe");
89 } catch(com.sun.star.uno.Exception e) {
90 e.printStackTrace(log);
91 throw new StatusException("Couldn't create instance", e);
94 oObj = (XInterface) oInterface;
96 final XOutputStream xPipeOutput = UnoRuntime.queryInterface(XOutputStream.class, oPipe);
98 XActiveDataSource xDataSource = UnoRuntime.queryInterface(XActiveDataSource.class, oObj);
100 xDataSource.setOutputStream(xPipeOutput);
102 // all data types for writing to an XDataInputStream
103 ArrayList<Object> data = new ArrayList<Object>() ;
104 data.add(new Boolean(true)) ;
105 data.add(new Byte((byte)123)) ;
106 data.add(new Character((char)1234)) ;
107 data.add(new Short((short)1234)) ;
108 data.add(new Integer(123456)) ;
109 data.add(new Float(1.234)) ;
110 data.add(new Double(1.23456)) ;
111 data.add("DataInputStream") ;
112 // information for writing to the pipe
113 byte[] byteData = new byte[] {
114 1, 2, 3, 4, 5, 6, 7, 8 } ;
116 log.println("creating a new environment for object");
117 TestEnvironment tEnv = new TestEnvironment( oObj );
119 tEnv.addObjRelation("StreamData", data);
120 tEnv.addObjRelation("ByteData", byteData);
121 tEnv.addObjRelation("OutputStream", oPipe);
123 //add relation for io.XOutputStream
124 final XMultiServiceFactory msf = xMSF;
125 final XInputStream xPipeInput = UnoRuntime.queryInterface(XInputStream.class, oPipe);
126 tEnv.addObjRelation("XOutputStream.StreamChecker",
127 new ifc.io._XOutputStream.StreamChecker() {
128 XInputStream xInStream = null;
129 public void resetStreams() {
130 if (xInStream != null) {
131 try {
132 xInStream.closeInput();
133 xInStream = null;
134 } catch(com.sun.star.io.IOException e) {
136 } else {
137 try {
138 xPipeOutput.closeOutput();
139 } catch(com.sun.star.io.IOException e) {
144 public XInputStream getInStream() {
145 resetStreams();
146 try {
147 Object oInStream = msf.createInstance(
148 "com.sun.star.io.DataInputStream");
149 xInStream = UnoRuntime.queryInterface
150 (XInputStream.class, oInStream);
151 } catch(com.sun.star.uno.Exception e) {
152 return null;
155 XActiveDataSink xDataSink = UnoRuntime.queryInterface(
156 XActiveDataSink.class, xInStream);
157 xDataSink.setInputStream(xPipeInput);
159 return xInStream;
163 return tEnv;
164 } // finish method getTestEnvironment