xref: /trunk/test/testuno/source/fvt/uno/sd/bullet/CheckBuildInBullet.java (revision 07d7dbdcb8e526dfaf85923a181c45494526d79d)
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  * There are 8 build-in bullets. Verify those bullets can be applied successfully.
23  * insert text into a SD
24  * apply the 8 bullets one by one, and check
25  */
26 package fvt.uno.sd.bullet;
27 
28 import static org.junit.Assert.assertEquals;
29 import static testlib.uno.PageUtil.getDrawPageByIndex;
30 import static testlib.uno.ShapeUtil.addPortion;
31 import static testlib.uno.ShapeUtil.getPortion;
32 
33 import java.io.File;
34 import java.util.Arrays;
35 import java.util.Collection;
36 
37 import org.junit.After;
38 import org.junit.AfterClass;
39 import org.junit.Before;
40 import org.junit.BeforeClass;
41 import org.junit.Test;
42 import org.junit.runner.RunWith;
43 import org.junit.runners.Parameterized;
44 import org.junit.runners.Parameterized.Parameters;
45 import org.openoffice.test.common.FileUtil;
46 import org.openoffice.test.common.Testspace;
47 import org.openoffice.test.uno.UnoApp;
48 
49 import testlib.uno.SDUtil;
50 
51 import com.sun.star.beans.PropertyValue;
52 import com.sun.star.beans.XPropertySet;
53 import com.sun.star.container.XIndexReplace;
54 import com.sun.star.drawing.XShape;
55 import com.sun.star.lang.XComponent;
56 import com.sun.star.style.NumberingType;
57 import com.sun.star.uno.UnoRuntime;
58 
59 
60 /**
61  * @author LouQL
62  *
63  */
64 @RunWith(Parameterized.class)
65 public class CheckBuildInBullet {
66 
67     private static final UnoApp app = new UnoApp();
68     private XComponent m_xSDComponent = null;
69     private String m_filePath = null;
70     private XPropertySet m_xtextProps = null;
71     private String m_BulletChar = null;
72     private String m_expectedBulletChar = null;
73     /**
74      * @throws java.lang.Exception
75      */
76 
77     public CheckBuildInBullet(String BulletChar, String expected) {
78         this.m_BulletChar = BulletChar;
79         m_expectedBulletChar = expected;
80     }
81     @Parameters
82     public static Collection<String[]> data() {
83         String[][] bulletChar = new String[][] {{"\u25cf","\u25cf"}, {"\u2022","\u2022"}, {"\ue00c","\ue00c"},{"\ue00a","\ue00a"},{"\u2794","\u2794"}, {"\u27a2","\u27a2"}, {"\u2717","\u2717"},{"\u2714","\u2714"}};
84         return Arrays.asList(bulletChar);
85     }
86 
87     @BeforeClass
88     public static void setUpBeforeClass() throws Exception {
89         app.start();
90         File temp = new File(Testspace.getPath("temp"));
91         temp.mkdirs();
92     }
93 
94     /**
95      * @throws java.lang.Exception
96      */
97     @AfterClass
98     public static void tearDownAfterClass() throws Exception {
99         app.close();
100         //remove the temp file
101         FileUtil.deleteFile(Testspace.getPath("temp"));
102     }
103 
104     /**
105      * @throws java.lang.Exception
106      */
107     @Before
108     public void setUp() throws Exception {
109         m_filePath = Testspace.getPath("temp/CheckBuildInBullet.odt");
110 //      m_filePath = "F:/aa.odp";
111         if(FileUtil.fileExists(m_filePath))
112         {   //load
113             m_xtextProps = load();
114         }
115         else{
116             //create a sd
117             m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress"));
118             Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
119             Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0);
120             XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
121             m_xtextProps = addPortion(xfirstTextBox, "test Build-in Bullet", false);
122         }
123     }
124 
125     /**
126      * @throws java.lang.Exception
127      */
128     @After
129     public void tearDown() throws Exception {
130         app.closeDocument(m_xSDComponent);
131     }
132     private XPropertySet load() throws Exception{
133         m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
134                 app.loadDocument(m_filePath));
135         Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
136         Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0);
137         XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
138         return getPortion(xfirstTextBox, 0);
139     }
140 
141     @Test
142     public void testBuildInBullet() throws Exception {
143 
144         Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
145 
146         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
147                  XIndexReplace.class, numberingrules);
148 
149         PropertyValue[] props = new PropertyValue[2];
150         props[0] = new PropertyValue();
151         props[0].Name = "NumberingType";
152         props[0].Value = new Short(NumberingType.CHAR_SPECIAL );
153 
154         props[1] = new PropertyValue();
155         props[1].Name = "BulletChar";
156         props[1].Value = this.m_BulletChar;
157 
158         //set numberingType
159         xReplace.replaceByIndex(0, props);
160         m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
161       //set numbering level to 0
162         m_xtextProps.setPropertyValue("NumberingLevel", new Short((short)0));
163 
164         app.saveDocument(m_xSDComponent, m_filePath);
165         app.closeDocument(m_xSDComponent);
166         //reopen
167         m_xtextProps = load();
168 
169         Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
170 
171         XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
172                  XIndexReplace.class, numberingrules2);
173 
174         PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);
175         assertEquals("NumberingType should be CHAR_SPECIAL", NumberingType.CHAR_SPECIAL, proValues2[0].Value);
176         assertEquals("BulletChar should be"+m_expectedBulletChar, m_expectedBulletChar, proValues2[4].Value);
177     }
178 }
179