aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/usermodel
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2008-05-16 18:55:02 +0000
committerJosh Micich <josh@apache.org>2008-05-16 18:55:02 +0000
commitc2f389c43700d44ef95f8074f119f86f16bedc36 (patch)
tree1bc5047bc6bbedd62d7efd285d0669b3769b0aad /src/testcases/org/apache/poi/hssf/usermodel
parentf1f36fe6660e15a7debc64062938916f3ed29752 (diff)
downloadpoi-c2f389c43700d44ef95f8074f119f86f16bedc36.tar.gz
poi-c2f389c43700d44ef95f8074f119f86f16bedc36.zip
Fix for bug 40414 - update selected/active sheet after removing sheet from workbook
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@657167 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel')
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java77
1 files changed, 75 insertions, 2 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
index e1afb453bc..587e907925 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
@@ -299,8 +299,81 @@ public final class TestHSSFWorkbook extends TestCase {
}
}
+
+ public void testActiveSheetAfterDelete_bug40414() {
+ HSSFWorkbook wb=new HSSFWorkbook();
+ HSSFSheet sheet0 = wb.createSheet("Sheet0");
+ HSSFSheet sheet1 = wb.createSheet("Sheet1");
+ HSSFSheet sheet2 = wb.createSheet("Sheet2");
+ HSSFSheet sheet3 = wb.createSheet("Sheet3");
+ HSSFSheet sheet4 = wb.createSheet("Sheet4");
+
+ // confirm default activation/selection
+ confirmActiveSelected(sheet0, true);
+ confirmActiveSelected(sheet1, false);
+ confirmActiveSelected(sheet2, false);
+ confirmActiveSelected(sheet3, false);
+ confirmActiveSelected(sheet4, false);
+
+ wb.setActiveSheet(3);
+ wb.setSelectedTab(3);
+
+ confirmActiveSelected(sheet0, false);
+ confirmActiveSelected(sheet1, false);
+ confirmActiveSelected(sheet2, false);
+ confirmActiveSelected(sheet3, true);
+ confirmActiveSelected(sheet4, false);
+
+ wb.removeSheetAt(3);
+ // after removing the only active/selected sheet, another should be active/selected in its place
+ if (!sheet4.isSelected()) {
+ throw new AssertionFailedError("identified bug 40414 a");
+ }
+ if (!sheet4.isActive()) {
+ throw new AssertionFailedError("identified bug 40414 b");
+ }
+
+ confirmActiveSelected(sheet0, false);
+ confirmActiveSelected(sheet1, false);
+ confirmActiveSelected(sheet2, false);
+ confirmActiveSelected(sheet4, true);
+
+ sheet3 = sheet4; // re-align local vars in this test case
+
+ // Some more cases of removing sheets
+
+ // Starting with a multiple selection, and different active sheet
+ wb.setSelectedTabs(new int[] { 1, 3, });
+ wb.setActiveSheet(2);
+ confirmActiveSelected(sheet0, false, false);
+ confirmActiveSelected(sheet1, false, true);
+ confirmActiveSelected(sheet2, true, false);
+ confirmActiveSelected(sheet3, false, true);
+
+ // removing a sheet that is not active, and not the only selected sheet
+ wb.removeSheetAt(3);
+ confirmActiveSelected(sheet0, false, false);
+ confirmActiveSelected(sheet1, false, true);
+ confirmActiveSelected(sheet2, true, false);
+
+ // removing the only selected sheet
+ wb.removeSheetAt(1);
+ confirmActiveSelected(sheet0, false, false);
+ confirmActiveSelected(sheet2, true, true);
+
+ // The last remaining sheet should always be active+selected
+ wb.removeSheetAt(1);
+ confirmActiveSelected(sheet0, true, true);
+ }
+
private static void confirmActiveSelected(HSSFSheet sheet, boolean expected) {
- assertEquals(expected, sheet.isActive());
- assertEquals(expected, sheet.isSelected());
+ confirmActiveSelected(sheet, expected, expected);
+ }
+
+
+ private static void confirmActiveSelected(HSSFSheet sheet,
+ boolean expectedActive, boolean expectedSelected) {
+ assertEquals("active", expectedActive, sheet.isActive());
+ assertEquals("selected", expectedSelected, sheet.isSelected());
}
}