mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
Tests - fixed test timing issues
This commit is contained in:
parent
e16bd30366
commit
cc6020736c
3 changed files with 85 additions and 24 deletions
|
@ -25,6 +25,7 @@ import org.junit.*;
|
||||||
|
|
||||||
import docking.widgets.table.model.TestDataModel;
|
import docking.widgets.table.model.TestDataModel;
|
||||||
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
||||||
|
import ghidra.util.Msg;
|
||||||
import ghidra.util.table.GhidraTable;
|
import ghidra.util.table.GhidraTable;
|
||||||
|
|
||||||
public class GTableTest extends AbstractGhidraHeadedIntegrationTest {
|
public class GTableTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
|
@ -44,6 +45,9 @@ public class GTableTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
frame.getContentPane().add(new JScrollPane(table));
|
frame.getContentPane().add(new JScrollPane(table));
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
// showing the table will trigger a call to sort; wait for sorting to finish
|
||||||
|
waitForSort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -59,26 +63,31 @@ public class GTableTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
setSelectedRow(table, 0);
|
setSelectedRow(table, 0);
|
||||||
|
|
||||||
triggerText(table, "a");
|
triggerText(table, "a");
|
||||||
assertEquals(11, table.getSelectedRow());
|
assertSelectedRow(11, "a");
|
||||||
|
|
||||||
triggerText(table, "c");
|
triggerText(table, "c");
|
||||||
assertEquals(12, table.getSelectedRow());
|
assertSelectedRow(12, "c");
|
||||||
timeout();
|
timeout();
|
||||||
|
|
||||||
triggerText(table, "ad");
|
triggerText(table, "ad");
|
||||||
assertEquals(24, table.getSelectedRow());
|
assertSelectedRow(24, "ad");
|
||||||
timeout();
|
timeout();
|
||||||
|
|
||||||
triggerText(table, "av");
|
triggerText(table, "av");
|
||||||
assertEquals(70, table.getSelectedRow());
|
assertSelectedRow(70, "av");
|
||||||
timeout();
|
timeout();
|
||||||
|
|
||||||
triggerText(table, "x");
|
triggerText(table, "x");
|
||||||
assertEquals(1920, table.getSelectedRow());
|
assertSelectedRow(1920, "x");
|
||||||
timeout();
|
timeout();
|
||||||
|
|
||||||
triggerText(table, "a");
|
triggerText(table, "a");
|
||||||
assertEquals(11, table.getSelectedRow());
|
assertSelectedRow(11, "a");
|
||||||
|
|
||||||
// test the case where no match is found
|
// test the case where no match is found
|
||||||
table.setAutoLookupTimeout(1000); // longer timeout needed for multiple keys
|
table.setAutoLookupTimeout(1000); // longer timeout needed for multiple keys
|
||||||
triggerText(table, "zed");
|
triggerText(table, "zed");
|
||||||
assertEquals(11, table.getSelectedRow()); // no change
|
assertSelectedRow(11, "zed"); // no change
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -92,31 +101,31 @@ public class GTableTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
setSelectedRow(table, 0);
|
setSelectedRow(table, 0);
|
||||||
|
|
||||||
triggerText(table, "a");
|
triggerText(table, "a");
|
||||||
assertEquals(1846, table.getSelectedRow());
|
assertSelectedRow(1846, "a");
|
||||||
|
|
||||||
triggerText(table, "c");
|
triggerText(table, "c");
|
||||||
assertEquals(1902, table.getSelectedRow());
|
assertSelectedRow(1902, "c");
|
||||||
|
|
||||||
timeout();
|
timeout();
|
||||||
triggerText(table, "ad");
|
triggerText(table, "ad");
|
||||||
assertEquals(1885, table.getSelectedRow());
|
assertSelectedRow(1885, "ad");
|
||||||
|
|
||||||
timeout();
|
timeout();
|
||||||
triggerText(table, "av");
|
triggerText(table, "av");
|
||||||
assertEquals(1848, table.getSelectedRow());
|
assertSelectedRow(1848, "av");
|
||||||
|
|
||||||
timeout();
|
timeout();
|
||||||
triggerText(table, "x");
|
triggerText(table, "x");
|
||||||
assertEquals(0, table.getSelectedRow());
|
assertSelectedRow(0, "x");
|
||||||
|
|
||||||
timeout();
|
timeout();
|
||||||
triggerText(table, "a");
|
triggerText(table, "a");
|
||||||
assertEquals(1846, table.getSelectedRow());
|
assertSelectedRow(1846, "a");
|
||||||
|
|
||||||
// test the case where no match is found
|
// test the case where no match is found
|
||||||
table.setAutoLookupTimeout(1000); // longer timeout needed for multiple keys
|
table.setAutoLookupTimeout(1000); // longer timeout needed for multiple keys
|
||||||
triggerText(table, "zed");
|
triggerText(table, "zed");
|
||||||
assertEquals(1846, table.getSelectedRow()); // no change
|
assertSelectedRow(1846, "zed"); // no change
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -132,26 +141,31 @@ public class GTableTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
// note: the order checked here is the same as the sorted order, since we did not move
|
// note: the order checked here is the same as the sorted order, since we did not move
|
||||||
// any rows after disabling the sort
|
// any rows after disabling the sort
|
||||||
triggerText(table, "a");
|
triggerText(table, "a");
|
||||||
assertEquals(11, table.getSelectedRow());
|
assertSelectedRow(11, "a");
|
||||||
|
|
||||||
triggerText(table, "c");
|
triggerText(table, "c");
|
||||||
assertEquals(12, table.getSelectedRow());
|
assertSelectedRow(12, "c");
|
||||||
timeout();
|
timeout();
|
||||||
|
|
||||||
triggerText(table, "ad");
|
triggerText(table, "ad");
|
||||||
assertEquals(24, table.getSelectedRow());
|
assertSelectedRow(24, "ad");
|
||||||
timeout();
|
timeout();
|
||||||
|
|
||||||
triggerText(table, "av");
|
triggerText(table, "av");
|
||||||
assertEquals(70, table.getSelectedRow());
|
assertSelectedRow(70, "av");
|
||||||
timeout();
|
timeout();
|
||||||
|
|
||||||
triggerText(table, "x");
|
triggerText(table, "x");
|
||||||
assertEquals(1920, table.getSelectedRow());
|
assertSelectedRow(1920, "x");
|
||||||
timeout();
|
timeout();
|
||||||
|
|
||||||
triggerText(table, "a");
|
triggerText(table, "a");
|
||||||
assertEquals(11, table.getSelectedRow());
|
assertSelectedRow(11, "a");
|
||||||
|
|
||||||
// test the case where no match is found
|
// test the case where no match is found
|
||||||
table.setAutoLookupTimeout(1000); // longer timeout needed for multiple keys
|
table.setAutoLookupTimeout(1000); // longer timeout needed for multiple keys
|
||||||
triggerText(table, "zed");
|
triggerText(table, "zed");
|
||||||
assertEquals(11, table.getSelectedRow()); // no change
|
assertSelectedRow(11, "zed"); // no change
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -192,9 +206,31 @@ public class GTableTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertEquals("Auto-lookup failed to change the table row", 11, table.getSelectedRow());
|
assertEquals("Auto-lookup failed to change the table row", 11, table.getSelectedRow());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertSelectedRow(int row, String lookupText) {
|
||||||
|
|
||||||
|
int actual = runSwing(() -> table.getSelectedRow());
|
||||||
|
if (row != actual) {
|
||||||
|
|
||||||
|
int col = 4; // String 'Name' column
|
||||||
|
String expectedString = (String) table.getValueAt(row, col);
|
||||||
|
String actualString = (String) table.getValueAt(actual, col);
|
||||||
|
String message = "Auto-lookup row not selected for '" + lookupText + "'.\n\t" +
|
||||||
|
"Expected text: '" + expectedString + "'; Actual text: '" + actualString + "'";
|
||||||
|
Msg.out(message);
|
||||||
|
assertEquals(message, row, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void removeSortColumn(int column) {
|
private void removeSortColumn(int column) {
|
||||||
waitForSwing();
|
waitForSwing();
|
||||||
runSwing(() -> TableUtils.columnAlternativelySelected(table, column));
|
runSwing(() -> TableUtils.columnAlternativelySelected(table, column));
|
||||||
|
waitForSort();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void waitForSort() {
|
||||||
|
// the call to sort may be run in an invokeLater()
|
||||||
|
waitForSwing();
|
||||||
|
waitForCondition(() -> !model.isSortPending());
|
||||||
waitForSwing();
|
waitForSwing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +238,7 @@ public class GTableTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
|
|
||||||
TableSortState descendingSortState = TableSortState.createDefaultSortState(column, false);
|
TableSortState descendingSortState = TableSortState.createDefaultSortState(column, false);
|
||||||
runSwing(() -> model.setTableSortState(descendingSortState));
|
runSwing(() -> model.setTableSortState(descendingSortState));
|
||||||
waitForSwing();
|
waitForSort();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void timeout() {
|
private void timeout() {
|
||||||
|
|
|
@ -190,10 +190,23 @@ public abstract class AbstractSortedTableModel<T> extends AbstractGTableModel<T>
|
||||||
return pendingSortState;
|
return pendingSortState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if there is a pending change to the current sort state
|
||||||
|
* (this includes a sort state that signals no sort will be applied)
|
||||||
|
*
|
||||||
|
* @return true if there is a pending change to the current sort state
|
||||||
|
*/
|
||||||
public boolean isSortPending() {
|
public boolean isSortPending() {
|
||||||
return isSortPending;
|
return isSortPending;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this model has been sorted and does not have a new pending sort that will
|
||||||
|
* be applied
|
||||||
|
*
|
||||||
|
* @return true if sorted
|
||||||
|
* @see #isSortPending()
|
||||||
|
*/
|
||||||
public boolean isSorted() {
|
public boolean isSorted() {
|
||||||
return !isSortPending && !sortState.isUnsorted();
|
return !isSortPending && !sortState.isUnsorted();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1747,8 +1747,15 @@ public class GhidraFileChooserTest extends AbstractDockingTest {
|
||||||
public void testHistoryRestoresSelectedFiles() throws Exception {
|
public void testHistoryRestoresSelectedFiles() throws Exception {
|
||||||
|
|
||||||
File startDir = createTempDir();
|
File startDir = createTempDir();
|
||||||
setDir(startDir);
|
File subDir = createFileSubFile(startDir, 3);
|
||||||
createFileSubFile(startDir, 3);
|
setDir(subDir);
|
||||||
|
|
||||||
|
// // debug
|
||||||
|
// DirectoryList list = getListView();
|
||||||
|
// ListSelectionModel sm = list.getSelectionModel();
|
||||||
|
// sm.addListSelectionListener(e -> {
|
||||||
|
// Msg.debug(this, "selection changed: " + e);
|
||||||
|
// });
|
||||||
|
|
||||||
pressUp();
|
pressUp();
|
||||||
selectFile(getListView(), 1);
|
selectFile(getListView(), 1);
|
||||||
|
@ -1930,6 +1937,11 @@ public class GhidraFileChooserTest extends AbstractDockingTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private File selectFile(DirectoryList list, int index) {
|
private File selectFile(DirectoryList list, int index) {
|
||||||
|
|
||||||
|
// TODO debug - remove when all tests passing on server
|
||||||
|
int size = list.getModel().getSize();
|
||||||
|
Msg.debug(this, "selectFile() - new index: " + index + "; list size: " + size);
|
||||||
|
|
||||||
runSwing(() -> list.setSelectedIndex(index));
|
runSwing(() -> list.setSelectedIndex(index));
|
||||||
return runSwing(() -> list.getSelectedFile());
|
return runSwing(() -> list.getSelectedFile());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue