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