bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _stm / DataOutputStream.java
blobd939efba379eeff5ab582c4b7c6f0b6fea980d90
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.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
29 import com.sun.star.io.XActiveDataSink;
30 import com.sun.star.io.XActiveDataSource;
31 import com.sun.star.io.XInputStream;
32 import com.sun.star.io.XOutputStream;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
37 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.io.DataOutputStream</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
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::XDataOutputStream</code></li>
45 * </ul>
46 * @see com.sun.star.io.DataOutputStream
47 * @see com.sun.star.io.XActiveDataSource
48 * @see com.sun.star.io.XOutputStream
49 * @see com.sun.star.io.XDataOutputStream
50 * @see ifc.io._XActiveDataSource
51 * @see ifc.io._XOutputStream
52 * @see ifc.io._XDataOutputStream
54 public class DataOutputStream extends TestCase {
56 /**
57 * Creating a Testenvironment for the interfaces to be tested.
58 * Creates an instance of the service
59 * <code>com.sun.star.io.DataOutputStream</code>
60 * and an instance of the service <code>com.sun.star.io.Pipe</code>.
61 * Plugs the created pipe as output stream for the created DataOutputStream.
62 * @see com.sun.star.io.DataOutputStream
63 * Object relations created :
64 * <ul>
65 * <li> <code>'StreamData'</code> for
66 * {@link ifc.io._XDataInputStream}(the data that should be written into
67 * the stream) </li>
68 * <li> <code>'ByteData'</code> for
69 * {@link ifc.io._XInputStream}(the data that should be written into
70 * the stream) </li>
71 * <li> <code>'OutputStream'</code> for
72 * {@link ifc.io._XActiveDataSource}
73 * (an input stream to set and get) </li>
74 * <li> <code>'XOutputStream.StreamChecker'</code> for
75 * {@link ifc.io._XOutputStream}( implementation of the interface
76 * ifc.io._XOutputStream.StreamChecker ) </li>
77 * </ul>
79 public TestEnvironment createTestEnvironment(
80 TestParameters Param, PrintWriter log) throws StatusException {
82 XInterface oObj = null;
83 Object oInterface = null;
84 XInterface oPipe = null;
85 XMultiServiceFactory xMSF = null ;
87 try {
88 xMSF = (XMultiServiceFactory)Param.getMSF();
89 oInterface = xMSF.createInstance
90 ("com.sun.star.io.DataOutputStream");
91 oPipe = (XInterface)xMSF.createInstance("com.sun.star.io.Pipe");
92 } catch(com.sun.star.uno.Exception e) {
93 e.printStackTrace(log);
94 throw new StatusException("Couldn't create instance", e);
97 oObj = (XInterface) oInterface;
99 final XOutputStream xPipeOutput = UnoRuntime.queryInterface(XOutputStream.class, oPipe);
101 XActiveDataSource xDataSource = UnoRuntime.queryInterface(XActiveDataSource.class, oObj);
103 xDataSource.setOutputStream(xPipeOutput);
105 // all data types for writing to an XDataInputStream
106 ArrayList<Object> data = new ArrayList<Object>() ;
107 data.add(new Boolean(true)) ;
108 data.add(new Byte((byte)123)) ;
109 data.add(new Character((char)1234)) ;
110 data.add(new Short((short)1234)) ;
111 data.add(new Integer(123456)) ;
112 data.add(new Float(1.234)) ;
113 data.add(new Double(1.23456)) ;
114 data.add("DataInputStream") ;
115 // information for writing to the pipe
116 byte[] byteData = new byte[] {
117 1, 2, 3, 4, 5, 6, 7, 8 } ;
119 log.println("creating a new environment for object");
120 TestEnvironment tEnv = new TestEnvironment( oObj );
122 tEnv.addObjRelation("StreamData", data);
123 tEnv.addObjRelation("ByteData", byteData);
124 tEnv.addObjRelation("OutputStream", oPipe);
126 //add relation for io.XOutputStream
127 final XMultiServiceFactory msf = xMSF;
128 final XInputStream xPipeInput = UnoRuntime.queryInterface(XInputStream.class, oPipe);
129 tEnv.addObjRelation("XOutputStream.StreamChecker",
130 new ifc.io._XOutputStream.StreamChecker() {
131 XInputStream xInStream = null;
132 public void resetStreams() {
133 if (xInStream != null) {
134 try {
135 xInStream.closeInput();
136 xInStream = null;
137 } catch(com.sun.star.io.IOException e) {
139 } else {
140 try {
141 xPipeOutput.closeOutput();
142 } catch(com.sun.star.io.IOException e) {
147 public XInputStream getInStream() {
148 resetStreams();
149 try {
150 Object oInStream = msf.createInstance(
151 "com.sun.star.io.DataInputStream");
152 xInStream = UnoRuntime.queryInterface
153 (XInputStream.class, oInStream);
154 } catch(com.sun.star.uno.Exception e) {
155 return null;
158 XActiveDataSink xDataSink = UnoRuntime.queryInterface(
159 XActiveDataSink.class, xInStream);
160 xDataSink.setInputStream(xPipeInput);
162 return xInStream;
166 return tEnv;
167 } // finish method getTestEnvironment