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.gui.sc.cell; 23 24 import static org.junit.Assert.*; 25 import static testlib.gui.AppTool.*; 26 import static testlib.gui.UIMap.*; 27 28 import org.junit.After; 29 import org.junit.Before; 30 import org.junit.Rule; 31 import org.junit.Test; 32 import org.openoffice.test.common.Logger; 33 34 import testlib.gui.SCTool; 35 36 /** 37 * Before running the testing class, you need specify the AOO location firstly 38 * with system property openoffice.home. 39 * 40 * 41 */ 42 43 public class InserCells { 44 45 @Rule 46 public Logger log = Logger.getLogger(this); 47 48 @Before 49 public void setUp() throws Exception { 50 app.start(); 51 app.dispatch("private:factory/scalc"); 52 calc.waitForExistence(10, 3); 53 } 54 55 @After 56 public void tearDown() throws Exception { 57 app.close(); 58 } 59 60 /** 61 * Shift row and column, insert entire row and column 62 * 63 * @throws Exception 64 */ 65 66 @Test 67 public void testShiftRowandColumn() { 68 69 // Input data to cell range A1:B2 70 SCTool.selectRange("A1"); 71 typeKeys("1<right>2<down><left>3<right>4"); 72 73 // Set expected result after executing shift cell down 74 String[][] expectedShiftCellDownResult = new String[][] { { "", "2" }, { "1", "4" }, { "3", "" }, }; 75 76 // Select Cell A1 77 SCTool.selectRange("Sheet1.A1"); 78 79 // Launch insert cells dialog via menu 80 calc.menuItem("Insert->Cells...").select(); 81 82 // Select the first option "shift cells down" from dialog 83 typeKeys("<enter>"); 84 85 // Verify results after shift one cell down 86 assertArrayEquals("Verify results after shift one cell down", expectedShiftCellDownResult, SCTool.getCellTexts("A1:B3")); 87 88 // Set expected result after executing shift cell right 89 String[][] expectedShiftCellRightResult = new String[][] { { "", "1", "2" }, { "3", "4", "" }, }; 90 91 // Undo 92 calc.menuItem("Edit->Undo: Insert").select(); 93 94 // Select cell B2 95 SCTool.selectRange("Sheet1.A1"); 96 97 // Launch insert cells dialog via menu 98 calc.menuItem("Insert->Cells...").select(); 99 100 // Select the second option "shift cells right" from dialog 101 typeKeys("<down>"); 102 typeKeys("<enter>"); 103 104 // Verify results after shift one cell right 105 assertArrayEquals("Verify results after shift one cell right", expectedShiftCellRightResult, SCTool.getCellTexts("A1:C2")); 106 107 // Set expected result after executing insert entire row 108 String[][] expectedEntireRowResult = new String[][] { { "", "" }, { "1", "2" }, { "3", "4" }, }; 109 110 // Undo 111 calc.menuItem("Edit->Undo: Insert").select(); 112 113 // Select Cell B2 114 SCTool.selectRange("Sheet1.A1"); 115 116 // Launch insert cells dialog via menu 117 calc.menuItem("Insert->Cells...").select(); 118 119 // Select the third option "Entire row" from dialog 120 typeKeys("<down>"); 121 typeKeys("<enter>"); 122 123 // Verify results after insert entire row 124 assertArrayEquals("Verify results after insert entire row", expectedEntireRowResult, SCTool.getCellTexts("A1:B3")); 125 126 // Set expected result after executing insert entire column 127 String[][] expectedEntireColumnResult = new String[][] { 128 129 { "", "1", "2" }, { "", "3", "4" }, }; 130 131 // Undo 132 calc.menuItem("Edit->Undo: Insert").select(); 133 134 // Select Cell A1 135 SCTool.selectRange("Sheet1.A1"); 136 137 // Launch insert cells dialog via menu 138 calc.menuItem("Insert->Cells...").select(); 139 140 // Select the fourth option "Entire column" from dialog 141 typeKeys("<down>"); 142 typeKeys("<enter>"); 143 144 // Verify the results after inserting entire column 145 assertArrayEquals("Verify the results after inserting entire column", expectedEntireColumnResult, SCTool.getCellTexts("A1:C2")); 146 147 } 148 149 } 150