aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2019-12-22 21:44:45 +0000
committerAndreas Beeker <kiwiwings@apache.org>2019-12-22 21:44:45 +0000
commitba6152503eb947266d9d3fc1ee599613acdb2eee (patch)
treea016637e0d9cfd3009aa614ebcf054a456297cb9 /src/testcases/org/apache
parentecb42bd78db3fbd2fd2e2c093554749329bb3123 (diff)
downloadpoi-ba6152503eb947266d9d3fc1ee599613acdb2eee.tar.gz
poi-ba6152503eb947266d9d3fc1ee599613acdb2eee.zip
#64004 - Replace clone() with copy constructor - mainly HSSF classes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1871911 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java23
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java74
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java9
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java26
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java51
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java76
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java90
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java10
12 files changed, 195 insertions, 175 deletions
diff --git a/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java b/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java
index 45819504f6..9bc4dfde22 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestAutoFilterInfoRecord.java
@@ -18,6 +18,7 @@
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
+
import junit.framework.TestCase;
/**
@@ -57,7 +58,7 @@ public final class TestAutoFilterInfoRecord extends TestCase {
record.setNumEntries((short)3);
byte[] src = record.serialize();
- AutoFilterInfoRecord cloned = record.clone();
+ AutoFilterInfoRecord cloned = record.copy();
assertEquals(3, record.getNumEntries());
byte[] cln = cloned.serialize();
diff --git a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
index acaddd0f6b..5b99e8c973 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
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;
@@ -42,8 +43,6 @@ import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
import org.apache.poi.util.LittleEndian;
import org.junit.Test;
-import junit.framework.AssertionFailedError;
-
/**
* Tests the serialization and deserialization of the TestCFRuleRecord
* class works correctly.
@@ -141,8 +140,8 @@ public final class TestCFRuleRecord {
record.getMultiStateFormatting().getThresholds()[1].setValue(10d);
record.getMultiStateFormatting().getThresholds()[2].setType(RangeType.NUMBER.id);
record.getMultiStateFormatting().getThresholds()[2].setValue(-4d);
-
- // Check it
+
+ // Check it
testCFRule12Record(record);
assertEquals(IconSet.GREY_5_ARROWS, record.getMultiStateFormatting().getIconSet());
assertEquals(5, record.getMultiStateFormatting().getThresholds().length);
@@ -156,7 +155,7 @@ public final class TestCFRuleRecord {
// 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);
@@ -172,10 +171,10 @@ public final class TestCFRuleRecord {
}
workbook.close();
}
-
+
private void testCFRuleRecord(CFRuleRecord record) {
testCFRuleBase(record);
-
+
assertFalse(record.isLeftBorderModified());
record.setLeftBorderModified(true);
assertTrue(record.isLeftBorderModified());
@@ -445,22 +444,22 @@ public final class TestCFRuleRecord {
byte[] data = rr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(CFRuleRecord.sid, DATA_REFN, data);
}
-
+
@Test
public void testBug53691() throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
CFRuleRecord record = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
-
- CFRuleRecord clone = record.clone();
-
+
+ CFRuleRecord clone = record.copy();
+
byte [] serializedRecord = record.serialize();
byte [] serializedClone = clone.serialize();
assertArrayEquals(serializedRecord, serializedClone);
workbook.close();
}
-
+
@Test
public void testBug57231_rewrite() throws IOException {
HSSFWorkbook wb1 = HSSFITestDataProvider.instance.openSampleWorkbook("57231_MixedGasReport.xls");
diff --git a/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java
index 3823072348..a4ba179be9 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestFtCblsSubRecord.java
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
+
import junit.framework.TestCase;
/**
@@ -56,7 +57,7 @@ public final class TestFtCblsSubRecord extends TestCase {
FtCblsSubRecord record = new FtCblsSubRecord();
byte[] src = record.serialize();
- FtCblsSubRecord cloned = record.clone();
+ FtCblsSubRecord cloned = record.copy();
byte[] cln = cloned.serialize();
assertEquals(record.getDataSize(), cloned.getDataSize());
diff --git a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
index 2379a29db4..b2290b1913 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
@@ -34,40 +34,40 @@ import org.junit.Test;
public final class TestHyperlinkRecord {
//link to http://www.lakings.com/
- private static final byte[] data1 = {
+ private static final byte[] data1 = {
0x02, 0x00, //First row of the hyperlink
0x02, 0x00, //Last row of the hyperlink
0x00, 0x00, //First column of the hyperlink
0x00, 0x00, //Last column of the hyperlink
-
+
//16-byte GUID. Seems to be always the same. Does not depend on the hyperlink type
(byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11,
(byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B,
-
+
0x02, 0x00, 0x00, 0x00, //integer, always 2
-
+
// flags. Define the type of the hyperlink:
// HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_ABS | HyperlinkRecord.HLINK_LABEL
0x17, 0x00, 0x00, 0x00,
-
+
0x08, 0x00, 0x00, 0x00, //length of the label including the trailing '\0'
-
+
//label:
0x4D, 0x00, 0x79, 0x00, 0x20, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x6B, 0x00, 0x00, 0x00,
-
+
//16-byte link moniker: HyperlinkRecord.URL_MONIKER
(byte)0xE0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11,
(byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B,
-
+
//count of bytes in the address including the tail
0x48, 0x00, 0x00, 0x00, //integer
-
+
//the actual link, terminated by '\u0000'
0x68, 0x00, 0x74, 0x00, 0x74, 0x00, 0x70, 0x00, 0x3A, 0x00, 0x2F, 0x00,
0x2F, 0x00, 0x77, 0x00, 0x77, 0x00, 0x77, 0x00, 0x2E, 0x00, 0x6C, 0x00,
0x61, 0x00, 0x6B, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x73, 0x00,
0x2E, 0x00, 0x63, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x2F, 0x00, 0x00, 0x00,
-
+
//standard 24-byte tail of a URL link. Seems to always be the same for all URL HLINKs
0x79, 0x58, (byte)0x81, (byte)0xF4, 0x3B, 0x1D, 0x7F, 0x48, (byte)0xAF, 0x2C,
(byte)0x82, 0x5D, (byte)0xC4, (byte)0x85, 0x27, 0x63, 0x00, 0x00, 0x00,
@@ -83,29 +83,29 @@ public final class TestHyperlinkRecord {
//16-bit GUID. Seems to be always the same. Does not depend on the hyperlink type
(byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11,
(byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B,
-
+
0x02, 0x00, 0x00, 0x00, //integer, always 2
-
+
0x15, 0x00, 0x00, 0x00, //options: HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_LABEL
-
+
0x05, 0x00, 0x00, 0x00, //length of the label
//label
0x66, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x00, 0x00,
-
+
//16-byte link moniker: HyperlinkRecord.FILE_MONIKER
0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
-
+
0x00, 0x00, //level
0x0A, 0x00, 0x00, 0x00, //length of the path )
-
+
//path to the file (plain ISO-8859 bytes, NOT UTF-16LE!)
0x6C, 0x69, 0x6E, 0x6B, 0x31, 0x2E, 0x78, 0x6C, 0x73, 0x00,
-
+
//standard 24-byte tail of a file link
(byte)0xFF, (byte)0xFF, (byte)0xAD, (byte)0xDE, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
-
+
0x00, 0x00, 0x00, 0x00, // length of address link field
};
@@ -115,25 +115,25 @@ public final class TestHyperlinkRecord {
0x01, 0x00,
0x00, 0x00,
0x00, 0x00,
-
+
//16-bit GUID. Seems to be always the same. Does not depend on the hyperlink type
(byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11,
(byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B,
-
+
0x02, 0x00, 0x00, 0x00, //integer, always 2
-
+
0x17, 0x00, 0x00, 0x00, //options: HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_ABS | HyperlinkRecord.HLINK_LABEL
-
+
0x06, 0x00, 0x00, 0x00, //length of the label
0x65, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x00, 0x00, //label
-
+
//16-byte link moniker: HyperlinkRecord.URL_MONIKER
(byte)0xE0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11,
(byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B,
-
+
//length of the address including the tail.
0x76, 0x00, 0x00, 0x00,
-
+
//the address is terminated by '\u0000'
0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x74, 0x00, 0x6F, 0x00,
0x3A, 0x00, 0x65, 0x00, 0x62, 0x00, 0x67, 0x00, 0x61, 0x00, 0x6E, 0x00,
@@ -143,7 +143,7 @@ public final class TestHyperlinkRecord {
0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x2C, 0x00,
0x25, 0x00, 0x32, 0x00, 0x30, 0x00, 0x45, 0x00, 0x62, 0x00, 0x67, 0x00,
0x61, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x21, 0x00, 0x00, 0x00,
-
+
//standard 24-byte tail of a URL link
0x79, 0x58, (byte)0x81, (byte)0xF4, 0x3B, 0x1D, 0x7F, 0x48, (byte)0xAF, (byte)0x2C,
(byte)0x82, 0x5D, (byte)0xC4, (byte)0x85, 0x27, 0x63, 0x00, 0x00, 0x00,
@@ -156,21 +156,21 @@ public final class TestHyperlinkRecord {
0x03, 0x00,
0x00, 0x00,
0x00, 0x00,
-
+
//16-bit GUID. Seems to be always the same. Does not depend on the hyperlink type
(byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11,
(byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B,
-
+
0x02, 0x00, 0x00, 0x00, //integer, always 2
-
+
0x1C, 0x00, 0x00, 0x00, //flags: HyperlinkRecord.HLINK_LABEL | HyperlinkRecord.HLINK_PLACE
-
+
0x06, 0x00, 0x00, 0x00, //length of the label
-
+
0x70, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x63, 0x00, 0x65, 0x00, 0x00, 0x00, //label
-
+
0x0A, 0x00, 0x00, 0x00, //length of the document link including trailing zero
-
+
//link: Sheet1!A1
0x53, 0x00, 0x68, 0x00, 0x65, 0x00, 0x65, 0x00, 0x74, 0x00, 0x31, 0x00, 0x21,
0x00, 0x41, 0x00, 0x31, 0x00, 0x00, 0x00
@@ -246,7 +246,7 @@ public final class TestHyperlinkRecord {
"61 00 72 00 65 00 5C 00 6D 00 79 00 44 00 69 00 " +
"72 00 5C 00 50 00 52 00 4F 00 44 00 4E 00 41 00 " +
"4D 00 45 00 2E 00 78 00 6C 00 73 00 00 00 " +
-
+
"0C 00 00 00 " + // textMark: PRODNAME!C2
"50 00 52 00 4F 00 44 00 4E 00 41 00 4D 00 45 00 21 00 " +
"43 00 32 00 00 00"
@@ -274,7 +274,7 @@ public final class TestHyperlinkRecord {
private void confirmGUID(GUID expectedGuid, GUID actualGuid) {
assertEquals(expectedGuid, actualGuid);
}
-
+
@Test
public void testReadURLLink(){
RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, data1);
@@ -442,7 +442,7 @@ public final class TestHyperlinkRecord {
for (final byte[] d : data) {
RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, d);
HyperlinkRecord link = new HyperlinkRecord(is);
- HyperlinkRecord clone = link.clone();
+ HyperlinkRecord clone = link.copy();
assertArrayEquals(link.serialize(), clone.serialize());
}
@@ -480,7 +480,7 @@ public final class TestHyperlinkRecord {
fail("Identified bug with option URL and UNC set at same time");
}
}
-
+
@Test
public void testGUID() {
GUID g;
diff --git a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
index f002aa8ebc..4694306d34 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java
@@ -22,7 +22,6 @@ import java.util.List;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.aggregates.MergedCellsTable;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
@@ -35,14 +34,14 @@ import org.apache.poi.ss.util.CellRangeAddress;
*
*/
public final class TestMergeCellsRecord extends TestCase {
-
+
/**
* Make sure when a clone is called, we actually clone it.
*/
public void testCloneReferences() {
CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), };
MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length);
- MergeCellsRecord clone = merge.clone();
+ MergeCellsRecord clone = merge.copy();
assertNotSame("Merged and cloned objects are the same", merge, clone);
@@ -56,7 +55,7 @@ public final class TestMergeCellsRecord extends TestCase {
assertNotSame(merge.getAreaAt(0), clone.getAreaAt(0));
}
-
+
private static final RecordVisitor dummyRecordVisitor = new RecordVisitor() {
@Override
public void visitRecord(Record r) {
@@ -67,7 +66,7 @@ public final class TestMergeCellsRecord extends TestCase {
MergedCellsTable mct = new MergedCellsTable();
List<Record> recList = new ArrayList<>();
CellRangeAddress[] cras = new CellRangeAddress[] {
- new CellRangeAddress(0, 0, 0, 3),
+ new CellRangeAddress(0, 0, 0, 3),
};
recList.add(new MergeCellsRecord(cras, 0, 1));
RecordStream rs = new RecordStream(recList, 0);
diff --git a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java
index 5f238f80c7..1f2e37709f 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java
@@ -18,9 +18,9 @@
package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
+
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-
import org.apache.poi.util.HexRead;
/**
@@ -53,7 +53,7 @@ public final class TestNoteRecord extends TestCase {
public void testWrite() {
NoteRecord record = new NoteRecord();
assertEquals(NoteRecord.sid, record.getSid());
-
+
record.setRow((short)6);
record.setColumn((short)1);
record.setFlags(NoteRecord.NOTE_VISIBLE);
@@ -73,7 +73,7 @@ public final class TestNoteRecord extends TestCase {
record.setShapeId((short)1026);
record.setAuthor("Apache Software Foundation");
- NoteRecord cloned = record.clone();
+ NoteRecord cloned = record.copy();
assertEquals(record.getRow(), cloned.getRow());
assertEquals(record.getColumn(), cloned.getColumn());
assertEquals(record.getFlags(), cloned.getFlags());
@@ -85,14 +85,14 @@ public final class TestNoteRecord extends TestCase {
byte[] cln = cloned.serialize();
assertArrayEquals(src, cln);
}
-
+
public void testUnicodeAuthor() {
- // This sample data was created by setting the 'user name' field in the 'Personalize'
- // section of Excel's options to \u30A2\u30D1\u30C3\u30C1\u65CF, and then
+ // This sample data was created by setting the 'user name' field in the 'Personalize'
+ // section of Excel's options to \u30A2\u30D1\u30C3\u30C1\u65CF, and then
// creating a cell comment.
byte[] data = HexRead.readFromString("01 00 01 00 00 00 03 00 " +
"05 00 01 " + // len=5, 16bit
- "A2 30 D1 30 C3 30 C1 30 CF 65 " + // character data
+ "A2 30 D1 30 C3 30 C1 30 CF 65 " + // character data
"00 " // padding byte
);
RecordInputStream in = TestcaseRecordInputStream.create(NoteRecord.sid, data);
@@ -102,7 +102,7 @@ public final class TestNoteRecord extends TestCase {
}
assertEquals("\u30A2\u30D1\u30C3\u30C1\u65CF", nr.getAuthor());
assertTrue(nr.authorIsMultibyte());
-
+
byte[] ser = nr.serialize();
TestcaseRecordInputStream.confirmRecordEncoding(NoteRecord.sid, data, ser);
@@ -111,23 +111,23 @@ public final class TestNoteRecord extends TestCase {
nr = new NoteRecord(in);
assertEquals("\u30A2\u30D1\u30C3\u30C1\u65CF", nr.getAuthor());
assertTrue(nr.authorIsMultibyte());
-
-
+
+
// Change to a non unicode author, will stop being unicode
nr.setAuthor("Simple");
ser = nr.serialize();
in = TestcaseRecordInputStream.create(ser);
nr = new NoteRecord(in);
-
+
assertEquals("Simple", nr.getAuthor());
assertFalse(nr.authorIsMultibyte());
-
+
// Now set it back again
nr.setAuthor("Unicode\u1234");
ser = nr.serialize();
in = TestcaseRecordInputStream.create(ser);
nr = new NoteRecord(in);
-
+
assertEquals("Unicode\u1234", nr.getAuthor());
assertTrue(nr.authorIsMultibyte());
}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java
index 5a4d5c887c..30631243a5 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestNoteStructureSubRecord.java
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.record;
import static org.junit.Assert.assertArrayEquals;
+
import junit.framework.TestCase;
/**
@@ -58,7 +59,7 @@ public final class TestNoteStructureSubRecord extends TestCase {
NoteStructureSubRecord record = new NoteStructureSubRecord();
byte[] src = record.serialize();
- NoteStructureSubRecord cloned = record.clone();
+ NoteStructureSubRecord cloned = record.copy();
byte[] cln = cloned.serialize();
assertEquals(record.getDataSize(), cloned.getDataSize());
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java b/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java
index e2b2652a43..e024f67af4 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java
@@ -18,23 +18,34 @@
package org.apache.poi.hssf.record;
import junit.framework.TestCase;
-
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
import org.apache.poi.util.IntMapper;
+import org.apache.poi.util.LittleEndianConsts;
/**
* Tests that records size calculates correctly.
- *
+ *
* @author Glen Stampoultzis (glens at apache.org)
*/
public final class TestSSTRecordSizeCalculator extends TestCase {
private static final String SMALL_STRING = "Small string";
private static final int COMPRESSED_PLAIN_STRING_OVERHEAD = 3;
private static final int OPTION_FIELD_SIZE = 1;
-
+
private final IntMapper<UnicodeString> strings = new IntMapper<>();
+
+ /** standard record overhead: two shorts (record id plus data space size)*/
+ private static final int STD_RECORD_OVERHEAD = 2 * LittleEndianConsts.SHORT_SIZE;
+
+ /** SST overhead: the standard record overhead, plus the number of strings and the number of unique strings -- two ints */
+ private static final int SST_RECORD_OVERHEAD = STD_RECORD_OVERHEAD + 2 * LittleEndianConsts.INT_SIZE;
+
+ /** how much data can we stuff into an SST record? That would be _max minus the standard SST record overhead */
+ private static final int MAX_DATA_SPACE = RecordInputStream.MAX_RECORD_DATA_SIZE - 8;
+
+
private void confirmSize(int expectedSize) {
ContinuableRecordOutput cro = ContinuableRecordOutput.createForCountingOnly();
SSTSerializer ss = new SSTSerializer(strings, 0, 0);
@@ -44,64 +55,64 @@ public final class TestSSTRecordSizeCalculator extends TestCase {
public void testBasic() {
strings.add(makeUnicodeString(SMALL_STRING));
- confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+ confirmSize(SST_RECORD_OVERHEAD
+ COMPRESSED_PLAIN_STRING_OVERHEAD
+ SMALL_STRING.length());
}
public void testBigStringAcrossUnicode() {
- int bigString = SSTRecord.MAX_DATA_SPACE + 100;
+ int bigString = MAX_DATA_SPACE + 100;
strings.add(makeUnicodeString(bigString));
- confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+ confirmSize(SST_RECORD_OVERHEAD
+ COMPRESSED_PLAIN_STRING_OVERHEAD
- + SSTRecord.MAX_DATA_SPACE
- + SSTRecord.STD_RECORD_OVERHEAD
+ + MAX_DATA_SPACE
+ + STD_RECORD_OVERHEAD
+ OPTION_FIELD_SIZE
+ 100);
}
public void testPerfectFit() {
- int perfectFit = SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD;
+ int perfectFit = MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD;
strings.add(makeUnicodeString(perfectFit));
- confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+ confirmSize(SST_RECORD_OVERHEAD
+ COMPRESSED_PLAIN_STRING_OVERHEAD
+ perfectFit);
}
public void testJustOversized() {
- int tooBig = SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD + 1;
+ int tooBig = MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD + 1;
strings.add(makeUnicodeString(tooBig));
- confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+ confirmSize(SST_RECORD_OVERHEAD
+ COMPRESSED_PLAIN_STRING_OVERHEAD
+ tooBig - 1
// continue record
- + SSTRecord.STD_RECORD_OVERHEAD
+ + STD_RECORD_OVERHEAD
+ OPTION_FIELD_SIZE + 1);
}
public void testSecondStringStartsOnNewContinuation() {
- int perfectFit = SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD;
+ int perfectFit = MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD;
strings.add(makeUnicodeString(perfectFit));
strings.add(makeUnicodeString(SMALL_STRING));
- confirmSize(SSTRecord.SST_RECORD_OVERHEAD
- + SSTRecord.MAX_DATA_SPACE
+ confirmSize(SST_RECORD_OVERHEAD
+ + MAX_DATA_SPACE
// second string
- + SSTRecord.STD_RECORD_OVERHEAD
+ + STD_RECORD_OVERHEAD
+ COMPRESSED_PLAIN_STRING_OVERHEAD
+ SMALL_STRING.length());
}
public void testHeaderCrossesNormalContinuePoint() {
- int almostPerfectFit = SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD - 2;
+ int almostPerfectFit = MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD - 2;
strings.add(makeUnicodeString(almostPerfectFit));
String oneCharString = new String(new char[1]);
strings.add(makeUnicodeString(oneCharString));
- confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+ confirmSize(SST_RECORD_OVERHEAD
+ COMPRESSED_PLAIN_STRING_OVERHEAD
+ almostPerfectFit
// second string
- + SSTRecord.STD_RECORD_OVERHEAD
+ + STD_RECORD_OVERHEAD
+ COMPRESSED_PLAIN_STRING_OVERHEAD
+ oneCharString.length());
diff --git a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
index a6bcf3e607..77449ca640 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
@@ -139,7 +139,7 @@ public final class TestTextObjectRecord extends TestCase {
obj.setStr( str );
- TextObjectRecord cloned = (TextObjectRecord)obj.clone();
+ TextObjectRecord cloned = obj.copy();
assertEquals(obj.getRecordSize(), cloned.getRecordSize());
assertEquals(obj.getHorizontalTextAlignment(), cloned.getHorizontalTextAlignment());
assertEquals(obj.getStr().getString(), cloned.getStr().getString());
diff --git a/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java b/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
index 1a823e3aaa..d8f4b76b02 100644
--- a/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
+++ b/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
@@ -26,8 +26,6 @@ import java.io.IOException;
import org.apache.poi.hssf.record.ContinueRecord;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.SSTRecord;
-import org.apache.poi.hssf.record.common.UnicodeString.ExtRst;
-import org.apache.poi.hssf.record.common.UnicodeString.FormatRun;
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
import org.apache.poi.hssf.usermodel.HSSFOptimiser;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -93,9 +91,9 @@ public final class TestUnicodeString {
//Test a compressed small string that has rich text formatting
s.setString("Test");
s.setOptionFlags((byte)0x8);
- UnicodeString.FormatRun r = new UnicodeString.FormatRun((short)0,(short)1);
+ FormatRun r = new FormatRun((short)0,(short)1);
s.addFormatRun(r);
- UnicodeString.FormatRun r2 = new UnicodeString.FormatRun((short)2,(short)2);
+ FormatRun r2 = new FormatRun((short)2,(short)2);
s.addFormatRun(r2);
confirmSize(17, s);
@@ -108,7 +106,7 @@ public final class TestUnicodeString {
s.setString("Test");
s.setOptionFlags((byte)0xC);
confirmSize(17, s);
-
+
// Extended phonetics data
// Minimum size is 14
// Also adds 4 bytes to hold the length
@@ -121,7 +119,7 @@ public final class TestUnicodeString {
s.setString(STR_16_BIT);
s.setOptionFlags((byte)0xD);
confirmSize(39, s);
-
+
s.setExtendedRst(null);
confirmSize(21, s);
}
@@ -144,8 +142,8 @@ public final class TestUnicodeString {
public void perfectRichStringSize() {
//Test a rich text string
UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1-8-2);
- s.addFormatRun(new UnicodeString.FormatRun((short)1,(short)0));
- s.addFormatRun(new UnicodeString.FormatRun((short)2,(short)1));
+ s.addFormatRun(new FormatRun((short)1,(short)0));
+ s.addFormatRun(new FormatRun((short)2,(short)1));
s.setOptionFlags((byte)0x8);
confirmSize(MAX_DATA_SIZE, s);
@@ -153,8 +151,8 @@ public final class TestUnicodeString {
//Note that we can only ever get to a maximum size of 8227 since an uncompressed
//string is writing double bytes.
s = makeUnicodeString((MAX_DATA_SIZE-2-1-8-2)/2, true);
- s.addFormatRun(new UnicodeString.FormatRun((short)1,(short)0));
- s.addFormatRun(new UnicodeString.FormatRun((short)2,(short)1));
+ s.addFormatRun(new FormatRun((short)1,(short)0));
+ s.addFormatRun(new FormatRun((short)2,(short)1));
s.setOptionFlags((byte)0x9);
confirmSize(MAX_DATA_SIZE-1, s);
}
@@ -180,25 +178,25 @@ public final class TestUnicodeString {
UnicodeString s = makeUnicodeString(strSize);
confirmSize(MAX_DATA_SIZE*2, s);
}
-
+
@Test
public void formatRun() {
FormatRun fr = new FormatRun((short)4, (short)0x15c);
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
-
+
fr.serialize(out);
-
+
byte[] b = baos.toByteArray();
assertEquals(4, b.length);
assertEquals(4, b[0]);
assertEquals(0, b[1]);
assertEquals(0x5c, b[2]);
assertEquals(0x01, b[3]);
-
+
LittleEndianInputStream inp = new LittleEndianInputStream(
new ByteArrayInputStream(b)
);
@@ -206,34 +204,34 @@ public final class TestUnicodeString {
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
}
-
+
@Test
public void extRstFromEmpty() {
ExtRst ext = new ExtRst();
-
+
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals(0, ext.getFormattingOptions());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
assertEquals(10, ext.getDataSize()); // Excludes 4 byte header
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
ContinuableRecordOutput cout = new ContinuableRecordOutput(out, 0xffff);
-
+
ext.serialize(cout);
cout.writeContinue();
-
+
byte[] b = baos.toByteArray();
assertEquals(20, b.length);
-
+
// First 4 bytes from the outputstream
assertEquals(-1, b[0]);
assertEquals(-1, b[1]);
assertEquals(14, b[2]);
assertEquals(0, b[3]);
-
+
// Reserved
assertEquals(1, b[4]);
assertEquals(0, b[5]);
@@ -253,12 +251,12 @@ public final class TestUnicodeString {
assertEquals(0, b[15]);
assertEquals(0, b[16]);
assertEquals(0, b[17]);
-
+
// Last 2 bytes from the outputstream
assertEquals(ContinueRecord.sid, b[18]);
assertEquals(0, b[19]);
-
-
+
+
// Load in again and re-test
byte[] data = new byte[14];
System.arraycopy(b, 4, data, 0, data.length);
@@ -266,14 +264,14 @@ public final class TestUnicodeString {
new ByteArrayInputStream(data)
);
ext = new ExtRst(inp, data.length);
-
+
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals(0, ext.getFormattingOptions());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
}
-
+
@Test
public void extRstFromData() {
byte[] data = new byte[] {
@@ -284,39 +282,39 @@ public final class TestUnicodeString {
0, 0 // Cruft at the end, as found from real files
};
assertEquals(16, data.length);
-
+
LittleEndianInputStream inp = new LittleEndianInputStream(
new ByteArrayInputStream(data)
);
ExtRst ext = new ExtRst(inp, data.length);
assertEquals(0x0c, ext.getDataSize()); // Excludes 4 byte header
-
+
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0x37, ext.getFormattingOptions());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
}
-
+
@Test
public void corruptExtRstDetection() {
byte[] data = new byte[] {
- 0x79, 0x79, 0x11, 0x11,
- 0x22, 0x22, 0x33, 0x33,
+ 0x79, 0x79, 0x11, 0x11,
+ 0x22, 0x22, 0x33, 0x33,
};
assertEquals(8, data.length);
-
+
LittleEndianInputStream inp = new LittleEndianInputStream(
new ByteArrayInputStream(data)
);
ExtRst ext = new ExtRst(inp, data.length);
-
+
// Will be empty
assertEquals(ext, new ExtRst());
// If written, will be the usual size
assertEquals(10, ext.getDataSize()); // Excludes 4 byte header
-
+
// Is empty
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0, ext.getFormattingOptions());
@@ -342,12 +340,12 @@ public final class TestUnicodeString {
bos.writeShort(1);
bos.writeShort(3);
bos.writeShort(42);
-
+
LittleEndianInput in = new LittleEndianByteArrayInputStream(buf, 0, bos.getWriteIndex());
- UnicodeString.ExtRst extRst1 = new UnicodeString.ExtRst(in, bos.getWriteIndex());
+ ExtRst extRst1 = new ExtRst(in, bos.getWriteIndex());
in = new LittleEndianByteArrayInputStream(buf, 0, bos.getWriteIndex());
- UnicodeString.ExtRst extRst2 = new UnicodeString.ExtRst(in, bos.getWriteIndex());
-
+ ExtRst extRst2 = new ExtRst(in, bos.getWriteIndex());
+
assertEquals(extRst1, extRst2);
assertEquals(extRst1.hashCode(), extRst2.hashCode());
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
index e3f4aeaef2..f3bb535b12 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
@@ -77,7 +77,7 @@ import org.junit.Test;
*/
public final class TestHSSFWorkbook extends BaseTestWorkbook {
private static final HSSFITestDataProvider _testDataProvider = HSSFITestDataProvider.instance;
-
+
public TestHSSFWorkbook() {
super(_testDataProvider);
}
@@ -215,10 +215,10 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
confirmActiveSelected(sheet2, true);
confirmActiveSelected(sheet3, false);
confirmActiveSelected(sheet4, false);
-
+
wb.close();
}
-
+
private static List<Integer> arrayToList(int[] array) {
List<Integer> list = new ArrayList<>(array.length);
for ( Integer element : array ) {
@@ -226,7 +226,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
}
return list;
}
-
+
private static void assertCollectionsEquals(Collection<Integer> expected, Collection<Integer> actual) {
assertEquals("size", expected.size(), actual.size());
for (int e : expected) {
@@ -247,7 +247,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
HSSFSheet sheet4 = wb.createSheet("Sheet4");
HSSFSheet sheet5 = wb.createSheet("Sheet5");
-
+
List<Integer> selected = arrayToList(new int[] { 0, 2, 3 });
wb.setSelectedTabs(selected);
@@ -292,7 +292,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
throw new RuntimeException(e);
}
}*/
-
+
wb.close();
}
@@ -358,7 +358,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
// The last remaining sheet should always be active+selected
wb.removeSheetAt(1);
confirmActiveSelected(sheet0, true, true);
-
+
wb.close();
}
@@ -394,7 +394,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
// Expected badly behaved sheet record to cause exception
assertTrue(e.getMessage().startsWith("Actual serialized sheet size"));
}
-
+
wb.close();
}
@@ -482,7 +482,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertEquals("OnSheet3", n.getNameName());
assertEquals("Sheet3", n.getSheetName());
assertEquals("Sheet3!$A$1:$A$2", n.getRefersToFormula());
-
+
b.close();
}
@@ -505,6 +505,10 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
public int getRecordSize() {
return 8;
}
+ @Override
+ public BadlyBehavedRecord copy() {
+ return null;
+ }
}
/**
@@ -571,12 +575,12 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
ClassID clsid2 = fs2.getRoot().getStorageClsid();
assertEquals(clsid1, clsid2);
-
+
fs2.close();
wb.close();
fs1.close();
}
-
+
/**
* If we try to open an old (pre-97) workbook, we get a helpful
* Exception give to explain what we've done wrong
@@ -591,7 +595,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertContains(e.getMessage(), "BIFF4");
}
excel4.close();
-
+
InputStream excel5 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_5.xls");
try {
new HSSFWorkbook(excel5).close();
@@ -600,7 +604,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertContains(e.getMessage(), "BIFF5");
}
excel5.close();
-
+
InputStream excel95 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_95.xls");
try {
new HSSFWorkbook(excel95).close();
@@ -722,7 +726,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
"You can define up to 4000 styles in a .xls workbook", e.getMessage());
}
assertEquals(MAX_STYLES, wb.getNumCellStyles());
-
+
wb.close();
}
@@ -809,7 +813,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
EscherBSERecord bse = iwb.getBSERecord(pictureIndex);
assertEquals(3, bse.getRef());
}
-
+
wb.close();
}
@@ -829,7 +833,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
@Test
public void selectedSheetShort() throws IOException {
HSSFWorkbook wb=new HSSFWorkbook();
-
+
HSSFSheet sheet1 = wb.createSheet("Sheet1");
HSSFSheet sheet2 = wb.createSheet("Sheet2");
HSSFSheet sheet3 = wb.createSheet("Sheet3");
@@ -895,7 +899,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage(), e.getMessage().contains("outside the allowable range"));
}
-
+
wb.close();
}
@@ -905,7 +909,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
wb.insertChartRecord();
//wb.dumpDrawingGroupRecords(true);
//wb.dumpDrawingGroupRecords(false);
-
+
wb.close();
}
@@ -917,7 +921,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
wb.writeProtectWorkbook("mypassword", "myuser");
assertTrue(wb.isWriteProtected());
-
+
// OutputStream os = new FileOutputStream("/tmp/protected.xls");
// try {
// wb.write(os);
@@ -1008,7 +1012,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
read.close();
wb.close();
}
-
+
@Test
public void bug54500() throws Exception {
String nameName = "AName";
@@ -1016,7 +1020,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("54500.xls");
assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3");
-
+
wb.createSheet(sheetName);
assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
@@ -1030,7 +1034,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
final HSSFName name = wb.getName(nameName);
assertNotNull(name);
assertEquals("ASheet!A1", name.getRefersToFormula());
-
+
ByteArrayOutputStream stream = new ByteArrayOutputStream();
wb.write(stream);
@@ -1068,7 +1072,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
public void test49423() throws Exception
{
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("49423.xls");
-
+
boolean found = false;
int numSheets = workbook.getNumberOfSheets();
for (int i = 0; i < numSheets; i++) {
@@ -1076,7 +1080,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
List<HSSFShape> shapes = sheet.getDrawingPatriarch().getChildren();
for(HSSFShape shape : shapes){
HSSFAnchor anchor = shape.getAnchor();
-
+
if(anchor instanceof HSSFClientAnchor){
// absolute coordinates
HSSFClientAnchor clientAnchor = (HSSFClientAnchor)anchor;
@@ -1084,7 +1088,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
//System.out.println(clientAnchor.getRow1() + "," + clientAnchor.getRow2());
found = true;
} else if (anchor instanceof HSSFChildAnchor){
- // shape is grouped and the anchor is expressed in the coordinate system of the group
+ // shape is grouped and the anchor is expressed in the coordinate system of the group
HSSFChildAnchor childAnchor = (HSSFChildAnchor)anchor;
assertNotNull(childAnchor);
//System.out.println(childAnchor.getDy1() + "," + childAnchor.getDy2());
@@ -1092,7 +1096,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
}
}
}
-
+
assertTrue("Should find some images via Client or Child anchors, but did not find any at all", found);
workbook.close();
}
@@ -1108,10 +1112,10 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
final Sheet sheet = workbook.createSheet("foo");
final Row row = sheet.createRow(1);
row.createCell(1).setCellValue("bar");
-
+
writeAndCloseWorkbook(workbook, file);
}
-
+
// edit the workbook
{
try (POIFSFileSystem fs = new POIFSFileSystem(file, false)) {
@@ -1143,17 +1147,17 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
fileOut.close();
}
-
+
@Test
public void closeDoesNotModifyWorkbook() throws IOException {
final String filename = "SampleSS.xls";
final File file = POIDataSamples.getSpreadSheetInstance().getFile(filename);
Workbook wb;
-
+
// File via POIFileStream (java.nio)
wb = new HSSFWorkbook(new POIFSFileSystem(file));
assertCloseDoesNotModifyFile(filename, wb);
-
+
// InputStream
wb = new HSSFWorkbook(new FileInputStream(file));
assertCloseDoesNotModifyFile(filename, wb);
@@ -1171,11 +1175,11 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
throw new Exception("Moving a sheet to the end should not throw an exception, but threw ", e);
}
}
-
+
@Test
public void invalidInPlaceWrite() throws Exception {
HSSFWorkbook wb;
-
+
// Can't work for new files
wb = new HSSFWorkbook();
try {
@@ -1185,7 +1189,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
// expected here
}
wb.close();
-
+
// Can't work for InputStream opened files
wb = new HSSFWorkbook(
POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls"));
@@ -1196,7 +1200,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
// expected here
}
wb.close();
-
+
// Can't work for Read-Only files
POIFSFileSystem fs = new POIFSFileSystem(
POIDataSamples.getSpreadSheetInstance().getFile("SampleSS.xls"), true);
@@ -1209,7 +1213,7 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
}
wb.close();
}
-
+
@Test
public void inPlaceWrite() throws Exception {
// Setup as a copy of a known-good file
@@ -1218,27 +1222,27 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
FileOutputStream outputStream = new FileOutputStream(file)) {
IOUtils.copy(inputStream, outputStream);
}
-
+
// Open from the temp file in read-write mode
HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(file, false));
assertEquals(3, wb.getNumberOfSheets());
-
+
// Change
wb.removeSheetAt(2);
wb.removeSheetAt(1);
wb.getSheetAt(0).getRow(0).getCell(0).setCellValue("Changed!");
-
+
// Save in-place, close, re-open and check
wb.write();
wb.close();
-
+
wb = new HSSFWorkbook(new POIFSFileSystem(file));
assertEquals(1, wb.getNumberOfSheets());
assertEquals("Changed!", wb.getSheetAt(0).getRow(0).getCell(0).toString());
wb.close();
}
-
+
@Test
public void testWriteToNewFile() throws Exception {
// Open from a Stream
@@ -1249,13 +1253,13 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
wb.write(file);
wb.close();
-
+
// Read and check
wb = new HSSFWorkbook(new POIFSFileSystem(file));
assertEquals(3, wb.getNumberOfSheets());
wb.close();
}
-
+
@Ignore
@Test
@Override
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java
index bf17bca54f..0dbd1e6ae6 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java
@@ -41,7 +41,7 @@ public class TestAbstractFunctionPtg {
public void testInvalidRuntimeClass() {
new FunctionPtg(1, 300, null, 255);
}
-
+
private static class FunctionPtg extends AbstractFunctionPtg {
protected FunctionPtg(int functionIndex, int pReturnClass,
@@ -54,7 +54,13 @@ public class TestAbstractFunctionPtg {
}
public void write(LittleEndianOutput out) {
-
+
+ }
+
+ @Override
+ public FunctionPtg copy() {
+ // immutable
+ return this;
}
}
}