Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657137 via svnmerge from

https://svn.apache.org:443/repos/asf/poi/trunk

........
  r657136 | josh | 2008-05-16 18:14:02 +0100 (Fri, 16 May 2008) | 1 line
  
  Should have been submitted with r656893 (for bug 44523)
........


git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@657138 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-05-16 17:17:59 +00:00
parent 8f9f5b0065
commit 4a3f50df56
1 changed files with 124 additions and 28 deletions

View File

@ -17,11 +17,16 @@
package org.apache.poi.hssf.usermodel;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.util.TempFile;
/**
*
*/
@ -105,8 +110,8 @@ public final class TestHSSFWorkbook extends TestCase {
public void testWindowOneDefaults() {
HSSFWorkbook b = new HSSFWorkbook( );
try {
assertEquals(b.getSelectedTab(), 0);
assertEquals(b.getDisplayedTab(), 0);
assertEquals(b.getActiveSheetIndex(), 0);
assertEquals(b.getFirstVisibleTab(), 0);
} catch (NullPointerException npe) {
fail("WindowOneRecord in Workbook is probably not initialized");
}
@ -116,10 +121,11 @@ public final class TestHSSFWorkbook extends TestCase {
HSSFWorkbook b = new HSSFWorkbook();
b.createSheet("Sheet One");
b.createSheet("Sheet Two");
b.setSelectedTab((short) 1);
b.setDisplayedTab((short) 1);
assertEquals(b.getSelectedTab(), 1);
assertEquals(b.getDisplayedTab(), 1);
b.setActiveSheet(1);
b.setSelectedTab(1);
b.setFirstVisibleTab(1);
assertEquals(1, b.getActiveSheetIndex());
assertEquals(1, b.getFirstVisibleTab());
}
public void testSheetClone() {
@ -207,4 +213,94 @@ public final class TestHSSFWorkbook extends TestCase {
private static HSSFWorkbook writeRead(HSSFWorkbook b) {
return HSSFTestDataSamples.writeOutAndReadBack(b);
}
public void testSelectedSheet_bug44523() {
HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFSheet sheet2 = wb.createSheet("Sheet2");
HSSFSheet sheet3 = wb.createSheet("Sheet3");
HSSFSheet sheet4 = wb.createSheet("Sheet4");
confirmActiveSelected(sheet1, true);
confirmActiveSelected(sheet2, false);
confirmActiveSelected(sheet3, false);
confirmActiveSelected(sheet4, false);
wb.setSelectedTab(1);
// Demonstrate bug 44525:
// Well... not quite, since isActive + isSelected were also added in the same bug fix
if (sheet1.isSelected()) {
throw new AssertionFailedError("Identified bug 44525 a");
}
wb.setActiveSheet(1);
if (sheet1.isActive()) {
throw new AssertionFailedError("Identified bug 44525 b");
}
confirmActiveSelected(sheet1, false);
confirmActiveSelected(sheet2, true);
confirmActiveSelected(sheet3, false);
confirmActiveSelected(sheet4, false);
}
public void testSelectMultiple() {
HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFSheet sheet2 = wb.createSheet("Sheet2");
HSSFSheet sheet3 = wb.createSheet("Sheet3");
HSSFSheet sheet4 = wb.createSheet("Sheet4");
HSSFSheet sheet5 = wb.createSheet("Sheet5");
HSSFSheet sheet6 = wb.createSheet("Sheet6");
wb.setSelectedTabs(new int[] { 0, 2, 3});
assertEquals(true, sheet1.isSelected());
assertEquals(false, sheet2.isSelected());
assertEquals(true, sheet3.isSelected());
assertEquals(true, sheet4.isSelected());
assertEquals(false, sheet5.isSelected());
assertEquals(false, sheet6.isSelected());
wb.setSelectedTabs(new int[] { 1, 3, 5});
assertEquals(false, sheet1.isSelected());
assertEquals(true, sheet2.isSelected());
assertEquals(false, sheet3.isSelected());
assertEquals(true, sheet4.isSelected());
assertEquals(false, sheet5.isSelected());
assertEquals(true, sheet6.isSelected());
assertEquals(true, sheet1.isActive());
assertEquals(false, sheet2.isActive());
assertEquals(true, sheet1.isActive());
assertEquals(false, sheet3.isActive());
wb.setActiveSheet(2);
assertEquals(false, sheet1.isActive());
assertEquals(true, sheet3.isActive());
if (false) { // helpful if viewing this workbook in excel:
sheet1.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet1"));
sheet2.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet2"));
sheet3.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet3"));
sheet4.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet4"));
try {
File fOut = TempFile.createTempFile("sheetMultiSelect", ".xls");
FileOutputStream os = new FileOutputStream(fOut);
wb.write(os);
os.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
private static void confirmActiveSelected(HSSFSheet sheet, boolean expected) {
assertEquals(expected, sheet.isActive());
assertEquals(expected, sheet.isSelected());
}
}