1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.text;
29 
30 import lib.MultiPropertyTest;
31 
32 import com.sun.star.container.XNameContainer;
33 import com.sun.star.uno.AnyConverter;
34 import com.sun.star.uno.Type;
35 import com.sun.star.xml.AttributeData;
36 
37 /**
38 * Testing <code>com.sun.star.text.CellProperties</code>
39 * service properties :
40 * <ul>
41 *  <li><code> BackColor</code></li>
42 *  <li><code> BackGraphicURL</code></li>
43 *  <li><code> BackGraphicFilter</code></li>
44 *  <li><code> BackGraphicLocation</code></li>
45 *  <li><code> NumberFormat</code></li>
46 *  <li><code> BackTransparent</code></li>
47 *  <li><code> LeftBorder</code></li>
48 *  <li><code> RightBorder</code></li>
49 *  <li><code> TopBorder</code></li>
50 *  <li><code> BottomBorder</code></li>
51 *  <li><code> LeftBorderDistance</code></li>
52 *  <li><code> RightBorderDistance</code></li>
53 *  <li><code> TopBorderDistance</code></li>
54 *  <li><code> BottomBorderDistance</code></li>
55 *  <li><code> UserDefinedAttributes</code></li>
56 *  <li><code> TextSection</code></li>
57 *  <li><code> IsProtected</code></li>
58 * </ul> <p>
59 * This test needs the following object relations :
60 * <ul>
61 *  <li> <code>'CellProperties.TextSection'</code> (of type
62 *  <code>XInterface</code>):
63 *   instance of <code>com.sun.star.text.TextSection</code></li>
64 * </ul> <p>
65 * The following predefined files needed to complete the test:
66 * <ul>
67 *  <li> <code> crazy-blue.jpg </code> : jpeg image used to test
68 *  BackGraphicURL()</li>
69 *  <li> <code> space-metal.jpg </code> : jpeg image used to test
70 *  BackGraphicURL()</li>
71 * </ul> <p>
72 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
73 * @see com.sun.star.text.CellProperties
74 */
75 public class _CellProperties extends MultiPropertyTest {
76 
77     /**
78     * This property can be void, so new value must be specified from
79     * corresponding object relation.
80     */
81     public void _TextSection() {
82         log.println("Testing with custom Property tester") ;
83         testProperty("TextSection", new PropertyTester() {
84             protected Object getNewValue(String propName, Object oldValue) {
85                 return tEnv.getObjRelation("CellProperties.TextSection");
86             }
87         });
88     }
89 
90 
91     /**
92     * Redefined method returns value, that differs from property value.
93     */
94     public void _BackColor() {
95         final Short val1 = new Short( (short) 4 );
96         final Short val2 = new Short( (short) 6 );
97         log.println("Testing with custom Property tester") ;
98         testProperty("BackColor", new PropertyTester() {
99             protected Object getNewValue(String propName, Object oldValue) {
100                 if ( oldValue.equals(val1) )
101                     return val2;
102                 else
103                     return val1;
104             }
105         });
106     }
107 
108 
109     /**
110     * Redefined method returns value, that differs from property value.
111     */
112     public void _BackGraphicURL() {
113         log.println("Testing with custom Property tester") ;
114         testProperty("BackGraphicURL", new PropertyTester() {
115             protected Object getNewValue(String propName, Object oldValue) {
116                 if (oldValue.equals(util.utils.getFullTestURL
117                         ("space-metal.jpg")))
118                     return util.utils.getFullTestURL("crazy-blue.jpg");
119                 else
120                     return util.utils.getFullTestURL("space-metal.jpg");
121             }
122         });
123     }
124 
125 
126     /**
127     * Redefined method returns object, that contains changed property value.
128     */
129     public void _UserDefinedAttributes() {
130         log.println("Testing with custom property tester");
131         testProperty("UserDefinedAttributes", new PropertyTester() {
132             protected Object getNewValue(String propName, Object oldValue) {
133                 XNameContainer NC = null;
134                 try {
135                     NC = (XNameContainer)
136                     AnyConverter.toObject(new Type(XNameContainer.class),oldValue);
137                     NC.insertByName("MyAttribute",
138                         new AttributeData("","CDATA","Value"));
139                 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
140                     log.println("Failed to check 'UserDefinedAttributes'");
141                     e.printStackTrace(log);
142                 } catch ( com.sun.star.lang.WrappedTargetException e ) {
143                     log.println("Failed to check 'UserDefinedAttributes'");
144                     e.printStackTrace(log);
145                 } catch ( com.sun.star.container.ElementExistException e ) {
146                     log.println("Failed to check 'UserDefinedAttributes'");
147                     e.printStackTrace(log);
148                 }
149                 return NC;
150             }
151         });
152     }
153 
154 } //finish class _CellProperties
155 
156