Tests - fixed failing tests

This commit is contained in:
dragonmacher 2019-11-29 16:31:34 -05:00
parent 2c4e0155db
commit b126f6bd06
3 changed files with 34 additions and 35 deletions

View file

@ -18,14 +18,9 @@ package ghidra.app.plugin.core.function.tags;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Optional;
import javax.swing.BorderFactory; import javax.swing.*;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import docking.DockingWindowManager; import docking.DockingWindowManager;
import docking.widgets.OptionDialog; import docking.widgets.OptionDialog;
@ -34,9 +29,7 @@ import ghidra.app.cmd.function.ChangeFunctionTagCmd;
import ghidra.app.cmd.function.DeleteFunctionTagCmd; import ghidra.app.cmd.function.DeleteFunctionTagCmd;
import ghidra.framework.cmd.Command; import ghidra.framework.cmd.Command;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.listing.Function; import ghidra.program.model.listing.*;
import ghidra.program.model.listing.FunctionTag;
import ghidra.program.model.listing.Program;
import ghidra.util.Msg; import ghidra.util.Msg;
/** /**
@ -64,11 +57,11 @@ public abstract class TagListPanel extends JPanel {
this.tool = tool; this.tool = tool;
setLayout(new BorderLayout()); setLayout(new BorderLayout());
model = new FunctionTagTableModel("", provider.getTool()) ; model = new FunctionTagTableModel("", provider.getTool());
filteredModel = new FunctionTagTableModel("", provider.getTool()); filteredModel = new FunctionTagTableModel("", provider.getTool());
table = new FunctionTagTable(filteredModel); table = new FunctionTagTable(filteredModel);
table.addMouseListener(new MouseAdapter() { table.addMouseListener(new MouseAdapter() {
@Override @Override
@ -83,9 +76,9 @@ public abstract class TagListPanel extends JPanel {
// a dialog for editing the tag name and/or comment. // a dialog for editing the tag name and/or comment.
@Override @Override
public void mouseClicked(MouseEvent evt) { public void mouseClicked(MouseEvent evt) {
FunctionTagTable table = (FunctionTagTable)evt.getSource(); FunctionTagTable table = (FunctionTagTable) evt.getSource();
if (evt.getClickCount() == 2) { if (evt.getClickCount() == 2) {
int row = table.getSelectedRow(); int row = table.getSelectedRow();
int nameCol = table.getColumnModel().getColumnIndex("Name"); int nameCol = table.getColumnModel().getColumnIndex("Name");
@ -98,9 +91,9 @@ public abstract class TagListPanel extends JPanel {
// If the tag is a temporary one, it's not editable. Show a message to the user. // If the tag is a temporary one, it's not editable. Show a message to the user.
if (tag instanceof FunctionTagTemp) { if (tag instanceof FunctionTagTemp) {
Msg.showWarn(this, table, "Tag Not Editable", "Tag " + "\"" + tag.getName() + Msg.showWarn(this, table, "Tag Not Editable",
"\"" + "Tag " + "\"" + tag.getName() + "\"" +
" must be added to the program before it can be modified/deleted"); " must be added to the program before it can be modified/deleted");
return; return;
} }
@ -121,7 +114,8 @@ public abstract class TagListPanel extends JPanel {
// If the name is empty, show a warning and don't allow it. A user should // If the name is empty, show a warning and don't allow it. A user should
// never want to do this. // never want to do this.
if (newName.isEmpty()) { if (newName.isEmpty()) {
Msg.showWarn(this, table, "Empty Tag Name?", "Tag name cannot be empty"); Msg.showWarn(this, table, "Empty Tag Name?",
"Tag name cannot be empty");
return false; return false;
} }
@ -149,13 +143,13 @@ public abstract class TagListPanel extends JPanel {
} }
} }
}); });
titleLabel = new JLabel(title); titleLabel = new JLabel(title);
titleLabel.setBorder(BorderFactory.createEmptyBorder(3, 5, 0, 0)); titleLabel.setBorder(BorderFactory.createEmptyBorder(3, 5, 0, 0));
add(titleLabel, BorderLayout.NORTH); add(titleLabel, BorderLayout.NORTH);
add(new JScrollPane(table), BorderLayout.CENTER); add(new JScrollPane(table), BorderLayout.CENTER);
} }
/****************************************************************************** /******************************************************************************
* PUBLIC METHODS * PUBLIC METHODS
******************************************************************************/ ******************************************************************************/
@ -219,14 +213,14 @@ public abstract class TagListPanel extends JPanel {
protected boolean isSelectionImmutable() { protected boolean isSelectionImmutable() {
int[] selectedRows = table.getSelectedRows(); int[] selectedRows = table.getSelectedRows();
int nameCol = table.getColumnModel().getColumnIndex("Name"); int nameCol = table.getColumnModel().getColumnIndex("Name");
for (int i=0; i<selectedRows.length; i++) { for (int selectedRow : selectedRows) {
String tagName = (String) table.getValueAt(i, nameCol); String tagName = (String) table.getValueAt(selectedRow, nameCol);
FunctionTag tag = filteredModel.getTag(tagName); FunctionTag tag = filteredModel.getTag(tagName);
if (tag instanceof FunctionTagTemp) { if (tag instanceof FunctionTagTemp) {
return true; return true;
} }
} }
return false; return false;
} }
@ -265,7 +259,7 @@ public abstract class TagListPanel extends JPanel {
*/ */
protected void applyFilter() { protected void applyFilter() {
filteredModel.clear(); filteredModel.clear();
for (FunctionTag tag : model.getTags()) { for (FunctionTag tag : model.getTags()) {
if (filterString.isEmpty()) { if (filterString.isEmpty()) {
filteredModel.addTag(tag); filteredModel.addTag(tag);
@ -274,8 +268,8 @@ public abstract class TagListPanel extends JPanel {
filteredModel.addTag(tag); filteredModel.addTag(tag);
} }
} }
filteredModel.reload(); filteredModel.reload();
} }
/** /**
@ -302,7 +296,8 @@ public abstract class TagListPanel extends JPanel {
int[] selectedIndices = table.getSelectedRows(); int[] selectedIndices = table.getSelectedRows();
for (int i : selectedIndices) { for (int i : selectedIndices) {
String tagName = (String) filteredModel.getValueAt(i, 0); String tagName = (String) filteredModel.getValueAt(i, 0);
Optional<FunctionTag> tag = filteredModel.getTags().stream().filter(t -> t.getName().equals(tagName)).findAny(); Optional<FunctionTag> tag =
filteredModel.getTags().stream().filter(t -> t.getName().equals(tagName)).findAny();
if (tag.isPresent()) { if (tag.isPresent()) {
tags.add(tag.get()); tags.add(tag.get());
} }

View file

@ -15,7 +15,7 @@
*/ */
package ghidra.app.plugin.core.navigation; package ghidra.app.plugin.core.navigation;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import java.awt.Color; import java.awt.Color;
@ -82,7 +82,7 @@ public class NextPrevCodeUnitPluginTest extends AbstractGhidraHeadedIntegrationT
tool.addPlugin(BookmarkPlugin.class.getName()); tool.addPlugin(BookmarkPlugin.class.getName());
NextPrevCodeUnitPlugin p = getPlugin(tool, NextPrevCodeUnitPlugin.class); NextPrevCodeUnitPlugin p = getPlugin(tool, NextPrevCodeUnitPlugin.class);
direction = getAction(p, "Toggle Code Unit Search Direction"); direction = getAction(p, "Toggle Search Direction");
nextInst = getAction(p, "Next Instruction"); nextInst = getAction(p, "Next Instruction");
nextData = getAction(p, "Next Data"); nextData = getAction(p, "Next Data");
nextUndef = getAction(p, "Next Undefined"); nextUndef = getAction(p, "Next Undefined");

View file

@ -17,6 +17,8 @@ package ghidra.util;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.junit.Test; import org.junit.Test;
@ -30,9 +32,11 @@ public class DateUtilsTest {
} }
@Test @Test
public void testFormatDateTime() { public void testFormatDateTime() throws ParseException {
Date date = new Date(1572896586687L); SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy hh:mm a");
assertEquals("Nov 04, 2019 02:43 PM", DateUtils.formatDateTimestamp(date)); String dateString = "Nov 04, 2019 02:43 PM";
Date date = format.parse(dateString);
assertEquals(dateString, DateUtils.formatDateTimestamp(date));
} }
@Test @Test