xref: /trunk/main/sc/qa/complex/dataPilot/_XNamed.java (revision 3309286857f19787ae62bd793a98b5af4edd2ad3)
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 package complex.dataPilot;
23 
24 import com.sun.star.container.XNamed;
25 import lib.TestParameters;
26 // import share.LogWriter;
27 // import util.utils;
28 
29 /**
30 * Testing <code>com.sun.star.container.XNamed</code>
31 * interface methods :
32 * <ul>
33 *  <li><code> getName()</code></li>
34 *  <li><code> setName()</code></li>
35 * </ul>
36 * This test need the following object relations :
37 * <ul>
38 *  <li> <code>'setName'</code> : of <code>Boolean</code>
39 *    type. If it exists then <code>setName</code> method
40 *    isn't to be tested and result of this test will be
41 *    equal to relation value.</li>
42 * <ul> <p>
43 * Test is <b> NOT </b> multithread compliant. <p>
44 * @see com.sun.star.container.XNamed
45 */
46 public class _XNamed {
47 
48     /**
49      * The object that is tested.
50      */
51     public XNamed oObj = null;
52 
53     /**
54      * The test parameters
55      */
56     private TestParameters param = null;
57 
58     /**
59      * The log writer
60      */
61     // private LogWriter log = null;
62 
63     /**
64      * Constructor: gets the object to test, a logger and the test parameters
65      * @param xObj The test object
66      * @param log A log writer
67      * @param param The test parameters
68      */
69     public _XNamed(XNamed xObj/*, LogWriter log*/, TestParameters param) {
70         oObj = xObj;
71         // this.log = log;
72         this.param = param;
73     }
74 
75     /**
76     * Test calls the method and checks return value and that
77     * no exceptions were thrown. <p>
78     * Has <b> OK </b> status if the method returns non null value
79     * and no exceptions were thrown. <p>
80     */
81     public boolean _getName() {
82 
83         // write to log what we try next
84         System.out.println( "test for getName()" );
85 
86         boolean result = true;
87         boolean loc_result = true;
88         String name = null;
89         String NewName = null;
90 
91         loc_result = ((name = oObj.getName()) != null);
92         System.out.println("getting the name \"" + name + "\"");
93 
94         if (loc_result)
95         {
96             System.out.println("... getName() - OK");
97         }
98         else
99         {
100             System.out.println("... getName() - FAILED");
101         }
102         result &= loc_result;
103         return result;
104     }
105 
106     /**
107     * Sets a new name for object and checks if it was properly
108     * set. Special cases for the following objects :
109     * <ul>
110     *  <li><code>ScSheetLinkObj</code> : name must be in form of URL.</li>
111     *  <li><code>ScDDELinkObj</code> : name must contain link to cell in
112     *     some external Sheet.</li>
113     * </ul>
114     * Has <b> OK </b> status if new name was successfully set, or if
115     * object environment contains relation <code>'setName'</code> with
116     * value <code>true</code>. <p>
117     * The following method tests are to be completed successfully before :
118     * <ul>
119     *  <li> <code> getName() </code> : to be sure the method works</li>
120     * </ul>
121     */
122     public boolean _setName(){
123 //        requiredMethod("getName()");
124         System.out.println("testing setName() ... ");
125 
126         String oldName = oObj.getName();
127         String NewName = oldName == null ? "XNamed" : oldName + "X" ;
128 
129         boolean result = true;
130         boolean loc_result = true;
131         System.out.println("set the name of object to \"" + NewName + "\"");
132         oObj.setName(NewName);
133         System.out.println("check that container has element with this name");
134 
135         String name = oObj.getName();
136         System.out.println("getting the name \"" + name + "\"");
137         loc_result = name.equals(NewName);
138 
139         if (loc_result)
140         {
141             System.out.println("... setName() - OK");
142         }
143         else
144         {
145             System.out.println("... setName() - FAILED");
146         }
147         result &= loc_result;
148         oObj.setName(oldName);
149         return result;
150     }
151 }
152