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