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 ifc.drawing;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.drawing.XDrawPage;
29 import com.sun.star.drawing.XShape;
30 import com.sun.star.drawing.XShapeBinder;
31 import com.sun.star.drawing.XShapes;
32 import com.sun.star.uno.UnoRuntime;
33 
34 /**
35 * Testing <code>com.sun.star.drawing.XShapeBinder</code>
36 * interface methods :
37 * <ul>
38 *  <li><code> bind()</code></li>
39 *  <li><code> unbind()</code></li>
40 * </ul> <p>
41 * This test needs the following object relations :
42 * <ul>
43 *  <li> <code>'DrawPage'</code> (must implement <code>XShapes</code>):
44 *   the collection of shapes in a document which used to create a group.</li>
45 * <ul> <p>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * @see com.sun.star.drawing.XShapeBinder
48 */
49 public class _XShapeBinder extends MultiMethodTest {
50 
51     public XShapeBinder oObj = null;
52     XShape group = null;
53     int countBeforeBind = 0;
54     XShapes oShapes = null;
55 
56     /**
57     * Retrieves draw page collection from relation and binds them. <p>
58     *
59     * Has <b> OK </b> status if the shape group returned is not null
60     * number of shapes in collection is 1 (shapes are binded into a single
61     * shape). <p>
62     */
_bind()63     public void _bind () {
64         XDrawPage dp = (XDrawPage) tEnv.getObjRelation("DrawPage");
65         oShapes = (XShapes)UnoRuntime.queryInterface( XShapes.class, dp );
66         boolean result = false;
67         log.println("testing bind() ... ");
68         countBeforeBind = oShapes.getCount();
69         log.println("Count before bind:" + countBeforeBind);
70         group = oObj.bind(oShapes);
71         int countAfterBind = oShapes.getCount();
72         log.println("Count after bind:" + countAfterBind);
73         result = group != null &&  countAfterBind == 1;
74 
75         tRes.tested("bind()", result);
76 
77     }
78 
79     /**
80     * Unbinds the group created before. <p>
81     *
82     * Has <b> OK </b> status if number of shapes in collection
83     * increases after the method call. <p>
84     *
85     * The following method tests are to be completed successfully before :
86     * <ul>
87     *  <li> <code> bind() </code> : to create a shape group </li>
88     * </ul>
89     */
_unbind()90     public void _unbind () {
91         requiredMethod("bind()");
92         boolean result = false;
93 
94         // get the current thread's holder
95         log.println("unbinding the shape...");
96 
97         oObj.unbind(group);
98         int countAfterUnbind = oShapes.getCount();
99         log.println("Count after unbind:" + countAfterUnbind);
100         result = countAfterUnbind >= countBeforeBind;
101 
102         tRes.tested("unbind()", result);
103     }
104 }
105 
106