xref: /AOO41X/test/testuno/source/fvt/uno/sd/bullet/NumberingBulletTypes.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.GraphicUtil.getUniqueIDOfGraphicFile;
27 import static testlib.uno.PageUtil.getDrawPageByIndex;
28 import static testlib.uno.ShapeUtil.addPortion;
29 import static testlib.uno.ShapeUtil.getPortion;
30 
31 import java.util.Arrays;
32 import java.util.Collection;
33 
34 import org.junit.After;
35 import org.junit.AfterClass;
36 import org.junit.Before;
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.junit.runners.Parameterized;
41 import org.junit.runners.Parameterized.Parameters;
42 import org.openoffice.test.uno.UnoApp;
43 import org.openoffice.test.common.FileUtil;
44 import org.openoffice.test.common.Testspace;
45 
46 import testlib.uno.SDUtil;
47 
48 import com.sun.star.awt.Size;
49 import com.sun.star.beans.PropertyValue;
50 import com.sun.star.beans.UnknownPropertyException;
51 import com.sun.star.beans.XPropertySet;
52 import com.sun.star.container.XIndexReplace;
53 import com.sun.star.drawing.XDrawPage;
54 import com.sun.star.drawing.XShape;
55 import com.sun.star.lang.WrappedTargetException;
56 import com.sun.star.lang.XComponent;
57 import com.sun.star.style.NumberingType;
58 import com.sun.star.uno.UnoRuntime;
59 
60 /**
61  * @author LouQL
62  *
63  */
64 @RunWith(Parameterized.class)
65 public class NumberingBulletTypes {
66 
67     private static final UnoApp app = new UnoApp();
68 
69     private XComponent m_xSDComponent = null;
70     private String m_filePath = null;
71     private XPropertySet m_xtextProps = null;
72     private short m_numberingType = 0;
73     private short m_expectType=0;
74 
75     @Before
setUpDocument()76     public void setUpDocument() throws Exception {
77         m_filePath = Testspace.getPath("temp/NumberingBulletTypes.odp");
78         if (FileUtil.fileExists(m_filePath)) {//load
79             m_xtextProps = load();
80         } else {//new
81             m_xSDComponent = (XComponent) UnoRuntime.queryInterface(
82                     XComponent.class, app.newDocument("simpress"));
83             Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
84             Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1);
85             XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox);
86             m_xtextProps = addPortion(xsecondTextBox, "Numbering bullets", false);
87         }
88     }
load()89     private XPropertySet load() throws Exception{
90         m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
91                 app.loadDocument(m_filePath));
92         Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
93         XDrawPage firstpage = getDrawPageByIndex(m_xSDComponent, 0);
94         Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1);
95         XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox);
96         return getPortion(xsecondTextBox, 0);
97     }
98 
99     @After
tearDownDocument()100     public void tearDownDocument() {
101         app.closeDocument(m_xSDComponent);
102         //remove the temp file
103         FileUtil.deleteFile(Testspace.getPath("temp"));
104     }
105 
106     @BeforeClass
setUpConnection()107     public static void setUpConnection() throws Exception {
108         app.start();
109     }
110 
111     @AfterClass
tearDownConnection()112     public static void tearDownConnection() throws InterruptedException,
113             Exception {
114         app.close();
115 
116     }
117 
118     @Parameters
data()119     public static Collection<Short[]> data(){
120         Short[][] numberingTypes = new Short[][]{
121                 {NumberingType.CHARS_UPPER_LETTER, NumberingType.CHARS_UPPER_LETTER},
122                 {NumberingType.CHARS_LOWER_LETTER, NumberingType.CHARS_LOWER_LETTER},
123                 {NumberingType.ROMAN_UPPER, NumberingType.ROMAN_UPPER},
124                 {NumberingType.ROMAN_LOWER, NumberingType.ROMAN_LOWER},
125                 {NumberingType.ARABIC, NumberingType.ARABIC},
126                 //bug: 120752
127 //              {NumberingType.CIRCLE_NUMBER, NumberingType.CIRCLE_NUMBER},
128                 {NumberingType.NUMBER_NONE, NumberingType.NUMBER_NONE}};
129         return Arrays.asList(numberingTypes);
130     }
131 
NumberingBulletTypes(short input, short expect)132     public NumberingBulletTypes(short input, short expect){
133         m_numberingType = input;
134         m_expectType = expect;
135     }
136 
137     /*NumberingType: specifies the type of numbering
138      * GUI entry:Numbering and Bullet dialog->Customize->Numbering
139      * */
140     @Test
testNumberingTypes()141     public void testNumberingTypes() throws Exception {
142         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
143 
144         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
145                  XIndexReplace.class, numberingrules);
146 
147         PropertyValue[] props = new PropertyValue[1];
148         props[0] = new PropertyValue();
149         props[0].Name = "NumberingType";
150         props[0].Value = m_numberingType;
151 
152         xReplace.replaceByIndex(0, props);
153 
154         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
155           //set numbering level to 0
156         m_xtextProps.setPropertyValue("NumberingLevel", new Short((short)0));
157 
158         app.saveDocument(m_xSDComponent, m_filePath);
159         app.closeDocument(m_xSDComponent);
160 //      m_xSDComponent.dispose();
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 
171         assertEquals("NumberingType should be"+m_numberingType, m_expectType, proValues2[0].Value);
172     }
173 }
174