Return-Path: X-Original-To: apmail-incubator-ooo-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-ooo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 27F7ADDC3 for ; Fri, 31 Aug 2012 05:49:10 +0000 (UTC) Received: (qmail 28850 invoked by uid 500); 31 Aug 2012 05:49:08 -0000 Delivered-To: apmail-incubator-ooo-commits-archive@incubator.apache.org Received: (qmail 28807 invoked by uid 500); 31 Aug 2012 05:49:08 -0000 Mailing-List: contact ooo-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ooo-dev@incubator.apache.org Delivered-To: mailing list ooo-commits@incubator.apache.org Received: (qmail 28782 invoked by uid 99); 31 Aug 2012 05:49:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Aug 2012 05:49:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Aug 2012 05:49:05 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E7E3723888E3; Fri, 31 Aug 2012 05:48:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1379298 - /incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/rowcolumn/ResizeHideShowRowColumn.java Date: Fri, 31 Aug 2012 05:48:22 -0000 To: ooo-commits@incubator.apache.org From: liuzhe@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120831054822.E7E3723888E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: liuzhe Date: Fri Aug 31 05:48:22 2012 New Revision: 1379298 URL: http://svn.apache.org/viewvc?rev=1379298&view=rev Log: #120701 - [testuno] Resize/hide/show row and column in spreadsheet. Patch By: Guo Bin Review By: Liu Zhe Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/rowcolumn/ResizeHideShowRowColumn.java Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/rowcolumn/ResizeHideShowRowColumn.java URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/rowcolumn/ResizeHideShowRowColumn.java?rev=1379298&view=auto ============================================================================== --- incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/rowcolumn/ResizeHideShowRowColumn.java (added) +++ incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/rowcolumn/ResizeHideShowRowColumn.java Fri Aug 31 05:48:22 2012 @@ -0,0 +1,251 @@ +package testcase.uno.sc.rowcolumn; + +import static org.junit.Assert.*; +import static testlib.uno.SCUtil.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openoffice.test.uno.UnoApp; + +import com.sun.star.lang.XComponent; +import com.sun.star.sheet.XSpreadsheet; +import com.sun.star.sheet.XSpreadsheetDocument; +import com.sun.star.sheet.XSpreadsheets; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.table.XTableColumns; +import com.sun.star.table.XTableRows; +import com.sun.star.table.XColumnRowRange; +import com.sun.star.beans.XPropertySet; +import com.sun.star.table.XCellRange; +import com.sun.star.frame.XModel; +import com.sun.star.frame.XController; +import com.sun.star.frame.XStorable; +import com.sun.star.sheet.XSpreadsheetView; + + +public class ResizeHideShowRowColumn { + + UnoApp unoApp = new UnoApp(); + XSpreadsheetDocument scDocument = null; + XComponent scComponent = null; + + @Before + public void setUp() throws Exception { + unoApp.start(); + } + + @After + public void tearDown() throws Exception { + unoApp.closeDocument(scComponent); + unoApp.close(); + } + +@Test +public void testResizeColumn() throws Exception { + String sheetname = "AddTest"; + XPropertySet PropSet = null; + + //Create Spreadsheet file. + scComponent = unoApp.newDocument("scalc"); + scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); + + //Create a sheet at the first place. + XSpreadsheets spreadsheets = scDocument.getSheets(); + spreadsheets.insertNewByName(sheetname, (short) 0); + Object sheetObj = spreadsheets.getByName(sheetname); + + XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); + + //Active the new sheet. + XModel scModel = (XModel) UnoRuntime.queryInterface(XModel.class, scDocument); + XController scController = scModel.getCurrentController(); + XSpreadsheetView sheetview = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, scController); + sheetview.setActiveSheet(sheet); + + //Set cell range to A1:B1 + XCellRange CellRange = sheet.getCellRangeByPosition(0, 0, 1, 0); + + //Get column A1 by index + XColumnRowRange ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); + XTableColumns Columns = ColRowRange.getColumns(); + Object aColumnObj = Columns.getByIndex( 0 ); + + PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aColumnObj); + + //Verify the default values of specified column A1 + int expectedDefaultWidth = 2267; + + assertEquals("Verify default width value is 2267.", expectedDefaultWidth, PropSet.getPropertyValue("Width")); + assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible")); + + //Resize width of column A1 to "6001" + PropSet.setPropertyValue( "Width", new Integer( 6001 )); + + //Save and reload document + saveFileAs(scComponent, "TestColumn", "ods"); + XSpreadsheetDocument TempSCDocument = reloadFile(unoApp, scDocument, "TestColumn.ods"); + scDocument = TempSCDocument; + + spreadsheets = scDocument.getSheets(); + sheetObj = spreadsheets.getByName(sheetname); + sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); + + //Set cell range to A1:B1 + CellRange = sheet.getCellRangeByPosition(0, 0, 1, 0); + ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); + Columns = ColRowRange.getColumns(); + + //Get column A1 by index + aColumnObj = Columns.getByIndex( 0 ); + + PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aColumnObj); + + //Verify the values of specified column A1 after resize + int expectedWidth = 6001; + + assertEquals("Verify current width value is 6001.", expectedWidth, PropSet.getPropertyValue("Width")); + assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible")); + + //Set column is invisible + PropSet.setPropertyValue("IsVisible", new Boolean(false)); + + //Save and reload document + //Save the modified spreadsheet first + save(TempSCDocument); + //close it and reload it + TempSCDocument = reloadFile(unoApp, scDocument, "TestColumn.ods"); + scDocument = TempSCDocument; + + spreadsheets = scDocument.getSheets(); + sheetObj = spreadsheets.getByName(sheetname); + sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); + + //Set cell range to A1:B1 + CellRange = sheet.getCellRangeByPosition(0, 0, 1, 0); + ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); + Columns = ColRowRange.getColumns(); + + //Get column A1 by index + aColumnObj = Columns.getByIndex( 0 ); + + PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aColumnObj); + + //Verify the values of specified column A1 after save + assertFalse("Verify column A1 is invisible", (Boolean) PropSet.getPropertyValue("IsVisible")); + assertEquals("Verify current width value is 6001 after hide it.", expectedWidth, PropSet.getPropertyValue("Width")); + } + +@Test +public void testResizeRow() throws Exception { + String sheetname = "AddTest"; + XPropertySet PropSet = null; + + //Create Spreadsheet file. + scComponent = unoApp.newDocument("scalc"); + scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); + + //Create a sheet at the first place. + XSpreadsheets spreadsheets = scDocument.getSheets(); + spreadsheets.insertNewByName(sheetname, (short) 0); + Object sheetObj = spreadsheets.getByName(sheetname); + XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); + + //Active the new sheet. + XModel scModel = (XModel) UnoRuntime.queryInterface(XModel.class, scDocument); + XController scController = scModel.getCurrentController(); + XSpreadsheetView sheetview = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, scController); + sheetview.setActiveSheet(sheet); + + //Set cell range to A1:A2 + XCellRange CellRange = sheet.getCellRangeByPosition(0, 0, 0, 1); + //XCell cell = sheet.getCellByPosition(1, 0); + XColumnRowRange ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); + XTableRows Rows = ColRowRange.getRows(); + + //Get Row 1 by index + Object aRowObj = Rows.getByIndex( 0 ); + + PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj ); + + //Verify the default values of specified Row 1 + int expectedDefaultHeight = 453; + + assertEquals("Verify default width value is 453.", expectedDefaultHeight, PropSet.getPropertyValue("Height")); + assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible")); + + //Resize Height of Row 1 to "5001" + PropSet.setPropertyValue( "Height", new Integer( 5001 ) ); + + // Save and reload document + saveFileAs(scComponent, "TestRow", "xls"); + XSpreadsheetDocument TempSCDocument = reloadFile(unoApp, scDocument, "TestRow.xls"); + scDocument = TempSCDocument; + + spreadsheets = scDocument.getSheets(); + sheetObj = spreadsheets.getByName(sheetname); + sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); + + //Set cell range to A1:A2 + CellRange = sheet.getCellRangeByPosition(0, 0, 0, 1); + ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); + Rows = ColRowRange.getRows(); + + //Get Row 1 by index + aRowObj = Rows.getByIndex( 0 ); + + PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); + + //Verify the values of specified Row 1 after resize + int expectedHeight = 5001; + + assertEquals("Verify current width value is 5001.", expectedHeight, PropSet.getPropertyValue("Height")); + assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible")); + + //Set Row is invisible + PropSet.setPropertyValue("IsVisible", new Boolean(false)); + + //Save and reload document + //Save the modified spreadsheet first + save(TempSCDocument); + //Close and reload it + TempSCDocument = reloadFile(unoApp, scDocument, "TestRow.xls"); + scDocument = TempSCDocument; + + spreadsheets = scDocument.getSheets(); + sheetObj = spreadsheets.getByName(sheetname); + sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); + + //Set cell range to A1:A2 + CellRange = sheet.getCellRangeByPosition(0, 0, 0, 1); + ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); + Rows = ColRowRange.getRows(); + + //Get Row 1 by index + aRowObj = Rows.getByIndex( 0 ); + + PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); + + //Verify the values of specified Row 1 after resize + assertEquals("Verify current width value is 5001 after hide it.", expectedHeight, PropSet.getPropertyValue("Height")); + assertFalse("Verify column is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible")); + + } + +/* Save file after open file. +* +* @param xSpreadsheetDocument +* @throws Exception +*/ +public static void save(XSpreadsheetDocument xSpreadsheetDocument) + throws Exception { + + XStorable scStorable = (XStorable) UnoRuntime.queryInterface( + XStorable.class, xSpreadsheetDocument); + scStorable.store(); + + } + +} + +