1*07d7dbdcSHerbert Dürr /**************************************************************
2*07d7dbdcSHerbert Dürr *
3*07d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one
4*07d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file
5*07d7dbdcSHerbert Dürr * distributed with this work for additional information
6*07d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file
7*07d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the
8*07d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance
9*07d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at
10*07d7dbdcSHerbert Dürr *
11*07d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0
12*07d7dbdcSHerbert Dürr *
13*07d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing,
14*07d7dbdcSHerbert Dürr * software distributed under the License is distributed on an
15*07d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*07d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the
17*07d7dbdcSHerbert Dürr * specific language governing permissions and limitations
18*07d7dbdcSHerbert Dürr * under the License.
19*07d7dbdcSHerbert Dürr *
20*07d7dbdcSHerbert Dürr *************************************************************/
216fbc0818SLiu Zhe
22eba4d44aSLiu Zhe package fvt.uno.sc.rowcolumn;
236fbc0818SLiu Zhe
246fbc0818SLiu Zhe import static org.junit.Assert.*;
256fbc0818SLiu Zhe
266fbc0818SLiu Zhe import org.junit.After;
276fbc0818SLiu Zhe import org.junit.Before;
286fbc0818SLiu Zhe import org.junit.Test;
296fbc0818SLiu Zhe
306fbc0818SLiu Zhe import org.openoffice.test.uno.UnoApp;
316fbc0818SLiu Zhe
326fbc0818SLiu Zhe
336fbc0818SLiu Zhe import com.sun.star.lang.XComponent;
346fbc0818SLiu Zhe import com.sun.star.sheet.XSpreadsheet;
356fbc0818SLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
366fbc0818SLiu Zhe import com.sun.star.sheet.XSpreadsheets;
376fbc0818SLiu Zhe import com.sun.star.table.XCell;
386fbc0818SLiu Zhe import com.sun.star.uno.UnoRuntime;
396fbc0818SLiu Zhe import com.sun.star.table.XTableColumns;
406fbc0818SLiu Zhe import com.sun.star.table.XTableRows;
416fbc0818SLiu Zhe import com.sun.star.table.XColumnRowRange;
426fbc0818SLiu Zhe
436fbc0818SLiu Zhe /**
446fbc0818SLiu Zhe * Test insert or delete rows and columns
456fbc0818SLiu Zhe * @author test
466fbc0818SLiu Zhe *
476fbc0818SLiu Zhe */
486fbc0818SLiu Zhe
496fbc0818SLiu Zhe public class InsertDeleteRowAndColumn {
506fbc0818SLiu Zhe
516fbc0818SLiu Zhe UnoApp unoApp = new UnoApp();
526fbc0818SLiu Zhe XSpreadsheetDocument scDocument = null;
536fbc0818SLiu Zhe XComponent scComponent = null;
546fbc0818SLiu Zhe
556fbc0818SLiu Zhe @Before
setUp()566fbc0818SLiu Zhe public void setUp() throws Exception {
576fbc0818SLiu Zhe unoApp.start();
586fbc0818SLiu Zhe }
596fbc0818SLiu Zhe
606fbc0818SLiu Zhe @After
tearDown()616fbc0818SLiu Zhe public void tearDown() throws Exception {
626fbc0818SLiu Zhe unoApp.closeDocument(scComponent);
636fbc0818SLiu Zhe unoApp.close();
646fbc0818SLiu Zhe }
656fbc0818SLiu Zhe
666fbc0818SLiu Zhe @Test
testInsertDeleteRows()676fbc0818SLiu Zhe public void testInsertDeleteRows() throws Exception {
686fbc0818SLiu Zhe
696fbc0818SLiu Zhe String sheetname = "sheet1";
706fbc0818SLiu Zhe scComponent = unoApp.newDocument("scalc");
716fbc0818SLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent);
726fbc0818SLiu Zhe XSpreadsheets spreadsheets = scDocument.getSheets();
736fbc0818SLiu Zhe Object sheetObj = spreadsheets.getByName(sheetname);
746fbc0818SLiu Zhe
756fbc0818SLiu Zhe
766fbc0818SLiu Zhe XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
776fbc0818SLiu Zhe XColumnRowRange xCRRange = (XColumnRowRange) UnoRuntime.queryInterface( XColumnRowRange.class, sheet );
786fbc0818SLiu Zhe XTableRows xRows = xCRRange.getRows();
796fbc0818SLiu Zhe
806fbc0818SLiu Zhe // Create a cell series "A2:A8" with the values 1 ... 7.
816fbc0818SLiu Zhe int nRow = 1;
826fbc0818SLiu Zhe for (int i = 1; i < 8; ++i) {
836fbc0818SLiu Zhe sheet.getCellByPosition( 0, nRow ).setValue( nRow );
846fbc0818SLiu Zhe nRow += 1;
856fbc0818SLiu Zhe }
866fbc0818SLiu Zhe
876fbc0818SLiu Zhe //Insert a row between row 2 and row 3
886fbc0818SLiu Zhe xRows.insertByIndex( 2, 1 );
896fbc0818SLiu Zhe
906fbc0818SLiu Zhe //Get value of cell A3
916fbc0818SLiu Zhe XCell cell = sheet.getCellByPosition(0, 2);
926fbc0818SLiu Zhe double checkvalue = 0.0;
936fbc0818SLiu Zhe
946fbc0818SLiu Zhe //Verify after insert row
956fbc0818SLiu Zhe assertEquals("Verify one new row inserted after Row 2",checkvalue, cell.getValue(),0);
966fbc0818SLiu Zhe
976fbc0818SLiu Zhe //Delete the row 3 and row 4
986fbc0818SLiu Zhe xRows.removeByIndex( 2, 2 );
996fbc0818SLiu Zhe
1006fbc0818SLiu Zhe //Get value of cell A3 and A4
1016fbc0818SLiu Zhe XCell cellA3 = sheet.getCellByPosition(0, 2);
1026fbc0818SLiu Zhe XCell cellA4 = sheet.getCellByPosition(0, 3);
1036fbc0818SLiu Zhe double checkvalueA3 = 3.0;
1046fbc0818SLiu Zhe double checkvalueA4 = 4.0;
1056fbc0818SLiu Zhe
1066fbc0818SLiu Zhe //Verify after delete row3 and row4
1076fbc0818SLiu Zhe assertEquals("Verify tow rows deleted the value of row 3",checkvalueA3, cellA3.getValue(),0);
1086fbc0818SLiu Zhe assertEquals("Verify tow rows deleted the value of row 4",checkvalueA4, cellA4.getValue(),0);
1096fbc0818SLiu Zhe
1106fbc0818SLiu Zhe }
1116fbc0818SLiu Zhe
1126fbc0818SLiu Zhe @Test
testInsertDeleteColumns()1136fbc0818SLiu Zhe public void testInsertDeleteColumns() throws Exception {
1146fbc0818SLiu Zhe
1156fbc0818SLiu Zhe String sheetname = "sheet1";
1166fbc0818SLiu Zhe scComponent = unoApp.newDocument("scalc");
1176fbc0818SLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent);
1186fbc0818SLiu Zhe XSpreadsheets spreadsheets = scDocument.getSheets();
1196fbc0818SLiu Zhe Object sheetObj = spreadsheets.getByName(sheetname);
1206fbc0818SLiu Zhe
1216fbc0818SLiu Zhe
1226fbc0818SLiu Zhe XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
1236fbc0818SLiu Zhe XColumnRowRange xCRRange = (XColumnRowRange) UnoRuntime.queryInterface( XColumnRowRange.class, sheet );
1246fbc0818SLiu Zhe XTableColumns xColumns = xCRRange.getColumns();
1256fbc0818SLiu Zhe
1266fbc0818SLiu Zhe // Create a cell series "A2:A8" with the values 1 ... 7.
1276fbc0818SLiu Zhe int nRow = 1;
1286fbc0818SLiu Zhe for (int i = 1; i < 8; ++i) {
1296fbc0818SLiu Zhe sheet.getCellByPosition( 1, nRow ).setValue( nRow );
1306fbc0818SLiu Zhe nRow += 1;
1316fbc0818SLiu Zhe }
1326fbc0818SLiu Zhe
1336fbc0818SLiu Zhe //Insert a row between row 2 and row 3
1346fbc0818SLiu Zhe xColumns.insertByIndex( 0, 1 );
1356fbc0818SLiu Zhe
1366fbc0818SLiu Zhe //Get value of cell C2
1376fbc0818SLiu Zhe XCell cell = sheet.getCellByPosition(2, 1);
1386fbc0818SLiu Zhe double checkvalue = 1.0;
1396fbc0818SLiu Zhe
1406fbc0818SLiu Zhe //Verify after insert row
1416fbc0818SLiu Zhe assertEquals("Verify if one new column inserted after Column A",checkvalue, cell.getValue(),0);
1426fbc0818SLiu Zhe
1436fbc0818SLiu Zhe //Delete the row 3 and row 4
1446fbc0818SLiu Zhe xColumns.removeByIndex( 0, 1 );
1456fbc0818SLiu Zhe
1466fbc0818SLiu Zhe //Get value of cell A3 and A4
1476fbc0818SLiu Zhe XCell cellA3 = sheet.getCellByPosition(1, 2);
1486fbc0818SLiu Zhe XCell cellA4 = sheet.getCellByPosition(1, 3);
1496fbc0818SLiu Zhe double checkvalueA3 = 2.0;
1506fbc0818SLiu Zhe double checkvalueA4 = 3.0;
1516fbc0818SLiu Zhe
1526fbc0818SLiu Zhe //Verify after delete row3 and row4
1536fbc0818SLiu Zhe assertEquals("Verify after tow rows deleted, the value of A3",checkvalueA3, cellA3.getValue(),0);
1546fbc0818SLiu Zhe assertEquals("Verify after tow rows deleted, the value of A4",checkvalueA4, cellA4.getValue(),0);
1556fbc0818SLiu Zhe
1566fbc0818SLiu Zhe }
1576fbc0818SLiu Zhe
1586fbc0818SLiu Zhe }
1596fbc0818SLiu Zhe
160