Merge remote-tracking branch 'origin/GP-0-dragonmacher-test-fixes-5-21-25'

This commit is contained in:
Ryan Kurtz 2025-05-21 10:32:29 -04:00
commit 30b0e80733
4 changed files with 42 additions and 41 deletions

View file

@ -934,9 +934,14 @@ public class ProgramBuilder {
} }
public void createComment(String address, String comment, int commentType) { public void createComment(String address, String comment, int commentType) {
CommentType type = CommentType.values()[commentType];
createComment(address, comment, type);
}
public void createComment(String address, String comment, CommentType type) {
tx(() -> { tx(() -> {
Listing listing = program.getListing(); Listing listing = program.getListing();
listing.setComment(addr(address), commentType, comment); listing.setComment(addr(address), type, comment);
}); });
} }

View file

@ -26,7 +26,6 @@ import ghidra.program.database.ProgramDB;
import ghidra.program.model.data.*; import ghidra.program.model.data.*;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.util.InvalidNameException; import ghidra.util.InvalidNameException;
import ghidra.util.Msg;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest { public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
@ -49,10 +48,8 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test @Test
public void testSetName() throws InvalidNameException { public void testSetName() throws InvalidNameException {
String oldName = dataMgr.getName();
String newName = "NewName"; String newName = "NewName";
dataMgr.setName("NewName"); dataMgr.setName(newName);
assertEquals(newName, dataMgr.getName()); assertEquals(newName, dataMgr.getName());
} }
@ -99,16 +96,12 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "Enum", 2), null); dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "Enum", 2), null);
dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "Enum", 2), null); dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "Enum", 2), null);
dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "zEnum", 2), null);
dataMgr.resolve(new EnumDataType(s3.getCategoryPath(), "zEnum2", 2), null);
List<DataType> list = new ArrayList<DataType>(); List<DataType> list = new ArrayList<DataType>();
dataMgr.findDataTypes("Enum", list); dataMgr.findDataTypes("Enum", list);
assertEquals(3, list.size()); assertEquals(3, list.size());
list.clear(); list.clear();
dataMgr.findDataTypes("Enum1", list); dataMgr.findDataTypes("Enum1", list);
Msg.debug(this, "dts: " + list);
Category c1 = root.createCategory("c1"); Category c1 = root.createCategory("c1");
dataMgr.resolve(new EnumDataType(c1.getCategoryPath(), "Enum", 2), null); dataMgr.resolve(new EnumDataType(c1.getCategoryPath(), "Enum", 2), null);
@ -468,25 +461,20 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test @Test
public void testResolveDataType() { public void testResolveDataType() {
StandAloneDataTypeManager dtm = new StandAloneDataTypeManager("Test");
DataTypeManager dtm = new StandAloneDataTypeManager("Test");
int id = dtm.startTransaction(""); int id = dtm.startTransaction("");
try { DataType byteDT = dtm.resolve(new ByteDataType(), null);
DataType byteDT = dtm.resolve(new ByteDataType(), null); DataType myByteDT = dataMgr.resolve(byteDT, null);
assertTrue(myByteDT == dataMgr.getDataType("/byte"));
DataType myByteDT = dataMgr.resolve(byteDT, null); assertNotNull(myByteDT);
assertTrue(myByteDT == dataMgr.getDataType("/byte")); assertEquals(myByteDT.getCategoryPath(), CategoryPath.ROOT);
assertNotNull(myByteDT); dtm.endTransaction(id, true);
assertEquals(myByteDT.getCategoryPath(), CategoryPath.ROOT); dtm.close();
}
finally {
dtm.endTransaction(id, true);
}
} }
@Test @Test
public void testResolveDataType2() throws Exception { public void testResolveDataType2() throws Exception {
DataTypeManager dtm = new StandAloneDataTypeManager("Test"); StandAloneDataTypeManager dtm = new StandAloneDataTypeManager("Test");
int id = dtm.startTransaction(""); int id = dtm.startTransaction("");
Category otherRoot = dataMgr.getRootCategory(); Category otherRoot = dataMgr.getRootCategory();
Category subc = otherRoot.createCategory("subc"); Category subc = otherRoot.createCategory("subc");
@ -501,7 +489,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
@Test @Test
public void testResolveDataType3() throws Exception { public void testResolveDataType3() throws Exception {
DataTypeManager dtm = new StandAloneDataTypeManager("Test"); StandAloneDataTypeManager dtm = new StandAloneDataTypeManager("Test");
int id = dtm.startTransaction(""); int id = dtm.startTransaction("");
Category otherRoot = dataMgr.getRootCategory(); Category otherRoot = dataMgr.getRootCategory();
Category subc = otherRoot.createCategory("subc"); Category subc = otherRoot.createCategory("subc");

View file

@ -459,10 +459,10 @@ public class DiffTest extends DiffTestAdapter {
programBuilderDiffTest1.createMemory("d4", "0x400", 0x100); programBuilderDiffTest1.createMemory("d4", "0x400", 0x100);
programBuilderDiffTest2.createMemory("d2", "0x200", 0x100); programBuilderDiffTest2.createMemory("d2", "0x200", 0x100);
programBuilderDiffTest2.createComment("0x01008000", "My comment", CodeUnit.EOL_COMMENT); programBuilderDiffTest2.createComment("0x01008000", "My comment", CommentType.EOL);
programBuilderDiffTest2.createComment("0x01008607", "My comment", CodeUnit.EOL_COMMENT); programBuilderDiffTest2.createComment("0x01008607", "My comment", CommentType.EOL);
programBuilderDiffTest2.createComment("0x01008a99", "My comment", CodeUnit.EOL_COMMENT); programBuilderDiffTest2.createComment("0x01008a99", "My comment", CommentType.EOL);
programBuilderDiffTest2.createComment("0x0100a001", "My comment", CodeUnit.EOL_COMMENT); programBuilderDiffTest2.createComment("0x0100a001", "My comment", CommentType.EOL);
openDiff(diffTestP1, diffTestP2); openDiff(diffTestP1, diffTestP2);
JTree tree = getProgramTree(); JTree tree = getProgramTree();
@ -528,10 +528,10 @@ public class DiffTest extends DiffTestAdapter {
programBuilderDiffTest1.createMemory("d4", "0x400", 0x100); programBuilderDiffTest1.createMemory("d4", "0x400", 0x100);
programBuilderDiffTest2.createMemory("d2", "0x200", 0x100); programBuilderDiffTest2.createMemory("d2", "0x200", 0x100);
programBuilderDiffTest2.createComment("0x01008000", "My comment", CodeUnit.EOL_COMMENT); programBuilderDiffTest2.createComment("0x01008000", "My comment", CommentType.EOL);
programBuilderDiffTest2.createComment("0x01008607", "My comment", CodeUnit.EOL_COMMENT); programBuilderDiffTest2.createComment("0x01008607", "My comment", CommentType.EOL);
programBuilderDiffTest2.createComment("0x01009943", "My comment", CodeUnit.EOL_COMMENT); programBuilderDiffTest2.createComment("0x01009943", "My comment", CommentType.EOL);
programBuilderDiffTest2.createComment("0x0100a001", "My comment", CodeUnit.EOL_COMMENT); programBuilderDiffTest2.createComment("0x0100a001", "My comment", CommentType.EOL);
openDiff(diffTestP1, diffTestP2); openDiff(diffTestP1, diffTestP2);
JTree tree = getProgramTree(); JTree tree = getProgramTree();

View file

@ -71,11 +71,6 @@ public interface CodeUnit extends MemBuffer, PropertySet {
@Deprecated @Deprecated
public static final int REPEATABLE_COMMENT = 4; public static final int REPEATABLE_COMMENT = 4;
// /**
// * Property type for fall through property
// */
// public static final int FALL_THROUGH = 4;
/** /**
* Any comment property. * Any comment property.
*/ */
@ -105,11 +100,13 @@ public interface CodeUnit extends MemBuffer, PropertySet {
/** /**
* Get the label for this code unit. * Get the label for this code unit.
* @return the label for this code unit.
*/ */
public String getLabel(); public String getLabel();
/** /**
* Get the Symbols for this code unit. * Get the Symbols for this code unit.
* @return the Symbols for this code unit.
* @throws ConcurrentModificationException if this object is no * @throws ConcurrentModificationException if this object is no
* longer valid. * longer valid.
*/ */
@ -117,6 +114,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {
/** /**
* Get the Primary Symbol for this code unit. * Get the Primary Symbol for this code unit.
* @return the Primary Symbol for this code unit.
* @throws ConcurrentModificationException if this object is no * @throws ConcurrentModificationException if this object is no
* longer valid. * longer valid.
*/ */
@ -124,16 +122,19 @@ public interface CodeUnit extends MemBuffer, PropertySet {
/** /**
* Get the starting address for this code unit. * Get the starting address for this code unit.
* @return the starting address for this code unit.
*/ */
public Address getMinAddress(); public Address getMinAddress();
/** /**
* Get the ending address for this code unit. * Get the ending address for this code unit.
* @return the ending address for this code unit.
*/ */
public Address getMaxAddress(); public Address getMaxAddress();
/** /**
* Get the mnemonic for this code unit, e.g., MOV, JMP * Get the mnemonic for this code unit, e.g., MOV, JMP
* @return the mnemonic for this code unit, e.g., MOV, JMP
*/ */
public String getMnemonicString(); public String getMnemonicString();
@ -143,7 +144,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {
* @param commentType either EOL_COMMENT, PRE_COMMENT, * @param commentType either EOL_COMMENT, PRE_COMMENT,
* POST_COMMENT, or REPEATABLE_COMMENT * POST_COMMENT, or REPEATABLE_COMMENT
* @return the comment string of the appropriate type or null if no comment of * @return the comment string of the appropriate type or null if no comment of
* that type exists for this codeunit * that type exists for this code unit
* @throws IllegalArgumentException if type is not one of the * @throws IllegalArgumentException if type is not one of the
* three types of comments supported * three types of comments supported
* @deprecated use {@link #getComment(CommentType)} instead * @deprecated use {@link #getComment(CommentType)} instead
@ -250,7 +251,8 @@ public interface CodeUnit extends MemBuffer, PropertySet {
public byte[] getBytes() throws MemoryAccessException; public byte[] getBytes() throws MemoryAccessException;
/** /**
* Copies max(buffer.length, code unit length) bytes into buffer starting at location offset in buffer. * Copies max(buffer.length, code unit length) bytes into buffer starting at the given offset in
* {@code buffer}.
* @param buffer byte array to copy into * @param buffer byte array to copy into
* @param bufferOffset offset in byte array the copy will start * @param bufferOffset offset in byte array the copy will start
* @throws MemoryAccessException if the full number of bytes could not be read. * @throws MemoryAccessException if the full number of bytes could not be read.
@ -260,6 +262,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {
/** /**
* Returns true if address is contained in the range of this codeUnit * Returns true if address is contained in the range of this codeUnit
* @param testAddr the address to test. * @param testAddr the address to test.
* @return true if address is contained in the range of this codeUnit
*/ */
public boolean contains(Address testAddr); public boolean contains(Address testAddr);
@ -297,12 +300,14 @@ public interface CodeUnit extends MemBuffer, PropertySet {
/** /**
* Get the references for the operand index. * Get the references for the operand index.
* @param index operand index (0 is the first operand) * @param index operand index (0 is the first operand)
* @return the references for the operand index.
*/ */
public Reference[] getOperandReferences(int index); public Reference[] getOperandReferences(int index);
/** /**
* Get the primary reference for the operand index. * Get the primary reference for the operand index.
* @param index operand index (0 is the first operand) * @param index operand index (0 is the first operand)
* @return the primary reference for the operand index.
*/ */
public Reference getPrimaryReference(int index); public Reference getPrimaryReference(int index);
@ -332,15 +337,16 @@ public interface CodeUnit extends MemBuffer, PropertySet {
/** /**
* Get an iterator over all references TO this code unit. * Get an iterator over all references TO this code unit.
* @return an iterator over all references TO this code unit.
*/ */
public ReferenceIterator getReferenceIteratorTo(); public ReferenceIterator getReferenceIteratorTo();
/** /**
* Returns the program that generated this CodeUnit. * Returns the program that generated this CodeUnit.
* @return the program that generated this CodeUnit.
*/ */
public Program getProgram(); public Program getProgram();
//////////////////////////////////////////////////////////////////////////
/** /**
* Gets the external reference (if any) at the opIndex * Gets the external reference (if any) at the opIndex
* @param opIndex the operand index to look for external references * @param opIndex the operand index to look for external references
@ -351,6 +357,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {
/** /**
* Remove external reference (if any) at the given opIndex * Remove external reference (if any) at the given opIndex
* opIndex the index of the operand from which to remove any external reference. * opIndex the index of the operand from which to remove any external reference.
* @param opIndex the op index
*/ */
public void removeExternalReference(int opIndex); public void removeExternalReference(int opIndex);
@ -397,6 +404,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {
/** /**
* Get the number of operands for this code unit. * Get the number of operands for this code unit.
* @return the number of operands for this code unit.
*/ */
public int getNumOperands(); public int getNumOperands();
@ -404,7 +412,7 @@ public interface CodeUnit extends MemBuffer, PropertySet {
* Get the Address for the given operand index if one exists. Data * Get the Address for the given operand index if one exists. Data
* objects have one operand (the value). * objects have one operand (the value).
* @param opIndex index of the operand. * @param opIndex index of the operand.
* @return An addres if the operand represents a fully qualified * @return An address if the operand represents a fully qualified
* address (given the context), or if the operand is a Scalar treated * address (given the context), or if the operand is a Scalar treated
* as an address. Null is returned if no address or scalar exists on that * as an address. Null is returned if no address or scalar exists on that
* operand. * operand.