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,7 +310,9 @@ class EnumEditorPanel extends JPanel {
EnumCellRenderer cellRenderer = new EnumCellRenderer();
table.setRowHeight(table.getRowHeight() + 4);
table.setDefaultEditor(String.class, new EnumStringCellEditor());
table.getColumnModel().getColumn(EnumTableModel.VALUE_COL).setCellEditor(
table.getColumnModel()
.getColumn(EnumTableModel.VALUE_COL)
.setCellEditor(
new EnumLongCellEditor());
table.setDefaultRenderer(String.class, cellRenderer);
add(createInfoPanel(), BorderLayout.SOUTH);
@ -335,13 +337,17 @@ class EnumEditorPanel extends JPanel {
}
private void changed() {
String name = nameField.getText();
String name = nameField.getText().trim();
if (name.length() == 0) {
return;
}
if (!name.equals(editedEnumDT.getName())) {
try {
editedEnumDT.setName(name);
}
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
* @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));
}
@ -56,16 +58,17 @@ public class FunctionTagLoader {
try {
return loadTags(Application.getModuleDataFile(moduleDataFilePath));
}
catch (FileNotFoundException e) {
catch (SAXException | IOException e) {
Msg.error(FunctionTagLoader.class,
"Error loading function tags file from " + moduleDataFilePath, e);
}
return new HashSet<>();
}
protected static Set<FunctionTag> loadTags(final ResourceFile tagDataFile) {
Set<FunctionTag> tags = new HashSet<>();
protected static Set<FunctionTag> loadTags(final ResourceFile tagDataFile)
throws SAXException, IOException {
Set<FunctionTag> tags = new HashSet<>();
try {
ErrorHandler errHandler = new ErrorHandler() {
@Override
@ -116,10 +119,6 @@ public class FunctionTagLoader {
Msg.error(FunctionTagLoader.class, "Error parsing function tags from " + tagDataFile,
e);
}
catch (SAXException | IOException e) {
Msg.error(FunctionTagLoader.class, "Error loading function tags from " + tagDataFile,
e);
}
return tags;
}

View file

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

View file

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