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.text.XTextColumns;
29 import com.sun.star.uno.AnyConverter;
30 import com.sun.star.uno.Type;
31 
32 /**
33  * Testing <code>com.sun.star.text.TextSection</code>
34  * service properties :
35  * <ul>
36  *  <li><code> Condition</code></li>
37  *  <li><code> IsVisible</code></li>
38  *  <li><code> IsProtected</code></li>
39  *  <li><code> FileLink</code></li>
40  *  <li><code> LinkRegion</code></li>
41  *  <li><code> DDECommandType</code></li>
42  *  <li><code> DDECommandFile</code></li>
43  *  <li><code> DDECommandElement</code></li>
44  *  <li><code> BackGraphicURL</code></li>
45  *  <li><code> BackGraphicFilter</code></li>
46  *  <li><code> BackGraphicLocation</code></li>
47  *  <li><code> FootnoteIsCollectAtTextEnd</code></li>
48  *  <li><code> FootnoteIsRestartNumbering</code></li>
49  *  <li><code> FootnoteRestartNumberingAt</code></li>
50  *  <li><code> FootnoteIsOwnNumbering</code></li>
51  *  <li><code> FootnoteNumberingType</code></li>
52  *  <li><code> FootnoteNumberingPrefix</code></li>
53  *  <li><code> FootnoteNumberingSuffix</code></li>
54  *  <li><code> EndnoteIsCollectAtTextEnd</code></li>
55  *  <li><code> EndnoteIsRestartNumbering</code></li>
56  *  <li><code> EndnoteRestartNumberingAt</code></li>
57  *  <li><code> EndnoteIsOwnNumbering</code></li>
58  *  <li><code> EndnoteNumberingType</code></li>
59  *  <li><code> EndnoteNumberingPrefix</code></li>
60  *  <li><code> EndnoteNumberingSuffix</code></li>
61  *  <li><code> IsAutomaticUpdate</code></li>
62  * </ul> <p>
63  * The following predefined files needed to complete the test:
64  * <ul>
65  *  <li> <code>crazy-blue.jpg, space-metal.jpg</code> : are used for
66  *  setting 'BackGraphicURL' property. </li>
67  * <ul> <p>
68  * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
69  * @see com.sun.star.text.TextSection
70  */
71 public class _TextSection extends MultiPropertyTest {
72 
73     /**
74      * Only image file URL can be used as a value.
75      */
_BackGraphicURL()76     public void _BackGraphicURL() {
77         log.println("Testing with custom Property tester") ;
78         testProperty("BackGraphicURL",
79         util.utils.getFullTestURL("crazy-blue.jpg"),
80         util.utils.getFullTestURL("space-metal.jpg")) ;
81     }
82 
83     /**
84      * This property can be void, so if old value is <code> null </code>
85      * new value must be specified.
86      */
_FootnoteNumberingType()87     public void _FootnoteNumberingType() {
88         log.println("Testing with custom Property tester") ;
89         testProperty("FootnoteNumberingType",
90         new Short(com.sun.star.text.FootnoteNumbering.PER_DOCUMENT),
91         new Short(com.sun.star.text.FootnoteNumbering.PER_PAGE)) ;
92     }
93 
94 
95     /**
96     * Custom property tester for property <code>TextColumns</code>
97     */
98     protected PropertyTester TextColumnsTester = new PropertyTester() {
99 
100         protected Object getNewValue(String propName, Object oldValue) {
101         XTextColumns TC = null;
102         short val2set = 25;
103 
104         TC = (XTextColumns) tEnv.getObjRelation("TC");
105         try {
106             val2set += ((XTextColumns) AnyConverter.toObject(
107                 new Type(XTextColumns.class),oldValue)).getColumnCount();
108         } catch (com.sun.star.lang.IllegalArgumentException iae) {
109             log.println("Couldn't change Column count");
110         }
111         TC.setColumnCount(val2set);
112 
113         return TC;
114         }
115 
116         protected boolean compare(Object obj1, Object obj2) {
117             short val1 = 0;
118             short val2 = 1;
119             try {
120                 val1 = ((XTextColumns) AnyConverter.toObject(
121                     new Type(XTextColumns.class),obj1)).getColumnCount();
122                 val2 = ((XTextColumns) AnyConverter.toObject(
123                     new Type(XTextColumns.class),obj2)).getColumnCount();
124             } catch (com.sun.star.lang.IllegalArgumentException iae) {
125                 log.println("comparing values failed");
126             }
127             return val1 == val2;
128         }
129 
130         protected String toString(Object obj) {
131             return "XTextColumns: ColumnCount = "+
132                         ((XTextColumns) obj).getColumnCount();
133         }
134 
135     };
136 
_TextColumns()137     public void _TextColumns() {
138         log.println("Testing with custom Property tester");
139         testProperty("TextColumns", TextColumnsTester);
140     }
141 
142 
143 } //finish class _TextContent
144 
145