1 package testcase.uno.sw.puretext;
2 
3 import static org.junit.Assert.*;
4 
5 import org.junit.After;
6 import org.junit.Before;
7 import org.junit.Ignore;
8 import org.junit.Test;
9 import org.openoffice.test.common.FileUtil;
10 import org.openoffice.test.common.Testspace;
11 import org.openoffice.test.uno.UnoApp;
12 import com.sun.star.text.*;
13 import com.sun.star.beans.*;
14 import com.sun.star.frame.XStorable;
15 import com.sun.star.uno.UnoRuntime;
16 
17 public class CharacterPosition {
18 	private static final UnoApp app = new UnoApp();
19 	XText xText = null;
20 
21 	@Before
22 	public void setUp() throws Exception {
23 		app.start();
24 
25 	}
26 
27 	@After
28 	public void tearDown() throws Exception {
29 		app.close();
30 	}
31 
32 	@Test
33 	public void testCharacterSuperscriptSetting() throws Exception {
34 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
35 		xText = xTextDocument.getText();
36 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
37 				+ "and we all love our home very much!!!");
38 		// create text cursor for selecting and formatting text
39 		XTextCursor xTextCursor = xText.createTextCursor();
40 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
41 		xTextCursor.gotoStart(false);
42 		xTextCursor.goRight((short) 102, true);
43 		xCursorProps.setPropertyValue("CharEscapement", (short)29);
44 		xCursorProps.setPropertyValue("CharEscapementHeight", (byte)50);
45 		//save to odt
46 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
47 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
48 		aStoreProperties_odt[0] = new PropertyValue();
49 		aStoreProperties_odt[1] = new PropertyValue();
50 		aStoreProperties_odt[0].Name = "Override";
51 		aStoreProperties_odt[0].Value = true;
52 		aStoreProperties_odt[1].Name = "FilterName";
53 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
54 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
55 		//save to doc
56 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
57 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
58 		aStoreProperties_doc[0] = new PropertyValue();
59 		aStoreProperties_doc[1] = new PropertyValue();
60 		aStoreProperties_doc[0].Name = "Override";
61 		aStoreProperties_doc[0].Value = true;
62 		aStoreProperties_doc[1].Name = "FilterName";
63 		aStoreProperties_doc[1].Value = "MS Word 97";
64 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
65 		app.closeDocument(xTextDocument);
66 
67 		//reopen the document and assert character position setting
68 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
69 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
70 		//verify set property
71 		assertEquals("assert character position",(short)29,xCursorProps_assert_odt.getPropertyValue("CharEscapement"));
72 		assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
73 
74 		//reopen the document and assert character position setting
75 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
76 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
77 		//verify set property
78 		assertEquals("assert character position",(short)29,xCursorProps_assert_doc.getPropertyValue("CharEscapement"));
79 		assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
80 	}
81 	@Test@Ignore //bug120674_the lower and relative font size value of subscript change when save to doc.
82 	public void testCharacterSubscriptSetting() throws Exception {
83 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
84 		xText = xTextDocument.getText();
85 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
86 				+ "and we all love our home very much!!!");
87 		// create text cursor for selecting and formatting text
88 		XTextCursor xTextCursor = xText.createTextCursor();
89 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
90 		xTextCursor.gotoStart(false);
91 		xTextCursor.goRight((short) 102, true);
92 		xCursorProps.setPropertyValue("CharEscapement", (short)-29);
93 		xCursorProps.setPropertyValue("CharEscapementHeight", (byte)50);
94 		//save to odt
95 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
96 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
97 		aStoreProperties_odt[0] = new PropertyValue();
98 		aStoreProperties_odt[1] = new PropertyValue();
99 		aStoreProperties_odt[0].Name = "Override";
100 		aStoreProperties_odt[0].Value = true;
101 		aStoreProperties_odt[1].Name = "FilterName";
102 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
103 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
104 		//save to doc
105 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
106 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
107 		aStoreProperties_doc[0] = new PropertyValue();
108 		aStoreProperties_doc[1] = new PropertyValue();
109 		aStoreProperties_doc[0].Name = "Override";
110 		aStoreProperties_doc[0].Value = true;
111 		aStoreProperties_doc[1].Name = "FilterName";
112 		aStoreProperties_doc[1].Value = "MS Word 97";
113 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
114 		app.closeDocument(xTextDocument);
115 
116 		//reopen the document and assert character position setting
117 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
118 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
119 		//verify set property
120 		assertEquals("assert character position",(short)-29,xCursorProps_assert_odt.getPropertyValue("CharEscapement"));
121 		assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
122 
123 		//reopen the document and assert character position setting
124 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
125 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
126 		//verify set property
127 		assertEquals("assert character position",(short)-29,xCursorProps_assert_doc.getPropertyValue("CharEscapement"));
128 		assertEquals("assert character position",(byte)50,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
129 	}
130 	@Test
131 	public void testCharacterDefaultPositionSetting() throws Exception {
132 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
133 		xText = xTextDocument.getText();
134 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
135 				+ "and we all love our home very much!!!");
136 		// create text cursor for selecting and formatting text
137 		XTextCursor xTextCursor = xText.createTextCursor();
138 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
139 		xTextCursor.gotoStart(false);
140 		xTextCursor.goRight((short) 102, true);
141 		xCursorProps.setPropertyValue("CharEscapement", (short)0);
142 		xCursorProps.setPropertyValue("CharEscapementHeight", (byte)100);
143 		//save to odt
144 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
145 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
146 		aStoreProperties_odt[0] = new PropertyValue();
147 		aStoreProperties_odt[1] = new PropertyValue();
148 		aStoreProperties_odt[0].Name = "Override";
149 		aStoreProperties_odt[0].Value = true;
150 		aStoreProperties_odt[1].Name = "FilterName";
151 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
152 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
153 		//save to doc
154 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
155 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
156 		aStoreProperties_doc[0] = new PropertyValue();
157 		aStoreProperties_doc[1] = new PropertyValue();
158 		aStoreProperties_doc[0].Name = "Override";
159 		aStoreProperties_doc[0].Value = true;
160 		aStoreProperties_doc[1].Name = "FilterName";
161 		aStoreProperties_doc[1].Value = "MS Word 97";
162 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
163 		app.closeDocument(xTextDocument);
164 
165 		//reopen the document and assert character position setting
166 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
167 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
168 		//verify set property
169 		assertEquals("assert character position",(short)0,xCursorProps_assert_odt.getPropertyValue("CharEscapement"));
170 		assertEquals("assert character position",(byte)100,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
171 
172 		//reopen the document and assert character position setting
173 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
174 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
175 		//verify set property
176 		assertEquals("assert character position",(short)0,xCursorProps_assert_doc.getPropertyValue("CharEscapement"));
177 		assertEquals("assert character position",(byte)100,xCursorProps_assert_odt.getPropertyValue("CharEscapementHeight"));
178 	}
179 }
180