Fixed tests for legend and implemented testresult for bitfields

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352645 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew C. Oliver 2002-05-19 21:40:59 +00:00
parent a743c4248d
commit f75fb848ba
4 changed files with 150 additions and 121 deletions

View File

@ -61,18 +61,18 @@ package org.apache.poi.hssf.record;
import org.apache.poi.util.*; import org.apache.poi.util.*;
/** /**
* The legend record specifies the location of legend on a chart and it's overall size. * Defines a legend for a chart.
* NOTE: This source is automatically generated please do not modify this file. Either subclass or * NOTE: This source is automatically generated please do not modify this file. Either subclass or
* remove the record in src/records/definitions. * remove the record in src/records/definitions.
* @author Glen Stampoultzis (glens at apache.org) * @author Andrew C. Oliver (acoliver at apache.org)
*/ */
public class LegendRecord public class LegendRecord
extends Record extends Record
{ {
public final static short sid = 0x1015; public final static short sid = 0x1015;
private int field_1_xPosition; private int field_1_xAxisUpperLeft;
private int field_2_yPosition; private int field_2_yAxisUpperLeft;
private int field_3_xSize; private int field_3_xSize;
private int field_4_ySize; private int field_4_ySize;
private byte field_5_type; private byte field_5_type;
@ -81,7 +81,7 @@ public class LegendRecord
public final static byte TYPE_TOP = 2; public final static byte TYPE_TOP = 2;
public final static byte TYPE_RIGHT = 3; public final static byte TYPE_RIGHT = 3;
public final static byte TYPE_LEFT = 4; public final static byte TYPE_LEFT = 4;
public final static byte TYPE_NOT_DOCKED = 7; public final static byte TYPE_UNDOCKED = 7;
private byte field_6_spacing; private byte field_6_spacing;
public final static byte SPACING_CLOSE = 0; public final static byte SPACING_CLOSE = 0;
public final static byte SPACING_MEDIUM = 1; public final static byte SPACING_MEDIUM = 1;
@ -89,10 +89,10 @@ public class LegendRecord
private short field_7_options; private short field_7_options;
private BitField autoPosition = new BitField(0x1); private BitField autoPosition = new BitField(0x1);
private BitField autoSeries = new BitField(0x2); private BitField autoSeries = new BitField(0x2);
private BitField autoPosX = new BitField(0x4); private BitField autoXPositioning = new BitField(0x4);
private BitField autoPosY = new BitField(0x8); private BitField autoYPositioning = new BitField(0x8);
private BitField vert = new BitField(0x10); private BitField vertical = new BitField(0x10);
private BitField containsDataTable = new BitField(0x20); private BitField dataTable = new BitField(0x20);
public LegendRecord() public LegendRecord()
@ -144,8 +144,8 @@ public class LegendRecord
protected void fillFields(byte [] data, short size, int offset) protected void fillFields(byte [] data, short size, int offset)
{ {
field_1_xPosition = LittleEndian.getInt(data, 0x0 + offset); field_1_xAxisUpperLeft = LittleEndian.getInt(data, 0x0 + offset);
field_2_yPosition = LittleEndian.getInt(data, 0x4 + offset); field_2_yAxisUpperLeft = LittleEndian.getInt(data, 0x4 + offset);
field_3_xSize = LittleEndian.getInt(data, 0x8 + offset); field_3_xSize = LittleEndian.getInt(data, 0x8 + offset);
field_4_ySize = LittleEndian.getInt(data, 0xc + offset); field_4_ySize = LittleEndian.getInt(data, 0xc + offset);
field_5_type = data[ 0x10 + offset ]; field_5_type = data[ 0x10 + offset ];
@ -160,15 +160,15 @@ public class LegendRecord
buffer.append("[Legend]\n"); buffer.append("[Legend]\n");
buffer.append(" .xPosition = ") buffer.append(" .xAxisUpperLeft = ")
.append("0x") .append("0x")
.append(HexDump.toHex((int)getXPosition())) .append(HexDump.toHex((int)getXAxisUpperLeft()))
.append(" (").append(getXPosition()).append(" )\n"); .append(" (").append(getXAxisUpperLeft()).append(" )\n");
buffer.append(" .yPosition = ") buffer.append(" .yAxisUpperLeft = ")
.append("0x") .append("0x")
.append(HexDump.toHex((int)getYPosition())) .append(HexDump.toHex((int)getYAxisUpperLeft()))
.append(" (").append(getYPosition()).append(" )\n"); .append(" (").append(getYAxisUpperLeft()).append(" )\n");
buffer.append(" .xSize = ") buffer.append(" .xSize = ")
.append("0x") .append("0x")
@ -196,10 +196,10 @@ public class LegendRecord
.append(" (").append(getOptions()).append(" )\n"); .append(" (").append(getOptions()).append(" )\n");
buffer.append(" .autoPosition = ").append(isAutoPosition ()).append('\n'); buffer.append(" .autoPosition = ").append(isAutoPosition ()).append('\n');
buffer.append(" .autoSeries = ").append(isAutoSeries ()).append('\n'); buffer.append(" .autoSeries = ").append(isAutoSeries ()).append('\n');
buffer.append(" .autoPosX = ").append(isAutoPosX ()).append('\n'); buffer.append(" .autoXPositioning = ").append(isAutoXPositioning ()).append('\n');
buffer.append(" .autoPosY = ").append(isAutoPosY ()).append('\n'); buffer.append(" .autoYPositioning = ").append(isAutoYPositioning ()).append('\n');
buffer.append(" .vert = ").append(isVert ()).append('\n'); buffer.append(" .vertical = ").append(isVertical ()).append('\n');
buffer.append(" .containsDataTable = ").append(isContainsDataTable ()).append('\n'); buffer.append(" .dataTable = ").append(isDataTable ()).append('\n');
buffer.append("[/Legend]\n"); buffer.append("[/Legend]\n");
return buffer.toString(); return buffer.toString();
@ -210,8 +210,8 @@ public class LegendRecord
LittleEndian.putShort(data, 0 + offset, sid); LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
LittleEndian.putInt(data, 4 + offset, field_1_xPosition); LittleEndian.putInt(data, 4 + offset, field_1_xAxisUpperLeft);
LittleEndian.putInt(data, 8 + offset, field_2_yPosition); LittleEndian.putInt(data, 8 + offset, field_2_yAxisUpperLeft);
LittleEndian.putInt(data, 12 + offset, field_3_xSize); LittleEndian.putInt(data, 12 + offset, field_3_xSize);
LittleEndian.putInt(data, 16 + offset, field_4_ySize); LittleEndian.putInt(data, 16 + offset, field_4_ySize);
data[ 20 + offset ] = field_5_type; data[ 20 + offset ] = field_5_type;
@ -236,35 +236,35 @@ public class LegendRecord
/** /**
* Get the x position field for the Legend record. * Get the x axis upper left field for the Legend record.
*/ */
public int getXPosition() public int getXAxisUpperLeft()
{ {
return field_1_xPosition; return field_1_xAxisUpperLeft;
} }
/** /**
* Set the x position field for the Legend record. * Set the x axis upper left field for the Legend record.
*/ */
public void setXPosition(int field_1_xPosition) public void setXAxisUpperLeft(int field_1_xAxisUpperLeft)
{ {
this.field_1_xPosition = field_1_xPosition; this.field_1_xAxisUpperLeft = field_1_xAxisUpperLeft;
} }
/** /**
* Get the y position field for the Legend record. * Get the y axis upper left field for the Legend record.
*/ */
public int getYPosition() public int getYAxisUpperLeft()
{ {
return field_2_yPosition; return field_2_yAxisUpperLeft;
} }
/** /**
* Set the y position field for the Legend record. * Set the y axis upper left field for the Legend record.
*/ */
public void setYPosition(int field_2_yPosition) public void setYAxisUpperLeft(int field_2_yAxisUpperLeft)
{ {
this.field_2_yPosition = field_2_yPosition; this.field_2_yAxisUpperLeft = field_2_yAxisUpperLeft;
} }
/** /**
@ -308,7 +308,7 @@ public class LegendRecord
* TYPE_TOP * TYPE_TOP
* TYPE_RIGHT * TYPE_RIGHT
* TYPE_LEFT * TYPE_LEFT
* TYPE_NOT_DOCKED * TYPE_UNDOCKED
*/ */
public byte getType() public byte getType()
{ {
@ -325,7 +325,7 @@ public class LegendRecord
* TYPE_TOP * TYPE_TOP
* TYPE_RIGHT * TYPE_RIGHT
* TYPE_LEFT * TYPE_LEFT
* TYPE_NOT_DOCKED * TYPE_UNDOCKED
*/ */
public void setType(byte field_5_type) public void setType(byte field_5_type)
{ {
@ -377,7 +377,7 @@ public class LegendRecord
/** /**
* Sets the auto position field value. * Sets the auto position field value.
* set to true if legend is docked * automatic positioning (1=docked)
*/ */
public void setAutoPosition(boolean value) public void setAutoPosition(boolean value)
{ {
@ -385,7 +385,7 @@ public class LegendRecord
} }
/** /**
* set to true if legend is docked * automatic positioning (1=docked)
* @return the auto position field value. * @return the auto position field value.
*/ */
public boolean isAutoPosition() public boolean isAutoPosition()
@ -395,7 +395,7 @@ public class LegendRecord
/** /**
* Sets the auto series field value. * Sets the auto series field value.
* automatic series distribution * excel 5 only (true)
*/ */
public void setAutoSeries(boolean value) public void setAutoSeries(boolean value)
{ {
@ -403,7 +403,7 @@ public class LegendRecord
} }
/** /**
* automatic series distribution * excel 5 only (true)
* @return the auto series field value. * @return the auto series field value.
*/ */
public boolean isAutoSeries() public boolean isAutoSeries()
@ -412,75 +412,75 @@ public class LegendRecord
} }
/** /**
* Sets the auto pos x field value. * Sets the auto x positioning field value.
* x positioning is done automatically * position of legend on the x axis is automatic
*/ */
public void setAutoPosX(boolean value) public void setAutoXPositioning(boolean value)
{ {
field_7_options = autoPosX.setShortBoolean(field_7_options, value); field_7_options = autoXPositioning.setShortBoolean(field_7_options, value);
} }
/** /**
* x positioning is done automatically * position of legend on the x axis is automatic
* @return the auto pos x field value. * @return the auto x positioning field value.
*/ */
public boolean isAutoPosX() public boolean isAutoXPositioning()
{ {
return autoPosX.isSet(field_7_options); return autoXPositioning.isSet(field_7_options);
} }
/** /**
* Sets the auto pos y field value. * Sets the auto y positioning field value.
* y positioning is done automatically * position of legend on the y axis is automatic
*/ */
public void setAutoPosY(boolean value) public void setAutoYPositioning(boolean value)
{ {
field_7_options = autoPosY.setShortBoolean(field_7_options, value); field_7_options = autoYPositioning.setShortBoolean(field_7_options, value);
} }
/** /**
* y positioning is done automatically * position of legend on the y axis is automatic
* @return the auto pos y field value. * @return the auto y positioning field value.
*/ */
public boolean isAutoPosY() public boolean isAutoYPositioning()
{ {
return autoPosY.isSet(field_7_options); return autoYPositioning.isSet(field_7_options);
} }
/** /**
* Sets the vert field value. * Sets the vertical field value.
* if true legend is vertical (otherwise it's horizonal) * vertical or horizontal legend (1 or 0 respectively). Always 0 if not automatic.
*/ */
public void setVert(boolean value) public void setVertical(boolean value)
{ {
field_7_options = vert.setShortBoolean(field_7_options, value); field_7_options = vertical.setShortBoolean(field_7_options, value);
} }
/** /**
* if true legend is vertical (otherwise it's horizonal) * vertical or horizontal legend (1 or 0 respectively). Always 0 if not automatic.
* @return the vert field value. * @return the vertical field value.
*/ */
public boolean isVert() public boolean isVertical()
{ {
return vert.isSet(field_7_options); return vertical.isSet(field_7_options);
} }
/** /**
* Sets the contains data table field value. * Sets the data table field value.
* true if the chart contains the data table * 1 if chart contains data table
*/ */
public void setContainsDataTable(boolean value) public void setDataTable(boolean value)
{ {
field_7_options = containsDataTable.setShortBoolean(field_7_options, value); field_7_options = dataTable.setShortBoolean(field_7_options, value);
} }
/** /**
* true if the chart contains the data table * 1 if chart contains data table
* @return the contains data table field value. * @return the data table field value.
*/ */
public boolean isContainsDataTable() public boolean isDataTable()
{ {
return containsDataTable.isSet(field_7_options); return dataTable.isSet(field_7_options);
} }

View File

@ -32,12 +32,24 @@
<testresult value="0x1"/> <testresult value="0x1"/>
</field> </field>
<field type="int" size="2" name="options" description="various bit settings"> <field type="int" size="2" name="options" description="various bit settings">
<bit number="0" name="auto position" description="automatic positioning (1=docked)"/> <bit number="0" name="auto position" description="automatic positioning (1=docked)">
<bit number="1" name="auto series" description="excel 5 only (true)"/> <testresult value="true"/>
<bit mask="0x4" name="auto x positioning" description="position of legend on the x axis is automatic"/> </bit>
<bit mask="0x8" name="auto y positioning" description="position of legend on the y axis is automatic"/> <bit number="1" name="auto series" description="excel 5 only (true)">
<bit mask="0x10" name="vertical" description="vertical or horizontal legend (1 or 0 respectively). Always 0 if not automatic."/> <testresult value="true"/>
<bit mask="0x20" name="data table" description="1 if chart contains data table"/> </bit>
<bit number="2" name="auto x positioning" description="position of legend on the x axis is automatic">
<testresult value="true"/>
</bit>
<bit number="3" name="auto y positioning" description="position of legend on the y axis is automatic">
<testresult value="true"/>
</bit>
<bit number="4" name="vertical" description="vertical or horizontal legend (1 or 0 respectively). Always 0 if not automatic.">
<testresult value="true"/>
</bit>
<bit number="5" name="data table" description="1 if chart contains data table">
<testresult value="false"/>
</bit>
<!-- rest is always 0 --> <!-- rest is always 0 -->
<testresult value="0x1f"/> <testresult value="0x1f"/>
</field> </field>
@ -45,5 +57,5 @@
<testdata> <testdata>
76 0E 00 00 86 07 00 00 19 01 00 00 8B 00 00 00 03 01 1F 00 76 0E 00 00 86 07 00 00 19 01 00 00 8B 00 00 00 03 01 1F 00
</testdata> </testdata>
<testsize>10</testsize> <testsize>24</testsize>
</record> </record>

View File

@ -143,12 +143,12 @@ public class Test<xsl:value-of select="@name"/>Record
</xsl:template> </xsl:template>
<xsl:template match="bit" mode="get"> <xsl:template match="bit" mode="get">
<xsl:text> </xsl:text>assertEquals( XXX, record.is<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>() );<xsl:text> <xsl:text> </xsl:text>assertEquals( <xsl:value-of select="./testresult/@value"/>, record.is<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>() );<xsl:text>
</xsl:text> </xsl:text>
</xsl:template> </xsl:template>
<xsl:template match="bit" mode="set"> <xsl:template match="bit" mode="set">
<xsl:text> </xsl:text>record.set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>( XXX );<xsl:text> <xsl:text> </xsl:text>record.set<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>( <xsl:value-of select="./testresult/@value"/> );<xsl:text>
</xsl:text> </xsl:text>
</xsl:template> </xsl:template>

View File

@ -1,3 +1,4 @@
/* ==================================================================== /* ====================================================================
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
@ -52,8 +53,10 @@
* <http://www.apache.org/>. * <http://www.apache.org/>.
*/ */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
@ -61,19 +64,14 @@ import junit.framework.TestCase;
* class works correctly. Test data taken directly from a real * class works correctly. Test data taken directly from a real
* Excel file. * Excel file.
* *
* @author Glen Stampoultzis (glens at apache.org)
* @author Andrew C. Oliver (acoliver at apache.org)
*/ */
public class TestLegendRecord public class TestLegendRecord
extends TestCase extends TestCase
{ {
byte[] data = new byte[] { byte[] data = new byte[] {
(byte)0xB2,(byte)0x0D,(byte)0x00,(byte)0x00, //field_1_xPosition (byte)0x76,(byte)0x0E,(byte)0x00,(byte)0x00,(byte)0x86,(byte)0x07,(byte)0x00,(byte)0x00,(byte)0x19,(byte)0x01,(byte)0x00,(byte)0x00,(byte)0x8B,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x03,(byte)0x01,(byte)0x1F,(byte)0x00
(byte)0x39,(byte)0x06,(byte)0x00,(byte)0x00, //field_2_yPosition
(byte)0xD9,(byte)0x01,(byte)0x00,(byte)0x00, //field_3_xSize
(byte)0x34,(byte)0x02,(byte)0x00,(byte)0x00, //field_4_ySize
(byte)0x03, //field_5_type
(byte)0x01, //field_6_spacing
(byte)0x1F,(byte)0x00 //field_7_options
}; };
public TestLegendRecord(String name) public TestLegendRecord(String name)
@ -84,44 +82,63 @@ public class TestLegendRecord
public void testLoad() public void testLoad()
throws Exception throws Exception
{ {
LegendRecord record = new LegendRecord((short)0x1015, (short)data.length, data);
LegendRecord legendRecord = new LegendRecord((short)0x1015, (short)data.length, data);
assertEquals(3506, legendRecord.getXPosition());
assertEquals(1593, legendRecord.getYPosition());
assertEquals(473, legendRecord.getXSize());
assertEquals(564, legendRecord.getYSize());
assertEquals(LegendRecord.TYPE_RIGHT, legendRecord.getType());
assertEquals(LegendRecord.SPACING_MEDIUM, legendRecord.getSpacing());
assertEquals(31, legendRecord.getOptions());
assertEquals(true, legendRecord.isAutoPosition());
assertEquals(true, legendRecord.isAutoSeries());
assertEquals(true, legendRecord.isAutoPosX());
assertEquals(true, legendRecord.isAutoPosY());
assertEquals(true, legendRecord.isVert());
assertEquals(false, legendRecord.isContainsDataTable());
assertEquals(24, legendRecord.getRecordSize()); assertEquals( (int)0xe76, record.getXAxisUpperLeft());
legendRecord.validateSid((short)0x1015); assertEquals( (int)0x786, record.getYAxisUpperLeft());
assertEquals( (int)0x119, record.getXSize());
assertEquals( (int)0x8b, record.getYSize());
assertEquals( (byte)0x3, record.getType());
assertEquals( (byte)0x1, record.getSpacing());
assertEquals( (short)0x1f, record.getOptions());
assertEquals( true, record.isAutoPosition() );
assertEquals( true, record.isAutoSeries() );
assertEquals( true, record.isAutoXPositioning() );
assertEquals( true, record.isAutoYPositioning() );
assertEquals( true, record.isVertical() );
assertEquals( false, record.isDataTable() );
assertEquals( 24, record.getRecordSize() );
record.validateSid((short)0x1015);
} }
public void testStore() public void testStore()
{ {
LegendRecord legendRecord = new LegendRecord(); LegendRecord record = new LegendRecord();
legendRecord.setXPosition(3506);
legendRecord.setYPosition(1593);
legendRecord.setXSize(473);
legendRecord.setYSize(564);
legendRecord.setType(LegendRecord.TYPE_RIGHT);
legendRecord.setSpacing(LegendRecord.SPACING_MEDIUM);
legendRecord.setAutoPosition(true);
legendRecord.setAutoSeries(true);
legendRecord.setAutoPosX(true);
legendRecord.setAutoPosY(true);
legendRecord.setVert(true);
legendRecord.setContainsDataTable(false);
byte [] recordBytes = legendRecord.serialize();
record.setXAxisUpperLeft( (int)0xe76 );
record.setYAxisUpperLeft( (int)0x786 );
record.setXSize( (int)0x119 );
record.setYSize( (int)0x8b );
record.setType( (byte)0x3 );
record.setSpacing( (byte)0x1 );
record.setOptions( (short)0x1f );
record.setAutoPosition( true );
record.setAutoSeries( true );
record.setAutoXPositioning( true );
record.setAutoYPositioning( true );
record.setVertical( true );
record.setDataTable( false );
byte [] recordBytes = record.serialize();
assertEquals(recordBytes.length - 4, data.length); assertEquals(recordBytes.length - 4, data.length);
for (int i = 0; i < data.length; i++) for (int i = 0; i < data.length; i++)
assertEquals("At offset " + i, data[i], recordBytes[i+4]); assertEquals("At offset " + i, data[i], recordBytes[i+4]);