xref: /AOO41X/test/testuno/source/fvt/uno/sd/bullet/NumberingProperty.java (revision 28725c1964ec4d1e262fa3c5c925042422efbc77)
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 fvt.uno.sd.bullet;
25 import static org.junit.Assert.*;
26 import static testlib.uno.PageUtil.getDrawPageByIndex;
27 import static testlib.uno.ShapeUtil.addPortion;
28 import static testlib.uno.ShapeUtil.getPortion;
29 
30 import org.junit.After;
31 import org.junit.AfterClass;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Ignore;
35 import org.junit.Test;
36 import org.openoffice.test.uno.UnoApp;
37 import org.openoffice.test.common.FileUtil;
38 import org.openoffice.test.common.Testspace;
39 
40 import testlib.uno.SDUtil;
41 
42 import com.sun.star.beans.PropertyValue;
43 import com.sun.star.beans.UnknownPropertyException;
44 import com.sun.star.beans.XPropertySet;
45 import com.sun.star.container.XIndexAccess;
46 import com.sun.star.container.XIndexReplace;
47 import com.sun.star.drawing.XDrawPage;
48 import com.sun.star.drawing.XShape;
49 import com.sun.star.lang.WrappedTargetException;
50 import com.sun.star.lang.XComponent;
51 import com.sun.star.style.NumberingType;
52 import com.sun.star.text.HoriOrientation;
53 import com.sun.star.uno.AnyConverter;
54 import com.sun.star.uno.UnoRuntime;
55 
56 /**
57  * @author LouQL
58  *
59  */
60 public class NumberingProperty {
61 
62     private static final UnoApp app = new UnoApp();
63 
64     private XComponent m_xSDComponent = null;
65     private String m_filePath = null;
66     private XPropertySet m_xtextProps = null;
67 
68     @Before
setUpDocument()69     public void setUpDocument() throws Exception {
70         m_filePath = Testspace.getPath("temp/NumberingProperty.odp");
71 //      m_filePath = "F:/aa.odp";
72         if (FileUtil.fileExists(m_filePath)) {//load
73             m_xtextProps = load();
74         } else {//new
75             m_xSDComponent = (XComponent) UnoRuntime.queryInterface(
76                     XComponent.class, app.newDocument("simpress"));
77             Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
78             Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1);
79             XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox);
80             m_xtextProps = addPortion(xsecondTextBox,
81                     "test the property of Numbering bullets. There are two lines in this test",
82                     false);
83             setNumberingType(m_xtextProps, NumberingType.ARABIC, (short)0);
84         }
85     }
86 
load()87     private XPropertySet load() throws Exception{
88         m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
89                 app.loadDocument(m_filePath));
90         Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
91         XDrawPage firstpage = getDrawPageByIndex(m_xSDComponent, 0);
92         Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1);
93         XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox);
94         return getPortion(xsecondTextBox, 0);
95     }
96 
97     @After
tearDownDocument()98     public void tearDownDocument() {
99         app.closeDocument(m_xSDComponent);
100         //remove the temp file
101         FileUtil.deleteFile(Testspace.getPath("temp"));
102     }
103 
104     @BeforeClass
setUpConnection()105     public static void setUpConnection() throws Exception {
106         app.start();
107     }
108 
109     @AfterClass
tearDownConnection()110     public static void tearDownConnection() throws InterruptedException,
111             Exception {
112         app.close();
113 
114     }
115 
116     /*NumberingType: specifies the type of numbering
117      * GUI entry:Numbering and Bullet dialog->Customize->Numbering
118      * */
setNumberingType(XPropertySet textPros, short numberingType, short level)119     private void setNumberingType(XPropertySet textPros, short numberingType, short level) throws Exception{
120         Object numberingRules = textPros.getPropertyValue("NumberingRules");
121         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
122                  XIndexReplace.class, numberingRules);
123 
124         PropertyValue[] props = new PropertyValue[1];
125         props[0] = new PropertyValue();
126         props[0].Name = "NumberingType";
127         props[0].Value = numberingType;
128 
129         xReplace.replaceByIndex(level, props);
130 
131         m_xtextProps.setPropertyValue("NumberingRules", numberingRules);
132           //set numbering level to 0
133         m_xtextProps.setPropertyValue("NumberingLevel", level);
134     }
135 
136 
137 
138     @Test
139     /*
140      * Prefix: the prefix of the numbering symbol
141      * GUI entry: Numbering and Bullet dialog->customize->Before
142      * */
testPrefix()143     public void testPrefix() throws Exception {
144         String prefix = "Prefix";
145         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
146 
147         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
148                  XIndexReplace.class, numberingrules);
149 
150         PropertyValue[] props = new PropertyValue[1];
151         props[0] = new PropertyValue();
152         props[0].Name = "Prefix";
153         props[0].Value = prefix;
154 
155         xReplace.replaceByIndex(0, props);
156 
157         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
158 
159         app.saveDocument(m_xSDComponent, m_filePath);
160         app.closeDocument(m_xSDComponent);
161         //reopen
162         m_xtextProps = load();
163 
164         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
165 
166         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
167                  XIndexReplace.class, numberingrules2);
168 
169         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
170         for(int i=0;i<proValues2.length;i++)
171         {
172             if(proValues2[i].Name.equals("Prefix"))
173             {
174                 assertEquals("Prefix should be "+prefix, prefix, proValues2[i].Value);
175                 break;
176             }
177         }
178 
179     }
180 
181     @Test
182     /*
183      * Suffix: the suffix of the numbering symbol
184      * GUI entry: Numbering and Bullet dialog->customize->After
185      * */
testSuffix()186     public void testSuffix() throws Exception {
187         String suffix = "--";
188         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
189 
190         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
191                  XIndexReplace.class, numberingrules);
192 
193         PropertyValue[] props = new PropertyValue[1];
194         props[0] = new PropertyValue();
195         props[0].Name = "Suffix";
196         props[0].Value = suffix;
197 
198         xReplace.replaceByIndex(0, props);
199 
200         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
201 
202         app.saveDocument(m_xSDComponent, m_filePath);
203         app.closeDocument(m_xSDComponent);
204         //reopen
205         m_xtextProps = load();
206 
207         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
208 
209         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
210                  XIndexReplace.class, numberingrules2);
211 
212         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
213         for(int i=0;i<proValues2.length;i++)
214         {
215             if(proValues2[i].Name.equals("Suffix"))
216             {
217                 assertEquals("Suffix should be "+suffix, suffix, proValues2[i].Value);
218                 break;
219             }
220         }
221 
222 
223     }
224 
225     @Test
226     /*
227      * StartWith: specifies the start value for the numbering.
228      * GUI entry: Numbering and Bullet dialog->customize->Start At
229      * */
testStartWith()230     public void testStartWith() throws Exception {
231         short startWith = 5;
232         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
233 
234         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
235                  XIndexReplace.class, numberingrules);
236 
237         PropertyValue[] props = new PropertyValue[1];
238         props[0] = new PropertyValue();
239         props[0].Name = "StartWith";
240         props[0].Value = startWith;
241 
242         xReplace.replaceByIndex(0, props);
243 
244         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
245 
246         app.saveDocument(m_xSDComponent, m_filePath);
247         app.closeDocument(m_xSDComponent);
248         //reopen
249         m_xtextProps = load();
250 
251         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
252 
253         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
254                  XIndexReplace.class, numberingrules2);
255 
256         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
257 
258         String sStartWith = Short.toString(startWith);
259         for(int i=0;i<proValues2.length;i++)
260         {
261             if(proValues2[i].Name.equals("StartWith"))
262             {
263                 assertEquals("StartWith should be "+sStartWith, startWith, proValues2[i].Value);
264                 break;
265             }
266         }
267 
268     }
269 
270 
271 
272 
273     @Test
274     /*FirstLineOffset: specifies the offset between the beginning of the first line
275      * and the beginning of the following lines of the paragraph.
276     *GUI entry: paragraph dialog->Position tab->Width of numbering
277     */
testFirstLineOffset()278     public void testFirstLineOffset() throws Exception {
279         Integer firstLineOffset = -4500;
280         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
281         XIndexAccess xNum = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,
282                 numberingrules);
283         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
284                  XIndexReplace.class, xNum);
285 
286         PropertyValue[] props = new PropertyValue[1];
287         props[0] = new PropertyValue();
288         props[0].Name = "FirstLineOffset";
289         props[0].Value = firstLineOffset;
290 
291         xReplace.replaceByIndex(0, props);
292 
293         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
294 
295         app.saveDocument(m_xSDComponent, m_filePath);
296         app.closeDocument(m_xSDComponent);
297         //reopen
298         m_xtextProps = load();
299 
300         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
301 
302         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
303                  XIndexReplace.class, numberingrules2);
304 
305         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
306 
307         for(int i=0;i<proValues2.length;i++)
308         {
309             if(proValues2[i].Name.equals("FirstLineOffset"))
310             {
311                 assertEquals("SymbolTextDistance should be "+Integer.toString(firstLineOffset),
312                         firstLineOffset, proValues2[i].Value);
313                 break;
314             }
315         }
316 
317     }
318 
319     @Test
320     /*Leftmargin: specifies the left margin of the numbering
321      * GUI entry: Numbering and Bullet dialog->Position->Indent = Leftmargin+FirstLineOffset
322     */
testLeftMargin()323     public void testLeftMargin() throws Exception {
324         Integer leftMargin = 2000;
325         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
326         XIndexAccess xNum = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,
327                 numberingrules);
328         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
329                  XIndexReplace.class, xNum);
330 
331         PropertyValue[] props = new PropertyValue[1];
332         props[0] = new PropertyValue();
333         props[0].Name = "LeftMargin";
334         props[0].Value = leftMargin;
335 
336         xReplace.replaceByIndex(0, props);
337 
338         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
339 
340         app.saveDocument(m_xSDComponent, m_filePath);
341         app.closeDocument(m_xSDComponent);
342         //reopen
343         m_xtextProps = load();
344 
345         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
346 
347         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
348                  XIndexReplace.class, numberingrules2);
349 
350         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
351 
352         for(int i=0;i<proValues2.length;i++)
353         {
354             if(proValues2[i].Name.equals("LeftMargin"))
355             {
356                 assertEquals("Leftmargin should be "+Integer.toString(leftMargin), leftMargin, proValues2[i].Value);
357                 break;
358             }
359         }
360 
361     }
362     @Ignore
363     @Test
364     /*symbolTextDistance: specifies the distance between the numbering symbol and the text of the paragraph.
365     *GUI entry: ??
366     *This property cannot be set, it's always the same value as FirstLineOffset
367     */
testSymbolTextDistance()368     public void testSymbolTextDistance() throws Exception {
369         Integer symbolTextDistance = -2000;
370         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
371         XIndexAccess xNum = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,
372                 numberingrules);
373         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
374                  XIndexReplace.class, xNum);
375 
376         PropertyValue[] props = new PropertyValue[1];
377         props[0] = new PropertyValue();
378         props[0].Name = "SymbolTextDistance";
379         props[0].Value = symbolTextDistance;
380 
381         xReplace.replaceByIndex(0, props);
382 //      PropertyValue[] proValues = (PropertyValue[])xReplace.getByIndex(0);
383 //      for(int m=0;m<proValues.length;m++)
384 //      {
385 //          System.out.println(proValues[m].Name+"="+proValues[m].Value);
386 //      }
387 
388         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
389 
390         app.saveDocument(m_xSDComponent, m_filePath);
391         app.closeDocument(m_xSDComponent);
392         //reopen
393         m_xtextProps = load();
394 
395         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
396 
397         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
398                  XIndexReplace.class, numberingrules2);
399 
400         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
401 
402         for(int i=0;i<proValues2.length;i++)
403         {
404             if(proValues2[i].Name.equals("SymbolTextDistance"))
405             {
406                 assertEquals("SymbolTextDistance should be "+Integer.toString(symbolTextDistance),
407                         symbolTextDistance, proValues2[i].Value);
408                 break;
409             }
410         }
411 
412     }
413 
414     /*
415      * Ajust: adjusts the numbering (HoriOrientation_LEFT/RIGHT/CENTER)
416      * GUI entry: Numbering and Bullet dialog->Position->Numbering alignment
417      * */
418     @Test
testAjustRight()419     public void testAjustRight() throws Exception {
420         Short ajust = HoriOrientation.RIGHT;
421         setAjust(ajust);
422 
423         app.saveDocument(m_xSDComponent, m_filePath);
424         app.closeDocument(m_xSDComponent);
425         //reopen
426         m_xtextProps = load();
427 
428         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
429 
430         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
431                  XIndexReplace.class, numberingrules2);
432 
433         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
434 
435         for(int i=0;i<proValues2.length;i++)
436         {
437             if(proValues2[i].Name.equals("Adjust"))
438             {
439                 assertEquals("Ajust should be HoriOrientation.RIGHT", HoriOrientation.RIGHT, AnyConverter.toUnsignedShort(proValues2[i].Value));
440                 break;
441             }
442         }
443     }
setAjust(Short ajust)444     private void setAjust(Short ajust) throws Exception{
445         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
446 
447         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
448                  XIndexReplace.class, numberingrules);
449 
450         PropertyValue[] props = new PropertyValue[1];
451         props[0] = new PropertyValue();
452         props[0].Name = "Adjust";
453         props[0].Value = ajust;
454 
455         xReplace.replaceByIndex(0, props);
456 
457         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
458     }
459 
460     /*
461      * Ajust: adjusts the numbering (HoriOrientation_LEFT/RIGHT/CENTER)
462      * GUI entry: Numbering and Bullet dialog->Position->Numbering alignment
463      * */
464     @Test
testAjustCenter()465     public void testAjustCenter() throws Exception {
466         Short ajust = HoriOrientation.CENTER;
467         setAjust(ajust);
468         app.saveDocument(m_xSDComponent, m_filePath);
469         app.closeDocument(m_xSDComponent);
470         //reopen
471         m_xtextProps = load();
472 
473         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
474 
475         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
476                  XIndexReplace.class, numberingrules2);
477 
478         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
479         String sAdjust = Short.toString(ajust);
480         for(int i=0;i<proValues2.length;i++)
481         {
482             if(proValues2[i].Name.equals("Adjust"))
483             {
484                 assertEquals("Ajust should be HoriOrientation.CENTER", HoriOrientation.CENTER, AnyConverter.toUnsignedShort(proValues2[i].Value));
485                 break;
486             }
487         }
488 
489     }
490 
491     /*
492      * Ajust: adjusts the numbering (HoriOrientation_LEFT/RIGHT/CENTER)
493      * GUI entry: Numbering and Bullet dialog->Position->Numbering alignment
494      * */
495     @Test
testAjustLeft()496     public void testAjustLeft() throws Exception {
497         Short ajust = HoriOrientation.LEFT;
498         setAjust(ajust);
499         app.saveDocument(m_xSDComponent, m_filePath);
500         app.closeDocument(m_xSDComponent);
501         //reopen
502         m_xtextProps = load();
503 
504         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
505 
506         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
507                  XIndexReplace.class, numberingrules2);
508 
509         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
510         String sAdjust = Short.toString(ajust);
511         for(int i=0;i<proValues2.length;i++)
512         {
513             if(proValues2[i].Name.equals("Adjust"))
514             {
515                 assertEquals("Ajust should be HoriOrientation.LEFT",
516                         HoriOrientation.LEFT, AnyConverter.toUnsignedShort(proValues2[i].Value));
517                 break;
518             }
519         }
520     }
521 
522     @Test
523     /*BulletColor: contains the color for the symbol.
524      * In SDK docs it says this is only valid if the numbering type is NumberingType::CHAR_SPECIAL.
525      * But infact it also valid here
526     *GUI entry: Bullet and Numbering dialog->Customize->Color
527     */
testSymbolColor()528     public void testSymbolColor() throws Exception {
529         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
530 
531         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
532                  XIndexReplace.class, numberingrules);
533 
534         PropertyValue[] props = new PropertyValue[1];
535         props[0] = new PropertyValue();
536         props[0].Name = "BulletColor";
537         props[0].Value = new Integer(255);
538 
539         xReplace.replaceByIndex(0, props);
540 
541         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
542 
543         app.saveDocument(m_xSDComponent, m_filePath);
544         app.closeDocument(m_xSDComponent);
545         //reopen
546         m_xtextProps = load();
547 
548         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
549 
550         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
551                  XIndexReplace.class, numberingrules2);
552 
553         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
554 
555         for(int i=0;i<proValues2.length;i++)
556         {
557 
558             if(proValues2[i].Name.equals("BulletColor"))
559             {
560                 assertEquals("BulletColor should be Blue",
561                         new Integer(255), proValues2[i].Value);
562                 break;
563             }
564         }
565 
566     }
567 
568     @Test
569     /*BulletRelSize: contains the size of the symbol relative to the high of the paragraph
570      * In SDK docs it says this is only valid if the numbering type is NumberingType::CHAR_SPECIAL.
571      * But in fact it also valid here
572     *GUI entry: Bullet and Numbering dialog->Customize->Relative Size
573     */
testSymbolSize()574     public void testSymbolSize() throws Exception {
575         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
576 
577         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
578                  XIndexReplace.class, numberingrules);
579 
580         PropertyValue[] props = new PropertyValue[1];
581         props[0] = new PropertyValue();
582         props[0].Name = "BulletRelSize";
583         props[0].Value = new Short((short)100);
584 
585         xReplace.replaceByIndex(0, props);
586 
587         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
588 
589         app.saveDocument(m_xSDComponent, m_filePath);
590         app.closeDocument(m_xSDComponent);
591         //reopen
592         m_xtextProps = load();
593 
594         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
595 
596         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
597                  XIndexReplace.class, numberingrules2);
598 
599         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
600 
601         for(int i=0;i<proValues2.length;i++)
602         {
603             if(proValues2[i].Name.equals("BulletRelSize"))
604             {
605                 assertEquals("BulletRelSize should be 100%",
606                         new Short((short)100), proValues2[i].Value);
607                 break;
608             }
609         }
610 
611     }
612 
613 }
614