View | Details | Raw Unified | Return to issue 120562
Collapse All | Expand All

(-)CheckCharacterStyle.java (+201 lines)
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 com.sun.star.beans.PropertyValue;
29
import com.sun.star.beans.XPropertySet;
30
import com.sun.star.container.XIndexAccess;
31
import com.sun.star.drawing.XDrawPage;
32
import com.sun.star.drawing.XDrawPagesSupplier;
33
import com.sun.star.drawing.XShapes;
34
import com.sun.star.frame.XStorable;
35
36
import com.sun.star.lang.XComponent;
37
38
import com.sun.star.text.XText;
39
import com.sun.star.uno.UnoRuntime;
40
41
/**
42
 * @author LouQL
43
 *
44
 */
45
public class CheckCharacterStyle {
46
47
	private static final UnoApp app = new UnoApp();	
48
	private XComponent m_xSDComponent = null;
49
	private XText xShapeText = null;
50
	private String filePath = null;
51
	private XPropertySet xtextProps = null;
52
	/**
53
	 * @throws java.lang.Exception
54
	 */
55
	@BeforeClass
56
	public static void setUpConnection() throws Exception {
57
		app.start();
58
		File temp = new File(Testspace.getPath("temp"));
59
		temp.mkdirs();
60
	}
61
	
62
	@AfterClass
63
	public static void tearDownConnection() throws Exception {
64
		app.close();
65
		//remove the temp file
66
		FileUtil.deleteFile(Testspace.getPath("temp"));
67
	}
68
69
	/**
70
	 * @throws java.lang.Exception
71
	 */
72
	@Before
73
	public void setUp() throws Exception {
74
		filePath = Testspace.getPath("temp/CheckCharacterStyle.odt");
75
		if(FileUtil.fileExists(filePath))
76
		{	//load
77
			m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 
78
						app.loadDocument(filePath));
79
			xShapeText = getFirstTextbox(m_xSDComponent);	  			    
80
		}
81
		else{
82
			//create a sd
83
			m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress"));
84
			xShapeText = getFirstTextbox(m_xSDComponent);	 
85
			xShapeText.setString("test");
86
		}		   	
87
		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);
88
	}
89
	
90
	private XText getFirstTextbox(XComponent xcomponent) throws Exception
91
	{
92
		XDrawPagesSupplier xDrawPagesSupplier = 
93
                (XDrawPagesSupplier)UnoRuntime.queryInterface(
94
                    XDrawPagesSupplier.class, xcomponent);
95
96
        Object drawPages = xDrawPagesSupplier.getDrawPages();
97
        XIndexAccess xIndexedDrawPages = (XIndexAccess)UnoRuntime.queryInterface(
98
                XIndexAccess.class, drawPages);
99
        Object drawPage = xIndexedDrawPages.getByIndex(0);
100
 
101
        XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage);
102
        XShapes m_xdrawShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class, xDrawPage);  
103
                       
104
        Object m_firstTextbox = m_xdrawShapes.getByIndex(0);               	
105
        return (XText)UnoRuntime.queryInterface(XText.class, m_firstTextbox); 
106
	}
107
	
108
	private void saveFile(XComponent xcomponent, String toPath) throws Exception{			
109
		XStorable m_xstorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, xcomponent);	
110
		if(FileUtil.fileExists(toPath))
111
		{
112
			m_xstorable.store();
113
		}
114
		else{
115
			String fileUrl = FileUtil.getUrl(new File(toPath));	
116
			m_xstorable.storeAsURL(fileUrl, new PropertyValue[0]);
117
		}
118
	}
119
120
	/**
121
	 * @throws java.lang.Exception
122
	 */
123
	@After
124
	public void tearDown() throws Exception {
125
		//close odp after each test
126
		m_xSDComponent.dispose();
127
	}
128
129
	@Test
130
	public void testFontColor() throws Exception{
131
		//set font color to red
132
		xtextProps.setPropertyValue("CharColor", 0xFF0000);
133
		saveFile(m_xSDComponent, filePath);
134
		m_xSDComponent.dispose();
135
		//reopen
136
		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 
137
					app.loadDocument(filePath));
138
		xShapeText = getFirstTextbox(m_xSDComponent);	   
139
		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);
140
		//check character styles		
141
		assertEquals("character color should be red", 0xFF0000,xtextProps.getPropertyValue("CharColor"));
142
		
143
	}
144
	@Test
145
	public void testFontUnderline() throws Exception{
146
		//set font color to red
147
		xtextProps.setPropertyValue("CharUnderline", com.sun.star.awt.FontUnderline.SINGLE);
148
		saveFile(m_xSDComponent, filePath);
149
		m_xSDComponent.dispose();
150
		//reopen
151
		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 
152
					app.loadDocument(filePath));
153
		xShapeText = getFirstTextbox(m_xSDComponent);	   
154
		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);
155
		//check character styles		
156
		assertEquals("character should be underlined", com.sun.star.awt.FontUnderline.SINGLE, xtextProps.getPropertyValue("CharUnderline"));
157
		
158
	}
159
	
160
	@Test
161
	public void testFontSize() throws Exception{
162
		//set font color to red
163
		xtextProps.setPropertyValue("CharHeight", 12);
164
		saveFile(m_xSDComponent, filePath);
165
		m_xSDComponent.dispose();
166
		//reopen
167
		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 
168
					app.loadDocument(filePath));
169
		xShapeText = getFirstTextbox(m_xSDComponent);	   
170
		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);
171
		//check character styles		
172
		assertEquals("font size should be 12.0", "12.0", xtextProps.getPropertyValue("CharHeight").toString());
173
	}
174
	@Test
175
	public void testFontBoldStyle() throws Exception  {	
176
		//change the font style to Bold
177
		xtextProps.setPropertyValue("CharWeight", com.sun.star.awt.FontWeight.BOLD);
178
		saveFile(m_xSDComponent, filePath);
179
		m_xSDComponent.dispose();
180
		//reopen
181
		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 
182
					app.loadDocument(filePath));
183
		xShapeText = getFirstTextbox(m_xSDComponent);	   
184
		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);		
185
		assertEquals("font style should be bold", com.sun.star.awt.FontWeight.BOLD, xtextProps.getPropertyValue("CharWeight"));		
186
	}
187
	
188
	@Test
189
	public void testFontItalicStyle() throws Exception  {	
190
		//change the font style to Bold
191
		xtextProps.setPropertyValue("CharPosture", com.sun.star.awt.FontSlant.ITALIC);
192
		saveFile(m_xSDComponent, filePath);
193
		m_xSDComponent.dispose();
194
		//reopen
195
		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 
196
					app.loadDocument(filePath));
197
		xShapeText = getFirstTextbox(m_xSDComponent);	   
198
		xtextProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShapeText);		
199
		assertEquals("font style should be bold", com.sun.star.awt.FontSlant.ITALIC, xtextProps.getPropertyValue("CharPosture"));		
200
	}
201
}

Return to issue 120562