You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2016/09/28 21:01:41 UTC
svn commit: r1762709 [2/2] - in /poi/branches/hssf_cryptoapi: ./ sonar/
sonar/examples/ sonar/excelant/ sonar/main/ sonar/ooxml-schema-encryption/
sonar/ooxml-schema-security/ sonar/ooxml-schema/ sonar/ooxml/
sonar/scratchpad/ src/examples/src/org/apac...
Modified: poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java Wed Sep 28 21:01:40 2016
@@ -28,7 +28,7 @@ import org.apache.poi.ss.formula.eval.Va
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
-import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.util.Internal;
/**
* Internal POI use only - parent of XSSF and SXSSF formula evaluators
@@ -53,6 +53,78 @@ public abstract class BaseXSSFFormulaEva
}
/**
+ * If cell contains formula, it evaluates the formula,
+ * and saves the result of the formula. The cell
+ * remains as a formula cell.
+ * Else if cell does not contain formula, this method leaves
+ * the cell unchanged.
+ * Note that the type of the formula result is returned,
+ * so you know what kind of value is also stored with
+ * the formula.
+ * <pre>
+ * CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
+ * </pre>
+ * Be aware that your cell will hold both the formula,
+ * and the result. If you want the cell replaced with
+ * the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)} }
+ * @param cell The cell to evaluate
+ * @return The type of the formula result (the cell's type remains as CellType.FORMULA however)
+ * If cell is not a formula cell, returns {@link CellType#_NONE} rather than throwing an exception.
+ * @since POI 3.15 beta 3
+ * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791.
+ */
+ @Internal(since="POI 3.15 beta 3")
+ public CellType evaluateFormulaCellEnum(Cell cell) {
+ if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
+ return CellType._NONE;
+ }
+ CellValue cv = evaluateFormulaCellValue(cell);
+ // cell remains a formula cell, but the cached value is changed
+ setCellValue(cell, cv);
+ return cv.getCellType();
+ }
+
+ /**
+ * If cell contains formula, it evaluates the formula, and
+ * puts the formula result back into the cell, in place
+ * of the old formula.
+ * Else if cell does not contain formula, this method leaves
+ * the cell unchanged.
+ */
+ protected void doEvaluateInCell(Cell cell) {
+ if (cell == null) return;
+ if (cell.getCellTypeEnum() == CellType.FORMULA) {
+ CellValue cv = evaluateFormulaCellValue(cell);
+ setCellType(cell, cv); // cell will no longer be a formula cell
+ setCellValue(cell, cv);
+ }
+ }
+
+ private static void setCellValue(Cell cell, CellValue cv) {
+ CellType cellType = cv.getCellType();
+ switch (cellType) {
+ case BOOLEAN:
+ cell.setCellValue(cv.getBooleanValue());
+ break;
+ case ERROR:
+ cell.setCellErrorValue(cv.getErrorValue());
+ break;
+ case NUMERIC:
+ cell.setCellValue(cv.getNumberValue());
+ break;
+ case STRING:
+ cell.setCellValue(new XSSFRichTextString(cv.getStringValue()));
+ break;
+ case BLANK:
+ // never happens - blanks eventually get translated to zero
+ case FORMULA:
+ // this will never happen, we have already evaluated the formula
+ default:
+ throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
+ }
+ }
+
+ /**
* Turns a XSSFCell / SXSSFCell into a XSSFEvaluationCell
*/
protected abstract EvaluationCell toEvaluationCell(Cell cell);
Modified: poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCacheDefinition.java Wed Sep 28 21:01:40 2016
@@ -28,10 +28,13 @@ import javax.xml.namespace.QName;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.Beta;
@@ -41,6 +44,7 @@ import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheField;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheFields;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCacheDefinition;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetSource;
public class XSSFPivotCacheDefinition extends POIXMLDocumentPart{
@@ -117,13 +121,47 @@ public class XSSFPivotCacheDefinition ex
}
/**
+ * Find the 2D base data area for the pivot table, either from its direct reference or named table/range.
+ * @return AreaReference representing the current area defined by the pivot table
+ * @throws IllegalArgumentException if the ref attribute is not contiguous or the name attribute is not found.
+ */
+ @Beta
+ public AreaReference getPivotArea(Workbook wb) throws IllegalArgumentException {
+ final CTWorksheetSource wsSource = ctPivotCacheDefinition.getCacheSource().getWorksheetSource();
+
+ final String ref = wsSource.getRef();
+ final String name = wsSource.getName();
+
+ if (ref == null && name == null) throw new IllegalArgumentException("Pivot cache must reference an area, named range, or table.");
+
+ // this is the XML format, so tell the reference that.
+ if (ref != null) return new AreaReference(ref, SpreadsheetVersion.EXCEL2007);
+
+ if (name != null) {
+ // named range or table?
+ final Name range = wb.getName(name);
+ if (range != null) return new AreaReference(range.getRefersToFormula(), SpreadsheetVersion.EXCEL2007);
+ // not a named range, check for a table.
+ // do this second, as tables are sheet-specific, but named ranges are not, and may not have a sheet name given.
+ final XSSFSheet sheet = (XSSFSheet) wb.getSheet(wsSource.getSheet());
+ for (XSSFTable table : sheet.getTables()) {
+ if (table.getName().equals(name)) { //case-sensitive?
+ return new AreaReference(table.getStartCellReference(), table.getEndCellReference());
+ }
+ }
+ }
+
+ throw new IllegalArgumentException("Name '" + name + "' was not found.");
+ }
+
+ /**
* Generates a cache field for each column in the reference area for the pivot table.
* @param sheet The sheet where the data i collected from
*/
@Beta
protected void createCacheFields(Sheet sheet) {
//Get values for start row, start and end column
- AreaReference ar = new AreaReference(ctPivotCacheDefinition.getCacheSource().getWorksheetSource().getRef());
+ AreaReference ar = getPivotArea(sheet.getWorkbook());
CellReference firstCell = ar.getFirstCell();
CellReference lastCell = ar.getLastCell();
int columnStart = firstCell.getCol();
Modified: poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java Wed Sep 28 21:01:40 2016
@@ -30,11 +30,11 @@ import javax.xml.namespace.QName;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataConsolidateFunction;
import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.Beta;
@@ -214,13 +214,8 @@ public class XSSFPivotTable extends POIX
}
protected AreaReference getPivotArea() {
- AreaReference pivotArea = new AreaReference(
- getPivotCacheDefinition()
- .getCTPivotCacheDefinition()
- .getCacheSource()
- .getWorksheetSource()
- .getRef(),
- SpreadsheetVersion.EXCEL2007);
+ final Workbook wb = getDataSheet().getWorkbook();
+ AreaReference pivotArea = getPivotCacheDefinition().getPivotArea(wb);
return pivotArea;
}
@@ -419,12 +414,13 @@ public class XSSFPivotTable extends POIX
/**
* Creates cacheSource and workSheetSource for pivot table and sets the source reference as well assets the location of the pivot table
- * @param source Source for data for pivot table
* @param position Position for pivot table in sheet
* @param sourceSheet Sheet where the source will be collected from
+ * @param refConfig an configurator that knows how to configure pivot table references
*/
@Beta
- protected void createSourceReferences(AreaReference source, CellReference position, Sheet sourceSheet){
+ protected void createSourceReferences(CellReference position, Sheet sourceSheet, PivotTableReferenceConfigurator refConfig){
+
//Get cell one to the right and one down from position, add both to AreaReference and set pivot table location.
AreaReference destination = new AreaReference(position, new CellReference(position.getRow()+1, position.getCol()+1));
@@ -448,9 +444,8 @@ public class XSSFPivotTable extends POIX
worksheetSource.setSheet(sourceSheet.getSheetName());
setDataSheet(sourceSheet);
- String[] firstCell = source.getFirstCell().getCellRefParts();
- String[] lastCell = source.getLastCell().getCellRefParts();
- worksheetSource.setRef(firstCell[2]+firstCell[1]+':'+lastCell[2]+lastCell[1]);
+ refConfig.configureReference(worksheetSource);
+ if (worksheetSource.getName() == null && worksheetSource.getRef() == null) throw new IllegalArgumentException("Pivot table source area reference or name must be specified.");
}
@Beta
@@ -465,11 +460,20 @@ public class XSSFPivotTable extends POIX
int firstColumn = sourceArea.getFirstCell().getCol();
int lastColumn = sourceArea.getLastCell().getCol();
CTPivotField pivotField;
- for(int i = 0; i<=lastColumn-firstColumn; i++) {
+ for(int i = firstColumn; i<=lastColumn; i++) {
pivotField = pivotFields.addNewPivotField();
pivotField.setDataField(false);
pivotField.setShowAll(false);
}
pivotFields.setCount(pivotFields.sizeOfPivotFieldArray());
}
+
+ protected static interface PivotTableReferenceConfigurator {
+
+ /**
+ * Configure the name or area reference for the pivot table
+ * @param wsSource CTWorksheetSource that needs the pivot source reference assignment
+ */
+ public void configureReference(CTWorksheetSource wsSource);
+ }
}
Modified: poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Wed Sep 28 21:01:40 2016
@@ -64,8 +64,10 @@ import org.apache.poi.ss.usermodel.Foote
import org.apache.poi.ss.usermodel.Header;
import org.apache.poi.ss.usermodel.IgnoredErrorType;
import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Table;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
@@ -80,6 +82,7 @@ import org.apache.poi.util.POILogFactory
import org.apache.poi.util.POILogger;
import org.apache.poi.util.Removal;
import org.apache.poi.xssf.model.CommentsTable;
+import org.apache.poi.xssf.usermodel.XSSFPivotTable.PivotTableReferenceConfigurator;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
import org.apache.poi.xssf.usermodel.helpers.XSSFIgnoredErrorHelper;
import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
@@ -1925,15 +1928,17 @@ public class XSSFSheet extends POIXMLDoc
}
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
- final Integer rownumI = new Integer(row.getRowNum()); // NOSONAR
- int idx = _rows.headMap(rownumI).size();
- _rows.remove(rownumI);
+ final int rowNum = row.getRowNum();
+ final Integer rowNumI = new Integer(rowNum); // NOSONAR
+ // this is not the physical row number!
+ final int idx = _rows.headMap(rowNumI).size();
+ _rows.remove(rowNumI);
worksheet.getSheetData().removeRow(idx);
// also remove any comment located in that row
if(sheetComments != null) {
for (CellAddress ref : getCellComments().keySet()) {
- if (ref.getRow() == idx) {
+ if (ref.getRow() == rowNum) {
sheetComments.removeComment(ref);
}
}
@@ -4158,27 +4163,56 @@ public class XSSFSheet extends POIXMLDoc
}
/**
- * Create a pivot table and set area of source, source sheet and a position for pivot table
- * @param source Area from where data will be collected
- * @param position A reference to the cell where the table will start
- * @param sourceSheet The sheet where source will be collected from
+ * Create a pivot table using the AreaReference range on sourceSheet, at the given position.
+ * If the source reference contains a sheet name, it must match the sourceSheet
+ * @param source location of pivot data
+ * @param position A reference to the top left cell where the pivot table will start
+ * @param sourceSheet The sheet containing the source data, if the source reference doesn't contain a sheet name
+ * @throws IllegalArgumentException if source references a sheet different than sourceSheet
* @return The pivot table
*/
@Beta
- public XSSFPivotTable createPivotTable(AreaReference source, CellReference position, Sheet sourceSheet) {
+ public XSSFPivotTable createPivotTable(final AreaReference source, CellReference position, Sheet sourceSheet) {
final String sourceSheetName = source.getFirstCell().getSheetName();
if(sourceSheetName != null && !sourceSheetName.equalsIgnoreCase(sourceSheet.getSheetName())) {
throw new IllegalArgumentException("The area is referenced in another sheet than the "
+ "defined source sheet " + sourceSheet.getSheetName() + ".");
}
+
+ return createPivotTable(position, sourceSheet, new PivotTableReferenceConfigurator() {
+ public void configureReference(CTWorksheetSource wsSource) {
+ final String[] firstCell = source.getFirstCell().getCellRefParts();
+ final String firstRow = firstCell[1];
+ final String firstCol = firstCell[2];
+ final String[] lastCell = source.getLastCell().getCellRefParts();
+ final String lastRow = lastCell[1];
+ final String lastCol = lastCell[2];
+ final String ref = firstCol+firstRow+':'+lastCol+lastRow; //or just source.formatAsString()
+ wsSource.setRef(ref);
+ }
+ });
+ }
+
+ /**
+ * Create a pivot table using the AreaReference or named/table range on sourceSheet, at the given position.
+ * If the source reference contains a sheet name, it must match the sourceSheet.
+ * @param sourceRef location of pivot data - mutually exclusive with SourceName
+ * @param sourceName range or table name for pivot data - mutually exclusive with SourceRef
+ * @param position A reference to the top left cell where the pivot table will start
+ * @param sourceSheet The sheet containing the source data, if the source reference doesn't contain a sheet name
+ * @throws IllegalArgumentException if source references a sheet different than sourceSheet
+ * @return The pivot table
+ */
+ private XSSFPivotTable createPivotTable(CellReference position, Sheet sourceSheet, PivotTableReferenceConfigurator refConfig) {
+
XSSFPivotTable pivotTable = createPivotTable();
//Creates default settings for the pivot table
pivotTable.setDefaultPivotTableDefinition();
//Set sources and references
- pivotTable.createSourceReferences(source, position, sourceSheet);
+ pivotTable.createSourceReferences(position, sourceSheet, refConfig);
- //Create cachefield/s and empty SharedItems
+ //Create cachefield/s and empty SharedItems - must be after creating references
pivotTable.getPivotCacheDefinition().createCacheFields(sourceSheet);
pivotTable.createDefaultDataColumns();
@@ -4186,9 +4220,10 @@ public class XSSFSheet extends POIXMLDoc
}
/**
- * Create a pivot table and set area of source and a position for pivot table
- * @param source Area from where data will be collected
- * @param position A reference to the cell where the table will start
+ * Create a pivot table using the AreaReference range, at the given position.
+ * If the source reference contains a sheet name, that sheet is used, otherwise this sheet is assumed as the source sheet.
+ * @param source location of pivot data
+ * @param position A reference to the top left cell where the pivot table will start
* @return The pivot table
*/
@Beta
@@ -4202,6 +4237,57 @@ public class XSSFSheet extends POIXMLDoc
}
/**
+ * Create a pivot table using the Name range reference on sourceSheet, at the given position.
+ * If the source reference contains a sheet name, it must match the sourceSheet
+ * @param source location of pivot data
+ * @param position A reference to the top left cell where the pivot table will start
+ * @param sourceSheet The sheet containing the source data, if the source reference doesn't contain a sheet name
+ * @throws IllegalArgumentException if source references a sheet different than sourceSheet
+ * @return The pivot table
+ */
+ @Beta
+ public XSSFPivotTable createPivotTable(final Name source, CellReference position, Sheet sourceSheet) {
+ if(source.getSheetName() != null && !source.getSheetName().equals(sourceSheet.getSheetName())) {
+ throw new IllegalArgumentException("The named range references another sheet than the "
+ + "defined source sheet " + sourceSheet.getSheetName() + ".");
+ }
+
+ return createPivotTable(position, sourceSheet, new PivotTableReferenceConfigurator() {
+ public void configureReference(CTWorksheetSource wsSource) {
+ wsSource.setName(source.getNameName());
+ }
+ });
+ }
+
+ /**
+ * Create a pivot table using the Name range, at the given position.
+ * If the source reference contains a sheet name, that sheet is used, otherwise this sheet is assumed as the source sheet.
+ * @param source location of pivot data
+ * @param position A reference to the top left cell where the pivot table will start
+ * @return The pivot table
+ */
+ @Beta
+ public XSSFPivotTable createPivotTable(Name source, CellReference position) {
+ return createPivotTable(source, position, getWorkbook().getSheet(source.getSheetName()));
+ }
+
+ /**
+ * Create a pivot table using the Table, at the given position.
+ * Tables are required to have a sheet reference, so no additional logic around reference sheet is needed.
+ * @param source location of pivot data
+ * @param position A reference to the top left cell where the pivot table will start
+ * @return The pivot table
+ */
+ @Beta
+ public XSSFPivotTable createPivotTable(final Table source, CellReference position) {
+ return createPivotTable(position, getWorkbook().getSheet(source.getSheetName()), new PivotTableReferenceConfigurator() {
+ public void configureReference(CTWorksheetSource wsSource) {
+ wsSource.setName(source.getName());
+ }
+ });
+ }
+
+ /**
* Returns all the pivot tables for this Sheet
*/
@Beta
Modified: poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java Wed Sep 28 21:01:40 2016
@@ -319,6 +319,7 @@ public class ColumnHelper {
}
public int getIndexOfColumn(CTCols cols, CTCol searchCol) {
+ if (cols == null || searchCol == null) return -1;
int i = 0;
for (CTCol col : cols.getColArray()) {
if (col.getMin() == searchCol.getMin() && col.getMax() == searchCol.getMax()) {
Modified: poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java Wed Sep 28 21:01:40 2016
@@ -147,7 +147,8 @@ public final class XSSFRowShifter extend
}
- if (f.isSetRef()) { //Range of cells which the formula applies to.
+ //Range of cells which the formula applies to.
+ if (f.isSetRef()) {
String ref = f.getRef();
String shiftedRef = shiftFormula(row, ref, shifter);
if (shiftedRef != null) f.setRef(shiftedRef);
Modified: poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java Wed Sep 28 21:01:40 2016
@@ -16,6 +16,7 @@
==================================================================== */
package org.apache.poi.extractor;
+import static org.apache.poi.POITestCase.assertContains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -37,6 +38,7 @@ import org.apache.poi.hdgf.extractor.Vis
import org.apache.poi.hpbf.extractor.PublisherTextExtractor;
import org.apache.poi.hslf.extractor.PowerPointExtractor;
import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
+import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
@@ -1019,4 +1021,16 @@ public class TestExtractorFactory {
// expected here
}
}
+
+ // This bug is currently open. This test will fail with "expected error not thrown" when the bug has been fixed.
+ // When this happens, change this from @Test(expected=...) to @Test
+ // bug 45565: text within TextBoxes is extracted by ExcelExtractor and WordExtractor
+ @Test(expected=AssertionError.class)
+ public void test45565() throws Exception {
+ POITextExtractor extractor = ExtractorFactory.createExtractor(HSSFTestDataSamples.getSampleFile("45565.xls"));
+ String text = extractor.getText();
+ assertContains(text, "testdoc");
+ assertContains(text, "test phrase");
+ extractor.close();
+ }
}
Modified: poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java Wed Sep 28 21:01:40 2016
@@ -55,6 +55,7 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.poifs.crypt.dsig.DigestInfo;
import org.apache.poi.poifs.crypt.dsig.SignatureConfig;
import org.apache.poi.poifs.crypt.dsig.SignatureInfo;
@@ -99,7 +100,7 @@ public class TestSignatureInfo {
public static void initBouncy() throws IOException {
CryptoFunctions.registerBouncyCastle();
- /*** TODO : set cal to now ... only set to fixed date for debugging ... */
+ // Set cal to now ... only set to fixed date for debugging ...
cal = LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC);
assertNotNull(cal);
// cal.set(2014, 7, 6, 21, 42, 12);
@@ -403,7 +404,9 @@ public class TestSignatureInfo {
// verify
Iterator<SignaturePart> spIter = si.getSignatureParts().iterator();
- assertTrue(spIter.hasNext());
+ assertTrue("Had: " + si.getSignatureConfig().getOpcPackage().
+ getRelationshipsByType(PackageRelationshipTypes.DIGITAL_SIGNATURE_ORIGIN),
+ spIter.hasNext());
SignaturePart sp = spIter.next();
boolean valid = sp.validate();
assertTrue(valid);
Modified: poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java Wed Sep 28 21:01:40 2016
@@ -31,7 +31,6 @@ import org.apache.poi.xssf.usermodel.XSS
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
Modified: poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Wed Sep 28 21:01:40 2016
@@ -3091,4 +3091,41 @@ public final class TestXSSFBugs extends
assertEquals("09 Mar 2016", result);
}
+
+ // This bug is currently open. When this bug is fixed, it should not throw an AssertionError
+ @Test(expected=AssertionError.class)
+ public void test55076_collapseColumnGroups() throws Exception {
+ Workbook wb = new XSSFWorkbook();
+ Sheet sheet = wb.createSheet();
+
+ // this column collapsing bug only occurs when the grouped columns are different widths
+ sheet.setColumnWidth(1, 400);
+ sheet.setColumnWidth(2, 600);
+ sheet.setColumnWidth(3, 800);
+
+ assertEquals(400, sheet.getColumnWidth(1));
+ assertEquals(600, sheet.getColumnWidth(2));
+ assertEquals(800, sheet.getColumnWidth(3));
+
+ sheet.groupColumn(1, 3);
+ sheet.setColumnGroupCollapsed(1, true);
+
+ assertEquals(0, sheet.getColumnOutlineLevel(0));
+ assertEquals(1, sheet.getColumnOutlineLevel(1));
+ assertEquals(1, sheet.getColumnOutlineLevel(2));
+ assertEquals(1, sheet.getColumnOutlineLevel(3));
+ assertEquals(0, sheet.getColumnOutlineLevel(4));
+
+ // none of the columns should be hidden
+ // column group collapsing is a different concept
+ for (int c=0; c<5; c++) {
+ assertFalse("Column " + c, sheet.isColumnHidden(c));
+ }
+
+ assertEquals(400, sheet.getColumnWidth(1));
+ assertEquals(600, sheet.getColumnWidth(2));
+ assertEquals(800, sheet.getColumnWidth(3));
+
+ wb.close();
+ }
}
Modified: poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java Wed Sep 28 21:01:40 2016
@@ -682,15 +682,4 @@ public final class TestXSSFFormulaEvalua
value = evaluator.evaluate(cell);
assertEquals(1, value.getNumberValue(), 0.001);
}
-
- @Test
- public void evaluateInCellReturnsSameDataType() throws IOException {
- XSSFWorkbook wb = new XSSFWorkbook();
- wb.createSheet().createRow(0).createCell(0);
- XSSFFormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
- XSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
- XSSFCell same = evaluator.evaluateInCell(cell);
- assertSame(cell, same);
- wb.close();
- }
}
Modified: poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Wed Sep 28 21:01:40 2016
@@ -1581,7 +1581,7 @@ public final class TestXSSFSheet extends
System.out.println("Array formulas currently unsupported");
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
/*
- assertEquals("[Array Formula] N7 cell type", CellType.FORMULA, cell.getCellType());
+ assertEquals("[Array Formula] N7 cell type", CellType.FORMULA, cell.getCellTypeEnum());
assertEquals("[Array Formula] N7 cell formula", "{SUM(H7:J7*{1,2,3})}", cell.getCellFormula());
*/
@@ -1792,12 +1792,12 @@ public final class TestXSSFSheet extends
// System.out.println("Array formulas currently unsupported");
/*
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
- assertEquals("[Array Formula] N10 cell type", CellType.FORMULA, cell.getCellType());
+ assertEquals("[Array Formula] N10 cell type", CellType.FORMULA, cell.getCellTypeEnum());
assertEquals("[Array Formula] N10 cell formula", "{SUM(H10:J10*{1,2,3})}", cell.getCellFormula());
cell = CellUtil.getCell(destRow2, col);
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
- assertEquals("[Array Formula] N11 cell type", CellType.FORMULA, cell.getCellType());
+ assertEquals("[Array Formula] N11 cell type", CellType.FORMULA, cell.getCellTypeEnum());
assertEquals("[Array Formula] N11 cell formula", "{SUM(H11:J11*{1,2,3})}", cell.getCellFormula());
*/
@@ -2020,4 +2020,21 @@ public final class TestXSSFSheet extends
}
}
+
+ // bug 59687: XSSFSheet.RemoveRow doesn't handle row gaps properly when removing row comments
+ @Test
+ public void testRemoveRowWithCommentAndGapAbove() throws IOException {
+ final Workbook wb = _testDataProvider.openSampleWorkbook("59687.xlsx");
+ final Sheet sheet = wb.getSheetAt(0);
+
+ // comment exists
+ CellAddress commentCellAddress = new CellAddress("A4");
+ assertNotNull(sheet.getCellComment(commentCellAddress));
+
+ assertEquals("Wrong starting # of comments", 1, sheet.getCellComments().size());
+
+ sheet.removeRow(sheet.getRow(commentCellAddress.getRow()));
+
+ assertEquals("There should not be any comments left!", 0, sheet.getCellComments().size());
+ }
}
Modified: poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java (original)
+++ poi/branches/hssf_cryptoapi/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java Wed Sep 28 21:01:40 2016
@@ -17,6 +17,8 @@
package org.apache.poi.xssf.usermodel;
+import static org.apache.poi.POITestCase.skipTest;
+import static org.apache.poi.POITestCase.testPassesNow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -35,7 +37,7 @@ import org.apache.poi.ss.util.CellAddres
import org.apache.poi.ss.util.CellUtil;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.junit.Ignore;
+import org.apache.xmlbeans.impl.values.XmlValueDisconnectedException;
import org.junit.Test;
public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
@@ -377,7 +379,9 @@ public final class TestXSSFSheetShiftRow
wb.close();
}
- @Ignore("Bug 59733 - shiftRows() causes org.apache.xmlbeans.impl.values.XmlValueDisconnectedException")
+ // This test is written as expected-to-fail and should be rewritten
+ // as expected-to-pass when the bug is fixed.
+ //@Ignore("Bug 59733 - shiftRows() causes org.apache.xmlbeans.impl.values.XmlValueDisconnectedException")
@Test
public void bug59733() throws IOException {
Workbook workbook = new XSSFWorkbook();
@@ -399,9 +403,50 @@ public final class TestXSSFSheetShiftRow
at org.apache.poi.xssf.usermodel.XSSFRow.getRowNum(XSSFRow.java:363)
at org.apache.poi.xssf.usermodel.TestXSSFSheetShiftRows.bug59733(TestXSSFSheetShiftRows.java:393)
*/
- sheet.removeRow(sheet.getRow(0));
- assertEquals(1, sheet.getRow(1).getRowNum());
+ // FIXME: remove try, catch, and testPassesNow, skipTest when test passes
+ try {
+ sheet.removeRow(sheet.getRow(0));
+ assertEquals(1, sheet.getRow(1).getRowNum());
+ testPassesNow(59733);
+ } catch (XmlValueDisconnectedException e) {
+ skipTest(e);
+ }
+
workbook.close();
+ }
+
+ private static String getCellFormula(Sheet sheet, String address) {
+ CellAddress cellAddress = new CellAddress(address);
+ Row row = sheet.getRow(cellAddress.getRow());
+ assertNotNull(row);
+ Cell cell = row.getCell(cellAddress.getColumn());
+ assertNotNull(cell);
+ assertEquals(CellType.FORMULA, cell.getCellTypeEnum());
+ return cell.getCellFormula();
+ }
+
+ // This test is written as expected-to-fail and should be rewritten
+ // as expected-to-pass when the bug is fixed.
+ @Test
+ public void testSharedFormulas() throws Exception {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("TestShiftRowSharedFormula.xlsx");
+ XSSFSheet sheet = wb.getSheetAt(0);
+ assertEquals("SUM(C2:C4)", getCellFormula(sheet, "C5"));
+ assertEquals("SUM(D2:D4)", getCellFormula(sheet, "D5"));
+ assertEquals("SUM(E2:E4)", getCellFormula(sheet, "E5"));
+
+ sheet.shiftRows(3, sheet.getLastRowNum(), 1);
+ // FIXME: remove try, catch, and testPassesNow, skipTest when test passes
+ try {
+ assertEquals("SUM(C2:C5)", getCellFormula(sheet, "C6"));
+ assertEquals("SUM(D2:D5)", getCellFormula(sheet, "D6"));
+ assertEquals("SUM(E2:E5)", getCellFormula(sheet, "E6"));
+ testPassesNow(59983);
+ } catch (AssertionError e) {
+ skipTest(e);
+ }
+
+ wb.close();
}
}
Modified: poi/branches/hssf_cryptoapi/src/scratchpad/src/org/apache/poi/hmef/Attachment.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/scratchpad/src/org/apache/poi/hmef/Attachment.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/scratchpad/src/org/apache/poi/hmef/Attachment.java (original)
+++ poi/branches/hssf_cryptoapi/src/scratchpad/src/org/apache/poi/hmef/Attachment.java Wed Sep 28 21:01:40 2016
@@ -137,6 +137,8 @@ public final class Attachment {
/**
* Returns the contents of the attachment.
+ *
+ * @throws IllegalArgumentException if there is no AttachmentData available in this Attachment
*/
public byte[] getContents() {
TNEFAttribute contents = getAttribute(TNEFProperty.ID_ATTACHDATA);
Modified: poi/branches/hssf_cryptoapi/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java (original)
+++ poi/branches/hssf_cryptoapi/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java Wed Sep 28 21:01:40 2016
@@ -154,37 +154,37 @@ public class WordToFoUtils extends Abstr
{
block.setAttribute(
"text-indent",
- String.valueOf( paragraph.getFirstLineIndent()
- / TWIPS_PER_PT )
+ paragraph.getFirstLineIndent()
+ / TWIPS_PER_PT
+ "pt" );
}
if ( paragraph.getIndentFromLeft() != 0 )
{
block.setAttribute(
"start-indent",
- String.valueOf( paragraph.getIndentFromLeft()
- / TWIPS_PER_PT )
+ paragraph.getIndentFromLeft()
+ / TWIPS_PER_PT
+ "pt" );
}
if ( paragraph.getIndentFromRight() != 0 )
{
block.setAttribute(
"end-indent",
- String.valueOf( paragraph.getIndentFromRight()
- / TWIPS_PER_PT )
+ paragraph.getIndentFromRight()
+ / TWIPS_PER_PT
+ "pt" );
}
if ( paragraph.getSpacingBefore() != 0 )
{
block.setAttribute(
"space-before",
- String.valueOf( paragraph.getSpacingBefore() / TWIPS_PER_PT )
+ paragraph.getSpacingBefore() / TWIPS_PER_PT
+ "pt" );
}
if ( paragraph.getSpacingAfter() != 0 )
{
block.setAttribute( "space-after",
- String.valueOf( paragraph.getSpacingAfter() / TWIPS_PER_PT )
+ paragraph.getSpacingAfter() / TWIPS_PER_PT
+ "pt" );
}
}
Modified: poi/branches/hssf_cryptoapi/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java (original)
+++ poi/branches/hssf_cryptoapi/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java Wed Sep 28 21:01:40 2016
@@ -32,11 +32,13 @@ import org.apache.poi.hwpf.model.PlexOfF
import org.apache.poi.hwpf.model.SubdocumentType;
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -901,4 +903,19 @@ public class TestBugs extends TestCase
HWPFDocument hwpfDocument2 = HWPFTestDataSamples.writeOutAndReadBack(hwpfDocument);
assertNotNull(hwpfDocument2);
}
+
+ public void test57843() throws IOException {
+ try {
+ File f = POIDataSamples.getDocumentInstance().getFile("57843.doc");
+ boolean readOnly = true;
+ POIFSFileSystem fs = new POIFSFileSystem(f, readOnly);
+ HWPFOldDocument doc = new HWPFOldDocument(fs);
+ assertNotNull(doc);
+ doc.close();
+ fs.close();
+ fixed("57843");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // expected until this bug is fixed
+ }
+ }
}
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/POITestCase.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/POITestCase.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/POITestCase.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/POITestCase.java Wed Sep 28 21:01:40 2016
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
@@ -174,4 +175,62 @@ public final class POITestCase {
}
}
}
+
+ /**
+ * Rather than adding {@literal @}Ignore to known-failing tests,
+ * write the test so that it notifies us if it starts passing.
+ * This is useful for closing related or forgotten bugs.
+ *
+ * An Example:
+ * <code><pre>
+ * public static int add(int a, int b) {
+ * // a known bug in behavior that has not been fixed yet
+ * raise UnsupportedOperationException("add");
+ * }
+ *
+ * {@literal @}Test
+ * public void knownFailingUnitTest() {
+ * try {
+ * assertEquals(2, add(1,1));
+ * // this test fails because the assumption that this bug had not been fixed is false
+ * testPassesNow(12345);
+ * } catch (UnsupportedOperationException e) {
+ * // test is skipped because the assumption that this bug had not been fixed is true
+ * skipTest(e);
+ * }
+ * }
+ *
+ * Once passing, this unit test can be rewritten as:
+ * {@literal @}Test
+ * public void knownPassingUnitTest() {
+ * assertEquals(2, add(1,1));
+ * }
+ *
+ * If you have a better idea how to simplify test code while still notifying
+ * us when a previous known-failing test now passes, please improve these.
+ * As a bonus, a known-failing test that fails should not be counted as a
+ * passing test.
+ *
+ * One possible alternative is to expect the known exception, but without
+ * a clear message that it is a good thing to no longer get the expected
+ * exception once the test passes.
+ * {@literal @}Test(expected=UnsupportedOperationException.class)
+ * public void knownFailingUnitTest() {
+ * assertEquals(2, add(1,1));
+ * }
+ *
+ * @param e the exception that was caught that will no longer
+ * be raised when the bug is fixed
+ */
+ public static void skipTest(Throwable e) {
+ assumeTrue("This test currently fails with " + e, false);
+ }
+ /**
+ * @see #skipTest(Throwable)
+ *
+ * @param bug the bug number corresponding to a known bug in bugzilla
+ */
+ public static void testPassesNow(int bug) {
+ fail("This test passes now. Please update the unit test and bug " + bug + ".");
+ }
}
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Wed Sep 28 21:01:40 2016
@@ -1885,12 +1885,12 @@ public final class TestBugs extends Base
// TODO - Fix these so they work...
/*row = s.getRow(4);
- assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
+ assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum());
assertEquals("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula());
assertEquals(123.0, row.getCell(1).getNumericCellValue(), 0);
row = s.getRow(5);
- assertEquals(CellType.FORMULA, row.getCell(1).getCellType());
+ assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum());
assertEquals("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula());
assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0);*/
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java Wed Sep 28 21:01:40 2016
@@ -227,7 +227,7 @@ public final class TestPOIFSDocumentPath
{
for (int k = 0; k < paths.length; k++)
{
- assertEquals(String.valueOf(j) + "<>" + String.valueOf(k),
+ assertEquals(j + "<>" + k,
paths[ j ], paths[ k ]);
}
}
@@ -274,13 +274,13 @@ public final class TestPOIFSDocumentPath
{
if (k == j)
{
- assertEquals(String.valueOf(j) + "<>"
- + String.valueOf(k), fullPaths[ j ],
+ assertEquals(j + "<>"
+ + k, fullPaths[ j ],
builtUpPaths[ k ]);
}
else
{
- assertTrue(String.valueOf(j) + "<>" + String.valueOf(k),
+ assertTrue(j + "<>" + k,
!(fullPaths[ j ].equals(builtUpPaths[ k ])));
}
}
@@ -306,7 +306,7 @@ public final class TestPOIFSDocumentPath
{
for (int j = 0; j < badPaths.length; j++)
{
- assertTrue(String.valueOf(j) + "<>" + String.valueOf(k),
+ assertTrue(j + "<>" + k,
!(fullPaths[ k ].equals(badPaths[ j ])));
}
}
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java Wed Sep 28 21:01:40 2016
@@ -18,10 +18,10 @@
package org.apache.poi.poifs.macros;
import static org.apache.poi.POITestCase.assertContains;
+import static org.apache.poi.POITestCase.skipTest;
+import static org.apache.poi.POITestCase.testPassesNow;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.io.FileInputStream;
@@ -268,16 +268,28 @@ public class TestVBAMacroReader {
public void bug59858() throws IOException {
try {
fromFile(POIDataSamples.getSpreadSheetInstance(), "59858.xls");
- fail("This test passes now. Please update the unit test and bug 59858.");
+ testPassesNow(59858);
} catch (IOException e) {
if (e.getMessage().matches("Module offset for '.+' was never read.")) {
//e.printStackTrace();
// NPE when reading module.offset in VBAMacroReader.readMacros (approx line 258)
- assumeTrue("This test currently fails. See stdout.", false);
+ skipTest(e);
} else {
// something unexpected failed
throw e;
}
}
}
+
+ // This test is written as expected-to-fail and should be rewritten
+ // as expected-to-pass when the bug is fixed.
+ @Test
+ public void bug60158() throws IOException {
+ try {
+ fromFile(POIDataSamples.getDocumentInstance(), "60158.docm");
+ testPassesNow(60158);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ skipTest(e);
+ }
+ }
}
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/formula/atp/TestIfError.java Wed Sep 28 21:01:40 2016
@@ -84,7 +84,7 @@ public class TestIfError extends TestCas
assertEquals("Checks that the cell is numeric",
- CellType.STRING, evaluator.evaluate(cell2).getCellTypeEnum());
+ CellType.STRING, evaluator.evaluate(cell2).getCellTypeEnum());
assertEquals("Rounds -10 to a nearest multiple of -3 (-9)",
"Error in calculation", evaluator.evaluate(cell2).getStringValue());
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java Wed Sep 28 21:01:40 2016
@@ -33,12 +33,9 @@ import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.geom.Rectangle2D;
-import java.io.FileInputStream;
import java.io.IOException;
import java.text.AttributedString;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import static org.junit.Assert.*;
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java Wed Sep 28 21:01:40 2016
@@ -17,6 +17,8 @@
package org.apache.poi.ss.usermodel;
+import static org.apache.poi.POITestCase.skipTest;
+import static org.apache.poi.POITestCase.testPassesNow;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -295,7 +297,7 @@ public abstract class BaseTestSheetShift
wb.close();
}
- @Ignore("bug 56454: Incorrectly handles merged regions that do not contain column 0")
+ //@Ignore("bug 56454: Incorrectly handles merged regions that do not contain column 0")
@Test
public final void shiftWithMergedRegions_bug56454() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
@@ -328,7 +330,15 @@ public abstract class BaseTestSheetShift
expectedMergedRegions.add(A4_B8);
expectedMergedRegions.add(C4_D8);
- assertEquals(expectedMergedRegions, sheet.getMergedRegions());
+ // This test is written as expected-to-fail and should be rewritten
+ // as expected-to-pass when the bug is fixed.
+ // FIXME: remove try, catch, and testPassesNow, skipTest when test passes
+ try {
+ assertEquals(expectedMergedRegions, sheet.getMergedRegions());
+ testPassesNow(56454);
+ } catch (AssertionError e) {
+ skipTest(e);
+ }
wb.close();
}
@@ -589,7 +599,7 @@ public abstract class BaseTestSheetShift
read.close();
}
- @Ignore("bug 56454: Incorrectly handles merged regions that do not contain column 0")
+ //@Ignore("bug 56454: Incorrectly handles merged regions that do not contain column 0")
@Test
public void shiftRowsWithMergedRegionsThatDoNotContainColumnZero() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
@@ -614,9 +624,17 @@ public abstract class BaseTestSheetShift
// C5:D7 will be shifted down with same size
sheet.shiftRows(4, sheet.getLastRowNum(), 1);
- assertEquals(2, sheet.getNumMergedRegions());
- assertEquals(CellRangeAddress.valueOf("A4:B8"), sheet.getMergedRegion(0));
- assertEquals(CellRangeAddress.valueOf("C5:D8"), sheet.getMergedRegion(1));
+ // This test is written as expected-to-fail and should be rewritten
+ // as expected-to-pass when the bug is fixed.
+ // FIXME: remove try, catch, and testPassesNow, skipTest when test passes
+ try {
+ assertEquals(2, sheet.getNumMergedRegions());
+ assertEquals(CellRangeAddress.valueOf("A4:B8"), sheet.getMergedRegion(0));
+ assertEquals(CellRangeAddress.valueOf("C5:D8"), sheet.getMergedRegion(1));
+ testPassesNow(56454);
+ } catch (AssertionError e) {
+ skipTest(e);
+ }
wb.close();
}
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java Wed Sep 28 21:01:40 2016
@@ -570,7 +570,7 @@ public abstract class BaseTestSheetUpdat
assertEquals(cra.formatAsString(), mcell.getArrayFormulaRange().formatAsString());
assertEquals("A2:A4*B2:B4", mcell.getCellFormula());
assertTrue(mcell.isPartOfArrayFormulaGroup());
- assertEquals(CellType.FORMULA, mcell.getCellType());
+ assertEquals(CellType.FORMULA, mcell.getCellTypeEnum());
}
*/
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/util/DummyPOILogger.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/util/DummyPOILogger.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/util/DummyPOILogger.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/util/DummyPOILogger.java Wed Sep 28 21:01:40 2016
@@ -23,6 +23,7 @@ import java.util.List;
* POILogger which logs into an ArrayList, so that
* tests can see what got logged
*/
+@Internal
public class DummyPOILogger extends POILogger {
public List<String>logged = new ArrayList<String>();
@@ -39,12 +40,12 @@ public class DummyPOILogger extends POIL
public void initialize(String cat) {}
@Override
- public void log(int level, Object obj1) {
+ protected void _log(int level, Object obj1) {
logged.add(level + " - " + obj1);
}
@Override
- public void log(int level, Object obj1, Throwable exception) {
+ protected void _log(int level, Object obj1, Throwable exception) {
logged.add(level + " - " + obj1 + " - " + exception);
}
}
Modified: poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/util/TestPOILogger.java
URL: http://svn.apache.org/viewvc/poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/util/TestPOILogger.java?rev=1762709&r1=1762708&r2=1762709&view=diff
==============================================================================
--- poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/util/TestPOILogger.java (original)
+++ poi/branches/hssf_cryptoapi/src/testcases/org/apache/poi/util/TestPOILogger.java Wed Sep 28 21:01:40 2016
@@ -65,13 +65,13 @@ public final class TestPOILogger extends
}
@Override
- public void log(int level, Object obj1) {
+ protected void _log(int level, Object obj1) {
lastLog = (obj1 == null) ? "" : obj1.toString();
lastEx = null;
}
@Override
- public void log(int level, Object obj1, Throwable exception) {
+ protected void _log(int level, Object obj1, Throwable exception) {
lastLog = (obj1 == null) ? "" : obj1.toString();
lastEx = exception;
}
Propchange: poi/branches/hssf_cryptoapi/test-data/diagram/44501a.vsd
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/diagram/44501b.vsd
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/diagram/44501d.vsd
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/hsmf/logsat.com_signatures_valid.msg
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/slideshow/aascu.org_workarea_downloadasset.aspx_id=5864.pptx
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/slideshow/br.com.diversas.palestras_Nelson_20-_20Temas_20Diversos_20XXXVI_pmrg_462538ba7a204-programa_alianca_12-04-2007.ppt
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/slideshow/br.com.tvcamboriu.www_pps_Pensar_5b1_5d.ppt
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/spreadsheet/Themes2.xls
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/spreadsheet/at.gv.land-oberoesterreich.www_cps_rde_xbcr_SID-4A1B954F-5C07F98E_ooe_stat_download_bp10.xls
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/spreadsheet/craftonhills.edu_programreview_report.aspx_goalpriorityreport_0011d159-1eeb-4b63-8833-867b0926e5f3.xlsx
('svn:executable' removed)
Propchange: poi/branches/hssf_cryptoapi/test-data/spreadsheet/noSharedStringTable.xlsx
('svn:executable' removed)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org