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