xref: /aoo41x/main/sc/qa/complex/dataPilot/_XNamed.java (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package complex.dataPilot;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import com.sun.star.container.XNamed;
31*cdf0e10cSrcweir import lib.TestParameters;
32*cdf0e10cSrcweir // import share.LogWriter;
33*cdf0e10cSrcweir // import util.utils;
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir /**
36*cdf0e10cSrcweir * Testing <code>com.sun.star.container.XNamed</code>
37*cdf0e10cSrcweir * interface methods :
38*cdf0e10cSrcweir * <ul>
39*cdf0e10cSrcweir *  <li><code> getName()</code></li>
40*cdf0e10cSrcweir *  <li><code> setName()</code></li>
41*cdf0e10cSrcweir * </ul>
42*cdf0e10cSrcweir * This test need the following object relations :
43*cdf0e10cSrcweir * <ul>
44*cdf0e10cSrcweir *  <li> <code>'setName'</code> : of <code>Boolean</code>
45*cdf0e10cSrcweir *    type. If it exists then <code>setName</code> method
46*cdf0e10cSrcweir *    isn't to be tested and result of this test will be
47*cdf0e10cSrcweir *    equal to relation value.</li>
48*cdf0e10cSrcweir * <ul> <p>
49*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
50*cdf0e10cSrcweir * @see com.sun.star.container.XNamed
51*cdf0e10cSrcweir */
52*cdf0e10cSrcweir public class _XNamed {
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     /**
55*cdf0e10cSrcweir      * The object that is testsed.
56*cdf0e10cSrcweir      */
57*cdf0e10cSrcweir     public XNamed oObj = null;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     /**
60*cdf0e10cSrcweir      * The test parameters
61*cdf0e10cSrcweir      */
62*cdf0e10cSrcweir     private TestParameters param = null;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     /**
65*cdf0e10cSrcweir      * The log writer
66*cdf0e10cSrcweir      */
67*cdf0e10cSrcweir     // private LogWriter log = null;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     /**
70*cdf0e10cSrcweir      * Constructor: gets the object to test, a logger and the test parameters
71*cdf0e10cSrcweir      * @param xObj The test object
72*cdf0e10cSrcweir      * @param log A log writer
73*cdf0e10cSrcweir      * @param param The test parameters
74*cdf0e10cSrcweir      */
75*cdf0e10cSrcweir     public _XNamed(XNamed xObj/*, LogWriter log*/, TestParameters param) {
76*cdf0e10cSrcweir         oObj = xObj;
77*cdf0e10cSrcweir         // this.log = log;
78*cdf0e10cSrcweir         this.param = param;
79*cdf0e10cSrcweir     }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     /**
82*cdf0e10cSrcweir     * Test calls the method and checks return value and that
83*cdf0e10cSrcweir     * no exceptions were thrown. <p>
84*cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns non null value
85*cdf0e10cSrcweir     * and no exceptions were thrown. <p>
86*cdf0e10cSrcweir     */
87*cdf0e10cSrcweir     public boolean _getName() {
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir         // write to log what we try next
90*cdf0e10cSrcweir         System.out.println( "test for getName()" );
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         boolean result = true;
93*cdf0e10cSrcweir         boolean loc_result = true;
94*cdf0e10cSrcweir         String name = null;
95*cdf0e10cSrcweir         String NewName = null;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir         loc_result = ((name = oObj.getName()) != null);
98*cdf0e10cSrcweir         System.out.println("getting the name \"" + name + "\"");
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         if (loc_result)
101*cdf0e10cSrcweir         {
102*cdf0e10cSrcweir             System.out.println("... getName() - OK");
103*cdf0e10cSrcweir         }
104*cdf0e10cSrcweir         else
105*cdf0e10cSrcweir         {
106*cdf0e10cSrcweir             System.out.println("... getName() - FAILED");
107*cdf0e10cSrcweir         }
108*cdf0e10cSrcweir         result &= loc_result;
109*cdf0e10cSrcweir         return result;
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     /**
113*cdf0e10cSrcweir     * Sets a new name for object and checks if it was properly
114*cdf0e10cSrcweir     * set. Special cases for the following objects :
115*cdf0e10cSrcweir     * <ul>
116*cdf0e10cSrcweir     *  <li><code>ScSheetLinkObj</code> : name must be in form of URL.</li>
117*cdf0e10cSrcweir     *  <li><code>ScDDELinkObj</code> : name must contain link to cell in
118*cdf0e10cSrcweir     *     some external Sheet.</li>
119*cdf0e10cSrcweir     * </ul>
120*cdf0e10cSrcweir     * Has <b> OK </b> status if new name was successfully set, or if
121*cdf0e10cSrcweir     * object environment contains relation <code>'setName'</code> with
122*cdf0e10cSrcweir     * value <code>true</code>. <p>
123*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
124*cdf0e10cSrcweir     * <ul>
125*cdf0e10cSrcweir     *  <li> <code> getName() </code> : to be sure the method works</li>
126*cdf0e10cSrcweir     * </ul>
127*cdf0e10cSrcweir     */
128*cdf0e10cSrcweir     public boolean _setName(){
129*cdf0e10cSrcweir //        requiredMethod("getName()");
130*cdf0e10cSrcweir         System.out.println("testing setName() ... ");
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir         String oldName = oObj.getName();
133*cdf0e10cSrcweir         String NewName = oldName == null ? "XNamed" : oldName + "X" ;
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir         boolean result = true;
136*cdf0e10cSrcweir         boolean loc_result = true;
137*cdf0e10cSrcweir         System.out.println("set the name of object to \"" + NewName + "\"");
138*cdf0e10cSrcweir         oObj.setName(NewName);
139*cdf0e10cSrcweir         System.out.println("check that container has element with this name");
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir         String name = oObj.getName();
142*cdf0e10cSrcweir         System.out.println("getting the name \"" + name + "\"");
143*cdf0e10cSrcweir         loc_result = name.equals(NewName);
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir         if (loc_result)
146*cdf0e10cSrcweir         {
147*cdf0e10cSrcweir             System.out.println("... setName() - OK");
148*cdf0e10cSrcweir         }
149*cdf0e10cSrcweir         else
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir             System.out.println("... setName() - FAILED");
152*cdf0e10cSrcweir         }
153*cdf0e10cSrcweir         result &= loc_result;
154*cdf0e10cSrcweir         oObj.setName(oldName);
155*cdf0e10cSrcweir         return result;
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 
160