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.text;
25 
26 import lib.MultiPropertyTest;
27 
28 import com.sun.star.container.XNameContainer;
29 import com.sun.star.uno.AnyConverter;
30 import com.sun.star.uno.Type;
31 import com.sun.star.xml.AttributeData;
32 
33 /**
34 * Testing <code>com.sun.star.text.CellProperties</code>
35 * service properties :
36 * <ul>
37 *  <li><code> BackColor</code></li>
38 *  <li><code> BackGraphicURL</code></li>
39 *  <li><code> BackGraphicFilter</code></li>
40 *  <li><code> BackGraphicLocation</code></li>
41 *  <li><code> NumberFormat</code></li>
42 *  <li><code> BackTransparent</code></li>
43 *  <li><code> LeftBorder</code></li>
44 *  <li><code> RightBorder</code></li>
45 *  <li><code> TopBorder</code></li>
46 *  <li><code> BottomBorder</code></li>
47 *  <li><code> LeftBorderDistance</code></li>
48 *  <li><code> RightBorderDistance</code></li>
49 *  <li><code> TopBorderDistance</code></li>
50 *  <li><code> BottomBorderDistance</code></li>
51 *  <li><code> UserDefinedAttributes</code></li>
52 *  <li><code> TextSection</code></li>
53 *  <li><code> IsProtected</code></li>
54 * </ul> <p>
55 * This test needs the following object relations :
56 * <ul>
57 *  <li> <code>'CellProperties.TextSection'</code> (of type
58 *  <code>XInterface</code>):
59 *   instance of <code>com.sun.star.text.TextSection</code></li>
60 * </ul> <p>
61 * The following predefined files needed to complete the test:
62 * <ul>
63 *  <li> <code> crazy-blue.jpg </code> : jpeg image used to test
64 *  BackGraphicURL()</li>
65 *  <li> <code> space-metal.jpg </code> : jpeg image used to test
66 *  BackGraphicURL()</li>
67 * </ul> <p>
68 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
69 * @see com.sun.star.text.CellProperties
70 */
71 public class _CellProperties extends MultiPropertyTest {
72 
73     /**
74     * This property can be void, so new value must be specified from
75     * corresponding object relation.
76     */
_TextSection()77     public void _TextSection() {
78         log.println("Testing with custom Property tester") ;
79         testProperty("TextSection", new PropertyTester() {
80             protected Object getNewValue(String propName, Object oldValue) {
81                 return tEnv.getObjRelation("CellProperties.TextSection");
82             }
83         });
84     }
85 
86 
87     /**
88     * Redefined method returns value, that differs from property value.
89     */
_BackColor()90     public void _BackColor() {
91         final Short val1 = new Short( (short) 4 );
92         final Short val2 = new Short( (short) 6 );
93         log.println("Testing with custom Property tester") ;
94         testProperty("BackColor", new PropertyTester() {
95             protected Object getNewValue(String propName, Object oldValue) {
96                 if ( oldValue.equals(val1) )
97                     return val2;
98                 else
99                     return val1;
100             }
101         });
102     }
103 
104 
105     /**
106     * Redefined method returns value, that differs from property value.
107     */
_BackGraphicURL()108     public void _BackGraphicURL() {
109         log.println("Testing with custom Property tester") ;
110         testProperty("BackGraphicURL", new PropertyTester() {
111             protected Object getNewValue(String propName, Object oldValue) {
112                 if (oldValue.equals(util.utils.getFullTestURL
113                         ("space-metal.jpg")))
114                     return util.utils.getFullTestURL("crazy-blue.jpg");
115                 else
116                     return util.utils.getFullTestURL("space-metal.jpg");
117             }
118         });
119     }
120 
121 
122     /**
123     * Redefined method returns object, that contains changed property value.
124     */
_UserDefinedAttributes()125     public void _UserDefinedAttributes() {
126         log.println("Testing with custom property tester");
127         testProperty("UserDefinedAttributes", new PropertyTester() {
128             protected Object getNewValue(String propName, Object oldValue) {
129                 XNameContainer NC = null;
130                 try {
131                     NC = (XNameContainer)
132                     AnyConverter.toObject(new Type(XNameContainer.class),oldValue);
133                     NC.insertByName("MyAttribute",
134                         new AttributeData("","CDATA","Value"));
135                 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
136                     log.println("Failed to check 'UserDefinedAttributes'");
137                     e.printStackTrace(log);
138                 } catch ( com.sun.star.lang.WrappedTargetException e ) {
139                     log.println("Failed to check 'UserDefinedAttributes'");
140                     e.printStackTrace(log);
141                 } catch ( com.sun.star.container.ElementExistException e ) {
142                     log.println("Failed to check 'UserDefinedAttributes'");
143                     e.printStackTrace(log);
144                 }
145                 return NC;
146             }
147         });
148     }
149 
150 } //finish class _CellProperties
151 
152