Merge remote-tracking branch 'origin/GP-0-dragonmacher-test-fixes-6-5-24--SQUASHED'

This commit is contained in:
Ryan Kurtz 2024-06-06 06:05:01 -04:00
commit 4031dca062
9 changed files with 139 additions and 223 deletions

View file

@ -140,8 +140,8 @@ public class DebuggerCopyActionsPluginScreenShots extends GhidraScreenShotGenera
listingProvider.requestFocus(); listingProvider.requestFocus();
waitForSwing(); waitForSwing();
listingProvider.setSelection( runSwing(() -> listingProvider.setSelection(
new ProgramSelection(tb.trace.getMemoryManager().getRegionsAddressSet(snap))); new ProgramSelection(tb.trace.getMemoryManager().getRegionsAddressSet(snap))));
waitForCondition(() -> copyPlugin.actionCopyIntoCurrentProgram.isEnabled()); waitForCondition(() -> copyPlugin.actionCopyIntoCurrentProgram.isEnabled());
performAction(copyPlugin.actionCopyIntoCurrentProgram, false); performAction(copyPlugin.actionCopyIntoCurrentProgram, false);

View file

@ -282,9 +282,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
createAndOpenTrace(); createAndOpenTrace();
TraceThread thread1; TraceThread thread1;
TraceThread thread2; TraceThread thread2;
DebuggerListingProvider extraProvider = SwingExecutorService.LATER DebuggerListingProvider extraProvider = SwingExecutorService.LATER.submit(
.submit(() -> listingPlugin.createListingIfMissing(PCLocationTrackingSpec.INSTANCE, () -> listingPlugin.createListingIfMissing(PCLocationTrackingSpec.INSTANCE, true))
true))
.get(); .get();
try (Transaction tx = tb.startTransaction()) { try (Transaction tx = tb.startTransaction()) {
DBTraceMemoryManager memory = tb.trace.getMemoryManager(); DBTraceMemoryManager memory = tb.trace.getMemoryManager();
@ -754,9 +753,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
waitRecorder(recorder); waitRecorder(recorder);
buf.clear(); buf.clear();
assertEquals(data.length, assertEquals(data.length, trace.getMemoryManager()
trace.getMemoryManager() .getBytes(recorder.getSnap(), addr(trace, 0x55550000), buf));
.getBytes(recorder.getSnap(), addr(trace, 0x55550000), buf));
assertArrayEquals(data, buf.array()); assertArrayEquals(data, buf.array());
})); }));
} }
@ -803,9 +801,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
assertEquals(traceManager.getCurrentView(), listingProvider.getProgram()); assertEquals(traceManager.getCurrentView(), listingProvider.getProgram());
assertEquals("(nowhere)", listingProvider.locationLabel.getText()); assertEquals("(nowhere)", listingProvider.locationLabel.getText());
DebuggerListingProvider extraProvider = DebuggerListingProvider extraProvider = runSwing(
runSwing(() -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE, () -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE, false));
false));
waitForSwing(); waitForSwing();
assertEquals(traceManager.getCurrentView(), extraProvider.getProgram()); assertEquals(traceManager.getCurrentView(), extraProvider.getProgram());
assertEquals("(nowhere)", extraProvider.locationLabel.getText()); assertEquals("(nowhere)", extraProvider.locationLabel.getText());
@ -951,8 +948,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
() -> assertEquals(tb.addr(0x00401234), listingProvider.getLocation().getAddress())); () -> assertEquals(tb.addr(0x00401234), listingProvider.getLocation().getAddress()));
setActionStateWithTrigger(listingProvider.actionTrackLocation, setActionStateWithTrigger(listingProvider.actionTrackLocation,
SPLocationTrackingSpec.INSTANCE, SPLocationTrackingSpec.INSTANCE, EventTrigger.GUI_ACTION);
EventTrigger.GUI_ACTION);
waitForSwing(); waitForSwing();
waitForPass( waitForPass(
() -> assertEquals(tb.addr(0x1fff8765), listingProvider.getLocation().getAddress())); () -> assertEquals(tb.addr(0x1fff8765), listingProvider.getLocation().getAddress()));
@ -1077,8 +1073,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
performAction(listingProvider.actionSyncSelectionFromStaticListing, performAction(listingProvider.actionSyncSelectionFromStaticListing,
codeProvider.getActionContext(null), true); codeProvider.getActionContext(null), true);
assertEquals(tb.set(tb.range(0x00401234, 0x00404321)), assertEquals(tb.set(tb.range(0x00401234, 0x00404321)), listingPlugin.getCurrentSelection());
listingPlugin.getCurrentSelection());
} }
@Test @Test
@ -1104,9 +1099,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
traceManager.activateThread(thread1); traceManager.activateThread(thread1);
// NOTE: Action does not exist for main dynamic listing // NOTE: Action does not exist for main dynamic listing
DebuggerListingProvider extraProvider = DebuggerListingProvider extraProvider = runSwing(
runSwing(() -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE, () -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE, true));
true));
waitForSwing(); waitForSwing();
assertTrue(extraProvider.actionFollowsCurrentThread.isEnabled()); assertTrue(extraProvider.actionFollowsCurrentThread.isEnabled());
assertTrue(extraProvider.actionFollowsCurrentThread.isSelected()); assertTrue(extraProvider.actionFollowsCurrentThread.isSelected());
@ -1150,7 +1144,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
// Still // Still
assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled()); assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());
listingProvider.setSelection(sel); runSwing(() -> listingProvider.setSelection(sel));
waitForSwing(); waitForSwing();
// Still // Still
assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled()); assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());
@ -1172,7 +1166,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
// Action is still disabled, because it requires a selection // Action is still disabled, because it requires a selection
assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled()); assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());
listingProvider.setSelection(sel); runSwing(() -> listingProvider.setSelection(sel));
waitForSwing(); waitForSwing();
// Now, it should be enabled // Now, it should be enabled
assertTrue(listingProvider.actionRefreshSelectedMemory.isEnabled()); assertTrue(listingProvider.actionRefreshSelectedMemory.isEnabled());

View file

@ -15,8 +15,7 @@
*/ */
package ghidra.app.plugin.core.debug.gui.memory; package ghidra.app.plugin.core.debug.gui.memory;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import java.util.*; import java.util.*;
@ -384,7 +383,8 @@ public class DebuggerRegionsProviderLegacyTest extends AbstractGhidraHeadedDebug
assertEquals(region, row.getRegion()); assertEquals(region, row.getRegion());
assertFalse(tb.trace.getProgramView().getMemory().isEmpty()); assertFalse(tb.trace.getProgramView().getMemory().isEmpty());
listing.setSelection(new ProgramSelection(tb.set(tb.range(0x00401234, 0x00404321)))); runSwing(() -> listing
.setSelection(new ProgramSelection(tb.set(tb.range(0x00401234, 0x00404321)))));
waitForPass(() -> assertEquals(tb.set(tb.range(0x00401234, 0x00404321)), waitForPass(() -> assertEquals(tb.set(tb.range(0x00401234, 0x00404321)),
new AddressSet(listing.getSelection()))); new AddressSet(listing.getSelection())));

View file

@ -149,14 +149,14 @@ public class DebuggerRegionsProviderTest extends AbstractGhidraHeadedDebuggerTes
assertEquals(size, provider.panel.getAllItems().size()); assertEquals(size, provider.panel.getAllItems().size());
} }
protected void assertRow(int position, Object object, String name, Address start, protected void assertRow(int position, Object object, String name, Address start, Address end,
Address end, long length, String flags) { long length, String flags) {
ValueRow row = provider.panel.getAllItems().get(position); ValueRow row = provider.panel.getAllItems().get(position);
var tableModel = QueryPanelTestHelper.getTableModel(provider.panel); var tableModel = QueryPanelTestHelper.getTableModel(provider.panel);
GhidraTable table = QueryPanelTestHelper.getTable(provider.panel); GhidraTable table = QueryPanelTestHelper.getTable(provider.panel);
DynamicTableColumn<ValueRow, ?, Trace> nameCol = QueryPanelTestHelper DynamicTableColumn<ValueRow, ?, Trace> nameCol =
.getColumnByNameAndType(tableModel, table, "Name", ValueRow.class) QueryPanelTestHelper.getColumnByNameAndType(tableModel, table, "Name", ValueRow.class)
.column(); .column();
DynamicTableColumn<ValueRow, ?, Trace> startCol = QueryPanelTestHelper DynamicTableColumn<ValueRow, ?, Trace> startCol = QueryPanelTestHelper
.getColumnByNameAndType(tableModel, table, "Start", ValueProperty.class) .getColumnByNameAndType(tableModel, table, "Start", ValueProperty.class)
.column(); .column();
@ -474,8 +474,8 @@ public class DebuggerRegionsProviderTest extends AbstractGhidraHeadedDebuggerTes
waitForPass(() -> { waitForPass(() -> {
assertTableSize(1); assertTableSize(1);
assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000), assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000), tb.addr(0x0040ffff),
tb.addr(0x0040ffff), 0x10000, "rx"); 0x10000, "rx");
}); });
waitForPass(() -> assertFalse(tb.trace.getProgramView().getMemory().isEmpty())); waitForPass(() -> assertFalse(tb.trace.getProgramView().getMemory().isEmpty()));
@ -523,12 +523,13 @@ public class DebuggerRegionsProviderTest extends AbstractGhidraHeadedDebuggerTes
waitForPass(() -> { waitForPass(() -> {
assertTableSize(1); assertTableSize(1);
assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000), assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000), tb.addr(0x0040ffff),
tb.addr(0x0040ffff), 0x10000, "rx"); 0x10000, "rx");
}); });
waitForPass(() -> assertFalse(tb.trace.getProgramView().getMemory().isEmpty())); waitForPass(() -> assertFalse(tb.trace.getProgramView().getMemory().isEmpty()));
listing.setSelection(new ProgramSelection(tb.set(tb.range(0x00401234, 0x00404321)))); runSwing(() -> listing
.setSelection(new ProgramSelection(tb.set(tb.range(0x00401234, 0x00404321)))));
waitForPass(() -> assertEquals(tb.set(tb.range(0x00401234, 0x00404321)), waitForPass(() -> assertEquals(tb.set(tb.range(0x00401234, 0x00404321)),
new AddressSet(listing.getSelection()))); new AddressSet(listing.getSelection())));

View file

@ -139,7 +139,7 @@ public class DebuggerStaticMappingProviderTest extends AbstractGhidraHeadedDebug
ProgramSelection traceSel = ProgramSelection traceSel =
new ProgramSelection(tb.addr(0xdeadbeefL), tb.addr(0xdeadbeefL + 0x0f)); new ProgramSelection(tb.addr(0xdeadbeefL), tb.addr(0xdeadbeefL + 0x0f));
listingPlugin.getProvider().setSelection(traceSel); runSwing(() -> listingPlugin.getProvider().setSelection(traceSel));
codeViewerPlugin.goTo(new ProgramLocation(program, addr(program, 0xc0de1234L)), true); codeViewerPlugin.goTo(new ProgramLocation(program, addr(program, 0xc0de1234L)), true);
waitForSwing(); waitForSwing();

View file

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,10 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
package ghidra.program.util; package ghidra.program.util;
import java.util.Objects;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
/** /**
* Specifies a selection that consists of components inside a structure. * Specifies a selection that consists of components inside a structure.
*/ */
public class InteriorSelection { public class InteriorSelection {
@ -34,19 +36,21 @@ public class InteriorSelection {
* @param start start address * @param start start address
* @param end end address * @param end end address
*/ */
public InteriorSelection(ProgramLocation from, ProgramLocation to, Address start, Address end) { public InteriorSelection(ProgramLocation from, ProgramLocation to, Address start, Address end) {
this.from = from; this.from = from;
this.to = to; this.to = to;
this.start = start; this.start = start;
this.end = end; this.end = end;
} }
/**
* Get the start location. /**
* @return ProgramLocation * Get the start location.
*/ * @return ProgramLocation
*/
public ProgramLocation getFrom() { public ProgramLocation getFrom() {
return from; return from;
} }
/** /**
* Get the end location. * Get the end location.
* @return ProgramLocation * @return ProgramLocation
@ -54,6 +58,7 @@ public class InteriorSelection {
public ProgramLocation getTo() { public ProgramLocation getTo() {
return to; return to;
} }
/** /**
* Get the start address of this selection. * Get the start address of this selection.
* @return Address * @return Address
@ -61,6 +66,7 @@ public class InteriorSelection {
public Address getStartAddress() { public Address getStartAddress() {
return start; return start;
} }
/** /**
* Get the end address of this selection. * Get the end address of this selection.
* @return Address * @return Address
@ -68,41 +74,38 @@ public class InteriorSelection {
public Address getEndAddress() { public Address getEndAddress() {
return end; return end;
} }
/** /**
* Get the number of bytes contained in the selection. * Get the number of bytes contained in the selection.
* @return int * @return int
*/ */
public int getByteLength() { public int getByteLength() {
long diff = end.subtract(start); long diff = end.subtract(start);
return (int) (diff+1); return (int) (diff + 1);
} }
/**
*
* @see java.lang.Object#equals(Object)
*/
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (getClass() != obj.getClass()) {
return false;
}
InteriorSelection is = (InteriorSelection)obj;
return from.equals(is.from) && to.equals(is.to);
}
/* (non Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public int hashCode() {
return Objects.hash(from, to);
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (getClass() != obj.getClass()) {
return false;
}
InteriorSelection is = (InteriorSelection) obj;
return from.equals(is.from) && to.equals(is.to);
}
@Override
public String toString() {
return "From = " + from.getAddress() + ", To = " + to.getAddress(); return "From = " + from.getAddress() + ", To = " + to.getAddress();
} }
} }

View file

@ -16,6 +16,7 @@
package ghidra.program.util; package ghidra.program.util;
import java.util.Iterator; import java.util.Iterator;
import java.util.Objects;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
@ -114,9 +115,11 @@ public class ProgramSelection implements AddressSetView {
return interiorSelection; return interiorSelection;
} }
/** @Override
* Return whether this ProgramSelection is equal to obj. public int hashCode() {
*/ return Objects.hash(interiorSelection, addressSet);
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) { if (obj == null) {
@ -135,113 +138,61 @@ public class ProgramSelection implements AddressSetView {
return addressSet.hasSameAddresses(ps.addressSet); return addressSet.hasSameAddresses(ps.addressSet);
} }
/**
* Test if the address exists within this set.
* <P>
* @param addr address to test.
* @return true if addr exists in the set, false otherwise.
*/
@Override @Override
public boolean contains(Address addr) { public boolean contains(Address addr) {
return addressSet.contains(addr); return addressSet.contains(addr);
} }
/**
* Test if the given address range is in the set.
* <P>
* @param start the first address in the range.
* @param end the last address in the range.
* @return true if entire range is contained within the set,
* false otherwise.
*/
@Override @Override
public boolean contains(Address start, Address end) { public boolean contains(Address start, Address end) {
return addressSet.contains(start, end); return addressSet.contains(start, end);
} }
/**
* Test if the given address set is a subset of this set.
* <P>
* @param rangeSet the set to test.
* @return true if the entire set is contained within this set,
* false otherwise.
*/
@Override @Override
public boolean contains(AddressSetView rangeSet) { public boolean contains(AddressSetView rangeSet) {
return addressSet.contains(rangeSet); return addressSet.contains(rangeSet);
} }
/**
* Determine if this program selection intersects with the specified address set.
*
* @param addrSet address set to check intersection with.
*/
@Override @Override
public boolean intersects(AddressSetView addrSet) { public boolean intersects(AddressSetView addrSet) {
return addressSet != null && addressSet.intersects(addrSet); return addressSet != null && addressSet.intersects(addrSet);
} }
/**
* @see ghidra.program.model.address.AddressSetView#intersect(ghidra.program.model.address.AddressSetView)
*/
@Override @Override
public AddressSet intersect(AddressSetView view) { public AddressSet intersect(AddressSetView view) {
return addressSet.intersect(view); return addressSet.intersect(view);
} }
/**
* @see ghidra.program.model.address.AddressSetView#intersectRange(ghidra.program.model.address.Address, ghidra.program.model.address.Address)
*/
@Override @Override
public AddressSet intersectRange(Address start, Address end) { public AddressSet intersectRange(Address start, Address end) {
return addressSet.intersectRange(start, end); return addressSet.intersectRange(start, end);
} }
/**
* Returns true if this set is empty.
*/
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
return addressSet.isEmpty(); return addressSet.isEmpty();
} }
/**
* Return the minimum address for this set.
*/
@Override @Override
public Address getMinAddress() { public Address getMinAddress() {
return addressSet.getMinAddress(); return addressSet.getMinAddress();
} }
/**
* Return the maximum address for this set.
*/
@Override @Override
public Address getMaxAddress() { public Address getMaxAddress() {
return addressSet.getMaxAddress(); return addressSet.getMaxAddress();
} }
/**
* Return the number of address ranges in this set.
*/
@Override @Override
public int getNumAddressRanges() { public int getNumAddressRanges() {
return addressSet.getNumAddressRanges(); return addressSet.getNumAddressRanges();
} }
/**
* Returns an iterator over the address ranges in this address set.
* @param atStart if true, the iterator is positioned at the minimum address.
* if false, the iterator is positioned at the maximum address.
*/
@Override @Override
public AddressRangeIterator getAddressRanges(boolean atStart) { public AddressRangeIterator getAddressRanges(boolean atStart) {
return addressSet.getAddressRanges(atStart); return addressSet.getAddressRanges(atStart);
} }
/**
* Returns an iterator over the address ranges in this address set.
*/
@Override @Override
public AddressRangeIterator getAddressRanges() { public AddressRangeIterator getAddressRanges() {
return addressSet.getAddressRanges(); return addressSet.getAddressRanges();
@ -252,25 +203,16 @@ public class ProgramSelection implements AddressSetView {
return getAddressRanges(); return getAddressRanges();
} }
/**
* Returns the number of addresses in this set.
*/
@Override @Override
public long getNumAddresses() { public long getNumAddresses() {
return addressSet.getNumAddresses(); return addressSet.getNumAddresses();
} }
/**
* @see ghidra.program.model.address.AddressSetView#getAddresses(boolean)
*/
@Override @Override
public AddressIterator getAddresses(boolean forward) { public AddressIterator getAddresses(boolean forward) {
return addressSet.getAddresses(forward); return addressSet.getAddresses(forward);
} }
/**
* @see ghidra.program.model.address.AddressSetView#getAddresses(ghidra.program.model.address.Address, boolean)
*/
@Override @Override
public AddressIterator getAddresses(Address start, boolean forward) { public AddressIterator getAddresses(Address start, boolean forward) {
return addressSet.getAddresses(start, forward); return addressSet.getAddresses(start, forward);
@ -290,41 +232,26 @@ public class ProgramSelection implements AddressSetView {
return addressSet.hasSameAddresses(asv); return addressSet.hasSameAddresses(asv);
} }
/**
* @see AddressSetView#intersects(Address, Address)
*/
@Override @Override
public boolean intersects(Address start, Address end) { public boolean intersects(Address start, Address end) {
return addressSet.intersects(start, end); return addressSet.intersects(start, end);
} }
/**
* @see ghidra.program.model.address.AddressSetView#union(ghidra.program.model.address.AddressSetView)
*/
@Override @Override
public AddressSet union(AddressSetView view) { public AddressSet union(AddressSetView view) {
return addressSet.union(view); return addressSet.union(view);
} }
/**
* @see ghidra.program.model.address.AddressSetView#xor(ghidra.program.model.address.AddressSetView)
*/
@Override @Override
public AddressSet xor(AddressSetView view) { public AddressSet xor(AddressSetView view) {
return addressSet.xor(view); return addressSet.xor(view);
} }
/**
* @see ghidra.program.model.address.AddressSetView#subtract(ghidra.program.model.address.AddressSetView)
*/
@Override @Override
public AddressSet subtract(AddressSetView view) { public AddressSet subtract(AddressSetView view) {
return addressSet.subtract(view); return addressSet.subtract(view);
} }
/* (non Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public String toString() {
if (interiorSelection != null) { if (interiorSelection != null) {
@ -367,5 +294,4 @@ public class ProgramSelection implements AddressSetView {
public Address findFirstAddressInCommon(AddressSetView set) { public Address findFirstAddressInCommon(AddressSetView set) {
return addressSet.findFirstAddressInCommon(set); return addressSet.findFirstAddressInCommon(set);
} }
} }

View file

@ -431,6 +431,13 @@ public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDock
return null; return null;
} }
public AddressSet toAddressSet(Program p, String from, String to) {
AddressFactory af = p.getAddressFactory();
Address a1 = af.getAddress(from);
Address a2 = af.getAddress(to);
return af.getAddressSet(a1, a2);
}
public AddressSet toAddressSet(List<Address> addrs) { public AddressSet toAddressSet(List<Address> addrs) {
AddressSet set = new AddressSet(); AddressSet set = new AddressSet();
for (Address addr : addrs) { for (Address addr : addrs) {

View file

@ -21,8 +21,7 @@
*/ */
package ghidra.app.plugin.core.select.reference; package ghidra.app.plugin.core.select.reference;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import org.junit.*; import org.junit.*;
@ -70,7 +69,6 @@ public class SelectRefereceActionsTest extends AbstractGhidraHeadedIntegrationTe
SelectRefsPlugin plugin = env.getPlugin(SelectRefsPlugin.class); SelectRefsPlugin plugin = env.getPlugin(SelectRefsPlugin.class);
forwardAction = (SelectForwardRefsAction) getInstanceField("forwardAction", plugin); forwardAction = (SelectForwardRefsAction) getInstanceField("forwardAction", plugin);
backwardAction = (SelectBackRefsAction) getInstanceField("backwardAction", plugin); backwardAction = (SelectBackRefsAction) getInstanceField("backwardAction", plugin);
} }
@After @After
@ -86,24 +84,21 @@ public class SelectRefereceActionsTest extends AbstractGhidraHeadedIntegrationTe
@Test @Test
public void testForwardLocation() { public void testForwardLocation() {
String start = "0020"; String start = "0020";
// Selection of address 01001144 gets expanded within code viewer provider
// to full code unit
CodeUnit cu = program.getListing().getCodeUnitContaining(addr("0010"));
ProgramLocation location = new AddressFieldLocation(program, addr(start)); ProgramLocation location = new AddressFieldLocation(program, addr(start));
cb.goTo(location); cb.goTo(location);
ProgramSelection selection = getCurrentSelection(); ProgramSelection currentSelection = getCurrentSelection();
assertTrue(selection.isEmpty()); assertTrue(currentSelection.isEmpty());
performAction(forwardAction, cb.getProvider().getActionContext(null), true); performAction(forwardAction, cb.getProvider(), true);
selection = getCurrentSelection(); currentSelection = getCurrentSelection();
assertEquals(selection.getNumAddresses(), cu.getLength()); CodeUnit cu = program.getListing().getCodeUnitContaining(addr("0010"));
assertEquals(currentSelection.getNumAddresses(), cu.getLength());
for (Address addr = cu.getMinAddress(); addr.compareTo(cu.getMaxAddress()) <= 0; addr = for (Address addr = cu.getMinAddress(); addr.compareTo(cu.getMaxAddress()) <= 0; addr =
addr.add(1)) { addr.add(1)) {
assertTrue(selection.contains(addr)); assertTrue(currentSelection.contains(addr));
} }
} }
@ -111,98 +106,88 @@ public class SelectRefereceActionsTest extends AbstractGhidraHeadedIntegrationTe
public void testBackwardLocation() { public void testBackwardLocation() {
String start = "0020"; String start = "0020";
// Selection of address 010064c0 and 010064fb gets expanded within code viewer provider
// to full code unit
AddressSet set = new AddressSet();
CodeUnit cu = program.getListing().getCodeUnitContaining(addr("0030"));
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
cu = program.getListing().getCodeUnitContaining(addr("0040"));
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
ProgramLocation location = new AddressFieldLocation(program, addr(start)); ProgramLocation location = new AddressFieldLocation(program, addr(start));
cb.goTo(location); cb.goTo(location);
ProgramSelection selection = getCurrentSelection(); ProgramSelection currentSelection = getCurrentSelection();
assertTrue(selection.isEmpty()); assertTrue(currentSelection.isEmpty());
performAction(backwardAction, cb.getProvider().getActionContext(null), true); performAction(backwardAction, cb.getProvider(), true);
selection = getCurrentSelection();
assertEquals(new AddressSet(selection), set); AddressSet referenceAddrs = getCodeUnitAddrs("0030", "0040");
currentSelection = getCurrentSelection();
assertEquals(new AddressSet(currentSelection), referenceAddrs);
} }
@Test @Test
public void testSelectionWithNoReferences() { public void testSelectionWithNoReferences() {
ProgramSelection selection = new ProgramSelection(addr("0050"), addr("0060")); AddressSetView addrs = toAddressSet(program, "0050", "0060");
CodeViewerProvider provider = cb.getProvider(); CodeViewerProvider provider = cb.getProvider();
provider.setSelection(selection);
performAction(forwardAction, provider.getActionContext(null), true); makeSelection(env.getTool(), program, addrs);
performAction(forwardAction, provider, true);
selection = getCurrentSelection(); ProgramSelection currentSelection = getCurrentSelection();
assertEquals(selection.isEmpty(), true); assertEquals(currentSelection.isEmpty(), true);
selection = new ProgramSelection(addr("010049d0"), addr("010049dd")); currentSelection = new ProgramSelection(addr("010049d0"), addr("010049dd"));
provider.setSelection(selection); addrs = toAddressSet(program, "010049d0", "010049dd");
makeSelection(env.getTool(), program, addrs);
performAction(backwardAction, provider.getActionContext(null), true); performAction(backwardAction, provider, true);
selection = getCurrentSelection(); currentSelection = getCurrentSelection();
assertEquals(selection.isEmpty(), true); assertEquals(currentSelection.isEmpty(), true);
} }
@Test @Test
public void testSelectionForwardReferencesOnly() { public void testSelectionForwardReferencesOnly() {
String[] start = { "0030", "0050" };
ProgramSelection selection = new ProgramSelection(addr(start[0]), addr(start[1]));
// Selection of address 01005a3c and 01005bff gets expanded within code viewer provider AddressSetView addrs = toAddressSet(program, "0030", "0050");
// to full code unit AddressSet referenceAddrs = getCodeUnitAddrs("0014", "0020");
AddressSet set = new AddressSet();
Listing listing = program.getListing();
CodeUnit cu = listing.getCodeUnitContaining(addr("0014"));
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
cu = listing.getCodeUnitContaining(addr("0020"));
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
CodeViewerProvider provider = cb.getProvider(); CodeViewerProvider provider = cb.getProvider();
provider.setSelection(selection);
performAction(backwardAction, provider.getActionContext(null), true); makeSelection(env.getTool(), program, addrs);
selection = getCurrentSelection(); performAction(backwardAction, provider, true);
ProgramSelection selection = getCurrentSelection();
assertTrue(selection.isEmpty()); assertTrue(selection.isEmpty());
selection = new ProgramSelection(addr(start[0]), addr(start[1])); makeSelection(env.getTool(), program, addrs);
provider.setSelection(selection); performAction(forwardAction, provider, true);
performAction(forwardAction, provider.getActionContext(null), true);
selection = getCurrentSelection(); selection = getCurrentSelection();
assertEquals(new AddressSet(selection), set); assertEquals(new AddressSet(selection), referenceAddrs);
} }
@Test @Test
public void testSelectionBackwardReferencesOnly() { public void testSelectionBackwardReferencesOnly() {
String[] start = { "0000", "0014" };
ProgramSelection selection = new ProgramSelection(addr(start[0]), addr(start[1]));
// Selection of address 01006580, 01006511 and 010065cc gets expanded within code viewer provider AddressSetView addrs = toAddressSet(program, "0000", "0014");
// to full code unit AddressSet referenceAddrs = getCodeUnitAddrs("0020", "0044");
AddressSet set = new AddressSet();
Listing listing = program.getListing();
CodeUnit cu = listing.getCodeUnitContaining(addr("0020"));
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
cu = listing.getCodeUnitContaining(addr("0044"));
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
CodeViewerProvider provider = cb.getProvider(); CodeViewerProvider provider = cb.getProvider();
provider.setSelection(selection);
performAction(forwardAction, provider.getActionContext(null), true); makeSelection(env.getTool(), program, addrs);
selection = getCurrentSelection(); performAction(forwardAction, provider, true);
assertTrue(selection.isEmpty());
selection = new ProgramSelection(addr(start[0]), addr(start[1])); ProgramSelection curentSelection = getCurrentSelection();
provider.setSelection(selection); assertTrue(curentSelection.isEmpty());
performAction(backwardAction, provider.getActionContext(null), true);
selection = getCurrentSelection(); makeSelection(env.getTool(), program, addrs);
assertEquals(new AddressSet(selection), set); performAction(backwardAction, provider, true);
curentSelection = getCurrentSelection();
assertEquals(new AddressSet(curentSelection), referenceAddrs);
}
private AddressSet getCodeUnitAddrs(String... addrs) {
// Selection of addresses gets expanded within code viewer provider to full code unit
AddressSet set = new AddressSet();
Listing listing = program.getListing();
for (String addr : addrs) {
CodeUnit cu = listing.getCodeUnitContaining(addr(addr));
set.addRange(cu.getMinAddress(), cu.getMaxAddress());
}
return set;
} }
private Address addr(String address) { private Address addr(String address) {