1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.drawing;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.drawing.XDrawPage;
33 import com.sun.star.drawing.XShape;
34 import com.sun.star.drawing.XShapeBinder;
35 import com.sun.star.drawing.XShapes;
36 import com.sun.star.uno.UnoRuntime;
37 
38 /**
39 * Testing <code>com.sun.star.drawing.XShapeBinder</code>
40 * interface methods :
41 * <ul>
42 *  <li><code> bind()</code></li>
43 *  <li><code> unbind()</code></li>
44 * </ul> <p>
45 * This test needs the following object relations :
46 * <ul>
47 *  <li> <code>'DrawPage'</code> (must implement <code>XShapes</code>):
48 *   the collection of shapes in a document which used to create a group.</li>
49 * <ul> <p>
50 * Test is <b> NOT </b> multithread compilant. <p>
51 * @see com.sun.star.drawing.XShapeBinder
52 */
53 public class _XShapeBinder extends MultiMethodTest {
54 
55     public XShapeBinder oObj = null;
56     XShape group = null;
57     int countBeforeBind = 0;
58     XShapes oShapes = null;
59 
60     /**
61     * Retrieves draw page collection from relation and binds them. <p>
62     *
63     * Has <b> OK </b> status if the shape group returned is not null
64     * number of shapes in collection is 1 (shapes are binded into a single
65     * shape). <p>
66     */
67     public void _bind () {
68         XDrawPage dp = (XDrawPage) tEnv.getObjRelation("DrawPage");
69         oShapes = (XShapes)UnoRuntime.queryInterface( XShapes.class, dp );
70         boolean result = false;
71         log.println("testing bind() ... ");
72         countBeforeBind = oShapes.getCount();
73         log.println("Count before bind:" + countBeforeBind);
74         group = oObj.bind(oShapes);
75         int countAfterBind = oShapes.getCount();
76         log.println("Count after bind:" + countAfterBind);
77         result = group != null &&  countAfterBind == 1;
78 
79         tRes.tested("bind()", result);
80 
81     }
82 
83     /**
84     * Unbinds the group created before. <p>
85     *
86     * Has <b> OK </b> status if number of shapes in collection
87     * increases after the method call. <p>
88     *
89     * The following method tests are to be completed successfully before :
90     * <ul>
91     *  <li> <code> bind() </code> : to create a shape group </li>
92     * </ul>
93     */
94     public void _unbind () {
95         requiredMethod("bind()");
96         boolean result = false;
97 
98         // get the current thread's holder
99         log.println("unbinding the shape...");
100 
101         oObj.unbind(group);
102         int countAfterUnbind = oShapes.getCount();
103         log.println("Count after unbind:" + countAfterUnbind);
104         result = countAfterUnbind >= countBeforeBind;
105 
106         tRes.tested("unbind()", result);
107     }
108 }
109 
110