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._streams.uno;
25 
26 import com.sun.star.io.XActiveDataSink;
27 import com.sun.star.io.XActiveDataSource;
28 import com.sun.star.io.XInputStream;
29 import com.sun.star.io.XOutputStream;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
33 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 
39 /**
40 * Test for object which is represented by service
41 * <code>com.sun.star.io.MarkableInputStream</code>. <p>
42 * Object implements the following interfaces :
43 * <ul>
44 *  <li> <code>com::sun::star::io::XInputStream</code></li>
45 *  <li> <code>com::sun::star::io::XMarkableStream</code></li>
46 *  <li> <code>com::sun::star::io::XConnectable</code></li>
47 *  <li> <code>com::sun::star::io::XActiveDataSink</code></li>
48 * </ul>
49 * @see com.sun.star.io.MarkableInputStream
50 * @see com.sun.star.io.XInputStream
51 * @see com.sun.star.io.XMarkableStream
52 * @see com.sun.star.io.XConnectable
53 * @see com.sun.star.io.XActiveDataSink
54 * @see ifc.io._XInputStream
55 * @see ifc.io._XMarkableStream
56 * @see ifc.io._XConnectable
57 * @see ifc.io._XActiveDataSink
58 */
59 public class MarkableInputStream extends TestCase {
60 
61     /**
62     * Creating a Testenvironment for the interfaces to be tested.
63     * Creates an instances of services <code>com.sun.star.io.Pipe</code>,
64     * <code>com.sun.star.io.MarkableInputStream</code> and
65     * <code>com.sun.star.io.MarkableOutputStream</code>.
66     * Plugs the created pipe as output stream for the created
67     * <code>MarkableOutputStream</code>. Plugs the created pipe as input stream
68     * for the created <code>MarkableInputStream</code>. Writes some data to the
69     * <code>MarkableOutputStream</code>.
70     * Object relations created :
71     * <ul>
72     *  <li> <code>'StreamWriter'</code> for
73     *      {@link ifc.io._XInputStream}(a stream to write data to) </li>
74     *  <li> <code>'ByteData'</code> for
75     *      {@link ifc.io._XInputStream}(the data that should be written into
76     *      the stream) </li>
77     *  <li> <code>'Connectable'</code> for
78     *      {@link ifc.io._XConnectable}(another object that can be connected) </li>
79     *  <li> <code>'InputStream'</code> for
80     *      {@link ifc.io._XActiveDataSink}(an input stream to set and get) </li>
81     * </ul>
82     * @see com.sun.star.io.Pipe
83     * @see com.sun.star.io.MarkableInputStream
84     * @see com.sun.star.io.MarkableOutputStream
85     */
createTestEnvironment(TestParameters Param, PrintWriter log)86     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
87 
88         XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
89 
90         Object aPipe = null;
91         Object mostream = null;
92         Object mistream = null;
93         Object xConnect = null;
94         try {
95             aPipe = xMSF.createInstance("com.sun.star.io.Pipe");
96             mistream = xMSF.createInstance("com.sun.star.io.MarkableInputStream");
97             mostream = xMSF.createInstance("com.sun.star.io.MarkableOutputStream");
98             xConnect = xMSF.createInstance("com.sun.star.io.DataInputStream");
99         } catch(com.sun.star.uno.Exception e) {
100             e.printStackTrace(log);
101             throw new StatusException("Couldn't create instance", e) ;
102         }
103 
104         // Creating construction :
105         // MarkableOutputStream -> Pipe -> MarkableInputStream
106         XActiveDataSource xdSmo = (XActiveDataSource)
107             UnoRuntime.queryInterface(XActiveDataSource.class, mostream);
108 
109         XOutputStream PipeOut = (XOutputStream)
110             UnoRuntime.queryInterface(XOutputStream.class, aPipe);
111         XInputStream PipeIn = (XInputStream)
112             UnoRuntime.queryInterface(XInputStream.class, aPipe);
113 
114         xdSmo.setOutputStream(PipeOut);
115 
116         XActiveDataSink xmSi = (XActiveDataSink)
117             UnoRuntime.queryInterface(XActiveDataSink.class, mistream);
118 
119         xmSi.setInputStream(PipeIn) ;
120 
121         XInterface oObj = (XInterface) mistream;
122 
123         byte[] byteData = new byte[] {1,2,3,4,5,6};
124 
125         log.println( "creating a new environment for object" );
126         TestEnvironment tEnv = new TestEnvironment( oObj );
127 
128         // add a writer
129         tEnv.addObjRelation("StreamWriter", mostream);
130         // add a connectable
131         tEnv.addObjRelation("Connectable", xConnect);
132         // add an inputStream
133         tEnv.addObjRelation("InputStream", mistream);
134         tEnv.addObjRelation("ByteData", byteData);
135 
136         return tEnv;
137     } // finish method getTestEnvironment
138 
139 }
140 
141