Search in sources :

Example 86 with AssertionFailedError

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());
}
Also used : HSSFFormulaEvaluator(org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator) EmptyStackException(java.util.EmptyStackException) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) CellValue(org.apache.poi.ss.usermodel.CellValue) AssertionFailedError(junit.framework.AssertionFailedError) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 87 with AssertionFailedError

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");
    }
}
Also used : HSSFFormulaEvaluator(org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) CellValue(org.apache.poi.ss.usermodel.CellValue) AssertionFailedError(junit.framework.AssertionFailedError) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 88 with AssertionFailedError

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);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AssertionFailedError(junit.framework.AssertionFailedError) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 89 with AssertionFailedError

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()]);
}
Also used : ArrayList(java.util.ArrayList) AssertionFailedError(junit.framework.AssertionFailedError)

Example 90 with AssertionFailedError

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);
}
Also used : LastCellOfRowDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) StringRecord(org.apache.poi.hssf.record.StringRecord) MissingRowDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord) MissingCellDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord) LastCellOfRowDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

AssertionFailedError (junit.framework.AssertionFailedError)787 TestFailureException (org.apache.openejb.test.TestFailureException)503 JMSException (javax.jms.JMSException)336 EJBException (javax.ejb.EJBException)334 RemoteException (java.rmi.RemoteException)268 InitialContext (javax.naming.InitialContext)168 RemoveException (javax.ejb.RemoveException)80 CreateException (javax.ejb.CreateException)77 NamingException (javax.naming.NamingException)65 BasicStatefulObject (org.apache.openejb.test.stateful.BasicStatefulObject)42 Test (org.junit.Test)42 BasicBmpObject (org.apache.openejb.test.entity.bmp.BasicBmpObject)41 BasicStatelessObject (org.apache.openejb.test.stateless.BasicStatelessObject)38 CountDownLatch (java.util.concurrent.CountDownLatch)28 EntityManager (javax.persistence.EntityManager)21 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)21 EntityManagerFactory (javax.persistence.EntityManagerFactory)17 IOException (java.io.IOException)16 DataSource (javax.sql.DataSource)16 ConnectionFactory (javax.jms.ConnectionFactory)15