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