1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 
19 package ifc.drawing;
20 
21 import lib.MultiMethodTest;
22 import util.XInstCreator;
23 
24 import com.sun.star.drawing.XShape;
25 import com.sun.star.drawing.XShapes;
26 import com.sun.star.uno.XInterface;
27 
28 
29 /**
30 * Testing <code>com.sun.star.drawing.XShapes</code>
31 * interface methods :
32 * <ul>
33 *  <li><code> add()</code></li>
34 *  <li><code> remove()</code></li>
35 * </ul> <p>
36 * This test needs the following object relations :
37 * <ul>
38 *  <li> <code>'Shape'</code> (of type <code>XShape</code>):
39 *   a shape which can be inserted into shape collection. </li>
40 * <ul> <p>
41 * Test is <b> NOT </b> multithread compliant. <p>
42 * @see com.sun.star.drawing.XShapes
43 */
44 public class _XShapes extends MultiMethodTest {
45 
46     public XShapes oObj = null;                // oObj filled by MultiMethodTest
47     XInstCreator shape = null;
48     XInterface oShape = null;
49 
50 
51     /**
52     * Retrieves a shape from relation and adds it to the collection.
53     * Number of shapes is checked before and after adding.<p>
54     * Has <b> OK </b> status if after adding number of shapes increases by
55     * 1. <p>
56     */
_add()57     public void _add () {
58 
59         boolean result = false;
60         shape = (XInstCreator)tEnv.getObjRelation("Shape");
61         oShape = shape.createInstance();
62         XShape oSh = (XShape) oShape;
63 
64         log.println("testing add() ... ");
65 
66         int cntBefore = oObj.getCount();
67         oObj.add(oSh);
68         int cntAfter = oObj.getCount();
69         result = cntBefore + 1 == cntAfter ;
70 
71         tRes.tested("add()", result);
72     }
73 
74     /**
75     * Removes the shape added before from the collection.
76     * Number of shapes is checked before and after removing.<p>
77     * Has <b> OK </b> status if after removing number of shapes decreases by
78     * 1. <p>
79     * The following method tests are to be completed successfully before :
80     * <ul>
81     *  <li> <code> add() </code> : a shape added. </li>
82     * </ul>
83     */
_remove()84     public void _remove () {
85         requiredMethod("add()");
86         boolean result = false;
87 
88         log.println("removing the shape...");
89 
90         int cntBefore = oObj.getCount();
91         oObj.remove((XShape) oShape);
92         int cntAfter = oObj.getCount();
93         result = cntBefore == cntAfter + 1;
94 
95         tRes.tested("remove()", result);
96     }
97 
98 }
99 
100 
101