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.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 
13 import com.sun.star.style.TabAlign;
14 import com.sun.star.style.TabStop;
15 import com.sun.star.text.*;
16 import com.sun.star.beans.*;
17 import com.sun.star.frame.XStorable;
18 import com.sun.star.uno.UnoRuntime;
19 
20 public class ParagraphTabs {
21 	private static final UnoApp app = new UnoApp();
22 	XText xText = null;
23 
24 	@Before
25 	public void setUp() throws Exception {
26 		app.start();
27 
28 	}
29 
30 	@After
31 	public void tearDown() throws Exception {
32 		app.close();
33 	}
34 	@Test
35 	public void ParagraphTabs_Center() throws Exception {
36 
37 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
38 		xText = xTextDocument.getText();
39 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!");
40 		// create text cursor for selecting and formatting text
41 		XTextCursor xTextCursor = xText.createTextCursor();
42 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
43 		//paraTabStops.
44 		TabStop[] tabStop=new TabStop[1];
45 		tabStop[0]=new TabStop();
46 		tabStop[0].Position=5001;
47 		tabStop[0].Alignment=TabAlign.CENTER;
48 		tabStop[0].FillChar='_';
49 		//set paragraph tab stops
50 		xCursorProps.setPropertyValue("ParaTabStops",tabStop);
51 		//save to odt
52 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
53 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
54 		aStoreProperties_odt[0] = new PropertyValue();
55 		aStoreProperties_odt[1] = new PropertyValue();
56 		aStoreProperties_odt[0].Name = "Override";
57 		aStoreProperties_odt[0].Value = true;
58 		aStoreProperties_odt[1].Name = "FilterName";
59 		aStoreProperties_odt[1].Value = "writer8";
60 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
61 		//save to doc
62 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
63 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
64 		aStoreProperties_doc[0] = new PropertyValue();
65 		aStoreProperties_doc[1] = new PropertyValue();
66 		aStoreProperties_doc[0].Name = "Override";
67 		aStoreProperties_doc[0].Value = true;
68 		aStoreProperties_doc[1].Name = "FilterName";
69 		aStoreProperties_doc[1].Value = "MS Word 97";
70 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
71 		app.closeDocument(xTextDocument);
72 
73 		//reopen the document
74 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
75 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
76 		Object paraTabs_obj_odt=xCursorProps_Assert_odt.getPropertyValue("ParaTabStops");
77 		TabStop[] paraTabs_assert_odt=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, paraTabs_obj_odt);
78 		//verify paragraph tabs
79 		assertEquals("assert paragraph tab setting",TabAlign.CENTER,paraTabs_assert_odt[0].Alignment);
80 		assertEquals("assert paragraph tab setting",'_',paraTabs_assert_odt[0].FillChar);
81 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_odt[0].Position);
82 
83 		//reopen the document
84 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
85 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
86 		TabStop[] paraTabs_assert_doc=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, xCursorProps_Assert_doc.getPropertyValue("ParaTabStops"));
87 		//verify paragraph tabs
88 		assertEquals("assert paragraph tab setting",TabAlign.CENTER,paraTabs_assert_doc[0].Alignment);
89 		assertEquals("assert paragraph tab setting",'_',paraTabs_assert_doc[0].FillChar);
90 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_doc[0].Position);
91 	}
92 	@Test
93 	public void ParagraphTabs_Left() throws Exception {
94 
95 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
96 		xText = xTextDocument.getText();
97 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!");
98 		// create text cursor for selecting and formatting text
99 		XTextCursor xTextCursor = xText.createTextCursor();
100 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
101 		//paraTabStops.
102 		TabStop[] tabStop=new TabStop[1];
103 		tabStop[0]=new TabStop();
104 		tabStop[0].Position=5001;
105 		tabStop[0].Alignment=TabAlign.LEFT;
106 		tabStop[0].FillChar='.';
107 		//set paragraph tab stops
108 		xCursorProps.setPropertyValue("ParaTabStops",tabStop);
109 		//save to odt
110 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
111 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
112 		aStoreProperties_odt[0] = new PropertyValue();
113 		aStoreProperties_odt[1] = new PropertyValue();
114 		aStoreProperties_odt[0].Name = "Override";
115 		aStoreProperties_odt[0].Value = true;
116 		aStoreProperties_odt[1].Name = "FilterName";
117 		aStoreProperties_odt[1].Value = "writer8";
118 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
119 		//save to doc
120 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
121 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
122 		aStoreProperties_doc[0] = new PropertyValue();
123 		aStoreProperties_doc[1] = new PropertyValue();
124 		aStoreProperties_doc[0].Name = "Override";
125 		aStoreProperties_doc[0].Value = true;
126 		aStoreProperties_doc[1].Name = "FilterName";
127 		aStoreProperties_doc[1].Value = "MS Word 97";
128 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
129 		app.closeDocument(xTextDocument);
130 
131 		//reopen the document
132 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
133 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
134 		Object paraTabs_obj_odt=xCursorProps_Assert_odt.getPropertyValue("ParaTabStops");
135 		TabStop[] paraTabs_assert_odt=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, paraTabs_obj_odt);
136 		//verify paragraph tabs
137 		assertEquals("assert paragraph tab setting",TabAlign.LEFT,paraTabs_assert_odt[0].Alignment);
138 		assertEquals("assert paragraph tab setting",'.',paraTabs_assert_odt[0].FillChar);
139 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_odt[0].Position);
140 
141 		//reopen the document
142 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
143 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
144 		TabStop[] paraTabs_assert_doc=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, xCursorProps_Assert_doc.getPropertyValue("ParaTabStops"));
145 		//verify paragraph tabs
146 		assertEquals("assert paragraph tab setting",TabAlign.LEFT,paraTabs_assert_doc[0].Alignment);
147 		assertEquals("assert paragraph tab setting",'.',paraTabs_assert_doc[0].FillChar);
148 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_doc[0].Position);
149 	}
150 	@Test
151 	public void ParagraphTabs_Right() throws Exception {
152 
153 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
154 		xText = xTextDocument.getText();
155 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!");
156 		// create text cursor for selecting and formatting text
157 		XTextCursor xTextCursor = xText.createTextCursor();
158 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
159 		//paraTabStops.
160 		TabStop[] tabStop=new TabStop[1];
161 		tabStop[0]=new TabStop();
162 		tabStop[0].Position=5001;
163 		tabStop[0].Alignment=TabAlign.RIGHT;
164 		tabStop[0].FillChar='-';
165 		//set paragraph tab stops
166 		xCursorProps.setPropertyValue("ParaTabStops",tabStop);
167 		//save to odt
168 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
169 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
170 		aStoreProperties_odt[0] = new PropertyValue();
171 		aStoreProperties_odt[1] = new PropertyValue();
172 		aStoreProperties_odt[0].Name = "Override";
173 		aStoreProperties_odt[0].Value = true;
174 		aStoreProperties_odt[1].Name = "FilterName";
175 		aStoreProperties_odt[1].Value = "writer8";
176 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
177 		//save to doc
178 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
179 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
180 		aStoreProperties_doc[0] = new PropertyValue();
181 		aStoreProperties_doc[1] = new PropertyValue();
182 		aStoreProperties_doc[0].Name = "Override";
183 		aStoreProperties_doc[0].Value = true;
184 		aStoreProperties_doc[1].Name = "FilterName";
185 		aStoreProperties_doc[1].Value = "MS Word 97";
186 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
187 		app.closeDocument(xTextDocument);
188 
189 		//reopen the document
190 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
191 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
192 		Object paraTabs_obj_odt=xCursorProps_Assert_odt.getPropertyValue("ParaTabStops");
193 		TabStop[] paraTabs_assert_odt=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, paraTabs_obj_odt);
194 		//verify paragraph tabs
195 		assertEquals("assert paragraph tab setting",TabAlign.RIGHT,paraTabs_assert_odt[0].Alignment);
196 		assertEquals("assert paragraph tab setting",'-',paraTabs_assert_odt[0].FillChar);
197 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_odt[0].Position);
198 
199 		//reopen the document
200 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
201 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
202 		TabStop[] paraTabs_assert_doc=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, xCursorProps_Assert_doc.getPropertyValue("ParaTabStops"));
203 		//verify paragraph tabs
204 		assertEquals("assert paragraph tab setting",TabAlign.RIGHT,paraTabs_assert_doc[0].Alignment);
205 		assertEquals("assert paragraph tab setting",'-',paraTabs_assert_doc[0].FillChar);
206 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_doc[0].Position);
207 	}
208 	@Test
209 	public void ParagraphTabs_Decimal() throws Exception {
210 
211 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
212 		xText = xTextDocument.getText();
213 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!");
214 		// create text cursor for selecting and formatting text
215 		XTextCursor xTextCursor = xText.createTextCursor();
216 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
217 		//paraTabStops.
218 		TabStop[] tabStop=new TabStop[1];
219 		tabStop[0]=new TabStop();
220 		tabStop[0].Position=5001;
221 		tabStop[0].Alignment=TabAlign.DECIMAL;
222 		tabStop[0].DecimalChar='.';
223 		tabStop[0].FillChar='-';
224 		//set paragraph tab stops
225 		xCursorProps.setPropertyValue("ParaTabStops",tabStop);
226 		//save to odt
227 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
228 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
229 		aStoreProperties_odt[0] = new PropertyValue();
230 		aStoreProperties_odt[1] = new PropertyValue();
231 		aStoreProperties_odt[0].Name = "Override";
232 		aStoreProperties_odt[0].Value = true;
233 		aStoreProperties_odt[1].Name = "FilterName";
234 		aStoreProperties_odt[1].Value = "writer8";
235 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
236 		//save to doc
237 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
238 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
239 		aStoreProperties_doc[0] = new PropertyValue();
240 		aStoreProperties_doc[1] = new PropertyValue();
241 		aStoreProperties_doc[0].Name = "Override";
242 		aStoreProperties_doc[0].Value = true;
243 		aStoreProperties_doc[1].Name = "FilterName";
244 		aStoreProperties_doc[1].Value = "MS Word 97";
245 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
246 		app.closeDocument(xTextDocument);
247 
248 		//reopen the document
249 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
250 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
251 		Object paraTabs_obj_odt=xCursorProps_Assert_odt.getPropertyValue("ParaTabStops");
252 		TabStop[] paraTabs_assert_odt=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, paraTabs_obj_odt);
253 		//verify paragraph tabs
254 		assertEquals("assert paragraph tab setting",TabAlign.DECIMAL,paraTabs_assert_odt[0].Alignment);
255 		assertEquals("assert paragraph tab setting",'-',paraTabs_assert_odt[0].FillChar);
256 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_odt[0].Position);
257 		assertEquals("assert paragraph tab setting",'.',paraTabs_assert_odt[0].DecimalChar);
258 
259 		//reopen the document
260 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
261 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
262 		TabStop[] paraTabs_assert_doc=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, xCursorProps_Assert_doc.getPropertyValue("ParaTabStops"));
263 		//verify paragraph tabs
264 		assertEquals("assert paragraph tab setting",TabAlign.DECIMAL,paraTabs_assert_doc[0].Alignment);
265 		assertEquals("assert paragraph tab setting",'-',paraTabs_assert_doc[0].FillChar);
266 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_doc[0].Position);
267 		assertEquals("assert paragraph tab setting",'.',paraTabs_assert_doc[0].DecimalChar);
268 	}
269 	@Test@Ignore("Bug #120748 - [testUNO patch]the tabstops character of paragraph change to default when save to doc.")
270 	public void ParagraphTabs_Decimal_UserDefineCharacter() throws Exception {
271 
272 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
273 		xText = xTextDocument.getText();
274 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!");
275 		// create text cursor for selecting and formatting text
276 		XTextCursor xTextCursor = xText.createTextCursor();
277 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
278 		//paraTabStops.
279 		TabStop[] tabStop=new TabStop[1];
280 		tabStop[0]=new TabStop();
281 		tabStop[0].Position=5001;
282 		tabStop[0].Alignment=TabAlign.DECIMAL;
283 		tabStop[0].DecimalChar='@';
284 		tabStop[0].FillChar='%';
285 		//set paragraph tab stops
286 		xCursorProps.setPropertyValue("ParaTabStops",tabStop);
287 		//save to odt
288 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
289 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
290 		aStoreProperties_odt[0] = new PropertyValue();
291 		aStoreProperties_odt[1] = new PropertyValue();
292 		aStoreProperties_odt[0].Name = "Override";
293 		aStoreProperties_odt[0].Value = true;
294 		aStoreProperties_odt[1].Name = "FilterName";
295 		aStoreProperties_odt[1].Value = "writer8";
296 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
297 		//save to doc
298 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
299 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
300 		aStoreProperties_doc[0] = new PropertyValue();
301 		aStoreProperties_doc[1] = new PropertyValue();
302 		aStoreProperties_doc[0].Name = "Override";
303 		aStoreProperties_doc[0].Value = true;
304 		aStoreProperties_doc[1].Name = "FilterName";
305 		aStoreProperties_doc[1].Value = "MS Word 97";
306 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
307 		app.closeDocument(xTextDocument);
308 
309 		//reopen the document
310 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
311 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
312 		Object paraTabs_obj_odt=xCursorProps_Assert_odt.getPropertyValue("ParaTabStops");
313 		TabStop[] paraTabs_assert_odt=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, paraTabs_obj_odt);
314 		//verify paragraph tabs
315 		assertEquals("assert paragraph tab setting",TabAlign.DECIMAL,paraTabs_assert_odt[0].Alignment);
316 		assertEquals("assert paragraph tab setting",'%',paraTabs_assert_odt[0].FillChar);
317 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_odt[0].Position);
318 		assertEquals("assert paragraph tab setting",'@',paraTabs_assert_odt[0].DecimalChar);
319 
320 		//reopen the document
321 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
322 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
323 		TabStop[] paraTabs_assert_doc=(TabStop[]) UnoRuntime.queryInterface(TabStop[].class, xCursorProps_Assert_doc.getPropertyValue("ParaTabStops"));
324 		//verify paragraph tabs
325 		assertEquals("assert paragraph tab setting",TabAlign.DECIMAL,paraTabs_assert_doc[0].Alignment);
326 		assertEquals("assert paragraph tab setting",'%',paraTabs_assert_doc[0].FillChar);
327 		assertEquals("assert paragraph tab setting",5001,paraTabs_assert_doc[0].Position);
328 		assertEquals("assert paragraph tab setting",'@',paraTabs_assert_doc[0].DecimalChar);
329 	}
330 }
331