FindBugs fix

- fixed "Class defines equals() and uses Object.hashCode()"
- see http://findbugs.sourceforge.net/bugDescriptions.html#HE_EQUALS_USE_HASHCODE
- implemented UnicodeString.ExtRst.hashCode() + junit-test

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1566427 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2014-02-09 21:19:20 +00:00
parent d726e23680
commit 413e76aed0
27 changed files with 319 additions and 100 deletions

View File

@ -884,7 +884,7 @@ under the License.
<classpath refid="@{classpath}"/>
<syspropertyset refid="junit.properties"/>
<jvmarg value="${poi.test.locale}"/>
<!-- <jvmarg value="-ea"/> -->
<jvmarg value="-ea"/>
<formatter type="plain"/>
<formatter type="xml"/>
<batchtest todir="${ooxml.reports.test}">

View File

@ -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;
}

View File

@ -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;

View File

@ -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
}
}

View File

@ -274,6 +274,12 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
&& anchor.getRow1() == getRow1() && anchor.getRow2() == getRow2() && anchor.getAnchorType() == getAnchorType();
}
@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}
@Override
public int getDx1() {
return _escherClientAnchor.getDx1();

View File

@ -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.
*/

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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

View File

@ -172,6 +172,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();

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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."
*/

View File

@ -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 "

View File

@ -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
}
}

View File

@ -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();

View File

@ -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;

View File

@ -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

View File

@ -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.

View File

@ -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()
{

View File

@ -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 );

View File

@ -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
{

View File

@ -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
{

View File

@ -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;

View File

@ -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
}
}

View File

@ -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;
}
}

View File

@ -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);