Tests - MultiTabPluginTest; ExternalCodeBrowserNavigationTest

This commit is contained in:
dragonmacher
2019-09-20 15:18:59 -04:00
parent 9cf7369b07
commit cbf4c9d34a
4 changed files with 38 additions and 28 deletions

View File

@@ -15,8 +15,7 @@
*/
package ghidra.app.plugin.core.codebrowser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
@@ -40,6 +39,7 @@ import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.ExternalLocation;
import ghidra.program.util.OperandFieldLocation;
import ghidra.program.util.ProgramLocation;
import ghidra.util.Msg;
import ghidra.util.table.GhidraTable;
import ghidra.util.task.TaskMonitor;
import mockit.*;
@@ -95,13 +95,11 @@ public class ExternalCodeBrowserNavigationTest extends AbstractCodeBrowserNaviga
program.endTransaction(txId, true);
}
/**
/*
* This test is intended to verify proper navigation on operand external
* reference associated with an operand when the External Navigation option
* indicates Navigate to Linkage (default behavior) and external program
* path has already been established.
*
* @throws Exception
*/
@Test
public void testOperandExternalLinkageNavigation() throws Exception {
@@ -132,14 +130,12 @@ public class ExternalCodeBrowserNavigationTest extends AbstractCodeBrowserNaviga
}
/**
/*
* This test is intended to verify proper navigation on operand external
* reference associated with an operand when the External Navigation option
* indicates Navigate to Linkage (default behavior) and multiple linkages
* exist which will cause a list of linkage locations to be displayed
* allowing one to be selected.
*
* @throws Exception
*/
@Test
public void testOperandExternalMultipleLinkageNavigation() throws Exception {
@@ -178,13 +174,11 @@ public class ExternalCodeBrowserNavigationTest extends AbstractCodeBrowserNaviga
runSwing(() -> table.navigate(row, col));
}
/**
/*
* This test is intended to verify proper navigation on operand external
* reference associated with an operand when the External Navigation option
* indicates Navigate to External Program (non-default behavior) and
* external program path has already been established.
*
* @throws Exception
*/
@Test
public void testOperandExternalProgramNavigation() throws Exception {
@@ -199,7 +193,11 @@ public class ExternalCodeBrowserNavigationTest extends AbstractCodeBrowserNaviga
// verify that navigation to the external program, address 0x1001888, is performed
// since navigation initiated from linkage location
click(cb, 2);
assertEquals(addr("1001888"), cb.getCurrentAddress());
// note: we have to use a 'wait' here, since the tool must open another program
Address expected = addr("1001888");
waitForCondition(() -> expected.equals(cb.getCurrentAddress()));
assertEquals("FILE1", lastNavigationProgram.getDomainFile().getName());
assertEquals(addr("1001888"), lastNavigationLocation.getAddress());
}
@@ -219,19 +217,19 @@ public class ExternalCodeBrowserNavigationTest extends AbstractCodeBrowserNaviga
// since navigation initiated from linkage location
click(cb, 2);
String otherAddress = "0x01001000";
assertEquals(addr(otherAddress), cb.getCurrentAddress());
// note: we have to use a 'wait' here, since the tool must open another program
Address expected = addr("0x01001000");
waitForCondition(() -> expected.equals(cb.getCurrentAddress()));
assertEquals("FILE1", lastNavigationProgram.getDomainFile().getName());
assertEquals(addr(otherAddress), lastNavigationLocation.getAddress());
assertEquals(expected, lastNavigationLocation.getAddress());
}
/**
/*
* This test is intended to verify proper navigation on operand external
* reference associated with an operand when the External Navigation option
* indicates Navigate to External Program (non-default behavior) and
* external program path has NOT been established.
*
* @throws Exception
*/
@Test
public void testOperandExternalProgramMissingPathNavigation() throws Exception {
@@ -253,7 +251,7 @@ public class ExternalCodeBrowserNavigationTest extends AbstractCodeBrowserNaviga
// since navigation initiated from linkage location
click(cb, 2, false);
DockingDialog dialog = (DockingDialog) waitForWindow("No Program Association", 2000);
DockingDialog dialog = (DockingDialog) waitForWindow("No Program Association");
assertNotNull("Expected No Program Association Dialog", dialog);
pressButtonByText(dialog, "Cancel"); // cancel on first try
waitForSwing();
@@ -262,7 +260,7 @@ public class ExternalCodeBrowserNavigationTest extends AbstractCodeBrowserNaviga
click(cb, 2, false); // try again
dialog = (DockingDialog) waitForWindow("No Program Association", 2000);
dialog = (DockingDialog) waitForWindow("No Program Association");
assertNotNull("Expected No Program Association Dialog", dialog);
pressButtonByText(dialog, "Create Association");
waitForSwing();
@@ -280,7 +278,7 @@ public class ExternalCodeBrowserNavigationTest extends AbstractCodeBrowserNaviga
DomainFile extFile = getTool().getProject().getProjectData().getFile(filePath);
assertNotNull("FILE1 not found", extFile);
DataTreeDialog projectTreeDialog = waitForDialogComponent(null, DataTreeDialog.class, 2000);
DataTreeDialog projectTreeDialog = waitForDialogComponent(DataTreeDialog.class);
projectTreeDialog.selectDomainFile(extFile);
waitForDialogTree(projectTreeDialog);
@@ -303,6 +301,8 @@ public class ExternalCodeBrowserNavigationTest extends AbstractCodeBrowserNaviga
public boolean goTo(Invocation inv, final Navigatable navigatable, ProgramLocation loc,
Program p) {
Msg.debug(this, "goTo() called with " + loc);
// Track last navigation location
lastNavigationLocation = loc;
lastNavigationProgram = p;

View File

@@ -517,7 +517,17 @@ public class MultiTabPluginTest extends AbstractGhidraHeadedIntegrationTest {
System.out.println("Total width: " + totalWidth + " out of " + panelWidth);
}
private void assertShowing(Program p) {
private void assertShowing(Program p) throws Exception {
waitForConditionWithoutFailing(() -> {
boolean isHidden = runSwing(() -> panel.isHidden(p));
return !isHidden;
});
boolean isHidden = runSwing(() -> panel.isHidden(p));
if (isHidden) {
capture(tool.getToolFrame(), "multi.tabs.program2.should.be.showing");
}
assertFalse(runSwing(() -> panel.isHidden(p)));
}

View File

@@ -15,8 +15,7 @@
*/
package docking.test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import java.awt.*;
import java.awt.datatransfer.*;
@@ -2221,7 +2220,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
* @param name the file name suffix
* @throws Exception if there is any issue capturing the component
*/
public void capture(JComponent c, String name) throws Exception {
public void capture(Component c, String name) throws Exception {
// old way of grabbing images--still need this if you want to capture a window's
// decorations

View File

@@ -15,7 +15,7 @@
*/
package ghidra.graph.viewer;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.awt.*;
@@ -25,7 +25,8 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import javax.swing.*;
import javax.swing.JDialog;
import javax.swing.JTextArea;
import org.junit.Before;
import org.junit.Test;
@@ -370,7 +371,7 @@ public class GraphComponentTest extends AbstractVisualGraphTest {
}
@Override
public void capture(JComponent c, String name) throws Exception {
public void capture(Component c, String name) throws Exception {
waitForAnimation();
super.capture(c, name);