1 package testcase.uno.sc.rowcolumn; 2 3 import static org.junit.Assert.*; 4 import static testlib.uno.SCUtil.*; 5 6 import org.junit.After; 7 import org.junit.Before; 8 import org.junit.Test; 9 import org.openoffice.test.uno.UnoApp; 10 11 import com.sun.star.lang.XComponent; 12 import com.sun.star.sheet.XSpreadsheet; 13 import com.sun.star.sheet.XSpreadsheetDocument; 14 import com.sun.star.sheet.XSpreadsheets; 15 import com.sun.star.uno.UnoRuntime; 16 import com.sun.star.table.XTableColumns; 17 import com.sun.star.table.XTableRows; 18 import com.sun.star.table.XColumnRowRange; 19 import com.sun.star.beans.XPropertySet; 20 import com.sun.star.table.XCellRange; 21 import com.sun.star.frame.XModel; 22 import com.sun.star.frame.XController; 23 import com.sun.star.sheet.XSpreadsheetView; 24 25 26 public class ResizeHideShowRowColumn { 27 28 UnoApp unoApp = new UnoApp(); 29 XSpreadsheetDocument scDocument = null; 30 XComponent scComponent = null; 31 32 @Before 33 public void setUp() throws Exception { 34 unoApp.start(); 35 } 36 37 @After 38 public void tearDown() throws Exception { 39 unoApp.closeDocument(scComponent); 40 unoApp.close(); 41 } 42 43 @Test 44 public void testResizeColumn() throws Exception { 45 String sheetname = "AddTest"; 46 XPropertySet PropSet = null; 47 48 //Create Spreadsheet file. 49 scComponent = unoApp.newDocument("scalc"); 50 scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); 51 52 //Create a sheet at the first place. 53 XSpreadsheets spreadsheets = scDocument.getSheets(); 54 spreadsheets.insertNewByName(sheetname, (short) 0); 55 Object sheetObj = spreadsheets.getByName(sheetname); 56 57 XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 58 59 //Active the new sheet. 60 XModel scModel = (XModel) UnoRuntime.queryInterface(XModel.class, scDocument); 61 XController scController = scModel.getCurrentController(); 62 XSpreadsheetView sheetview = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, scController); 63 sheetview.setActiveSheet(sheet); 64 65 //Set cell range to A1:B1 66 XCellRange CellRange = sheet.getCellRangeByPosition(0, 0, 1, 0); 67 68 //Get column A1 by index 69 XColumnRowRange ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); 70 XTableColumns Columns = ColRowRange.getColumns(); 71 Object aColumnObj = Columns.getByIndex( 0 ); 72 73 PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aColumnObj); 74 75 //Verify the default values of specified column A1 76 assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible")); 77 78 //Resize width of column A1 to "6001" 79 PropSet.setPropertyValue( "Width", new Integer( 6001 )); 80 81 //Save and reload document 82 saveFileAs(scComponent, "TestColumn", "ods"); 83 XSpreadsheetDocument TempSCDocument = reloadFile(unoApp, scDocument, "TestColumn.ods"); 84 scDocument = TempSCDocument; 85 86 spreadsheets = scDocument.getSheets(); 87 sheetObj = spreadsheets.getByName(sheetname); 88 sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 89 90 //Set cell range to A1:B1 91 CellRange = sheet.getCellRangeByPosition(0, 0, 1, 0); 92 ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); 93 Columns = ColRowRange.getColumns(); 94 95 //Get column A1 by index 96 aColumnObj = Columns.getByIndex( 0 ); 97 98 PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aColumnObj); 99 100 //Verify the values of specified column A1 after resize 101 int expectedWidth = 6001; 102 103 assertEquals("Verify current width value is 6001.", expectedWidth, PropSet.getPropertyValue("Width")); 104 assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible")); 105 106 //Set column is invisible 107 PropSet.setPropertyValue("IsVisible", new Boolean(false)); 108 109 //Save and reload document 110 //Save the modified spreadsheet first 111 save(TempSCDocument); 112 //close it and reload it 113 TempSCDocument = reloadFile(unoApp, scDocument, "TestColumn.ods"); 114 scDocument = TempSCDocument; 115 116 spreadsheets = scDocument.getSheets(); 117 sheetObj = spreadsheets.getByName(sheetname); 118 sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 119 120 //Set cell range to A1:B1 121 CellRange = sheet.getCellRangeByPosition(0, 0, 1, 0); 122 ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); 123 Columns = ColRowRange.getColumns(); 124 125 //Get column A1 by index 126 aColumnObj = Columns.getByIndex( 0 ); 127 128 PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aColumnObj); 129 130 //Verify the values of specified column A1 after save 131 assertFalse("Verify column A1 is invisible", (Boolean) PropSet.getPropertyValue("IsVisible")); 132 assertEquals("Verify current width value is 6001 after hide it.", expectedWidth, PropSet.getPropertyValue("Width")); 133 } 134 135 @Test 136 public void testResizeRow() throws Exception { 137 String sheetname = "AddTest"; 138 XPropertySet PropSet = null; 139 140 //Create Spreadsheet file. 141 scComponent = unoApp.newDocument("scalc"); 142 scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); 143 144 //Create a sheet at the first place. 145 XSpreadsheets spreadsheets = scDocument.getSheets(); 146 spreadsheets.insertNewByName(sheetname, (short) 0); 147 Object sheetObj = spreadsheets.getByName(sheetname); 148 XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 149 150 //Active the new sheet. 151 XModel scModel = (XModel) UnoRuntime.queryInterface(XModel.class, scDocument); 152 XController scController = scModel.getCurrentController(); 153 XSpreadsheetView sheetview = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, scController); 154 sheetview.setActiveSheet(sheet); 155 156 //Set cell range to A1:A2 157 XCellRange CellRange = sheet.getCellRangeByPosition(0, 0, 0, 1); 158 //XCell cell = sheet.getCellByPosition(1, 0); 159 XColumnRowRange ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); 160 XTableRows Rows = ColRowRange.getRows(); 161 162 //Get Row 1 by index 163 Object aRowObj = Rows.getByIndex( 0 ); 164 165 PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj ); 166 167 //Verify the default values of specified Row 1 168 assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible")); 169 170 //Resize Height of Row 1 to "5001" 171 PropSet.setPropertyValue( "Height", new Integer( 5001 ) ); 172 173 // Save and reload document 174 saveFileAs(scComponent, "TestRow", "xls"); 175 XSpreadsheetDocument TempSCDocument = reloadFile(unoApp, scDocument, "TestRow.xls"); 176 scDocument = TempSCDocument; 177 178 spreadsheets = scDocument.getSheets(); 179 sheetObj = spreadsheets.getByName(sheetname); 180 sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 181 182 //Set cell range to A1:A2 183 CellRange = sheet.getCellRangeByPosition(0, 0, 0, 1); 184 ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); 185 Rows = ColRowRange.getRows(); 186 187 //Get Row 1 by index 188 aRowObj = Rows.getByIndex( 0 ); 189 190 PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 191 192 //Verify the values of specified Row 1 after resize 193 int expectedHeight = 5001; 194 195 assertEquals("Verify current width value is 5001.", expectedHeight, PropSet.getPropertyValue("Height")); 196 assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible")); 197 198 //Set Row is invisible 199 PropSet.setPropertyValue("IsVisible", new Boolean(false)); 200 201 //Save and reload document 202 //Save the modified spreadsheet first 203 save(TempSCDocument); 204 //Close and reload it 205 TempSCDocument = reloadFile(unoApp, scDocument, "TestRow.xls"); 206 scDocument = TempSCDocument; 207 208 spreadsheets = scDocument.getSheets(); 209 sheetObj = spreadsheets.getByName(sheetname); 210 sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 211 212 //Set cell range to A1:A2 213 CellRange = sheet.getCellRangeByPosition(0, 0, 0, 1); 214 ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange ); 215 Rows = ColRowRange.getRows(); 216 217 //Get Row 1 by index 218 aRowObj = Rows.getByIndex( 0 ); 219 220 PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 221 222 //Verify the values of specified Row 1 after resize 223 assertEquals("Verify current height value is 5001 after hide it.", expectedHeight, PropSet.getPropertyValue("Height")); 224 assertFalse("Verify column is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible")); 225 226 } 227 228 } 229 230 231