From: <gjo...@us...> - 2007-08-17 15:00:15
|
Revision: 2470 http://abbot.svn.sourceforge.net/abbot/?rev=2470&view=rev Author: gjohnsto Date: 2007-08-17 07:59:32 -0700 (Fri, 17 Aug 2007) Log Message: ----------- o Matcher hierarchy tweaks. o CompositeWidgetMultiMatcher now extends CompositeMultiMatcher<Widget> and implements WidgetMultiMatcher rather than simply extending CompositeWidgetMatcher. Got that? :-) Thanks to Sky Yan for the suggestion that led to this. o IndexMatcher constructor now takes Matcher<Widget> rather than WidgetMatcher. o Added LabeledTextMatcher. Constructor takes a String and matches a Text that is a sibling of (child of the same Composite) a Label with the specified String as its text. Useful for finding Labeled entry field Texts. o Added some append() methods to ItemPath. o Fixed a Mac-specific BUTTON_POPUP value in abbot.swt.tester.Robot. Thanks to Sky Yan for the fix. o TableTester, TableItemTester fixes & enhancements. o Fixed problem of selection events not being generated by some of the actionSelect*() methods. o TableItemTester: o Added TableItemTester.getSelected(TableItem). o Added TableItemTester.actionSelectItem(TableItem, boolean) and TableItemTester.actionCheckItem(TableItem, boolean). o TableTester: o Added getItem(Table, String). o Deprecated getSelectedTableItems(Table). Use getSelection(Table). o Added actionSelectItem(Table, int, boolean) and actionSelectItem(Table, String, boolean). o Deprecated actionSelectTableItem(Table, TableItem) and actionSelectTableIndex(Table, int). Use one of the new methods above. o Added actionCheckItem(Table, index, boolean) and actionCheckItem(Table, String, boolean). o Deprecated actionCheckTableItem(Table, TableItem) and actionCheckTableIndex(Table, int). Use one of the new methods above. o Added addSelectionListener(Table, SelectionListener) and removeSelectionListener(Table, SelectionListener). o TextTester o Added actionKeyString(Text, String). o Added some JFace-ish Dialog, Wizard and Workbench support. These are just somewhat higher-level API to make it more convenient and concise to manipulate & check Dialogs & Wizards and such. More to come. o New classes & methods: o DialogTester.actionClickButton(Shell dialogShell, String buttonText) o WizardTester o IWizardPage actionClickNext(Shell wizardShell) o IWizardPage actionClickNext(Shell wizardShell, String nextPageTitle) o IWizardPage actionClickBack(Shell wizardShell) o IWizardPage actionClickBack(Shell wizardShell, String previousPageTitle) o actionClickFinish(Shell wizardShell) o actionClickCancel(Shell wizardShell) o IWizardPage getCurrentPage(Shell wizardShell) o IWizardPage getNextPage(Shell wizardShell) o IWizardPage getPreviousPage(Shell wizardShell) o WizardDialog getWizard(Shell wizardShell) o Control getCurrentControl(Shell wizardShell) o Widget findCurrent(Shell wizardShell, Matcher<Widget> matcher) o actionSelectWizard(Shell wizardShell, ItemPath wizardPath, String wizardPageTitle) o IWizardPage actionGoToPage(Shell wizardShell, String targetPageTitle) o IWizardPage actionGoToNextPage(Shell wizardShell) o IWizardPage actionGoToBackPage(Shell wizardShell) o int getCurrentPageIndex(Shell wizardShell) o int getPageIndex(Shell wizardShell, String pageTitle) o WorkbenchTester o actionClickMenuBarItem(ItemPath) o Shell actionLaunchWizard(String menuLabel, String wizardShellText) o Shell actionLaunchNewWizard() o Shell actionLaunchNewWizard(ItemPath wizardPath, String wizardPageTitle) o Shell actionLaunchProjectWizard() o Shell actionLaunchProjectWizard(ItemPath wizardPath, String wizardPageTitle) o DynamicWebProjectWizardTester o Shell actionLaunchWizard o Text getProjectNameText(Shell wizardShell) o actionEnterProjectName(Shell wizardShell, String projectName) o Combo getPresetCombo(Shell wizardShell) o actionSelectPresetLabel(Shell wizardShell, String label) o actionSelectPresetId(Shell wizardShell, String id) o actionSelectFacet(Shell wizardShell, String facetName, String facetVersion) Modified Paths: -------------- abbot.swt/trunk/abbot.swt.test/src/abbot/swt/finder/matchers/test/CompositeMatcherTest.java abbot.swt/trunk/abbot.swt.test/src/abbot/swt/finder/matchers/test/CompositeMultiMatcherTest.java abbot.swt/trunk/abbot.swt.test/src/abbot/swt/tester/test/ItemPathTest.java abbot.swt/trunk/abbot.swt.test/src/abbot/swt/tester/test/TableTesterTest.java Modified: abbot.swt/trunk/abbot.swt.test/src/abbot/swt/finder/matchers/test/CompositeMatcherTest.java =================================================================== --- abbot.swt/trunk/abbot.swt.test/src/abbot/swt/finder/matchers/test/CompositeMatcherTest.java 2007-08-17 14:59:21 UTC (rev 2469) +++ abbot.swt/trunk/abbot.swt.test/src/abbot/swt/finder/matchers/test/CompositeMatcherTest.java 2007-08-17 14:59:32 UTC (rev 2470) @@ -6,25 +6,26 @@ import org.eclipse.swt.widgets.Widget; import abbot.swt.finder.generic.Matcher; +import abbot.swt.finder.matchers.CompositeMatcher; import abbot.swt.finder.matchers.CompositeWidgetMatcher; import abbot.swt.finder.matchers.WidgetMatcher; public class CompositeMatcherTest extends MatcherTest { - protected CompositeWidgetMatcher getMatcher(Matcher<Widget>[] matchers) { + protected CompositeMatcher<Widget> getMatcher(Matcher<Widget>[] matchers) { return new CompositeWidgetMatcher(matchers); } - protected CompositeWidgetMatcher getMatcher(Collection<Matcher<Widget>> matchers) { + protected CompositeMatcher<Widget> getMatcher(Collection<Matcher<Widget>> matchers) { return new CompositeWidgetMatcher(matchers); } - protected CompositeWidgetMatcher getMatcher(Matcher<Widget> matcher0, Matcher<Widget> matcher1) { + protected CompositeMatcher<Widget> getMatcher(Matcher<Widget> matcher0, Matcher<Widget> matcher1) { return new CompositeWidgetMatcher(matcher0, matcher1); } - protected CompositeWidgetMatcher getMatcher(Matcher<Widget> matcher0, Matcher<Widget> matcher1, - Matcher<Widget> matcher2) { + protected CompositeMatcher<Widget> getMatcher(Matcher<Widget> matcher0, + Matcher<Widget> matcher1, Matcher<Widget> matcher2) { return new CompositeWidgetMatcher(matcher0, matcher1, matcher2); } @@ -96,7 +97,7 @@ public void testMatchingCollection() { for (int i = 0; i < tests.length; i++) { Collection<Matcher<Widget>> matchers = Arrays.asList(tests[i].matchers); - WidgetMatcher matcher = getMatcher(matchers); + CompositeMatcher<Widget> matcher = getMatcher(matchers); assertEquals(tests[i].matchExpected, matcher.matches(app.shell)); } } @@ -106,7 +107,7 @@ MatcherTest test = tests[i]; Matcher<Widget>[] matchers = test.matchers; boolean expected = test.matchExpected; - WidgetMatcher matcher = null; + CompositeMatcher<Widget> matcher = null; switch (matchers.length) { case 0: case 1: Modified: abbot.swt/trunk/abbot.swt.test/src/abbot/swt/finder/matchers/test/CompositeMultiMatcherTest.java =================================================================== --- abbot.swt/trunk/abbot.swt.test/src/abbot/swt/finder/matchers/test/CompositeMultiMatcherTest.java 2007-08-17 14:59:21 UTC (rev 2469) +++ abbot.swt/trunk/abbot.swt.test/src/abbot/swt/finder/matchers/test/CompositeMultiMatcherTest.java 2007-08-17 14:59:32 UTC (rev 2470) @@ -10,6 +10,7 @@ import abbot.swt.finder.generic.Matcher; import abbot.swt.finder.generic.MultiMatcher; import abbot.swt.finder.generic.MultipleFoundException; +import abbot.swt.finder.matchers.CompositeMatcher; import abbot.swt.finder.matchers.CompositeMultiMatcher; import abbot.swt.finder.matchers.CompositeWidgetMatcher; import abbot.swt.finder.matchers.CompositeWidgetMultiMatcher; @@ -17,19 +18,19 @@ public class CompositeMultiMatcherTest extends CompositeMatcherTest { - protected CompositeWidgetMatcher getMatcher(Matcher<Widget>[] matchers) { + protected CompositeMatcher<Widget> getMatcher(Matcher<Widget>[] matchers) { return new CompositeWidgetMultiMatcher(matchers); } - protected CompositeWidgetMatcher getMatcher(Collection<Matcher<Widget>> matchers) { + protected CompositeMatcher<Widget> getMatcher(Collection<Matcher<Widget>> matchers) { return new CompositeWidgetMultiMatcher(matchers); } - protected CompositeWidgetMatcher getMatcher(Matcher<Widget> matcher0, Matcher<Widget> matcher1) { + protected CompositeMatcher<Widget> getMatcher(Matcher<Widget> matcher0, Matcher<Widget> matcher1) { return new CompositeWidgetMultiMatcher(matcher0, matcher1); } - protected CompositeWidgetMatcher getMatcher(Matcher<Widget> matcher0, Matcher<Widget> matcher1, + protected CompositeMatcher<Widget> getMatcher(Matcher<Widget> matcher0, Matcher<Widget> matcher1, Matcher<Widget> matcher2) { return new CompositeWidgetMultiMatcher(matcher0, matcher1, matcher2); } Modified: abbot.swt/trunk/abbot.swt.test/src/abbot/swt/tester/test/ItemPathTest.java =================================================================== --- abbot.swt/trunk/abbot.swt.test/src/abbot/swt/tester/test/ItemPathTest.java 2007-08-17 14:59:21 UTC (rev 2469) +++ abbot.swt/trunk/abbot.swt.test/src/abbot/swt/tester/test/ItemPathTest.java 2007-08-17 14:59:32 UTC (rev 2470) @@ -1,6 +1,9 @@ package abbot.swt.tester.test; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; +import java.util.List; import junit.framework.TestCase; import abbot.swt.tester.ItemPath; @@ -42,6 +45,93 @@ } + public void testAppendPath() { + + // First path has no segments. + checkAppendPath(new String[0], new String[0]); + checkAppendPath(new String[0], new String[] { "abc" }); + checkAppendPath(new String[0], new String[] { "abc", "def" }); + + // First path has 1 segment. + checkAppendPath(new String[] { "abc" }, new String[0]); + checkAppendPath(new String[] { "abc" }, new String[] { "def" }); + checkAppendPath(new String[] { "abc" }, new String[] { "def", "ghi" }); + + // First path has 2 segments. + checkAppendPath(new String[] { "abc", "def" }, new String[0]); + checkAppendPath(new String[] { "abc", "def" }, new String[] { "ghi" }); + checkAppendPath(new String[] { "abc", "def" }, new String[] { "ghi", "jkl" }); + } + + private void checkAppendPath(String[] segments1, String[] segments2) { + + ItemPath path1 = new ItemPath(segments1); + ItemPath path2 = new ItemPath(segments2); + + ItemPath path = path1.append(path2); + + // Input paths should be unchanged. + checkPath(path1, segments1); + checkPath(path2, segments2); + + // New path should not be the same object as either input path. + assertNotSame(path, path1); + assertNotSame(path, path2); + + // New path should be path1 and path2 concatenated. + List<String> list = new ArrayList<String>(segments1.length + segments2.length); + list.addAll(Arrays.asList(segments1)); + list.addAll(Arrays.asList(segments2)); + String[] segments = list.toArray(new String[list.size()]); + checkPath(path, segments); + } + + public void testAppendString() { + + // First path has no segments. + checkAppendString(new String[0], new String[0]); + checkAppendString(new String[0], new String[] { "abc" }); + checkAppendString(new String[0], new String[] { "abc", "def" }); + + // First path has 1 segment. + checkAppendString(new String[] { "abc" }, new String[0]); + checkAppendString(new String[] { "abc" }, new String[] { "def" }); + checkAppendString(new String[] { "abc" }, new String[] { "def", "ghi" }); + + // First path has 2 segments. + checkAppendString(new String[] { "abc", "def" }, new String[0]); + checkAppendString(new String[] { "abc", "def" }, new String[] { "ghi" }); + checkAppendString(new String[] { "abc", "def" }, new String[] { "ghi", "jkl" }); + } + + private void checkAppendString(String[] segments1, String[] segments2) { + + ItemPath path1 = new ItemPath(segments1); + + StringBuffer buffer2 = new StringBuffer(); + for (int i = 0; i < segments2.length; i++) { + if (buffer2.length() > 0) + buffer2.append(ItemPath.DEFAULT_DELIMITER); + buffer2.append(segments2[i]); + } + String path2 = buffer2.toString(); + + ItemPath path = path1.append(path2); + + // Input path should be unchanged. + checkPath(path1, segments1); + + // New path should not be the same object as input path. + assertNotSame(path, path1); + + // New path should be path1 and path2 concatenated. + List<String> list = new ArrayList<String>(segments1.length + segments2.length); + list.addAll(Arrays.asList(segments1)); + list.addAll(Arrays.asList(segments2)); + String[] segments = list.toArray(new String[list.size()]); + checkPath(path, segments); + } + private void checkPath(ItemPath path, String[] items) { Iterator<String> iterator = path.iterator(); for (String item : items) { Modified: abbot.swt/trunk/abbot.swt.test/src/abbot/swt/tester/test/TableTesterTest.java =================================================================== --- abbot.swt/trunk/abbot.swt.test/src/abbot/swt/tester/test/TableTesterTest.java 2007-08-17 14:59:21 UTC (rev 2469) +++ abbot.swt/trunk/abbot.swt.test/src/abbot/swt/tester/test/TableTesterTest.java 2007-08-17 14:59:32 UTC (rev 2470) @@ -1,15 +1,18 @@ package abbot.swt.tester.test; import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import abbot.swt.examples.TableSample; import abbot.swt.junit.extensions.SWTTestCase; +import abbot.swt.script.Condition; +import abbot.swt.tester.ShellTester; import abbot.swt.tester.TableTester; -import abbot.swt.tester.WidgetTester; +import abbot.swt.utilities.Displays.BooleanResult; /** * @author hmceuen @@ -23,10 +26,8 @@ private TableSample app; - private TableTester tester; + private TableTester tableTester; - private volatile boolean selected; - public TableTesterTest(String name) { super(name); } @@ -40,10 +41,9 @@ } }); - WidgetTester.waitForShellShowing(TableSample.SHELL_TEXT); - - tester = (TableTester) WidgetTester.getTester(Table.class); - + ShellTester.waitVisible(TableSample.SHELL_TEXT); + + tableTester = TableTester.getTableTester(); } public void tearDown() { @@ -57,76 +57,242 @@ } } - public void testSelectionAndChecking() { + public void testSelectTableColumn() { - tester.actionSelectTableItem(app.table, app.items[3]); - TableItem[] items = tester.getSelectedTableItems(app.table); - assertTrue("Item 3 not selected by item", app.items[3] == items[0]); - sleep(250); + SelectedListener listener2 = new SelectedListener(); + SelectedListener listener1 = new SelectedListener(); - tester.actionSelectTableIndex(app.table, 2); - items = tester.getSelectedTableItems(app.table); - assertTrue("Failed to select multiple items", items.length == 2); - assertTrue("Item 2 not selected by index", app.items[2] == items[0] - || app.items[2] == items[1]); - sleep(250); + addSelectionListener(app.cols[2], listener2); + addSelectionListener(app.cols[1], listener1); - tester.actionCheckTableItem(app.table, app.items[0]); - items = tester.getCheckedTableItems(app.table); - assertTrue("Item 0 not checked by item", app.items[0] == items[0]); - sleep(250); + try { - tester.actionCheckTableIndex(app.table, 4); - items = tester.getCheckedTableItems(app.table); - assertTrue("Item 4 not checkd by index", app.items[4] == items[0] - || app.items[4] == items[1]); - sleep(250); + tableTester.actionClickTableColumnHeader(app.table, app.cols[2]); + listener2.waitEvent(5000L); + tableTester.actionClickTableColumnHeader(app.table, app.cols[1]); + listener1.waitEvent(5000L); + } finally { + removeSelectionListener(app.cols[2], listener2); + removeSelectionListener(app.cols[1], listener1); + } } - public void testSelectTableColumn() { + private class SelectedListener implements SelectionListener { - tester.addListener(app.cols[2], SWT.Selection, new Listener() { - public void handleEvent(Event e) { - selected = true; - } - }); - tester.addListener(app.cols[1], SWT.Selection, new Listener() { - public void handleEvent(Event e) { - selected = true; - } - }); + private SelectionEvent event = null; - selected = false; - tester.actionClickTableColumnHeader(app.table, app.cols[2]); - tester.actionDelay(500); - assertTrue("Failed to select column 2", selected); + public synchronized SelectionEvent getEvent() { + return event; + } - selected = false; - tester.actionClickTableColumnHeader(app.table, app.cols[1]); - tester.actionDelay(500); - assertTrue("Failed to select column 1", selected); + public synchronized void reset() { + event = null; + } + + public void widgetDefaultSelected(SelectionEvent event) { + fail("unexpected"); + } + + public synchronized void widgetSelected(SelectionEvent event) { + assertNull(this.event); + this.event = event; + } + + public SelectionEvent waitEvent(long timeout) { + final SelectionEvent[] eventRef = new SelectionEvent[1]; + tableTester.wait(new Condition() { + public boolean test() { + eventRef[0] = getEvent(); + return eventRef[0] != null; + } + }, timeout); + return eventRef[0]; + } + } + public void testSelectTableItem() { + + // Ensure nothing is selected to start with. + TableItem[] selectedItems = tableTester.getSelectedTableItems(app.table); + assertTrue(selectedItems.length == 0); + + SelectedListener listener = new SelectedListener(); + addSelectionListener(app.table, listener); + + try { + + // Check selecting item 3. + tableTester.actionSelectTableItem(app.table, app.items[3]); + listener.waitEvent(5000L); + TableItem[] items = tableTester.getSelectedTableItems(app.table); + assertTrue(app.items[3] == items[0]); + + // Check selecting item 2 (with 3 already selected). + listener.reset(); + tableTester.actionSelectTableIndex(app.table, 2); + listener.waitEvent(5000L); + items = tableTester.getSelectedTableItems(app.table); + assertTrue(items.length == 2); + assertTrue(app.items[2] == items[0] || app.items[2] == items[1]); + + } finally { + removeSelectionListener(app.table, listener); + } + } + public void testUnselect() { // Assert that it is unselected to start with. - assertTrue(!tester.isSelected(app.table, 0)); + assertTrue(!tableTester.isSelected(app.table, 0)); // Select it and assert that it gets selected. - tester.actionSelectTableItem(app.table, app.items[0]); - tester.actionDelay(300); - assertTrue(tester.isSelected(app.table, 0)); + tableTester.actionSelectTableItem(app.table, app.items[0]); + tableTester.actionDelay(300); + assertTrue(tableTester.isSelected(app.table, 0)); // Select it again and assert that it gets deselected. - tester.actionSelectTableItem(app.table, app.items[0]); - tester.actionDelay(300); - assertTrue(!tester.isSelected(app.table, 0)); + tableTester.actionSelectTableItem(app.table, app.items[0]); + tableTester.actionDelay(300); + assertTrue(!tableTester.isSelected(app.table, 0)); } + public void testCheckTableItem() { + + // Ensure nothing is checked to start with. + TableItem[] checkedItems = tableTester.getCheckedTableItems(app.table); + assertTrue(checkedItems.length == 0); + + // Check a few checks. + checkTest(0, true, 0); + checkTest(4, true, 0, 4); + checkTest(0, false, 4); + checkTest(4, false); + + // Should be nothing checked at this point. + checkedItems = tableTester.getCheckedTableItems(app.table); + assertTrue(checkedItems.length == 0); + } + + private void checkTest(int index, boolean checked, int... expectedIndexes) { + + // Add listener and ensure that it will get removed. + final CheckListener listener = new CheckListener(); + addSelectionListener(app.table, listener); + try { + + // Invoke the method under test. + tableTester.actionCheckItem(app.table, index, checked); + + // Wait for the expected event. + final SelectionEvent[] eventRef = new SelectionEvent[1]; + tableTester.wait(new Condition() { + public boolean test() { + eventRef[0] = listener.getEvent(); + return eventRef[0] != null; + } + }, 5000L); + + // Check that all items' check states are what we expect them to be. + for (int i = 0; i < app.items.length; i++) { + assertSame(contains(i, expectedIndexes), isChecked(app.items[i])); + } + + } finally { + removeSelectionListener(app.table, listener); + } + } + + private boolean contains(int needle, int[] haystack) { + for (int i : haystack) { + if (i == needle) + return true; + } + return false; + } + + private boolean isChecked(final TableItem item) { + return (boolean) syncExec(new BooleanResult() { + public boolean result() { + return item.getChecked(); + } + }); + } + + private void addSelectionListener(final Table table, final SelectionListener listener) { + syncExec(new Runnable() { + public void run() { + table.addSelectionListener(listener); + } + }); + } + + private void removeSelectionListener(final Table table, final SelectionListener listener) { + syncExec(new Runnable() { + public void run() { + table.removeSelectionListener(listener); + } + }); + } + + private void addSelectionListener(final TableColumn tableColumn, + final SelectionListener listener) { + syncExec(new Runnable() { + public void run() { + tableColumn.addSelectionListener(listener); + } + }); + } + + private void removeSelectionListener(final TableColumn tableColumn, + final SelectionListener listener) { + syncExec(new Runnable() { + public void run() { + tableColumn.removeSelectionListener(listener); + } + }); + } + + private class CheckListener implements SelectionListener { + + private SelectionEvent event = null; + + public synchronized SelectionEvent getEvent() { + return event; + } + + public synchronized void reset() { + event = null; + } + + public void widgetDefaultSelected(SelectionEvent event) { + fail("unexpected"); + } + + public synchronized void widgetSelected(SelectionEvent event) { + if (event.widget == app.table && event.detail == SWT.CHECK) { + assertNull(this.event); + this.event = event; + } + } + + public SelectionEvent waitEvent(long timeout) { + final SelectionEvent[] event = new SelectionEvent[1]; + tableTester.wait(new Condition() { + public boolean test() { + event[0] = getEvent(); + return event[0] != null; + } + }, timeout); + return event[0]; + } + + } + // TODO test on tables with images in the items and cols -// public static void main(String[] args) { -// RepeatHelper.runTests(args, TableTesterTest.class); -// } + // public static void main(String[] args) { + // RepeatHelper.runTests(args, TableTesterTest.class); + // } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |