Slightly more test-coverage in HSSFSheet/XSSFSheet/SXSSFSheet and fix some Eclipse warnings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1537331 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3fdf865d88
commit
d08ab9dc0d
@ -681,7 +681,7 @@ under the License.
|
||||
<group name="Main">
|
||||
<classfiles>
|
||||
<fileset dir="${main.output.dir}">
|
||||
<exclude name=""/>
|
||||
<exclude name="org/apache/poi/hssf/usermodel/DummyGraphics2d.class"/>
|
||||
</fileset>
|
||||
</classfiles>
|
||||
<sourcefiles encoding="UTF-8">
|
||||
|
@ -32,14 +32,14 @@ import org.apache.poi.hssf.record.*;
|
||||
import org.apache.poi.hssf.record.aggregates.DataValidityTable;
|
||||
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
|
||||
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
|
||||
import org.apache.poi.ss.formula.FormulaShifter;
|
||||
import org.apache.poi.ss.formula.ptg.MemFuncPtg;
|
||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
import org.apache.poi.ss.formula.ptg.Area3DPtg;
|
||||
import org.apache.poi.ss.formula.ptg.UnionPtg;
|
||||
import org.apache.poi.hssf.util.PaneInformation;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.formula.FormulaShifter;
|
||||
import org.apache.poi.ss.formula.FormulaType;
|
||||
import org.apache.poi.ss.formula.ptg.Area3DPtg;
|
||||
import org.apache.poi.ss.formula.ptg.MemFuncPtg;
|
||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
import org.apache.poi.ss.formula.ptg.UnionPtg;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellRange;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
@ -1203,9 +1203,9 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||
*/
|
||||
public void setZoom(int numerator, int denominator) {
|
||||
if (numerator < 1 || numerator > 65535)
|
||||
throw new IllegalArgumentException("Numerator must be greater than 1 and less than 65536");
|
||||
throw new IllegalArgumentException("Numerator must be greater than 0 and less than 65536");
|
||||
if (denominator < 1 || denominator > 65535)
|
||||
throw new IllegalArgumentException("Denominator must be greater than 1 and less than 65536");
|
||||
throw new IllegalArgumentException("Denominator must be greater than 0 and less than 65536");
|
||||
|
||||
SCLRecord sclRecord = new SCLRecord();
|
||||
sclRecord.setNumerator((short) numerator);
|
||||
|
@ -29,6 +29,7 @@ package org.apache.poi.util;
|
||||
*/
|
||||
public class NullLogger extends POILogger
|
||||
{
|
||||
@Override
|
||||
public void initialize(final String cat)
|
||||
{
|
||||
//do nothing
|
||||
@ -41,6 +42,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj1 The object to log.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1)
|
||||
{
|
||||
//do nothing
|
||||
@ -52,6 +54,7 @@ public class NullLogger extends POILogger
|
||||
* @param level One of DEBUG, INFO, WARN, ERROR, FATAL
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean check(final int level)
|
||||
{
|
||||
return false;
|
||||
@ -65,6 +68,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj2 second object to place in the message
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2)
|
||||
{
|
||||
//do nothing
|
||||
@ -79,6 +83,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj3 third Object to place in the message
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3)
|
||||
{
|
||||
@ -95,6 +100,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj4 fourth Object to place in the message
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4)
|
||||
{
|
||||
@ -112,6 +118,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj5 fifth Object to place in the message
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4, final Object obj5)
|
||||
{
|
||||
@ -130,6 +137,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj6 sixth Object to place in the message
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4, final Object obj5,
|
||||
final Object obj6)
|
||||
@ -150,6 +158,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj7 seventh Object to place in the message
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4, final Object obj5,
|
||||
final Object obj6, final Object obj7)
|
||||
@ -171,6 +180,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj8 eighth Object to place in the message
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4, final Object obj5,
|
||||
final Object obj6, final Object obj7, final Object obj8)
|
||||
@ -186,6 +196,7 @@ public class NullLogger extends POILogger
|
||||
* @param exception An exception to be logged
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1,
|
||||
final Throwable exception)
|
||||
{
|
||||
@ -201,6 +212,7 @@ public class NullLogger extends POILogger
|
||||
* @param exception An exception to be logged
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Throwable exception)
|
||||
{
|
||||
@ -217,6 +229,7 @@ public class NullLogger extends POILogger
|
||||
* @param exception An error message to be logged
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Throwable exception)
|
||||
{
|
||||
@ -234,6 +247,7 @@ public class NullLogger extends POILogger
|
||||
* @param exception An exception to be logged
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4,
|
||||
final Throwable exception)
|
||||
@ -253,6 +267,7 @@ public class NullLogger extends POILogger
|
||||
* @param exception An exception to be logged
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4, final Object obj5,
|
||||
final Throwable exception)
|
||||
@ -273,6 +288,7 @@ public class NullLogger extends POILogger
|
||||
* @param exception An exception to be logged
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4, final Object obj5,
|
||||
final Object obj6, final Throwable exception)
|
||||
@ -294,6 +310,7 @@ public class NullLogger extends POILogger
|
||||
* @param exception An exception to be logged
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4, final Object obj5,
|
||||
final Object obj6, final Object obj7,
|
||||
@ -317,6 +334,7 @@ public class NullLogger extends POILogger
|
||||
* @param exception An exception to be logged
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void log(final int level, final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4, final Object obj5,
|
||||
final Object obj6, final Object obj7, final Object obj8,
|
||||
@ -350,6 +368,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj1 The first object to match against.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void logFormatted(final int level, final String message,
|
||||
final Object obj1)
|
||||
{
|
||||
@ -382,6 +401,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj2 The second object to match against.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void logFormatted(final int level, final String message,
|
||||
final Object obj1, final Object obj2)
|
||||
{
|
||||
@ -415,6 +435,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj3 The third object to match against.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void logFormatted(final int level, final String message,
|
||||
final Object obj1, final Object obj2,
|
||||
final Object obj3)
|
||||
@ -450,6 +471,7 @@ public class NullLogger extends POILogger
|
||||
* @param obj4 The forth object to match against.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void logFormatted(final int level, final String message,
|
||||
final Object obj1, final Object obj2,
|
||||
final Object obj3, final Object obj4)
|
||||
|
@ -19,7 +19,8 @@
|
||||
|
||||
package org.apache.poi.util;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Provides logging without clients having to mess with
|
||||
@ -64,7 +65,7 @@ public class POILogFactory
|
||||
* @return a POILogger for the specified class
|
||||
*/
|
||||
|
||||
public static POILogger getLogger(final Class theclass)
|
||||
public static POILogger getLogger(final Class<?> theclass)
|
||||
{
|
||||
return getLogger(theclass.getName());
|
||||
}
|
||||
@ -111,7 +112,8 @@ public class POILogFactory
|
||||
logger = _loggers.get(cat);
|
||||
} else {
|
||||
try {
|
||||
Class<? extends POILogger> loggerClass =
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends POILogger> loggerClass =
|
||||
(Class<? extends POILogger>)Class.forName(_loggerClassName);
|
||||
logger = loggerClass.newInstance();
|
||||
logger.initialize(cat);
|
||||
|
@ -19,9 +19,10 @@
|
||||
|
||||
package org.apache.poi.xssf.streaming;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.BaseTestSheet;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.SXSSFITestDataProvider;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
|
||||
|
@ -347,17 +347,23 @@ public final class TestHSSFSheet extends BaseTestSheet {
|
||||
int expectedHashB = -14556;
|
||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||
HSSFSheet hssfSheet = workbook.createSheet();
|
||||
assertFalse(hssfSheet.getObjectProtect());
|
||||
hssfSheet.protectSheet(passwordA);
|
||||
assertTrue(hssfSheet.getObjectProtect());
|
||||
assertEquals(expectedHashA, hssfSheet.getPassword());
|
||||
|
||||
assertEquals(expectedHashA, hssfSheet.getSheet().getProtectionBlock().getPasswordHash());
|
||||
|
||||
// Clone the sheet, and make sure the password hash is preserved
|
||||
HSSFSheet sheet2 = workbook.cloneSheet(0);
|
||||
assertTrue(hssfSheet.getObjectProtect());
|
||||
assertEquals(expectedHashA, sheet2.getSheet().getProtectionBlock().getPasswordHash());
|
||||
|
||||
// change the password on the first sheet
|
||||
hssfSheet.protectSheet(passwordB);
|
||||
assertTrue(hssfSheet.getObjectProtect());
|
||||
assertEquals(expectedHashB, hssfSheet.getSheet().getProtectionBlock().getPasswordHash());
|
||||
assertEquals(expectedHashB, hssfSheet.getPassword());
|
||||
// but the cloned sheet's password should remain unchanged
|
||||
assertEquals(expectedHashA, sheet2.getSheet().getProtectionBlock().getPasswordHash());
|
||||
}
|
||||
@ -452,6 +458,32 @@ public final class TestHSSFSheet extends BaseTestSheet {
|
||||
int sclLoc = sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid);
|
||||
int window2Loc = sheet.getSheet().findFirstRecordLocBySid(WindowTwoRecord.sid);
|
||||
assertTrue(sclLoc == window2Loc + 1);
|
||||
|
||||
// verify limits
|
||||
try {
|
||||
sheet.setZoom(0, 2);
|
||||
fail("Should catch Exception here");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage());
|
||||
}
|
||||
try {
|
||||
sheet.setZoom(65536, 2);
|
||||
fail("Should catch Exception here");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage());
|
||||
}
|
||||
try {
|
||||
sheet.setZoom(2, 0);
|
||||
fail("Should catch Exception here");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage());
|
||||
}
|
||||
try {
|
||||
sheet.setZoom(2, 65536);
|
||||
fail("Should catch Exception here");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -538,7 +570,8 @@ public final class TestHSSFSheet extends BaseTestSheet {
|
||||
workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
|
||||
}
|
||||
|
||||
public void testAutoSizeColumn() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testAutoSizeColumn() {
|
||||
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("43902.xls");
|
||||
String sheetName = "my sheet";
|
||||
HSSFSheet sheet = wb.getSheet(sheetName);
|
||||
@ -561,6 +594,7 @@ public final class TestHSSFSheet extends BaseTestSheet {
|
||||
|
||||
//create a region over the 2nd row and auto size the first column
|
||||
sheet.addMergedRegion(new CellRangeAddress(1,1,0,1));
|
||||
assertNotNull(sheet.getMergedRegionAt(0));
|
||||
sheet.autoSizeColumn((short)0);
|
||||
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||
|
||||
@ -1009,4 +1043,27 @@ public final class TestHSSFSheet extends BaseTestSheet {
|
||||
}
|
||||
assertEquals(40000, sheet.getColumnWidth((short)10));
|
||||
}
|
||||
|
||||
public void testShowInPane() {
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
sheet.showInPane(2, 3);
|
||||
|
||||
try {
|
||||
sheet.showInPane(Integer.MAX_VALUE, 3);
|
||||
fail("Should catch exception here");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Maximum row number is 65535", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testDrawingRecords() {
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet();
|
||||
|
||||
/* TODO: NPE?
|
||||
sheet.dumpDrawingRecords(false);
|
||||
sheet.dumpDrawingRecords(true);*/
|
||||
assertNull(sheet.getDrawingEscherAggregate());
|
||||
}
|
||||
}
|
||||
|
@ -787,4 +787,17 @@ public abstract class BaseTestSheet extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testBaseZoom() {
|
||||
Workbook wb = _testDataProvider.createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
|
||||
// here we can only verify that setting some zoom values works, range-checking is different between the implementations
|
||||
sheet.setZoom(3,4);
|
||||
}
|
||||
|
||||
public void testBaseShowInPane() {
|
||||
Workbook wb = _testDataProvider.createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
sheet.showInPane(2, 3);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user