use of junit.framework.AssertionFailedError in project poi by apache.
the class TestMissingArgEval method testEvaluateMissingArgs.
public void testEvaluateMissingArgs() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFCell cell = sheet.createRow(0).createCell(0);
cell.setCellFormula("if(true,)");
fe.clearAllCachedResultValues();
CellValue cv;
try {
cv = fe.evaluate(cell);
} catch (EmptyStackException e) {
throw new AssertionFailedError("Missing args evaluation not implemented (bug 43354");
}
// MissingArg -> BlankEval -> zero (as formula result)
assertEquals(0.0, cv.getNumberValue(), 0.0);
// MissingArg -> BlankEval -> empty string (in concatenation)
cell.setCellFormula("\"abc\"&if(true,)");
fe.clearAllCachedResultValues();
assertEquals("abc", fe.evaluate(cell).getStringValue());
}
use of junit.framework.AssertionFailedError in project poi by apache.
the class TestCountFuncs method testCountFunctionFromSpreadsheet.
private static void testCountFunctionFromSpreadsheet(String FILE_NAME, int START_ROW_IX, int COL_IX_ACTUAL, int COL_IX_EXPECTED, String functionName) {
int failureCount = 0;
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(FILE_NAME);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
int maxRow = sheet.getLastRowNum();
for (int rowIx = START_ROW_IX; rowIx < maxRow; rowIx++) {
HSSFRow row = sheet.getRow(rowIx);
if (row == null) {
continue;
}
HSSFCell cell = row.getCell(COL_IX_ACTUAL);
CellValue cv = fe.evaluate(cell);
double actualValue = cv.getNumberValue();
double expectedValue = row.getCell(COL_IX_EXPECTED).getNumericCellValue();
if (actualValue != expectedValue) {
System.err.println("Problem with test case on row " + (rowIx + 1) + " " + "Expected = (" + expectedValue + ") Actual=(" + actualValue + ") ");
failureCount++;
}
}
if (failureCount > 0) {
throw new AssertionFailedError(failureCount + " " + functionName + " evaluations failed. See stderr for more details");
}
}
use of junit.framework.AssertionFailedError in project poi by apache.
the class TestIndex method testMissingArg.
/**
* Tests expressions like "INDEX(A1:C1,,2)".<br/>
* This problem was found while fixing bug 47048 and is observable up to svn r773441.
*/
public void testMissingArg() {
ValueEval[] values = { new NumberEval(25.0), new NumberEval(26.0), new NumberEval(28.0) };
AreaEval arg0 = EvalFactory.createAreaEval("A10:C10", values);
ValueEval[] args = new ValueEval[] { arg0, MissingArgEval.instance, new NumberEval(2) };
ValueEval actualResult;
try {
actualResult = FUNC_INST.evaluate(args, -1, -1);
} catch (RuntimeException e) {
if (e.getMessage().equals("Unexpected arg eval type (org.apache.poi.hssf.record.formula.eval.MissingArgEval")) {
throw new AssertionFailedError("Identified bug 47048b - INDEX() should support missing-arg");
}
throw e;
}
// result should be an area eval "B10:B10"
AreaEval ae = confirmAreaEval("B10:B10", actualResult);
actualResult = ae.getValue(0, 0);
assertEquals(NumberEval.class, actualResult.getClass());
assertEquals(26.0, ((NumberEval) actualResult).getNumberValue(), 0.0);
}
use of junit.framework.AssertionFailedError in project poi by apache.
the class TestTxMasterStyleAtom method getMasterStyles.
/**
* Collect all TxMasterStyleAtom records contained in the supplied slide show.
* There must be a TxMasterStyleAtom per each type of text defined in TextHeaderAtom
*/
protected TxMasterStyleAtom[] getMasterStyles() {
List<TxMasterStyleAtom> lst = new ArrayList<TxMasterStyleAtom>();
Record[] coreRecs = _ppt.getMostRecentCoreRecords();
for (final Record coreRec : coreRecs) {
if (coreRec.getRecordType() == RecordTypes.MainMaster.typeID) {
Record[] recs = coreRec.getChildRecords();
int cnt = 0;
for (final Record rec : recs) {
if (rec instanceof TxMasterStyleAtom) {
lst.add((TxMasterStyleAtom) rec);
cnt++;
}
}
assertEquals("MainMaster must contain 7 TxMasterStyleAtoms ", 7, cnt);
} else if (coreRec.getRecordType() == RecordTypes.Document.typeID) {
TxMasterStyleAtom txstyle = null;
Document doc = (Document) coreRec;
Record[] rec = doc.getEnvironment().getChildRecords();
for (final Record atom : rec) {
if (atom instanceof TxMasterStyleAtom) {
if (txstyle != null)
fail("Document.Environment must contain 1 TxMasterStyleAtom");
txstyle = (TxMasterStyleAtom) atom;
}
}
if (txstyle == null) {
throw new AssertionFailedError("TxMasterStyleAtom not found in Document.Environment");
}
assertEquals("Document.Environment must contain TxMasterStyleAtom with type=TextHeaderAtom.OTHER_TYPE", TextHeaderAtom.OTHER_TYPE, txstyle.getTextType());
lst.add(txstyle);
}
}
return lst.toArray(new TxMasterStyleAtom[lst.size()]);
}
use of junit.framework.AssertionFailedError in project poi by apache.
the class TestMissingRecordAwareHSSFListener method testEndOfRow_bug45672.
/**
* Make sure that the presence of shared formulas does not cause extra
* end-of-row records.
*/
public void testEndOfRow_bug45672() {
readRecords("ex45672.xls");
Record[] rr = r;
int eorCount = 0;
int sfrCount = 0;
for (Record record : rr) {
if (record instanceof SharedFormulaRecord) {
sfrCount++;
}
if (record instanceof LastCellOfRowDummyRecord) {
eorCount++;
}
}
if (eorCount == 2) {
throw new AssertionFailedError("Identified bug 45672");
}
assertEquals(1, eorCount);
assertEquals(1, sfrCount);
}
Aggregations