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.text;
25 
26 import lib.MultiMethodTest;
27 import lib.Status;
28 import lib.StatusException;
29 
30 import com.sun.star.text.XTextTable;
31 
32 /**
33  * Testing <code>com.sun.star.text.XTextTable</code>
34  * interface methods :
35  * <ul>
36  *  <li><code> initialize()</code></li>
37  *  <li><code> getRows()</code></li>
38  *  <li><code> getColumns()</code></li>
39  *  <li><code> getCellByName()</code></li>
40  *  <li><code> getCellNames()</code></li>
41  *  <li><code> createCursorByCellName()</code></li>
42  * </ul> <p>
43  * This test needs the following object relations :
44  * <ul>
45  *  <li> <code>'NROW'</code> : the number of rows in table
46  *  </li>
47  *  <li> <code>'NCOL'</code> : the number of columns in table
48  *  </li>
49  *
50  * Test is <b> NOT </b> multithread compilant. <p>
51  * @see com.sun.star.text.XTextTable
52  */
53 public class _XTextTable extends MultiMethodTest {
54 
55     public XTextTable oObj = null;        // oObj filled by MultiMethodTest
56     int nRow;
57     int nCol;
58 
59     String cellNamesList[] = null ;
60 
before()61     protected void before() {
62         Integer num_row = (Integer)tEnv.getObjRelation("NROW");
63         if (num_row == null) {
64             throw new StatusException
65                 (Status.failed("Couldn't get relation 'NROW'"));
66         }
67         Integer num_col = (Integer)tEnv.getObjRelation("NCOL");
68         if (num_col == null) {
69             throw new StatusException
70                 (Status.failed("Couldn't get relation 'NCOL'"));
71         }
72         nRow = num_row.intValue();
73         nCol = num_col.intValue();
74     }
75 
76     /**
77      * The method is not called directly here, because it must
78      * be called before being inserted to the document. <p>
79      *
80      * Always has <b> OK </b> status. <p>
81      */
_initialize()82     public void _initialize() {
83 
84         // initialize()
85         log.println( "test for initialize()" );
86         tRes.tested( "initialize()", true);
87     }
88 
89     /**
90      * Test calls the method passing as cell name the first
91      * element from names returned by <code>getCellNames</code>
92      * method. <p>
93      *
94      * Has <b> OK </b> status if the method returns not
95      * <code>null</code> value.
96      *
97      * The following method tests are to be completed successfully before :
98      * <ul>
99      *  <li> <code> getCellNames() </code> : its result used by test. </li>
100      * </ul>
101      */
_createCursorByCellName()102     public void _createCursorByCellName(){
103         requiredMethod("getCellNames()") ;
104 
105         // createCursorByCellName()
106         log.println( "test for createCursorByCellName()" );
107         tRes.tested( "createCursorByCellName()",
108                     oObj.createCursorByCellName( cellNamesList[0] ) != null );
109     }
110 
111     /**
112      * Test calls the method passing as cell name the first
113      * element from names returned by <code>getCellNames</code>
114      * method. <p>
115      *
116      * Has <b> OK </b> status if the method returns not
117      * <code>null</code> value.
118      *
119      * The following method tests are to be completed successfully before :
120      * <ul>
121      *  <li> <code> getCellNames() </code> : its result used by test. </li>
122      * </ul>
123      */
_getCellByName()124     public void _getCellByName(){
125         requiredMethod("getCellNames()") ;
126 
127         // getCellByName()
128         log.println( "test for getCellByName()" );
129         tRes.tested( "getCellByName()",
130             oObj.getCellByName( cellNamesList[0] ) != null );
131     }
132 
133     /**
134      * Obtains cell names of the table. <p>
135      *
136      * Has <b>OK</b> status if number of elements in the returned
137      * array is equal to [row number] * [column number]
138      * and if the first name is 'A1'.
139      */
_getCellNames()140     public void _getCellNames(){
141         // getCellNames()
142         log.println( "test for getCellNames()" );
143         cellNamesList = oObj.getCellNames();
144 
145         boolean result = cellNamesList.length == ( nRow * nCol ) ;
146         result &= cellNamesList[0].equals( "A1" ) ;
147 
148         tRes.tested( "getCellNames()", result ) ;
149     }
150 
151     /**
152      * Obtains columns of the table. <p>
153      *
154      * Has <b>OK</b> status if the number of element of returned
155      * collection is equal to real number of columns in the table.
156      */
_getColumns()157     public void _getColumns(){
158         // getColumns()
159         log.println( "test for getColumns()" );
160         tRes.tested( "getColumns()", nCol == oObj.getColumns().getCount() );
161     }
162 
163     /**
164      * Obtains rows of the table. <p>
165      *
166      * Has <b>OK</b> status if the number of element of returned
167      * collection is equal to real number of rows in the table.
168      */
_getRows()169     public void _getRows(){
170         // getRows()
171         log.println( "test for getRows()" );
172         tRes.tested( "getRows()", nRow == oObj.getRows().getCount() );
173     }
174 
175 }
176 
177 
178