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

(-)org/openoffice/test/uno/UnoApp.java (+8 lines)
Lines 21-26 Link Here
21
21
22
package org.openoffice.test.uno;
22
package org.openoffice.test.uno;
23
23
24
import java.io.File;
24
import java.util.Timer;
25
import java.util.Timer;
25
import java.util.TimerTask;
26
import java.util.TimerTask;
26
27
Lines 34-39 Link Here
34
import com.sun.star.comp.helper.Bootstrap;
35
import com.sun.star.comp.helper.Bootstrap;
35
import com.sun.star.frame.XComponentLoader;
36
import com.sun.star.frame.XComponentLoader;
36
import com.sun.star.frame.XDesktop;
37
import com.sun.star.frame.XDesktop;
38
import com.sun.star.frame.XStorable;
37
import com.sun.star.lang.XComponent;
39
import com.sun.star.lang.XComponent;
38
import com.sun.star.lang.XMultiComponentFactory;
40
import com.sun.star.lang.XMultiComponentFactory;
39
import com.sun.star.lang.XMultiServiceFactory;
41
import com.sun.star.lang.XMultiServiceFactory;
Lines 150-155 Link Here
150
		return componentLoader.loadComponentFromURL("private:factory/" + type, "_blank", 0, new PropertyValue[0]);
152
		return componentLoader.loadComponentFromURL("private:factory/" + type, "_blank", 0, new PropertyValue[0]);
151
	}
153
	}
152
	
154
	
155
	public void SaveDocument(XComponent doc, String toPath) throws Exception {
156
		XStorable m_xstorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, doc);	
157
		String fileUrl = FileUtil.getUrl(new File(toPath));	
158
		m_xstorable.storeAsURL(fileUrl, new PropertyValue[0]);
159
	}
160
	
153
	public void closeDocument(XComponent doc) {
161
	public void closeDocument(XComponent doc) {
154
		try {
162
		try {
155
			XModifiable modified = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, doc);
163
			XModifiable modified = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, doc);
(-)testcase/uno/sd/CheckCharacterStyle.java (+181 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 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
}
(-)testlib/uno/SDUnoUtil.java (+48 lines)
Line 0 Link Here
1
/**
2
 * 
3
 */
4
package testlib.uno;
5
6
import com.sun.star.container.XIndexAccess;
7
import com.sun.star.drawing.XDrawPage;
8
import com.sun.star.drawing.XDrawPagesSupplier;
9
import com.sun.star.drawing.XShapes;
10
import com.sun.star.lang.IndexOutOfBoundsException;
11
import com.sun.star.lang.WrappedTargetException;
12
import com.sun.star.lang.XComponent;
13
import com.sun.star.text.XText;
14
import com.sun.star.uno.UnoRuntime;
15
16
/**
17
 * 
18
 *
19
 */
20
public class SDUnoUtil {
21
22
	/**
23
	 * @throws WrappedTargetException 
24
	 * @throws  
25
	 * @throws java.lang.Exception
26
	 */
27
	public SDUnoUtil(){
28
		
29
	}
30
		
31
	public Object getPageByIndex(XComponent doc, int index) throws Exception{
32
		XDrawPagesSupplier xDrawPagesSupplier = 
33
                (XDrawPagesSupplier)UnoRuntime.queryInterface(
34
                    XDrawPagesSupplier.class, doc);
35
36
        Object drawPages = xDrawPagesSupplier.getDrawPages();
37
        XIndexAccess xIndexedDrawPages = (XIndexAccess)UnoRuntime.queryInterface(
38
                XIndexAccess.class, drawPages);
39
        return xIndexedDrawPages.getByIndex(index);
40
	}
41
	
42
	public Object getShapeOfPageByIndex(Object page, int index) throws Exception{
43
		XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, page);
44
		XShapes m_xdrawShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class, xDrawPage);  
45
        return m_xdrawShapes.getByIndex(index); 
46
	}
47
48
}

Return to issue 120562