1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._stm;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 
33 import com.sun.star.io.XActiveDataSink;
34 import com.sun.star.io.XActiveDataSource;
35 import com.sun.star.io.XInputStream;
36 import com.sun.star.io.XOutputStream;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.io.MarkableInputStream</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 *  <li> <code>com::sun::star::io::XInputStream</code></li>
47 *  <li> <code>com::sun::star::io::XMarkableStream</code></li>
48 *  <li> <code>com::sun::star::io::XConnectable</code></li>
49 *  <li> <code>com::sun::star::io::XActiveDataSink</code></li>
50 * </ul>
51 * @see com.sun.star.io.MarkableInputStream
52 * @see com.sun.star.io.XInputStream
53 * @see com.sun.star.io.XMarkableStream
54 * @see com.sun.star.io.XConnectable
55 * @see com.sun.star.io.XActiveDataSink
56 * @see ifc.io._XInputStream
57 * @see ifc.io._XMarkableStream
58 * @see ifc.io._XConnectable
59 * @see ifc.io._XActiveDataSink
60 */
61 public class MarkableInputStream extends TestCase {
62 
63     /**
64     * Creating a Testenvironment for the interfaces to be tested.
65     * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
66     * <code>com.sun.star.io.MarkableInputStream</code> and
67     * <code>com.sun.star.io.MarkableOutputStream</code>.
68     * Plugs the created pipe as output stream for the created
69     * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
70     * for the created <code>MarkableInputStream</code>. Writes some data to the
71     * <code>MarkableOutputStream</code>.
72     * Object relations created :
73     * <ul>
74     *  <li> <code>'StreamWriter'</code> for
75     *      {@link ifc.io._XInputStream}(a stream to write data to) </li>
76     *  <li> <code>'ByteData'</code> for
77     *      {@link ifc.io._XInputStream}(the data that should be written into
78     *      the stream) </li>
79     *  <li> <code>'Connectable'</code> for
80     *      {@link ifc.io._XConnectable}(another object that can be connected) </li>
81     *  <li> <code>'InputStream'</code> for
82     *      {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
83     * </ul>
84     * @see com.sun.star.io.Pipe
85     * @see com.sun.star.io.MarkableInputStream
86     * @see com.sun.star.io.MarkableOutputStream
87     */
createTestEnvironment( TestParameters Param, PrintWriter log)88     public TestEnvironment createTestEnvironment(
89         TestParameters Param, PrintWriter log) throws StatusException {
90 
91         XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
92 
93         Object aPipe = null;
94         Object mostream = null;
95         Object mistream = null;
96         Object xConnect = null;
97         try {
98             aPipe = xMSF.createInstance("com.sun.star.io.Pipe");
99             mistream = xMSF.createInstance("com.sun.star.io.MarkableInputStream");
100             mostream = xMSF.createInstance("com.sun.star.io.MarkableOutputStream");
101             xConnect = xMSF.createInstance("com.sun.star.io.DataInputStream");
102         } catch(com.sun.star.uno.Exception e) {
103             e.printStackTrace(log);
104             throw new StatusException("Couldn't create instance", e) ;
105         }
106 
107         // Creating construction :
108         // MarkableOutputStream -> Pipe -> MarkableInputStream
109         XActiveDataSource xdSmo = (XActiveDataSource)
110             UnoRuntime.queryInterface(XActiveDataSource.class, mostream);
111 
112         XOutputStream PipeOut = (XOutputStream)
113             UnoRuntime.queryInterface(XOutputStream.class, aPipe);
114         XInputStream PipeIn = (XInputStream)
115             UnoRuntime.queryInterface(XInputStream.class, aPipe);
116 
117         xdSmo.setOutputStream(PipeOut);
118 
119         XActiveDataSink xmSi = (XActiveDataSink)
120             UnoRuntime.queryInterface(XActiveDataSink.class, mistream);
121 
122         xmSi.setInputStream(PipeIn) ;
123 
124         XInterface oObj = (XInterface) mistream;
125 
126         byte[] byteData = new byte[] {1,2,3,4,5,6};
127 
128         log.println( "creating a new environment for object" );
129         TestEnvironment tEnv = new TestEnvironment( oObj );
130 
131         // add a writer
132         tEnv.addObjRelation("StreamWriter", mostream);
133         // add a connectable
134         tEnv.addObjRelation("Connectable", xConnect);
135         // add an inputStream
136         tEnv.addObjRelation("InputStream", mistream);
137         tEnv.addObjRelation("ByteData", byteData);
138 
139         return tEnv;
140     } // finish method getTestEnvironment
141 
142 }
143 
144