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.table; 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.uno.UnoRuntime; 35 import com.sun.star.text.*; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.beans.PropertyValue; 38 import com.sun.star.container.XIndexAccess; 39 import com.sun.star.container.XNamed; 40 import com.sun.star.frame.XStorable; 41 42 43 public class TableName { 44 45 private static final UnoApp app = new UnoApp(); 46 private XTextDocument xTextDocument=null; 47 private XMultiServiceFactory xWriterFactory=null; 48 private XText xText=null; 49 @Before setUp()50 public void setUp() throws Exception { 51 app.start(); 52 } 53 54 @After tearDown()55 public void tearDown() throws Exception { 56 app.close(); 57 } 58 /* 59 * test table border spacing to content 60 * 1.new a text document and create a table 61 * 2.set table name 62 * 3.save to odt/doc,close it and reopen new saved document 63 * 4.check the table name 64 */ 65 @Test@Ignore("Bug #120739 - [testUNO patch]the table name change to default name when save to doc.") testtableName()66 public void testtableName() throws Exception { 67 xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 68 xText=xTextDocument.getText(); 69 XTextCursor xTextCursor = xText.createTextCursor(); 70 // get internal service factory of the document 71 xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 72 // Create a new table from the document's factory 73 XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 74 xText.insertTextContent(xTextCursor,xTable,false); 75 XNamed tableName=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable); 76 assertEquals("assert default table name","Table1",tableName.getName()); 77 tableName.setName("test_TableExample"); 78 //save to odt 79 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 80 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 81 aStoreProperties_odt[0] = new PropertyValue(); 82 aStoreProperties_odt[1] = new PropertyValue(); 83 aStoreProperties_odt[0].Name = "Override"; 84 aStoreProperties_odt[0].Value = true; 85 aStoreProperties_odt[1].Name = "FilterName"; 86 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 87 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 88 //save to doc 89 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 90 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 91 aStoreProperties_doc[0] = new PropertyValue(); 92 aStoreProperties_doc[1] = new PropertyValue(); 93 aStoreProperties_doc[0].Name = "Override"; 94 aStoreProperties_doc[0].Value = true; 95 aStoreProperties_doc[1].Name = "FilterName"; 96 aStoreProperties_doc[1].Value = "MS Word 97"; 97 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 98 app.closeDocument(xTextDocument); 99 100 //reopen the odt document and assert table border spacing to content 101 XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 102 XTextTablesSupplier xTablesSupplier_odt = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_odt ); 103 XIndexAccess xIndexedTables_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_odt.getTextTables()); 104 Object xTable_obj_odt=xIndexedTables_odt.getByIndex(0); 105 XTextTable xTable_Assert_odt=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_odt); 106 XNamed tableName_odt=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_odt); 107 assertEquals("assert default table name","test_TableExample",tableName_odt.getName()); 108 109 //reopen the doc document and assert table border spacing to content 110 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 111 XTextTablesSupplier xTablesSupplier_doc = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_doc ); 112 XIndexAccess xIndexedTables_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_doc.getTextTables()); 113 Object xTable_obj_doc=xIndexedTables_doc.getByIndex(0); 114 XTextTable xTable_Assert_doc=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_doc); 115 XNamed tableName_doc=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_doc); 116 assertEquals("assert default table name","test_TableExample",tableName_doc.getName()); 117 118 } 119 } 120 121