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.sheet;
25 
26 import lib.MultiMethodTest;
27 import lib.Status;
28 import lib.StatusException;
29 import util.ValueComparer;
30 
31 import com.sun.star.sheet.XSheetAnnotation;
32 import com.sun.star.table.CellAddress;
33 import com.sun.star.text.XSimpleText;
34 import com.sun.star.uno.UnoRuntime;
35 
36 /**
37 * Testing <code>com.sun.star.sheet.XSheetAnnotation</code>
38 * interface methods :
39 * <ul>
40 *  <li><code> getPosition()</code></li>
41 *  <li><code> getAuthor()</code></li>
42 *  <li><code> getDate()</code></li>
43 *  <li><code> getIsVisible()</code></li>
44 *  <li><code> setIsVisible()</code></li>
45 * </ul> <p>
46 * This test needs the following object relations :
47 * <ul>
48 *  <li> <code>'CELLPOS'</code> (of type
49 *   <code>com.sun.star.table.CellAddress</code>):
50 *   The position of cell with annotation. </li>
51 * <ul> <p>
52 * Test is <b> NOT </b> multithread compilant. <p>
53 * @see com.sun.star.sheet.XSheetAnnotation
54 */
55 public class _XSheetAnnotation extends MultiMethodTest {
56 
57     public XSheetAnnotation oObj = null;
58 
59         /**
60         * Gets the author of annotation. <p>
61         * Has <b>OK</b> status if not null value returned.
62         */
_getAuthor()63         public void _getAuthor() {
64           String author = oObj.getAuthor();
65           tRes.tested("getAuthor()", author != null);
66         }
67 
68         /**
69         * Gets the modification date of annotation. <p>
70         * Has <b>OK</b> status if not null value returned.
71         */
_getDate()72         public void _getDate() {
73           String date = oObj.getDate();
74           tRes.tested("getDate()", date != null);
75         }
76 
77         /**
78         * Sets the string of annotation, then makes it visible and
79         * checks the value returned by <code>getIsVisible</code> method. <p>
80         * Has <b>OK</b> status if the method returns <code>true</code>.
81         */
_getIsVisible()82         public void _getIsVisible() {
83           XSimpleText oText  = (XSimpleText)
84             UnoRuntime.queryInterface(XSimpleText.class, oObj);
85           oText.setString("XSheetAnnotation");
86           oObj.setIsVisible(true);
87           boolean bVis = oObj.getIsVisible();
88           tRes.tested("getIsVisible()", bVis);
89         }
90 
91         /**
92         * Gets the position of annotated cell and compares it to
93         * the position passed as relation. <p>
94         * Has <b>OK</b> status if these positions are equal and not
95         * null.
96         */
_getPosition()97         public void _getPosition() {
98           boolean bResult = false;
99           CellAddress sCAddr = (CellAddress) tEnv.getObjRelation("CELLPOS") ;
100           if (sCAddr == null) throw new StatusException(Status.failed
101             ("Relation 'CELLPOS' not found"));
102 
103           CellAddress oCAddr = oObj.getPosition();
104 
105           bResult = (oCAddr != null) && (sCAddr != null) &&
106             ValueComparer.equalValue(oCAddr, sCAddr) ;
107 
108           tRes.tested("getPosition()", bResult);
109         }
110 
111         /**
112         * Sets the string of annotation, makes it hidden and then
113         * visible. Visibility is checked in both cases. <p>
114         * Has <b>OK</b> status if the <code>getIsVisible</code> method
115         * returns <code>flase</code> in the first case and <code>true</code>
116         * in the second.
117         */
_setIsVisible()118         public void _setIsVisible() {
119           boolean bResult = true;
120           XSimpleText oText  = (XSimpleText)
121               UnoRuntime.queryInterface(XSimpleText.class, oObj);
122           oText.setString("XSheetAnnotation");
123           oObj.setIsVisible(false);
124           boolean bVis = oObj.getIsVisible();
125           if (!bVis) {
126               oObj.setIsVisible(true);
127               bVis = oObj.getIsVisible();
128               if (bVis) {
129                   bResult = true;
130               }
131           }
132 
133           tRes.tested("setIsVisible()", bResult);
134         }
135 
136 } // EOC _XSheetAnnotation
137 
138