Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / drawing / _XShapeGrouper.java
blob26b5045d1a5155f34b46ebd306455ab8b6da1944
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.drawing;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.drawing.XShape;
26 import com.sun.star.drawing.XShapeGroup;
27 import com.sun.star.drawing.XShapeGrouper;
28 import com.sun.star.drawing.XShapes;
29 import com.sun.star.uno.UnoRuntime;
31 /**
32 * Testing <code>com.sun.star.drawing.XShapeGrouper</code>
33 * interface methods :
34 * <ul>
35 * <li><code> group()</code></li>
36 * <li><code> ungroup()</code></li>
37 * </ul> <p>
38 * This test needs the following object relations :
39 * <ul>
40 * <li> <code>'DrawPage'</code> (must implement <code>XShapes</code>):
41 * the collection of shapes in a document which used to create a group.</li>
42 * <ul> <p>
43 * Test is <b> NOT </b> multithread compliant. <p>
44 * @see com.sun.star.drawing.XShapeGrouper
46 public class _XShapeGrouper extends MultiMethodTest {
48 public XShapeGrouper oObj = null; // oObj filled by MultiMethodTest
49 XShape oGroup = null;
50 int countAfterGr = 0;
51 XShapes oShapes = null;
53 /**
54 * Retrieves draw page collection from relation and groups them. <p>
55 * Has <b> OK </b> status if the shape group returned is not null. <p>
57 public void _group() {
58 Object dp = tEnv.getObjRelation("DrawPage");
59 if (dp == null)
60 throw new StatusException(Status.failed("Relation not found")) ;
62 oShapes = UnoRuntime.queryInterface( XShapes.class, dp );
63 boolean result = false;
64 log.println("Grouping " + oShapes.getCount() + " shapes ... ");
66 int countBeforeGr = oShapes.getCount();
67 oGroup = oObj.group(oShapes);
68 countAfterGr = oShapes.getCount();
69 log.println("Number of shapes after grouping: " + countAfterGr);
70 result = oGroup != null ;
71 result &= countAfterGr < countBeforeGr;
73 tRes.tested("group()", result);
76 /**
77 * Ungroups the group created before. <p>
78 * Has <b> OK </b> status if the method successfully returns
79 * and no exceptions were thrown. <p>
80 * The following method tests are to be completed successfully before :
81 * <ul>
82 * <li> <code> group() </code> : to create a shape group </li>
83 * </ul>
85 public void _ungroup() {
86 requiredMethod("group()");
87 boolean result = false;
88 log.println("ungrouping the shape...");
90 oObj.ungroup((XShapeGroup)oGroup);
91 int countAfterUnGr = oShapes.getCount();
92 log.println("Number of shapes after ungrouping: " + countAfterUnGr);
94 result = countAfterUnGr != countAfterGr;
96 tRes.tested("ungroup()", result);