1 package fvt.uno.sw.paragraph;
2 
3 import static org.junit.Assert.*;
4 
5 import org.junit.After;
6 import org.junit.Before;
7 import org.junit.Test;
8 import org.openoffice.test.common.FileUtil;
9 import org.openoffice.test.common.Testspace;
10 import org.openoffice.test.uno.UnoApp;
11 import com.sun.star.text.*;
12 import com.sun.star.beans.*;
13 import com.sun.star.frame.XStorable;
14 import com.sun.star.uno.UnoRuntime;
15 
16 public class ParagraphTexttoTextAlignment {
17 	private static final UnoApp app = new UnoApp();
18 	XText xText = null;
19 
20 	@Before
21 	public void setUp() throws Exception {
22 		app.start();
23 
24 	}
25 
26 	@After
27 	public void tearDown() throws Exception {
28 		app.close();
29 	}
30 	/*
31 	 * test paragraph background color
32 	 * 1.new a text document
33 	 * 2.insert some text
34 	 * 3.set paragraph text to text alignment
35 	 * 4.save and close the document
36 	 * 5.reload the saved document and check the paragraph text to text alignment
37 	 */
38 	@Test
39 	public void testTexttoTextAlignment_Baseline() throws Exception {
40 
41 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
42 		xText = xTextDocument.getText();
43 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
44 				"Hello,world!Hello,world!");
45 		// create text cursor for selecting and formatting text
46 		XTextCursor xTextCursor = xText.createTextCursor();
47 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
48 		xCursorProps.setPropertyValue("ParaVertAlignment",ParagraphVertAlign.BASELINE);
49 		//save to odt
50 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
51 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
52 		aStoreProperties_odt[0] = new PropertyValue();
53 		aStoreProperties_odt[1] = new PropertyValue();
54 		aStoreProperties_odt[0].Name = "Override";
55 		aStoreProperties_odt[0].Value = true;
56 		aStoreProperties_odt[1].Name = "FilterName";
57 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
58 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
59 		//save to doc
60 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
61 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
62 		aStoreProperties_doc[0] = new PropertyValue();
63 		aStoreProperties_doc[1] = new PropertyValue();
64 		aStoreProperties_doc[0].Name = "Override";
65 		aStoreProperties_doc[0].Value = true;
66 		aStoreProperties_doc[1].Name = "FilterName";
67 		aStoreProperties_doc[1].Value = "MS Word 97";
68 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
69 		app.closeDocument(xTextDocument);
70 
71 		//reopen the document
72 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
73 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
74 		//verify paragraph text to text alignment
75 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.BASELINE,xCursorProps_Assert_odt.getPropertyValue("ParaVertAlignment"));
76 
77 		//reopen the document
78 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
79 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
80 		//verify paragraph text to text alignment
81 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.BASELINE,xCursorProps_Assert_doc.getPropertyValue("ParaVertAlignment"));
82 	}
83 	@Test
84 	public void testTexttoTextAlignment_Bottom() throws Exception {
85 
86 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
87 		xText = xTextDocument.getText();
88 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
89 				"Hello,world!Hello,world!");
90 		// create text cursor for selecting and formatting text
91 		XTextCursor xTextCursor = xText.createTextCursor();
92 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
93 		xCursorProps.setPropertyValue("ParaVertAlignment",ParagraphVertAlign.BOTTOM);
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
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 paragraph text to text alignment
120 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.BOTTOM,xCursorProps_Assert_odt.getPropertyValue("ParaVertAlignment"));
121 
122 		//reopen the document
123 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
124 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
125 		//verify paragraph text to text alignment
126 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.BOTTOM,xCursorProps_Assert_doc.getPropertyValue("ParaVertAlignment"));
127 	}
128 	@Test
129 	public void testTexttoTextAlignment_Center() throws Exception {
130 
131 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
132 		xText = xTextDocument.getText();
133 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
134 				"Hello,world!Hello,world!");
135 		// create text cursor for selecting and formatting text
136 		XTextCursor xTextCursor = xText.createTextCursor();
137 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
138 		xCursorProps.setPropertyValue("ParaVertAlignment",ParagraphVertAlign.CENTER);
139 		//save to odt
140 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
141 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
142 		aStoreProperties_odt[0] = new PropertyValue();
143 		aStoreProperties_odt[1] = new PropertyValue();
144 		aStoreProperties_odt[0].Name = "Override";
145 		aStoreProperties_odt[0].Value = true;
146 		aStoreProperties_odt[1].Name = "FilterName";
147 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
148 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
149 		//save to doc
150 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
151 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
152 		aStoreProperties_doc[0] = new PropertyValue();
153 		aStoreProperties_doc[1] = new PropertyValue();
154 		aStoreProperties_doc[0].Name = "Override";
155 		aStoreProperties_doc[0].Value = true;
156 		aStoreProperties_doc[1].Name = "FilterName";
157 		aStoreProperties_doc[1].Value = "MS Word 97";
158 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
159 		app.closeDocument(xTextDocument);
160 
161 		//reopen the document
162 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
163 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
164 		//verify paragraph text to text alignment
165 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.CENTER,xCursorProps_Assert_odt.getPropertyValue("ParaVertAlignment"));
166 
167 		//reopen the document
168 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
169 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
170 		//verify paragraph text to text alignment
171 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.CENTER,xCursorProps_Assert_doc.getPropertyValue("ParaVertAlignment"));
172 	}
173 	@Test
174 	public void testTexttoTextAlignment_Top() throws Exception {
175 
176 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
177 		xText = xTextDocument.getText();
178 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
179 				"Hello,world!Hello,world!");
180 		// create text cursor for selecting and formatting text
181 		XTextCursor xTextCursor = xText.createTextCursor();
182 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
183 		xCursorProps.setPropertyValue("ParaVertAlignment",ParagraphVertAlign.TOP);
184 		//save to odt
185 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
186 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
187 		aStoreProperties_odt[0] = new PropertyValue();
188 		aStoreProperties_odt[1] = new PropertyValue();
189 		aStoreProperties_odt[0].Name = "Override";
190 		aStoreProperties_odt[0].Value = true;
191 		aStoreProperties_odt[1].Name = "FilterName";
192 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
193 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
194 		//save to doc
195 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
196 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
197 		aStoreProperties_doc[0] = new PropertyValue();
198 		aStoreProperties_doc[1] = new PropertyValue();
199 		aStoreProperties_doc[0].Name = "Override";
200 		aStoreProperties_doc[0].Value = true;
201 		aStoreProperties_doc[1].Name = "FilterName";
202 		aStoreProperties_doc[1].Value = "MS Word 97";
203 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
204 		app.closeDocument(xTextDocument);
205 
206 		//reopen the document
207 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
208 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
209 		//verify paragraph text to text alignment
210 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.TOP,xCursorProps_Assert_odt.getPropertyValue("ParaVertAlignment"));
211 
212 		//reopen the document
213 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
214 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
215 		//verify paragraph text to text alignment
216 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.TOP,xCursorProps_Assert_doc.getPropertyValue("ParaVertAlignment"));
217 	}
218 	@Test
219 	public void testTexttoTextAlignment_Automatic() throws Exception {
220 
221 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
222 		xText = xTextDocument.getText();
223 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
224 				"Hello,world!Hello,world!");
225 		// create text cursor for selecting and formatting text
226 		XTextCursor xTextCursor = xText.createTextCursor();
227 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
228 		xCursorProps.setPropertyValue("ParaVertAlignment",ParagraphVertAlign.AUTOMATIC);
229 		//save to odt
230 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
231 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
232 		aStoreProperties_odt[0] = new PropertyValue();
233 		aStoreProperties_odt[1] = new PropertyValue();
234 		aStoreProperties_odt[0].Name = "Override";
235 		aStoreProperties_odt[0].Value = true;
236 		aStoreProperties_odt[1].Name = "FilterName";
237 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
238 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
239 		//save to doc
240 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
241 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
242 		aStoreProperties_doc[0] = new PropertyValue();
243 		aStoreProperties_doc[1] = new PropertyValue();
244 		aStoreProperties_doc[0].Name = "Override";
245 		aStoreProperties_doc[0].Value = true;
246 		aStoreProperties_doc[1].Name = "FilterName";
247 		aStoreProperties_doc[1].Value = "MS Word 97";
248 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
249 		app.closeDocument(xTextDocument);
250 
251 		//reopen the document
252 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
253 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
254 		//verify paragraph text to text alignment
255 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.AUTOMATIC,xCursorProps_Assert_odt.getPropertyValue("ParaVertAlignment"));
256 
257 		//reopen the document
258 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
259 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
260 		//verify paragraph text to text alignment
261 		assertEquals("assert paragraph text to text alignment",ParagraphVertAlign.AUTOMATIC,xCursorProps_Assert_doc.getPropertyValue("ParaVertAlignment"));
262 	}
263 }
264