Test fixes

This commit is contained in:
dragonmacher 2021-10-22 10:55:48 -04:00
parent 4b01baeebe
commit 7b875023ad
4 changed files with 33 additions and 25 deletions

View file

@ -47,7 +47,7 @@ public class FindDataTypesByNameAction extends DockingAction {
public void actionPerformed(ActionContext context) { public void actionPerformed(ActionContext context) {
InputDialog inputDialog = InputDialog inputDialog =
new InputDialog("Find Data Types", "Please enter the search string: "); new InputDialog(NAME, "Please enter the search string: ");
PluginTool tool = plugin.getTool(); PluginTool tool = plugin.getTool();
tool.showDialog(inputDialog); tool.showDialog(inputDialog);
if (inputDialog.isCanceled()) { if (inputDialog.isCanceled()) {

View file

@ -27,6 +27,7 @@ import ghidra.program.model.mem.*;
import ghidra.program.model.scalar.Scalar; import ghidra.program.model.scalar.Scalar;
import ghidra.program.model.symbol.*; import ghidra.program.model.symbol.*;
import ghidra.program.util.*; import ghidra.program.util.*;
import ghidra.util.StringUtilities;
/** /**
* Utility class with methods to get comment information that can be displayed in the * Utility class with methods to get comment information that can be displayed in the
@ -520,26 +521,7 @@ public class DisplayableEol {
} }
Address address = memRefs[i].getToAddress(); Address address = memRefs[i].getToAddress();
String repeatableComment = listing.getComment(CodeUnit.REPEATABLE_COMMENT, address); String[] comment = getComment(listing, address);
if (repeatableComment != null) {
set.add(new RefRepeatComment(address, new String[] { repeatableComment }));
}
CodeUnit cu = listing.getCodeUnitAt(address);
if (cu == null) {
continue;
}
String[] comment = new String[0];
Function func = listing.getFunctionAt(address);
if (func != null) {
comment = func.getRepeatableCommentAsArray();
}
if (comment.length == 0) {
comment = cu.getCommentAsArray(CodeUnit.REPEATABLE_COMMENT);
}
if (comment != null && comment.length > 0) { if (comment != null && comment.length > 0) {
set.add(new RefRepeatComment(address, comment)); set.add(new RefRepeatComment(address, comment));
totalCommentsFound++; totalCommentsFound++;
@ -549,6 +531,27 @@ public class DisplayableEol {
return set.toArray(new RefRepeatComment[set.size()]); return set.toArray(new RefRepeatComment[set.size()]);
} }
private String[] getComment(Listing listing, Address address) {
// prefer listing comments first since there may not be a code unit at this address
String repeatableComment = listing.getComment(CodeUnit.REPEATABLE_COMMENT, address);
if (repeatableComment != null) {
return StringUtilities.toLines(repeatableComment);
}
CodeUnit cu = listing.getCodeUnitAt(address);
if (cu == null) {
return null;
}
Function func = listing.getFunctionAt(address);
if (func != null) {
return func.getRepeatableCommentAsArray();
}
return cu.getCommentAsArray(CodeUnit.REPEATABLE_COMMENT);
}
/** /**
* Return all the comments * Return all the comments
* @return the comments * @return the comments

View file

@ -75,4 +75,9 @@ public class RefRepeatComment {
return true; return true;
} }
@Override
public String toString() {
return Arrays.toString(commentLines);
}
} }

View file

@ -211,7 +211,7 @@ public class CodeBrowserOptionsTest extends AbstractGhidraHeadedIntegrationTest
assertEquals(options1, options2); assertEquals(options1, options2);
options1.setString("foo", "foo1"); options1.setString("foo", "foo1");
assertTrue(!options1.equals(options2)); assertFalse(options1.equals(options2));
} }
@Test @Test
@ -699,7 +699,7 @@ public class CodeBrowserOptionsTest extends AbstractGhidraHeadedIntegrationTest
cb.updateNow(); cb.updateNow();
btf = (ListingTextField) cb.getCurrentField(); btf = (ListingTextField) cb.getCurrentField();
assertEquals(12, getNumberOfLines(btf)); assertEquals(12, getNumberOfLines(btf));
assertTrue(!"; ".equals(btf.getFieldElement(1, 0).getText())); assertFalse("; ".equals(btf.getFieldElement(1, 0).getText()));
assertEquals("01003fa1", btf.getFieldElement(11, 4).getText()); assertEquals("01003fa1", btf.getFieldElement(11, 4).getText());
assertEquals("Mem ref line1.", btf.getFieldElement(11, 11).getText()); assertEquals("Mem ref line1.", btf.getFieldElement(11, 11).getText());
@ -707,7 +707,7 @@ public class CodeBrowserOptionsTest extends AbstractGhidraHeadedIntegrationTest
cb.updateNow(); cb.updateNow();
btf = (ListingTextField) cb.getCurrentField(); btf = (ListingTextField) cb.getCurrentField();
assertEquals(11, getNumberOfLines(btf)); assertEquals(11, getNumberOfLines(btf));
assertTrue(!"; ".equals(btf.getFieldElement(1, 0).getText())); assertFalse("; ".equals(btf.getFieldElement(1, 0).getText()));
cb.goToField(callAddress, "EOL Comment", 9, 4); cb.goToField(callAddress, "EOL Comment", 9, 4);
btf = (ListingTextField) cb.getCurrentField(); btf = (ListingTextField) cb.getCurrentField();
@ -730,7 +730,7 @@ public class CodeBrowserOptionsTest extends AbstractGhidraHeadedIntegrationTest
cb.updateNow(); cb.updateNow();
waitForPostedSwingRunnables(); waitForPostedSwingRunnables();
assertTrue(!cb.goToField(addr("0x10048a3"), "Label", 0, 0)); assertFalse(cb.goToField(addr("0x10048a3"), "Label", 0, 0));
options.setBoolean(names.get(0), true); options.setBoolean(names.get(0), true);
cb.updateNow(); cb.updateNow();
waitForPostedSwingRunnables(); waitForPostedSwingRunnables();