xref: /AOO41X/test/testuno/source/fvt/uno/sw/puretext/CharacterRelief.java (revision eba4d44a33e5be0b2528d5a9a6f0dcbf65adaa0d)
1*eba4d44aSLiu Zhe package fvt.uno.sw.puretext;
2*eba4d44aSLiu Zhe 
3*eba4d44aSLiu Zhe import static org.junit.Assert.*;
4*eba4d44aSLiu Zhe 
5*eba4d44aSLiu Zhe import org.junit.After;
6*eba4d44aSLiu Zhe import org.junit.Before;
7*eba4d44aSLiu Zhe import org.junit.Test;
8*eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil;
9*eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace;
10*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
11*eba4d44aSLiu Zhe //import org.openoffice.test.vcl.Tester.*;
12*eba4d44aSLiu Zhe import com.sun.star.text.*;
13*eba4d44aSLiu Zhe import com.sun.star.beans.*;
14*eba4d44aSLiu Zhe import com.sun.star.frame.XStorable;
15*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
16*eba4d44aSLiu Zhe 
17*eba4d44aSLiu Zhe public class CharacterRelief {
18*eba4d44aSLiu Zhe 	private static final UnoApp app = new UnoApp();
19*eba4d44aSLiu Zhe 	XText xText = null;
20*eba4d44aSLiu Zhe 
21*eba4d44aSLiu Zhe 	@Before
22*eba4d44aSLiu Zhe 	public void setUp() throws Exception {
23*eba4d44aSLiu Zhe 		app.start();
24*eba4d44aSLiu Zhe 
25*eba4d44aSLiu Zhe 	}
26*eba4d44aSLiu Zhe 
27*eba4d44aSLiu Zhe 	@After
28*eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
29*eba4d44aSLiu Zhe 		app.close();
30*eba4d44aSLiu Zhe 	}
31*eba4d44aSLiu Zhe 
32*eba4d44aSLiu Zhe 	@Test
33*eba4d44aSLiu Zhe 	public void testCharacterReliefSetting() throws Exception {
34*eba4d44aSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
35*eba4d44aSLiu Zhe 		xText = xTextDocument.getText();
36*eba4d44aSLiu Zhe 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
37*eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
38*eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!we are Chinese,they are American.We are all living in one earth!"
39*eba4d44aSLiu Zhe 				+ "and we all love our home very much!!!");
40*eba4d44aSLiu Zhe 		// create text cursor for selecting and formatting text
41*eba4d44aSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
42*eba4d44aSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
43*eba4d44aSLiu Zhe 		xTextCursor.gotoStart(false);
44*eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 102, true);
45*eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharRelief", new Short(com.sun.star.text.FontRelief.EMBOSSED));
46*eba4d44aSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
47*eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 102, true);
48*eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharRelief", new Short(com.sun.star.text.FontRelief.ENGRAVED));
49*eba4d44aSLiu Zhe 		xTextCursor.gotoRange(xTextCursor, false);
50*eba4d44aSLiu Zhe 		xTextCursor.goRight((short) 102, true);
51*eba4d44aSLiu Zhe 		xCursorProps.setPropertyValue("CharRelief", new Short(com.sun.star.text.FontRelief.NONE));
52*eba4d44aSLiu Zhe 		//save to odt
53*eba4d44aSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
54*eba4d44aSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
55*eba4d44aSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
56*eba4d44aSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
57*eba4d44aSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
58*eba4d44aSLiu Zhe 		aStoreProperties_odt[0].Value = true;
59*eba4d44aSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
60*eba4d44aSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
61*eba4d44aSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
62*eba4d44aSLiu Zhe 		//save to doc
63*eba4d44aSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
64*eba4d44aSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
65*eba4d44aSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
66*eba4d44aSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
67*eba4d44aSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
68*eba4d44aSLiu Zhe 		aStoreProperties_doc[0].Value = true;
69*eba4d44aSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
70*eba4d44aSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
71*eba4d44aSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
72*eba4d44aSLiu Zhe 		app.closeDocument(xTextDocument);
73*eba4d44aSLiu Zhe 
74*eba4d44aSLiu Zhe 		//reopen the document and assert row height setting
75*eba4d44aSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
76*eba4d44aSLiu Zhe 		XTextCursor xTextCursor_assert_odt=assertDocument_odt.getText().createTextCursor();
77*eba4d44aSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt);
78*eba4d44aSLiu Zhe 		//verify set property
79*eba4d44aSLiu Zhe 		xTextCursor_assert_odt.gotoStart(false);
80*eba4d44aSLiu Zhe 		xTextCursor_assert_odt.goRight((short) 102, true);
81*eba4d44aSLiu Zhe 		assertEquals("assert character relief",com.sun.star.text.FontRelief.EMBOSSED,xCursorProps_assert_odt.getPropertyValue("CharRelief"));
82*eba4d44aSLiu Zhe 		xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
83*eba4d44aSLiu Zhe 		xTextCursor_assert_odt.goRight((short) 102, true);
84*eba4d44aSLiu Zhe 		assertEquals("assert character relief",com.sun.star.text.FontRelief.ENGRAVED,xCursorProps_assert_odt.getPropertyValue("CharRelief"));
85*eba4d44aSLiu Zhe 		xTextCursor_assert_odt.gotoRange(xTextCursor_assert_odt, false);
86*eba4d44aSLiu Zhe 		xTextCursor_assert_odt.goRight((short) 102, true);
87*eba4d44aSLiu Zhe 		assertEquals("assert character relief",com.sun.star.text.FontRelief.NONE,xCursorProps_assert_odt.getPropertyValue("CharRelief"));
88*eba4d44aSLiu Zhe 
89*eba4d44aSLiu Zhe 		//reopen the document and assert row height setting
90*eba4d44aSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
91*eba4d44aSLiu Zhe 		XTextCursor xTextCursor_assert_doc=assertDocument_doc.getText().createTextCursor();
92*eba4d44aSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc);
93*eba4d44aSLiu Zhe 		//verify set property
94*eba4d44aSLiu Zhe 		xTextCursor_assert_doc.gotoStart(false);
95*eba4d44aSLiu Zhe 		xTextCursor_assert_doc.goRight((short) 102, true);
96*eba4d44aSLiu Zhe 		assertEquals("assert character relief",com.sun.star.text.FontRelief.EMBOSSED,xCursorProps_assert_doc.getPropertyValue("CharRelief"));
97*eba4d44aSLiu Zhe 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
98*eba4d44aSLiu Zhe 		xTextCursor_assert_doc.goRight((short) 102, true);
99*eba4d44aSLiu Zhe 		assertEquals("assert character relief",com.sun.star.text.FontRelief.ENGRAVED,xCursorProps_assert_doc.getPropertyValue("CharRelief"));
100*eba4d44aSLiu Zhe 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
101*eba4d44aSLiu Zhe 		xTextCursor_assert_doc.goRight((short) 102, true);
102*eba4d44aSLiu Zhe 		assertEquals("assert character relief",com.sun.star.text.FontRelief.NONE,xCursorProps_assert_doc.getPropertyValue("CharRelief"));
103*eba4d44aSLiu Zhe 	}
104*eba4d44aSLiu Zhe }
105