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