GP-5326 fixed junit tests and removed check for default field names

This commit is contained in:
ghidragon 2025-03-18 12:30:03 -04:00
parent 2f581d0ead
commit 9429fa0a8e
4 changed files with 7 additions and 22 deletions

View file

@ -138,7 +138,7 @@ public class EditDataFieldDialog extends DialogComponentProvider {
private void initializeFields() { private void initializeFields() {
String name = component.getFieldName(); String name = component.getFieldName();
if (StringUtils.isBlank(name)) { if (StringUtils.isBlank(name)) {
name = component.getDefaultFieldName(); name = "";
} }
nameField.setText(name); nameField.setText(name);
commentField.setText(component.getComment()); commentField.setText(component.getComment());

View file

@ -123,7 +123,7 @@ public class EditFieldDialogTest extends AbstractGhidraHeadedIntegrationTest {
goTo(0x101); goTo(0x101);
showFieldEditDialog(); showFieldEditDialog();
assertNull(structure.getComponent(1).getFieldName()); assertNull(structure.getComponent(1).getFieldName());
assertEquals("field1_0x1", getNameText()); assertEquals("", getNameText());
setNameText("abc"); setNameText("abc");
@ -162,23 +162,6 @@ public class EditFieldDialogTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals("byte", structure.getComponent(1).getDataType().getDisplayName()); assertEquals("byte", structure.getComponent(1).getDataType().getDisplayName());
} }
@Test
public void testRenameToDuplicateNameError() {
goTo(0x104);
showFieldEditDialog();
assertEquals("count", structure.getComponent(4).getFieldName());
assertEquals("count", getNameText());
setNameText("color");
pressOk();
waitForTasks();
assertTrue(isDialogVisible());
assertEquals("Duplicate field name", getDialogStatusText());
assertEquals("count", structure.getComponent(4).getFieldName());
}
private boolean isDialogVisible() { private boolean isDialogVisible() {
return runSwing(() -> dialog.isVisible()); return runSwing(() -> dialog.isVisible());
} }

View file

@ -117,8 +117,10 @@ public interface DataTypeComponent {
* *
* @param fieldName the new field name for this component. * @param fieldName the new field name for this component.
* *
* @throws DuplicateNameException if another component of the parent has * @throws DuplicateNameException This is actually never thrown anymore. All the other ways
* the specified field name. * of naming fields did not perform this check and it would cause quite a bit of churn to
* add that exception to all the other methods that affect field names. So to be consistent,
* we no longer do the check in this method.
*/ */
public void setFieldName(String fieldName) throws DuplicateNameException; public void setFieldName(String fieldName) throws DuplicateNameException;

View file

@ -64,7 +64,7 @@ public interface InternalDataTypeComponent extends DataTypeComponent {
public default String cleanupFieldName(String name) { public default String cleanupFieldName(String name) {
// For now, silently convert whitespace to underscores // For now, silently convert whitespace to underscores
String fieldName = StringUtilities.whitespaceToUnderscores(name); String fieldName = StringUtilities.whitespaceToUnderscores(name);
if (StringUtils.isBlank(fieldName) || fieldName.equals(getDefaultFieldName())) { if (StringUtils.isBlank(fieldName)) {
fieldName = null; fieldName = null;
} }
return fieldName; return fieldName;