Fix some IDE warnings, JavaDoc, ...

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1766063 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2016-10-21 16:31:37 +00:00
parent 359820ba80
commit 0610a20d87
7 changed files with 182 additions and 224 deletions

View File

@ -57,16 +57,16 @@ public enum HyperlinkType {
/** /**
* The codes don't have any real meaning. * The codes don't have any real meaning.
* There bytes that are read in and written out from HSSF, HSLF, XSSF, and XSLF are different * They are bytes that are read in and written out from HSSF, HSLF, XSSF, and XSLF are different
* that the codes here. * that the codes here.
* These codes only exist to assist in transitioning from using ints to enums. * These codes only exist to assist in transitioning from using ints to enums.
* *
* @param code * @param code The unique number for this type.
* @deprecated POI 3.15 beta 3 * @deprecated POI 3.15 beta 3
*/ */
@Internal(since="3.15 beta 3") @Internal(since="3.15 beta 3")
@Deprecated @Deprecated
private HyperlinkType(int code) { HyperlinkType(int code) {
this.code = code; this.code = code;
} }

View File

@ -43,6 +43,7 @@ public final class WindowOneRecord extends StandardRecord {
BitFieldFactory.getInstance(0x01); // is this window is hidden BitFieldFactory.getInstance(0x01); // is this window is hidden
static final private BitField iconic = static final private BitField iconic =
BitFieldFactory.getInstance(0x02); // is this window is an icon BitFieldFactory.getInstance(0x02); // is this window is an icon
@SuppressWarnings("unused")
static final private BitField reserved = BitFieldFactory.getInstance(0x04); // reserved static final private BitField reserved = BitFieldFactory.getInstance(0x04); // reserved
static final private BitField hscroll = static final private BitField hscroll =
BitFieldFactory.getInstance(0x08); // display horizontal scrollbar BitFieldFactory.getInstance(0x08); // display horizontal scrollbar
@ -353,41 +354,37 @@ public final class WindowOneRecord extends StandardRecord {
return field_9_tab_width_ratio; return field_9_tab_width_ratio;
} }
public String toString() public String toString() {
{ return "[WINDOW1]\n" +
StringBuffer buffer = new StringBuffer(); " .h_hold = " +
Integer.toHexString(getHorizontalHold()) + "\n" +
buffer.append("[WINDOW1]\n"); " .v_hold = " +
buffer.append(" .h_hold = ") Integer.toHexString(getVerticalHold()) + "\n" +
.append(Integer.toHexString(getHorizontalHold())).append("\n"); " .width = " +
buffer.append(" .v_hold = ") Integer.toHexString(getWidth()) + "\n" +
.append(Integer.toHexString(getVerticalHold())).append("\n"); " .height = " +
buffer.append(" .width = ") Integer.toHexString(getHeight()) + "\n" +
.append(Integer.toHexString(getWidth())).append("\n"); " .options = " +
buffer.append(" .height = ") Integer.toHexString(getOptions()) + "\n" +
.append(Integer.toHexString(getHeight())).append("\n"); " .hidden = " + getHidden() +
buffer.append(" .options = ") "\n" +
.append(Integer.toHexString(getOptions())).append("\n"); " .iconic = " + getIconic() +
buffer.append(" .hidden = ").append(getHidden()) "\n" +
.append("\n"); " .hscroll = " +
buffer.append(" .iconic = ").append(getIconic()) getDisplayHorizontalScrollbar() + "\n" +
.append("\n"); " .vscroll = " +
buffer.append(" .hscroll = ") getDisplayVerticalScrollbar() + "\n" +
.append(getDisplayHorizontalScrollbar()).append("\n"); " .tabs = " + getDisplayTabs() +
buffer.append(" .vscroll = ") "\n" +
.append(getDisplayVerticalScrollbar()).append("\n"); " .activeSheet = " +
buffer.append(" .tabs = ").append(getDisplayTabs()) Integer.toHexString(getActiveSheetIndex()) + "\n" +
.append("\n"); " .firstVisibleTab = " +
buffer.append(" .activeSheet = ") Integer.toHexString(getFirstVisibleTab()) + "\n" +
.append(Integer.toHexString(getActiveSheetIndex())).append("\n"); " .numselectedtabs = " +
buffer.append(" .firstVisibleTab = ") Integer.toHexString(getNumSelectedTabs()) + "\n" +
.append(Integer.toHexString(getFirstVisibleTab())).append("\n"); " .tabwidthratio = " +
buffer.append(" .numselectedtabs = ") Integer.toHexString(getTabWidthRatio()) + "\n" +
.append(Integer.toHexString(getNumSelectedTabs())).append("\n"); "[/WINDOW1]\n";
buffer.append(" .tabwidthratio = ")
.append(Integer.toHexString(getTabWidthRatio())).append("\n");
buffer.append("[/WINDOW1]\n");
return buffer.toString();
} }
public void serialize(LittleEndianOutput out) { public void serialize(LittleEndianOutput out) {

View File

@ -28,7 +28,7 @@ import java.io.IOException;
* data from slow (ie, non FileInputStream) sources, for example when * data from slow (ie, non FileInputStream) sources, for example when
* reading an OLE2 Document over a network. * reading an OLE2 Document over a network.
* *
* Possible extentions: add a timeout. Curently a call to read(byte[]) on this * Possible extensions: add a timeout. Currently a call to read(byte[]) on this
* class is blocking, so use at your own peril if your underlying stream blocks. * class is blocking, so use at your own peril if your underlying stream blocks.
* *
* @author Jens Gerhard * @author Jens Gerhard

View File

@ -36,40 +36,33 @@ public class FontMetricsDumper
Properties props = new Properties(); Properties props = new Properties();
Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for ( int i = 0; i < allFonts.length; i++ ) for (Font allFont : allFonts) {
{ String fontName = allFont.getFontName();
String fontName = allFonts[i].getFontName();
Font font = new Font(fontName, Font.BOLD, 10); Font font = new Font(fontName, Font.BOLD, 10);
FontMetrics fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(font); FontMetrics fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
int fontHeight = fontMetrics.getHeight(); int fontHeight = fontMetrics.getHeight();
props.setProperty("font." + fontName + ".height", fontHeight+""); props.setProperty("font." + fontName + ".height", fontHeight + "");
StringBuffer characters = new StringBuffer(); StringBuilder characters = new StringBuilder();
for (char c = 'a'; c <= 'z'; c++) for (char c = 'a'; c <= 'z'; c++) {
{ characters.append(c).append(", ");
characters.append( c + ", " );
} }
for (char c = 'A'; c <= 'Z'; c++) for (char c = 'A'; c <= 'Z'; c++) {
{ characters.append(c).append(", ");
characters.append( c + ", " );
} }
for (char c = '0'; c <= '9'; c++) for (char c = '0'; c <= '9'; c++) {
{ characters.append(c).append(", ");
characters.append( c + ", " );
} }
StringBuffer widths = new StringBuffer(); StringBuilder widths = new StringBuilder();
for (char c = 'a'; c <= 'z'; c++) for (char c = 'a'; c <= 'z'; c++) {
{ widths.append(fontMetrics.getWidths()[c]).append(", ");
widths.append( fontMetrics.getWidths()[c] + ", " );
} }
for (char c = 'A'; c <= 'Z'; c++) for (char c = 'A'; c <= 'Z'; c++) {
{ widths.append(fontMetrics.getWidths()[c]).append(", ");
widths.append( fontMetrics.getWidths()[c] + ", " );
} }
for (char c = '0'; c <= '9'; c++) for (char c = '0'; c <= '9'; c++) {
{ widths.append(fontMetrics.getWidths()[c]).append(", ");
widths.append( fontMetrics.getWidths()[c] + ", " );
} }
props.setProperty("font." + fontName + ".characters", characters.toString()); props.setProperty("font." + fontName + ".characters", characters.toString());
props.setProperty("font." + fontName + ".widths", widths.toString()); props.setProperty("font." + fontName + ".widths", widths.toString());

View File

@ -265,7 +265,6 @@ public class Range { // TODO -instantiable superclass
// This means there's nested stuff, so we // This means there's nested stuff, so we
// can just zap the lot // can just zap the lot
text = text.substring(0, first13) + text.substring(last15 + 1); text = text.substring(0, first13) + text.substring(last15 + 1);
continue;
} }
return text; return text;
@ -648,8 +647,8 @@ public class Range { // TODO -instantiable superclass
public void replaceText(String pPlaceHolder, String pValue, int pOffset) { public void replaceText(String pPlaceHolder, String pValue, int pOffset) {
int absPlaceHolderIndex = getStartOffset() + pOffset; int absPlaceHolderIndex = getStartOffset() + pOffset;
Range subRange = new Range(absPlaceHolderIndex, (absPlaceHolderIndex + pPlaceHolder Range subRange = new Range(absPlaceHolderIndex,
.length()), this); (absPlaceHolderIndex + pPlaceHolder.length()), this);
subRange.insertBefore(pValue); subRange.insertBefore(pValue);
// re-create the sub-range so we can delete it // re-create the sub-range so we can delete it
@ -669,15 +668,14 @@ public class Range { // TODO -instantiable superclass
* The replacement text (e.g., "Apache Software Foundation") * The replacement text (e.g., "Apache Software Foundation")
*/ */
public void replaceText(String pPlaceHolder, String pValue) { public void replaceText(String pPlaceHolder, String pValue) {
boolean keepLooking = true; while (true) {
while (keepLooking) {
String text = text(); String text = text();
int offset = text.indexOf(pPlaceHolder); int offset = text.indexOf(pPlaceHolder);
if (offset >= 0) if (offset >= 0) {
replaceText(pPlaceHolder, pValue, offset); replaceText(pPlaceHolder, pValue, offset);
else } else {
keepLooking = false; break;
}
} }
} }
@ -726,10 +724,8 @@ public class Range { // TODO -instantiable superclass
istd = papx.getIstd(); istd = papx.getIstd();
} }
CharacterRun chp = new CharacterRun( chpx, _doc.getStyleSheet(), istd, return new CharacterRun( chpx, _doc.getStyleSheet(), istd,
this ); this);
return chp;
} }
/** /**
@ -742,8 +738,7 @@ public class Range { // TODO -instantiable superclass
public Section getSection(int index) { public Section getSection(int index) {
initSections(); initSections();
SEPX sepx = _sections.get(index + _sectionStart); SEPX sepx = _sections.get(index + _sectionStart);
Section sep = new Section(sepx, this); return new Section(sepx, this);
return sep;
} }
/** /**
@ -949,8 +944,6 @@ public class Range { // TODO -instantiable superclass
* *
* @param rpl * @param rpl
* A list of property nodes. * A list of property nodes.
* @param min
* A hint on where to start looking.
* @param start * @param start
* The starting character offset. * The starting character offset.
* @param end * @param end

View File

@ -39,7 +39,6 @@ import org.apache.poi.util.POILogger;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
@ -130,7 +129,6 @@ public class TestBugs extends TestCase
/** /**
* Bug 33519 - HWPF fails to read a file * Bug 33519 - HWPF fails to read a file
* @throws IOException
*/ */
public void test33519() throws IOException public void test33519() throws IOException
{ {
@ -139,7 +137,6 @@ public class TestBugs extends TestCase
/** /**
* Bug 34898 - WordExtractor doesn't read the whole string from the file * Bug 34898 - WordExtractor doesn't read the whole string from the file
* @throws IOException
*/ */
public void test34898() throws IOException public void test34898() throws IOException
{ {
@ -180,7 +177,6 @@ public class TestBugs extends TestCase
/** /**
* Bug 44331 - HWPFDocument.write destroys fields * Bug 44331 - HWPFDocument.write destroys fields
* @throws IOException
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void test44431() throws IOException public void test44431() throws IOException
@ -209,7 +205,6 @@ public class TestBugs extends TestCase
/** /**
* Bug 44331 - HWPFDocument.write destroys fields * Bug 44331 - HWPFDocument.write destroys fields
* @throws IOException
*/ */
public void test44431_2() throws IOException public void test44431_2() throws IOException
{ {
@ -237,7 +232,6 @@ public class TestBugs extends TestCase
/** /**
* Bug 45473 - HWPF cannot read file after save * Bug 45473 - HWPF cannot read file after save
* @throws IOException
*/ */
public void test45473() throws IOException public void test45473() throws IOException
{ {
@ -292,7 +286,6 @@ public class TestBugs extends TestCase
/** /**
* [RESOLVED FIXED] Bug 46817 - Regression: Text from some table cells * [RESOLVED FIXED] Bug 46817 - Regression: Text from some table cells
* missing * missing
* @throws IOException
*/ */
public void test46817() throws IOException public void test46817() throws IOException
{ {
@ -307,7 +300,6 @@ public class TestBugs extends TestCase
* [FAILING] Bug 47286 - Word documents saves in wrong format if source * [FAILING] Bug 47286 - Word documents saves in wrong format if source
* contains form elements * contains form elements
* *
* @throws IOException
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void test47286() throws IOException public void test47286() throws IOException
@ -526,7 +518,6 @@ public class TestBugs extends TestCase
/** /**
* [FAILING] Bug 50955 - error while retrieving the text file * [FAILING] Bug 50955 - error while retrieving the text file
* @throws IOException
*/ */
public void test50955() throws IOException public void test50955() throws IOException
{ {
@ -571,9 +562,6 @@ public class TestBugs extends TestCase
/** /**
* [RESOLVED FIXED] Bug 51604 - replace text fails for doc (poi 3.8 beta * [RESOLVED FIXED] Bug 51604 - replace text fails for doc (poi 3.8 beta
* release from download site ) * release from download site )
*
* @throws IOException
* @throws FileNotFoundException
*/ */
public void test51604p2() throws Exception public void test51604p2() throws Exception
{ {
@ -581,18 +569,7 @@ public class TestBugs extends TestCase
Range range = doc.getRange(); Range range = doc.getRange();
int numParagraph = range.numParagraphs(); int numParagraph = range.numParagraphs();
for (int i = 0; i < numParagraph; i++ ) replaceText(range, numParagraph);
{
Paragraph paragraph = range.getParagraph(i);
int numCharRuns = paragraph.numCharacterRuns();
for (int j = 0; j < numCharRuns; j++ )
{
CharacterRun charRun = paragraph.getCharacterRun(j);
String text = charRun.text();
if (text.contains("Header" ) )
charRun.replaceText(text, "added");
}
}
doc = HWPFTestDataSamples.writeOutAndReadBack(doc); doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
final FileInformationBlock fileInformationBlock = doc final FileInformationBlock fileInformationBlock = doc
@ -610,6 +587,21 @@ public class TestBugs extends TestCase
assertEquals(doc.getText().length(), totalLength); assertEquals(doc.getText().length(), totalLength);
} }
private void replaceText(Range range, int numParagraph) {
for (int i = 0; i < numParagraph; i++ )
{
Paragraph paragraph = range.getParagraph(i);
int numCharRuns = paragraph.numCharacterRuns();
for (int j = 0; j < numCharRuns; j++ )
{
CharacterRun charRun = paragraph.getCharacterRun(j);
String text = charRun.text();
if (text.contains("Header" ) )
charRun.replaceText(text, "added");
}
}
}
/** /**
* [RESOLVED FIXED] Bug 51604 - replace text fails for doc (poi 3.8 beta * [RESOLVED FIXED] Bug 51604 - replace text fails for doc (poi 3.8 beta
* release from download site ) * release from download site )
@ -632,18 +624,7 @@ public class TestBugs extends TestCase
Range range = doc.getRange(); Range range = doc.getRange();
int numParagraph = range.numParagraphs(); int numParagraph = range.numParagraphs();
for (int i = 0; i < numParagraph; i++ ) replaceText(range, numParagraph);
{
Paragraph paragraph = range.getParagraph(i);
int numCharRuns = paragraph.numCharacterRuns();
for (int j = 0; j < numCharRuns; j++ )
{
CharacterRun charRun = paragraph.getCharacterRun(j);
String text = charRun.text();
if (text.contains("Header" ) )
charRun.replaceText(text, "added");
}
}
doc = HWPFTestDataSamples.writeOutAndReadBack(doc); doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
@ -675,7 +656,6 @@ public class TestBugs extends TestCase
/** /**
* Bug 51678 - Extracting text from Bug51524.zip is slow Bug 51524 - * Bug 51678 - Extracting text from Bug51524.zip is slow Bug 51524 -
* PapBinTable constructor is slow * PapBinTable constructor is slow
* @throws IOException
*/ */
public void test51678And51524() throws IOException public void test51678And51524() throws IOException
{ {
@ -822,34 +802,21 @@ public class TestBugs extends TestCase
private int section2BottomMargin = 1440; private int section2BottomMargin = 1440;
private final int section2NumColumns = 3; private final int section2NumColumns = 3;
@SuppressWarnings("SuspiciousNameCombination")
public void testHWPFSections() { public void testHWPFSections() {
HWPFDocument document = null; HWPFDocument document = HWPFTestDataSamples.openSampleFile("Bug53453Section.doc");
Paragraph para = null; Range overallRange = document.getOverallRange();
Section section = null; int numParas = overallRange.numParagraphs();
Range overallRange = null;
int numParas = 0;
int numSections = 0;
document = HWPFTestDataSamples.openSampleFile("Bug53453Section.doc");
overallRange = document.getOverallRange();
numParas = overallRange.numParagraphs();
for(int i = 0; i < numParas; i++) { for(int i = 0; i < numParas; i++) {
para = overallRange.getParagraph(i); Paragraph para = overallRange.getParagraph(i);
numSections = para.numSections(); int numSections = para.numSections();
for(int j = 0; j < numSections; j++) { for(int j = 0; j < numSections; j++) {
section = para.getSection(j); Section section = para.getSection(j);
if(para.text().trim().equals("Section1")) { if(para.text().trim().equals("Section1")) {
assertEquals(section1BottomMargin, section.getMarginBottom()); assertSection1Margin(section);
assertEquals(section1LeftMargin, section.getMarginLeft());
assertEquals(section1RightMargin, section.getMarginRight());
assertEquals(section1TopMargin, section.getMarginTop());
assertEquals(section1NumColumns, section.getNumColumns());
} }
else if(para.text().trim().equals("Section2")) { else if(para.text().trim().equals("Section2")) {
assertEquals(section2BottomMargin, section.getMarginBottom()); assertSection2Margin(section);
assertEquals(section2LeftMargin, section.getMarginLeft());
assertEquals(section2RightMargin, section.getMarginRight());
assertEquals(section2TopMargin, section.getMarginTop());
assertEquals(section2NumColumns, section.getNumColumns());
// Change the margin widths // Change the margin widths
this.section2BottomMargin = (int)(1.5 * AbstractWordUtils.TWIPS_PER_INCH); this.section2BottomMargin = (int)(1.5 * AbstractWordUtils.TWIPS_PER_INCH);
@ -869,53 +836,70 @@ public class TestBugs extends TestCase
overallRange = document.getOverallRange(); overallRange = document.getOverallRange();
numParas = overallRange.numParagraphs(); numParas = overallRange.numParagraphs();
for(int i = 0; i < numParas; i++) { for(int i = 0; i < numParas; i++) {
para = overallRange.getParagraph(i); Paragraph para = overallRange.getParagraph(i);
numSections = para.numSections(); int numSections = para.numSections();
for(int j = 0; j < numSections; j++) { for(int j = 0; j < numSections; j++) {
section = para.getSection(j); Section section = para.getSection(j);
if(para.text().trim().equals("Section1")) { if(para.text().trim().equals("Section1")) {
// No changes to the margins in Section1 // No changes to the margins in Section1
assertEquals(section1BottomMargin, section.getMarginBottom()); assertSection1Margin(section);
assertEquals(section1LeftMargin, section.getMarginLeft());
assertEquals(section1RightMargin, section.getMarginRight());
assertEquals(section1TopMargin, section.getMarginTop());
assertEquals(section1NumColumns, section.getNumColumns());
} }
else if(para.text().trim().equals("Section2")) { else if(para.text().trim().equals("Section2")) {
// The margins in Section2 have kept the new settings. // The margins in Section2 have kept the new settings.
assertEquals(section2BottomMargin, section.getMarginBottom()); assertSection2Margin(section);
assertEquals(section2LeftMargin, section.getMarginLeft());
assertEquals(section2RightMargin, section.getMarginRight());
assertEquals(section2TopMargin, section.getMarginTop());
assertEquals(section2NumColumns, section.getNumColumns());
} }
} }
} }
} }
@SuppressWarnings("Duplicates")
private void assertSection1Margin(Section section) {
assertEquals(section1BottomMargin, section.getMarginBottom());
assertEquals(section1LeftMargin, section.getMarginLeft());
assertEquals(section1RightMargin, section.getMarginRight());
assertEquals(section1TopMargin, section.getMarginTop());
assertEquals(section1NumColumns, section.getNumColumns());
}
@SuppressWarnings("Duplicates")
private void assertSection2Margin(Section section) {
assertEquals(section2BottomMargin, section.getMarginBottom());
assertEquals(section2LeftMargin, section.getMarginLeft());
assertEquals(section2RightMargin, section.getMarginRight());
assertEquals(section2TopMargin, section.getMarginTop());
assertEquals(section2NumColumns, section.getNumColumns());
}
public void testRegressionIn315beta2() { public void testRegressionIn315beta2() {
HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile("cap.stanford.edu_profiles_viewbiosketch_facultyid=4009&name=m_maciver.doc"); HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile("cap.stanford.edu_profiles_viewbiosketch_facultyid=4009&name=m_maciver.doc");
assertNotNull(hwpfDocument); assertNotNull(hwpfDocument);
} }
public void DISABLEDtest57603SevenRowTable() throws Exception { public void test57603SevenRowTable() throws Exception {
HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile("57603-seven_columns.doc");
HWPFDocument hwpfDocument2 = HWPFTestDataSamples.writeOutAndReadBack(hwpfDocument);
assertNotNull(hwpfDocument2);
}
public void test57843() throws IOException {
try { try {
File f = POIDataSamples.getDocumentInstance().getFile("57843.doc"); HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile("57603-seven_columns.doc");
boolean readOnly = true; HWPFDocument hwpfDocument2 = HWPFTestDataSamples.writeOutAndReadBack(hwpfDocument);
POIFSFileSystem fs = new POIFSFileSystem(f, readOnly); assertNotNull(hwpfDocument2);
HWPFOldDocument doc = new HWPFOldDocument(fs); hwpfDocument2.close();
assertNotNull(doc); hwpfDocument.close();
doc.close(); fixed("57603");
fs.close();
fixed("57843");
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
// expected until this bug is fixed // expected until this bug is fixed
} }
} }
public void test57843() throws IOException {
File f = POIDataSamples.getDocumentInstance().getFile("57843.doc");
POIFSFileSystem fs = new POIFSFileSystem(f, true);
try {
HWPFOldDocument doc = new HWPFOldDocument(fs);
assertNotNull(doc);
doc.close();
fixed("57843");
} catch (ArrayIndexOutOfBoundsException e) {
// expected until this bug is fixed
} finally {
fs.close();
}
}
} }

View File

@ -95,6 +95,7 @@ import org.junit.Test;
* <b>YK: If a bug can be tested in terms of common ss interfaces, * <b>YK: If a bug can be tested in terms of common ss interfaces,
* define the test in the base class {@link BaseTestBugzillaIssues}</b> * define the test in the base class {@link BaseTestBugzillaIssues}</b>
*/ */
@SuppressWarnings("deprecation")
public final class TestBugs extends BaseTestBugzillaIssues { public final class TestBugs extends BaseTestBugzillaIssues {
// to not affect other tests running in the same JVM // to not affect other tests running in the same JVM
@After @After
@ -894,7 +895,6 @@ public final class TestBugs extends BaseTestBugzillaIssues {
/** /**
* Problems with extracting check boxes from * Problems with extracting check boxes from
* HSSFObjectData * HSSFObjectData
* @throws Exception
*/ */
@Test(expected=FileNotFoundException.class) @Test(expected=FileNotFoundException.class)
public void bug44840() throws Exception { public void bug44840() throws Exception {
@ -943,33 +943,15 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Check all names fit within range, and use // Check all names fit within range, and use
// DeletedArea3DPtg // DeletedArea3DPtg
InternalWorkbook w = wb1.getWorkbook(); InternalWorkbook w = wb1.getWorkbook();
for(int i=0; i<w.getNumNames(); i++) { assertNames(wb1, w);
NameRecord r = w.getNameRecord(i);
assertTrue(r.getSheetNumber() <= wb1.getNumberOfSheets());
Ptg[] nd = r.getNameDefinition();
assertEquals(1, nd.length);
assertTrue(nd[0] instanceof DeletedArea3DPtg);
}
// Delete the 2nd sheet // Delete the 2nd sheet
wb1.removeSheetAt(1); wb1.removeSheetAt(1);
// Re-check // Re-check
assertEquals(1, wb1.getNumberOfNames()); assertEquals(1, wb1.getNumberOfNames());
assertEquals(2, wb1.getNumberOfSheets()); assertEquals(2, wb1.getNumberOfSheets());
assertNames(wb1, w);
for(int i=0; i<w.getNumNames(); i++) {
NameRecord r = w.getNameRecord(i);
assertTrue(r.getSheetNumber() <= wb1.getNumberOfSheets());
Ptg[] nd = r.getNameDefinition();
assertEquals(1, nd.length);
assertTrue(nd[0] instanceof DeletedArea3DPtg);
}
// Save and re-load // Save and re-load
HSSFWorkbook wb2 = writeOutAndReadBack(wb1); HSSFWorkbook wb2 = writeOutAndReadBack(wb1);
@ -979,20 +961,23 @@ public final class TestBugs extends BaseTestBugzillaIssues {
assertEquals(1, wb2.getNumberOfNames()); assertEquals(1, wb2.getNumberOfNames());
assertEquals(2, wb2.getNumberOfSheets()); assertEquals(2, wb2.getNumberOfSheets());
assertNames(wb2, w);
wb2.close();
}
private void assertNames(HSSFWorkbook wb1, InternalWorkbook w) {
for(int i=0; i<w.getNumNames(); i++) { for(int i=0; i<w.getNumNames(); i++) {
NameRecord r = w.getNameRecord(i); NameRecord r = w.getNameRecord(i);
assertTrue(r.getSheetNumber() <= wb2.getNumberOfSheets()); assertTrue(r.getSheetNumber() <= wb1.getNumberOfSheets());
Ptg[] nd = r.getNameDefinition(); Ptg[] nd = r.getNameDefinition();
assertEquals(1, nd.length); assertEquals(1, nd.length);
assertTrue(nd[0] instanceof DeletedArea3DPtg); assertTrue(nd[0] instanceof DeletedArea3DPtg);
} }
wb2.close();
} }
/** /**
* Test that fonts get added properly * Test that fonts get added properly
* @throws IOException
*/ */
@Test @Test
public void bug45338() throws IOException { public void bug45338() throws IOException {
@ -1061,12 +1046,14 @@ public final class TestBugs extends BaseTestBugzillaIssues {
"Thingy", false, true, (short)2, (byte)2 "Thingy", false, true, (short)2, (byte)2
) )
); );
HSSFFont font = wb.findFont(
(short) 11, (short) 123, (short) 22,
"Thingy", false, true, (short) 2, (byte) 2
);
assertNotNull(font);
assertEquals( assertEquals(
5, 5,
wb.findFont( font.getIndex()
(short)11, (short)123, (short)22,
"Thingy", false, true, (short)2, (byte)2
).getIndex()
); );
assertEquals(nf, assertEquals(nf,
wb.findFont( wb.findFont(
@ -1187,10 +1174,10 @@ public final class TestBugs extends BaseTestBugzillaIssues {
* In this sample file, the vector column * In this sample file, the vector column
* is C, and the data column is B. * is C, and the data column is B.
* *
* For now, blows up with an exception from ExtPtg
* Expected ExpPtg to be converted from Shared to Non-Shared... * Expected ExpPtg to be converted from Shared to Non-Shared...
*/ */
@Ignore @Ignore("For now, blows up with an exception from ExtPtg")
@Test
public void test43623() throws Exception { public void test43623() throws Exception {
HSSFWorkbook wb1 = openSample("43623.xls"); HSSFWorkbook wb1 = openSample("43623.xls");
assertEquals(1, wb1.getNumberOfSheets()); assertEquals(1, wb1.getNumberOfSheets());
@ -1223,7 +1210,6 @@ public final class TestBugs extends BaseTestBugzillaIssues {
/** /**
* People are all getting confused about the last * People are all getting confused about the last
* row and cell number * row and cell number
* @throws IOException
*/ */
@Test @Test
public void bug30635() throws IOException { public void bug30635() throws IOException {
@ -1796,7 +1782,9 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Ensure the print setup // Ensure the print setup
assertEquals("new_sheet!$A$1:$C$1", wb2.getPrintArea(0)); assertEquals("new_sheet!$A$1:$C$1", wb2.getPrintArea(0));
assertEquals("new_sheet!$A$1:$C$1", wb2.getName("Print_Area").getRefersToFormula()); HSSFName printArea = wb2.getName("Print_Area");
assertNotNull(printArea);
assertEquals("new_sheet!$A$1:$C$1", printArea.getRefersToFormula());
// Needs reference not value // Needs reference not value
NameRecord nr = wb2.getWorkbook().getNameRecord( NameRecord nr = wb2.getWorkbook().getNameRecord(
@ -1902,30 +1890,33 @@ public final class TestBugs extends BaseTestBugzillaIssues {
*/ */
@Test @Test
public void bug49185() throws Exception { public void bug49185() throws Exception {
HSSFWorkbook wb1 = openSample("49185.xls"); HSSFWorkbook wb1 = openSample("49185.xls");
Name name = wb1.getName("foobarName"); Name name = wb1.getName("foobarName");
assertEquals("This is a comment", name.getComment()); assertNotNull(name);
assertEquals("This is a comment", name.getComment());
// Rename the name, comment comes with it // Rename the name, comment comes with it
name.setNameName("ChangedName"); name.setNameName("ChangedName");
assertEquals("This is a comment", name.getComment()); assertEquals("This is a comment", name.getComment());
// Save and re-check // Save and re-check
HSSFWorkbook wb2 = writeOutAndReadBack(wb1); HSSFWorkbook wb2 = writeOutAndReadBack(wb1);
wb1.close(); wb1.close();
name = wb2.getName("ChangedName"); name = wb2.getName("ChangedName");
assertEquals("This is a comment", name.getComment()); assertNotNull(name);
assertEquals("This is a comment", name.getComment());
// Now try to change it // Now try to change it
name.setComment("Changed Comment"); name.setComment("Changed Comment");
assertEquals("Changed Comment", name.getComment()); assertEquals("Changed Comment", name.getComment());
// Save and re-check // Save and re-check
HSSFWorkbook wb3 = writeOutAndReadBack(wb2); HSSFWorkbook wb3 = writeOutAndReadBack(wb2);
wb2.close(); wb2.close();
name = wb3.getName("ChangedName"); name = wb3.getName("ChangedName");
assertEquals("Changed Comment", name.getComment()); assertNotNull(name);
wb3.close(); assertEquals("Changed Comment", name.getComment());
wb3.close();
} }
/** /**
@ -2081,7 +2072,6 @@ public final class TestBugs extends BaseTestBugzillaIssues {
/** /**
* Last row number when shifting rows * Last row number when shifting rows
* @throws IOException
*/ */
@Test @Test
public void bug50416LastRowNumber() throws IOException { public void bug50416LastRowNumber() throws IOException {
@ -2562,10 +2552,11 @@ public final class TestBugs extends BaseTestBugzillaIssues {
/** Row style information is 12 not 16 bits */ /** Row style information is 12 not 16 bits */
@Test @Test
public void bug49237() throws Exception { public void bug49237() throws Exception {
HSSFWorkbook wb = openSample("49237.xls"); Workbook wb = openSample("49237.xls");
HSSFSheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(0); Row row = sheet.getRow(0);
HSSFCellStyle rstyle = row.getRowStyle(); CellStyle rstyle = row.getRowStyle();
assertNotNull(rstyle);
assertEquals(BorderStyle.DOUBLE, rstyle.getBorderBottomEnum()); assertEquals(BorderStyle.DOUBLE, rstyle.getBorderBottomEnum());
wb.close(); wb.close();
} }