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