Skip to content

Commit 2b2eafc

Browse files
committed
Merge remote-tracking branch 'origin/GP-0-dragonmacher-test-fixes-8-15-23'
2 parents 71a9df1 + c35a598 commit 2b2eafc

File tree

2 files changed

+157
-145
lines changed

2 files changed

+157
-145
lines changed

Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/datamgr/editor/EnumEditor1Test.java

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ public void setUp() throws Exception {
6969

7070
@After
7171
public void tearDown() throws Exception {
72-
env.release(program);
7372
env.dispose();
7473
}
7574

7675
@Test
7776
public void testEnumFields() throws Exception {
7877
Category c = program.getListing()
79-
.getDataTypeManager()
80-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
78+
.getDataTypeManager()
79+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
8180
Enum enumm = createEnum(c, "TestEnum", 1);
8281
edit(enumm);
8382

@@ -100,7 +99,7 @@ public void testEnumFields() throws Exception {
10099
JTextField catField = getTextField(panel, "Category");
101100
assertNotNull(catField);
102101
assertEquals("notepad/Category1", catField.getText());
103-
assertTrue(!catField.isEditable());
102+
assertFalse(catField.isEditable());
104103

105104
// size should be "1"
106105
@SuppressWarnings("unchecked")
@@ -114,12 +113,12 @@ public void testEnumFields() throws Exception {
114113
// add action should be enabled
115114
// apply action should be disabled
116115
// delete action should be disabled
117-
DockingActionIf addAction = getAction(plugin, "Add Enum Value");
116+
DockingActionIf addAction = getAddAction();
118117
assertTrue(addAction.isEnabled());
119-
DockingActionIf applyAction = getAction(plugin, "Apply Enum Changes");
120-
assertTrue(!applyAction.isEnabled());
121-
DockingActionIf deleteAction = getAction(plugin, "Delete Enum Value");
122-
assertTrue(!deleteAction.isEnabled());
118+
DockingActionIf applyAction = getApplyAction();
119+
assertFalse(applyAction.isEnabled());
120+
DockingActionIf deleteAction = getDeleteAction();
121+
assertFalse(deleteAction.isEnabled());
123122

124123
// sort column should be on the value column
125124
JTable table = (JTable) findContainer(panel, JTable.class);
@@ -130,8 +129,8 @@ public void testEnumFields() throws Exception {
130129
@Test
131130
public void testEnumSize1() throws Exception {
132131
Category category = program.getListing()
133-
.getDataTypeManager()
134-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
132+
.getDataTypeManager()
133+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
135134
Enum enumm = createEnum(category, "TestEnum", 1);
136135
edit(enumm);
137136

@@ -141,7 +140,7 @@ public void testEnumSize1() throws Exception {
141140
addEnumValue();
142141

143142
waitForSwing();
144-
DockingActionIf applyAction = getAction(plugin, "Apply Enum Changes");
143+
DockingActionIf applyAction = getApplyAction();
145144
assertTrue(applyAction.isEnabled());
146145
assertTrue(panel.needsSave());
147146

@@ -181,8 +180,8 @@ public void testEnumSize1() throws Exception {
181180
public void testEnumSize1BadInput() throws Exception {
182181
// test entering too large a value
183182
Category category = program.getListing()
184-
.getDataTypeManager()
185-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
183+
.getDataTypeManager()
184+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
186185
Enum enumm = createEnum(category, "TestEnum", 1);
187186
edit(enumm);
188187

@@ -192,7 +191,7 @@ public void testEnumSize1BadInput() throws Exception {
192191
addEnumValue();
193192

194193
waitForSwing();
195-
DockingActionIf applyAction = getAction(plugin, "Apply Enum Changes");
194+
DockingActionIf applyAction = getApplyAction();
196195
assertTrue(applyAction.isEnabled());
197196
assertTrue(panel.needsSave());
198197

@@ -224,8 +223,8 @@ public void testEnumSize1BadInput() throws Exception {
224223
@Test
225224
public void testEnumSize4BadInput() throws Exception {
226225
Category category = program.getListing()
227-
.getDataTypeManager()
228-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
226+
.getDataTypeManager()
227+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
229228
Enum enumm = createEnum(category, "MyTestEnum", 4);
230229
edit(enumm);
231230

@@ -243,12 +242,12 @@ public void testEnumSize4BadInput() throws Exception {
243242

244243
addEnumValue();
245244
waitForSwing();
246-
DockingActionIf applyAction = getAction(plugin, "Apply Enum Changes");
245+
DockingActionIf applyAction = getApplyAction();
247246
assertTrue(applyAction.isEnabled());
248247
assertTrue(panel.needsSave());
249248

250-
final JTable table = panel.getTable();
251-
final EnumTableModel model = (EnumTableModel) table.getModel();
249+
JTable table = panel.getTable();
250+
EnumTableModel model = (EnumTableModel) table.getModel();
252251

253252
assertEquals("New_Name", model.getValueAt(0, NAME_COL));
254253
assertEquals(0L, model.getValueAt(0, VALUE_COL));
@@ -275,14 +274,14 @@ public void testEnumSize4BadInput() throws Exception {
275274
@Test
276275
public void testBadInputForValue() throws Exception {
277276
Category cat = program.getListing()
278-
.getDataTypeManager()
279-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
277+
.getDataTypeManager()
278+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
280279
Enum enumm = createEnum(cat, "TestEnum", 1);
281280
edit(enumm);
282281

283282
EnumEditorPanel panel = findEditorPanel(tool.getToolFrame());
284-
final JTable table = panel.getTable();
285-
final EnumTableModel model = (EnumTableModel) table.getModel();
283+
JTable table = panel.getTable();
284+
EnumTableModel model = (EnumTableModel) table.getModel();
286285

287286
addEnumValue();
288287
waitForSwing();
@@ -304,8 +303,8 @@ public void testBadInputForValue() throws Exception {
304303
public void testEditExistingEnum1() throws Exception {
305304

306305
Category cat = program.getListing()
307-
.getDataTypeManager()
308-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
306+
.getDataTypeManager()
307+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
309308
final Enum enumm = new EnumDataType("Colors", 1);
310309
enumm.add("Red", 0);
311310
enumm.add("Green", 1);
@@ -368,8 +367,8 @@ public void testEditExistingEnum2() throws Exception {
368367
@Test
369368
public void testValueForNewEntry() throws Exception {
370369
Category cat = program.getListing()
371-
.getDataTypeManager()
372-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
370+
.getDataTypeManager()
371+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
373372
final Enum enumm = new EnumDataType("Colors", 1);
374373
enumm.add("Red", 0x10);
375374
enumm.add("Green", 0x20);
@@ -389,7 +388,7 @@ public void testValueForNewEntry() throws Exception {
389388
runSwing(() -> {
390389
int lastRow = model.getRowCount() - 1;
391390
table.addRowSelectionInterval(lastRow, lastRow);
392-
DockingActionIf addAction = getAction(plugin, "Add Enum Value");
391+
DockingActionIf addAction = getAddAction();
393392
addAction.actionPerformed(new DefaultActionContext());
394393
});
395394
waitForSwing();
@@ -762,12 +761,11 @@ public void testNewEnumFromAction() throws Exception {
762761
public void testChangeEnumSizeAndInStructure() throws Exception {
763762

764763
Category category = program.getListing()
765-
.getDataTypeManager()
766-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
764+
.getDataTypeManager()
765+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
767766
Enum enumm = createEnum(category, "EnumX", 2);
768767

769-
int transactionID = program.startTransaction("Test");
770-
try {
768+
tx(program, () -> {
771769
enumm.add("Zero", 0);
772770
enumm.add("One", 1);
773771

@@ -783,10 +781,7 @@ public void testChangeEnumSizeAndInStructure() throws Exception {
783781
structY.add(new ByteDataType());
784782
structY.add(enumm);
785783
category.addDataType(structY, DataTypeConflictHandler.DEFAULT_HANDLER);
786-
}
787-
finally {
788-
program.endTransaction(transactionID, true);
789-
}
784+
});
790785

791786
edit(enumm);
792787

@@ -832,12 +827,11 @@ public void testChangeEnumSizeAndInStructure() throws Exception {
832827
public void testChangeEnumDescriptionEtcAndInStructure() throws Exception {
833828

834829
Category category = program.getListing()
835-
.getDataTypeManager()
836-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
830+
.getDataTypeManager()
831+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
837832
Enum enumm = createEnum(category, "EnumX", 2);
838833

839-
int transactionID = program.startTransaction("Test");
840-
try {
834+
tx(program, () -> {
841835
enumm.add("Zero", 0);
842836
enumm.add("One", 1);
843837
enumm.setDescription("ABCD");
@@ -854,10 +848,7 @@ public void testChangeEnumDescriptionEtcAndInStructure() throws Exception {
854848
structY.add(new ByteDataType());
855849
structY.add(enumm);
856850
category.addDataType(structY, DataTypeConflictHandler.DEFAULT_HANDLER);
857-
}
858-
finally {
859-
program.endTransaction(transactionID, true);
860-
}
851+
});
861852

862853
edit(enumm);
863854

@@ -1140,8 +1131,8 @@ private Pair<Integer, Integer> getEditingCell(final JTable table) {
11401131

11411132
private Enum createRedGreenBlueEnum() {
11421133
Category cat = program.getListing()
1143-
.getDataTypeManager()
1144-
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
1134+
.getDataTypeManager()
1135+
.getCategory(new CategoryPath(CategoryPath.ROOT, "Category1"));
11451136
final Enum enumm = new EnumDataType("Colors", 1);
11461137
enumm.add("Red", 0);
11471138
enumm.add("Green", 1);
@@ -1165,7 +1156,7 @@ private void edit(final Enum enummDt) {
11651156

11661157
private void apply() {
11671158
runSwing(() -> {
1168-
DockingActionIf applyAction = getAction(plugin, "Apply Enum Changes");
1159+
DockingActionIf applyAction = getApplyAction();
11691160
applyAction.actionPerformed(new DefaultActionContext());
11701161
}, false);
11711162
program.flushEvents();
@@ -1290,12 +1281,10 @@ private void doTestFieldChangedWithWarning(boolean alsoRemove) throws Exception
12901281
}
12911282

12921283
private void editValueInTable(int row, String newValue) {
1293-
12941284
editCellInTable(row, VALUE_COL, newValue);
12951285
}
12961286

12971287
private void editNameInTable(int row, String newValue) {
1298-
12991288
editCellInTable(row, NAME_COL, newValue);
13001289
}
13011290

@@ -1331,11 +1320,23 @@ private void createEquate(String name) throws Exception {
13311320

13321321
private void addEnumValue() {
13331322
runSwing(() -> {
1334-
DockingActionIf addAction = getAction(plugin, "Add Enum Value");
1323+
DockingActionIf addAction = getAddAction();
13351324
addAction.actionPerformed(new DefaultActionContext());
13361325
});
13371326
}
13381327

1328+
private DockingActionIf getAddAction() {
1329+
return getAction(plugin, DataTypeEditorManager.EDIT_ACTION_PREFIX + "Add Enum Value");
1330+
}
1331+
1332+
private DockingActionIf getApplyAction() {
1333+
return getAction(plugin, DataTypeEditorManager.EDIT_ACTION_PREFIX + "Apply Enum Changes");
1334+
}
1335+
1336+
private DockingActionIf getDeleteAction() {
1337+
return getAction(plugin, DataTypeEditorManager.EDIT_ACTION_PREFIX + "Delete Enum Value");
1338+
}
1339+
13391340
private int getRowFor(String theName) {
13401341

13411342
JTable table = getEditTable();

0 commit comments

Comments
 (0)