mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-01 08:15:08 +08:00
GT-2136 - Fixed NPE in program data type manager
This commit is contained in:
+30
-41
@@ -26,30 +26,14 @@ import ghidra.program.database.ProgramBuilder;
|
||||
import ghidra.program.database.ProgramDB;
|
||||
import ghidra.program.model.data.*;
|
||||
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
||||
import ghidra.util.InvalidNameException;
|
||||
import ghidra.util.task.TaskMonitorAdapter;
|
||||
|
||||
/**
|
||||
*
|
||||
* Tests for the DataManager.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
private ProgramDB program;
|
||||
private DataTypeManagerDB dataMgr;
|
||||
private int transactionID;
|
||||
|
||||
/**
|
||||
* Constructor for DataManagerTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public DataManagerTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see TestCase#setUp()
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
program = createDefaultProgram(testName.getMethodName(), ProgramBuilder._TOY, this);
|
||||
@@ -57,9 +41,6 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
startTransaction();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see TestCase#tearDown()
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
endTransaction();
|
||||
@@ -67,14 +48,23 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUniqueName() throws Exception {
|
||||
public void testSetName() throws InvalidNameException {
|
||||
String oldName = dataMgr.getName();
|
||||
String newName = "NewName";
|
||||
dataMgr.setName("NewName");
|
||||
|
||||
assertEquals(newName, dataMgr.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUniqueName() throws Exception {
|
||||
DataType bt = new EnumDataType("test", 2);
|
||||
dataMgr.resolve(bt, null);
|
||||
assertEquals("test_1", dataMgr.getUniqueName(CategoryPath.ROOT, "test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataTypeByID() throws Exception {
|
||||
public void testGetDataTypeByID() throws Exception {
|
||||
Category root = dataMgr.getRootCategory();
|
||||
|
||||
Category sub1 = root.createCategory("SubCat-A");
|
||||
@@ -95,7 +85,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindDataTypes() throws Exception {
|
||||
public void testFindDataTypes() throws Exception {
|
||||
Category root = dataMgr.getRootCategory();
|
||||
|
||||
Category sub1 = root.createCategory("SubCat-A");
|
||||
@@ -147,7 +137,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindDataTypesWildcard() throws Exception {
|
||||
public void testFindDataTypesWildcard() throws Exception {
|
||||
Category root = dataMgr.getRootCategory();
|
||||
|
||||
Category sub1 = root.createCategory("SubCat-A");
|
||||
@@ -180,7 +170,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindDataType() throws Exception {
|
||||
public void testFindDataType() throws Exception {
|
||||
Category root = dataMgr.getRootCategory();
|
||||
Category subc = root.createCategory("subc");
|
||||
subc.createCategory("subc2");
|
||||
@@ -193,7 +183,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateCategoryHierarchy() throws Exception {
|
||||
public void testCreateCategoryHierarchy() throws Exception {
|
||||
String fullName = "/cat1/cat2/cat3/cat4/cat5";
|
||||
CategoryPath cp = new CategoryPath(fullName);
|
||||
dataMgr.createCategory(cp);
|
||||
@@ -211,7 +201,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateArray() throws Exception {
|
||||
public void testCreateArray() throws Exception {
|
||||
ArrayDataType adt = new ArrayDataType(new ByteDataType(), 3, 1);
|
||||
Array array = (Array) dataMgr.addDataType(adt, null);
|
||||
assertNotNull(array);
|
||||
@@ -222,7 +212,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTypedef() throws Exception {
|
||||
public void testCreateTypedef() throws Exception {
|
||||
ArrayDataType adt = new ArrayDataType(new ByteDataType(), 3, 1);
|
||||
Array array = (Array) dataMgr.addDataType(adt, null);
|
||||
TypedefDataType tdt = new TypedefDataType("ArrayTypedef", array);
|
||||
@@ -232,7 +222,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatePointer() throws Exception {
|
||||
public void testCreatePointer() throws Exception {
|
||||
|
||||
ArrayDataType adt = new ArrayDataType(new ByteDataType(), 5, 1);
|
||||
Array array = (Array) dataMgr.addDataType(adt, null);
|
||||
@@ -249,7 +239,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatePointers() throws Exception {
|
||||
public void testCreatePointers() throws Exception {
|
||||
|
||||
Array array = new ArrayDataType(new ByteDataType(), 5, 1);
|
||||
TypeDef td = new TypedefDataType("ByteTypedef", array);
|
||||
@@ -269,7 +259,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveDataType() throws Exception {
|
||||
public void testRemoveDataType() throws Exception {
|
||||
Array array = new ArrayDataType(new ByteDataType(), 5, 1);
|
||||
TypeDef td = new TypedefDataType("ByteTypedef", array);
|
||||
Pointer p = new Pointer32DataType(td);
|
||||
@@ -292,7 +282,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveDataType2() throws Exception {
|
||||
public void testRemoveDataType2() throws Exception {
|
||||
Array array = new ArrayDataType(new ByteDataType(), 5, 1);
|
||||
TypeDef td = new TypedefDataType("ByteTypedef", array);
|
||||
Pointer p = new Pointer32DataType(td);
|
||||
@@ -322,7 +312,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testCreateStructure() {
|
||||
public void testCreateStructure() {
|
||||
StructureDataType sdt = new StructureDataType("test", 0);
|
||||
Structure struct = (Structure) dataMgr.addDataType(sdt, null);
|
||||
assertNotNull(struct);
|
||||
@@ -333,7 +323,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUnion() {
|
||||
public void testCreateUnion() {
|
||||
UnionDataType udt = new UnionDataType("test");
|
||||
Union union = (Union) dataMgr.addDataType(udt, null);
|
||||
assertNotNull(union);
|
||||
@@ -342,7 +332,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFunctionDef() {
|
||||
public void testCreateFunctionDef() {
|
||||
FunctionDefinitionDataType fdt =
|
||||
new FunctionDefinitionDataType(new FunctionDefinitionDataType("test"));
|
||||
FunctionDefinition funcDef = (FunctionDefinition) dataMgr.addDataType(fdt, null);
|
||||
@@ -366,7 +356,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataTypeSizeChanged() {
|
||||
public void testDataTypeSizeChanged() {
|
||||
|
||||
Structure dt = new StructureDataType("MyStruct", 100);
|
||||
dt.insert(0, new ByteDataType());
|
||||
@@ -391,7 +381,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDataType() {
|
||||
public void testResolveDataType() {
|
||||
|
||||
DataTypeManager dtm = new StandAloneDataTypeManager("Test");
|
||||
int id = dtm.startTransaction("");
|
||||
@@ -409,7 +399,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDataType2() throws Exception {
|
||||
public void testResolveDataType2() throws Exception {
|
||||
DataTypeManager dtm = new StandAloneDataTypeManager("Test");
|
||||
int id = dtm.startTransaction("");
|
||||
Category otherRoot = dataMgr.getRootCategory();
|
||||
@@ -424,7 +414,7 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDataType3() throws Exception {
|
||||
public void testResolveDataType3() throws Exception {
|
||||
DataTypeManager dtm = new StandAloneDataTypeManager("Test");
|
||||
int id = dtm.startTransaction("");
|
||||
Category otherRoot = dataMgr.getRootCategory();
|
||||
@@ -443,9 +433,8 @@ public class DataManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
dtm.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoubleReplace() throws Exception {
|
||||
public void testDoubleReplace() throws Exception {
|
||||
Structure struct = new StructureDataType("test", 0);
|
||||
struct.add(new ByteDataType());
|
||||
struct.add(new WordDataType());
|
||||
|
||||
Reference in New Issue
Block a user