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 import lib.Status;
32 import lib.StatusException;
33 
34 import com.sun.star.drawing.XShape;
35 import com.sun.star.drawing.XShapeGroup;
36 import com.sun.star.drawing.XShapeGrouper;
37 import com.sun.star.drawing.XShapes;
38 import com.sun.star.uno.UnoRuntime;
39 
40 /**
41 * Testing <code>com.sun.star.drawing.XShapeGrouper</code>
42 * interface methods :
43 * <ul>
44 *  <li><code> group()</code></li>
45 *  <li><code> ungroup()</code></li>
46 * </ul> <p>
47 * This test needs the following object relations :
48 * <ul>
49 *  <li> <code>'DrawPage'</code> (must implement <code>XShapes</code>):
50 *   the collection of shapes in a document which used to create a group.</li>
51 * <ul> <p>
52 * Test is <b> NOT </b> multithread compilant. <p>
53 * @see com.sun.star.drawing.XShapeGrouper
54 */
55 public class _XShapeGrouper extends MultiMethodTest {
56 
57     public XShapeGrouper oObj = null;                // oObj filled by MultiMethodTest
58     XShape oGroup = null;
59     int countAfterGr = 0;
60     XShapes oShapes = null;
61 
62     /**
63     * Retrieves draw page collection from relation and groups them. <p>
64     * Has <b> OK </b> status if the shape group returned is not null. <p>
65     */
66     public void _group() {
67         Object dp = tEnv.getObjRelation("DrawPage");
68         if (dp == null)
69             throw new StatusException(Status.failed("Relation not found")) ;
70 
71         oShapes = (XShapes)UnoRuntime.queryInterface( XShapes.class, dp );
72         boolean result = false;
73         log.println("Grouping " + oShapes.getCount() + " shapes ... ");
74 
75         int countBeforeGr = oShapes.getCount();
76         oGroup = oObj.group(oShapes);
77         countAfterGr = oShapes.getCount();
78         log.println("Number of shapes after grouping: " + countAfterGr);
79         result = oGroup != null ;
80         result &= countAfterGr < countBeforeGr;
81 
82         tRes.tested("group()", result);
83     }
84 
85     /**
86     * Ungroups the group created before. <p>
87     * Has <b> OK </b> status if the method successfully returns
88     * and no exceptions were thrown. <p>
89     * The following method tests are to be completed successfully before :
90     * <ul>
91     *  <li> <code> group() </code> : to create a shape group </li>
92     * </ul>
93     */
94     public void _ungroup() {
95         requiredMethod("group()");
96         boolean result = false;
97         log.println("ungrouping the shape...");
98 
99         oObj.ungroup((XShapeGroup)oGroup);
100         int countAfterUnGr = oShapes.getCount();
101         log.println("Number of shapes after ungrouping: " + countAfterUnGr);
102 
103         result = countAfterUnGr != countAfterGr;
104 
105         tRes.tested("ungroup()", result);
106     }
107 }
108 
109 
110 
111