1*eba4d44aSLiu Zhe package fvt.uno.sw.puretext;
2352c0eacSLiu Zhe 
3352c0eacSLiu Zhe import static org.junit.Assert.*;
4352c0eacSLiu Zhe 
5352c0eacSLiu Zhe import org.junit.After;
6352c0eacSLiu Zhe import org.junit.Before;
7352c0eacSLiu Zhe import org.junit.Ignore;
8352c0eacSLiu Zhe import org.junit.Test;
9352c0eacSLiu Zhe import org.openoffice.test.common.FileUtil;
10352c0eacSLiu Zhe import org.openoffice.test.common.Testspace;
11352c0eacSLiu Zhe import org.openoffice.test.uno.UnoApp;
12352c0eacSLiu Zhe import com.sun.star.text.*;
13352c0eacSLiu Zhe import com.sun.star.beans.*;
14352c0eacSLiu Zhe import com.sun.star.frame.XStorable;
15352c0eacSLiu Zhe import com.sun.star.uno.UnoRuntime;
16352c0eacSLiu Zhe 
17352c0eacSLiu Zhe public class CharacterPosition {
18352c0eacSLiu Zhe 	private static final UnoApp app = new UnoApp();
19352c0eacSLiu Zhe 	XText xText = null;
20352c0eacSLiu Zhe 
21352c0eacSLiu Zhe 	@Before
22352c0eacSLiu Zhe 	public void setUp() throws Exception {
23352c0eacSLiu Zhe 		app.start();
24352c0eacSLiu Zhe 
25352c0eacSLiu Zhe 	}
26352c0eacSLiu Zhe 
27352c0eacSLiu Zhe 	@After
28352c0eacSLiu Zhe 	public void tearDown() throws Exception {
29352c0eacSLiu Zhe 		app.close();
30352c0eacSLiu Zhe 	}
31352c0eacSLiu Zhe 
32352c0eacSLiu Zhe 	@Test
33352c0eacSLiu Zhe 	public void testCharacterSuperscriptSetting() throws Exception {
34352c0eacSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
35352c0eacSLiu Zhe 		xText = xTextDocument.getText();
36352c0eacSLiu Zhe 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
37352c0eacSLiu Zhe 				+ "and we all love our home very much!!!");
38352c0eacSLiu Zhe 		// create text cursor for selecting and formatting text
39352c0eacSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
40352c0eacSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
41352c0eacSLiu Zhe 		xTextCursor.gotoStart(false);
42352c0eacSLiu Zhe 		xTextCursor.goRight((short) 102, true);
43352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharEscapement", (short)29);
44352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharEscapementHeight", (byte)50);
45352c0eacSLiu Zhe 		//save to odt
46352c0eacSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
47352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
48352c0eacSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
49352c0eacSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
50352c0eacSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
51352c0eacSLiu Zhe 		aStoreProperties_odt[0].Value = true;
52352c0eacSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
53352c0eacSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
54352c0eacSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
55352c0eacSLiu Zhe 		//save to doc
56352c0eacSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
57352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
58352c0eacSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
59352c0eacSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
60352c0eacSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
61352c0eacSLiu Zhe 		aStoreProperties_doc[0].Value = true;
62352c0eacSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
63352c0eacSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
64352c0eacSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
65352c0eacSLiu Zhe 		app.closeDocument(xTextDocument);
66352c0eacSLiu Zhe 
67352c0eacSLiu Zhe 		//reopen the document and assert character position setting
68352c0eacSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
69352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
70352c0eacSLiu Zhe 		//verify set property
71352c0eacSLiu Zhe 		assertEquals("assert character position",(short)29,xCursorProps_assert_odt.getPropertyValue("CharEscapement"));
72352c0eacSLiu Zhe 		assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
73352c0eacSLiu Zhe 
74352c0eacSLiu Zhe 		//reopen the document and assert character position setting
75352c0eacSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
76352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
77352c0eacSLiu Zhe 		//verify set property
78352c0eacSLiu Zhe 		assertEquals("assert character position",(short)29,xCursorProps_assert_doc.getPropertyValue("CharEscapement"));
79352c0eacSLiu Zhe 		assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
80352c0eacSLiu Zhe 	}
81932de486SLiu Zhe 	@Test@Ignore("Bug #120674 - [testUNO patch]the lower and relative font size value of subscript change when save to doc.")
82352c0eacSLiu Zhe 	public void testCharacterSubscriptSetting() throws Exception {
83352c0eacSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
84352c0eacSLiu Zhe 		xText = xTextDocument.getText();
85352c0eacSLiu Zhe 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
86352c0eacSLiu Zhe 				+ "and we all love our home very much!!!");
87352c0eacSLiu Zhe 		// create text cursor for selecting and formatting text
88352c0eacSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
89352c0eacSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
90352c0eacSLiu Zhe 		xTextCursor.gotoStart(false);
91352c0eacSLiu Zhe 		xTextCursor.goRight((short) 102, true);
92352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharEscapement", (short)-29);
93352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharEscapementHeight", (byte)50);
94352c0eacSLiu Zhe 		//save to odt
95352c0eacSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
96352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
97352c0eacSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
98352c0eacSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
99352c0eacSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
100352c0eacSLiu Zhe 		aStoreProperties_odt[0].Value = true;
101352c0eacSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
102352c0eacSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
103352c0eacSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
104352c0eacSLiu Zhe 		//save to doc
105352c0eacSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
106352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
107352c0eacSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
108352c0eacSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
109352c0eacSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
110352c0eacSLiu Zhe 		aStoreProperties_doc[0].Value = true;
111352c0eacSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
112352c0eacSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
113352c0eacSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
114352c0eacSLiu Zhe 		app.closeDocument(xTextDocument);
115352c0eacSLiu Zhe 
116352c0eacSLiu Zhe 		//reopen the document and assert character position setting
117352c0eacSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
118352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
119352c0eacSLiu Zhe 		//verify set property
120352c0eacSLiu Zhe 		assertEquals("assert character position",(short)-29,xCursorProps_assert_odt.getPropertyValue("CharEscapement"));
121352c0eacSLiu Zhe 		assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
122352c0eacSLiu Zhe 
123352c0eacSLiu Zhe 		//reopen the document and assert character position setting
124352c0eacSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
125352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
126352c0eacSLiu Zhe 		//verify set property
127352c0eacSLiu Zhe 		assertEquals("assert character position",(short)-29,xCursorProps_assert_doc.getPropertyValue("CharEscapement"));
128352c0eacSLiu Zhe 		assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
129352c0eacSLiu Zhe 	}
130352c0eacSLiu Zhe 	@Test
131352c0eacSLiu Zhe 	public void testCharacterDefaultPositionSetting() throws Exception {
132352c0eacSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
133352c0eacSLiu Zhe 		xText = xTextDocument.getText();
134352c0eacSLiu Zhe 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
135352c0eacSLiu Zhe 				+ "and we all love our home very much!!!");
136352c0eacSLiu Zhe 		// create text cursor for selecting and formatting text
137352c0eacSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
138352c0eacSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
139352c0eacSLiu Zhe 		xTextCursor.gotoStart(false);
140352c0eacSLiu Zhe 		xTextCursor.goRight((short) 102, true);
141352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharEscapement", (short)0);
142352c0eacSLiu Zhe 		xCursorProps.setPropertyValue("CharEscapementHeight", (byte)100);
143352c0eacSLiu Zhe 		//save to odt
144352c0eacSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
145352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
146352c0eacSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
147352c0eacSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
148352c0eacSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
149352c0eacSLiu Zhe 		aStoreProperties_odt[0].Value = true;
150352c0eacSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
151352c0eacSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
152352c0eacSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
153352c0eacSLiu Zhe 		//save to doc
154352c0eacSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
155352c0eacSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
156352c0eacSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
157352c0eacSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
158352c0eacSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
159352c0eacSLiu Zhe 		aStoreProperties_doc[0].Value = true;
160352c0eacSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
161352c0eacSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
162352c0eacSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
163352c0eacSLiu Zhe 		app.closeDocument(xTextDocument);
164352c0eacSLiu Zhe 
165352c0eacSLiu Zhe 		//reopen the document and assert character position setting
166352c0eacSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
167352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
168352c0eacSLiu Zhe 		//verify set property
169352c0eacSLiu Zhe 		assertEquals("assert character position",(short)0,xCursorProps_assert_odt.getPropertyValue("CharEscapement"));
170352c0eacSLiu Zhe 		assertEquals("assert character position",(byte)100,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
171352c0eacSLiu Zhe 
172352c0eacSLiu Zhe 		//reopen the document and assert character position setting
173352c0eacSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
174352c0eacSLiu Zhe 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
175352c0eacSLiu Zhe 		//verify set property
176352c0eacSLiu Zhe 		assertEquals("assert character position",(short)0,xCursorProps_assert_doc.getPropertyValue("CharEscapement"));
177352c0eacSLiu Zhe 		assertEquals("assert character position",(byte)100,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
178352c0eacSLiu Zhe 	}
179352c0eacSLiu Zhe }
180