use of junit.framework.AssertionFailedError in project poi by apache.
the class TestPageSettingsBlock method testDuplicatePSBRecord_bug47199.
/**
* The PageSettingsBlock should not allow multiple copies of the same record. This extra assertion
* was added while fixing bug 47199. All existing POI test samples comply with this requirement.
*/
public void testDuplicatePSBRecord_bug47199() {
// Hypothetical setup of PSB records which should cause POI to crash
Record[] recs = { new HeaderRecord("&LSales Figures"), new HeaderRecord("&LInventory") };
RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
try {
new PageSettingsBlock(rs);
throw new AssertionFailedError("Identified bug 47199b - duplicate PSB records should not be allowed");
} catch (org.apache.poi.util.RecordFormatException e) {
if (!e.getMessage().equals("Duplicate PageSettingsBlock record (sid=0x14)")) {
throw new AssertionFailedError("Expected RecordFormatException due to duplicate PSB record");
}
}
}
use of junit.framework.AssertionFailedError in project poi by apache.
the class TestWriteAccessRecord method testMissingStringHeader_bug47001a.
public void testMissingStringHeader_bug47001a() {
/*
* Data taken from offset 0x0224 in
* attachment 23468 from bugzilla 47001
*/
byte[] data = HexRead.readFromString("" + "5C 00 70 00 " + "4A 61 76 61 20 45 78 63 65 6C 20 41 50 49 20 76 " + "32 2E 36 2E 34" + "20 20 20 20 20 20 20 20 20 20 20 " + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " + HEX_SIXTYFOUR_SPACES);
RecordInputStream in = TestcaseRecordInputStream.create(data);
WriteAccessRecord rec;
try {
rec = new WriteAccessRecord(in);
} catch (RecordFormatException e) {
if (e.getMessage().equals("Not enough data (0) to read requested (1) bytes")) {
throw new AssertionFailedError("Identified bug 47001a");
}
throw e;
}
assertEquals("Java Excel API v2.6.4", rec.getUsername());
byte[] expectedEncoding = HexRead.readFromString("" + "15 00 00 4A 61 76 61 20 45 78 63 65 6C 20 41 50 " + "49 20 76 32 2E 36 2E 34" + "20 20 20 20 20 20 20 20 " + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " + HEX_SIXTYFOUR_SPACES);
TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
}
use of junit.framework.AssertionFailedError in project poi by apache.
the class TestcaseRecordInputStream method confirmRecordEncoding.
/**
* Confirms data sections are equal
* @param msgPrefix message prefix to be displayed in case of failure
* @param expectedData - just raw data (without ushort sid, ushort size)
* @param actualRecordBytes this includes 4 prefix bytes (sid & size)
*/
public static void confirmRecordEncoding(String msgPrefix, int expectedSid, byte[] expectedData, byte[] actualRecordBytes) throws AssertionFailedError {
int expectedDataSize = expectedData.length;
Assert.assertEquals("Size of encode data mismatch", actualRecordBytes.length - 4, expectedDataSize);
Assert.assertEquals(expectedSid, LittleEndian.getShort(actualRecordBytes, 0));
Assert.assertEquals(expectedDataSize, LittleEndian.getShort(actualRecordBytes, 2));
for (int i = 0; i < expectedDataSize; i++) if (expectedData[i] != actualRecordBytes[i + 4]) {
StringBuilder sb = new StringBuilder(64);
if (msgPrefix != null) {
sb.append(msgPrefix).append(": ");
}
sb.append("At offset ").append(i);
sb.append(": expected ").append(HexDump.byteToHex(expectedData[i]));
sb.append(" but found ").append(HexDump.byteToHex(actualRecordBytes[i + 4]));
throw new AssertionFailedError(sb.toString());
}
}
use of junit.framework.AssertionFailedError in project poi by apache.
the class TestPLVRecord method testPLVRecord.
public void testPLVRecord() throws Exception {
InputStream is = HSSFTestDataSamples.openSampleFileStream(XLS_FILENAME);
HSSFWorkbook workbook = new HSSFWorkbook(is);
CellRangeAddressList cellRange = new CellRangeAddressList(0, 0, 1, 1);
DataValidationConstraint constraint = DVConstraint.createFormulaListConstraint(DV_DEFINITION);
HSSFDataValidation dataValidation = new HSSFDataValidation(cellRange, constraint);
// This used to throw an error before
try {
workbook.getSheet(SHEET_NAME).addValidationData(dataValidation);
} catch (IllegalStateException ex) {
throw new AssertionFailedError("Identified bug 53972, PLV record breaks addDataValidation()");
}
}
use of junit.framework.AssertionFailedError in project poi by apache.
the class TestRecalcIdRecord method testBadFirstField_bug48096.
public void testBadFirstField_bug48096() {
/**
* Data taken from the sample file referenced in Bugzilla 48096, file offset 0x0D45.
* The apparent problem is that the first data short field has been written with the
* wrong <i>endianness</n>. Excel seems to ignore whatever value is present in this
* field, and always rewrites it as (C1, 01). POI now does the same.
*/
byte[] badData = HexRead.readFromString("C1 01 08 00 01 C1 00 00 00 01 69 61");
byte[] goodData = HexRead.readFromString("C1 01 08 00 C1 01 00 00 00 01 69 61");
RecordInputStream in = TestcaseRecordInputStream.create(badData);
RecalcIdRecord r;
try {
r = new RecalcIdRecord(in);
} catch (RecordFormatException e) {
if (e.getMessage().equals("expected 449 but got 49409")) {
throw new AssertionFailedError("Identified bug 48096");
}
throw e;
}
assertEquals(0, in.remaining());
assertArrayEquals(r.serialize(), goodData);
}
Aggregations