xref: /aoo42x/main/qadevOOo/tests/java/mod/_stm/Pipe.java (revision ef39d40d)
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.XInputStream;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
37 
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.io.Pipe</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 *  <li> <code>com::sun::star::io::XInputStream</code></li>
44 *  <li> <code>com::sun::star::io::XOutputStream</code></li>
45 * </ul>
46 * @see com.sun.star.io.Pipe
47 * @see com.sun.star.io.XInputStream
48 * @see com.sun.star.io.XOutputStream
49 * @see ifc.io._XInputStream
50 * @see ifc.io._XOutputStream
51 */
52 public class Pipe extends TestCase {
53 
54     /**
55     * Creating a Testenvironment for the interfaces to be tested.
56     * Creates an instance of the service <code>com.sun.star.io.Pipe</code>.
57     * Writes some information to the created pipe.
58     * Object relations created :
59     * <ul>
60     *  <li> <code>'XOutputStream.StreamChecker'</code> for
61     *      {@link ifc.io._XOutputStream}( implementation of the interface
62     *      ifc.io._XOutputStream.StreamChecker ) </li>
63     * </ul>
64     * @see com.sun.star.io.Pipe
65     */
createTestEnvironment( TestParameters Param, PrintWriter log)66     public TestEnvironment createTestEnvironment(
67         TestParameters Param, PrintWriter log) throws StatusException {
68 
69         XInterface oObj = null;
70         Object oInterface = null;
71 
72         try {
73             XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
74             oInterface = xMSF.createInstance( "com.sun.star.io.Pipe" );
75         } catch(com.sun.star.uno.Exception e) {
76             e.printStackTrace(log);
77             throw new StatusException("Couldn't create instance", e);
78         }
79 
80         oObj = (XInterface) oInterface;
81 
82         // writing some information to the pipe
83         byte[] byteData = new byte[] {
84             1, 2, 3, 4, 5, 6, 7, 8 } ;
85 
86         log.println( "creating a new environment for object" );
87         TestEnvironment tEnv = new TestEnvironment( oObj );
88 
89         //add relation for io.XOutputStream
90         final XInputStream iStream = (XInputStream)
91                 UnoRuntime.queryInterface(XInputStream.class, oObj);
92 
93         tEnv.addObjRelation("ByteData", byteData);
94         tEnv.addObjRelation("StreamWriter", oObj);
95 
96         tEnv.addObjRelation("XOutputStream.StreamChecker",
97             new ifc.io._XOutputStream.StreamChecker() {
98                 XInputStream inStream = null;
99                 public void resetStreams() {
100                 }
101 
102                 public XInputStream getInStream() {
103                     return iStream;
104                 }
105             });
106 
107         return tEnv;
108     } // finish method getTestEnvironment
109 
110 }
111 
112