mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-02-18 08:30:11 +00:00
Tests - fixed decompiler test failing due to not use the correct
provider
This commit is contained in:
parent
df2b59c96e
commit
e3bd31dd41
@ -109,6 +109,14 @@ public abstract class AbstractDecompilerTest extends AbstractProgramBasedTest {
|
||||
return (ClangTextField) line;
|
||||
}
|
||||
|
||||
protected ClangTextField getFieldForLine(DecompilerProvider theProvider, int lineNumber) {
|
||||
|
||||
DecompilerPanel panel = theProvider.getDecompilerPanel();
|
||||
List<Field> fields = panel.getFields();
|
||||
Field line = fields.get(lineNumber - 1); // -1 for 1-based line number
|
||||
return (ClangTextField) line;
|
||||
}
|
||||
|
||||
// note: the index is 0-based; use getFieldForLine() when using 1-based line numbers
|
||||
protected ClangTextField getFieldForIndex(int lineIndex) {
|
||||
|
||||
@ -119,15 +127,16 @@ public abstract class AbstractDecompilerTest extends AbstractProgramBasedTest {
|
||||
}
|
||||
|
||||
protected ClangToken getToken(int line, int col) {
|
||||
FieldLocation loc = loc(line, col);
|
||||
ClangTextField field = getFieldForLine(line);
|
||||
ClangToken token = field.getToken(loc);
|
||||
return token;
|
||||
return getToken(loc(line, col));
|
||||
}
|
||||
|
||||
protected ClangToken getToken(FieldLocation loc) {
|
||||
return getToken(provider, loc);
|
||||
}
|
||||
|
||||
protected ClangToken getToken(DecompilerProvider theProvider, FieldLocation loc) {
|
||||
int lineNumber = loc.getIndex().intValue() + 1; // 0-based
|
||||
ClangTextField field = getFieldForLine(lineNumber);
|
||||
ClangTextField field = getFieldForLine(theProvider, lineNumber);
|
||||
ClangToken token = field.getToken(loc);
|
||||
return token;
|
||||
}
|
||||
@ -141,9 +150,13 @@ public abstract class AbstractDecompilerTest extends AbstractProgramBasedTest {
|
||||
* @return the token under the cursor
|
||||
*/
|
||||
protected ClangToken getToken() {
|
||||
DecompilerPanel panel = getDecompilerPanel();
|
||||
return getToken(provider);
|
||||
}
|
||||
|
||||
protected ClangToken getToken(DecompilerProvider theProvider) {
|
||||
DecompilerPanel panel = theProvider.getDecompilerPanel();
|
||||
FieldLocation loc = panel.getCursorPosition();
|
||||
return getToken(loc);
|
||||
return getToken(theProvider, loc);
|
||||
}
|
||||
|
||||
protected String getTokenText(FieldLocation loc) {
|
||||
|
@ -755,12 +755,13 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
|
||||
Color color = highlight();
|
||||
|
||||
DecompilerProvider clone = cloneDecompiler();
|
||||
assertAllFieldsHighlighted(clone, secondaryHighlightText, color);
|
||||
ClangToken cloneToken = getToken(clone);
|
||||
assertAllFieldsSecondaryHighlighted(clone, cloneToken, color);
|
||||
|
||||
// ensure one field provider does not affect the other
|
||||
removeSecondaryHighlight();
|
||||
assertNoFieldsSecondaryHighlighted(secondaryHighlightText);
|
||||
assertAllFieldsHighlighted(clone, secondaryHighlightText, color);
|
||||
assertAllFieldsSecondaryHighlighted(clone, cloneToken, color);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -989,8 +990,11 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
|
||||
}
|
||||
|
||||
private Color getCombinedHighlightColor(ClangToken token) {
|
||||
DecompilerController controller = provider.getController();
|
||||
DecompilerPanel panel = controller.getDecompilerPanel();
|
||||
return getCombinedHighlightColor(provider, token);
|
||||
}
|
||||
|
||||
private Color getCombinedHighlightColor(DecompilerProvider theProvider, ClangToken token) {
|
||||
DecompilerPanel panel = theProvider.getDecompilerPanel();
|
||||
ClangHighlightController highlightController = panel.getHighlightController();
|
||||
return highlightController.getCombinedColor(token);
|
||||
}
|
||||
@ -1168,12 +1172,19 @@ public class DecompilerClangTest extends AbstractDecompilerTest {
|
||||
assertAllFieldsHighlighted(provider, name, colorMatcher, ignore);
|
||||
}
|
||||
|
||||
private void assertAllFieldsHighlighted(DecompilerProvider theProvider, String name,
|
||||
Color color) {
|
||||
private void assertAllFieldsSecondaryHighlighted(DecompilerProvider theProvider,
|
||||
ClangToken token, Color color) {
|
||||
|
||||
ColorMatcher cm = new ColorMatcher(color);
|
||||
Predicate<ClangToken> noIgnores = t -> false;
|
||||
assertAllFieldsHighlighted(theProvider, name, cm, noIgnores);
|
||||
Predicate<ClangToken> ignores = t -> t == token;
|
||||
String name = token.getText();
|
||||
Color combinedColor = getCombinedHighlightColor(theProvider, token);
|
||||
ColorMatcher cm = new ColorMatcher(color, combinedColor);
|
||||
assertAllFieldsHighlighted(theProvider, name, cm, ignores);
|
||||
|
||||
// test the token under the cursor directly, as that may have a combined highlight applied
|
||||
Color actual = token.getHighlight();
|
||||
assertTrue("Token is not highlighted: '" + token + "'" + "\n\texpected: " + cm +
|
||||
"; found: " + toString(actual), cm.matches(actual));
|
||||
}
|
||||
|
||||
private void assertAllFieldsHighlighted(DecompilerProvider theProvider, String name,
|
||||
|
Loading…
Reference in New Issue
Block a user