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