Skip to content

Commit 6d5c3fb

Browse files
committed
Corrected EquatePluginTest1 failure and ConvertCommand
1 parent 05f1d70 commit 6d5c3fb

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/ConvertCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ private boolean applyDataSettings(Data data)
9595
DataType dt = data.getBaseDataType();
9696
Settings settings = data;
9797
Settings defaultSettings = dt.getDefaultSettings();
98-
if (Scalar.class.equals(data.getValueClass()) || !(dt instanceof AbstractIntegerDataType)) {
98+
if (!(Scalar.class.equals(data.getValueClass())) ||
99+
!(dt instanceof AbstractIntegerDataType)) {
99100
msg = "Unsupported data type for convert: " + data.getDataType().getDisplayName();
100101
return false;
101102
}

Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/equate/AbstractEquatePluginTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -433,22 +433,20 @@ protected void flushProgramEvents() {
433433
}
434434

435435
protected void createSignedData(Address addr) throws Exception {
436-
int id = program.startTransaction("Test - Create Signed Data");
437-
438-
SignedWordDataType dt = new SignedWordDataType(program.getDataTypeManager());
439-
int length = dt.getLength();
440-
listing.clearCodeUnits(addr, addr.add(length), true);
441-
listing.createData(addr, dt);
442-
443-
program.endTransaction(id, true);
436+
createData(addr, SignedWordDataType.dataType);
444437
}
445438

446439
protected void createUnsignedData(Address addr) throws Exception {
447-
int id = program.startTransaction("Test - Create Unsigned Data");
440+
createData(addr, WordDataType.dataType);
441+
}
442+
443+
protected void createData(Address addr, DataType dt) throws Exception {
444+
int id = program.startTransaction("Test - Create Data");
448445

449-
WordDataType dt = new WordDataType(program.getDataTypeManager());
446+
dt = dt.clone(program.getDataTypeManager());
450447
int length = dt.getLength();
451-
listing.clearCodeUnits(addr, addr.add(length), true);
448+
assertTrue("", length > 0);
449+
listing.clearCodeUnits(addr, addr.add(length - 1), true);
452450
program.getListing().createData(addr, dt);
453451

454452
program.endTransaction(id, true);

Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/equate/EquatePlugin1Test.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import ghidra.program.model.address.Address;
4141
import ghidra.program.model.address.AddressSet;
4242
import ghidra.program.model.data.*;
43+
import ghidra.program.model.data.Enum;
4344
import ghidra.program.model.listing.Data;
4445
import ghidra.program.model.listing.Instruction;
4546
import ghidra.program.model.scalar.Scalar;
@@ -821,6 +822,35 @@ public void testConvertOnUnsignedData() throws Exception {
821822
assertTrue(data.getDataType() instanceof SignedWordDataType);
822823
}
823824

825+
@Test
826+
public void testNoConvertOnData() throws Exception {
827+
Address addr = addr(0x01003384);
828+
829+
// action should not apply to BooleanDataType which produces Scalar value
830+
createData(addr, BooleanDataType.dataType);
831+
Data data = program.getListing().getDataAt(addr);
832+
assertTrue(data.getDataType() instanceof BooleanDataType);
833+
834+
goTo(addr);
835+
DockingActionIf action = getAction(equatePlugin, "Convert To Signed Decimal");
836+
837+
assertFalse(action.isAddToPopup(getListingContext()));
838+
assertFalse(action.isEnabledForContext(getListingContext()));
839+
840+
// action should not apply to Enum which produces Scalar value
841+
EnumDataType myEnum = new EnumDataType("Joe", 2);
842+
myEnum.add("ValFFFF", -1);
843+
844+
createData(addr, myEnum);
845+
data = program.getListing().getDataAt(addr);
846+
assertTrue(data.getDataType() instanceof Enum);
847+
848+
goTo(addr);
849+
850+
assertFalse(action.isAddToPopup(getListingContext()));
851+
assertFalse(action.isEnabledForContext(getListingContext()));
852+
}
853+
824854
@Test
825855
public void testConvertPickSameDatatype() throws Exception {
826856
Address addr = addr(0x01003384);

0 commit comments

Comments
 (0)