Test fixes for non-failing stack traces in log file

This commit is contained in:
dragonmacher 2021-03-18 11:28:14 -04:00
parent 33e4d54062
commit c8a4f7dcf7
4 changed files with 50 additions and 32 deletions

View file

@ -310,8 +310,10 @@ class EnumEditorPanel extends JPanel {
EnumCellRenderer cellRenderer = new EnumCellRenderer(); EnumCellRenderer cellRenderer = new EnumCellRenderer();
table.setRowHeight(table.getRowHeight() + 4); table.setRowHeight(table.getRowHeight() + 4);
table.setDefaultEditor(String.class, new EnumStringCellEditor()); table.setDefaultEditor(String.class, new EnumStringCellEditor());
table.getColumnModel().getColumn(EnumTableModel.VALUE_COL).setCellEditor( table.getColumnModel()
new EnumLongCellEditor()); .getColumn(EnumTableModel.VALUE_COL)
.setCellEditor(
new EnumLongCellEditor());
table.setDefaultRenderer(String.class, cellRenderer); table.setDefaultRenderer(String.class, cellRenderer);
add(createInfoPanel(), BorderLayout.SOUTH); add(createInfoPanel(), BorderLayout.SOUTH);
@ -335,13 +337,17 @@ class EnumEditorPanel extends JPanel {
} }
private void changed() { private void changed() {
String name = nameField.getText(); String name = nameField.getText().trim();
if (name.length() == 0) {
return;
}
if (!name.equals(editedEnumDT.getName())) { if (!name.equals(editedEnumDT.getName())) {
try { try {
editedEnumDT.setName(name); editedEnumDT.setName(name);
} }
catch (InvalidNameException e) { catch (InvalidNameException e) {
e.printStackTrace(); setStatusMessage("'" + name + "' is not a valid name");
} }
} }

View file

@ -41,8 +41,10 @@ public class FunctionTagLoader {
* *
* @param tagFile tag file * @param tagFile tag file
* @return List list of function tags * @return List list of function tags
* @throws IOException if there is an exception reading the file
* @throws SAXException if there is an exception parsing the file
*/ */
protected static Set<FunctionTag> loadTags(File tagFile) { protected static Set<FunctionTag> loadTags(File tagFile) throws SAXException, IOException {
return loadTags(new ResourceFile(tagFile)); return loadTags(new ResourceFile(tagFile));
} }
@ -56,16 +58,17 @@ public class FunctionTagLoader {
try { try {
return loadTags(Application.getModuleDataFile(moduleDataFilePath)); return loadTags(Application.getModuleDataFile(moduleDataFilePath));
} }
catch (FileNotFoundException e) { catch (SAXException | IOException e) {
Msg.error(FunctionTagLoader.class, Msg.error(FunctionTagLoader.class,
"Error loading function tags file from " + moduleDataFilePath, e); "Error loading function tags file from " + moduleDataFilePath, e);
} }
return new HashSet<>(); return new HashSet<>();
} }
protected static Set<FunctionTag> loadTags(final ResourceFile tagDataFile) { protected static Set<FunctionTag> loadTags(final ResourceFile tagDataFile)
Set<FunctionTag> tags = new HashSet<>(); throws SAXException, IOException {
Set<FunctionTag> tags = new HashSet<>();
try { try {
ErrorHandler errHandler = new ErrorHandler() { ErrorHandler errHandler = new ErrorHandler() {
@Override @Override
@ -116,10 +119,6 @@ public class FunctionTagLoader {
Msg.error(FunctionTagLoader.class, "Error parsing function tags from " + tagDataFile, Msg.error(FunctionTagLoader.class, "Error parsing function tags from " + tagDataFile,
e); e);
} }
catch (SAXException | IOException e) {
Msg.error(FunctionTagLoader.class, "Error loading function tags from " + tagDataFile,
e);
}
return tags; return tags;
} }

View file

@ -18,7 +18,6 @@ package ghidra.app.plugin.core.function.tags;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -117,10 +116,14 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
public void testLoadTags_EmptyFile() throws Exception { public void testLoadTags_EmptyFile() throws Exception {
// Create file without contents // Create file without contents
File xxeFile = createTempFileForTest(); File xxeFile = createTempFileForTest();
Set<FunctionTag> tags = FunctionTagLoader.loadTags(xxeFile);
Set<FunctionTag> expectedTags = new HashSet<>(); try {
assertEquals(tags, expectedTags); FunctionTagLoader.loadTags(xxeFile);
fail("Did not get expected exception");
}
catch (Exception e) {
// good
}
} }
@Test @Test
@ -140,10 +143,13 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
File xxeFile = createTempFileForTest(); File xxeFile = createTempFileForTest();
xxeFile.delete(); xxeFile.delete();
Set<FunctionTag> tags = FunctionTagLoader.loadTags(xxeFile); try {
FunctionTagLoader.loadTags(xxeFile);
Set<FunctionTag> expectedTags = new HashSet<>(); fail("Did not get expected exception");
assertEquals(tags, expectedTags); }
catch (Exception e) {
// good
}
} }
@Test @Test
@ -151,10 +157,14 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
// Create file with contents // Create file with contents
File xxeFile = createTempFileForTest(); File xxeFile = createTempFileForTest();
Files.write(xxeFile.toPath(), FUNCTION_TAGS_MALFORMED_XML.getBytes()); Files.write(xxeFile.toPath(), FUNCTION_TAGS_MALFORMED_XML.getBytes());
Set<FunctionTag> tags = FunctionTagLoader.loadTags(xxeFile);
Set<FunctionTag> expectedTags = new HashSet<>(); try {
assertEquals(tags, expectedTags); FunctionTagLoader.loadTags(xxeFile);
fail("Did not get expected exception");
}
catch (Exception e) {
// good
}
} }
@Test @Test
@ -163,7 +173,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
* located in Base/data/functionTags.xml * located in Base/data/functionTags.xml
* @throws IOException * @throws IOException
*/ */
public void testLoadTags_XmlDefault() throws IOException { public void testLoadTags_XmlDefault() throws Exception {
// Create file with contents // Create file with contents
File xxeFile = createTempFileForTest(); File xxeFile = createTempFileForTest();
@ -184,7 +194,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
} }
@Test @Test
public void testLoadTags_XmlHasBlankNameValue() throws IOException { public void testLoadTags_XmlHasBlankNameValue() throws Exception {
// Create file with contents // Create file with contents
File xxeFile = createTempFileForTest(); File xxeFile = createTempFileForTest();
@ -204,7 +214,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
} }
@Test @Test
public void testLoadTags_XmlHasCommentValue() throws IOException { public void testLoadTags_XmlHasCommentValue() throws Exception {
// Create file with contents // Create file with contents
File xxeFile = createTempFileForTest(); File xxeFile = createTempFileForTest();
@ -225,7 +235,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
} }
@Test @Test
public void testLoadTags_XmlNoCommentTag() throws IOException { public void testLoadTags_XmlNoCommentTag() throws Exception {
// Create file with contents // Create file with contents
File xxeFile = createTempFileForTest(); File xxeFile = createTempFileForTest();
@ -252,7 +262,7 @@ public class FunctionTagLoaderTest extends AbstractGhidraHeadedIntegrationTest {
* *
* @throws IOException * @throws IOException
*/ */
public void testLoadTags_XmlNoNameTag() throws IOException { public void testLoadTags_XmlNoNameTag() throws Exception {
// Create file with contents // Create file with contents
File xxeFile = createTempFileForTest(); File xxeFile = createTempFileForTest();

View file

@ -17,8 +17,7 @@ package ghidra.test;
import java.awt.Window; import java.awt.Window;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.Collections; import java.util.*;
import java.util.Set;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
@ -34,8 +33,7 @@ import ghidra.framework.model.*;
import ghidra.framework.options.ToolOptions; import ghidra.framework.options.ToolOptions;
import ghidra.framework.plugintool.PluginEvent; import ghidra.framework.plugintool.PluginEvent;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.PluginClassManager; import ghidra.framework.plugintool.util.*;
import ghidra.framework.plugintool.util.ServiceListener;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
public class DummyTool extends PluginTool { public class DummyTool extends PluginTool {
@ -451,4 +449,9 @@ public class DummyTool extends PluginTool {
public JFrame getToolFrame() { public JFrame getToolFrame() {
return null; return null;
} }
@Override
public UndoRedoToolState getUndoRedoToolState(DomainObject domainObject) {
return new UndoRedoToolState(new ArrayList<>(), domainObject);
}
} }