BitFields - updated tests

This commit is contained in:
ghidra1 2019-05-15 12:19:46 -04:00
parent a6d692e19d
commit 54ac180e1a
4 changed files with 63 additions and 15 deletions

View File

@ -140,7 +140,29 @@ public class UnionDataTypeTest extends AbstractGTest {
}
@Test
public void testBitFieldUnionLength() throws Exception {
public void testBitFieldUnion() throws Exception {
int cnt = union.getNumComponents();
for (int i = 0; i < cnt; i++) {
union.delete(0);
}
// NOTE: bitOffset ignored for union
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
union.insert(0, ShortDataType.dataType);
//@formatter:off
CompositeTestUtils.assertExpectedComposite(this, "/TestUnion\n" +
"Unaligned\n" +
"Union TestUnion {\n" +
" 0 short 2 null \"\"\n" +
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
"}\n" +
"Size = 2 Actual Alignment = 1", union);
//@formatter:on
}
@Test
public void testAlignedBitFieldUnion() throws Exception {
int cnt = union.getNumComponents();
for (int i = 0; i < cnt; i++) {
@ -148,16 +170,17 @@ public class UnionDataTypeTest extends AbstractGTest {
}
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
union.insert(0, ShortDataType.dataType);
union.setInternallyAligned(true);
//@formatter:off
CompositeTestUtils.assertExpectedComposite(this, "/TestUnion\n" +
"Unaligned\n" +
"Union TestUnion {\n" +
" 0 short 2 null \"\"\n" +
" 1 byte:2(4) 1 bf1 \"bf1Comment\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", union);
//@formatter:on
//@formatter:off
CompositeTestUtils.assertExpectedComposite(this, "/TestUnion\n" +
"Aligned\n" +
"Union TestUnion {\n" +
" 0 short 2 null \"\"\n" +
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 4", union);
//@formatter:on
}
@Test

View File

@ -203,8 +203,8 @@ public interface Composite extends DataType {
/**
* Inserts a new bitfield at the specified ordinal position in this composite.
* Within an aligned composites the specified byteWidth and bitOffset will be ignored
* while bitOffset is always ignored for unions.
* Within aligned composites and unions the specified byteWidth and bitOffset will be
* ignored.
* The component length will be computed based upon the specified parameters and will
* be reduced from byteWidth to its minimal size for the new component.
* <p>

View File

@ -39,6 +39,7 @@ public class StructureDBTest extends AbstractGTest {
dataMgr = new StandAloneDataTypeManager("dummyDTM");
// default data organization is little-endian
// default BitFieldPackingImpl uses gcc conventions with type alignment enabled
dataMgr.startTransaction("Test");

View File

@ -40,6 +40,7 @@ public class UnionDBTest extends AbstractGTest {
dataMgr = new StandAloneDataTypeManager("dummydataMgr");
// default data organization is little-endian
// default BitFieldPackingImpl uses gcc conventions
dataMgr.startTransaction("Test");
@ -156,12 +157,13 @@ public class UnionDBTest extends AbstractGTest {
}
@Test
public void testBitFieldUnionLength() throws Exception {
public void testBitFieldUnion() throws Exception {
int cnt = union.getNumComponents();
for (int i = 0; i < cnt; i++) {
union.delete(0);
}
// NOTE: bitOffset ignored for union
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
union.insert(0, ShortDataType.dataType);
@ -170,9 +172,31 @@ public class UnionDBTest extends AbstractGTest {
"Unaligned\n" +
"Union TestUnion {\n" +
" 0 short 2 null \"\"\n" +
" 1 byte:2(4) 1 bf1 \"bf1Comment\"\n" +
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", union);
"Size = 2 Actual Alignment = 1", union);
//@formatter:on
}
@Test
public void testAlignedBitFieldUnion() throws Exception {
int cnt = union.getNumComponents();
for (int i = 0; i < cnt; i++) {
union.delete(0);
}
union.insertBitField(0, 4, 12, IntegerDataType.dataType, 2, "bf1", "bf1Comment");
union.insert(0, ShortDataType.dataType);
union.setInternallyAligned(true);
//@formatter:off
CompositeTestUtils.assertExpectedComposite(this, "/TestUnion\n" +
"Aligned\n" +
"Union TestUnion {\n" +
" 0 short 2 null \"\"\n" +
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 4", union);
//@formatter:on
}