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._cnt;
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.container.XIndexContainer;
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.cnt.CntUnoDataContainer</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 *  <li> <code>com::sun::star::io::XActiveDataSink</code></li>
44 *  <li> <code>com::sun::star::container::XIndexContainer</code></li>
45 *  <li> <code>com::sun::star::ucb::XDataContainer</code></li>
46 *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
47 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
48 *  <li> <code>com::sun::star::container::XIndexReplace</code></li>
49 * </ul>
50 * This object test <b> is NOT </b> designed to be run in several
51 * threads concurently.
52 * @see com.sun.star.io.XActiveDataSink
53 * @see com.sun.star.container.XIndexContainer
54 * @see com.sun.star.ucb.XDataContainer
55 * @see com.sun.star.container.XIndexAccess
56 * @see com.sun.star.container.XElementAccess
57 * @see com.sun.star.container.XIndexReplace
58 * @see ifc.io._XActiveDataSink
59 * @see ifc.container._XIndexContainer
60 * @see ifc.ucb._XDataContainer
61 * @see ifc.container._XIndexAccess
62 * @see ifc.container._XElementAccess
63 * @see ifc.container._XIndexReplace
64 */
65 public class CntUnoDataContainer extends TestCase {
66 
67     /**
68     * Creating a Testenvironment for the interfaces to be tested.
69     * Creates an instance of the service
70     * <code>com.sun.star.cnt.CntUnoDataContainer</code> and adds
71     * to it one <code>CntUnoDataContainer</code> instance. <p>
72     *     Object relations created :
73     * <ul>
74     *  <li> <code>'INSTANCE1'</code> for
75     *      {@link ifc.container._XIndexContainer},
76     *      {@link ifc.container._XIndexReplace} : for this object
77     *      elements contained in it are <code>CntUnoDataContainer</code>
78     *      instances. (only one relation for one interface thread is now
79     *      passed).</li>
80     *  <li> <code>'InputStream'</code> for
81     *      {@link ifc.io._XActiveDataSink} : a stream to set and get.
82     *       </li>
83     * </ul>
84     */
createTestEnvironment( TestParameters Param, PrintWriter log)85     protected TestEnvironment createTestEnvironment(
86                                     TestParameters Param, PrintWriter log) {
87         XInterface oObj = null;
88         Object oInterface = null;
89         XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
90         Object relationContainer = null ;
91         Object xIn = null;
92 
93         try {
94             oInterface = xMSF.createInstance
95                 ( "com.sun.star.ucb.DataContainer" );
96 
97             // adding one child container
98             XIndexContainer xIC = (XIndexContainer) UnoRuntime.queryInterface
99                 (XIndexContainer.class, oInterface) ;
100 
101             Object child = xMSF.createInstance
102                 ( "com.sun.star.ucb.DataContainer" );
103             xIC.insertByIndex(0, child) ;
104 
105             relationContainer = xMSF.createInstance
106                 ( "com.sun.star.ucb.DataContainer" );
107 
108             xIn = xMSF.createInstance
109                 ( "com.sun.star.io.DataInputStream" );
110         }
111         catch( com.sun.star.uno.Exception e ) {
112             log.println("Can't create an object." );
113             throw new StatusException( "Can't create an object", e );
114         }
115 
116         oObj = (XInterface) oInterface;
117 
118         TestEnvironment tEnv = new TestEnvironment( oObj );
119 
120         tEnv.addObjRelation("INSTANCE1", relationContainer) ;
121         tEnv.addObjRelation("InputStream", xIn) ;
122 
123         return tEnv;
124     } // finish method getTestEnvironment
125 
126 }    // finish class BreakIterator
127 
128