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.chart;
25 
26 import lib.MultiMethodTest;
27 import lib.Status;
28 import lib.StatusException;
29 
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.chart.XDiagram;
32 
33 /**
34 * Testing <code>com.sun.star.chart.XDiagram</code>
35 * interface methods :
36 * <ul>
37 *  <li><code> getDiagramType()</code></li>
38 *  <li><code> getDataRowProperties()</code></li>
39 *  <li><code> getDataPointProperties()</code></li>
40 * </ul> <p>
41 * This test needs the following object relations :
42 * <ul>
43 *  <li> <code>'ROWAMOUNT'</code> (of type <code>Integer</code>):
44 *   to have amount of rows </li>
45 *  <li> <code>'COLAMOUNT'</code> (of type <code>Integer</code>):
46 *   to have amount of columns </li>
47 * <ul> <p>
48 * @see com.sun.star.chart.XDiagram
49 */
50 public class _XDiagram extends MultiMethodTest {
51 
52     public XDiagram      oObj = null;
53     boolean         result = true;
54     Integer      rowamount = null;
55     Integer      colamount = null;
56 
57     /**
58     * Retrieves object relations.
59     * @throws StatusException If one of relations not found.
60     */
before()61     public void before() {
62         rowamount = (Integer)tEnv.getObjRelation("ROWAMOUNT");
63         if (rowamount == null) throw new StatusException(Status.failed
64             ("Relation 'ROWAMOUNT' not found"));
65 
66         colamount = (Integer)tEnv.getObjRelation("COLAMOUNT");
67         if (colamount == null) throw new StatusException(Status.failed
68             ("Relation 'COLAMOUNT' not found"));
69     }
70 
71     /**
72     * Test calls the method and checks returned value. <p>
73     * Has <b> OK </b> status if returned value start from 'com.sun.star.chart.' <p>
74     */
_getDiagramType()75     public void _getDiagramType() {
76         result = true;
77 
78         String stype = oObj.getDiagramType();
79         log.println("Current Diagram Type is " + stype);
80         result = (stype.startsWith("com.sun.star.chart."));
81 
82         tRes.tested("getDiagramType()", result);
83     }
84 
85     /**
86     * Test calls the method for every row and checks returned value. <p>
87     * Has <b> OK </b> status if returned value for every row isn't null and
88     * no exceptions were thrown. <p>
89     */
_getDataRowProperties()90     public void _getDataRowProperties() {
91         result = true;
92 
93         int rows = rowamount.intValue();
94         rows -= 1;
95         XPropertySet props = null;
96 
97         log.println("There are " + rows + " rows.");
98         try {
99             for (int i = 0; i < rows; i++) {
100                 props = oObj.getDataRowProperties(i);
101                 if (props != null) {
102                     log.println("Row " + i + " - OK");
103                 } else {
104                     log.println("Row " + i + " - FAILED");
105                     result = false;
106                 }
107             }
108         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
109             log.println("Exception while get data row properties");
110             e.printStackTrace(log);
111             result = false;
112         }
113 
114         tRes.tested("getDataRowProperties()", result);
115     }
116 
117     /**
118     * Test calls the method for every point and checks returned value. <p>
119     * Has <b> OK </b> status if returned value for every point isn't null and
120     * no exceptions were thrown. <p>
121     */
_getDataPointProperties()122     public void _getDataPointProperties() {
123         result = true;
124 
125         int rows = rowamount.intValue();
126         int cols = colamount.intValue();
127         XPropertySet props = null;
128 
129         log.println("There are " + rows + " rows and " + cols + " cols.");
130 
131         try {
132             for (int i = 0; i < rows; i++)
133                 for (int j = 0; j < cols; j++) {
134                     props = oObj.getDataPointProperties(i, j);
135                     if (props != null) {
136                         log.println("Row " + i + " Col " + j + " - OK");
137                     } else {
138                         log.println("Row " + i + " Col " + j + " - FAILED");
139                         result = false;
140                     }
141                 }
142         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
143             log.println("Exception while get data point properties");
144             e.printStackTrace(log);
145             result = false;
146         }
147 
148         tRes.tested("getDataPointProperties()", result);
149     }
150 }
151 
152 
153