1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski package fvt.uno.sw.table; 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski import static org.junit.Assert.*; 25*b1cdbd2cSJim Jagielski 26*b1cdbd2cSJim Jagielski import org.junit.After; 27*b1cdbd2cSJim Jagielski import org.junit.Before; 28*b1cdbd2cSJim Jagielski import org.junit.Ignore; 29*b1cdbd2cSJim Jagielski import org.junit.Test; 30*b1cdbd2cSJim Jagielski import org.openoffice.test.common.FileUtil; 31*b1cdbd2cSJim Jagielski import org.openoffice.test.common.Testspace; 32*b1cdbd2cSJim Jagielski import org.openoffice.test.uno.UnoApp; 33*b1cdbd2cSJim Jagielski 34*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 35*b1cdbd2cSJim Jagielski import com.sun.star.text.*; 36*b1cdbd2cSJim Jagielski import com.sun.star.lang.XMultiServiceFactory; 37*b1cdbd2cSJim Jagielski import com.sun.star.beans.PropertyValue; 38*b1cdbd2cSJim Jagielski import com.sun.star.container.XIndexAccess; 39*b1cdbd2cSJim Jagielski import com.sun.star.container.XNamed; 40*b1cdbd2cSJim Jagielski import com.sun.star.frame.XStorable; 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski 43*b1cdbd2cSJim Jagielski public class TableName { 44*b1cdbd2cSJim Jagielski 45*b1cdbd2cSJim Jagielski private static final UnoApp app = new UnoApp(); 46*b1cdbd2cSJim Jagielski private XTextDocument xTextDocument=null; 47*b1cdbd2cSJim Jagielski private XMultiServiceFactory xWriterFactory=null; 48*b1cdbd2cSJim Jagielski private XText xText=null; 49*b1cdbd2cSJim Jagielski @Before setUp()50*b1cdbd2cSJim Jagielski public void setUp() throws Exception { 51*b1cdbd2cSJim Jagielski app.start(); 52*b1cdbd2cSJim Jagielski } 53*b1cdbd2cSJim Jagielski 54*b1cdbd2cSJim Jagielski @After tearDown()55*b1cdbd2cSJim Jagielski public void tearDown() throws Exception { 56*b1cdbd2cSJim Jagielski app.close(); 57*b1cdbd2cSJim Jagielski } 58*b1cdbd2cSJim Jagielski /* 59*b1cdbd2cSJim Jagielski * test table border spacing to content 60*b1cdbd2cSJim Jagielski * 1.new a text document and create a table 61*b1cdbd2cSJim Jagielski * 2.set table name 62*b1cdbd2cSJim Jagielski * 3.save to odt/doc,close it and reopen new saved document 63*b1cdbd2cSJim Jagielski * 4.check the table name 64*b1cdbd2cSJim Jagielski */ 65*b1cdbd2cSJim Jagielski @Test@Ignore("Bug #120739 - [testUNO patch]the table name change to default name when save to doc.") testtableName()66*b1cdbd2cSJim Jagielski public void testtableName() throws Exception { 67*b1cdbd2cSJim Jagielski xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter")); 68*b1cdbd2cSJim Jagielski xText=xTextDocument.getText(); 69*b1cdbd2cSJim Jagielski XTextCursor xTextCursor = xText.createTextCursor(); 70*b1cdbd2cSJim Jagielski // get internal service factory of the document 71*b1cdbd2cSJim Jagielski xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument); 72*b1cdbd2cSJim Jagielski // Create a new table from the document's factory 73*b1cdbd2cSJim Jagielski XTextTable xTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, xWriterFactory.createInstance("com.sun.star.text.TextTable")); 74*b1cdbd2cSJim Jagielski xText.insertTextContent(xTextCursor,xTable,false); 75*b1cdbd2cSJim Jagielski XNamed tableName=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable); 76*b1cdbd2cSJim Jagielski assertEquals("assert default table name","Table1",tableName.getName()); 77*b1cdbd2cSJim Jagielski tableName.setName("test_TableExample"); 78*b1cdbd2cSJim Jagielski //save to odt 79*b1cdbd2cSJim Jagielski XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 80*b1cdbd2cSJim Jagielski PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 81*b1cdbd2cSJim Jagielski aStoreProperties_odt[0] = new PropertyValue(); 82*b1cdbd2cSJim Jagielski aStoreProperties_odt[1] = new PropertyValue(); 83*b1cdbd2cSJim Jagielski aStoreProperties_odt[0].Name = "Override"; 84*b1cdbd2cSJim Jagielski aStoreProperties_odt[0].Value = true; 85*b1cdbd2cSJim Jagielski aStoreProperties_odt[1].Name = "FilterName"; 86*b1cdbd2cSJim Jagielski aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 87*b1cdbd2cSJim Jagielski xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 88*b1cdbd2cSJim Jagielski //save to doc 89*b1cdbd2cSJim Jagielski XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 90*b1cdbd2cSJim Jagielski PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 91*b1cdbd2cSJim Jagielski aStoreProperties_doc[0] = new PropertyValue(); 92*b1cdbd2cSJim Jagielski aStoreProperties_doc[1] = new PropertyValue(); 93*b1cdbd2cSJim Jagielski aStoreProperties_doc[0].Name = "Override"; 94*b1cdbd2cSJim Jagielski aStoreProperties_doc[0].Value = true; 95*b1cdbd2cSJim Jagielski aStoreProperties_doc[1].Name = "FilterName"; 96*b1cdbd2cSJim Jagielski aStoreProperties_doc[1].Value = "MS Word 97"; 97*b1cdbd2cSJim Jagielski xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 98*b1cdbd2cSJim Jagielski app.closeDocument(xTextDocument); 99*b1cdbd2cSJim Jagielski 100*b1cdbd2cSJim Jagielski //reopen the odt document and assert table border spacing to content 101*b1cdbd2cSJim Jagielski XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 102*b1cdbd2cSJim Jagielski XTextTablesSupplier xTablesSupplier_odt = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_odt ); 103*b1cdbd2cSJim Jagielski XIndexAccess xIndexedTables_odt = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_odt.getTextTables()); 104*b1cdbd2cSJim Jagielski Object xTable_obj_odt=xIndexedTables_odt.getByIndex(0); 105*b1cdbd2cSJim Jagielski XTextTable xTable_Assert_odt=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_odt); 106*b1cdbd2cSJim Jagielski XNamed tableName_odt=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_odt); 107*b1cdbd2cSJim Jagielski assertEquals("assert default table name","test_TableExample",tableName_odt.getName()); 108*b1cdbd2cSJim Jagielski 109*b1cdbd2cSJim Jagielski //reopen the doc document and assert table border spacing to content 110*b1cdbd2cSJim Jagielski XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 111*b1cdbd2cSJim Jagielski XTextTablesSupplier xTablesSupplier_doc = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, assertDocument_doc ); 112*b1cdbd2cSJim Jagielski XIndexAccess xIndexedTables_doc = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTablesSupplier_doc.getTextTables()); 113*b1cdbd2cSJim Jagielski Object xTable_obj_doc=xIndexedTables_doc.getByIndex(0); 114*b1cdbd2cSJim Jagielski XTextTable xTable_Assert_doc=(XTextTable) UnoRuntime.queryInterface(XTextTable.class, xTable_obj_doc); 115*b1cdbd2cSJim Jagielski XNamed tableName_doc=(XNamed)UnoRuntime.queryInterface(XNamed.class, xTable_Assert_doc); 116*b1cdbd2cSJim Jagielski assertEquals("assert default table name","test_TableExample",tableName_doc.getName()); 117*b1cdbd2cSJim Jagielski 118*b1cdbd2cSJim Jagielski } 119*b1cdbd2cSJim Jagielski } 120*b1cdbd2cSJim Jagielski 121