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 2019/12/27 23:00:20 UTC
svn commit: r1872041 [8/23] - in /poi/trunk/src:
excelant/testcases/org/apache/poi/ss/examples/formula/
excelant/testcases/org/apache/poi/ss/excelant/
excelant/testcases/org/apache/poi/ss/excelant/util/
java/org/apache/poi/hssf/record/aggregates/ java/...
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java Fri Dec 27 23:00:13 2019
@@ -18,19 +18,19 @@
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests the AutoFilterInfoRecord class.
- *
- * @author Yegor Kozlov
*/
-public final class TestAutoFilterInfoRecord extends TestCase {
+public final class TestAutoFilterInfoRecord {
private final byte[] data = new byte[] {
0x05, 0x00
};
+ @Test
public void testRead() {
AutoFilterInfoRecord record = new AutoFilterInfoRecord(TestcaseRecordInputStream.create(AutoFilterInfoRecord.sid, data));
@@ -42,6 +42,7 @@ public final class TestAutoFilterInfoRec
assertEquals(3, record.getNumEntries());
}
+ @Test
public void testWrite() {
AutoFilterInfoRecord record = new AutoFilterInfoRecord();
record.setNumEntries((short)3);
@@ -52,6 +53,7 @@ public final class TestAutoFilterInfoRec
assertEquals(3, record.getNumEntries());
}
+ @Test
public void testClone()
{
AutoFilterInfoRecord record = new AutoFilterInfoRecord();
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoolErrRecord.java Fri Dec 27 23:00:13 2019
@@ -18,16 +18,19 @@
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
-import org.apache.poi.hssf.record.RecordInputStream.LeftoverDataException;
import org.apache.poi.util.HexRead;
+import org.junit.Test;
+
/**
* Tests for {@link BoolErrRecord}
*/
-public final class TestBoolErrRecord extends TestCase {
+public final class TestBoolErrRecord {
+ @Test
public void testError() {
byte[] data = HexRead.readFromString(
"00 00 00 00 0F 00 " + // row, col, xfIndex
@@ -38,18 +41,19 @@ public final class TestBoolErrRecord ext
BoolErrRecord ber = new BoolErrRecord(in);
assertTrue(ber.isError());
assertEquals(7, ber.getErrorValue());
-
+
TestcaseRecordInputStream.confirmRecordEncoding(BoolErrRecord.sid, data, ber.serialize());
}
/**
- * Bugzilla 47479 was due to an apparent error in OOO which (as of version 3.0.1)
+ * Bugzilla 47479 was due to an apparent error in OOO which (as of version 3.0.1)
* writes the <i>value</i> field of BOOLERR records as 2 bytes instead of 1.<br>
- * Coincidentally, the extra byte written is zero, which is exactly the value
+ * Coincidentally, the extra byte written is zero, which is exactly the value
* required by the <i>isError</i> field. This probably why Excel seems to have
* no problem. OOO does not have the same bug for error values (which wouldn't
- * work by the same coincidence).
+ * work by the same coincidence).
*/
+ @Test
public void testOooBadFormat_bug47479() {
byte[] data = HexRead.readFromString(
"05 02 09 00 " + // sid, size
@@ -59,19 +63,11 @@ public final class TestBoolErrRecord ext
RecordInputStream in = TestcaseRecordInputStream.create(data);
BoolErrRecord ber = new BoolErrRecord(in);
- boolean hasMore;
- try {
- hasMore = in.hasNextRecord();
- } catch (LeftoverDataException e) {
- if ("Initialisation of record 0x205 left 1 bytes remaining still to be read.".equals(e.getMessage())) {
- throw new AssertionFailedError("Identified bug 47479");
- }
- throw e;
- }
+ boolean hasMore = in.hasNextRecord();
assertFalse(hasMore);
assertTrue(ber.isBoolean());
assertTrue(ber.getBooleanValue());
-
+
// Check that the record re-serializes correctly
byte[] outData = ber.serialize();
byte[] expData = HexRead.readFromString(
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java Fri Dec 27 23:00:13 2019
@@ -18,46 +18,40 @@
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.poi.util.HexRead;
+import org.junit.Test;
/**
* Tests BoundSheetRecord.
- *
- * @see BoundSheetRecord
- *
- * @author Glen Stampoultzis (glens at apache.org)
*/
-public final class TestBoundSheetRecord extends TestCase {
-
+public final class TestBoundSheetRecord {
+ @Test
public void testRecordLength() {
BoundSheetRecord record = new BoundSheetRecord("Sheet1");
assertEquals(18, record.getRecordSize());
}
+ @Test
public void testWideRecordLength() {
BoundSheetRecord record = new BoundSheetRecord("Sheet\u20ac");
assertEquals(24, record.getRecordSize());
}
+ @Test(expected = IllegalArgumentException.class)
public void testName() {
BoundSheetRecord record = new BoundSheetRecord("1234567890223456789032345678904");
-
- try {
- record.setSheetname("s//*s");
- fail("Should have thrown IllegalArgumentException, but didnt");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ record.setSheetname("s//*s");
}
+ @Test
public void testDeserializeUnicode() {
byte[] data = HexRead.readFromString(""
@@ -80,6 +74,7 @@ public final class TestBoundSheetRecord
assertArrayEquals(data, data2);
}
+ @Test
public void testOrdering() {
BoundSheetRecord bs1 = new BoundSheetRecord("SheetB");
BoundSheetRecord bs2 = new BoundSheetRecord("SheetC");
@@ -100,32 +95,28 @@ public final class TestBoundSheetRecord
assertEquals(bs2, r[2]);
}
+ @Test
public void testValidNames() {
- confirmValid("Sheet1", true);
- confirmValid("O'Brien's sales", true);
- confirmValid(" data # ", true);
- confirmValid("data $1.00", true);
-
- confirmValid("data?", false);
- confirmValid("abc/def", false);
- confirmValid("data[0]", false);
- confirmValid("data*", false);
- confirmValid("abc\\def", false);
- confirmValid("'data", false);
- confirmValid("data'", false);
+ assertTrue(isValid("Sheet1"));
+ assertTrue(isValid("O'Brien's sales"));
+ assertTrue(isValid(" data # "));
+ assertTrue(isValid("data $1.00"));
+
+ assertFalse(isValid("data?"));
+ assertFalse(isValid("abc/def"));
+ assertFalse(isValid("data[0]"));
+ assertFalse(isValid("data*"));
+ assertFalse(isValid("abc\\def"));
+ assertFalse(isValid("'data"));
+ assertFalse(isValid("data'"));
}
- private static void confirmValid(String sheetName, boolean expectedResult) {
-
+ private static boolean isValid(String sheetName) {
try {
new BoundSheetRecord(sheetName);
- if (!expectedResult) {
- throw new AssertionFailedError("Expected sheet name '" + sheetName + "' to be invalid");
- }
+ return true;
} catch (IllegalArgumentException e) {
- if (expectedResult) {
- throw new AssertionFailedError("Expected sheet name '" + sheetName + "' to be valid");
- }
+ return false;
}
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java Fri Dec 27 23:00:13 2019
@@ -17,16 +17,20 @@
package org.apache.poi.hssf.record;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.apache.poi.ss.util.CellRangeAddress;
+import org.junit.Test;
/**
* Tests the serialization and deserialization of the {@link CFHeaderRecord}
- * and {@link CFHeader12Record} classes works correctly.
+ * and {@link CFHeader12Record} classes works correctly.
*/
-public final class TestCFHeaderRecord extends TestCase {
+public final class TestCFHeaderRecord {
+ @Test
public void testCreateCFHeaderRecord () {
CFHeaderRecord record = new CFHeaderRecord();
CellRangeAddress[] ranges = {
@@ -48,17 +52,18 @@ public final class TestCFHeaderRecord ex
assertFalse(record.getNeedRecalculation());
assertEquals(0, record.getID());
-
+
record.setNeedRecalculation(true);
assertTrue(record.getNeedRecalculation());
assertEquals(0, record.getID());
-
+
record.setID(7);
record.setNeedRecalculation(false);
assertFalse(record.getNeedRecalculation());
assertEquals(7, record.getID());
}
-
+
+ @Test
public void testCreateCFHeader12Record () {
CFHeader12Record record = new CFHeader12Record();
CellRangeAddress[] ranges = {
@@ -80,45 +85,46 @@ public final class TestCFHeaderRecord ex
assertFalse(record.getNeedRecalculation());
assertEquals(0, record.getID());
-
+
record.setNeedRecalculation(true);
assertTrue(record.getNeedRecalculation());
assertEquals(0, record.getID());
-
+
record.setID(7);
record.setNeedRecalculation(false);
assertFalse(record.getNeedRecalculation());
assertEquals(7, record.getID());
}
-
+
+ @Test
public void testSerialization() {
- byte[] recordData =
+ byte[] recordData =
{
(byte)0x03, (byte)0x00,
(byte)0x01, (byte)0x00,
-
+
(byte)0x00, (byte)0x00,
(byte)0x03, (byte)0x00,
(byte)0x00, (byte)0x00,
(byte)0x03, (byte)0x00,
-
+
(byte)0x04, (byte)0x00, // nRegions
-
+
(byte)0x00, (byte)0x00,
(byte)0x01, (byte)0x00,
(byte)0x00, (byte)0x00,
(byte)0x01, (byte)0x00,
-
+
(byte)0x00, (byte)0x00,
(byte)0x01, (byte)0x00,
(byte)0x02, (byte)0x00,
(byte)0x03, (byte)0x00,
-
+
(byte)0x02, (byte)0x00,
(byte)0x03, (byte)0x00,
(byte)0x00, (byte)0x00,
(byte)0x01, (byte)0x00,
-
+
(byte)0x02, (byte)0x00,
(byte)0x03, (byte)0x00,
(byte)0x02, (byte)0x00,
@@ -139,52 +145,40 @@ public final class TestCFHeaderRecord ex
assertEquals(recordData.length+4, record.getRecordSize());
byte[] output = record.serialize();
-
- assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
-
- for (int i = 0; i < recordData.length; i++)
- {
- assertEquals("CFHeaderRecord doesn't match", recordData[i], output[i+4]);
- }
+ confirmRecordEncoding(CFHeaderRecord.sid, recordData, output);
}
-
+
+ @Test
public void testExtremeRows() {
byte[] recordData = {
(byte)0x13, (byte)0x00, // nFormats
(byte)0x00, (byte)0x00,
-
+
(byte)0x00, (byte)0x00,
(byte)0xFF, (byte)0xFF,
(byte)0x00, (byte)0x00,
(byte)0xFF, (byte)0x00,
-
+
(byte)0x03, (byte)0x00, // nRegions
-
+
(byte)0x40, (byte)0x9C,
(byte)0x50, (byte)0xC3,
(byte)0x02, (byte)0x00,
(byte)0x02, (byte)0x00,
-
+
(byte)0x00, (byte)0x00,
(byte)0xFF, (byte)0xFF,
(byte)0x05, (byte)0x00,
(byte)0x05, (byte)0x00,
-
+
(byte)0x07, (byte)0x00,
(byte)0x07, (byte)0x00,
(byte)0x00, (byte)0x00,
(byte)0xFF, (byte)0x00,
};
- CFHeaderRecord record;
- try {
- record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData));
- } catch (IllegalArgumentException e) {
- if(e.getMessage().equals("invalid cell range (-25536, 2, -15536, 2)")) {
- throw new AssertionFailedError("Identified bug 44739b");
- }
- throw e;
- }
+ // bug 44739b - invalid cell range (-25536, 2, -15536, 2)
+ CFHeaderRecord record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData));
assertEquals("#CFRULES", 19, record.getNumberOfConditionalFormats());
assertFalse(record.getNeedRecalculation());
@@ -196,12 +190,7 @@ public final class TestCFHeaderRecord ex
confirm(ranges[2], 7, 7, 0, 255);
byte[] output = record.serialize();
-
- assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
-
- for (int i = 0; i < recordData.length;i++) {
- assertEquals("CFHeaderRecord doesn't match", recordData[i], output[i+4]);
- }
+ confirmRecordEncoding(CFHeaderRecord.sid, recordData, output);
}
private static void confirm(CellRangeAddress cr, int expFirstRow, int expLastRow, int expFirstCol, int expLastColumn) {
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java Fri Dec 27 23:00:13 2019
@@ -17,6 +17,7 @@
package org.apache.poi.hssf.record;
+import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -26,7 +27,6 @@ import static org.junit.Assert.assertTru
import java.io.IOException;
-import junit.framework.AssertionFailedError;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator;
import org.apache.poi.hssf.record.cf.BorderFormatting;
@@ -50,126 +50,108 @@ import org.junit.Test;
public final class TestCFRuleRecord {
@Test
public void testConstructors () throws IOException {
- HSSFWorkbook workbook = new HSSFWorkbook();
- HSSFSheet sheet = workbook.createSheet();
+ try (HSSFWorkbook workbook = new HSSFWorkbook()) {
+ HSSFSheet sheet = workbook.createSheet();
- CFRuleRecord rule1 = CFRuleRecord.create(sheet, "7");
- assertEquals(CFRuleBase.CONDITION_TYPE_FORMULA, rule1.getConditionType());
- assertEquals(ComparisonOperator.NO_COMPARISON, rule1.getComparisonOperation());
- assertNotNull(rule1.getParsedExpression1());
- assertSame(Ptg.EMPTY_PTG_ARRAY, rule1.getParsedExpression2());
-
- CFRuleRecord rule2 = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
- assertEquals(CFRuleBase.CONDITION_TYPE_CELL_VALUE_IS, rule2.getConditionType());
- assertEquals(ComparisonOperator.BETWEEN, rule2.getComparisonOperation());
- assertNotNull(rule2.getParsedExpression1());
- assertNotNull(rule2.getParsedExpression2());
-
- CFRuleRecord rule3 = CFRuleRecord.create(sheet, ComparisonOperator.EQUAL, null, null);
- assertEquals(CFRuleBase.CONDITION_TYPE_CELL_VALUE_IS, rule3.getConditionType());
- assertEquals(ComparisonOperator.EQUAL, rule3.getComparisonOperation());
- assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2());
- assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2());
- workbook.close();
+ CFRuleRecord rule1 = CFRuleRecord.create(sheet, "7");
+ assertEquals(CFRuleBase.CONDITION_TYPE_FORMULA, rule1.getConditionType());
+ assertEquals(ComparisonOperator.NO_COMPARISON, rule1.getComparisonOperation());
+ assertNotNull(rule1.getParsedExpression1());
+ assertSame(Ptg.EMPTY_PTG_ARRAY, rule1.getParsedExpression2());
+
+ CFRuleRecord rule2 = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
+ assertEquals(CFRuleBase.CONDITION_TYPE_CELL_VALUE_IS, rule2.getConditionType());
+ assertEquals(ComparisonOperator.BETWEEN, rule2.getComparisonOperation());
+ assertNotNull(rule2.getParsedExpression1());
+ assertNotNull(rule2.getParsedExpression2());
+
+ CFRuleRecord rule3 = CFRuleRecord.create(sheet, ComparisonOperator.EQUAL, null, null);
+ assertEquals(CFRuleBase.CONDITION_TYPE_CELL_VALUE_IS, rule3.getConditionType());
+ assertEquals(ComparisonOperator.EQUAL, rule3.getComparisonOperation());
+ assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2());
+ assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2());
+ }
}
@Test
public void testCreateCFRuleRecord() throws IOException {
- HSSFWorkbook workbook = new HSSFWorkbook();
- HSSFSheet sheet = workbook.createSheet();
- CFRuleRecord record = CFRuleRecord.create(sheet, "7");
- testCFRuleRecord(record);
-
- // Serialize
- byte [] serializedRecord = record.serialize();
-
- // Strip header
- byte [] recordData = new byte[serializedRecord.length-4];
- System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
-
- // Deserialize
- record = new CFRuleRecord(TestcaseRecordInputStream.create(CFRuleRecord.sid, recordData));
-
- // Serialize again
- byte[] output = record.serialize();
-
- // Compare
- assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
-
- for (int i = 0; i < recordData.length;i++) {
- assertEquals("CFRuleRecord doesn't match", recordData[i], output[i+4]);
+ try (HSSFWorkbook workbook = new HSSFWorkbook()) {
+ HSSFSheet sheet = workbook.createSheet();
+ CFRuleRecord record = CFRuleRecord.create(sheet, "7");
+ testCFRuleRecord(record);
+
+ // Serialize
+ byte[] serializedRecord = record.serialize();
+
+ // Strip header
+ byte[] recordData = new byte[serializedRecord.length - 4];
+ System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
+
+ // Deserialize
+ record = new CFRuleRecord(TestcaseRecordInputStream.create(CFRuleRecord.sid, recordData));
+
+ // Serialize again
+ byte[] output = record.serialize();
+ confirmRecordEncoding(CFRuleRecord.sid, recordData, output);
}
- workbook.close();
}
@Test
public void testCreateCFRule12Record() throws IOException {
- HSSFWorkbook workbook = new HSSFWorkbook();
- HSSFSheet sheet = workbook.createSheet();
- CFRule12Record record = CFRule12Record.create(sheet, "7");
- testCFRule12Record(record);
-
- // Serialize
- byte [] serializedRecord = record.serialize();
-
- // Strip header
- byte [] recordData = new byte[serializedRecord.length-4];
- System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
-
- // Deserialize
- record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid, recordData));
-
- // Serialize again
- byte[] output = record.serialize();
-
- // Compare
- assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
-
- for (int i = 0; i < recordData.length;i++) {
- assertEquals("CFRule12Record doesn't match", recordData[i], output[i+4]);
+ try (HSSFWorkbook workbook = new HSSFWorkbook()) {
+ HSSFSheet sheet = workbook.createSheet();
+ CFRule12Record record = CFRule12Record.create(sheet, "7");
+ testCFRule12Record(record);
+
+ // Serialize
+ byte[] serializedRecord = record.serialize();
+
+ // Strip header
+ byte[] recordData = new byte[serializedRecord.length - 4];
+ System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
+
+ // Deserialize
+ record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid, recordData));
+
+ // Serialize again
+ byte[] output = record.serialize();
+ confirmRecordEncoding(CFRule12Record.sid, recordData, output);
}
- workbook.close();
}
@Test
public void testCreateIconCFRule12Record() throws IOException {
- HSSFWorkbook workbook = new HSSFWorkbook();
- HSSFSheet sheet = workbook.createSheet();
- CFRule12Record record = CFRule12Record.create(sheet, IconSet.GREY_5_ARROWS);
- record.getMultiStateFormatting().getThresholds()[1].setType(RangeType.PERCENT.id);
- record.getMultiStateFormatting().getThresholds()[1].setValue(10d);
- record.getMultiStateFormatting().getThresholds()[2].setType(RangeType.NUMBER.id);
- record.getMultiStateFormatting().getThresholds()[2].setValue(-4d);
-
- // Check it
- testCFRule12Record(record);
- assertEquals(IconSet.GREY_5_ARROWS, record.getMultiStateFormatting().getIconSet());
- assertEquals(5, record.getMultiStateFormatting().getThresholds().length);
-
- // Serialize
- byte [] serializedRecord = record.serialize();
-
- // Strip header
- byte [] recordData = new byte[serializedRecord.length-4];
- System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
-
- // Deserialize
- record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid, recordData));
-
- // Check it has the icon, and the right number of thresholds
- assertEquals(IconSet.GREY_5_ARROWS, record.getMultiStateFormatting().getIconSet());
- assertEquals(5, record.getMultiStateFormatting().getThresholds().length);
-
- // Serialize again
- byte[] output = record.serialize();
-
- // Compare
- assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
-
- for (int i = 0; i < recordData.length;i++) {
- assertEquals("CFRule12Record doesn't match", recordData[i], output[i+4]);
+ try (HSSFWorkbook workbook = new HSSFWorkbook()) {
+ HSSFSheet sheet = workbook.createSheet();
+ CFRule12Record record = CFRule12Record.create(sheet, IconSet.GREY_5_ARROWS);
+ record.getMultiStateFormatting().getThresholds()[1].setType(RangeType.PERCENT.id);
+ record.getMultiStateFormatting().getThresholds()[1].setValue(10d);
+ record.getMultiStateFormatting().getThresholds()[2].setType(RangeType.NUMBER.id);
+ record.getMultiStateFormatting().getThresholds()[2].setValue(-4d);
+
+ // Check it
+ testCFRule12Record(record);
+ assertEquals(IconSet.GREY_5_ARROWS, record.getMultiStateFormatting().getIconSet());
+ assertEquals(5, record.getMultiStateFormatting().getThresholds().length);
+
+ // Serialize
+ byte[] serializedRecord = record.serialize();
+
+ // Strip header
+ byte[] recordData = new byte[serializedRecord.length - 4];
+ System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
+
+ // Deserialize
+ record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid, recordData));
+
+ // Check it has the icon, and the right number of thresholds
+ assertEquals(IconSet.GREY_5_ARROWS, record.getMultiStateFormatting().getIconSet());
+ assertEquals(5, record.getMultiStateFormatting().getThresholds().length);
+
+ // Serialize again
+ byte[] output = record.serialize();
+ confirmRecordEncoding(CFRule12Record.sid, recordData, output);
}
- workbook.close();
}
private void testCFRuleRecord(CFRuleRecord record) {
@@ -391,25 +373,25 @@ public final class TestCFRuleRecord {
@Test
public void testWrite() throws IOException {
- HSSFWorkbook workbook = new HSSFWorkbook();
- HSSFSheet sheet = workbook.createSheet();
- CFRuleRecord rr = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "5", "10");
-
- PatternFormatting patternFormatting = new PatternFormatting();
- patternFormatting.setFillPattern(PatternFormatting.BRICKS);
- rr.setPatternFormatting(patternFormatting);
-
- byte[] data = rr.serialize();
- assertEquals(26, data.length);
- assertEquals(3, LittleEndian.getShort(data, 6));
- assertEquals(3, LittleEndian.getShort(data, 8));
-
- int flags = LittleEndian.getInt(data, 10);
- assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000);
- assertEquals("undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy
- // check all remaining flag bits (some are not well understood yet)
- assertEquals(0x203FFFFF, flags);
- workbook.close();
+ try (HSSFWorkbook workbook = new HSSFWorkbook()) {
+ HSSFSheet sheet = workbook.createSheet();
+ CFRuleRecord rr = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "5", "10");
+
+ PatternFormatting patternFormatting = new PatternFormatting();
+ patternFormatting.setFillPattern(PatternFormatting.BRICKS);
+ rr.setPatternFormatting(patternFormatting);
+
+ byte[] data = rr.serialize();
+ assertEquals(26, data.length);
+ assertEquals(3, LittleEndian.getShort(data, 6));
+ assertEquals(3, LittleEndian.getShort(data, 8));
+
+ int flags = LittleEndian.getInt(data, 10);
+ assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000);
+ assertEquals("undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy
+ // check all remaining flag bits (some are not well understood yet)
+ assertEquals(0x203FFFFF, flags);
+ }
}
private static final byte[] DATA_REFN = {
@@ -433,9 +415,7 @@ public final class TestCFRuleRecord {
CFRuleRecord rr = new CFRuleRecord(is);
Ptg[] ptgs = rr.getParsedExpression1();
assertEquals(3, ptgs.length);
- if (ptgs[0] instanceof RefPtg) {
- throw new AssertionFailedError("Identified bug 45234");
- }
+ assertFalse("Identified bug 45234", ptgs[0] instanceof RefPtg);
assertEquals(RefNPtg.class, ptgs[0].getClass());
RefNPtg refNPtg = (RefNPtg) ptgs[0];
assertTrue(refNPtg.isColRelative());
@@ -447,26 +427,26 @@ public final class TestCFRuleRecord {
@Test
public void testBug53691() throws IOException {
- HSSFWorkbook workbook = new HSSFWorkbook();
- HSSFSheet sheet = workbook.createSheet();
+ try (HSSFWorkbook workbook = new HSSFWorkbook()) {
+ HSSFSheet sheet = workbook.createSheet();
- CFRuleRecord record = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
+ CFRuleRecord record = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
- CFRuleRecord clone = record.copy();
+ CFRuleRecord clone = record.copy();
- byte [] serializedRecord = record.serialize();
- byte [] serializedClone = clone.serialize();
- assertArrayEquals(serializedRecord, serializedClone);
- workbook.close();
+ byte[] serializedRecord = record.serialize();
+ byte[] serializedClone = clone.serialize();
+ assertArrayEquals(serializedRecord, serializedClone);
+ }
}
@Test
public void testBug57231_rewrite() throws IOException {
- HSSFWorkbook wb1 = HSSFITestDataProvider.instance.openSampleWorkbook("57231_MixedGasReport.xls");
- assertEquals(7, wb1.getNumberOfSheets());
- HSSFWorkbook wb2 = HSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
- assertEquals(7, wb2.getNumberOfSheets());
- wb2.close();
- wb1.close();
+ try (HSSFWorkbook wb1 = HSSFITestDataProvider.instance.openSampleWorkbook("57231_MixedGasReport.xls")) {
+ assertEquals(7, wb1.getNumberOfSheets());
+ try (HSSFWorkbook wb2 = HSSFITestDataProvider.instance.writeOutAndReadBack(wb1)) {
+ assertEquals(7, wb2.getNumberOfSheets());
+ }
+ }
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestColumnInfoRecord.java Fri Dec 27 23:00:13 2019
@@ -18,18 +18,18 @@
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import org.apache.poi.util.HexRead;
+import org.junit.Test;
/**
* Tests for {@link ColumnInfoRecord}
- *
- * @author Josh Micich
*/
-public final class TestColumnInfoRecord extends TestCase {
+public final class TestColumnInfoRecord {
+ @Test
public void testBasic() {
byte[] data = HexRead.readFromString("7D 00 0C 00 14 00 9B 00 C7 19 0F 00 01 13 00 00");
@@ -52,21 +52,15 @@ public final class TestColumnInfoRecord
* The attached file was apparently created by "SoftArtisans OfficeWriter for Excel".
* Excel reads that file OK and assumes zero for the value of the reserved field.
*/
+ @Test
public void testZeroResevedBytes_bug48332() {
// Taken from bugzilla attachment 24661 (offset 0x1E73)
byte[] inpData = HexRead.readFromString("7D 00 0A 00 00 00 00 00 D5 19 0F 00 02 00");
byte[] outData = HexRead.readFromString("7D 00 0C 00 00 00 00 00 D5 19 0F 00 02 00 00 00");
RecordInputStream in = TestcaseRecordInputStream.create(inpData);
- ColumnInfoRecord cir;
- try {
- cir = new ColumnInfoRecord(in);
- } catch (RuntimeException e) {
- if (e.getMessage().equals("Unusual record size remaining=(0)")) {
- throw new AssertionFailedError("Identified bug 48332");
- }
- throw e;
- }
+ // bug 48332 - Unusual record size remaining=(0)
+ ColumnInfoRecord cir = new ColumnInfoRecord(in);
assertEquals(0, in.remaining());
assertArrayEquals(outData, cir.serialize());
}
@@ -76,6 +70,7 @@ public final class TestColumnInfoRecord
* OddStyleRecord.xls, NoGutsRecords.xls, WORKBOOK_in_capitals.xls
* but this seems to cause no problem to Excel
*/
+ @Test
public void testOneReservedByte() {
byte[] inpData = HexRead.readFromString("7D 00 0B 00 00 00 00 00 24 02 0F 00 00 00 01");
byte[] outData = HexRead.readFromString("7D 00 0C 00 00 00 00 00 24 02 0F 00 00 00 01 00");
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java Fri Dec 27 23:00:13 2019
@@ -18,16 +18,19 @@
package org.apache.poi.hssf.record;
-import junit.framework.TestCase;
+import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
/**
* Tests the serialization and deserialization of the {@link CommonObjectDataSubRecord}
* class works correctly. Test data taken directly from a real
* Excel file.
- *
- * @author Glen Stampoultzis (glens at apache.org)
*/
-public final class TestCommonObjectDataSubRecord extends TestCase {
+public final class TestCommonObjectDataSubRecord {
byte[] data = new byte[] {
(byte)0x12,(byte)0x00,(byte)0x01,(byte)0x00,
(byte)0x01,(byte)0x00,(byte)0x11,(byte)0x60,
@@ -36,6 +39,7 @@ public final class TestCommonObjectDataS
(byte)0x00,(byte)0x00,
};
+ @Test
public void testLoad() {
CommonObjectDataSubRecord record = new CommonObjectDataSubRecord(TestcaseRecordInputStream.createLittleEndian(data), data.length);
@@ -52,6 +56,7 @@ public final class TestCommonObjectDataS
assertEquals(18, record.getDataSize());
}
+ @Test
public void testStore() {
CommonObjectDataSubRecord record = new CommonObjectDataSubRecord();
@@ -66,9 +71,7 @@ public final class TestCommonObjectDataS
record.setReserved2(218103808);
record.setReserved3(294);
- byte [] recordBytes = record.serialize();
- assertEquals(recordBytes.length - 4, data.length);
- for (int i = 0; i < data.length; i++)
- assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+ byte[] recordBytes = record.serialize();
+ confirmRecordEncoding(CommonObjectDataSubRecord.sid, data, recordBytes);
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java Fri Dec 27 23:00:13 2019
@@ -19,27 +19,27 @@
package org.apache.poi.hssf.record;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
-import junit.framework.TestCase;
-import org.apache.poi.util.LittleEndianOutputStream;
-import static org.junit.Assert.assertArrayEquals;
+import org.apache.poi.util.LittleEndianOutputStream;
+import org.junit.Test;
/**
* Unit tests for DConRefRecord class.
- *
- * @author Niklas Rehfeld
*/
-public class TestDConRefRecord extends TestCase
-{
+public class TestDConRefRecord {
/**
* record of a proper single-byte external 'volume'-style path with multiple parts and a sheet
* name.
*/
- final byte[] volumeString = new byte[]
- {
+ final byte[] volumeString = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
17, 0,//cchFile (2 bytes)
0, //char type
@@ -51,8 +51,7 @@ public class TestDConRefRecord extends T
* record of a proper single-byte external 'unc-volume'-style path with multiple parts and a
* sheet name.
*/
- final byte[] uncVolumeString = new byte[]
- {
+ final byte[] uncVolumeString = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
34, 0,//cchFile (2 bytes)
0, //char type
@@ -65,8 +64,7 @@ public class TestDConRefRecord extends T
/**
* record of a proper single-byte external 'simple-file-path-dcon' style path with a sheet name.
*/
- final byte[] simpleFilePathDconString = new byte[]
- {
+ final byte[] simpleFilePathDconString = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
16, 0,//cchFile (2 bytes)
0, //char type
@@ -77,8 +75,7 @@ public class TestDConRefRecord extends T
* record of a proper 'transfer-protocol'-style path. This one has a sheet name at the end, and
* another one inside the file path. The spec doesn't seem to care about what they are.
*/
- final byte[] transferProtocolString = new byte[]
- {
+ final byte[] transferProtocolString = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
33, 0,//cchFile (2 bytes)
0, //char type
@@ -91,8 +88,7 @@ public class TestDConRefRecord extends T
/**
* startup-type path.
*/
- final byte[] relVolumeString = new byte[]
- {
+ final byte[] relVolumeString = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
16, 0,//cchFile (2 bytes)
0, //char type
@@ -102,8 +98,7 @@ public class TestDConRefRecord extends T
/**
* startup-type path.
*/
- final byte[] startupString = new byte[]
- {
+ final byte[] startupString = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
16, 0,//cchFile (2 bytes)
0, //char type
@@ -113,8 +108,7 @@ public class TestDConRefRecord extends T
/**
* alt-startup-type path.
*/
- final byte[] altStartupString = new byte[]
- {
+ final byte[] altStartupString = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
16, 0,//cchFile (2 bytes)
0, //char type
@@ -124,8 +118,7 @@ public class TestDConRefRecord extends T
/**
* library-style path.
*/
- final byte[] libraryString = new byte[]
- {
+ final byte[] libraryString = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
16, 0,//cchFile (2 bytes)
0, //char type
@@ -135,8 +128,7 @@ public class TestDConRefRecord extends T
/**
* record of single-byte string, external, volume path.
*/
- final byte[] data1 = new byte[]
- {
+ final byte[] data1 = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
10, 0,//cchFile (2 bytes)
0, //char type
@@ -147,8 +139,7 @@ public class TestDConRefRecord extends T
/**
* record of double-byte string, self-reference.
*/
- final byte[] data2 = new byte[]
- {
+ final byte[] data2 = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
9, 0,//cchFile (2 bytes)
1, //char type = unicode
@@ -159,8 +150,7 @@ public class TestDConRefRecord extends T
/**
* record of single-byte string, self-reference.
*/
- final byte[] data3 = new byte[]
- {
+ final byte[] data3 = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
9, 0,//cchFile (2 bytes)
0, //char type = ansi
@@ -171,8 +161,7 @@ public class TestDConRefRecord extends T
/**
* double-byte string, external reference, unc-volume.
*/
- final byte[] data4 = new byte[]
- {
+ final byte[] data4 = {
0, 0, 0, 0, 0, 0, //ref (6 bytes) not used...
16, 0,//cchFile (2 bytes)
//stFile starts here:
@@ -187,8 +176,8 @@ public class TestDConRefRecord extends T
* test read-constructor-then-serialize for a single-byte external reference strings of
* various flavours. This uses the RecordInputStream constructor.
*/
- public void testReadWriteSBExtRef() throws IOException
- {
+ @Test
+ public void testReadWriteSBExtRef() throws IOException {
testReadWrite(data1, "read-write single-byte external reference, volume type path");
testReadWrite(volumeString,
"read-write properly formed single-byte external reference, volume type path");
@@ -212,13 +201,12 @@ public class TestDConRefRecord extends T
* test read-constructor-then-serialize for a double-byte external reference 'UNC-Volume' style
* string
*/
- public void testReadWriteDBExtRefUncVol() throws IOException
- {
+ @Test
+ public void testReadWriteDBExtRefUncVol() throws IOException {
testReadWrite(data4, "read-write double-byte external reference, UNC volume type path");
}
- private void testReadWrite(byte[] data, String message) throws IOException
- {
+ private void testReadWrite(byte[] data, String message) throws IOException {
RecordInputStream is = TestcaseRecordInputStream.create(81, data);
DConRefRecord d = new DConRefRecord(is);
ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
@@ -232,24 +220,24 @@ public class TestDConRefRecord extends T
/**
* test read-constructor-then-serialize for a double-byte self-reference style string
*/
- public void testReadWriteDBSelfRef() throws IOException
- {
+ @Test
+ public void testReadWriteDBSelfRef() throws IOException {
testReadWrite(data2, "read-write double-byte self reference");
}
/**
* test read-constructor-then-serialize for a single-byte self-reference style string
*/
- public void testReadWriteSBSelfRef() throws IOException
- {
+ @Test
+ public void testReadWriteSBSelfRef() throws IOException {
testReadWrite(data3, "read-write single byte self reference");
}
/**
* Test of getDataSize method, of class DConRefRecord.
*/
- public void testGetDataSize()
- {
+ @Test
+ public void testGetDataSize() {
DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
int expResult = data1.length;
int result = instance.getDataSize();
@@ -266,8 +254,8 @@ public class TestDConRefRecord extends T
/**
* Test of getSid method, of class DConRefRecord.
*/
- public void testGetSid()
- {
+ @Test
+ public void testGetSid() {
DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
short expResult = 81;
short result = instance.getSid();
@@ -276,10 +264,10 @@ public class TestDConRefRecord extends T
/**
* Test of getPath method, of class DConRefRecord.
- * @todo different types of paths.
*/
- public void testGetPath()
- {
+ @Test
+ public void testGetPath() {
+ // TODO: different types of paths.
DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
byte[] expResult = Arrays.copyOfRange(data1, 9, data1.length);
byte[] result = instance.getPath();
@@ -289,8 +277,8 @@ public class TestDConRefRecord extends T
/**
* Test of isExternalRef method, of class DConRefRecord.
*/
- public void testIsExternalRef()
- {
+ @Test
+ public void testIsExternalRef() {
DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
assertTrue("external reference", instance.isExternalRef());
instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data2));
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDVALRecord.java Fri Dec 27 23:00:13 2019
@@ -17,19 +17,17 @@
package org.apache.poi.hssf.record;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
import java.io.ByteArrayInputStream;
import org.apache.poi.util.LittleEndian;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-/**
- *
- * @author Josh Micich
- */
-public final class TestDVALRecord extends TestCase {
+public final class TestDVALRecord {
+ @Test
public void testRead() {
-
byte[] data = new byte[22];
LittleEndian.putShort(data, 0, DVALRecord.sid);
LittleEndian.putShort(data, 2, (short)18);
@@ -38,18 +36,16 @@ public final class TestDVALRecord extend
LittleEndian.putInt(data, 10, 57);
LittleEndian.putInt(data, 14, 58);
LittleEndian.putInt(data, 18, 59);
-
+
RecordInputStream in = new RecordInputStream(new ByteArrayInputStream(data));
in.nextRecord();
DVALRecord dv = new DVALRecord(in);
-
+
assertEquals(55, dv.getOptions());
assertEquals(56, dv.getHorizontalPos());
assertEquals(57, dv.getVerticalPos());
assertEquals(58, dv.getObjectID());
- if(dv.getDVRecNo() == 0) {
- fail("Identified bug 44510");
- }
+ assertNotEquals("Identified bug 44510",0, dv.getDVRecNo());
assertEquals(59, dv.getDVRecNo());
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java Fri Dec 27 23:00:13 2019
@@ -17,15 +17,19 @@
package org.apache.poi.hssf.record;
-import junit.framework.TestCase;
+import static org.apache.poi.hssf.record.TestcaseRecordInputStream.cut;
+import static org.junit.Assert.assertEquals;
+
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.util.HexDump;
+import org.junit.Test;
-public final class TestDrawingGroupRecord extends TestCase {
+public final class TestDrawingGroupRecord {
private static final int MAX_RECORD_SIZE = 8228;
private static final int MAX_DATA_SIZE = MAX_RECORD_SIZE - 4;
+ @Test
public void testGetRecordSize() {
DrawingGroupRecord r = new DrawingGroupRecord();
assertEquals(4, r.getRecordSize());
@@ -62,6 +66,7 @@ public final class TestDrawingGroupRecor
assertEquals( MAX_RECORD_SIZE * 2 + 5, r.getRecordSize() );
}
+ @Test
public void testSerialize() {
// Check under max record size
DrawingGroupRecord r = new DrawingGroupRecord();
@@ -112,21 +117,8 @@ public final class TestDrawingGroupRecor
assertEquals( 664856, r.getRecordSize() );
}
- private static byte[] cut( byte[] data, int fromInclusive, int toExclusive )
- {
- int length = toExclusive - fromInclusive;
- byte[] result = new byte[length];
- System.arraycopy( data, fromInclusive, result, 0, length);
- return result;
- }
-
+ @Test
public void testGrossSizeFromDataSize() {
- for (int i = 0; i < MAX_RECORD_SIZE * 4; i += 11)
- {
- //System.out.print( "data size = " + i + ", gross size = " + DrawingGroupRecord.grossSizeFromDataSize( i ) );
- //System.out.println( " Diff: " + (DrawingGroupRecord.grossSizeFromDataSize( i ) - i) );
- }
-
assertEquals( 4, DrawingGroupRecord.grossSizeFromDataSize( 0 ) );
assertEquals( 5, DrawingGroupRecord.grossSizeFromDataSize( 1 ) );
assertEquals( MAX_RECORD_SIZE, DrawingGroupRecord.grossSizeFromDataSize( MAX_DATA_SIZE ) );
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestDrawingRecord.java Fri Dec 27 23:00:13 2019
@@ -18,6 +18,8 @@
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -25,14 +27,15 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
+import org.junit.Test;
-public final class TestDrawingRecord extends TestCase {
+public final class TestDrawingRecord {
/**
* Check that RecordFactoryInputStream properly handles continued DrawingRecords
* See Bugzilla #47548
*/
+ @Test
public void testReadContinued() throws IOException {
//simulate a continues drawing record
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java Fri Dec 27 23:00:13 2019
@@ -17,25 +17,22 @@
package org.apache.poi.hssf.record;
+import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import org.apache.poi.util.HexRead;
-import org.apache.poi.util.RecordFormatException;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests the serialization and deserialization of the TestEmbeddedObjectRefSubRecord
- * class works correctly. Test data taken directly from a real
- * Excel file.
- *
- * @author Yegor Kozlov
+ * class works correctly. Test data taken directly from a real Excel file.
*/
-public final class TestEmbeddedObjectRefSubRecord extends TestCase {
+public final class TestEmbeddedObjectRefSubRecord {
private static final short EORSR_SID = EmbeddedObjectRefSubRecord.sid;
+ @Test
public void testStore() {
String data1
= "20 00 05 00 FC 10 76 01 02 24 14 DF 00 03 10 00 "
@@ -53,29 +50,15 @@ public final class TestEmbeddedObjectRef
RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
-
- confirmData(src, ser);
+ confirmRecordEncoding(EmbeddedObjectRefSubRecord.sid, src, ser);
assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
byte[] ser2 = record1.serialize();
assertArrayEquals(ser, ser2);
}
- /**
- * @param expectedData does not include sid & size
- * @param actualFullRecordData includes sid & size
- */
- private static void confirmData(byte[] expectedData, byte[] actualFullRecordData) {
- assertEquals(expectedData.length, actualFullRecordData.length-4);
- for (int i = 0; i < expectedData.length; i++) {
- if(expectedData[i] != actualFullRecordData[i+4]) {
- throw new AssertionFailedError("Difference at offset (" + i + ")");
- }
- }
- }
-
+ @Test
public void testCreate() {
-
EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord();
byte[] ser = record1.serialize();
@@ -89,8 +72,9 @@ public final class TestEmbeddedObjectRef
assertArrayEquals(ser, ser2);
}
+ @Test
public void testCameraTool_bug45912() {
- /**
+ /*
* taken from ftPictFmla sub-record in attachment 22645 (offset 0x40AB).
*/
byte[] data45912 = hr(
@@ -101,7 +85,7 @@ public final class TestEmbeddedObjectRef
EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data45912.length);
byte[] ser2 = rec.serialize();
- confirmData(data45912, ser2);
+ confirmRecordEncoding(EmbeddedObjectRefSubRecord.sid, data45912, ser2);
}
private static byte[] hr(String string) {
@@ -111,6 +95,7 @@ public final class TestEmbeddedObjectRef
/**
* tests various examples of OLE controls
*/
+ @Test
public void testVarious() {
String[] rawData = {
"12 00 0B 00 70 95 0B 05 3B 01 00 36 00 40 00 18 00 19 00 18",
@@ -143,8 +128,9 @@ public final class TestEmbeddedObjectRef
TestcaseRecordInputStream.confirmRecordEncoding("Test record " + i, EORSR_SID, data, ser2);
}
+ @Test
public void testVisioDrawing_bug46199() {
- /**
+ /*
* taken from ftPictFmla sub-record in attachment 22860 (stream offset 0x768F).<br>
* Note that the since the string length is zero, there is no unicode flag byte
*/
@@ -157,15 +143,8 @@ public final class TestEmbeddedObjectRef
+ "0F CB E8 00");
RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data46199);
- EmbeddedObjectRefSubRecord rec;
- try {
- rec = new EmbeddedObjectRefSubRecord(in, data46199.length);
- } catch (RecordFormatException e) {
- if (e.getMessage().equals("Not enough data (3) to read requested (4) bytes")) {
- throw new AssertionFailedError("Identified bug 22860");
- }
- throw e;
- }
+ // bug 22860 - Not enough data (3) to read requested (4) bytes
+ EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data46199.length);
byte[] ser2 = rec.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(EORSR_SID, data46199, ser2);
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java Fri Dec 27 23:00:13 2019
@@ -18,30 +18,27 @@
package org.apache.poi.hssf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Tests the serialization and deserialization of the EndSubRecord
- * class works correctly. Test data taken directly from a real
- * Excel file.
- *
- * @author Glen Stampoultzis (glens at apache.org)
+ * class works correctly. Test data taken directly from a real Excel file.
*/
-public final class TestEndSubRecord extends TestCase {
+public final class TestEndSubRecord {
private static final byte[] data = { };
+ @Test
public void testLoad() {
EndSubRecord record = new EndSubRecord(TestcaseRecordInputStream.create(0x00, data), 0);
assertEquals(0, record.getDataSize());
}
- public void testStore()
- {
+ @Test
+ public void testStore() {
EndSubRecord record = new EndSubRecord();
-
byte [] recordBytes = record.serialize();
- assertEquals(recordBytes.length - 4, data.length);
- for (int i = 0; i < data.length; i++)
- assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+ assertEquals(0, recordBytes.length - 4);
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java?rev=1872041&r1=1872040&r2=1872041&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java Fri Dec 27 23:00:13 2019
@@ -17,25 +17,26 @@
package org.apache.poi.hssf.record;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.poi.ddf.EscherClientDataRecord;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
-
-import java.util.ArrayList;
-import java.util.List;
+import org.junit.Test;
/**
* Tests the EscherAggregate class.
- *
- * @author Glen Stampoultzis (glens at apache.org)
*/
-public final class TestEscherAggregate extends TestCase {
+public final class TestEscherAggregate {
/**
* Tests that the create aggregate method correctly rejoins escher records together.
*/
+ @Test
public void testCreateAggregate() {
String msoDrawingRecord1 =
"0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" +
@@ -81,10 +82,9 @@ public final class TestEscherAggregate e
assertEquals( 1, aggregate.getEscherRecords().size() );
assertEquals( (short) 0xF002, aggregate.getEscherRecord( 0 ).getRecordId() );
assertEquals( 2, aggregate.getEscherRecord( 0 ).getChildRecords().size() );
-
-// System.out.println( "aggregate = " + aggregate );
}
+ @Test
public void testSerialize() {
EscherContainerRecord container1 = new EscherContainerRecord();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org