Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3222 - review fixes

dragonmacherc2f2a417c9b1
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/datatype/DataTypeUrl.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/datatype/DataTypeUrl.java
index 7fd6621b32..0c46d1af1c 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/datatype/DataTypeUrl.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/datatype/DataTypeUrl.java
@@ -69,29 +69,13 @@ public class DataTypeUrl {
String dtmId = matcher.group(1);
String dtId = matcher.group(2);
+ dataTypeName = matcher.group(3);
- if (dtmId.isBlank()) {
- throw new IllegalArgumentException("Data Type Manager ID cannot be blank");
- }
-
- if (dtId.isBlank()) {
- throw new IllegalArgumentException("Data Type ID cannot be blank");
- }
+ dataTypeManagerId = new UniversalID(Long.parseLong(dtmId));
- try {
- dataTypeManagerId = new UniversalID(Long.parseLong(dtmId));
- }
- catch (NumberFormatException e) {
- throw new IllegalArgumentException("Exception parsing Data Type Manager ID: ", e);
- }
-
- try {
+ if (!dtId.isBlank()) {
dataTypeId = new UniversalID(Long.parseLong(dtId));
}
- catch (NumberFormatException e) {
- throw new IllegalArgumentException("Exception parsing Data Type ID: ", e);
- }
- dataTypeName = matcher.group(3);
}
public UniversalID getDataTypeManagerId() {
@@ -102,6 +86,10 @@ public class DataTypeUrl {
return dataTypeId;
}
+ public String getDataTypeName() {
+ return dataTypeName;
+ }
+
/**
* Uses the given service and its {@link DataTypeManager}s to find the data type
* represented by this url
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeTestUtils.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeTestUtils.java
index 76636a4558..1918c0a86b 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeTestUtils.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/DataTypeTestUtils.java
@@ -53,12 +53,12 @@ public class DataTypeTestUtils {
}
// copies the default test archive into a local version
- static File createArchive(String filename) throws Exception {
+ public static File createArchive(String filename) throws Exception {
return createLocalArchiveFromExistingArchive(filename, "TestArchive.gdt");
}
// copies the archive from the given filename to a local version
- static File copyArchive(String filename) throws Exception {
+ public static File copyArchive(String filename) throws Exception {
return createLocalArchiveFromExistingArchive(filename, filename);
}
@@ -93,8 +93,8 @@ public class DataTypeTestUtils {
return scratchFile;
}
- static ArchiveNode openArchive(String archiveDirPath, String archiveName, boolean checkout,
- DataTypeManagerPlugin plugin) throws Exception {
+ public static ArchiveNode openArchive(String archiveDirPath, String archiveName,
+ boolean checkout, DataTypeManagerPlugin plugin) throws Exception {
File file = new File(archiveDirPath, archiveName);
DataTypeManagerHandler dataTypeManagerHandler = plugin.getDataTypeManagerHandler();
@@ -108,7 +108,7 @@ public class DataTypeTestUtils {
return (ArchiveNode) rootNode.getChild(trimFullArchiveName(archiveName));
}
- static ArchiveNode openArchive(String archiveName, boolean checkout,
+ public static ArchiveNode openArchive(String archiveName, boolean checkout,
DataTypeManagerPlugin plugin) throws Exception {
ArchiveNode openArchive = openArchive(archiveName, checkout, false, plugin);
waitForTree(plugin);
@@ -128,8 +128,8 @@ public class DataTypeTestUtils {
AbstractGenericTest.waitForPostedSwingRunnables();
}
- static ArchiveNode openArchive(String archiveName, boolean checkout, boolean isUserAction,
- DataTypeManagerPlugin plugin) throws Exception {
+ public static ArchiveNode openArchive(String archiveName, boolean checkout,
+ boolean isUserAction, DataTypeManagerPlugin plugin) throws Exception {
File tempDir = getTempDir();
File file = new File(tempDir, archiveName);
@@ -144,7 +144,7 @@ public class DataTypeTestUtils {
return (ArchiveNode) rootNode.getChild(trimFullArchiveName(archiveName));
}
- static void closeArchive(final ArchiveNode archiveNode, final boolean deleteFile)
+ public static void closeArchive(final ArchiveNode archiveNode, final boolean deleteFile)
throws Exception {
Exception exception = Swing.runNow(() -> {
@@ -190,8 +190,8 @@ public class DataTypeTestUtils {
* @return The archive node associated with the open archive
* @throws Exception If there is any problem finding or opening the archive for the given name
*/
- static ArchiveNode checkOutArchive(String archiveName, final DataTypeManagerPlugin plugin)
- throws Exception {
+ public static ArchiveNode checkOutArchive(String archiveName,
+ final DataTypeManagerPlugin plugin) throws Exception {
String archiveNodeName = trimFullArchiveName(archiveName);
GTree tree = plugin.getProvider().getGTree();
@@ -221,14 +221,14 @@ public class DataTypeTestUtils {
return archiveName;
}
- static ArchiveNode createOpenAndCheckoutArchive(String archiveName,
+ public static ArchiveNode createOpenAndCheckoutArchive(String archiveName,
DataTypeManagerPlugin plugin) throws Exception {
createArchive(archiveName);
return openArchive(archiveName, true, plugin);
}
- static ArchiveNode copyOpenAndCheckoutArchive(String archiveName, DataTypeManagerPlugin plugin)
- throws Exception {
+ public static ArchiveNode copyOpenAndCheckoutArchive(String archiveName,
+ DataTypeManagerPlugin plugin) throws Exception {
copyArchive(archiveName);
return openArchive(archiveName, true, plugin);
}
@@ -237,7 +237,8 @@ public class DataTypeTestUtils {
performAction(action, program, tree, true);
}
- static void performAction(DockingActionIf action, Program program, GTree tree, boolean wait) {
+ public static void performAction(DockingActionIf action, Program program, GTree tree,
+ boolean wait) {
AbstractGenericTest.runSwing(() -> {
ActionContext context =
new DataTypesActionContext(null, program, (DataTypeArchiveGTree) tree, null, true);
@@ -265,7 +266,7 @@ public class DataTypeTestUtils {
}
}
- static void createCategory(Category parent, String categoryName) throws Exception {
+ public static void createCategory(Category parent, String categoryName) throws Exception {
DataTypeManager dtm = parent.getDataTypeManager();
int id = dtm.startTransaction("create category");
try {
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/datamgr/util/DataTypeUtilsTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/datamgr/util/DataTypeUtilsTest.java
index 21324ebbf1..d0dd5a1340 100644
--- a/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/datamgr/util/DataTypeUtilsTest.java
+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/plugin/core/datamgr/util/DataTypeUtilsTest.java
@@ -15,23 +15,24 @@
*/
package ghidra.app.plugin.core.datamgr.util;
-import java.net.URL;
import java.util.*;
+import org.junit.Before;
import org.junit.Test;
-import generic.test.AbstractGenericTest;
-import ghidra.app.plugin.core.datamgr.archive.SourceArchive;
-import ghidra.docking.settings.Settings;
-import ghidra.docking.settings.SettingsDefinition;
-import ghidra.program.model.data.*;
+import generic.test.AbstractGTest;
+import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeComparator;
-import ghidra.program.model.mem.MemBuffer;
-import ghidra.util.*;
-import ghidra.util.exception.DuplicateNameException;
+import ghidra.program.model.data.TestDoubleDataType;
+import ghidra.util.UniversalIdGenerator;
public class DataTypeUtilsTest {
+ @Before
+ public void setUp() {
+ UniversalIdGenerator.initialize();
+ }
+
@Test
public void testDataSearch() throws Exception {
@@ -43,7 +44,7 @@ public class DataTypeUtilsTest {
final List<DataType> data = new ArrayList<>();
for (String element : TEST_DATA) {
- data.add(new DataTypeDummy(element));
+ data.add(new FakeDataType(element));
}
// sort them how our data will be sorted
@@ -110,266 +111,18 @@ public class DataTypeUtilsTest {
List<DataType> actualMatches =
DataTypeUtils.getMatchingSubList(text, text + endChar, sourceData);
- AbstractGenericTest.assertListEqualUnordered(null, expectedMatches, actualMatches);
+ AbstractGTest.assertListEqualUnordered(null, expectedMatches, actualMatches);
}
- private class DataTypeDummy implements DataType {
-
- String wrappedString;
- UniversalID id;
-
- DataTypeDummy(String wrappedString) {
- this.wrappedString = wrappedString;
- id = UniversalIdGenerator.nextID();
- }
-
- @Override
- public String toString() {
- return wrappedString;
- }
+ private class FakeDataType extends TestDoubleDataType {
- @Override
- public DataTypeManager getDataTypeManager() {
- return null;
- }
-
- @Override
- public DataOrganization getDataOrganization() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String getDisplayName() {
- return "This is a wrapper for: " + wrappedString;
- }
-
- @Override
- public String getName() {
- return wrappedString;
- }
-
- @Override
- public boolean isNotYetDefined() {
- return false;
- }
-
- @Override
- public boolean isDynamicallySized() {
- return false;
+ FakeDataType(String name) {
+ super(name);
}
@Override
public String getPathName() {
- return "/" + wrappedString;
- }
-
- @Override
- public SettingsDefinition[] getSettingsDefinitions() {
- return null;
- }
-
- @Override
- public Settings getDefaultSettings() {
- return null;
- }
-
- @Override
- public CategoryPath getCategoryPath() {
- return null;
- }
-
- @Override
- public DataTypePath getDataTypePath() {
- return null;
- }
-
- @Override
- public void setCategoryPath(CategoryPath path) throws DuplicateNameException {
- // no-op
- }
-
- @Override
- public void setName(String name) throws InvalidNameException, DuplicateNameException {
- // no-op
- }
-
- @Override
- public void setNameAndCategory(CategoryPath path, String name)
- throws InvalidNameException, DuplicateNameException {
- // no-op
- }
-
- @Override
- public String getMnemonic(Settings settings) {
- return null;
- }
-
- @Override
- public int getLength() {
- return 0;
- }
-
- @Override
- public String getDescription() {
- return null;
- }
-
- @Override
- public void setDescription(String description) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- getClass().getName() + " doesn't allow the description to be changed.");
- }
-
- @Override
- public URL getDocs() {
- return null;
- }
-
- @Override
- public Object getValue(MemBuffer buf, Settings settings, int length) {
- return null;
- }
-
- @Override
- public Class<?> getValueClass(Settings settings) {
- return null;
- }
-
- @Override
- public String getRepresentation(MemBuffer buf, Settings settings, int length) {
- return null;
- }
-
- @Override
- public boolean isDeleted() {
- return false;
- }
-
- @Override
- public boolean isEquivalent(DataType dt) {
- return false;
- }
-
- @Override
- public void dataTypeSizeChanged(DataType dt) {
- // no-op
- }
-
- @Override
- public void dataTypeDeleted(DataType dt) {
- // no-op
- }
-
- @Override
- public void dataTypeReplaced(DataType oldDt, DataType newDt) {
- // no-op
- }
-
- @Override
- public void setDefaultSettings(Settings settings) {
- // no-op
- }
-
- @Override
- public void addParent(DataType dt) {
- // no-op
- }
-
- @Override
- public void removeParent(DataType dt) {
- // no-op
- }
-
- @Override
- public void dataTypeNameChanged(DataType dt, String oldName) {
- // no-op
- }
-
- @Override
- public DataType[] getParents() {
- return null;
- }
-
- @Override
- public boolean dependsOn(DataType dt) {
- return false;
- }
-
- @Override
- public String getDefaultLabelPrefix() {
- return null;
- }
-
- @Override
- public String getDefaultAbbreviatedLabelPrefix() {
- return null;
- }
-
- @Override
- public String getDefaultLabelPrefix(MemBuffer buf, Settings settings, int len,
- DataTypeDisplayOptions options) {
- return null;
- }
-
- @Override
- public String getDefaultOffcutLabelPrefix(MemBuffer buf, Settings settings, int len,
- DataTypeDisplayOptions options, int offcutLength) {
- return null;
- }
-
- @Override
- public long getLastChangeTimeInSourceArchive() {
- return DataType.NO_SOURCE_SYNC_TIME;
- }
-
- @Override
- public long getLastChangeTime() {
- return DataType.NO_LAST_CHANGE_TIME;
- }
-
- @Override
- public SourceArchive getSourceArchive() {
- return null;
- }
-
- @Override
- public UniversalID getUniversalID() {
- return id;
- }
-
- @Override
- public void replaceWith(DataType dataType) {
- // no-op
- }
-
- @Override
- public void setLastChangeTime(long lastChangeTime) {
- // no-op
- }
-
- @Override
- public void setLastChangeTimeInSourceArchive(long lastChangeTimeInSourceArchive) {
- // no-op
- }
-
- @Override
- public void setSourceArchive(SourceArchive archive) {
- // no-op
- }
-
- @Override
- public DataType clone(DataTypeManager dtm) {
- return this;
- }
-
- @Override
- public DataType copy(DataTypeManager dtm) {
- return this;
- }
-
- @Override
- public int getAlignment() {
- return 1;
+ return "/" + getName();
}
}
}
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/services/TestDoubleDataTypeManagerService.java b/Ghidra/Features/Base/src/test/java/ghidra/app/services/TestDoubleDataTypeManagerService.java
new file mode 100644
index 0000000000..a906497d48
--- /dev/null
+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/services/TestDoubleDataTypeManagerService.java
@@ -0,0 +1,133 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.services;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+import javax.swing.tree.TreePath;
+
+import ghidra.app.plugin.core.datamgr.archive.Archive;
+import ghidra.app.plugin.core.datamgr.archive.DuplicateIdException;
+import ghidra.program.model.data.*;
+import ghidra.program.model.listing.DataTypeArchive;
+import ghidra.util.HelpLocation;
+
+/**
+ * A stub of the {@link DataTypeManagerService} interface. This can be used to supply a test values
+ * or to spy on system internals by overriding methods as needed.
+ */
+public class TestDoubleDataTypeManagerService implements DataTypeManagerService {
+
+ @Override
+ public DataTypeManager[] getDataTypeManagers() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<DataType> getSortedDataTypeList() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType getDataType(String filterText) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataTypeManager getBuiltInDataTypesManager() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<DataType> getFavorites() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addDataTypeManagerChangeListener(DataTypeManagerChangeListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeDataTypeManagerChangeListener(DataTypeManagerChangeListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setRecentlyUsed(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType getRecentlyUsed() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public HelpLocation getEditorHelpLocation(DataType dataType) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isEditable(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void edit(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void closeArchive(DataTypeManager dtm) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataTypeManager openDataTypeArchive(String archiveName)
+ throws IOException, DuplicateIdException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Archive openArchive(DataTypeArchive dataTypeArchive) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Archive openArchive(File file, boolean acquireWriteLock)
+ throws IOException, DuplicateIdException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setDataTypeSelected(DataType dataType) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType getDataType(TreePath selectedPath) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Set<String> getPossibleEquateNames(long value) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/util/datatype/DataTypeUrlTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/util/datatype/DataTypeUrlTest.java
new file mode 100644
index 0000000000..b36b2b4e30
--- /dev/null
+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/util/datatype/DataTypeUrlTest.java
@@ -0,0 +1,279 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.util.datatype;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import ghidra.app.services.DataTypeManagerService;
+import ghidra.app.services.TestDoubleDataTypeManagerService;
+import ghidra.program.model.data.*;
+import ghidra.util.UniversalID;
+import ghidra.util.UniversalIdGenerator;
+
+public class DataTypeUrlTest {
+
+ @Before
+ public void setUp() {
+ UniversalIdGenerator.initialize();
+ }
+
+ @Test
+ public void testConstructor_FromDataType() throws Exception {
+
+ String name = "string";
+ FakeDataType dt = new FakeDataType(name);
+ DataTypeUrl dtUrl = new DataTypeUrl(dt);
+
+ assertNotNull(dtUrl.getDataTypeManagerId());
+ assertNotNull(dtUrl.getDataTypeId());
+ assertEquals(name, dtUrl.getDataTypeName());
+ }
+
+ @Test
+ public void testConstructor_FromUrlString_AllDataIncluded() throws Exception {
+
+ String dtmId = "3295333330922457057";
+ String dtId = "3295333330922457056";
+ String name = "string";
+ String urlString = "datatype:/" + dtmId + "?uid=" + dtId + "&name=" + name;
+
+ DataTypeUrl dtUrl = new DataTypeUrl(urlString);
+ assertNotNull(dtUrl.getDataTypeManagerId());
+ assertNotNull(dtUrl.getDataTypeId());
+ assertEquals(name, dtUrl.getDataTypeName());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructor_FromUrlString_AllDataIncluded_BadDataTypeManagerId()
+ throws Exception {
+
+ String dtmId = "123bad_id123";
+ String dtId = "3295333330922457056";
+ String name = "string";
+ String urlString = "datatype:/" + dtmId + "?uid=" + dtId + "&name=" + name;
+
+ new DataTypeUrl(urlString);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructor_FromUrlString_AllDataIncluded_BadDataTypeId() throws Exception {
+
+ String dtmId = "3295333330922457057";
+ String dtId = "bad_id";
+ String name = "string";
+ String urlString = "datatype:/" + dtmId + "?uid=" + dtId + "&name=" + name;
+
+ new DataTypeUrl(urlString);
+ }
+
+ @Test
+ public void testConstructor_FromUrlString_NoDataTypeId() throws Exception {
+
+ String dtmId = "3295333330922457057";
+ String dtId = "";
+ String name = "string";
+ String urlString = "datatype:/" + dtmId + "?uid=" + dtId + "&name=" + name;
+
+ DataTypeUrl dtUrl = new DataTypeUrl(urlString);
+ assertNotNull(dtUrl.getDataTypeManagerId());
+ assertNull(dtUrl.getDataTypeId());
+ assertEquals(name, dtUrl.getDataTypeName());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructor_FromUrlString_NoDataTypeManagerId() throws Exception {
+
+ String dtmId = "";
+ String dtId = "3295333330922457056";
+ String name = "string";
+ String urlString = "datatype:/" + dtmId + "?uid=" + dtId + "&name=" + name;
+
+ new DataTypeUrl(urlString);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructor_FromUrlString_NoDataTypeName() throws Exception {
+
+ String dtmId = "3295333330922457057";
+ String dtId = "3295333330922457056";
+ String name = " ";
+ String urlString = "datatype:/" + dtmId + "?uid=" + dtId + "&name=" + name;
+
+ new DataTypeUrl(urlString);
+ }
+
+ @Test
+ public void testGetDataType() {
+
+ String name = "string";
+ String dtmId = "3295333330922457057";
+ FakeDataTypeManager manager = new FakeDataTypeManager(dtmId);
+ FakeDataType dt = new FakeDataType(name, manager);
+
+ DataTypeUrl dtUrl = new DataTypeUrl(dt);
+
+ DataTypeManagerService service = new FakeDataTypeManagerService(manager);
+ DataType actualDt = dtUrl.getDataType(service);
+ assertEquals(dt, actualDt);
+ }
+
+ @Test
+ public void testGetDataType_ByName() {
+
+ String name = "string";
+ String dtmId = "3295333330922457057";
+ FakeDataTypeManager manager = new FakeDataTypeManager(dtmId);
+ FakeDataType dt = new FakeDataType(name, manager);
+
+ String dtId = ""; // no id; name only
+ String urlString = "datatype:/" + dtmId + "?uid=" + dtId + "&name=" + name;
+ DataTypeUrl dtUrl = new DataTypeUrl(urlString);
+
+ DataTypeManagerService service = new FakeDataTypeManagerService(manager);
+ DataType actualDt = dtUrl.getDataType(service);
+ assertEquals(dt, actualDt);
+ }
+
+ @Test
+ public void testEquals() {
+
+ String name = "string";
+ FakeDataType dt = new FakeDataType(name);
+
+ DataTypeUrl dtUrl1 = new DataTypeUrl(dt);
+ DataTypeUrl dtUrl2 = new DataTypeUrl(dt);
+ assertEquals(dtUrl1, dtUrl2);
+
+ FakeDataType otherDt = new FakeDataType("otherType");
+ DataTypeUrl otherDtUrl = new DataTypeUrl(otherDt);
+ assertNotEquals(dtUrl1, otherDtUrl);
+ }
+
+ @Test
+ public void testHashCode() {
+
+ String name = "string";
+ FakeDataType dt = new FakeDataType(name);
+
+ DataTypeUrl dtUrl1 = new DataTypeUrl(dt);
+ DataTypeUrl dtUrl2 = new DataTypeUrl(dt);
+ assertEquals(dtUrl1.hashCode(), dtUrl2.hashCode());
+
+ FakeDataType otherDt = new FakeDataType("otherType");
+ DataTypeUrl otherDtUrl = new DataTypeUrl(otherDt);
+ assertNotEquals(dtUrl1.hashCode(), otherDtUrl.hashCode());
+ }
+
+ @Test
+ public void testToString() {
+
+ String dtmId = "3295333330922457057";
+ String dtId = "3295333330922457056";
+ String name = "string";
+ String urlString = "datatype:/" + dtmId + "?uid=" + dtId + "&name=" + name;
+
+ DataTypeUrl dtUrl = new DataTypeUrl(urlString);
+ assertEquals(urlString, dtUrl.toString());
+ }
+
+//==================================================================================================
+// Inner Classes
+//==================================================================================================
+
+ private class FakeDataType extends TestDoubleDataType {
+
+ private DataTypeManager manager = new FakeDataTypeManager();
+
+ FakeDataType(String name) {
+ super(name);
+ }
+
+ FakeDataType(String name, FakeDataTypeManager manager) {
+ super(name);
+ this.manager = manager;
+ manager.addDataType(this);
+ }
+
+ @Override
+ public DataTypeManager getDataTypeManager() {
+ return manager;
+ }
+ }
+
+ private class FakeDataTypeManager extends TestDoubleDataTypeManager {
+
+ private UniversalID id;
+ private List<DataType> types = new ArrayList<>();
+
+ FakeDataTypeManager() {
+ id = UniversalIdGenerator.nextID();
+ }
+
+ FakeDataTypeManager(String idString) {
+ id = new UniversalID(Long.parseLong(idString));
+ }
+
+ void addDataType(DataType dt) {
+ types.add(dt);
+ }
+
+ @Override
+ public UniversalID getUniversalID() {
+ return id;
+ }
+
+ @Override
+ public DataType getDataType(DataTypePath path) {
+ for (DataType dt : types) {
+ if (dt.getName().equals(path.getDataTypeName())) {
+ return dt;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public DataType findDataTypeForID(UniversalID datatypeID) {
+ for (DataType dt : types) {
+ if (dt.getUniversalID().equals(datatypeID)) {
+ return dt;
+ }
+ }
+ return null;
+ }
+ }
+
+ private class FakeDataTypeManagerService extends TestDoubleDataTypeManagerService {
+
+ private DataTypeManager manager;
+
+ FakeDataTypeManagerService(DataTypeManager manager) {
+ this.manager = manager;
+ }
+
+ @Override
+ public DataTypeManager[] getDataTypeManagers() {
+ return new DataTypeManager[] { manager };
+ }
+ }
+
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/data/TestDoubleDataType.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/data/TestDoubleDataType.java
new file mode 100644
index 0000000000..837b451152
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/data/TestDoubleDataType.java
@@ -0,0 +1,288 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+import java.net.URL;
+
+import ghidra.app.plugin.core.datamgr.archive.SourceArchive;
+import ghidra.docking.settings.Settings;
+import ghidra.docking.settings.SettingsDefinition;
+import ghidra.program.model.mem.MemBuffer;
+import ghidra.util.*;
+import ghidra.util.exception.DuplicateNameException;
+
+/**
+ * A stub of the {@link DataType} interface. This can be used to supply a test values
+ * or to spy on system internals by overriding methods as needed.
+ */
+public class TestDoubleDataType implements DataType {
+
+ private UniversalID id;
+ private String name;
+
+ public TestDoubleDataType(String name) {
+ this.name = name;
+ this.id = UniversalIdGenerator.nextID();
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ @Override
+ public boolean isDynamicallySized() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isNotYetDefined() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SettingsDefinition[] getSettingsDefinitions() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Settings getDefaultSettings() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType clone(DataTypeManager dtm) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType copy(DataTypeManager dtm) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public CategoryPath getCategoryPath() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataTypePath getDataTypePath() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setCategoryPath(CategoryPath path) throws DuplicateNameException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataTypeManager getDataTypeManager() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "Test double data type '" + getName() + "'";
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getPathName() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setName(String name) throws InvalidNameException, DuplicateNameException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setNameAndCategory(CategoryPath path, String name)
+ throws InvalidNameException, DuplicateNameException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getMnemonic(Settings settings) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getLength() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getDescription() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setDescription(String description) throws UnsupportedOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public URL getDocs() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object getValue(MemBuffer buf, Settings settings, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Class<?> getValueClass(Settings settings) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getDefaultLabelPrefix() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getDefaultAbbreviatedLabelPrefix() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getDefaultLabelPrefix(MemBuffer buf, Settings settings, int len,
+ DataTypeDisplayOptions options) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getDefaultOffcutLabelPrefix(MemBuffer buf, Settings settings, int len,
+ DataTypeDisplayOptions options, int offcutOffset) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getRepresentation(MemBuffer buf, Settings settings, int length) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isDeleted() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isEquivalent(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void dataTypeSizeChanged(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void dataTypeDeleted(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void dataTypeReplaced(DataType oldDt, DataType newDt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setDefaultSettings(Settings settings) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addParent(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeParent(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void dataTypeNameChanged(DataType dt, String oldName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType[] getParents() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getAlignment() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean dependsOn(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SourceArchive getSourceArchive() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setSourceArchive(SourceArchive archive) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getLastChangeTime() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getLastChangeTimeInSourceArchive() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public UniversalID getUniversalID() {
+ return id;
+ }
+
+ @Override
+ public void replaceWith(DataType dataType) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setLastChangeTime(long lastChangeTime) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setLastChangeTimeInSourceArchive(long lastChangeTimeInSourceArchive) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataOrganization getDataOrganization() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/data/TestDoubleDataTypeManager.java b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/data/TestDoubleDataTypeManager.java
new file mode 100644
index 0000000000..e19b915383
--- /dev/null
+++ b/Ghidra/Framework/SoftwareModeling/src/test/java/ghidra/program/model/data/TestDoubleDataTypeManager.java
@@ -0,0 +1,342 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.program.model.data;
+
+import java.util.*;
+
+import ghidra.app.plugin.core.datamgr.archive.SourceArchive;
+import ghidra.util.*;
+import ghidra.util.task.TaskMonitor;
+
+/**
+ * A stub of the {@link DataTypeManager} interface. This can be used to supply a test values
+ * or to spy on system internals by overriding methods as needed.
+ */
+public class TestDoubleDataTypeManager implements DataTypeManager {
+
+ private UniversalID id;
+
+ public TestDoubleDataTypeManager() {
+ this.id = UniversalIdGenerator.nextID();
+ }
+
+ @Override
+ public UniversalID getUniversalID() {
+ return id;
+ }
+
+ @Override
+ public boolean containsCategory(CategoryPath path) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getUniqueName(CategoryPath path, String baseName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType resolve(DataType dataType, DataTypeConflictHandler handler) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType addDataType(DataType dataType, DataTypeConflictHandler handler) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Iterator<DataType> getAllDataTypes() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void getAllDataTypes(List<DataType> list) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Iterator<Structure> getAllStructures() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Iterator<Composite> getAllComposites() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void findDataTypes(String name, List<DataType> list) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void findDataTypes(String name, List<DataType> list, boolean caseSensitive,
+ TaskMonitor monitor) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType replaceDataType(DataType existingDt, DataType replacementDt,
+ boolean updateCategoryPath) throws DataTypeDependencyException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType getDataType(String dataTypePath) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType findDataType(String dataTypePath) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType getDataType(DataTypePath dataTypePath) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getResolvedID(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getID(DataType dt) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType getDataType(long dataTypeID) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Category getCategory(long categoryID) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Category getCategory(CategoryPath path) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void dataTypeChanged(DataType dataType) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addDataTypeManagerListener(DataTypeManagerChangeListener l) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeDataTypeManagerListener(DataTypeManagerChangeListener l) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addInvalidatedListener(InvalidatedListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeInvalidatedListener(InvalidatedListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean remove(DataType dataType, TaskMonitor monitor) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean contains(DataType dataType) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Category createCategory(CategoryPath path) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType getDataType(CategoryPath path, String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getName() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setName(String name) throws InvalidNameException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int startTransaction(String description) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isUpdatable() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void endTransaction(int transactionID, boolean commit) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void flushEvents() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void close() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Pointer getPointer(DataType datatype) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Pointer getPointer(DataType datatype, int size) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Category getRootCategory() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isFavorite(DataType datatype) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setFavorite(DataType datatype, boolean isFavorite) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<DataType> getFavorites() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getCategoryCount() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getDataTypeCount(boolean includePointersAndArrays) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void findEnumValueNames(long value, Set<String> enumValueNames) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType getDataType(SourceArchive sourceArchive, UniversalID datatypeID) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataType findDataTypeForID(UniversalID datatypeID) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getLastChangeTimeForMyManager() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SourceArchive getSourceArchive(UniversalID sourceID) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ArchiveType getType() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<DataType> getDataTypes(SourceArchive sourceArchive) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SourceArchive getLocalSourceArchive() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void associateDataTypeWithArchive(DataType datatype, SourceArchive archive) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void disassociate(DataType datatype) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean updateSourceArchiveName(String archiveFileID, String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean updateSourceArchiveName(UniversalID sourceID, String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataOrganization getDataOrganization() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<SourceArchive> getSourceArchives() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeSourceArchive(SourceArchive sourceArchive) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SourceArchive resolveSourceArchive(SourceArchive sourceArchive) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Set<DataType> getDataTypesContaining(DataType dataType) {
+ throw new UnsupportedOperationException();
+ }
+}