Line 0
Link Here
|
|
|
1 |
/** |
2 |
* check character style |
3 |
* 1. new a impress |
4 |
* 2. insert one line text in the first textbox |
5 |
* 3. set the font color to red |
6 |
* 4. save, close, reopen, then check the font color |
7 |
* 5. set the underline to single |
8 |
* 6. save, close, reopen, then check the underline |
9 |
* 7. set the font size to 12 |
10 |
* 8. save, close, reopen, then check the font size |
11 |
* 9. set font style to Bold, Italic |
12 |
* 10. save, close, reopen, then check the font style |
13 |
*/ |
14 |
package testcase.uno.sd; |
15 |
|
16 |
import static org.junit.Assert.*; |
17 |
|
18 |
import java.io.File; |
19 |
import org.junit.After; |
20 |
import org.junit.AfterClass; |
21 |
import org.junit.Before; |
22 |
import org.junit.BeforeClass; |
23 |
import org.junit.Test; |
24 |
import org.openoffice.test.common.FileUtil; |
25 |
import org.openoffice.test.common.Testspace; |
26 |
import org.openoffice.test.uno.UnoApp; |
27 |
|
28 |
import testlib.uno.SDUnoUtil; |
29 |
|
30 |
import com.sun.star.beans.PropertyValue; |
31 |
import com.sun.star.beans.XPropertySet; |
32 |
import com.sun.star.container.XIndexAccess; |
33 |
import com.sun.star.drawing.XDrawPage; |
34 |
import com.sun.star.drawing.XDrawPages; |
35 |
import com.sun.star.drawing.XDrawPagesSupplier; |
36 |
import com.sun.star.drawing.XShapes; |
37 |
import com.sun.star.frame.XStorable; |
38 |
|
39 |
import com.sun.star.lang.XComponent; |
40 |
|
41 |
import com.sun.star.text.XText; |
42 |
import com.sun.star.uno.UnoRuntime; |
43 |
|
44 |
/** |
45 |
* @author LouQL |
46 |
* |
47 |
*/ |
48 |
public class CheckCharacterStyle { |
49 |
|
50 |
private static final UnoApp app = new UnoApp(); |
51 |
private static final SDUnoUtil SDUtil = new SDUnoUtil(); |
52 |
private XComponent m_xSDComponent = null; |
53 |
private XText xShapeText = null; |
54 |
private String filePath = null; |
55 |
private XPropertySet xtextProps = null; |
56 |
/** |
57 |
* @throws java.lang.Exception |
58 |
*/ |
59 |
@BeforeClass |
60 |
public static void setUpConnection() throws Exception { |
61 |
app.start(); |
62 |
File temp = new File(Testspace.getPath("temp")); |
63 |
temp.mkdirs(); |
64 |
} |
65 |
|
66 |
@AfterClass |
67 |
public static void tearDownConnection() throws Exception { |
68 |
app.close(); |
69 |
//remove the temp file |
70 |
FileUtil.deleteFile(Testspace.getPath("temp")); |
71 |
} |
72 |
|
73 |
/** |
74 |
* @throws java.lang.Exception |
75 |
*/ |
76 |
@Before |
77 |
public void setUp() throws Exception { |
78 |
filePath = Testspace.getPath("temp/CheckCharacterStyle.odt"); |
79 |
if(FileUtil.fileExists(filePath)) |
80 |
{ //load |
81 |
m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, |
82 |
app.loadDocument(filePath)); |
83 |
xShapeText = getFirstTextbox(); |
84 |
} |
85 |
else{ |
86 |
//create a sd |
87 |
m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress")); |
88 |
xShapeText = getFirstTextbox(); |
89 |
xShapeText.setString("test"); |
90 |
} |
91 |
xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); |
92 |
} |
93 |
|
94 |
private XText getFirstTextbox() throws Exception |
95 |
{ |
96 |
Object firstPage = SDUtil.getPageByIndex(m_xSDComponent, 0); |
97 |
Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0); |
98 |
return (XText)UnoRuntime.queryInterface(XText.class, firstTextBox); |
99 |
} |
100 |
|
101 |
/** |
102 |
* @throws java.lang.Exception |
103 |
*/ |
104 |
@After |
105 |
public void tearDown() throws Exception { |
106 |
//close odp after each test |
107 |
m_xSDComponent.dispose(); |
108 |
} |
109 |
|
110 |
@Test |
111 |
public void testFontColor() throws Exception{ |
112 |
//set font color to red |
113 |
xtextProps.setPropertyValue("CharColor", 0xFF0000); |
114 |
app.SaveDocument(m_xSDComponent, filePath); |
115 |
m_xSDComponent.dispose(); |
116 |
//reopen |
117 |
m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, |
118 |
app.loadDocument(filePath)); |
119 |
xShapeText = getFirstTextbox(); |
120 |
xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); |
121 |
//check character styles |
122 |
assertEquals("character color should be red", 0xFF0000,xtextProps.getPropertyValue("CharColor")); |
123 |
|
124 |
} |
125 |
@Test |
126 |
public void testFontUnderline() throws Exception{ |
127 |
//set font color to red |
128 |
xtextProps.setPropertyValue("CharUnderline", com.sun.star.awt.FontUnderline.SINGLE); |
129 |
app.SaveDocument(m_xSDComponent, filePath); |
130 |
m_xSDComponent.dispose(); |
131 |
//reopen |
132 |
m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, |
133 |
app.loadDocument(filePath)); |
134 |
xShapeText = getFirstTextbox(); |
135 |
xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); |
136 |
//check character styles |
137 |
assertEquals("character should be underlined", com.sun.star.awt.FontUnderline.SINGLE, xtextProps.getPropertyValue("CharUnderline")); |
138 |
} |
139 |
|
140 |
@Test |
141 |
public void testFontSize() throws Exception{ |
142 |
//set font color to red |
143 |
xtextProps.setPropertyValue("CharHeight", 12); |
144 |
app.SaveDocument(m_xSDComponent, filePath); |
145 |
m_xSDComponent.dispose(); |
146 |
//reopen |
147 |
m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, |
148 |
app.loadDocument(filePath)); |
149 |
xShapeText = getFirstTextbox(); |
150 |
xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); |
151 |
//check character styles |
152 |
assertEquals("font size should be 12.0", "12.0", xtextProps.getPropertyValue("CharHeight").toString()); |
153 |
} |
154 |
@Test |
155 |
public void testFontBoldStyle() throws Exception { |
156 |
//change the font style to Bold |
157 |
xtextProps.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD); |
158 |
app.SaveDocument(m_xSDComponent, filePath); |
159 |
m_xSDComponent.dispose(); |
160 |
//reopen |
161 |
m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, |
162 |
app.loadDocument(filePath)); |
163 |
xShapeText = getFirstTextbox(); |
164 |
xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); |
165 |
assertEquals("font style should be bold", com.sun.star.awt.FontWeight.BOLD, xtextProps.getPropertyValue("CharWeight")); |
166 |
} |
167 |
|
168 |
@Test |
169 |
public void testFontItalicStyle() throws Exception { |
170 |
//change the font style to Bold |
171 |
xtextProps.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC); |
172 |
app.SaveDocument(m_xSDComponent, filePath); |
173 |
m_xSDComponent.dispose(); |
174 |
//reopen |
175 |
m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, |
176 |
app.loadDocument(filePath)); |
177 |
xShapeText = getFirstTextbox(); |
178 |
xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText); |
179 |
assertEquals("font style should be bold", com.sun.star.awt.FontSlant.ITALIC, xtextProps.getPropertyValue("CharPosture")); |
180 |
} |
181 |
} |