aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/poi/hssf/record/HyperlinkRecord.java8
-rw-r--r--src/java/org/apache/poi/hssf/record/common/UnicodeString.java45
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java6
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java6
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java8
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFRow.java9
-rw-r--r--src/java/org/apache/poi/ss/util/CellReference.java6
-rw-r--r--src/java/org/apache/poi/ss/util/Region.java8
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java6
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java8
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java9
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java7
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java7
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java7
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java7
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java7
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java9
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java7
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java7
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java8
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java7
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java7
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java8
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/record/AllRecordTests.java137
-rw-r--r--src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java65
26 files changed, 318 insertions, 99 deletions
diff --git a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
index f13d7f0eb4..026f99754b 100644
--- a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
+++ b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
@@ -90,7 +90,13 @@ public final class HyperlinkRecord extends StandardRecord {
&& _d3 == other._d3 && _d4 == other._d4;
}
- public int getD1() {
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
+ public int getD1() {
return _d1;
}
diff --git a/src/java/org/apache/poi/hssf/record/common/UnicodeString.java b/src/java/org/apache/poi/hssf/record/common/UnicodeString.java
index 9e9ca03925..a9ba7b5ea4 100644
--- a/src/java/org/apache/poi/hssf/record/common/UnicodeString.java
+++ b/src/java/org/apache/poi/hssf/record/common/UnicodeString.java
@@ -18,14 +18,21 @@
package org.apache.poi.hssf.record.common;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import org.apache.poi.hssf.record.cont.ContinuableRecordInput;
import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.record.cont.ContinuableRecordInput;
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
-import org.apache.poi.util.*;
+import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.LittleEndianInput;
+import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.StringUtil;
/**
* Title: Unicode String<p/>
@@ -88,6 +95,12 @@ public class UnicodeString implements Comparable<UnicodeString> { // TODO - make
return _character - r._character;
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
public String toString() {
return "character="+_character+",fontIndex="+_fontIndex;
}
@@ -248,17 +261,33 @@ public class UnicodeString implements Comparable<UnicodeString> { // TODO - make
if(result != 0) return result;
result = phRuns[i].realTextFirstCharacterOffset - o.phRuns[i].realTextFirstCharacterOffset;
if(result != 0) return result;
- result = phRuns[i].realTextFirstCharacterOffset - o.phRuns[i].realTextLength;
+ result = phRuns[i].realTextLength - o.phRuns[i].realTextLength;
if(result != 0) return result;
}
- result = extraData.length - o.extraData.length;
- if(result != 0) return result;
+ result = Arrays.hashCode(extraData)-Arrays.hashCode(o.extraData);
- // If we get here, it's the same
- return 0;
+ return result;
}
-
+
+ @Override
+ public int hashCode() {
+ int hash = reserved;
+ hash = 31*hash+formattingFontIndex;
+ hash = 31*hash+formattingOptions;
+ hash = 31*hash+numberOfRuns;
+ hash = 31*hash+phoneticText.hashCode();
+
+ if (phRuns != null) {
+ for (PhRun ph : phRuns) {
+ hash = 31*hash+ph.phoneticTextFirstCharacterOffset;
+ hash = 31*hash+ph.realTextFirstCharacterOffset;
+ hash = 31*hash+ph.realTextLength;
+ }
+ }
+ return hash;
+ }
+
protected ExtRst clone() {
ExtRst ext = new ExtRst();
ext.reserved = reserved;
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java b/src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java
index be69c2a98d..a7a88c6b6b 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java
@@ -140,4 +140,10 @@ public final class HSSFChildAnchor extends HSSFAnchor {
return anchor.getDx1() == getDx1() && anchor.getDx2() == getDx2() && anchor.getDy1() == getDy1()
&& anchor.getDy2() == getDy2();
}
+
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java
index b1df28f221..0a65bbd8ff 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java
@@ -275,6 +275,12 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
}
@Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
+ @Override
public int getDx1() {
return _escherClientAnchor.getDx1();
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
index 434b7eff34..76572de746 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
@@ -301,6 +301,7 @@ public final class HSSFRichTextString implements Comparable<HSSFRichTextString>,
return _string.compareTo(r._string);
}
+ @Override
public boolean equals(Object o) {
if (o instanceof HSSFRichTextString) {
return _string.equals(((HSSFRichTextString)o)._string);
@@ -309,6 +310,13 @@ public final class HSSFRichTextString implements Comparable<HSSFRichTextString>,
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
+
/**
* @return the plain text representation of this string.
*/
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
index 6f6340afa3..1ef2acfc74 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
@@ -23,10 +23,10 @@ import java.util.NoSuchElementException;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.util.Configurator;
/**
@@ -684,6 +684,7 @@ public final class HSSFRow implements Row {
return -1;
}
+ @Override
public boolean equals(Object obj)
{
if (!(obj instanceof HSSFRow))
@@ -698,4 +699,10 @@ public final class HSSFRow implements Row {
}
return false;
}
+
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
}
diff --git a/src/java/org/apache/poi/ss/util/CellReference.java b/src/java/org/apache/poi/ss/util/CellReference.java
index b43eb1bfc6..0b063ec8b1 100644
--- a/src/java/org/apache/poi/ss/util/CellReference.java
+++ b/src/java/org/apache/poi/ss/util/CellReference.java
@@ -517,4 +517,10 @@ public class CellReference {
&& _isRowAbs == cr._isColAbs
&& _isColAbs == cr._isColAbs;
}
+
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
}
diff --git a/src/java/org/apache/poi/ss/util/Region.java b/src/java/org/apache/poi/ss/util/Region.java
index d0c373838c..b39681917a 100644
--- a/src/java/org/apache/poi/ss/util/Region.java
+++ b/src/java/org/apache/poi/ss/util/Region.java
@@ -164,6 +164,14 @@ public class Region implements Comparable<Region> {
return (compareTo(r) == 0);
}
+
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
+
/**
* Compares that the given region is the same less than or greater than this
* region. If any regional coordiant passed in is less than this regions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
index d1c7035160..14dbaff14d 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
@@ -173,6 +173,12 @@ public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
@Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
+ @Override
public String toString(){
return "from : " + cell1.toString() + "; to: " + cell2.toString();
}
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java
index e4b4e61f4d..6c8666f7aa 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java
@@ -181,7 +181,8 @@ public final class Ffn
}
- public boolean equals(Object o)
+ @Override
+ public boolean equals(Object o)
{
boolean retVal = true;
@@ -227,6 +228,11 @@ public final class Ffn
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
}
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java
index 55bad615a0..0abd236a07 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java
@@ -137,6 +137,7 @@ public final class FontTable
}
+ @Override
public boolean equals(Object o)
{
boolean retVal = true;
@@ -162,8 +163,10 @@ public final class FontTable
return retVal;
}
-
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
}
-
-
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
index 7bdd1fcd9a..3de08d8d43 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
@@ -101,6 +101,7 @@ public final class ListLevel
_xst = new Xst(numberText);
}
+ @Override
public boolean equals( Object obj )
{
if ( obj == null )
@@ -113,6 +114,12 @@ public final class ListLevel
&& lvl._xst.equals( this._xst );
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
/**
* "Alignment (left, right, or centered) of the paragraph number."
*/
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java
index bfaa8a9e31..837b83b97f 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java
@@ -155,6 +155,7 @@ public final class PAPX extends BytePropertyNode<PAPX> {
return props;
}
+ @Override
public boolean equals(Object o)
{
if (super.equals(o))
@@ -164,6 +165,12 @@ public final class PAPX extends BytePropertyNode<PAPX> {
return false;
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
public String toString()
{
return "PAPX from " + getStart() + " to " + getEnd() + " (in bytes "
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java
index 993f1a21b6..8cff9a5c64 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java
@@ -81,4 +81,11 @@ public final class ParagraphHeight
return infoField == ph.infoField && reserved == ph.reserved &&
dxaCol == ph.dxaCol && dymLineOrHeight == ph.dymLineOrHeight;
}
+
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
}
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java
index 4e1c0ce73f..ccf56cfe05 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java
@@ -64,6 +64,7 @@ public final class SEPX extends PropertyNode<SEPX>
return sectionProperties;
}
+ @Override
public boolean equals( Object o )
{
SEPX sepx = (SEPX) o;
@@ -74,6 +75,12 @@ public final class SEPX extends PropertyNode<SEPX>
return false;
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
public String toString()
{
return "SEPX from " + getStart() + " to " + getEnd();
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java
index 0486fa8517..bdddac7f3e 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java
@@ -77,12 +77,19 @@ public final class SectionDescriptor
this.fcSepx = fc;
}
+ @Override
public boolean equals(Object o)
{
SectionDescriptor sed = (SectionDescriptor)o;
return sed.fn == fn && sed.fnMpr == fnMpr;
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
public byte[] toByteArray()
{
int offset = 0;
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java
index c6891a7e3d..98df05f956 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java
@@ -174,6 +174,8 @@ public final class StyleSheet implements HDFType {
}
}
}
+
+ @Override
public boolean equals(Object o)
{
StyleSheet ss = (StyleSheet)o;
@@ -199,6 +201,13 @@ public final class StyleSheet implements HDFType {
}
return false;
}
+
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
/**
* Creates a PartagraphProperties object from a papx stored in the
* StyleDescription at the index istd in the StyleDescription array. The PAP
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
index 42e4b3793d..0c3e8c3725 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
@@ -201,6 +201,7 @@ public class TextPiece extends PropertyNode<TextPiece>
return (getEnd() - getStart()) * (_usesUnicode ? 2 : 1);
}
+ @Override
public boolean equals(Object o)
{
if (limitsAreEqual(o))
@@ -212,6 +213,12 @@ public class TextPiece extends PropertyNode<TextPiece>
return false;
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
/**
* Returns the character position we start at.
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java b/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java
index 69214348c6..95dd00bc30 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java
@@ -40,12 +40,19 @@ public final class UPX
return _upx.length;
}
+ @Override
public boolean equals(Object o)
{
UPX upx = (UPX)o;
return Arrays.equals(_upx, upx._upx);
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
@Override
public String toString()
{
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java
index a41b525a2c..440c666403 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java
@@ -150,12 +150,20 @@ public final class SprmBuffer implements Cloneable
_buf = newBuf;
}
}
+
+ @Override
public boolean equals(Object obj)
{
SprmBuffer sprmBuf = (SprmBuffer)obj;
return (Arrays.equals(_buf, sprmBuf._buf));
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
public SprmOperation findSprm( short opcode )
{
int operation = SprmOperation.getOperationFromOpcode( opcode );
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java
index 4526c052fa..47e3b352f9 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java
@@ -68,12 +68,19 @@ public final class BorderCode implements Cloneable {
return _info == 0 && _info2 == 0 || _info == -1;
}
+ @Override
public boolean equals(Object o)
{
BorderCode brc = (BorderCode)o;
return _info == brc._info && _info2 == brc._info2;
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
public Object clone()
throws CloneNotSupportedException
{
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java
index be988043b3..9000cc1ec8 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java
@@ -72,12 +72,19 @@ public final class DateAndTime
LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _info2);
}
+ @Override
public boolean equals(Object o)
{
DateAndTime dttm = (DateAndTime)o;
return _info == dttm._info && _info2 == dttm._info2;
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
public Object clone()
throws CloneNotSupportedException
{
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java
index 94c8f0eb16..e327f039ce 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java
@@ -71,6 +71,8 @@ public final class LineSpacingDescriptor
{
_dyaLine = dyaLine;
}
+
+ @Override
public boolean equals(Object o)
{
LineSpacingDescriptor lspd = (LineSpacingDescriptor)o;
@@ -78,6 +80,12 @@ public final class LineSpacingDescriptor
return _dyaLine == lspd._dyaLine && _fMultiLinespace == lspd._fMultiLinespace;
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
+
public boolean isEmpty()
{
return _dyaLine == 0 && _fMultiLinespace == 0;
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java
index 776015cc7f..8205e6be5d 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java
@@ -45,7 +45,8 @@ public final class SectionProperties extends SEPAbstractType
return copy;
}
-
+
+ @Override
public boolean equals( Object obj )
{
Field[] fields = SectionProperties.class.getSuperclass()
@@ -74,4 +75,9 @@ public final class SectionProperties extends SEPAbstractType
}
}
+ @Override
+ public int hashCode() {
+ assert false : "hashCode not designed";
+ return 42; // any arbitrary constant will do
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
index 8a3c92ba77..cbf9018647 100644
--- a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
+++ b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
@@ -17,87 +17,80 @@
package org.apache.poi.hssf.record;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.apache.poi.hssf.record.aggregates.AllRecordAggregateTests;
import org.apache.poi.hssf.record.cf.TestCellRange;
import org.apache.poi.hssf.record.chart.AllChartRecordTests;
import org.apache.poi.hssf.record.common.TestUnicodeString;
-import org.apache.poi.ss.formula.constant.TestConstantValueParser;
import org.apache.poi.hssf.record.crypto.AllHSSFEncryptionTests;
-import org.apache.poi.ss.formula.ptg.AllFormulaTests;
import org.apache.poi.hssf.record.pivot.AllPivotRecordTests;
+import org.apache.poi.ss.formula.constant.TestConstantValueParser;
+import org.apache.poi.ss.formula.ptg.AllFormulaTests;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Collects all tests for package <tt>org.apache.poi.hssf.record</tt> and sub-packages.
- *
- * @author Josh Micich
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ AllChartRecordTests.class,
+ AllHSSFEncryptionTests.class,
+ AllFormulaTests.class,
+ AllPivotRecordTests.class,
+ AllRecordAggregateTests.class,
+ TestArrayRecord.class,
+ TestBOFRecord.class,
+ TestBoolErrRecord.class,
+ TestBoundSheetRecord.class,
+ TestCellRange.class,
+ TestCFHeaderRecord.class,
+ TestCFRuleRecord.class,
+ TestColumnInfoRecord.class,
+ TestCommonObjectDataSubRecord.class,
+ TestConstantValueParser.class,
+ TestDVALRecord.class,
+ TestDrawingGroupRecord.class,
+ TestDrawingRecord.class,
+ TestEmbeddedObjectRefSubRecord.class,
+ TestEndSubRecord.class,
+ TestEscherAggregate.class,
+ TestExtendedFormatRecord.class,
+ TestExternalNameRecord.class,
+ TestFeatRecord.class,
+ TestFontRecord.class,
+ TestFormulaRecord.class,
+ TestHyperlinkRecord.class,
+ TestInterfaceEndRecord.class,
+ TestLabelRecord.class,
+ TestLbsDataSubRecord.class,
+ TestMergeCellsRecord.class,
+ TestNameRecord.class,
+ TestNoteRecord.class,
+ TestNoteStructureSubRecord.class,
+ TestObjRecord.class,
+ TestPaletteRecord.class,
+ TestPaneRecord.class,
+ TestPLVRecord.class,
+ TestRecalcIdRecord.class,
+ TestRecordFactory.class,
+ TestRecordFactoryInputStream.class,
+ TestRecordInputStream.class,
+ TestSCLRecord.class,
+ TestSSTDeserializer.class,
+ TestSSTRecord.class,
+ TestSSTRecordSizeCalculator.class,
+ TestSharedFormulaRecord.class,
+ TestStringRecord.class,
+ TestStyleRecord.class,
+ TestSubRecord.class,
+ TestSupBookRecord.class,
+ TestTableRecord.class,
+ TestTextObjectBaseRecord.class,
+ TestTextObjectRecord.class,
+ TestUnicodeNameRecord.class,
+ TestUnicodeString.class,
+ TestWriteAccessRecord.class,
+ TestDConRefRecord.class
+})
public final class AllRecordTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllRecordTests.class.getName());
-
- result.addTest(AllChartRecordTests.suite());
- result.addTest(AllHSSFEncryptionTests.suite());
- result.addTest(AllFormulaTests.suite());
- result.addTest(AllPivotRecordTests.suite());
- result.addTest(AllRecordAggregateTests.suite());
-
- result.addTestSuite(TestArrayRecord.class);
- result.addTestSuite(TestBOFRecord.class);
- result.addTestSuite(TestBoolErrRecord.class);
- result.addTestSuite(TestBoundSheetRecord.class);
- result.addTestSuite(TestCellRange.class);
- result.addTestSuite(TestCFHeaderRecord.class);
- result.addTestSuite(TestCFRuleRecord.class);
- result.addTestSuite(TestColumnInfoRecord.class);
- result.addTestSuite(TestCommonObjectDataSubRecord.class);
- result.addTestSuite(TestConstantValueParser.class);
- result.addTestSuite(TestDVALRecord.class);
- result.addTestSuite(TestDrawingGroupRecord.class);
- result.addTestSuite(TestDrawingRecord.class);
- result.addTestSuite(TestEmbeddedObjectRefSubRecord.class);
- result.addTestSuite(TestEndSubRecord.class);
- result.addTestSuite(TestEscherAggregate.class);
- result.addTestSuite(TestExtendedFormatRecord.class);
- result.addTestSuite(TestExternalNameRecord.class);
- result.addTestSuite(TestFeatRecord.class);
- result.addTestSuite(TestFontRecord.class);
- result.addTestSuite(TestFormulaRecord.class);
- result.addTestSuite(TestHyperlinkRecord.class);
- result.addTestSuite(TestInterfaceEndRecord.class);
- result.addTestSuite(TestLabelRecord.class);
- result.addTestSuite(TestLbsDataSubRecord.class);
- result.addTestSuite(TestMergeCellsRecord.class);
- result.addTestSuite(TestNameRecord.class);
- result.addTestSuite(TestNoteRecord.class);
- result.addTestSuite(TestNoteStructureSubRecord.class);
- result.addTestSuite(TestObjRecord.class);
- result.addTestSuite(TestPaletteRecord.class);
- result.addTestSuite(TestPaneRecord.class);
- result.addTestSuite(TestPLVRecord.class);
- result.addTestSuite(TestRecalcIdRecord.class);
- result.addTestSuite(TestRecordFactory.class);
- result.addTestSuite(TestRecordFactoryInputStream.class);
- result.addTestSuite(TestRecordInputStream.class);
- result.addTestSuite(TestSCLRecord.class);
- result.addTestSuite(TestSSTDeserializer.class);
- result.addTestSuite(TestSSTRecord.class);
- result.addTestSuite(TestSSTRecordSizeCalculator.class);
- result.addTestSuite(TestSharedFormulaRecord.class);
- result.addTestSuite(TestStringRecord.class);
- result.addTestSuite(TestStyleRecord.class);
- result.addTestSuite(TestSubRecord.class);
- result.addTestSuite(TestSupBookRecord.class);
- result.addTestSuite(TestTableRecord.class);
- result.addTestSuite(TestTextObjectBaseRecord.class);
- result.addTestSuite(TestTextObjectRecord.class);
- result.addTestSuite(TestUnicodeNameRecord.class);
- result.addTestSuite(TestUnicodeString.class);
- result.addTestSuite(TestWriteAccessRecord.class);
- result.addTestSuite(TestDConRefRecord.class);
- return result;
- }
}
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 591042d7eb..c1c585db4e 100644
--- a/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
+++ b/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
@@ -17,19 +17,25 @@
package org.apache.poi.hssf.record.common;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import junit.framework.TestCase;
-
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.util.LittleEndianByteArrayInputStream;
+import org.apache.poi.util.LittleEndianByteArrayOutputStream;
+import org.apache.poi.util.LittleEndianConsts;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.LittleEndianOutputStream;
+import org.apache.poi.util.StringUtil;
+import org.junit.Test;
/**
* Tests that {@link UnicodeString} record size calculates correctly. The record size
@@ -37,7 +43,7 @@ import org.apache.poi.util.LittleEndianOutputStream;
*
* @author Jason Height (jheight at apache.org)
*/
-public final class TestUnicodeString extends TestCase {
+public final class TestUnicodeString {
private static final int MAX_DATA_SIZE = RecordInputStream.MAX_RECORD_DATA_SIZE;
/** a 4 character string requiring 16 bit encoding */
@@ -65,7 +71,8 @@ public final class TestUnicodeString extends TestCase {
assertEquals(expectedSize, actualSize);
}
- public void testSmallStringSize() {
+ @Test
+ public void smallStringSize() {
//Test a basic string
UnicodeString s = makeUnicodeString("Test");
confirmSize(7, s);
@@ -111,7 +118,8 @@ public final class TestUnicodeString extends TestCase {
confirmSize(21, s);
}
- public void testPerfectStringSize() {
+ @Test
+ public void perfectStringSize() {
//Test a basic string
UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1);
confirmSize(MAX_DATA_SIZE, s);
@@ -124,7 +132,8 @@ public final class TestUnicodeString extends TestCase {
confirmSize(MAX_DATA_SIZE-1, s);
}
- public void testPerfectRichStringSize() {
+ @Test
+ 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));
@@ -142,14 +151,16 @@ public final class TestUnicodeString extends TestCase {
confirmSize(MAX_DATA_SIZE-1, s);
}
- public void testContinuedStringSize() {
+ @Test
+ public void continuedStringSize() {
//Test a basic string
UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1+20);
confirmSize(MAX_DATA_SIZE+4+1+20, s);
}
/** Tests that a string size calculation that fits neatly in two records, the second being a continue*/
- public void testPerfectContinuedStringSize() {
+ @Test
+ public void perfectContinuedStringSize() {
//Test a basic string
int strSize = MAX_DATA_SIZE*2;
//String overhead
@@ -162,7 +173,8 @@ public final class TestUnicodeString extends TestCase {
confirmSize(MAX_DATA_SIZE*2, s);
}
- public void testFormatRun() throws Exception {
+ @Test
+ public void formatRun() throws Exception {
FormatRun fr = new FormatRun((short)4, (short)0x15c);
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
@@ -187,7 +199,8 @@ public final class TestUnicodeString extends TestCase {
assertEquals(0x15c, fr.getFontIndex());
}
- public void testExtRstFromEmpty() throws Exception {
+ @Test
+ public void extRstFromEmpty() throws Exception {
ExtRst ext = new ExtRst();
assertEquals(0, ext.getNumberOfRuns());
@@ -253,7 +266,8 @@ public final class TestUnicodeString extends TestCase {
assertEquals(0, ext.getPhRuns().length);
}
- public void testExtRstFromData() throws Exception {
+ @Test
+ public void extRstFromData() throws Exception {
byte[] data = new byte[] {
01, 00, 0x0C, 00,
00, 00, 0x37, 00,
@@ -276,7 +290,8 @@ public final class TestUnicodeString extends TestCase {
assertEquals(0, ext.getPhRuns().length);
}
- public void testCorruptExtRstDetection() throws Exception {
+ @Test
+ public void corruptExtRstDetection() throws Exception {
byte[] data = new byte[] {
0x79, 0x79, 0x11, 0x11,
0x22, 0x22, 0x33, 0x33,
@@ -302,6 +317,32 @@ public final class TestUnicodeString extends TestCase {
assertEquals(0, ext.getPhRuns().length);
}
+ @Test
+ public void extRstEqualsAndHashCode() {
+ byte buf[] = new byte[200];
+ LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0);
+ String str = "\u1d02\u1d12\u1d22";
+ bos.writeShort(1);
+ bos.writeShort(5*LittleEndianConsts.SHORT_SIZE+str.length()*2+3*LittleEndianConsts.SHORT_SIZE+2); // data size
+ bos.writeShort(0x4711);
+ bos.writeShort(0x0815);
+ bos.writeShort(1);
+ bos.writeShort(str.length());
+ bos.writeShort(str.length());
+ StringUtil.putUnicodeLE(str, bos);
+ bos.writeShort(1);
+ 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());
+ in = new LittleEndianByteArrayInputStream(buf, 0, bos.getWriteIndex());
+ UnicodeString.ExtRst extRst2 = new UnicodeString.ExtRst(in, bos.getWriteIndex());
+
+ assertEquals(extRst1, extRst2);
+ assertEquals(extRst1.hashCode(), extRst2.hashCode());
+ }
private static UnicodeString makeUnicodeString(String s) {
UnicodeString st = new UnicodeString(s);