mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
Test timinig fixes
This commit is contained in:
parent
cf95afc23d
commit
900513ba93
9 changed files with 111 additions and 95 deletions
|
@ -177,7 +177,9 @@ public class ClearTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
public void testClearActionEnablement() throws Exception {
|
||||
|
||||
closeProgram();
|
||||
assertTrue(!clearAction.isEnabledForContext(new ActionContext()));
|
||||
|
||||
assertFalse(isEnabled(clearAction, cb.getProvider()));
|
||||
assertFalse(clearAction.isEnabledForContext(new ActionContext()));
|
||||
|
||||
showTool(tool);
|
||||
loadProgram("notepad");
|
||||
|
@ -185,10 +187,10 @@ public class ClearTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
waitForSwing();
|
||||
assertTrue(cb.goToField(addr("0x10026f0"), "Address", 0, 0));
|
||||
|
||||
assertTrue(clearAction.isEnabled());
|
||||
assertTrue(isEnabled(clearAction, cb.getProvider()));
|
||||
closeProgram();
|
||||
|
||||
assertTrue(!clearAction.isEnabledForContext(new ActionContext()));
|
||||
assertFalse(isEnabled(clearAction, cb.getProvider()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -201,7 +203,6 @@ public class ClearTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
doClearAction(true);
|
||||
|
||||
assertEquals(numInstructions, program.getListing().getNumInstructions());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -453,7 +454,7 @@ public class ClearTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
|
||||
Symbol[] symbols = program.getSymbolTable().getSymbols(addr("0x01001010"));
|
||||
assertEquals(1, symbols.length);
|
||||
assertTrue(!symbols[0].isDynamic());
|
||||
assertFalse(symbols[0].isDynamic());
|
||||
int id = program.startTransaction("Anchor");
|
||||
symbols[0].setPinned(true);
|
||||
program.endTransaction(id, true);
|
||||
|
@ -467,7 +468,7 @@ public class ClearTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
|
||||
symbols = program.getSymbolTable().getSymbols(addr("0x01001010"));
|
||||
assertEquals(1, symbols.length);
|
||||
assertTrue(!symbols[0].isDynamic());
|
||||
assertFalse(symbols[0].isDynamic());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -639,7 +640,7 @@ public class ClearTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
assertTrue(l.getNumInstructions() > 0);
|
||||
assertTrue(l.getNumDefinedData() > 0);
|
||||
|
||||
assertTrue(!program.getListing().getFunctions(true).hasNext());
|
||||
assertFalse(program.getListing().getFunctions(true).hasNext());
|
||||
|
||||
assertTrue(program.getSymbolTable().getNumSymbols() > 0);
|
||||
undo(program);
|
||||
|
@ -674,7 +675,7 @@ public class ClearTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
|
||||
okOnClearDialog();
|
||||
|
||||
assertTrue(!context.hasValueOverRange(ax, BigInteger.valueOf(5),
|
||||
assertFalse(context.hasValueOverRange(ax, BigInteger.valueOf(5),
|
||||
new AddressSet(addr("0x10022cc"))));
|
||||
undo(program);
|
||||
assertTrue(context.hasValueOverRange(ax, BigInteger.valueOf(5),
|
||||
|
|
|
@ -94,8 +94,6 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
|
|||
}
|
||||
|
||||
private void showProgramTree() {
|
||||
|
||||
ProgramTreePlugin ptree = env.getPlugin(ProgramTreePlugin.class);
|
||||
programTreeProvider = (ComponentProvider) getInstanceField("viewProvider", pt);
|
||||
tool.showComponentProvider(programTreeProvider, true);
|
||||
}
|
||||
|
@ -219,7 +217,7 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
|
|||
@Test
|
||||
public void testSelectWithView() throws Exception {
|
||||
AddressSet rsrcSet = new AddressSet(addr("0100a000"), addr("0100f3ff"));
|
||||
JTree tree = findComponent(tool.getToolFrame(), JTree.class);
|
||||
JTree tree = waitFor(() -> findComponent(tool.getToolFrame(), JTree.class));
|
||||
|
||||
// Replace view with .rsrc
|
||||
selectTreeNodeByText(tree, ".rsrc", true);
|
||||
|
@ -396,9 +394,6 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
|
|||
}, wait);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param instructionSet
|
||||
*/
|
||||
private void checkForInstructions(ProgramSelection instructionSet) {
|
||||
Listing listing = program.getListing();
|
||||
AddressIterator iter = instructionSet.getAddresses(true);
|
||||
|
@ -409,9 +404,6 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataSet
|
||||
*/
|
||||
private void checkForDefinedData(ProgramSelection dataSet) {
|
||||
Listing listing = program.getListing();
|
||||
AddressIterator iter = dataSet.getAddresses(true);
|
||||
|
@ -422,9 +414,6 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param undefinedSet
|
||||
*/
|
||||
private void checkForUndefined(ProgramSelection undefinedSet) {
|
||||
Listing listing = program.getListing();
|
||||
AddressIterator iter = undefinedSet.getAddresses(true);
|
||||
|
|
|
@ -97,7 +97,8 @@ public class TableChooserDialogTest extends AbstractGhidraHeadedIntegrationTest
|
|||
|
||||
Program program = builder.getProgram();
|
||||
Navigatable navigatable = null;
|
||||
dialog = new TableChooserDialog(tool, executor, program, "Dialog Title", navigatable);
|
||||
runSwing(() -> dialog =
|
||||
new TableChooserDialog(tool, executor, program, "Dialog Title", navigatable));
|
||||
|
||||
testAction = new TestAction();
|
||||
dialog.addAction(testAction);
|
||||
|
|
|
@ -43,7 +43,6 @@ public class CloseToolTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
env = new TestEnv();
|
||||
}
|
||||
|
||||
|
@ -62,7 +61,6 @@ public class CloseToolTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
assertNotNull(tool.getToolFrame());
|
||||
closeTool(tool);
|
||||
assertNull("Tool did not close after task", tool.getToolFrame());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -87,7 +85,7 @@ public class CloseToolTest extends AbstractGhidraHeadedIntegrationTest {
|
|||
assertNotNull(closeOthersAction);
|
||||
ProgramActionContext context = new ProgramActionContext(null, program1);
|
||||
assertEquals(true, closeOthersAction.isEnabledForContext(context));
|
||||
performAction(closeOthersAction, true);
|
||||
performAction(closeOthersAction, context, true);
|
||||
|
||||
allOpenPrograms = pm.getAllOpenPrograms();
|
||||
assertEquals(1, allOpenPrograms.length);
|
||||
|
|
|
@ -60,10 +60,11 @@ public class DefaultGraphDisplayProvider implements GraphDisplayProvider {
|
|||
return visibleGraph;
|
||||
}
|
||||
|
||||
DefaultGraphDisplay display =
|
||||
Swing.runNow(() -> new DefaultGraphDisplay(this, displayCounter++));
|
||||
return Swing.runNow(() -> {
|
||||
DefaultGraphDisplay display = new DefaultGraphDisplay(this, displayCounter++);
|
||||
displays.add(display);
|
||||
return display;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,10 +77,11 @@ public class DefaultGraphDisplayProvider implements GraphDisplayProvider {
|
|||
|
||||
@Override
|
||||
public List<GraphDisplay> getAllGraphDisplays() {
|
||||
return Swing.runNow(() -> {
|
||||
return displays.stream()
|
||||
.filter(d -> d.getComponent().isShowing())
|
||||
.sorted((d1, d2) -> -(d1.getId() - d2.getId())) // largest/newest IDs come first
|
||||
.collect(Collectors.toList());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,8 +38,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.junit.*;
|
||||
|
||||
import docking.*;
|
||||
import docking.action.DockingActionIf;
|
||||
import docking.action.ToggleDockingActionIf;
|
||||
import docking.action.*;
|
||||
import docking.actions.DockingToolActions;
|
||||
import docking.dnd.GClipboard;
|
||||
import docking.framework.DockingApplicationConfiguration;
|
||||
|
@ -2142,6 +2141,11 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
|
|||
return runSwing(() -> action.isEnabledForContext(new ActionContext()));
|
||||
}
|
||||
|
||||
public static boolean isEnabled(DockingActionIf action,
|
||||
ActionContextProvider contextProvider) {
|
||||
return runSwing(() -> action.isEnabledForContext(contextProvider.getActionContext(null)));
|
||||
}
|
||||
|
||||
public static boolean isEnabled(AbstractButton button) {
|
||||
return runSwing(() -> button.isEnabled());
|
||||
}
|
||||
|
|
|
@ -127,6 +127,7 @@ public class ImagePanel extends JPanel {
|
|||
|
||||
/**
|
||||
* Create an NavigableImagePanel with the specified image
|
||||
* @param image the image
|
||||
*/
|
||||
public ImagePanel(Image image) {
|
||||
initUI();
|
||||
|
@ -202,12 +203,24 @@ public class ImagePanel extends JPanel {
|
|||
return imagePanel.getBackground();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
* @param text unused
|
||||
* @deprecated unused
|
||||
*/
|
||||
@Deprecated(since = "10.2", forRemoval = true) // unused
|
||||
public void setText(String text) {
|
||||
label.setText(text);
|
||||
// unused
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
* @return unused
|
||||
* @deprecated unused
|
||||
*/
|
||||
@Deprecated(since = "10.2", forRemoval = true) // unused
|
||||
public String getText() {
|
||||
return label.getText();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -223,7 +236,7 @@ public class ImagePanel extends JPanel {
|
|||
* nearest pre-configured magnification factor, rounding down for zoom factors less than
|
||||
* 1.0, and up for factors greater than 1.0. Zoom factors outside the pre-configured range
|
||||
* are limited to the nearest range extent.
|
||||
* @param zoom
|
||||
* @param zoom the zoom
|
||||
*/
|
||||
public void setZoomFactor(float zoom) {
|
||||
|
||||
|
@ -270,8 +283,8 @@ public class ImagePanel extends JPanel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the default zoom level
|
||||
* @return
|
||||
* Get the default zoom factory
|
||||
* @return the zoom factor
|
||||
*/
|
||||
public float getDefaultZoomFactor() {
|
||||
return defaultZoomFactor;
|
||||
|
@ -279,7 +292,7 @@ public class ImagePanel extends JPanel {
|
|||
|
||||
/**
|
||||
* Set the default zoom level, adhering to the same set of constrains as {@link #setZoomFactor(float)}
|
||||
* @param zoom
|
||||
* @param zoom the zoom
|
||||
* @see #setZoomFactor(float)
|
||||
* @see #resetZoom()
|
||||
*/
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package docking.widgets.imagepanel;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.awt.Image;
|
||||
|
||||
|
@ -39,84 +39,92 @@ public class ImagePanelTest extends AbstractDockingTest {
|
|||
Image emptyImage = ResourceManager.getImageIcon(emptyIcon).getImage();
|
||||
imagePanel = new ImagePanel(emptyImage);
|
||||
|
||||
runSwing(() -> {
|
||||
frame = new JFrame("ImagePanel Test");
|
||||
frame.getContentPane().add(imagePanel);
|
||||
frame.setSize(400, 400);
|
||||
|
||||
frame.setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
frame.dispose();
|
||||
runSwing(() -> frame.dispose());
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
imagePanel.setZoomFactor(1.0f);
|
||||
setZoom(1.0f);
|
||||
|
||||
assertTrue("Unable to reset zoom factor",
|
||||
Float.compare(imagePanel.getZoomFactor(), 1.0f) == 0);
|
||||
|
||||
Float.compare(getZoom(), 1.0f) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoom_Neutral() {
|
||||
reset();
|
||||
|
||||
imagePanel.setZoomFactor(1.0f);
|
||||
setZoom(1.0f);
|
||||
|
||||
assertTrue("Zoom factor not set to 1.0x",
|
||||
Float.compare(imagePanel.getZoomFactor(), 1.0f) == 0);
|
||||
Float.compare(getZoom(), 1.0f) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoom_10Point0f() {
|
||||
reset();
|
||||
|
||||
imagePanel.setZoomFactor(10.0f);
|
||||
setZoom(10.0f);
|
||||
|
||||
assertTrue("Zoom factor not set to 10.0x",
|
||||
Float.compare(imagePanel.getZoomFactor(), 10.0f) == 0);
|
||||
Float.compare(getZoom(), 10.0f) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoom_0Point05() {
|
||||
reset();
|
||||
|
||||
imagePanel.setZoomFactor(0.05f);
|
||||
setZoom(0.05f);
|
||||
|
||||
assertTrue("Zoom factor not set to 0.05x",
|
||||
Float.compare(imagePanel.getZoomFactor(), 0.05f) == 0);
|
||||
Float.compare(getZoom(), 0.05f) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoom_20Point0() {
|
||||
reset();
|
||||
|
||||
imagePanel.setZoomFactor(20.0f);
|
||||
setZoom(20.0f);
|
||||
|
||||
assertTrue("Zoom factor not set to 20.0x; should be 10.0x",
|
||||
Float.compare(imagePanel.getZoomFactor(), 10.0f) == 0);
|
||||
Float.compare(getZoom(), 10.0f) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoom_0Point001() {
|
||||
reset();
|
||||
|
||||
imagePanel.setZoomFactor(0.001f);
|
||||
setZoom(0.001f);
|
||||
|
||||
assertTrue("Zoom factor not set to 0.001x; should be 0.05x",
|
||||
Float.compare(imagePanel.getZoomFactor(), 0.05f) == 0);
|
||||
Float.compare(getZoom(), 0.05f) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoom_3Point75() {
|
||||
reset();
|
||||
|
||||
imagePanel.setZoomFactor(3.75f);
|
||||
setZoom(3.75f);
|
||||
|
||||
assertTrue("Zoom factor not set to 3.75x; should be 4.0x",
|
||||
Float.compare(imagePanel.getZoomFactor(), 4.0f) == 0);
|
||||
Float.compare(getZoom(), 4.0f) == 0);
|
||||
}
|
||||
|
||||
private void setZoom(float zoom) {
|
||||
runSwing(() -> imagePanel.setZoomFactor(zoom));
|
||||
}
|
||||
|
||||
private float getZoom() {
|
||||
return runSwing(() -> imagePanel.getZoomFactor());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue