merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _stm / MarkableInputStream.java
blobf01711fbf55fd0bf51fa6ecb379f34234d1635c6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MarkableInputStream.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._stm;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
40 import com.sun.star.io.XActiveDataSink;
41 import com.sun.star.io.XActiveDataSource;
42 import com.sun.star.io.XInputStream;
43 import com.sun.star.io.XOutputStream;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
48 /**
49 * Test for object which is represented by service
50 * <code>com.sun.star.io.MarkableInputStream</code>. <p>
51 * Object implements the following interfaces :
52 * <ul>
53 * <li> <code>com::sun::star::io::XInputStream</code></li>
54 * <li> <code>com::sun::star::io::XMarkableStream</code></li>
55 * <li> <code>com::sun::star::io::XConnectable</code></li>
56 * <li> <code>com::sun::star::io::XActiveDataSink</code></li>
57 * </ul>
58 * @see com.sun.star.io.MarkableInputStream
59 * @see com.sun.star.io.XInputStream
60 * @see com.sun.star.io.XMarkableStream
61 * @see com.sun.star.io.XConnectable
62 * @see com.sun.star.io.XActiveDataSink
63 * @see ifc.io._XInputStream
64 * @see ifc.io._XMarkableStream
65 * @see ifc.io._XConnectable
66 * @see ifc.io._XActiveDataSink
68 public class MarkableInputStream extends TestCase {
70 /**
71 * Creating a Testenvironment for the interfaces to be tested.
72 * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
73 * <code>com.sun.star.io.MarkableInputStream</code> and
74 * <code>com.sun.star.io.MarkableOutputStream</code>.
75 * Plugs the created pipe as output stream for the created
76 * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
77 * for the created <code>MarkableInputStream</code>. Writes some data to the
78 * <code>MarkableOutputStream</code>.
79 * Object relations created :
80 * <ul>
81 * <li> <code>'StreamWriter'</code> for
82 * {@link ifc.io._XInputStream}(a stream to write data to) </li>
83 * <li> <code>'ByteData'</code> for
84 * {@link ifc.io._XInputStream}(the data that should be written into
85 * the stream) </li>
86 * <li> <code>'Connectable'</code> for
87 * {@link ifc.io._XConnectable}(another object that can be connected) </li>
88 * <li> <code>'InputStream'</code> for
89 * {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
90 * </ul>
91 * @see com.sun.star.io.Pipe
92 * @see com.sun.star.io.MarkableInputStream
93 * @see com.sun.star.io.MarkableOutputStream
95 public TestEnvironment createTestEnvironment(
96 TestParameters Param, PrintWriter log) throws StatusException {
98 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();;
100 Object aPipe = null;
101 Object mostream = null;
102 Object mistream = null;
103 Object xConnect = null;
104 try {
105 aPipe = xMSF.createInstance("com.sun.star.io.Pipe");
106 mistream = xMSF.createInstance("com.sun.star.io.MarkableInputStream");
107 mostream = xMSF.createInstance("com.sun.star.io.MarkableOutputStream");
108 xConnect = xMSF.createInstance("com.sun.star.io.DataInputStream");
109 } catch(com.sun.star.uno.Exception e) {
110 e.printStackTrace(log);
111 throw new StatusException("Couldn't create instance", e) ;
114 // Creating construction :
115 // MarkableOutputStream -> Pipe -> MarkableInputStream
116 XActiveDataSource xdSmo = (XActiveDataSource)
117 UnoRuntime.queryInterface(XActiveDataSource.class, mostream);
119 XOutputStream PipeOut = (XOutputStream)
120 UnoRuntime.queryInterface(XOutputStream.class, aPipe);
121 XInputStream PipeIn = (XInputStream)
122 UnoRuntime.queryInterface(XInputStream.class, aPipe);
124 xdSmo.setOutputStream(PipeOut);
126 XActiveDataSink xmSi = (XActiveDataSink)
127 UnoRuntime.queryInterface(XActiveDataSink.class, mistream);
129 xmSi.setInputStream(PipeIn) ;
131 XInterface oObj = (XInterface) mistream;
133 byte[] byteData = new byte[] {1,2,3,4,5,6};
135 log.println( "creating a new environment for object" );
136 TestEnvironment tEnv = new TestEnvironment( oObj );
138 // add a writer
139 tEnv.addObjRelation("StreamWriter", mostream);
140 // add a connectable
141 tEnv.addObjRelation("Connectable", xConnect);
142 // add an inputStream
143 tEnv.addObjRelation("InputStream", mistream);
144 tEnv.addObjRelation("ByteData", byteData);
146 return tEnv;
147 } // finish method getTestEnvironment