Browse Source

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
tags/REL_3_11_BETA1
Andreas Beeker 10 years ago
parent
commit
4b9d47af5a
27 changed files with 319 additions and 100 deletions
  1. 1
    1
      build.xml
  2. 7
    1
      src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
  3. 37
    8
      src/java/org/apache/poi/hssf/record/common/UnicodeString.java
  4. 6
    0
      src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java
  5. 6
    0
      src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java
  6. 8
    0
      src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
  7. 8
    1
      src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
  8. 6
    0
      src/java/org/apache/poi/ss/util/CellReference.java
  9. 8
    0
      src/java/org/apache/poi/ss/util/Region.java
  10. 6
    0
      src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
  11. 7
    1
      src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java
  12. 6
    3
      src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java
  13. 7
    0
      src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
  14. 7
    0
      src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java
  15. 7
    0
      src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java
  16. 7
    0
      src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java
  17. 7
    0
      src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java
  18. 9
    0
      src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java
  19. 7
    0
      src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
  20. 7
    0
      src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java
  21. 8
    0
      src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java
  22. 7
    0
      src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java
  23. 7
    0
      src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java
  24. 8
    0
      src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java
  25. 7
    1
      src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java
  26. 65
    72
      src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
  27. 53
    12
      src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java

+ 1
- 1
build.xml View File

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

+ 7
- 1
src/java/org/apache/poi/hssf/record/HyperlinkRecord.java View File

&& _d3 == other._d3 && _d4 == other._d4; && _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; return _d1;
} }



+ 37
- 8
src/java/org/apache/poi/hssf/record/common/UnicodeString.java View File

package org.apache.poi.hssf.record.common; package org.apache.poi.hssf.record.common;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; 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.RecordInputStream;
import org.apache.poi.hssf.record.cont.ContinuableRecordInput;
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput; 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/> * Title: Unicode String<p/>
return _character - r._character; return _character - r._character;
} }


@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}

public String toString() { public String toString() {
return "character="+_character+",fontIndex="+_fontIndex; return "character="+_character+",fontIndex="+_fontIndex;
} }
if(result != 0) return result; if(result != 0) return result;
result = phRuns[i].realTextFirstCharacterOffset - o.phRuns[i].realTextFirstCharacterOffset; result = phRuns[i].realTextFirstCharacterOffset - o.phRuns[i].realTextFirstCharacterOffset;
if(result != 0) return result; 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; 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() { protected ExtRst clone() {
ExtRst ext = new ExtRst(); ExtRst ext = new ExtRst();
ext.reserved = reserved; ext.reserved = reserved;

+ 6
- 0
src/java/org/apache/poi/hssf/usermodel/HSSFChildAnchor.java View File

return anchor.getDx1() == getDx1() && anchor.getDx2() == getDx2() && anchor.getDy1() == getDy1() return anchor.getDx1() == getDx1() && anchor.getDx2() == getDx2() && anchor.getDy1() == getDy1()
&& anchor.getDy2() == getDy2(); && anchor.getDy2() == getDy2();
} }

@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}
} }

+ 6
- 0
src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java View File

&& anchor.getRow1() == getRow1() && anchor.getRow2() == getRow2() && anchor.getAnchorType() == getAnchorType(); && 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 @Override
public int getDx1() { public int getDx1() {
return _escherClientAnchor.getDx1(); return _escherClientAnchor.getDx1();

+ 8
- 0
src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java View File

return _string.compareTo(r._string); return _string.compareTo(r._string);
} }


@Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o instanceof HSSFRichTextString) { if (o instanceof HSSFRichTextString) {
return _string.equals(((HSSFRichTextString)o)._string); return _string.equals(((HSSFRichTextString)o)._string);


} }


@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}

/** /**
* @return the plain text representation of this string. * @return the plain text representation of this string.
*/ */

+ 8
- 1
src/java/org/apache/poi/hssf/usermodel/HSSFRow.java View File

import org.apache.poi.hssf.record.CellValueRecordInterface; import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.ExtendedFormatRecord; import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.RowRecord; 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.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.util.Configurator; import org.apache.poi.util.Configurator;


/** /**
return -1; return -1;
} }


@Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
if (!(obj instanceof HSSFRow)) if (!(obj instanceof HSSFRow))
} }
return false; return false;
} }

@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}
} }

+ 6
- 0
src/java/org/apache/poi/ss/util/CellReference.java View File

&& _isRowAbs == cr._isColAbs && _isRowAbs == cr._isColAbs
&& _isColAbs == cr._isColAbs; && _isColAbs == cr._isColAbs;
} }

@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}
} }

+ 8
- 0
src/java/org/apache/poi/ss/util/Region.java View File

return (compareTo(r) == 0); 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 * 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 * region. If any regional coordiant passed in is less than this regions

+ 6
- 0
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java View File



} }


@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}

@Override @Override
public String toString(){ public String toString(){
return "from : " + cell1.toString() + "; to: " + cell2.toString(); return "from : " + cell1.toString() + "; to: " + cell2.toString();

+ 7
- 1
src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java View File



} }


public boolean equals(Object o)
@Override
public boolean equals(Object o)
{ {
boolean retVal = true; boolean retVal = true;


} }




@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}
} }





+ 6
- 3
src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java View File



} }


@Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
boolean retVal = true; boolean retVal = true;
return retVal; return retVal;
} }



@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}


} }



+ 7
- 0
src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java View File

_xst = new Xst(numberText); _xst = new Xst(numberText);
} }


@Override
public boolean equals( Object obj ) public boolean equals( Object obj )
{ {
if ( obj == null ) if ( obj == null )
&& lvl._xst.equals( this._xst ); && 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." * "Alignment (left, right, or centered) of the paragraph number."
*/ */

+ 7
- 0
src/scratchpad/src/org/apache/poi/hwpf/model/PAPX.java View File

return props; return props;
} }


@Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
if (super.equals(o)) if (super.equals(o))
return false; return false;
} }


@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}

public String toString() public String toString()
{ {
return "PAPX from " + getStart() + " to " + getEnd() + " (in bytes " return "PAPX from " + getStart() + " to " + getEnd() + " (in bytes "

+ 7
- 0
src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java View File

return infoField == ph.infoField && reserved == ph.reserved && return infoField == ph.infoField && reserved == ph.reserved &&
dxaCol == ph.dxaCol && dymLineOrHeight == ph.dymLineOrHeight; dxaCol == ph.dxaCol && dymLineOrHeight == ph.dymLineOrHeight;
} }

@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}

} }

+ 7
- 0
src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java View File

return sectionProperties; return sectionProperties;
} }


@Override
public boolean equals( Object o ) public boolean equals( Object o )
{ {
SEPX sepx = (SEPX) o; SEPX sepx = (SEPX) o;
return false; return false;
} }


@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}

public String toString() public String toString()
{ {
return "SEPX from " + getStart() + " to " + getEnd(); return "SEPX from " + getStart() + " to " + getEnd();

+ 7
- 0
src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java View File

this.fcSepx = fc; this.fcSepx = fc;
} }


@Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
SectionDescriptor sed = (SectionDescriptor)o; SectionDescriptor sed = (SectionDescriptor)o;
return sed.fn == fn && sed.fnMpr == fnMpr; 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() public byte[] toByteArray()
{ {
int offset = 0; int offset = 0;

+ 9
- 0
src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java View File

} }
} }
} }

@Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
StyleSheet ss = (StyleSheet)o; StyleSheet ss = (StyleSheet)o;
} }
return false; 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 * Creates a PartagraphProperties object from a papx stored in the
* StyleDescription at the index istd in the StyleDescription array. The PAP * StyleDescription at the index istd in the StyleDescription array. The PAP

+ 7
- 0
src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java View File

return (getEnd() - getStart()) * (_usesUnicode ? 2 : 1); return (getEnd() - getStart()) * (_usesUnicode ? 2 : 1);
} }


@Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
if (limitsAreEqual(o)) if (limitsAreEqual(o))
return false; 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. * Returns the character position we start at.

+ 7
- 0
src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java View File

return _upx.length; return _upx.length;
} }


@Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
UPX upx = (UPX)o; UPX upx = (UPX)o;
return Arrays.equals(_upx, upx._upx); return Arrays.equals(_upx, upx._upx);
} }


@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}

@Override @Override
public String toString() public String toString()
{ {

+ 8
- 0
src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java View File

_buf = newBuf; _buf = newBuf;
} }
} }

@Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
SprmBuffer sprmBuf = (SprmBuffer)obj; SprmBuffer sprmBuf = (SprmBuffer)obj;
return (Arrays.equals(_buf, sprmBuf._buf)); 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 ) public SprmOperation findSprm( short opcode )
{ {
int operation = SprmOperation.getOperationFromOpcode( opcode ); int operation = SprmOperation.getOperationFromOpcode( opcode );

+ 7
- 0
src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java View File

return _info == 0 && _info2 == 0 || _info == -1; return _info == 0 && _info2 == 0 || _info == -1;
} }


@Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
BorderCode brc = (BorderCode)o; BorderCode brc = (BorderCode)o;
return _info == brc._info && _info2 == brc._info2; 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() public Object clone()
throws CloneNotSupportedException throws CloneNotSupportedException
{ {

+ 7
- 0
src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java View File

LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _info2); LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _info2);
} }


@Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
DateAndTime dttm = (DateAndTime)o; DateAndTime dttm = (DateAndTime)o;
return _info == dttm._info && _info2 == dttm._info2; 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() public Object clone()
throws CloneNotSupportedException throws CloneNotSupportedException
{ {

+ 8
- 0
src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java View File

{ {
_dyaLine = dyaLine; _dyaLine = dyaLine;
} }
@Override
public boolean equals(Object o) public boolean equals(Object o)
{ {
LineSpacingDescriptor lspd = (LineSpacingDescriptor)o; LineSpacingDescriptor lspd = (LineSpacingDescriptor)o;
return _dyaLine == lspd._dyaLine && _fMultiLinespace == lspd._fMultiLinespace; 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() public boolean isEmpty()
{ {
return _dyaLine == 0 && _fMultiLinespace == 0; return _dyaLine == 0 && _fMultiLinespace == 0;

+ 7
- 1
src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java View File



return copy; return copy;
} }

@Override
public boolean equals( Object obj ) public boolean equals( Object obj )
{ {
Field[] fields = SectionProperties.class.getSuperclass() Field[] fields = SectionProperties.class.getSuperclass()
} }
} }


@Override
public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}
} }

+ 65
- 72
src/testcases/org/apache/poi/hssf/record/AllRecordTests.java View File



package org.apache.poi.hssf.record; 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.aggregates.AllRecordAggregateTests;
import org.apache.poi.hssf.record.cf.TestCellRange; import org.apache.poi.hssf.record.cf.TestCellRange;
import org.apache.poi.hssf.record.chart.AllChartRecordTests; import org.apache.poi.hssf.record.chart.AllChartRecordTests;
import org.apache.poi.hssf.record.common.TestUnicodeString; 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.hssf.record.crypto.AllHSSFEncryptionTests;
import org.apache.poi.ss.formula.ptg.AllFormulaTests;
import org.apache.poi.hssf.record.pivot.AllPivotRecordTests; 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. * 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 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;
}
} }

+ 53
- 12
src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java View File



package org.apache.poi.hssf.record.common; package org.apache.poi.hssf.record.common;


import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;


import junit.framework.TestCase;

import org.apache.poi.hssf.record.ContinueRecord; import org.apache.poi.hssf.record.ContinueRecord;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.SSTRecord; import org.apache.poi.hssf.record.SSTRecord;
import org.apache.poi.hssf.record.common.UnicodeString.ExtRst; import org.apache.poi.hssf.record.common.UnicodeString.ExtRst;
import org.apache.poi.hssf.record.common.UnicodeString.FormatRun; import org.apache.poi.hssf.record.common.UnicodeString.FormatRun;
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput; 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.LittleEndianInputStream;
import org.apache.poi.util.LittleEndianOutputStream; 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 * Tests that {@link UnicodeString} record size calculates correctly. The record size
* *
* @author Jason Height (jheight at apache.org) * @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; private static final int MAX_DATA_SIZE = RecordInputStream.MAX_RECORD_DATA_SIZE;


/** a 4 character string requiring 16 bit encoding */ /** a 4 character string requiring 16 bit encoding */
assertEquals(expectedSize, actualSize); assertEquals(expectedSize, actualSize);
} }


public void testSmallStringSize() {
@Test
public void smallStringSize() {
//Test a basic string //Test a basic string
UnicodeString s = makeUnicodeString("Test"); UnicodeString s = makeUnicodeString("Test");
confirmSize(7, s); confirmSize(7, s);
confirmSize(21, s); confirmSize(21, s);
} }


public void testPerfectStringSize() {
@Test
public void perfectStringSize() {
//Test a basic string //Test a basic string
UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1); UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1);
confirmSize(MAX_DATA_SIZE, s); confirmSize(MAX_DATA_SIZE, s);
confirmSize(MAX_DATA_SIZE-1, s); confirmSize(MAX_DATA_SIZE-1, s);
} }


public void testPerfectRichStringSize() {
@Test
public void perfectRichStringSize() {
//Test a rich text string //Test a rich text string
UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1-8-2); 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)1,(short)0));
confirmSize(MAX_DATA_SIZE-1, s); confirmSize(MAX_DATA_SIZE-1, s);
} }


public void testContinuedStringSize() {
@Test
public void continuedStringSize() {
//Test a basic string //Test a basic string
UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1+20); UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1+20);
confirmSize(MAX_DATA_SIZE+4+1+20, s); 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*/ /** 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 //Test a basic string
int strSize = MAX_DATA_SIZE*2; int strSize = MAX_DATA_SIZE*2;
//String overhead //String overhead
confirmSize(MAX_DATA_SIZE*2, s); 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); FormatRun fr = new FormatRun((short)4, (short)0x15c);
assertEquals(4, fr.getCharacterPos()); assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex()); assertEquals(0x15c, fr.getFontIndex());
assertEquals(0x15c, fr.getFontIndex()); assertEquals(0x15c, fr.getFontIndex());
} }
public void testExtRstFromEmpty() throws Exception {
@Test
public void extRstFromEmpty() throws Exception {
ExtRst ext = new ExtRst(); ExtRst ext = new ExtRst();
assertEquals(0, ext.getNumberOfRuns()); assertEquals(0, ext.getNumberOfRuns());
assertEquals(0, ext.getPhRuns().length); assertEquals(0, ext.getPhRuns().length);
} }
public void testExtRstFromData() throws Exception {
@Test
public void extRstFromData() throws Exception {
byte[] data = new byte[] { byte[] data = new byte[] {
01, 00, 0x0C, 00, 01, 00, 0x0C, 00,
00, 00, 0x37, 00, 00, 00, 0x37, 00,
assertEquals(0, ext.getPhRuns().length); assertEquals(0, ext.getPhRuns().length);
} }
public void testCorruptExtRstDetection() throws Exception {
@Test
public void corruptExtRstDetection() throws Exception {
byte[] data = new byte[] { byte[] data = new byte[] {
0x79, 0x79, 0x11, 0x11, 0x79, 0x79, 0x11, 0x11,
0x22, 0x22, 0x33, 0x33, 0x22, 0x22, 0x33, 0x33,
assertEquals(0, ext.getPhRuns().length); 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) { private static UnicodeString makeUnicodeString(String s) {
UnicodeString st = new UnicodeString(s); UnicodeString st = new UnicodeString(s);

Loading…
Cancel
Save