mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
Tests - fixed tests failing to bad test mouse clicking and focus
This commit is contained in:
parent
26cab55a64
commit
881dca75bf
5 changed files with 36 additions and 9 deletions
|
@ -215,10 +215,14 @@ public abstract class AbstractGhidraHeadedIntegrationTest
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void click(FieldPanel fp, int clickCount, boolean wait) {
|
protected void click(FieldPanel fp, int clickCount, boolean wait) {
|
||||||
|
|
||||||
Point cursor = fp.getCursorPoint();
|
Point cursor = fp.getCursorPoint();
|
||||||
int x = cursor.x;
|
click(fp, cursor, clickCount, wait);
|
||||||
int y = cursor.y;
|
}
|
||||||
|
|
||||||
|
protected void click(FieldPanel fp, Point p, int clickCount, boolean wait) {
|
||||||
|
|
||||||
|
int x = p.x;
|
||||||
|
int y = p.y;
|
||||||
MouseEvent ev = new MouseEvent(fp, 0, System.currentTimeMillis(), 0, x, y, clickCount,
|
MouseEvent ev = new MouseEvent(fp, 0, System.currentTimeMillis(), 0, x, y, clickCount,
|
||||||
false, MouseEvent.BUTTON1);
|
false, MouseEvent.BUTTON1);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ package ghidra.app.plugin.core.decompile;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
@ -76,10 +77,15 @@ public abstract class AbstractDecompilerTest extends AbstractProgramBasedTest {
|
||||||
|
|
||||||
protected void setDecompilerLocation(int line, int charPosition) {
|
protected void setDecompilerLocation(int line, int charPosition) {
|
||||||
|
|
||||||
runSwing(() -> provider.setCursorLocation(line, charPosition));
|
|
||||||
DecompilerPanel panel = provider.getDecompilerPanel();
|
DecompilerPanel panel = provider.getDecompilerPanel();
|
||||||
FieldPanel fp = panel.getFieldPanel();
|
FieldPanel fp = panel.getFieldPanel();
|
||||||
click(fp, 1, true);
|
FieldLocation loc = loc(line, charPosition);
|
||||||
|
|
||||||
|
// scroll to the field to make sure it has been built so that we can get its point
|
||||||
|
fp.scrollTo(loc);
|
||||||
|
Point p = fp.getPointForLocation(loc);
|
||||||
|
|
||||||
|
click(fp, p, 1, true);
|
||||||
waitForSwing();
|
waitForSwing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,6 +173,7 @@ public class DecompilerNavigationTest extends AbstractDecompilerTest {
|
||||||
assertToken("FUN_01002c93", line, character);
|
assertToken("FUN_01002c93", line, character);
|
||||||
setDecompilerLocation(line, character);
|
setDecompilerLocation(line, character);
|
||||||
|
|
||||||
|
// this is the address within the function of the call to the function we clicked
|
||||||
assertListingAddress(addr("01002d32"));
|
assertListingAddress(addr("01002d32"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,9 +224,8 @@ public class DecompilerNavigationTest extends AbstractDecompilerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertListingAddress(Address expected) {
|
private void assertListingAddress(Address expected) {
|
||||||
ProgramLocation cbLocation = codeBrowser.getCurrentLocation();
|
waitForCondition(() -> expected.equals(codeBrowser.getCurrentLocation().getAddress()),
|
||||||
assertEquals("The Listing is not at the expected address", expected,
|
"The Listing is not at the expected address");
|
||||||
cbLocation.getAddress());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertExternalNavigationPerformed() {
|
private void assertExternalNavigationPerformed() {
|
||||||
|
|
|
@ -1193,7 +1193,18 @@ public class FieldPanel extends JPanel
|
||||||
cursorHandler.doCursorEnd(trigger);
|
cursorHandler.doCursorEnd(trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private FieldLocation getLocationForPoint(int x, int y) {
|
public Point getPointForLocation(FieldLocation location) {
|
||||||
|
|
||||||
|
AnchoredLayout layout = findLayoutOnScreen(location.getIndex());
|
||||||
|
if (layout == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Rectangle r =
|
||||||
|
layout.getCursorRect(location.fieldNum, location.row, location.col);
|
||||||
|
return r.getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldLocation getLocationForPoint(int x, int y) {
|
||||||
FieldLocation location = new FieldLocation();
|
FieldLocation location = new FieldLocation();
|
||||||
// delegate to the appropriate layout to do the work
|
// delegate to the appropriate layout to do the work
|
||||||
Layout layout = findLayoutAt(y);
|
Layout layout = findLayoutAt(y);
|
||||||
|
|
|
@ -1724,6 +1724,12 @@ public class GhidraFileChooserTest extends AbstractDockingTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFocus_FilesViewStaysFocusedAfterRefresh() throws Exception {
|
public void testFocus_FilesViewStaysFocusedAfterRefresh() throws Exception {
|
||||||
|
|
||||||
|
if (BATCH_MODE) {
|
||||||
|
// I don't like this, but these seem to have a focus sensitivity that
|
||||||
|
// does not work correctly in headless
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DirectoryList list = getListView();
|
DirectoryList list = getListView();
|
||||||
focus(list);
|
focus(list);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue