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.drawing;
25 
26 import lib.MultiPropertyTest;
27 
28 import com.sun.star.style.XStyle;
29 
30 /**
31 * Testing <code>com.sun.star.drawing.Shape</code>
32 * service properties :
33 * <ul>
34 *  <li><code> ZOrder</code></li>
35 *  <li><code> LayerID</code></li>
36 *  <li><code> LayerName</code></li>
37 *  <li><code> Printable</code></li>
38 *  <li><code> MoveProtect</code></li>
39 *  <li><code> Name</code></li>
40 *  <li><code> SizeProtect</code></li>
41 *  <li><code> Style</code></li>
42 *  <li><code> Transformation</code></li>
43 * </ul> <p>
44 * This test needs the following object relations :
45 * <ul>
46 *  <li> <code>'Style1', 'Style2'</code>
47 *   (of type <code>com.sun.star.style.XStyle</code>):
48 *    relations used to change property 'Style'</li>
49 * <ul> <p>
50 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
51 * @see com.sun.star.drawing.Shape
52 */
53 public class _Shape extends MultiPropertyTest {
54 
55     XStyle style1 = null;
56     XStyle style2 = null;
57 
58     /**
59      * Custom tester which switches between two styles.
60      */
61     protected PropertyTester StyleTester = new PropertyTester() {
62         protected Object getNewValue(String propName, Object oldValue)
63                 throws java.lang.IllegalArgumentException {
64             if (util.ValueComparer.equalValue(oldValue,style1))
65                 return style2; else
66                 return style1;
67         }
68     } ;
69 
70     /**
71      * Custom tester for 'LayerName' property which switches two
72      * Strings ('layout' and 'controls').
73      */
74     protected PropertyTester StringTester = new PropertyTester() {
75         protected Object getNewValue(String propName, Object oldValue)
76                 throws java.lang.IllegalArgumentException {
77             if (util.ValueComparer.equalValue(oldValue,"layout"))
78                 return "controls"; else
79                 return "layout";
80         }
81     } ;
82 
83     /**
84      * Tested with custom StyleTester which switches between two
85      * styles.
86      */
_Style()87     public void _Style() {
88         log.println("Testing with custom Property tester") ;
89         style1 = (XStyle) tEnv.getObjRelation("Style1");
90         style2 = (XStyle) tEnv.getObjRelation("Style2");
91         testProperty("Style", StyleTester) ;
92     }
93 
94     /**
95      * Tested with custom StringTester which switches two
96      * Strings ('layout' and 'controls')
97      */
_LayerName()98     public void _LayerName() {
99         if (tEnv.getTestCase().getObjectName().equals("SwXShape")) {
100             log.println("There is only one Layer for SwXShape");
101             log.println("Therefore this property can't be changed");
102             tRes.tested("LayerName",true);
103         } else if (tEnv.getTestCase().getObjectName().equals("ScShapeObj")) {
104             log.println("There is only one Layer for ScShapeObj");
105             log.println("Therefore this property can't be changed");
106             tRes.tested("LayerName",true);
107         } else if (tEnv.getTestCase().getObjectName().equals("ScAnnotationShapeObj")) {
108             log.println("There is only one Layer for ScAnnotationShapeObj");
109             log.println("Therefore this property can't be changed");
110             String aName = null;
111             try {
112                 aName = (String) oObj.getPropertyValue ("LayerName");
113                 log.println("LayerName: '"+aName+"'");
114             } catch (Exception e) {
115                 e.printStackTrace (log);
116             }
117             tRes.tested("LayerName",aName != null);
118         } else {
119             log.println("Testing with custom Property tester") ;
120             testProperty("LayerName", StringTester) ;
121         }
122     }
123 
_ZOrder()124     public void _ZOrder() {
125         if (tEnv.getTestCase().getObjectName().equals("ScAnnotationShapeObj")) {
126             log.println("There is only one Layer for ScAnnotationShapeObj");
127             log.println("Therefore this property can't be changed");
128             tRes.tested("ZOrder",true);
129         } else {
130             testProperty("ZOrder", new Integer(0), new Integer(1));
131         }
132     }
133 
_LayerID()134     public void _LayerID() {
135         if (tEnv.getTestCase().getObjectName().equals("ScAnnotationShapeObj")) {
136             log.println("There is only one Layer for ScAnnotationShapeObj");
137             log.println("Therefore this property can't be changed");
138             Short aID = null;
139             try {
140                 aID = (Short) oObj.getPropertyValue ("LayerID");
141                 log.println("LayerID: '"+aID.intValue ()+"'");
142             } catch (Exception e) {
143                 e.printStackTrace (log);
144             }
145             tRes.tested("LayerID",aID != null);
146         } else {
147             log.println("Testing with custom Property tester") ;
148             testProperty("LayerID");
149         }
150     }
151 
152 
153 }
154 
155