1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package ifc.text;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
26cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
27cdf0e10cSrcweir import com.sun.star.container.XIndexReplace;
28cdf0e10cSrcweir import com.sun.star.text.XTextColumns;
29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import lib.MultiPropertyTest;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir /**
35cdf0e10cSrcweir * Testing <code>com.sun.star.text.BaseIndex</code>
36cdf0e10cSrcweir * service properties :
37cdf0e10cSrcweir * <ul>
38cdf0e10cSrcweir *  <li><code> Title</code></li>
39cdf0e10cSrcweir *  <li><code> IsProtected</code></li>
40cdf0e10cSrcweir *  <li><code> ParaStyleHeading</code></li>
41cdf0e10cSrcweir *  <li><code> ParaStyleLevel1</code></li>
42cdf0e10cSrcweir *  <li><code> ParaStyleLevel2</code></li>
43cdf0e10cSrcweir *  <li><code> ParaStyleLevel3</code></li>
44cdf0e10cSrcweir *  <li><code> ParaStyleLevel4</code></li>
45cdf0e10cSrcweir *  <li><code> ParaStyleLevel5</code></li>
46cdf0e10cSrcweir *  <li><code> ParaStyleLevel6</code></li>
47cdf0e10cSrcweir *  <li><code> ParaStyleLevel7</code></li>
48cdf0e10cSrcweir *  <li><code> ParaStyleLevel8</code></li>
49cdf0e10cSrcweir *  <li><code> ParaStyleLevel9</code></li>
50cdf0e10cSrcweir *  <li><code> ParaStyleLevel10</code></li>
51cdf0e10cSrcweir *  <li><code> ParaStyleSeparator</code></li>
52cdf0e10cSrcweir *  <li><code> TextColumns</code></li>
53cdf0e10cSrcweir *  <li><code> BackGraphicURL</code></li>
54cdf0e10cSrcweir *  <li><code> BackGraphicFilter</code></li>
55cdf0e10cSrcweir *  <li><code> BackGraphicLocation</code></li>
56cdf0e10cSrcweir *  <li><code> BackTransparent</code></li>
57cdf0e10cSrcweir *  <li><code> LevelFormat</code></li>
58cdf0e10cSrcweir *  <li><code> CreateFromChapter</code></li>
59cdf0e10cSrcweir * </ul> <p>
60cdf0e10cSrcweir * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
61cdf0e10cSrcweir * @see com.sun.star.text.BaseIndex
62cdf0e10cSrcweir */
63cdf0e10cSrcweir public class _BaseIndex extends MultiPropertyTest {
64cdf0e10cSrcweir     /**
65cdf0e10cSrcweir     * Redefined method returns object, that contains changed property value.
66cdf0e10cSrcweir     */
67cdf0e10cSrcweir     protected PropertyTester CustomTester = new PropertyTester() {
68cdf0e10cSrcweir         protected Object getNewValue(String propName, Object oldValue) {
69cdf0e10cSrcweir             XTextColumns TC = (XTextColumns) UnoRuntime.queryInterface(
70cdf0e10cSrcweir                                       XTextColumns.class, oldValue);
71cdf0e10cSrcweir             TC.setColumnCount((short) (TC.getColumnCount() + (short) 1));
72cdf0e10cSrcweir 
73cdf0e10cSrcweir             return TC;
74cdf0e10cSrcweir         }
75cdf0e10cSrcweir     };
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     /**
78cdf0e10cSrcweir     * New value must be defined for this property.
79cdf0e10cSrcweir     */
_TextColumns()80cdf0e10cSrcweir     public void _TextColumns() {
81cdf0e10cSrcweir         log.println(
82cdf0e10cSrcweir                 "Testing property 'TextColumns' with custom property tester");
83cdf0e10cSrcweir         testProperty("TextColumns", CustomTester);
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     /**
87cdf0e10cSrcweir      * The value of this property is a collection of document index
88cdf0e10cSrcweir      * level formats. This property is tested in the following manner :
89cdf0e10cSrcweir      * the property value (a collection) is obtained, the first element
90cdf0e10cSrcweir      * of this collection is replaced with new non-empty array
91cdf0e10cSrcweir      * (<code>PropertyValue[][]</code>) with some properties set.
92cdf0e10cSrcweir      * After that the collection is set back as property value. <p>
93cdf0e10cSrcweir      *
94cdf0e10cSrcweir      * Comparing of set and got <code>PropertyValue</code> arrays
95cdf0e10cSrcweir      * is difficult because values can be changed after setting
96cdf0e10cSrcweir      * by service miplementation. <p>
97cdf0e10cSrcweir      *
98cdf0e10cSrcweir      * Has <b>OK</b> status if the collection again gotten, has a
99cdf0e10cSrcweir      * new first element (i.e. lengths of the old array and the array
100cdf0e10cSrcweir      * get are different or their contents differ).
101cdf0e10cSrcweir      */
_LevelFormat()102cdf0e10cSrcweir     public void _LevelFormat() {
103cdf0e10cSrcweir         log.println(
104cdf0e10cSrcweir                 "Testing property 'LevelFormat' with custom property tester");
105cdf0e10cSrcweir         testProperty("LevelFormat",
106cdf0e10cSrcweir                      new PropertyTester() {
107cdf0e10cSrcweir             PropertyValue[][] newVal = null;
108cdf0e10cSrcweir             PropertyValue[][] oldVal = null;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir             protected Object getNewValue(String propName, Object oldValue) {
111cdf0e10cSrcweir                 XIndexReplace indProp = (XIndexReplace) UnoRuntime.queryInterface(
112cdf0e10cSrcweir                                                 XIndexReplace.class, oldValue);
113cdf0e10cSrcweir 
114cdf0e10cSrcweir                 try {
115cdf0e10cSrcweir                     oldVal = (PropertyValue[][]) indProp.getByIndex(0);
116cdf0e10cSrcweir 
117cdf0e10cSrcweir                     log.println("Get:");
118cdf0e10cSrcweir                     printLevelFormatProperty(oldValue);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir                     newVal = new PropertyValue[1][2];
121cdf0e10cSrcweir 
122cdf0e10cSrcweir                     for (int i = 0; i < newVal[0].length; i++) {
123cdf0e10cSrcweir                         newVal[0][i] = new PropertyValue();
124cdf0e10cSrcweir                     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir                     newVal[0][1].Name = "TokenType";
127cdf0e10cSrcweir                     newVal[0][1].Value = "TokenEntryText";
128cdf0e10cSrcweir                     newVal[0][0].Name = "Text";
129cdf0e10cSrcweir                     newVal[0][0].Value = "BaseIndex";
130cdf0e10cSrcweir 
131cdf0e10cSrcweir                     indProp.replaceByIndex(0, newVal);
132cdf0e10cSrcweir                 } catch (com.sun.star.lang.WrappedTargetException e) {
133cdf0e10cSrcweir                     log.println("Exception occured while testing LevelFormat");
134cdf0e10cSrcweir                     e.printStackTrace(log);
135cdf0e10cSrcweir                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
136cdf0e10cSrcweir                     log.println("Exception occured while testing LevelFormat");
137cdf0e10cSrcweir                     e.printStackTrace(log);
138cdf0e10cSrcweir                 } catch (com.sun.star.lang.IllegalArgumentException e) {
139cdf0e10cSrcweir                     log.println("Exception occured while testing LevelFormat");
140cdf0e10cSrcweir                     e.printStackTrace(log);
141cdf0e10cSrcweir                 }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir                 return indProp;
144cdf0e10cSrcweir             }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir             protected void checkResult(String propName, Object oldValue,
147cdf0e10cSrcweir                                        Object newValue, Object resValue,
148cdf0e10cSrcweir                                        Exception exception)
149cdf0e10cSrcweir                                 throws Exception {
150cdf0e10cSrcweir                 PropertyValue[][] res = (PropertyValue[][]) ((XIndexAccess) UnoRuntime.queryInterface(
151cdf0e10cSrcweir                                                                      XIndexAccess.class,
152cdf0e10cSrcweir                                                                      resValue)).getByIndex(0);
153cdf0e10cSrcweir 
154cdf0e10cSrcweir                 log.println("Result:");
155cdf0e10cSrcweir                 printLevelFormatProperty(resValue);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir                 boolean result = (res.length != oldVal.length) ||
158cdf0e10cSrcweir                                  !util.ValueComparer.equalValue(res, oldVal);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir                 tRes.tested(propName, result);
161cdf0e10cSrcweir             }
162cdf0e10cSrcweir         });
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     /**
166cdf0e10cSrcweir      * Outputs full description of 'LevelFormat' property
167cdf0e10cSrcweir      * value into <code>log</code>.
168cdf0e10cSrcweir      */
printLevelFormatProperty(Object value)169cdf0e10cSrcweir     private void printLevelFormatProperty(Object value) {
170cdf0e10cSrcweir         XIndexReplace indProp = (XIndexReplace) UnoRuntime.queryInterface(
171cdf0e10cSrcweir                                         XIndexReplace.class, value);
172cdf0e10cSrcweir         PropertyValue[][] val = null;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir         try {
175cdf0e10cSrcweir             log.println(" \u0421ollection has " + indProp.getCount() +
176cdf0e10cSrcweir                         " elements : ");
177cdf0e10cSrcweir 
178cdf0e10cSrcweir             for (int i = 0; i < indProp.getCount(); i++) {
179cdf0e10cSrcweir                 val = (PropertyValue[][]) indProp.getByIndex(i);
180cdf0e10cSrcweir 
181cdf0e10cSrcweir                 log.println("  " + i + ": has " + val.length + " levels :");
182cdf0e10cSrcweir 
183cdf0e10cSrcweir                 for (int j = 0; j < val.length; j++) {
184cdf0e10cSrcweir                     log.println("    " + j + " level :");
185cdf0e10cSrcweir 
186cdf0e10cSrcweir                     for (int k = 0; k < val[j].length; k++) {
187cdf0e10cSrcweir                         log.println("      " + val[j][k].Name + "=" +
188cdf0e10cSrcweir                                     val[j][k].Value);
189cdf0e10cSrcweir                     }
190cdf0e10cSrcweir                 }
191cdf0e10cSrcweir             }
192cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
193cdf0e10cSrcweir             log.println("Exception occured while printing LevelFormat");
194cdf0e10cSrcweir             e.printStackTrace(log);
195cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
196cdf0e10cSrcweir             log.println("Exception occured while printing LevelFormat");
197cdf0e10cSrcweir             e.printStackTrace(log);
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir } // finish class _NumberingRules
201