Sonar fixes - Tests should include assertions

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1872302 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2020-01-03 23:30:36 +00:00
parent 4aa8334e3b
commit d66af200eb
61 changed files with 699 additions and 634 deletions

View File

@ -17,8 +17,11 @@
package org.apache.poi.hssf.record;
import java.io.IOException;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.RecordFormatException;
/**
* Title: Bound Sheet Record (aka BundleSheet) (0x0085) for BIFF 5<P>
@ -44,6 +47,17 @@ public final class OldSheetRecord {
field_2_visibility = in.readUByte();
field_3_type = in.readUByte();
int field_4_sheetname_length = in.readUByte();
in.mark(1);
byte b = in.readByte();
// if the sheet name starts with a 0, we need to skip one byte, otherwise the following records will
// fail with a LeftOverDataException
if (b != 0) {
try {
in.reset();
} catch (IOException e) {
throw new RecordFormatException(e);
}
}
field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, MAX_RECORD_LENGTH);
in.read(field_5_sheetname, 0, field_4_sheetname_length);
}

View File

@ -30,15 +30,15 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.security.Permission;
import org.apache.poi.EmptyFileException;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.RecordFormatException;
import org.junit.Ignore;
import org.junit.Test;
/**
@ -53,153 +53,149 @@ public final class TestOldExcelExtractor {
@Test
public void testSimpleExcel3() throws IOException {
OldExcelExtractor extractor = createExtractor("testEXCEL_3.xls");
// Check we can call getText without error
String text = extractor.getText();
// Check we find a few words we expect in there
assertContains(text, "Season beginning August");
assertContains(text, "USDA");
// Check we find a few numbers we expect in there
assertContains(text, "347");
assertContains(text, "228");
// Check we find a few string-literal dates in there
assertContains(text, "1981/82");
// Check the type
assertEquals(3, extractor.getBiffVersion());
assertEquals(0x10, extractor.getFileType());
extractor.close();
}
@Test
public void testSimpleExcel3NoReading() throws IOException {
OldExcelExtractor extractor = createExtractor("testEXCEL_3.xls");
assertNotNull(extractor);
extractor.close();
}
@Test
public void testSimpleExcel4() throws IOException {
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
// Check we can call getText without error
String text = extractor.getText();
// Check we find a few words we expect in there
assertContains(text, "Size");
assertContains(text, "Returns");
// Check we find a few numbers we expect in there
assertContains(text, "11");
assertContains(text, "784");
// Check the type
assertEquals(4, extractor.getBiffVersion());
assertEquals(0x10, extractor.getFileType());
extractor.close();
}
@Test
public void testSimpleExcel5() throws IOException {
for (String ver : new String[] {"5", "95"}) {
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
try (OldExcelExtractor extractor = createExtractor("testEXCEL_3.xls")) {
// Check we can call getText without error
String text = extractor.getText();
// Check we find a few words we expect in there
assertContains(text, "Sample Excel");
assertContains(text, "Written and saved");
assertContains(text, "Season beginning August");
assertContains(text, "USDA");
// Check we find a few numbers we expect in there
assertContains(text, "15");
assertContains(text, "169");
assertContains(text, "347");
assertContains(text, "228");
// Check we got the sheet names (new formats only)
assertContains(text, "Sheet: Feuil3");
// Check we find a few string-literal dates in there
assertContains(text, "1981/82");
// Check the type
assertEquals(5, extractor.getBiffVersion());
assertEquals(0x05, extractor.getFileType());
assertEquals(3, extractor.getBiffVersion());
assertEquals(0x10, extractor.getFileType());
extractor.close();
}
}
@Test
public void testSimpleExcel3NoReading() throws IOException {
try (OldExcelExtractor extractor = createExtractor("testEXCEL_3.xls")) {
assertNotNull(extractor);
}
}
@Test
public void testSimpleExcel4() throws IOException {
try (OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls")) {
// Check we can call getText without error
String text = extractor.getText();
// Check we find a few words we expect in there
assertContains(text, "Size");
assertContains(text, "Returns");
// Check we find a few numbers we expect in there
assertContains(text, "11");
assertContains(text, "784");
// Check the type
assertEquals(4, extractor.getBiffVersion());
assertEquals(0x10, extractor.getFileType());
}
}
@Test
public void testSimpleExcel5() throws IOException {
for (String ver : new String[] {"5", "95"}) {
try (OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls")) {
// Check we can call getText without error
String text = extractor.getText();
// Check we find a few words we expect in there
assertContains(text, "Sample Excel");
assertContains(text, "Written and saved");
// Check we find a few numbers we expect in there
assertContains(text, "15");
assertContains(text, "169");
// Check we got the sheet names (new formats only)
assertContains(text, "Sheet: Feuil3");
// Check the type
assertEquals(5, extractor.getBiffVersion());
assertEquals(0x05, extractor.getFileType());
}
}
}
@Test
public void testStrings() throws IOException {
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
String text = extractor.getText();
try (OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls")) {
String text = extractor.getText();
// Simple strings
assertContains(text, "Table 10 -- Examination Coverage:");
assertContains(text, "Recommended and Average Recommended Additional Tax After");
assertContains(text, "Individual income tax returns, total");
// Simple strings
assertContains(text, "Table 10 -- Examination Coverage:");
assertContains(text, "Recommended and Average Recommended Additional Tax After");
assertContains(text, "Individual income tax returns, total");
// More complicated strings
assertContains(text, "$100,000 or more");
assertContains(text, "S corporation returns, Form 1120S [10,15]");
assertContains(text, "individual income tax return \u201Cshort forms.\u201D");
// More complicated strings
assertContains(text, "$100,000 or more");
assertContains(text, "S corporation returns, Form 1120S [10,15]");
assertContains(text, "individual income tax return \u201Cshort forms.\u201D");
// Formula based strings
// TODO Find some then test
extractor.close();
// Formula based strings
// TODO Find some then test
}
}
@Test
public void testFormattedNumbersExcel4() throws IOException {
OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls");
String text = extractor.getText();
try (OldExcelExtractor extractor = createExtractor("testEXCEL_4.xls")) {
String text = extractor.getText();
// Simple numbers
assertContains(text, "151");
assertContains(text, "784");
// Simple numbers
assertContains(text, "151");
assertContains(text, "784");
// Numbers which come from formulas
assertContains(text, "0.398"); // TODO Rounding
assertContains(text, "624");
// Numbers which come from formulas
assertContains(text, "0.398"); // TODO Rounding
assertContains(text, "624");
// Formatted numbers
// TODO
// assertContains(text, "55,624");
// assertContains(text, "11,743,477");
extractor.close();
// Formatted numbers
// TODO
// assertContains(text, "55,624");
// assertContains(text, "11,743,477");
}
}
@Test
public void testFormattedNumbersExcel5() throws IOException {
for (String ver : new String[] {"5", "95"}) {
OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls");
String text = extractor.getText();
try (OldExcelExtractor extractor = createExtractor("testEXCEL_"+ver+".xls")) {
String text = extractor.getText();
// Simple numbers
assertContains(text, "1");
// Simple numbers
assertContains(text, "1");
// Numbers which come from formulas
assertContains(text, "13");
assertContains(text, "169");
// Numbers which come from formulas
assertContains(text, "13");
assertContains(text, "169");
// Formatted numbers
// TODO
// assertContains(text, "100.00%");
// assertContains(text, "155.00%");
// assertContains(text, "1,125");
// assertContains(text, "189,945");
// assertContains(text, "1,234,500");
// assertContains(text, "$169.00");
// assertContains(text, "$1,253.82");
extractor.close();
// Formatted numbers
// TODO
// assertContains(text, "100.00%");
// assertContains(text, "155.00%");
// assertContains(text, "1,125");
// assertContains(text, "189,945");
// assertContains(text, "1,234,500");
// assertContains(text, "$169.00");
// assertContains(text, "$1,253.82");
}
}
}
@ -209,12 +205,11 @@ public final class TestOldExcelExtractor {
String filename = "testEXCEL_"+ver+".xls";
File f = HSSFTestDataSamples.getSampleFile(filename);
OldExcelExtractor extractor = new OldExcelExtractor(f);
String text = extractor.getText();
assertNotNull(text);
assertTrue(text.length() > 100);
extractor.close();
try (OldExcelExtractor extractor = new OldExcelExtractor(f)) {
String text = extractor.getText();
assertNotNull(text);
assertTrue(text.length() > 100);
}
}
}
@ -224,12 +219,11 @@ public final class TestOldExcelExtractor {
String filename = "testEXCEL_"+ver+".xls";
File f = HSSFTestDataSamples.getSampleFile(filename);
try (InputStream stream = new FileInputStream(f)) {
OldExcelExtractor extractor = new OldExcelExtractor(stream);
try (InputStream stream = new FileInputStream(f);
OldExcelExtractor extractor = new OldExcelExtractor(stream)) {
String text = extractor.getText();
assertNotNull(text);
assertTrue(text.length() > 100);
extractor.close();
}
}
}
@ -237,14 +231,14 @@ public final class TestOldExcelExtractor {
@Test(expected=OfficeXmlFileException.class)
public void testOpenInvalidFile1() throws IOException {
// a file that exists, but is a different format
createExtractor("WithVariousData.xlsx");
createExtractor("WithVariousData.xlsx").close();
}
@Test(expected=RecordFormatException.class)
public void testOpenInvalidFile2() throws IOException {
// a completely different type of file
createExtractor("48936-strings.txt");
createExtractor("48936-strings.txt").close();
}
@Test(expected=FileNotFoundException.class)
@ -258,71 +252,72 @@ public final class TestOldExcelExtractor {
@Test(expected=EmptyFileException.class)
public void testOpenNonExistingFile() throws IOException {
// a file that exists, but is a different format
OldExcelExtractor extractor = new OldExcelExtractor(new File("notexistingfile.xls"));
extractor.close();
new OldExcelExtractor(new File("notexistingfile.xls")).close();
}
@Test
public void testInputStream() throws IOException {
File file = HSSFTestDataSamples.getSampleFile("testEXCEL_3.xls");
try (InputStream stream = new FileInputStream(file)) {
OldExcelExtractor extractor = new OldExcelExtractor(stream);
try (InputStream stream = new FileInputStream(file);
OldExcelExtractor extractor = new OldExcelExtractor(stream);) {
String text = extractor.getText();
assertNotNull(text);
extractor.close();
}
}
@Test
public void testInputStreamNPOIHeader() throws IOException {
File file = HSSFTestDataSamples.getSampleFile("FormulaRefs.xls");
try (InputStream stream = new FileInputStream(file)) {
OldExcelExtractor extractor = new OldExcelExtractor(stream);
extractor.close();
try (InputStream stream = new FileInputStream(file);
OldExcelExtractor extractor = new OldExcelExtractor(stream)) {
String text = extractor.getText();
assertNotNull(text);
}
}
@Test
public void testPOIFSFileSystem() throws IOException {
File file = HSSFTestDataSamples.getSampleFile("FormulaRefs.xls");
try (POIFSFileSystem fs = new POIFSFileSystem(file)) {
OldExcelExtractor extractor = new OldExcelExtractor(fs);
extractor.close();
try (POIFSFileSystem fs = new POIFSFileSystem(file);
OldExcelExtractor extractor = new OldExcelExtractor(fs)){
String text = extractor.getText();
assertNotNull(text);
}
}
@Test
public void testDirectoryNode() throws IOException {
File file = HSSFTestDataSamples.getSampleFile("FormulaRefs.xls");
try (POIFSFileSystem fs = new POIFSFileSystem(file)) {
OldExcelExtractor extractor = new OldExcelExtractor(fs.getRoot());
extractor.close();
try (POIFSFileSystem fs = new POIFSFileSystem(file);
OldExcelExtractor extractor = new OldExcelExtractor(fs.getRoot())) {
String text = extractor.getText();
assertNotNull(text);
}
}
@Test
@Test(expected = FileNotFoundException.class)
public void testDirectoryNodeInvalidFile() throws IOException {
File file = POIDataSamples.getDocumentInstance().getFile("test.doc");
try (POIFSFileSystem fs = new POIFSFileSystem(file)) {
OldExcelExtractor extractor = new OldExcelExtractor(fs.getRoot());
extractor.close();
fail("Should catch exception here");
} catch (FileNotFoundException e) {
// expected here
try (POIFSFileSystem fs = new POIFSFileSystem(file);
OldExcelExtractor extractor = new OldExcelExtractor(fs.getRoot())) {
fail("Should throw exception here");
}
}
@Ignore("Calls System.exit()")
@Test
@Test(expected = ExitException.class)
public void testMainUsage() throws IOException {
PrintStream save = System.err;
SecurityManager sm = System.getSecurityManager();
System.setSecurityManager(new NoExitSecurityManager());
try {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
PrintStream str = new PrintStream(out, false, "UTF-8");
System.setErr(str);
// calls System.exit()
OldExcelExtractor.main(new String[]{});
}
} finally {
System.setSecurityManager(sm);
System.setErr(save);
}
}
@ -333,34 +328,49 @@ public final class TestOldExcelExtractor {
PrintStream save = System.out;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
PrintStream str = new PrintStream(out, false, "UTF-8");
System.setOut(str);
OldExcelExtractor.main(new String[] {file.getAbsolutePath()});
} finally {
out.close();
}
PrintStream str = new PrintStream(out, false, "UTF-8");
System.setOut(str);
OldExcelExtractor.main(new String[] {file.getAbsolutePath()});
String string = out.toString("UTF-8");
assertTrue("Had: " + string,
string.contains("Table C-13--Lemons"));
assertTrue("Had: " + string, string.contains("Table C-13--Lemons"));
} finally {
System.setOut(save);
}
}
@Test
@Test(expected = EncryptedDocumentException.class)
public void testEncryptionException() throws IOException {
//test file derives from Common Crawl
File file = HSSFTestDataSamples.getSampleFile("60284.xls");
OldExcelExtractor ex = new OldExcelExtractor(file);
assertEquals(5, ex.getBiffVersion());
assertEquals(5, ex.getFileType());
try {
try (OldExcelExtractor ex = new OldExcelExtractor(file)) {
assertEquals(5, ex.getBiffVersion());
assertEquals(5, ex.getFileType());
ex.getText();
fail();
} catch (EncryptedDocumentException e) {
assertTrue("correct exception thrown", true);
}
ex.close();
}
private static class NoExitSecurityManager extends SecurityManager {
@Override
public void checkPermission(Permission perm) {
// allow anything.
}
@Override
public void checkPermission(Permission perm, Object context) {
// allow anything.
}
@Override
public void checkExit(int status) {
super.checkExit(status);
throw new ExitException(status);
}
}
private static class ExitException extends SecurityException {
public final int status;
public ExitException(int status) {
super("There is no escape!");
this.status = status;
}
}
}

View File

@ -27,10 +27,8 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -178,12 +176,7 @@ public class TestDrawingAggregate {
@Test
public void testAllTestSamples() throws IOException {
File[] xls = new File(System.getProperty("POI.testdata.path"), "spreadsheet").listFiles(
new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".xls");
}
}
(dir, name) -> name.endsWith(".xls")
);
assertNotNull(
"Need to find files in test-data path, had path: " + new File(System.getProperty("POI.testdata.path"), "spreadsheet"),
@ -246,12 +239,17 @@ public class TestDrawingAggregate {
*/
@Test
public void testFailing() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("15573.xls");
HSSFSheet sh = wb.getSheetAt(0);
sh.getDrawingPatriarch();
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("15573.xls")) {
HSSFSheet sh = wb.getSheetAt(0);
HSSFPatriarch dp = sh.getDrawingPatriarch();
assertNotNull(dp);
HSSFTestDataSamples.writeOutAndReadBack(wb).close();
wb.close();
try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb)) {
HSSFSheet sh2 = wb2.getSheetAt(0);
HSSFPatriarch dp2 = sh2.getDrawingPatriarch();
assertNotNull(dp2);
}
}
}
private static byte[] toByteArray(List<RecordBase> records) {
@ -269,76 +267,81 @@ public class TestDrawingAggregate {
@Test
public void testSolverContainerMustBeSavedDuringSerialization() throws IOException{
HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("SolverContainerAfterSPGR.xls");
HSSFSheet sh = wb1.getSheetAt(0);
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = ish.getRecords();
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 22);
byte[] dgBytes = toByteArray(dgRecords);
sh.getDrawingPatriarch();
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertEquals(agg.getEscherRecords().get(0).getChildRecords().size(), 3);
assertEquals(agg.getEscherRecords().get(0).getChild(2).getRecordId(), EscherContainerRecord.SOLVER_CONTAINER);
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
sh = wb2.getSheetAt(0);
sh.getDrawingPatriarch();
ish = HSSFTestHelper.getSheetForTest(sh);
agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertEquals(agg.getEscherRecords().get(0).getChildRecords().size(), 3);
assertEquals(agg.getEscherRecords().get(0).getChild(2).getRecordId(), EscherContainerRecord.SOLVER_CONTAINER);
try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("SolverContainerAfterSPGR.xls")) {
HSSFSheet sh = wb1.getSheetAt(0);
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = ish.getRecords();
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 22);
byte[] dgBytes = toByteArray(dgRecords);
sh.getDrawingPatriarch();
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertNotNull(agg);
assertEquals(agg.getEscherRecords().get(0).getChildRecords().size(), 3);
assertEquals(agg.getEscherRecords().get(0).getChild(2).getRecordId(), EscherContainerRecord.SOLVER_CONTAINER);
try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
sh = wb2.getSheetAt(0);
sh.getDrawingPatriarch();
ish = HSSFTestHelper.getSheetForTest(sh);
agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertNotNull(agg);
assertEquals(agg.getEscherRecords().get(0).getChildRecords().size(), 3);
assertEquals(agg.getEscherRecords().get(0).getChild(2).getRecordId(), EscherContainerRecord.SOLVER_CONTAINER);
// collect drawing records into a byte buffer.
agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
wb2.close();
// collect drawing records into a byte buffer.
agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertNotNull(agg);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
}
}
}
@Test
public void testFileWithTextbox() throws IOException{
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("text.xls");
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = ish.getRecords();
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 23);
byte[] dgBytes = toByteArray(dgRecords);
sh.getDrawingPatriarch();
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("text.xls")) {
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = ish.getRecords();
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 23);
byte[] dgBytes = toByteArray(dgRecords);
sh.getDrawingPatriarch();
// collect drawing records into a byte buffer.
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
wb.close();
// collect drawing records into a byte buffer.
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertNotNull(agg);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
}
}
@Test
public void testFileWithCharts() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls");
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = ish.getRecords();
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 21);
byte[] dgBytes = toByteArray(dgRecords);
sh.getDrawingPatriarch();
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49581.xls")) {
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = ish.getRecords();
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 21);
byte[] dgBytes = toByteArray(dgRecords);
sh.getDrawingPatriarch();
// collect drawing records into a byte buffer.
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
for (int i=0; i< dgBytes.length; i++){
if (dgBytes[i] != dgBytesAfterSave[i]){
System.out.println("pos = " + i);
// collect drawing records into a byte buffer.
EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
assertNotNull(agg);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
for (int i = 0; i < dgBytes.length; i++) {
if (dgBytes[i] != dgBytesAfterSave[i]) {
System.out.println("pos = " + i);
}
}
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
}
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
wb.close();
}
/**
@ -346,62 +349,62 @@ public class TestDrawingAggregate {
*/
@Test
public void test45129() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("45129.xls");
HSSFSheet sh = wb.getSheetAt(0);
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("45129.xls")) {
HSSFSheet sh = wb.getSheetAt(0);
InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = isheet.getRecords();
List<RecordBase> records = isheet.getRecords();
// the sheet's drawing is not aggregated
assertEquals("wrong size of sheet records stream", 394, records.size());
// the last record before the drawing block
assertTrue(
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 389);
// collect drawing records into a byte buffer.
byte[] dgBytes = toByteArray(dgRecords);
for (RecordBase rb : dgRecords) {
Record r = (Record) rb;
short sid = r.getSid();
// we expect that drawing block consists of either
// DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
// the sheet's drawing is not aggregated
assertEquals("wrong size of sheet records stream", 394, records.size());
// the last record before the drawing block
assertTrue(
sid == DrawingRecord.sid ||
sid == ContinueRecord.sid ||
sid == ObjRecord.sid ||
sid == TextObjectRecord.sid);
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 389);
// collect drawing records into a byte buffer.
byte[] dgBytes = toByteArray(dgRecords);
for (RecordBase rb : dgRecords) {
Record r = (Record) rb;
short sid = r.getSid();
// we expect that drawing block consists of either
// DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
assertTrue(
sid == DrawingRecord.sid ||
sid == ContinueRecord.sid ||
sid == ObjRecord.sid ||
sid == TextObjectRecord.sid);
}
// the first record after the drawing block
assertTrue(
"records.get(389) is expected to be Window2",
records.get(389) instanceof WindowTwoRecord);
// aggregate drawing records.
// The subrange [19, 388] is expected to be replaced with a EscherAggregate object
DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
assertEquals("wrong size of the aggregated sheet records stream", 25, records.size());
assertTrue(
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(),
records.get(19) instanceof EscherAggregate);
assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(),
records.get(20) instanceof WindowTwoRecord);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
}
// the first record after the drawing block
assertTrue(
"records.get(389) is expected to be Window2",
records.get(389) instanceof WindowTwoRecord);
// aggregate drawing records.
// The subrange [19, 388] is expected to be replaced with a EscherAggregate object
DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
assertEquals("wrong size of the aggregated sheet records stream", 25, records.size());
assertTrue(
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(),
records.get(19) instanceof EscherAggregate);
assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(),
records.get(20) instanceof WindowTwoRecord);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
wb.close();
}
/**
@ -414,208 +417,207 @@ public class TestDrawingAggregate {
*/
@Test
public void testSerializeDrawingBigger8k() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DrawingContinue.xls");
InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DrawingContinue.xls")) {
InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
HSSFSheet sh = wb.getSheetAt(0);
InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = isheet.getRecords();
List<RecordBase> records = isheet.getRecords();
// the sheet's drawing is not aggregated
assertEquals("wrong size of sheet records stream", 32, records.size());
// the last record before the drawing block
assertTrue(
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 26);
for (RecordBase rb : dgRecords) {
Record r = (Record) rb;
short sid = r.getSid();
// we expect that drawing block consists of either
// DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
// the sheet's drawing is not aggregated
assertEquals("wrong size of sheet records stream", 32, records.size());
// the last record before the drawing block
assertTrue(
sid == DrawingRecord.sid ||
sid == ContinueRecord.sid ||
sid == ObjRecord.sid ||
sid == NoteRecord.sid ||
sid == TextObjectRecord.sid);
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 26);
for (RecordBase rb : dgRecords) {
Record r = (Record) rb;
short sid = r.getSid();
// we expect that drawing block consists of either
// DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
assertTrue(
sid == DrawingRecord.sid ||
sid == ContinueRecord.sid ||
sid == ObjRecord.sid ||
sid == NoteRecord.sid ||
sid == TextObjectRecord.sid);
}
// collect drawing records into a byte buffer.
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
assertTrue(
"records.get(26) is expected to be Window2",
records.get(26) instanceof WindowTwoRecord);
// aggregate drawing records.
// The subrange [19, 38] is expected to be replaced with a EscherAggregate object
DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
assertEquals("wrong size of the aggregated sheet records stream", 26, records.size());
assertTrue(
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(),
records.get(19) instanceof EscherAggregate);
assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(),
records.get(20) instanceof WindowTwoRecord);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
}
// collect drawing records into a byte buffer.
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
assertTrue(
"records.get(26) is expected to be Window2",
records.get(26) instanceof WindowTwoRecord);
// aggregate drawing records.
// The subrange [19, 38] is expected to be replaced with a EscherAggregate object
DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
assertEquals("wrong size of the aggregated sheet records stream", 26, records.size());
assertTrue(
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(),
records.get(19) instanceof EscherAggregate);
assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(),
records.get(20) instanceof WindowTwoRecord);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
wb.close();
}
@Test
public void testSerializeDrawingBigger8k_noAggregation() throws IOException {
HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("DrawingContinue.xls");
try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("DrawingContinue.xls")) {
InternalSheet isheet = HSSFTestHelper.getSheetForTest(wb1.getSheetAt(0));
List<RecordBase> records = isheet.getRecords();
InternalSheet isheet = HSSFTestHelper.getSheetForTest(wb1.getSheetAt(0));
List<RecordBase> records = isheet.getRecords();
try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
InternalSheet isheet2 = HSSFTestHelper.getSheetForTest(wb2.getSheetAt(0));
List<RecordBase> records2 = isheet2.getRecords();
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
InternalSheet isheet2 = HSSFTestHelper.getSheetForTest(wb2.getSheetAt(0));
List<RecordBase> records2 = isheet2.getRecords();
assertEquals(records.size(), records2.size());
for (int i = 0; i < records.size(); i++) {
RecordBase r1 = records.get(i);
RecordBase r2 = records2.get(i);
assertSame(r1.getClass(), r2.getClass());
assertEquals(r1.getRecordSize(), r2.getRecordSize());
if (r1 instanceof Record) {
assertEquals(((Record) r1).getSid(), ((Record) r2).getSid());
assertArrayEquals(((Record) r1).serialize(), ((Record) r2).serialize());
assertEquals(records.size(), records2.size());
for (int i = 0; i < records.size(); i++) {
RecordBase r1 = records.get(i);
RecordBase r2 = records2.get(i);
assertSame(r1.getClass(), r2.getClass());
assertEquals(r1.getRecordSize(), r2.getRecordSize());
if (r1 instanceof Record) {
assertEquals(((Record) r1).getSid(), ((Record) r2).getSid());
assertArrayEquals(((Record) r1).serialize(), ((Record) r2).serialize());
}
}
}
}
wb2.close();
}
@Test
public void testSerializeDrawingWithComments() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DrawingAndComments.xls");
HSSFSheet sh = wb.getSheetAt(0);
InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DrawingAndComments.xls")) {
HSSFSheet sh = wb.getSheetAt(0);
InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = isheet.getRecords();
List<RecordBase> records = isheet.getRecords();
// the sheet's drawing is not aggregated
assertEquals("wrong size of sheet records stream", 46, records.size());
// the last record before the drawing block
assertTrue(
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 39);
for (RecordBase rb : dgRecords) {
Record r = (Record) rb;
short sid = r.getSid();
// we expect that drawing block consists of either
// DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
// the sheet's drawing is not aggregated
assertEquals("wrong size of sheet records stream", 46, records.size());
// the last record before the drawing block
assertTrue(
sid == DrawingRecord.sid ||
sid == ContinueRecord.sid ||
sid == ObjRecord.sid ||
sid == NoteRecord.sid ||
sid == TextObjectRecord.sid);
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
// records to be aggregated
List<RecordBase> dgRecords = records.subList(19, 39);
for (RecordBase rb : dgRecords) {
Record r = (Record) rb;
short sid = r.getSid();
// we expect that drawing block consists of either
// DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
assertTrue(
sid == DrawingRecord.sid ||
sid == ContinueRecord.sid ||
sid == ObjRecord.sid ||
sid == NoteRecord.sid ||
sid == TextObjectRecord.sid);
}
// collect drawing records into a byte buffer.
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
assertTrue(
"records.get(39) is expected to be Window2",
records.get(39) instanceof WindowTwoRecord);
// aggregate drawing records.
// The subrange [19, 38] is expected to be replaced with a EscherAggregate object
DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
assertEquals("wrong size of the aggregated sheet records stream", 27, records.size());
assertTrue(
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(),
records.get(19) instanceof EscherAggregate);
assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(),
records.get(20) instanceof WindowTwoRecord);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
}
// collect drawing records into a byte buffer.
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
assertTrue(
"records.get(39) is expected to be Window2",
records.get(39) instanceof WindowTwoRecord);
// aggregate drawing records.
// The subrange [19, 38] is expected to be replaced with a EscherAggregate object
DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
assertEquals("wrong size of the aggregated sheet records stream", 27, records.size());
assertTrue(
"records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(),
records.get(18) instanceof RowRecordsAggregate);
assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(),
records.get(19) instanceof EscherAggregate);
assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(),
records.get(20) instanceof WindowTwoRecord);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
wb.close();
}
@Test
public void testFileWithPictures() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ContinueRecordProblem.xls");
HSSFSheet sh = wb.getSheetAt(0);
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ContinueRecordProblem.xls")) {
HSSFSheet sh = wb.getSheetAt(0);
InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
List<RecordBase> records = isheet.getRecords();
List<RecordBase> records = isheet.getRecords();
// the sheet's drawing is not aggregated
assertEquals("wrong size of sheet records stream", 315, records.size());
// the last record before the drawing block
assertTrue(
"records.get(21) is expected to be RowRecordsAggregate but was " + records.get(21).getClass().getSimpleName(),
records.get(21) instanceof RowRecordsAggregate);
// records to be aggregated
List<RecordBase> dgRecords = records.subList(22, 300);
for (RecordBase rb : dgRecords) {
Record r = (Record) rb;
short sid = r.getSid();
// we expect that drawing block consists of either
// DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
// the sheet's drawing is not aggregated
assertEquals("wrong size of sheet records stream", 315, records.size());
// the last record before the drawing block
assertTrue(
sid == DrawingRecord.sid ||
sid == ContinueRecord.sid ||
sid == ObjRecord.sid ||
sid == TextObjectRecord.sid);
"records.get(21) is expected to be RowRecordsAggregate but was " + records.get(21).getClass().getSimpleName(),
records.get(21) instanceof RowRecordsAggregate);
// records to be aggregated
List<RecordBase> dgRecords = records.subList(22, 300);
for (RecordBase rb : dgRecords) {
Record r = (Record) rb;
short sid = r.getSid();
// we expect that drawing block consists of either
// DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
assertTrue(
sid == DrawingRecord.sid ||
sid == ContinueRecord.sid ||
sid == ObjRecord.sid ||
sid == TextObjectRecord.sid);
}
// collect drawing records into a byte buffer.
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
assertTrue(
"records.get(300) is expected to be Window2",
records.get(300) instanceof WindowTwoRecord);
// aggregate drawing records.
// The subrange [19, 299] is expected to be replaced with a EscherAggregate object
DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
assertEquals("wrong size of the aggregated sheet records stream", 38, records.size());
assertTrue(
"records.get(21) is expected to be RowRecordsAggregate but was " + records.get(21).getClass().getSimpleName(),
records.get(21) instanceof RowRecordsAggregate);
assertTrue("records.get(22) is expected to be EscherAggregate but was " + records.get(22).getClass().getSimpleName(),
records.get(22) instanceof EscherAggregate);
assertTrue("records.get(23) is expected to be Window2 but was " + records.get(23).getClass().getSimpleName(),
records.get(23) instanceof WindowTwoRecord);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
}
// collect drawing records into a byte buffer.
byte[] dgBytes = toByteArray(dgRecords);
// the first record after the drawing block
assertTrue(
"records.get(300) is expected to be Window2",
records.get(300) instanceof WindowTwoRecord);
// aggregate drawing records.
// The subrange [19, 299] is expected to be replaced with a EscherAggregate object
DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
int loc = isheet.aggregateDrawingRecords(drawingManager, false);
EscherAggregate agg = (EscherAggregate) records.get(loc);
assertEquals("wrong size of the aggregated sheet records stream", 38, records.size());
assertTrue(
"records.get(21) is expected to be RowRecordsAggregate but was " + records.get(21).getClass().getSimpleName(),
records.get(21) instanceof RowRecordsAggregate);
assertTrue("records.get(22) is expected to be EscherAggregate but was " + records.get(22).getClass().getSimpleName(),
records.get(22) instanceof EscherAggregate);
assertTrue("records.get(23) is expected to be Window2 but was " + records.get(23).getClass().getSimpleName(),
records.get(23) instanceof WindowTwoRecord);
byte[] dgBytesAfterSave = agg.serialize();
assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
assertArrayEquals("drawing data before and after save is different", dgBytes, dgBytesAfterSave);
wb.close();
}
@Test

View File

@ -17,7 +17,11 @@
package org.apache.poi.hssf.model;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.Locale;
@ -37,45 +41,10 @@ import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.ss.formula.FormulaParser;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.constant.ErrorConstant;
import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg;
import org.apache.poi.ss.formula.ptg.AddPtg;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.AreaI;
import org.apache.poi.ss.formula.ptg.AreaPtg;
import org.apache.poi.ss.formula.ptg.AreaPtgBase;
import org.apache.poi.ss.formula.ptg.ArrayPtg;
import org.apache.poi.ss.formula.ptg.AttrPtg;
import org.apache.poi.ss.formula.ptg.BoolPtg;
import org.apache.poi.ss.formula.ptg.ConcatPtg;
import org.apache.poi.ss.formula.ptg.DividePtg;
import org.apache.poi.ss.formula.ptg.EqualPtg;
import org.apache.poi.ss.formula.ptg.ErrPtg;
import org.apache.poi.ss.formula.ptg.FuncPtg;
import org.apache.poi.ss.formula.ptg.FuncVarPtg;
import org.apache.poi.ss.formula.ptg.GreaterThanPtg;
import org.apache.poi.ss.formula.ptg.IntPtg;
import org.apache.poi.ss.formula.ptg.IntersectionPtg;
import org.apache.poi.ss.formula.ptg.MemAreaPtg;
import org.apache.poi.ss.formula.ptg.MemFuncPtg;
import org.apache.poi.ss.formula.ptg.MissingArgPtg;
import org.apache.poi.ss.formula.ptg.MultiplyPtg;
import org.apache.poi.ss.formula.ptg.NamePtg;
import org.apache.poi.ss.formula.ptg.NameXPtg;
import org.apache.poi.ss.formula.ptg.NumberPtg;
import org.apache.poi.ss.formula.ptg.ParenthesisPtg;
import org.apache.poi.ss.formula.ptg.PercentPtg;
import org.apache.poi.ss.formula.ptg.PowerPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.RangePtg;
import org.apache.poi.ss.formula.ptg.Ref3DPtg;
import org.apache.poi.ss.formula.ptg.RefPtg;
import org.apache.poi.ss.formula.ptg.StringPtg;
import org.apache.poi.ss.formula.ptg.SubtractPtg;
import org.apache.poi.ss.formula.ptg.UnaryMinusPtg;
import org.apache.poi.ss.formula.ptg.UnaryPlusPtg;
import org.apache.poi.ss.formula.ptg.UnionPtg;
import org.apache.poi.ss.formula.ptg.*;
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
@ -230,22 +199,30 @@ public final class TestFormulaParser {
@Test
public void testWorksheetReferences() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
try (HSSFWorkbook wb = new HSSFWorkbook()) {
wb.createSheet("NoQuotesNeeded");
wb.createSheet("Quotes Needed Here &#$@");
HSSFSheet sheet1 = wb.createSheet("NoQuotesNeeded");
sheet1.createRow(0).createCell(0).setCellValue("NoQuotesNeeded");
HSSFSheet sheet2 = wb.createSheet("Quotes Needed Here &#$@");
sheet2.createRow(0).createCell(0).setCellValue("Quotes Needed Here &#$@");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
cell = row.createCell(0);
cell.setCellFormula("NoQuotesNeeded!A1");
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
HSSFCell cell;
String act;
cell = row.createCell(1);
cell.setCellFormula("'Quotes Needed Here &#$@'!A1");
cell = row.createCell(0);
cell.setCellFormula("NoQuotesNeeded!A1");
act = evaluator.evaluate(cell).getStringValue();
assertEquals("NoQuotesNeeded", act);
wb.close();
cell = row.createCell(1);
cell.setCellFormula("'Quotes Needed Here &#$@'!A1");
act = evaluator.evaluate(cell).getStringValue();
assertEquals("Quotes Needed Here &#$@", act);
}
}
@Test
@ -330,18 +307,21 @@ public final class TestFormulaParser {
/** bug 35027, underscore in sheet name */
@Test
public void testUnderscore() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet1 = wb.createSheet("Cash_Flow");
sheet1.createRow(0).createCell(0).setCellValue("Cash_Flow");
wb.createSheet("Cash_Flow");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
cell = row.createCell(0);
cell.setCellFormula("Cash_Flow!A1");
cell = row.createCell(0);
cell.setCellFormula("Cash_Flow!A1");
wb.close();
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
String act = evaluator.evaluate(cell).getStringValue();
assertEquals("Cash_Flow", act);
}
}
/** bug 49725, defined names with underscore */

View File

@ -202,15 +202,15 @@ public final class TestSheet {
assertEquals("Should be no more merged regions", 0, sheet.getNumMergedRegions());
}
@Test
public void testGetMergedRegionAt() {
//TODO
}
// @Test
// public void testGetMergedRegionAt() {
// TODO
// }
@Test
public void testGetNumMergedRegions() {
//TODO
}
// @Test
// public void testGetNumMergedRegions() {
// TODO
// }
/**
* Makes sure all rows registered for this sheet are aggregated, they were being skipped

View File

@ -17,17 +17,25 @@
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.junit.Test;
/**
*
*/
public final class TestBOFRecord {
@Test
public void testBOFRecord() throws IOException {
// This used to throw an error before - #42794
HSSFTestDataSamples.openSampleWorkbook("bug_42794.xls").close();
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("bug_42794.xls")) {
Sheet sh = wb.getSheetAt(0);
for (int i=1; i<=10; i++) {
double act = sh.getRow(i).getCell(0).getNumericCellValue();
assertEquals(i, act, 0);
}
}
}
}

View File

@ -73,6 +73,7 @@ public final class TestCFRuleRecord {
}
}
@SuppressWarnings("squid:S2699")
@Test
public void testCreateCFRuleRecord() throws IOException {
try (HSSFWorkbook workbook = new HSSFWorkbook()) {
@ -96,6 +97,7 @@ public final class TestCFRuleRecord {
}
}
@SuppressWarnings("squid:S2699")
@Test
public void testCreateCFRule12Record() throws IOException {
try (HSSFWorkbook workbook = new HSSFWorkbook()) {
@ -422,7 +424,7 @@ public final class TestCFRuleRecord {
assertTrue(refNPtg.isRowRelative());
byte[] data = rr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(CFRuleRecord.sid, DATA_REFN, data);
confirmRecordEncoding(CFRuleRecord.sid, DATA_REFN, data);
}
@Test

View File

@ -56,6 +56,7 @@ public final class TestCommonObjectDataSubRecord {
assertEquals(18, record.getDataSize());
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
CommonObjectDataSubRecord record = new CommonObjectDataSubRecord();

View File

@ -72,6 +72,7 @@ public final class TestEmbeddedObjectRefSubRecord {
assertArrayEquals(ser, ser2);
}
@SuppressWarnings("squid:S2699")
@Test
public void testCameraTool_bug45912() {
/*
@ -95,6 +96,7 @@ public final class TestEmbeddedObjectRefSubRecord {
/**
* tests various examples of OLE controls
*/
@SuppressWarnings("squid:S2699")
@Test
public void testVarious() {
String[] rawData = {
@ -125,9 +127,10 @@ public final class TestEmbeddedObjectRefSubRecord {
EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data.length);
byte[] ser2 = rec.serialize();
TestcaseRecordInputStream.confirmRecordEncoding("Test record " + i, EORSR_SID, data, ser2);
confirmRecordEncoding("Test record " + i, EORSR_SID, data, ser2);
}
@SuppressWarnings("squid:S2699")
@Test
public void testVisioDrawing_bug46199() {
/*
@ -146,6 +149,6 @@ public final class TestEmbeddedObjectRefSubRecord {
// 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);
confirmRecordEncoding(EORSR_SID, data46199, ser2);
}
}

View File

@ -57,6 +57,7 @@ public final class TestExtendedFormatRecord {
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
// .fontindex = 0
@ -122,6 +123,7 @@ public final class TestExtendedFormatRecord {
@SuppressWarnings("squid:S2699")
@Test
public void testCloneOnto() {
ExtendedFormatRecord base = createEFR();

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record;
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.assertNotEquals;
@ -57,7 +58,7 @@ public final class TestExternalNameRecord {
assertEquals("FDS", enr.getText());
// bug 44695
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataFDS, enr.serialize());
confirmRecordEncoding(0x0023, dataFDS, enr.serialize());
}
@Test
@ -81,7 +82,7 @@ public final class TestExternalNameRecord {
assertFalse(enr.isPicureLink());
assertTrue(enr.isStdDocumentNameIdentifier());
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize());
confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize());
}
@Test
@ -96,7 +97,7 @@ public final class TestExternalNameRecord {
assertFalse(enr.isPicureLink());
assertFalse(enr.isStdDocumentNameIdentifier());
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataPlainName, enr.serialize());
confirmRecordEncoding(0x0023, dataPlainName, enr.serialize());
}
@Test
@ -121,7 +122,7 @@ public final class TestExternalNameRecord {
ExternalNameRecord enr = createSimpleENR(dataDDE);
assertEquals("010672AT0 MUNI,[RTG_MOODY_UNDERLYING,RTG_SP_UNDERLYING]", enr.getText());
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataDDE, enr.serialize());
confirmRecordEncoding(0x0023, dataDDE, enr.serialize());
}
@Test

View File

@ -18,6 +18,7 @@
package org.apache.poi.hssf.record;
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.assertNotEquals;
@ -67,6 +68,7 @@ public final class TestFontRecord {
assertEquals(21 + 4, record.getRecordSize());
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
// .fontheight = c8
@ -96,7 +98,7 @@ public final class TestFontRecord {
record.setFontName("Arial");
byte [] recordBytes = record.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(0x31, data, recordBytes);
confirmRecordEncoding(0x31, data, recordBytes);
}
@Test
@ -150,6 +152,6 @@ public final class TestFontRecord {
assertEquals(0, fr.getFontName().length());
byte[] recordBytes = fr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(SID, emptyNameData, recordBytes);
confirmRecordEncoding(SID, emptyNameData, recordBytes);
}
}

View File

@ -16,6 +16,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.assertNotEquals;
@ -453,12 +454,13 @@ public final class TestHyperlinkRecord {
}
@SuppressWarnings("squid:S2699")
@Test
public void testReserializeTargetFrame() {
RecordInputStream in = TestcaseRecordInputStream.create(HyperlinkRecord.sid, dataTargetFrame);
HyperlinkRecord hr = new HyperlinkRecord(in);
byte[] ser = hr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(HyperlinkRecord.sid, dataTargetFrame, ser);
confirmRecordEncoding(HyperlinkRecord.sid, dataTargetFrame, ser);
}
@Test
@ -467,7 +469,7 @@ public final class TestHyperlinkRecord {
RecordInputStream in = TestcaseRecordInputStream.create(HyperlinkRecord.sid, dataLinkToWorkbook);
HyperlinkRecord hr = new HyperlinkRecord(in);
byte[] ser = hr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(HyperlinkRecord.sid, dataLinkToWorkbook, ser);
confirmRecordEncoding(HyperlinkRecord.sid, dataLinkToWorkbook, ser);
assertNotEquals("Identified bug in reading workbook link", "YEARFR~1.XLS", hr.getAddress());
assertEquals("yearfracExamples.xls", hr.getAddress());
}
@ -478,7 +480,7 @@ public final class TestHyperlinkRecord {
RecordInputStream in = TestcaseRecordInputStream.create(HyperlinkRecord.sid, dataUNC);
HyperlinkRecord hr = new HyperlinkRecord(in);
byte[] ser = hr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(HyperlinkRecord.sid, dataUNC, ser);
confirmRecordEncoding(HyperlinkRecord.sid, dataUNC, ser);
assertNotNull(hr.toString());
}
@ -541,6 +543,6 @@ public final class TestHyperlinkRecord {
assertEquals("testfolder/test.PDF", link.getAddress());
byte[] ser = link.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(HyperlinkRecord.sid, data_47498, ser);
confirmRecordEncoding(HyperlinkRecord.sid, data_47498, ser);
}
}

View File

@ -18,6 +18,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.assertNull;
@ -71,7 +72,7 @@ public final class TestLbsDataSubRecord {
// check that it re-serializes to the same data
byte[] ser = record.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(ObjRecord.sid, data, ser);
confirmRecordEncoding(ObjRecord.sid, data, ser);
}
/**
@ -109,7 +110,7 @@ public final class TestLbsDataSubRecord {
// check that it re-serializes to the same data
byte[] ser = record.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(ObjRecord.sid, data, ser);
confirmRecordEncoding(ObjRecord.sid, data, ser);
}

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
import static org.junit.Assert.assertEquals;
import org.apache.poi.util.HexRead;
@ -37,6 +38,6 @@ public final class TestNameCommentRecord {
assertEquals("name", ncr.getNameText());
assertEquals("comment", ncr.getCommentText());
final byte[] data2 = ncr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(NameCommentRecord.sid, data, data2);
confirmRecordEncoding(NameCommentRecord.sid, data, data2);
}
}

View File

@ -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.assertNotEquals;
@ -68,7 +69,7 @@ public final class TestNameRecord {
NameRecord nr = new NameRecord(in);
assertEquals(0x0020, nr.getOptionFlag());
byte[] data2 = nr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(NameRecord.sid, data, data2);
confirmRecordEncoding(NameRecord.sid, data, data2);
}
@Test

View File

@ -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;
@ -64,7 +65,7 @@ public final class TestNoteRecord {
record.setAuthor("Apache Software Foundation");
byte[] ser = record.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(NoteRecord.sid, testData, ser);
confirmRecordEncoding(NoteRecord.sid, testData, ser);
}
@Test
@ -107,7 +108,7 @@ public final class TestNoteRecord {
assertTrue(nr.authorIsMultibyte());
byte[] ser = nr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(NoteRecord.sid, data, ser);
confirmRecordEncoding(NoteRecord.sid, data, ser);
// Re-check
in = TestcaseRecordInputStream.create(ser);

View File

@ -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.assertTrue;
@ -129,6 +130,7 @@ public final class TestObjRecord {
* Check that ObjRecord tolerates and preserves padding to a 4-byte boundary
* (normally padding is to a 2-byte boundary).
*/
@SuppressWarnings("squid:S2699")
@Test
public void test4BytePadding() {
// actual data from file saved by Excel 2007
@ -142,6 +144,6 @@ public final class TestObjRecord {
ObjRecord record = new ObjRecord(in);
// check that it re-serializes to the same data
byte[] ser = record.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(ObjRecord.sid, data, ser);
confirmRecordEncoding(ObjRecord.sid, data, ser);
}
}

View File

@ -50,6 +50,7 @@ public final class TestPaneRecord {
assertEquals( 14, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
PaneRecord record = new PaneRecord();

View File

@ -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;
@ -32,6 +33,7 @@ public final class TestRecalcIdRecord {
return result;
}
@SuppressWarnings("squid:S2699")
@Test
public void testBasicDeserializeReserialize() {
@ -41,7 +43,7 @@ public final class TestRecalcIdRecord {
"1D EB 01 00"); // engine id
RecalcIdRecord r = create(data);
TestcaseRecordInputStream.confirmRecordEncoding(RecalcIdRecord.sid, data, r.serialize());
confirmRecordEncoding(RecalcIdRecord.sid, data, r.serialize());
}
@Test

View File

@ -42,6 +42,7 @@ public final class TestSCLRecord {
assertEquals( 8, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
SCLRecord record = new SCLRecord();

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
import static org.junit.Assert.assertEquals;
import org.apache.poi.util.HexRead;
@ -35,6 +36,6 @@ public final class TestStyleRecord {
assertEquals("\u5E38\u89C4_Sheet1", sr.getName()); // "<Conventional>_Sheet1"
// bug 46385 - Incorrect number of bytes written - expected 27 but got 18
byte[] ser = sr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(StyleRecord.sid, data, ser);
confirmRecordEncoding(StyleRecord.sid, data, ser);
}
}

View File

@ -19,6 +19,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.assertNotEquals;
@ -141,6 +142,6 @@ public final class TestSubRecord {
ObjRecord or = new ObjRecord(in);
// make sure POI properly truncates the ObjRecord data
byte[] data2 = or.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(ObjRecord.sid, data, data2);
confirmRecordEncoding(ObjRecord.sid, data, data2);
}
}

View File

@ -26,6 +26,7 @@ import static org.apache.poi.hssf.record.SupBookRecord.CH_STARTUP_DIR;
import static org.apache.poi.hssf.record.SupBookRecord.CH_UP_DIR;
import static org.apache.poi.hssf.record.SupBookRecord.CH_VOLUME;
import static org.apache.poi.hssf.record.SupBookRecord.PATH_SEPERATOR;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -99,20 +100,22 @@ public final class TestSupBookRecord {
/**
* Tests that we can store the record
*/
@SuppressWarnings("squid:S2699")
@Test
public void testStoreIR() {
SupBookRecord record = SupBookRecord.createInternalReferences((short)4);
TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataIR, record.serialize());
confirmRecordEncoding(0x01AE, dataIR, record.serialize());
}
@SuppressWarnings("squid:S2699")
@Test
public void testStoreER() {
String url = "testURL";
String[] sheetNames = { "Sheet1", "Sheet2", };
SupBookRecord record = SupBookRecord.createExternalReferences(url, sheetNames);
TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataER, record.serialize());
confirmRecordEncoding(0x01AE, dataER, record.serialize());
}
@Test
@ -120,7 +123,7 @@ public final class TestSupBookRecord {
SupBookRecord record = SupBookRecord.createAddInFunctions();
assertEquals(1, record.getNumberOfSheets());
assertTrue(record.isAddInFunctions());
TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataAIF, record.serialize());
confirmRecordEncoding(0x01AE, dataAIF, record.serialize());
}
@Test

View File

@ -63,6 +63,7 @@ public final class TestTableRecord {
assertEquals( 16 + 4, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore()
{

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
import static org.junit.Assert.assertEquals;
import org.apache.poi.util.HexRead;
@ -61,7 +62,7 @@ public final class TestWriteAccessRecord {
+ "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());
confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
}
@Test
@ -90,6 +91,6 @@ public final class TestWriteAccessRecord {
+ "20 20 20 20 20 20 20 20 20 20 20 "
+ HEX_SIXTYFOUR_SPACES);
TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
}
}

View File

@ -58,6 +58,7 @@ public final class TestAreaFormatRecord {
assertEquals( 20, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
AreaFormatRecord record = new AreaFormatRecord();

View File

@ -48,6 +48,7 @@ public final class TestAreaRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
AreaRecord record = new AreaRecord();

View File

@ -42,6 +42,7 @@ public final class TestAxisLineFormatRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
AxisLineFormatRecord record = new AxisLineFormatRecord();

View File

@ -63,6 +63,7 @@ public final class TestAxisOptionsRecord {
assertEquals( 22, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
AxisOptionsRecord record = new AxisOptionsRecord();

View File

@ -50,6 +50,7 @@ public final class TestAxisParentRecord {
assertEquals( 22, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
AxisParentRecord record = new AxisParentRecord();

View File

@ -50,6 +50,7 @@ public final class TestAxisRecord {
assertEquals( 4 + 18, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
AxisRecord record = new AxisRecord();

View File

@ -42,6 +42,7 @@ public final class TestAxisUsedRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
AxisUsedRecord record = new AxisUsedRecord();

View File

@ -51,6 +51,7 @@ public final class TestBarRecord {
assertEquals( 10, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
BarRecord record = new BarRecord();

View File

@ -53,6 +53,7 @@ public final class TestCategorySeriesAxisRecord {
assertEquals( 4 + 8, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
CategorySeriesAxisRecord record = new CategorySeriesAxisRecord();

View File

@ -48,6 +48,7 @@ public final class TestChartRecord {
assertEquals( 20, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
ChartRecord record = new ChartRecord();
@ -56,7 +57,6 @@ public final class TestChartRecord {
record.setWidth( 30474216 );
record.setHeight( 15060168 );
byte [] recordBytes = record.serialize();
confirmRecordEncoding(ChartRecord.sid, data, recordBytes);
}

View File

@ -48,6 +48,7 @@ public final class TestDatRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
DatRecord record = new DatRecord();
@ -56,7 +57,6 @@ public final class TestDatRecord {
record.setBorder( true );
record.setShowSeriesKey( true );
byte [] recordBytes = record.serialize();
confirmRecordEncoding(DatRecord.sid, data, recordBytes);
}

View File

@ -50,6 +50,7 @@ public final class TestDataFormatRecord {
assertEquals( 12, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
DataFormatRecord record = new DataFormatRecord();

View File

@ -43,6 +43,7 @@ public final class TestDefaultDataLabelTextPropertiesRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
DefaultDataLabelTextPropertiesRecord record = new DefaultDataLabelTextPropertiesRecord();

View File

@ -50,6 +50,7 @@ public final class TestFontBasisRecord {
assertEquals( 14, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
FontBasisRecord record = new FontBasisRecord();

View File

@ -43,6 +43,7 @@ public final class TestFontIndexRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
FontIndexRecord record = new FontIndexRecord();

View File

@ -48,6 +48,7 @@ public final class TestFrameRecord {
assertEquals( 8, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
FrameRecord record = new FrameRecord();
@ -56,7 +57,6 @@ public final class TestFrameRecord {
record.setAutoSize( false );
record.setAutoPosition( true );
byte [] recordBytes = record.serialize();
confirmRecordEncoding(FrameRecord.sid, data, recordBytes);
}

View File

@ -62,22 +62,17 @@ public final class TestLegendRecord {
assertEquals(24, record.getRecordSize());
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
LegendRecord record = new LegendRecord();
record.setXAxisUpperLeft(0xe76);
record.setYAxisUpperLeft(0x786);
record.setXSize(0x119);
record.setYSize(0x8b);
record.setType((byte) 0x3);
record.setSpacing((byte) 0x1);
record.setOptions((short) 0x1f);
record.setAutoPosition(true);
record.setAutoSeries(true);

View File

@ -54,6 +54,7 @@ public final class TestLineFormatRecord {
assertEquals( 16, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
LineFormatRecord record = new LineFormatRecord();
@ -64,7 +65,6 @@ public final class TestLineFormatRecord {
record.setDrawTicks( false );
record.setColourPaletteIndex( (short)0x4d );
byte [] recordBytes = record.serialize();
confirmRecordEncoding(LineFormatRecord.sid, data, recordBytes);
}

View File

@ -175,6 +175,7 @@ recordid = 0x1051, size =8
assertEquals( data.length + 4, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
LinkedDataRecord record = new LinkedDataRecord();

View File

@ -42,6 +42,7 @@ public final class TestNumberFormatIndexRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
NumberFormatIndexRecord record = new NumberFormatIndexRecord();

View File

@ -45,6 +45,7 @@ public final class TestObjectLinkRecord {
assertEquals( 10, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
ObjectLinkRecord record = new ObjectLinkRecord();
@ -53,7 +54,6 @@ public final class TestObjectLinkRecord {
record.setLink1( (short)0x00 );
record.setLink2( (short)0x00 );
byte [] recordBytes = record.serialize();
confirmRecordEncoding(ObjectLinkRecord.sid, data, recordBytes);
}

View File

@ -45,13 +45,13 @@ public final class TestPlotGrowthRecord {
assertEquals( 12, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
PlotGrowthRecord record = new PlotGrowthRecord();
record.setHorizontalScale( 65536 );
record.setVerticalScale( 65536 );
byte [] recordBytes = record.serialize();
confirmRecordEncoding(PlotGrowthRecord.sid, data, recordBytes);
}

View File

@ -42,12 +42,12 @@ public final class TestSeriesChartGroupIndexRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
SeriesChartGroupIndexRecord record = new SeriesChartGroupIndexRecord();
record.setChartGroupIndex( (short)0 );
byte [] recordBytes = record.serialize();
confirmRecordEncoding(SeriesChartGroupIndexRecord.sid, data, recordBytes);
}

View File

@ -42,12 +42,12 @@ public final class TestSeriesIndexRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
SeriesIndexRecord record = new SeriesIndexRecord();
record.setIndex( (short)3 );
byte [] recordBytes = record.serialize();
confirmRecordEncoding(SeriesIndexRecord.sid, data, recordBytes);
}

View File

@ -50,6 +50,7 @@ public final class TestSeriesLabelsRecord {
assertEquals( 2+4, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
SeriesLabelsRecord record = new SeriesLabelsRecord();
@ -60,7 +61,6 @@ public final class TestSeriesLabelsRecord {
record.setShowLabel( false );
record.setShowBubbleSizes( false );
byte [] recordBytes = record.serialize();
confirmRecordEncoding(SeriesLabelsRecord.sid, data, recordBytes);
}

View File

@ -45,6 +45,7 @@ public final class TestSeriesListRecord {
assertEquals( 4 + 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
SeriesListRecord record = new SeriesListRecord(new short[] { (short)0x2001, (short)0xf0ff } );

View File

@ -53,6 +53,7 @@ public final class TestSeriesRecord {
assertEquals( 16, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
SeriesRecord record = new SeriesRecord();

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record.chart;
import static org.apache.poi.hssf.record.TestcaseRecordInputStream.confirmRecordEncoding;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -43,6 +44,7 @@ public final class TestSeriesTextRecord {
assertEquals(SIMPLE_DATA.length + 4, record.getRecordSize());
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
SeriesTextRecord record = new SeriesTextRecord();
@ -51,7 +53,7 @@ public final class TestSeriesTextRecord {
record.setText("Value Number");
byte[] recordBytes = record.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(SeriesTextRecord.sid, SIMPLE_DATA, recordBytes);
confirmRecordEncoding(SeriesTextRecord.sid, SIMPLE_DATA, recordBytes);
}
@Test
@ -88,6 +90,6 @@ public final class TestSeriesTextRecord {
assertTrue("Identified bug 45784b", str.getRecordSize() >= 0);
byte[] ser = str.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(SeriesTextRecord.sid, data, ser);
confirmRecordEncoding(SeriesTextRecord.sid, data, ser);
}
}

View File

@ -42,6 +42,7 @@ public final class TestSeriesToChartGroupRecord {
assertEquals( 0x6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
SeriesToChartGroupRecord record = new SeriesToChartGroupRecord();

View File

@ -56,6 +56,7 @@ public final class TestSheetPropertiesRecord {
assertEquals( 8, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
SheetPropertiesRecord record = new SheetPropertiesRecord();

View File

@ -81,6 +81,7 @@ public final class TestTextRecord {
assertEquals( 36, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
TextRecord record = new TextRecord();

View File

@ -63,6 +63,7 @@ public final class TestTickRecord {
assertEquals( 34, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
TickRecord record = new TickRecord();

View File

@ -43,6 +43,7 @@ public final class TestUnitsRecord {
assertEquals( 6, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
UnitsRecord record = new UnitsRecord();

View File

@ -64,6 +64,7 @@ public final class TestValueRangeRecord {
assertEquals( 42+4, record.getRecordSize() );
}
@SuppressWarnings("squid:S2699")
@Test
public void testStore() {
ValueRangeRecord record = new ValueRangeRecord();

View File

@ -44,6 +44,7 @@ public final class TestExtendedPivotTableViewFieldsRecord {
assertEquals(data.length, rec.getRecordSize());
}
@SuppressWarnings("squid:S2699")
@Test
public void testOlderFormat_bug46918() {
// There are 10 SXVDEX records in the file (not uploaded) that originated bugzilla 46918