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 import com.sun.star.text.*; 34 import com.sun.star.beans.*; 35 import com.sun.star.frame.XStorable; 36 import com.sun.star.uno.UnoRuntime; 37 38 public class ParagraphAlignment { 39 private static final UnoApp app = new UnoApp(); 40 XText xText = null; 41 42 @Before setUp()43 public void setUp() throws Exception { 44 app.start(); 45 46 } 47 48 @After tearDown()49 public void tearDown() throws Exception { 50 app.close(); 51 } 52 /* 53 * test paragraph alignment is justified 54 * 1.new a text document 55 * 2.insert some text 56 * 3.set paragraph alignment is justified,and last line align to left,check expand single word 57 * 4.save and close the document 58 * 5.reload the saved document and check the paragraph alignment 59 */ 60 @Test@Ignore("Bug #120636 - [testUNO patch]the expand single word option disable when save to doc") testParagraphAlignmentJustified()61 public void testParagraphAlignmentJustified() throws Exception { 62 63 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 64 xText = xTextDocument.getText(); 65 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!" + 66 "Hello,world!Hello,world!"); 67 // create text cursor for selecting and formatting text 68 XTextCursor xTextCursor = xText.createTextCursor(); 69 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 70 //apply paragraph alignment as justified and last line alignment 71 xTextCursor.gotoStart(false); 72 xTextCursor.goRight((short)180 , true); 73 xCursorProps.setPropertyValue("ParaAdjust",com.sun.star.style.ParagraphAdjust.BLOCK); 74 xCursorProps.setPropertyValue("ParaLastLineAdjust", com.sun.star.style.ParagraphAdjust.LEFT); 75 xCursorProps.setPropertyValue("ParaExpandSingleWord", true); 76 //save to odt 77 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 78 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 79 aStoreProperties_odt[0] = new PropertyValue(); 80 aStoreProperties_odt[1] = new PropertyValue(); 81 aStoreProperties_odt[0].Name = "Override"; 82 aStoreProperties_odt[0].Value = true; 83 aStoreProperties_odt[1].Name = "FilterName"; 84 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 85 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 86 //save to doc 87 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 88 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 89 aStoreProperties_doc[0] = new PropertyValue(); 90 aStoreProperties_doc[1] = new PropertyValue(); 91 aStoreProperties_doc[0].Name = "Override"; 92 aStoreProperties_doc[0].Value = true; 93 aStoreProperties_doc[1].Name = "FilterName"; 94 aStoreProperties_doc[1].Value = "MS Word 97"; 95 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 96 app.closeDocument(xTextDocument); 97 98 //reopen the document and assert table margin to page setting 99 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 100 XTextCursor xTextCursor_assert_odt = assertDocument_odt.getText().createTextCursor(); 101 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt); 102 //verify paragraph alignment property 103 assertEquals("assert first paragraph alignment is justified",(short)2,xCursorProps_assert_odt.getPropertyValue("ParaAdjust")); 104 assertEquals("assert first paragraph last line alignment is left",(short)0, xCursorProps_assert_odt.getPropertyValue("ParaLastLineAdjust")); 105 assertEquals("assert expand single word is true",true,xCursorProps_assert_odt.getPropertyValue("ParaExpandSingleWord")); 106 107 //reopen the document and assert table margin to page setting 108 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 109 XTextCursor xTextCursor_assert_doc = assertDocument_doc.getText().createTextCursor(); 110 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc); 111 //verify paragraph alignment property 112 assertEquals("assert first paragraph alignment is justified",(short)2,xCursorProps_assert_doc.getPropertyValue("ParaAdjust")); 113 assertEquals("assert first paragraph last line alignment is left",(short)0, xCursorProps_assert_doc.getPropertyValue("ParaLastLineAdjust")); 114 assertEquals("assert expand single word is true",true,xCursorProps_assert_doc.getPropertyValue("ParaExpandSingleWord")); 115 116 } 117 /* 118 * test paragraph alignment is left 119 * 1.new a text document 120 * 2.insert some text 121 * 3.set paragraph alignment is left 122 * 4.save and close the document 123 * 5.reload the saved document and check the paragraph alignment 124 */ 125 @Test testParagraphAlignmentLeft()126 public void testParagraphAlignmentLeft() throws Exception { 127 128 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 129 xText = xTextDocument.getText(); 130 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!" + 131 "Hello,world!Hello,world!"); 132 // create text cursor for selecting and formatting text 133 XTextCursor xTextCursor = xText.createTextCursor(); 134 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 135 xTextCursor.gotoStart(false); 136 xTextCursor.goRight((short)180 , true); 137 xCursorProps.setPropertyValue("ParaAdjust",com.sun.star.style.ParagraphAdjust.LEFT); 138 //save to odt 139 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 140 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 141 aStoreProperties_odt[0] = new PropertyValue(); 142 aStoreProperties_odt[1] = new PropertyValue(); 143 aStoreProperties_odt[0].Name = "Override"; 144 aStoreProperties_odt[0].Value = true; 145 aStoreProperties_odt[1].Name = "FilterName"; 146 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 147 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 148 //save to doc 149 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 150 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 151 aStoreProperties_doc[0] = new PropertyValue(); 152 aStoreProperties_doc[1] = new PropertyValue(); 153 aStoreProperties_doc[0].Name = "Override"; 154 aStoreProperties_doc[0].Value = true; 155 aStoreProperties_doc[1].Name = "FilterName"; 156 aStoreProperties_doc[1].Value = "MS Word 97"; 157 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 158 159 app.closeDocument(xTextDocument); 160 161 //reopen the odt document and assert paragraph alignment 162 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 163 XTextCursor xTextCursor_assert_odt = assertDocument_odt.getText().createTextCursor(); 164 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt); 165 //verify paragraph alignment property 166 assertEquals("assert first paragraph alignment is left",(short)0,xCursorProps_assert_odt.getPropertyValue("ParaAdjust")); 167 //reopen the doc document and assert paragraph alignment 168 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 169 XTextCursor xTextCursor_assert_doc = assertDocument_doc.getText().createTextCursor(); 170 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc); 171 //verify paragraph alignment property 172 assertEquals("assert first paragraph alignment is left",(short)0,xCursorProps_assert_doc.getPropertyValue("ParaAdjust")); 173 174 175 } 176 /* 177 * test paragraph alignment is justified 178 * 1.new a text document 179 * 2.insert some text 180 * 3.set paragraph alignment is right 181 * 4.save and close the document 182 * 5.reload the saved document and check the paragraph alignment 183 */ 184 @Test testParagraphAlignmentRight()185 public void testParagraphAlignmentRight() throws Exception { 186 187 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 188 xText = xTextDocument.getText(); 189 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!" + 190 "Hello,world!Hello,world!"); 191 // create text cursor for selecting and formatting text 192 XTextCursor xTextCursor = xText.createTextCursor(); 193 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 194 //apply paragraph alignment as justified and last line alignment 195 xTextCursor.gotoStart(false); 196 xTextCursor.goRight((short)180 , true); 197 xCursorProps.setPropertyValue("ParaAdjust",com.sun.star.style.ParagraphAdjust.RIGHT); 198 //save to odt 199 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 200 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 201 aStoreProperties_odt[0] = new PropertyValue(); 202 aStoreProperties_odt[1] = new PropertyValue(); 203 aStoreProperties_odt[0].Name = "Override"; 204 aStoreProperties_odt[0].Value = true; 205 aStoreProperties_odt[1].Name = "FilterName"; 206 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 207 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 208 //save to doc 209 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 210 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 211 aStoreProperties_doc[0] = new PropertyValue(); 212 aStoreProperties_doc[1] = new PropertyValue(); 213 aStoreProperties_doc[0].Name = "Override"; 214 aStoreProperties_doc[0].Value = true; 215 aStoreProperties_doc[1].Name = "FilterName"; 216 aStoreProperties_doc[1].Value = "MS Word 97"; 217 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 218 app.closeDocument(xTextDocument); 219 220 //reopen the document and assert paragraph alignment 221 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 222 XTextCursor xTextCursor_assert_odt = assertDocument_odt.getText().createTextCursor(); 223 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt); 224 //verify paragraph alignment property 225 assertEquals("assert first paragraph alignment is right",(short)1,xCursorProps_assert_odt.getPropertyValue("ParaAdjust")); 226 //reopen the document and assert paragraph alignment 227 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 228 XTextCursor xTextCursor_assert_doc = assertDocument_doc.getText().createTextCursor(); 229 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc); 230 //verify paragraph alignment property 231 assertEquals("assert first paragraph alignment is right",(short)1,xCursorProps_assert_doc.getPropertyValue("ParaAdjust")); 232 } 233 /* 234 * test paragraph alignment is justified 235 * 1.new a text document 236 * 2.insert some text 237 * 3.set paragraph alignment is center 238 * 4.save and close the document 239 * 5.reload the saved document and check the paragraph alignment 240 */ 241 @Test testParagraphAlignmentCenter()242 public void testParagraphAlignmentCenter() throws Exception { 243 244 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 245 xText = xTextDocument.getText(); 246 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!" + 247 "Hello,world!Hello,world!"); 248 // create text cursor for selecting and formatting text 249 XTextCursor xTextCursor = xText.createTextCursor(); 250 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 251 //apply paragraph alignment as justified and last line alignment 252 xTextCursor.gotoStart(false); 253 xTextCursor.goRight((short)180 , true); 254 xCursorProps.setPropertyValue("ParaAdjust",com.sun.star.style.ParagraphAdjust.CENTER); 255 //save to odt 256 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 257 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 258 aStoreProperties_odt[0] = new PropertyValue(); 259 aStoreProperties_odt[1] = new PropertyValue(); 260 aStoreProperties_odt[0].Name = "Override"; 261 aStoreProperties_odt[0].Value = true; 262 aStoreProperties_odt[1].Name = "FilterName"; 263 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 264 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 265 //save to doc 266 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 267 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 268 aStoreProperties_doc[0] = new PropertyValue(); 269 aStoreProperties_doc[1] = new PropertyValue(); 270 aStoreProperties_doc[0].Name = "Override"; 271 aStoreProperties_doc[0].Value = true; 272 aStoreProperties_doc[1].Name = "FilterName"; 273 aStoreProperties_doc[1].Value = "MS Word 97"; 274 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 275 276 app.closeDocument(xTextDocument); 277 278 //reopen the document and assert paragraph alignment 279 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 280 XTextCursor xTextCursor_assert_odt = assertDocument_odt.getText().createTextCursor(); 281 XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_odt); 282 assertEquals("assert first paragraph alignment is center",(short)3,xCursorProps_assert_odt.getPropertyValue("ParaAdjust")); 283 //reopen the document and assert paragraph alignment 284 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 285 XTextCursor xTextCursor_assert_doc = assertDocument_doc.getText().createTextCursor(); 286 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc); 287 assertEquals("assert first paragraph alignment is center",(short)3,xCursorProps_assert_doc.getPropertyValue("ParaAdjust")); 288 } 289 } 290