Ghidra is a software reverse engineering (SRE) framework
Test fixes
dragonmacherfd44cb530974
diff --git a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/copying/DebuggerCopyActionsPluginScreenShots.java b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/copying/DebuggerCopyActionsPluginScreenShots.javaindex 1dbd7e4283..57e2ffdbe2 100644--- a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/copying/DebuggerCopyActionsPluginScreenShots.java+++ b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/copying/DebuggerCopyActionsPluginScreenShots.java@@ -140,8 +140,8 @@ public class DebuggerCopyActionsPluginScreenShots extends GhidraScreenShotGeneralistingProvider.requestFocus();waitForSwing();- listingProvider.setSelection(- new ProgramSelection(tb.trace.getMemoryManager().getRegionsAddressSet(snap)));+ runSwing(() -> listingProvider.setSelection(+ new ProgramSelection(tb.trace.getMemoryManager().getRegionsAddressSet(snap))));waitForCondition(() -> copyPlugin.actionCopyIntoCurrentProgram.isEnabled());performAction(copyPlugin.actionCopyIntoCurrentProgram, false);diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.javaindex 6cbff18673..1ed5706e5b 100644--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java@@ -282,9 +282,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTescreateAndOpenTrace();TraceThread thread1;TraceThread thread2;- DebuggerListingProvider extraProvider = SwingExecutorService.LATER- .submit(() -> listingPlugin.createListingIfMissing(PCLocationTrackingSpec.INSTANCE,- true))+ DebuggerListingProvider extraProvider = SwingExecutorService.LATER.submit(+ () -> listingPlugin.createListingIfMissing(PCLocationTrackingSpec.INSTANCE, true)).get();try (Transaction tx = tb.startTransaction()) {DBTraceMemoryManager memory = tb.trace.getMemoryManager();@@ -754,9 +753,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTeswaitRecorder(recorder);buf.clear();- assertEquals(data.length,- trace.getMemoryManager()- .getBytes(recorder.getSnap(), addr(trace, 0x55550000), buf));+ assertEquals(data.length, trace.getMemoryManager()+ .getBytes(recorder.getSnap(), addr(trace, 0x55550000), buf));assertArrayEquals(data, buf.array());}));}@@ -803,9 +801,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTesassertEquals(traceManager.getCurrentView(), listingProvider.getProgram());assertEquals("(nowhere)", listingProvider.locationLabel.getText());- DebuggerListingProvider extraProvider =- runSwing(() -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE,- false));+ DebuggerListingProvider extraProvider = runSwing(+ () -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE, false));waitForSwing();assertEquals(traceManager.getCurrentView(), extraProvider.getProgram());assertEquals("(nowhere)", extraProvider.locationLabel.getText());@@ -951,8 +948,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes() -> assertEquals(tb.addr(0x00401234), listingProvider.getLocation().getAddress()));setActionStateWithTrigger(listingProvider.actionTrackLocation,- SPLocationTrackingSpec.INSTANCE,- EventTrigger.GUI_ACTION);+ SPLocationTrackingSpec.INSTANCE, EventTrigger.GUI_ACTION);waitForSwing();waitForPass(() -> assertEquals(tb.addr(0x1fff8765), listingProvider.getLocation().getAddress()));@@ -1077,8 +1073,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTesperformAction(listingProvider.actionSyncSelectionFromStaticListing,codeProvider.getActionContext(null), true);- assertEquals(tb.set(tb.range(0x00401234, 0x00404321)),- listingPlugin.getCurrentSelection());+ assertEquals(tb.set(tb.range(0x00401234, 0x00404321)), listingPlugin.getCurrentSelection());}@Test@@ -1104,9 +1099,8 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTestraceManager.activateThread(thread1);// NOTE: Action does not exist for main dynamic listing- DebuggerListingProvider extraProvider =- runSwing(() -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE,- true));+ DebuggerListingProvider extraProvider = runSwing(+ () -> listingPlugin.createListingIfMissing(NoneLocationTrackingSpec.INSTANCE, true));waitForSwing();assertTrue(extraProvider.actionFollowsCurrentThread.isEnabled());assertTrue(extraProvider.actionFollowsCurrentThread.isSelected());@@ -1150,7 +1144,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes// StillassertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());- listingProvider.setSelection(sel);+ runSwing(() -> listingProvider.setSelection(sel));waitForSwing();// StillassertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());@@ -1172,7 +1166,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes// Action is still disabled, because it requires a selectionassertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());- listingProvider.setSelection(sel);+ runSwing(() -> listingProvider.setSelection(sel));waitForSwing();// Now, it should be enabledassertTrue(listingProvider.actionRefreshSelectedMemory.isEnabled());diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProviderLegacyTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProviderLegacyTest.javaindex 764004e234..2885bd4c8a 100644--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProviderLegacyTest.java+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProviderLegacyTest.java@@ -15,8 +15,7 @@*/package ghidra.app.plugin.core.debug.gui.memory;-import static org.junit.Assert.assertEquals;-import static org.junit.Assert.assertFalse;+import static org.junit.Assert.*;import java.util.*;@@ -384,7 +383,8 @@ public class DebuggerRegionsProviderLegacyTest extends AbstractGhidraHeadedDebugassertEquals(region, row.getRegion());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)),new AddressSet(listing.getSelection())));diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProviderTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProviderTest.javaindex 62e175dca0..4a7dfc152c 100644--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProviderTest.java+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerRegionsProviderTest.java@@ -149,14 +149,14 @@ public class DebuggerRegionsProviderTest extends AbstractGhidraHeadedDebuggerTesassertEquals(size, provider.panel.getAllItems().size());}- protected void assertRow(int position, Object object, String name, Address start,- Address end, long length, String flags) {+ protected void assertRow(int position, Object object, String name, Address start, Address end,+ long length, String flags) {ValueRow row = provider.panel.getAllItems().get(position);var tableModel = QueryPanelTestHelper.getTableModel(provider.panel);GhidraTable table = QueryPanelTestHelper.getTable(provider.panel);- DynamicTableColumn<ValueRow, ?, Trace> nameCol = QueryPanelTestHelper- .getColumnByNameAndType(tableModel, table, "Name", ValueRow.class)- .column();+ DynamicTableColumn<ValueRow, ?, Trace> nameCol =+ QueryPanelTestHelper.getColumnByNameAndType(tableModel, table, "Name", ValueRow.class)+ .column();DynamicTableColumn<ValueRow, ?, Trace> startCol = QueryPanelTestHelper.getColumnByNameAndType(tableModel, table, "Start", ValueProperty.class).column();@@ -474,8 +474,8 @@ public class DebuggerRegionsProviderTest extends AbstractGhidraHeadedDebuggerTeswaitForPass(() -> {assertTableSize(1);- assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000),- tb.addr(0x0040ffff), 0x10000, "rx");+ assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000), tb.addr(0x0040ffff),+ 0x10000, "rx");});waitForPass(() -> assertFalse(tb.trace.getProgramView().getMemory().isEmpty()));@@ -523,12 +523,13 @@ public class DebuggerRegionsProviderTest extends AbstractGhidraHeadedDebuggerTeswaitForPass(() -> {assertTableSize(1);- assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000),- tb.addr(0x0040ffff), 0x10000, "rx");+ assertRow(0, region.getObject(), "bin:.text", tb.addr(0x00400000), tb.addr(0x0040ffff),+ 0x10000, "rx");});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)),new AddressSet(listing.getSelection())));diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/modules/DebuggerStaticMappingProviderTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/modules/DebuggerStaticMappingProviderTest.javaindex 43c36f7d94..36847a9a01 100644--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/modules/DebuggerStaticMappingProviderTest.java+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/modules/DebuggerStaticMappingProviderTest.java@@ -139,7 +139,7 @@ public class DebuggerStaticMappingProviderTest extends AbstractGhidraHeadedDebugProgramSelection traceSel =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);waitForSwing();diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/InteriorSelection.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/InteriorSelection.javaindex 35e16f065c..cd131b7596 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/InteriorSelection.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/InteriorSelection.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -15,13 +14,16 @@* limitations under the License.*/package ghidra.program.util;++import java.util.Objects;+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 {-+private ProgramLocation from;private ProgramLocation to;private Address start;@@ -34,19 +36,21 @@ public class InteriorSelection {* @param start start 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.to = to;this.start = start;this.end = end;- }- /**- * Get the start location.- * @return ProgramLocation- */+ }++ /**+ * Get the start location.+ * @return ProgramLocation+ */public ProgramLocation getFrom() {return from;}+/*** Get the end location.* @return ProgramLocation@@ -54,6 +58,7 @@ public class InteriorSelection {public ProgramLocation getTo() {return to;}+/*** Get the start address of this selection.* @return Address@@ -61,6 +66,7 @@ public class InteriorSelection {public Address getStartAddress() {return start;}+/*** Get the end address of this selection.* @return Address@@ -68,41 +74,38 @@ public class InteriorSelection {public Address getEndAddress() {return end;}+/*** Get the number of bytes contained in the selection.* @return int*/public int getByteLength() {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;+ @Override+ 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);- }+ }- /* (non Javadoc)- * @see java.lang.Object#toString()- */@Override- public String toString() {+ public String toString() {return "From = " + from.getAddress() + ", To = " + to.getAddress();}-}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramSelection.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramSelection.javaindex 0521bb9312..e7a5e76221 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramSelection.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramSelection.java@@ -16,6 +16,7 @@package ghidra.program.util;import java.util.Iterator;+import java.util.Objects;import ghidra.program.model.address.*;@@ -114,9 +115,11 @@ public class ProgramSelection implements AddressSetView {return interiorSelection;}- /**- * Return whether this ProgramSelection is equal to obj.- */+ @Override+ public int hashCode() {+ return Objects.hash(interiorSelection, addressSet);+ }+@Overridepublic boolean equals(Object obj) {if (obj == null) {@@ -135,113 +138,61 @@ public class ProgramSelection implements AddressSetView {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.- */@Overridepublic boolean contains(Address 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.- */@Overridepublic boolean contains(Address start, Address 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.- */@Overridepublic boolean contains(AddressSetView rangeSet) {return addressSet.contains(rangeSet);}- /**- * Determine if this program selection intersects with the specified address set.- *- * @param addrSet address set to check intersection with.- */@Overridepublic boolean intersects(AddressSetView addrSet) {return addressSet != null && addressSet.intersects(addrSet);}- /**- * @see ghidra.program.model.address.AddressSetView#intersect(ghidra.program.model.address.AddressSetView)- */@Overridepublic AddressSet intersect(AddressSetView view) {return addressSet.intersect(view);}- /**- * @see ghidra.program.model.address.AddressSetView#intersectRange(ghidra.program.model.address.Address, ghidra.program.model.address.Address)- */@Overridepublic AddressSet intersectRange(Address start, Address end) {return addressSet.intersectRange(start, end);}- /**- * Returns true if this set is empty.- */@Overridepublic boolean isEmpty() {return addressSet.isEmpty();}- /**- * Return the minimum address for this set.- */@Overridepublic Address getMinAddress() {return addressSet.getMinAddress();}- /**- * Return the maximum address for this set.- */@Overridepublic Address getMaxAddress() {return addressSet.getMaxAddress();}- /**- * Return the number of address ranges in this set.- */@Overridepublic int 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.- */@Overridepublic AddressRangeIterator getAddressRanges(boolean atStart) {return addressSet.getAddressRanges(atStart);}- /**- * Returns an iterator over the address ranges in this address set.- */@Overridepublic AddressRangeIterator getAddressRanges() {return addressSet.getAddressRanges();@@ -252,25 +203,16 @@ public class ProgramSelection implements AddressSetView {return getAddressRanges();}- /**- * Returns the number of addresses in this set.- */@Overridepublic long getNumAddresses() {return addressSet.getNumAddresses();}- /**- * @see ghidra.program.model.address.AddressSetView#getAddresses(boolean)- */@Overridepublic AddressIterator getAddresses(boolean forward) {return addressSet.getAddresses(forward);}- /**- * @see ghidra.program.model.address.AddressSetView#getAddresses(ghidra.program.model.address.Address, boolean)- */@Overridepublic AddressIterator getAddresses(Address start, boolean forward) {return addressSet.getAddresses(start, forward);@@ -290,41 +232,26 @@ public class ProgramSelection implements AddressSetView {return addressSet.hasSameAddresses(asv);}- /**- * @see AddressSetView#intersects(Address, Address)- */@Overridepublic boolean intersects(Address start, Address end) {return addressSet.intersects(start, end);}- /**- * @see ghidra.program.model.address.AddressSetView#union(ghidra.program.model.address.AddressSetView)- */@Overridepublic AddressSet union(AddressSetView view) {return addressSet.union(view);}- /**- * @see ghidra.program.model.address.AddressSetView#xor(ghidra.program.model.address.AddressSetView)- */@Overridepublic AddressSet xor(AddressSetView view) {return addressSet.xor(view);}- /**- * @see ghidra.program.model.address.AddressSetView#subtract(ghidra.program.model.address.AddressSetView)- */@Overridepublic AddressSet subtract(AddressSetView view) {return addressSet.subtract(view);}- /* (non Javadoc)- * @see java.lang.Object#toString()- */@Overridepublic String toString() {if (interiorSelection != null) {@@ -367,5 +294,4 @@ public class ProgramSelection implements AddressSetView {public Address findFirstAddressInCommon(AddressSetView set) {return addressSet.findFirstAddressInCommon(set);}-}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.java b/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.javaindex 1552637708..3b579615d8 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractGhidraHeadlessIntegrationTest.java@@ -431,6 +431,13 @@ public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDockreturn 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) {AddressSet set = new AddressSet();for (Address addr : addrs) {diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/select/reference/SelectRefereceActionsTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/select/reference/SelectRefereceActionsTest.javaindex ab2fc43371..9e918cbe98 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/select/reference/SelectRefereceActionsTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/select/reference/SelectRefereceActionsTest.java@@ -21,8 +21,7 @@*/package ghidra.app.plugin.core.select.reference;-import static org.junit.Assert.assertEquals;-import static org.junit.Assert.assertTrue;+import static org.junit.Assert.*;import org.junit.*;@@ -70,7 +69,6 @@ public class SelectRefereceActionsTest extends AbstractGhidraHeadedIntegrationTeSelectRefsPlugin plugin = env.getPlugin(SelectRefsPlugin.class);forwardAction = (SelectForwardRefsAction) getInstanceField("forwardAction", plugin);backwardAction = (SelectBackRefsAction) getInstanceField("backwardAction", plugin);-}@After@@ -86,24 +84,21 @@ public class SelectRefereceActionsTest extends AbstractGhidraHeadedIntegrationTe@Testpublic void testForwardLocation() {- String start = "0020";-- // Selection of address 01001144 gets expanded within code viewer provider- // to full code unit- CodeUnit cu = program.getListing().getCodeUnitContaining(addr("0010"));+ String start = "0020";ProgramLocation location = new AddressFieldLocation(program, addr(start));cb.goTo(location);- ProgramSelection selection = getCurrentSelection();- assertTrue(selection.isEmpty());- performAction(forwardAction, cb.getProvider().getActionContext(null), true);- selection = getCurrentSelection();- assertEquals(selection.getNumAddresses(), cu.getLength());+ ProgramSelection currentSelection = getCurrentSelection();+ assertTrue(currentSelection.isEmpty());+ performAction(forwardAction, cb.getProvider(), true);+ currentSelection = getCurrentSelection();+ CodeUnit cu = program.getListing().getCodeUnitContaining(addr("0010"));+ assertEquals(currentSelection.getNumAddresses(), cu.getLength());for (Address addr = cu.getMinAddress(); addr.compareTo(cu.getMaxAddress()) <= 0; addr =addr.add(1)) {- assertTrue(selection.contains(addr));+ assertTrue(currentSelection.contains(addr));}}@@ -111,98 +106,88 @@ public class SelectRefereceActionsTest extends AbstractGhidraHeadedIntegrationTepublic void testBackwardLocation() {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));cb.goTo(location);- ProgramSelection selection = getCurrentSelection();- assertTrue(selection.isEmpty());- performAction(backwardAction, cb.getProvider().getActionContext(null), true);- selection = getCurrentSelection();- assertEquals(new AddressSet(selection), set);+ ProgramSelection currentSelection = getCurrentSelection();+ assertTrue(currentSelection.isEmpty());+ performAction(backwardAction, cb.getProvider(), true);++ AddressSet referenceAddrs = getCodeUnitAddrs("0030", "0040");+ currentSelection = getCurrentSelection();+ assertEquals(new AddressSet(currentSelection), referenceAddrs);}@Testpublic void testSelectionWithNoReferences() {- ProgramSelection selection = new ProgramSelection(addr("0050"), addr("0060"));- CodeViewerProvider provider = cb.getProvider();- provider.setSelection(selection);+ AddressSetView addrs = toAddressSet(program, "0050", "0060");- performAction(forwardAction, provider.getActionContext(null), true);+ CodeViewerProvider provider = cb.getProvider();- selection = getCurrentSelection();- assertEquals(selection.isEmpty(), true);+ makeSelection(env.getTool(), program, addrs);+ performAction(forwardAction, provider, true);- selection = new ProgramSelection(addr("010049d0"), addr("010049dd"));- provider.setSelection(selection);+ ProgramSelection currentSelection = getCurrentSelection();+ assertEquals(currentSelection.isEmpty(), true);- performAction(backwardAction, provider.getActionContext(null), true);- selection = getCurrentSelection();- assertEquals(selection.isEmpty(), true);+ currentSelection = new ProgramSelection(addr("010049d0"), addr("010049dd"));+ addrs = toAddressSet(program, "010049d0", "010049dd");+ makeSelection(env.getTool(), program, addrs);+ performAction(backwardAction, provider, true);+ currentSelection = getCurrentSelection();+ assertEquals(currentSelection.isEmpty(), true);}@Testpublic 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- // to full code unit- 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());+ AddressSetView addrs = toAddressSet(program, "0030", "0050");+ AddressSet referenceAddrs = getCodeUnitAddrs("0014", "0020");CodeViewerProvider provider = cb.getProvider();- provider.setSelection(selection);- performAction(backwardAction, provider.getActionContext(null), true);- selection = getCurrentSelection();+ makeSelection(env.getTool(), program, addrs);+ performAction(backwardAction, provider, true);+ ProgramSelection selection = getCurrentSelection();assertTrue(selection.isEmpty());- selection = new ProgramSelection(addr(start[0]), addr(start[1]));- provider.setSelection(selection);- performAction(forwardAction, provider.getActionContext(null), true);+ makeSelection(env.getTool(), program, addrs);+ performAction(forwardAction, provider, true);selection = getCurrentSelection();- assertEquals(new AddressSet(selection), set);+ assertEquals(new AddressSet(selection), referenceAddrs);}@Testpublic 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- // to full code unit- 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());+ AddressSetView addrs = toAddressSet(program, "0000", "0014");+ AddressSet referenceAddrs = getCodeUnitAddrs("0020", "0044");CodeViewerProvider provider = cb.getProvider();- provider.setSelection(selection);- performAction(forwardAction, provider.getActionContext(null), true);- selection = getCurrentSelection();- assertTrue(selection.isEmpty());+ makeSelection(env.getTool(), program, addrs);+ performAction(forwardAction, provider, true);- selection = new ProgramSelection(addr(start[0]), addr(start[1]));- provider.setSelection(selection);- performAction(backwardAction, provider.getActionContext(null), true);- selection = getCurrentSelection();- assertEquals(new AddressSet(selection), set);+ ProgramSelection curentSelection = getCurrentSelection();+ assertTrue(curentSelection.isEmpty());++ makeSelection(env.getTool(), program, addrs);+ 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) {