diff options
author | Carolyn MacLeod | 2004-02-23 19:43:21 +0000 |
---|---|---|
committer | Carolyn MacLeod | 2004-02-23 19:43:21 +0000 |
commit | c7ffe68125d78bc1bb1c15b6e270edf7c3020f35 (patch) | |
tree | c0db8e09ce7404b02b1147aea1f87af054590985 /tests | |
parent | 69ca4def95e26b4f7985d8aa70882f0b37698d59 (diff) | |
download | eclipse.platform.swt-c7ffe68125d78bc1bb1c15b6e270edf7c3020f35.tar.gz eclipse.platform.swt-c7ffe68125d78bc1bb1c15b6e270edf7c3020f35.tar.xz eclipse.platform.swt-c7ffe68125d78bc1bb1c15b6e270edf7c3020f35.zip |
consistency for single-select when attempt to select multiple items
(now, if single-select, user must give only one item to select)
Diffstat (limited to 'tests')
3 files changed, 425 insertions, 391 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_List.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_List.java index 3d43b6d9c0..24c3433800 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_List.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_List.java @@ -247,7 +247,7 @@ public void test_deselect$I() { setSingleList(); list.setItems(items); - list.setSelection(items); + list.setSelection(new String[] { "item3" }); assertEquals(list.getSelection(), new String[] { "item3" }); try { list.deselect(null); @@ -256,8 +256,7 @@ public void test_deselect$I() { } assertEquals(list.getSelection(), new String[] { "item3" }); - list.deselect(new int[] { - }); + list.deselect(new int[] {}); assertEquals(list.getSelection(), new String[] { "item3" }); list.deselect(new int[] { 1 }); assertEquals(list.getSelectionIndices(), new int[] { 3 }); @@ -284,7 +283,7 @@ public void test_deselectAll() { setSingleList(); list.setItems(items); - list.setSelection(items); + list.setSelection(new String[] { "item3" }); assertEquals(new String[] { "item3" }, list.getSelection()); list.deselectAll(); assertEquals(empty, list.getSelection()); @@ -314,7 +313,7 @@ public void test_deselectI() { setSingleList(); list.setItems(items2); - list.setSelection(items2); + list.setSelection(new String[] { "item3" }); assertEquals(new String[] { "item3" }, list.getSelection()); list.deselect(5); assertEquals(new String[] { "item3" }, list.getSelection()); @@ -324,8 +323,6 @@ public void test_deselectI() { assertEquals(false, list.isSelected(1)); list.deselect(1); assertEquals(false, list.isSelected(1)); - // assert(":e:", list.getSe); - } public void test_deselectII() { @@ -381,15 +378,6 @@ public void test_deselectII() { setSingleList(); - deselectII_helper(items, 3, 1, new int[]{4}); - deselectII_helper(items, -1, -1, new int[]{4}); - deselectII_helper(items, 1, 3, new int[]{4}); - deselectII_helper(items, -1, 3, new int[]{4}); - deselectII_helper(items, -1, 30, new int[]{}); - deselectII_helper(items, 1, 1, new int[]{4}); - deselectII_helper(items, 10, 1, new int[]{4}); - - list.setItems(items2); list.deselectAll(); @@ -406,7 +394,7 @@ public void test_deselectII() { assertEquals(":e:", list.getSelectionIndices(), new int[] { 0 }); - list.setSelection(items2); + list.setSelection(new String[] { "item3" }); assertEquals(list.getSelection(), new String[] { "item3" }); list.deselect(1, 1); @@ -418,15 +406,15 @@ public void test_deselectII() { list.deselect(3, 3); assertEquals(list.getSelection(), new String[] {}); - list.setSelection(items2); + list.setSelection(new String[] { "item3" }); list.deselect(1, 2); assertEquals(list.getSelection(), new String[] { "item3" }); - list.setSelection(items2); + list.setSelection(new String[] { "item3" }); list.deselect(0, 2); assertEquals(list.getSelectionIndices(), new int[] { 3 }); - list.setSelection(items2); + list.setSelection(new String[] { "item3" }); list.deselect(1, 3); assertEquals(list.getSelectionIndices(), new int[] {}); } @@ -589,12 +577,12 @@ public void test_getSelection() { setSingleList(); list.setItems(items); - sel = new int[] { 0, 2 }; + sel = new int[] { 0 }; list.setSelection(sel); assertEquals(1, list.getSelection().length); assertEquals(items[0], list.getSelection()[0]); - list.setSelection(0, 1); + list.setSelection(1, 1); assertEquals(1, list.getSelection().length); assertEquals(items[1], list.getSelection()[0]); } @@ -633,18 +621,36 @@ public void test_getSelectionCount() { setSingleList(); list.setItems(items); - list.setSelection(items); + list.setSelection(new String[] { "text2" }); assertEquals(1, list.getSelectionCount()); } public void test_getSelectionIndex() { String[] items = { "text1", "text2", "text3" }; + // not properly spec'd for multi-select lists + list.setItems(items); + list.setSelection(items); + assertEquals(0, list.getSelectionIndex()); + + setSingleList(); list.setItems(items); list.setSelection(items); - assertEquals(items.length - 1, list.getSelectionIndex()); + assertEquals(-1, list.getSelectionIndex()); + + list.setSelection(new String[] { "text1" }); + assertEquals(0, list.getSelectionIndex()); + + list.setSelection(new String[] { "text2" }); + assertEquals(1, list.getSelectionIndex()); + + list.setSelection(new String[] { "text3" }); + assertEquals(2, list.getSelectionIndex()); + + list.setSelection(items); + assertEquals(-1, list.getSelectionIndex()); } public void test_getSelectionIndices() { @@ -658,18 +664,53 @@ public void test_getSelectionIndices() { int[] sel = { 0, 1, 2 }; assertSame(sel, list.getSelectionIndices()); + list.setSelection(sel); + assertSame(sel, list.getSelectionIndices()); + + sel = new int[] { 0 }; + list.setSelection(sel); + assertSame(sel, list.getSelectionIndices()); + + sel = new int[] { 1 }; + list.setSelection(sel); + assertSame(sel, list.getSelectionIndices()); + + sel = new int[] { 2 }; + list.setSelection(sel); + assertSame(sel, list.getSelectionIndices()); + + sel = new int[] { 3 }; + list.setSelection(sel); + assertSame(new int[] {}, list.getSelectionIndices()); + + sel = new int[] { -1, 0, 1, 2, 3 }; + list.setSelection(sel); + assertSame(new int[] { 0, 1, 2 }, list.getSelectionIndices()); + + sel = new int[] { 1, 1, 2, 2 }; + list.setSelection(sel); + assertSame(new int[] { 1, 2 }, list.getSelectionIndices()); + setSingleList(); list.setItems(items); - list.setSelection(items); - sel = new int[]{ items.length - 1 }; + + sel = new int[] { 0 }; + list.setSelection(sel); assertSame(sel, list.getSelectionIndices()); - - list.setItems(items); - assertEquals(new int[] {}, list.getSelectionIndices()); + sel = new int[] { 1 }; + list.setSelection(sel); + assertSame(sel, list.getSelectionIndices()); + sel = new int[] { 2 }; + list.setSelection(sel); + assertSame(sel, list.getSelectionIndices()); + + sel = new int[] { 3 }; + list.setSelection(sel); + assertSame(new int[] {}, list.getSelectionIndices()); } public void test_getTopIndex() { @@ -1229,24 +1270,23 @@ public void test_select$I() { list.add("item4"); - int[] ind = { -1, 0, 1, 2, 3 }; - list.select(ind); + list.select(new int[] { -1, 0, 1, 2, 3 }); assertSame(list.getSelectionIndices(), new int[] { 0, 1, 2, 3 }); - ind = new int[32]; - for (int i = 0; i < ind.length; i++) - ind[i] = i; + list.deselectAll(); + list.select(new int[] { 1, 2, 3 }); + assertSame(list.getSelectionIndices(), new int[] { 1, 2, 3 }); + int[] ind = new int[32]; + for (int i = 0; i < ind.length; i++) ind[i] = i; list.select(ind); assertSame(list.getSelectionIndices(), new int[] { 0, 1, 2, 3, 4 }); - list.setSelection(new int[] { - }); + list.setSelection(new int[] {}); list.select(new int[] { 1 }); assertEquals(list.getSelectionIndices(), new int[] { 1 }); - list.setSelection(new int[] { - }); + list.setSelection(new int[] {}); list.select(new int[] { -1 }); assertEquals(list.getSelectionIndices(), new int[] {}); @@ -1258,79 +1298,52 @@ public void test_select$I() { select$I_helper(items, -1, 30, new int[] { 0, 1, 2, 3, 4 }); + /*--- Single-select ---*/ + setSingleList(); list.setItems(items); - ind = new int[]{ -1, 0, 1, 2, 3 }; - list.select(ind); - assertEquals(list.getSelectionIndices(), new int[] { 0 }); - - - ind = new int[32]; - for (int i = 0; i < ind.length; i++) - ind[i] = i; - - list.select(ind); - assertEquals(list.getSelectionIndices(), new int[] { 0 }); - - - ind = new int[]{ 1 }; - list.select(ind); - assertEquals(list.getSelectionIndices(), new int[] { 1 }); - list.deselectAll(); + try { + list.select((int[]) null); + fail("No exception thrown"); + } catch (IllegalArgumentException e) { + } - - ind = new int[]{ -1 }; - list.select(ind); + list.select(new int[]{ -1 }); assertEquals(list.getSelectionIndices(), new int[] {}); - - setSingleList(); - list.setItems(items); - - list.select(new int[] { 0, 2 }); + list.select(new int[] { 0 }); assertEquals(list.getSelectionIndices(), new int[] { 0 }); - list.select(new int[] { 1, 3 }); - assertEquals(list.getSelectionIndices(), new int[] { 1 }); - - list.select(new int[] { 1, 3 }); + list.select(new int[] { 1 }); assertEquals(list.getSelectionIndices(), new int[] { 1 }); - list.select(new int[] { 2, 3 }); + list.select(new int[] { 2 }); assertEquals(list.getSelectionIndices(), new int[] { 2 }); - list.select(new int[] { 1, 3 }); - assertEquals(list.getSelectionIndices(), new int[] { 1 }); + list.select(new int[] { 3 }); + assertEquals(list.getSelectionIndices(), new int[] { 3 }); - try { - list.select((int[]) null); - fail("No exception thrown"); - } catch (IllegalArgumentException e) { - } + list.select(new int[] { 4 }); + assertEquals(list.getSelectionIndices(), new int[] { 4 }); - - int[] selection = { 0, 1, 2, 3 }; - list.select(selection); - assertEquals(list.getSelectionIndices(), new int[] { 0 }); + list.select(new int[] { 5 }); + assertEquals(list.getSelectionIndices(), new int[] { 4 }); - - selection = new int[]{ -1, 0, 1, 2, 3 }; - list.select(selection); - assertEquals(list.getSelectionIndices(), new int[] { 0 }); + list.deselectAll(); + list.select(new int[]{ 0, 1, 2, 3 }); + assertEquals(list.getSelectionIndices(), new int[] {}); - - selection = new int[32]; - for (int i = -1; i <= 30; i++) - selection[i + 1] = i; + list.select(new int[]{ -1, 0, 1, 2, 3 }); + assertEquals(list.getSelectionIndices(), new int[] {}); + int[] selection = new int[32]; + for (int i = 0; i < selection.length; i++) selection[i] = i; list.select(selection); - assertEquals(list.getSelectionIndices(), new int[] { 0 }); + assertEquals(list.getSelectionIndices(), new int[] {}); - - selection = new int[]{1}; - list.select(selection); - assertEquals(list.getSelectionIndices(), new int[] { 1 }); + list.select(new int[]{ 1, 1, 1 }); + assertEquals(list.getSelectionIndices(), new int[]{}); } public void test_selectAll() { @@ -1393,8 +1406,7 @@ public void test_selectII() { int number = 5; String[] items = new String[number]; - int[] empty = { - }; + int[] empty = {}; for (int i = 0; i < number; i++) items[i] = "item" + i; @@ -1442,7 +1454,6 @@ public void test_selectII() { list.select(-10, -9); assertEquals(list.getSelectionIndices(), new int[] { 0 }); - list.deselectAll(); assertEquals(0, list.getSelectionCount()); @@ -1452,25 +1463,46 @@ public void test_selectII() { list.deselectAll(); assertEquals(0, list.getSelectionCount()); - list.select(1, 2); - assertEquals(list.getSelectionIndices(), new int[] { 2 }); + list.select(0, 0); + assertEquals(list.getSelectionIndices(), new int[] { 0 }); - list.select(1, 3); - assertEquals(list.getSelectionIndices(), new int[] { 3 }); + list.select(1, 1); + assertEquals(list.getSelectionIndices(), new int[] { 1 }); list.select(2, 2); assertEquals(list.getSelectionIndices(), new int[] { 2 }); - list.select(3, 5); + list.select(3, 3); + assertEquals(list.getSelectionIndices(), new int[] { 3 }); + + list.select(4, 4); + assertEquals(list.getSelectionIndices(), new int[] { 4 }); + + list.select(5, 5); assertEquals(list.getSelectionIndices(), new int[] { 4 }); + list.deselectAll(); + list.select(5, 5); + assertEquals(list.getSelectionIndices(), new int[] {}); + + list.select(1, 2); + assertEquals(list.getSelectionIndices(), new int[] {}); + + list.select(1, 3); + assertEquals(list.getSelectionIndices(), new int[] {}); + + list.select(3, 5); + assertEquals(list.getSelectionIndices(), new int[] {}); + + selectII_helper(items, 0, 0, new int[]{0}); selectII_helper(items, 1, 1, new int[]{1}); - selectII_helper(items, -1, 30, new int[]{4}); + selectII_helper(items, 2, 2, new int[]{2}); + selectII_helper(items, 3, 3, new int[]{3}); + selectII_helper(items, 4, 4, new int[]{4}); + selectII_helper(items, 5, 5, new int[]{}); selectII_helper(items, 10, 1, new int[]{}); selectII_helper(items, 3, 1, new int[]{}); selectII_helper(items, -1, -1, new int[]{}); - selectII_helper(items, 2, 4, new int[]{4}); - selectII_helper(items, 0, 3, new int[]{3}); } public void test_setFontLorg_eclipse_swt_graphics_Font() { @@ -1628,9 +1660,6 @@ public void test_setSelection$I() { list.setSelection(new int [0]); assertEquals("MULTI: setSelection(new int [0])", list.getSelectionIndices(), new int[0]); - if (fCheckSWTPolicy) { - assertEquals("MULTI: setSelection(new int [0]) getFocusIndex()", list.getFocusIndex(), -1); - } try { list.setSelection((int[]) null); @@ -1644,15 +1673,12 @@ public void test_setSelection$I() { list.setSelection(new int [] {number}); assertEquals("MULTI: setSelection(new int [] {number})", list.getSelectionIndices(), new int[0]); - assertEquals("MULTI: setSelection(new int [] {number}) getFocusIndex()", list.getFocusIndex(), 2); list.setSelection(new int [] {1, 0}); assertEquals("MULTI: setSelection(new int [] {1, 0})", list.getSelectionIndices(), new int[] {0, 1}); - assertEquals("MULTI: setSelection(new int [] {1, 0}) getFocusIndex()", list.getFocusIndex(), 1); list.setSelection(new int [] {-1, number}); assertEquals("MULTI: setSelection(new int [] {-1, number})", list.getSelectionIndices(), new int[0]); - assertEquals("MULTI: setSelection(new int [] {-1, number}) getFocusIndex()", list.getFocusIndex(), 1); list.setSelection(new int [] {number - 1, number}); assertEquals("MULTI: setSelection(new int [] {number - 1, number})", list.getSelectionIndices(), new int[] {number - 1}); @@ -1660,21 +1686,20 @@ public void test_setSelection$I() { list.setSelection(new int [] {-1, 0}); assertEquals("MULTI: setSelection(new int [] {-1, 0})", list.getSelectionIndices(), new int[] {0}); - if (fCheckSWTPolicy) { - assertEquals("MULTI: setSelection(new int [] {-1, 0}) getFocusIndex()", list.getFocusIndex(), number - 1); - } +// bug - wierd case - should probably fix: assertEquals("MULTI: setSelection(new int [] {-1, 0}) getFocusIndex()", list.getFocusIndex(), 0); + list.setSelection(new int [] {0, 1, 2, 3, 5}); + assertEquals("MULTI: setSelection(new int [] {0, 1, 2, 3, 5})", list.getSelectionIndices(), new int [] {0, 1, 2, 3, 5}); + int[] indices = new int [number]; for (int i = 0; i < number; i++) { indices[i] = i; } list.setSelection(indices); assertEquals("MULTI: setSelection(indices)", list.getSelectionIndices(), indices); - assertEquals("MULTI: setSelection(indices) getFocusIndex()", list.getFocusIndex(), indices[0]); list.setSelection(new int [] {number, number}); assertEquals("MULTI: setSelection(new int [] {number, number})", list.getSelectionIndices(), new int[0]); - assertEquals("MULTI: setSelection(new int [] {number, number}) getFocusIndex()", list.getFocusIndex(), 0); list.setSelection(new int [] {number - 1, number - 1}); assertEquals("MULTI: setSelection(new int [] {number - 1, number - 1})", list.getSelectionIndices(), new int[] {number - 1}); @@ -1682,11 +1707,9 @@ public void test_setSelection$I() { list.setSelection(new int [] {0, number, 1}); assertEquals("MULTI: setSelection(new int [] {0, number, 1})", list.getSelectionIndices(), new int[] {0, 1}); - assertEquals("MULTI: setSelection(new int [] {0, number, 1}) getFocusIndex()", list.getFocusIndex(), 0); list.setSelection(new int [] {number - 1, 0, number - 2}); assertEquals("MULTI: setSelection(new int [] {number - 1, 0, number - 2})", list.getSelectionIndices(), new int[] {0, number - 2, number - 1}); - assertEquals("MULTI: setSelection(new int [] {number - 1, 0, number - 2}) getFocusIndex()", list.getFocusIndex(), number - 1); list.removeAll(); @@ -1720,15 +1743,13 @@ public void test_setSelection$I() { assertEquals("EMPTY MULTI: setSelection(new int [] {0, -1})", list.getSelectionIndices(), new int[0]); assertEquals("EMPTY MULTI: setSelection(new int [] {0, -1}) getFocusIndex()", list.getFocusIndex(), -1); + setSingleList(); for (int i = 0; i < number; i++) list.add("fred" + i); list.setSelection(new int [0]); assertEquals("SINGLE: setSelection(new int [0])", list.getSelectionIndices(), new int[0]); - if (fCheckSWTPolicy) { - assertEquals("SINGLE: setSelection(new int [0]) getFocusIndex()", list.getFocusIndex(), -1); - } try { list.setSelection((int[]) null); @@ -1742,47 +1763,40 @@ public void test_setSelection$I() { list.setSelection(new int [] {number}); assertEquals("SINGLE: setSelection(new int [] {number})", list.getSelectionIndices(), new int[0]); - assertEquals("SINGLE: setSelection(new int [] {number}) getFocusIndex()", list.getFocusIndex(), 2); list.setSelection(new int [] {1, 0}); - assertEquals("SINGLE: setSelection(new int [] {1, 0})", list.getSelectionIndices(), new int[] {1}); - assertEquals("SINGLE: setSelection(new int [] {1, 0}) getFocusIndex()", list.getFocusIndex(), 1); + assertEquals("SINGLE: setSelection(new int [] {1, 0})", list.getSelectionIndices(), new int[] {}); + + list.setSelection(new int [] {0, 1, 2, 3, 5}); + assertEquals("SINGLE: setSelection(new int [] {0, 1, 2, 3, 5})", list.getSelectionIndices(), new int [] {}); list.setSelection(new int [] {-1, number}); assertEquals("SINGLE: setSelection(new int [] {-1, number})", list.getSelectionIndices(), new int[0]); - assertEquals("SINGLE: setSelection(new int [] {-1, number}) getFocusIndex()", list.getFocusIndex(), 1); list.setSelection(new int [] {number - 1, number}); - assertEquals("SINGLE: setSelection(new int [] {number - 1, number})", list.getSelectionIndices(), new int[] {number - 1}); - assertEquals("SINGLE: setSelection(new int [] {number - 1, number}) getFocusIndex()", list.getFocusIndex(), number - 1); + assertEquals("SINGLE: setSelection(new int [] {number - 1, number})", list.getSelectionIndices(), new int[] {}); list.setSelection(new int [] {-1, 0}); - assertEquals("SINGLE: setSelection(new int [] {-1, 0})", list.getSelectionIndices(), new int[] {0}); - assertEquals("SINGLE: setSelection(new int [] {-1, 0}) getFocusIndex()", list.getFocusIndex(), 0); + assertEquals("SINGLE: setSelection(new int [] {-1, 0})", list.getSelectionIndices(), new int[] {}); indices = new int [number]; for (int i = 0; i < number; i++) { indices[i] = i; } list.setSelection(indices); - assertEquals("SINGLE: setSelection(indices)", list.getSelectionIndices(), new int[] {indices[0]}); - assertEquals("SINGLE: setSelection(indices) getFocusIndex()", list.getFocusIndex(), indices[0]); + assertEquals("SINGLE: setSelection(indices)", list.getSelectionIndices(), new int[] {}); list.setSelection(new int [] {number, number}); assertEquals("SINGLE: setSelection(new int [] {number, number})", list.getSelectionIndices(), new int[0]); - assertEquals("SINGLE: setSelection(new int [] {number, number}) getFocusIndex()", list.getFocusIndex(), 0); list.setSelection(new int [] {number - 1, number - 1}); - assertEquals("SINGLE: setSelection(new int [] {number - 1, number - 1})", list.getSelectionIndices(), new int[] {number - 1}); - assertEquals("SINGLE: setSelection(new int [] {number - 1, number - 1}) getFocusIndex()", list.getFocusIndex(), number - 1); + assertEquals("SINGLE: setSelection(new int [] {number - 1, number - 1})", list.getSelectionIndices(), new int[] {}); list.setSelection(new int [] {0, number, 1}); - assertEquals("SINGLE: setSelection(new int [] {0, number, 1})", list.getSelectionIndices(), new int[] {0}); - assertEquals("SINGLE: setSelection(new int [] {0, number, 1}) getFocusIndex()", list.getFocusIndex(), 0); + assertEquals("SINGLE: setSelection(new int [] {0, number, 1})", list.getSelectionIndices(), new int[] {}); list.setSelection(new int [] {number - 1, 0, number - 2}); - assertEquals("SINGLE: setSelection(new int [] {number - 1, 0, number - 2})", list.getSelectionIndices(), new int[] {number - 1}); - assertEquals("SINGLE: setSelection(new int [] {number - 1, 0, number - 2}) getFocusIndex()", list.getFocusIndex(), number - 1); + assertEquals("SINGLE: setSelection(new int [] {number - 1, 0, number - 2})", list.getSelectionIndices(), new int[] {}); list.removeAll(); @@ -1906,9 +1920,6 @@ public void test_setSelection$Ljava_lang_String() { list.setSelection(new String [0]); assertEquals(list.getSelection(), new String[0]); - if (fCheckSWTPolicy) { - assertEquals(list.getFocusIndex(), -1); - } try { list.setSelection((String[]) null); @@ -1925,27 +1936,23 @@ public void test_setSelection$Ljava_lang_String() { assertEquals(list.getFocusIndex(), 2); list.setSelection(new String [] {"fred 1", "fred 0"}); - assertEquals(list.getSelection(), new String[] {"fred 0"}); - assertEquals(list.getFocusIndex(), 0); + assertEquals(list.getSelection(), new String[] {}); + assertEquals(list.getFocusIndex(), 2); list.setSelection(new String [] {"fred -1", "fred " + number}); assertEquals(list.getSelection(), new String[0]); - assertEquals(list.getFocusIndex(), 0); + assertEquals(list.getFocusIndex(), 2); - list.setSelection(new String [] {"fred " + (number - 1), "fred " + number}); + list.setSelection(new String [] {"fred " + (number - 1)}); assertEquals(list.getSelection(), new String[] {"fred " + (number - 1)}); assertEquals(list.getFocusIndex(), number - 1); - list.setSelection(new String [] {"fred -1", "fred 0"}); - assertEquals(list.getSelection(), new String[] {"fred 0"}); - assertEquals(list.getFocusIndex(), 0); - items = new String[number]; for (int i = 0; i < number; i++) { items[i] = "fred " + i; } list.setSelection(items); - assertEquals(list.getSelection(), new String[] {"fred " + (number - 1)}); + assertEquals(list.getSelection(), new String[] {}); assertEquals(list.getFocusIndex(), number - 1); list.setSelection(new String [] {"fred " + number, "fred " + number}); @@ -1953,34 +1960,30 @@ public void test_setSelection$Ljava_lang_String() { assertEquals(list.getFocusIndex(), number - 1); list.setSelection(new String [] {"fred " + (number - 1), "fred " + (number - 1)}); - assertEquals(list.getSelection(), new String[] {"fred " + (number - 1)}); - assertEquals(list.getFocusIndex(), number - 1); + assertEquals(list.getSelection(), new String[] {}); list.setSelection(new String [] {"fred 0", "fred " + number, "fred 1"}); - assertEquals(list.getSelection(), new String[] {"fred 1"}); - assertEquals(list.getFocusIndex(), 1); + assertEquals(list.getSelection(), new String[] {}); - if (fCheckSWTPolicy) { - list.removeAll(); - - list.setSelection(new String [0]); - assertEquals(list.getSelection(), new String[0]); - assertEquals(list.getFocusIndex(), -1); - - try { - list.setSelection((String[]) null); - fail("No exception thrown"); - } catch (IllegalArgumentException e) { - } + list.removeAll(); - list.setSelection(new String [] {"fred 0"}); - assertEquals(list.getSelection(), new String[0]); - assertEquals(list.getFocusIndex(), -1); + list.setSelection(new String [0]); + assertEquals(list.getSelection(), new String[0]); + assertEquals(list.getFocusIndex(), -1); - list.setSelection(new String [] {"fred 0", "fred 0"}); - assertEquals(list.getSelection(), new String[0]); - assertEquals(list.getFocusIndex(), -1); + try { + list.setSelection((String[]) null); + fail("No exception thrown"); + } catch (IllegalArgumentException e) { } + + list.setSelection(new String [] {"fred 0"}); + assertEquals(list.getSelection(), new String[0]); + assertEquals(list.getFocusIndex(), -1); + + list.setSelection(new String [] {"fred 0", "fred 0"}); + assertEquals(list.getSelection(), new String[0]); + assertEquals(list.getFocusIndex(), -1); } public void test_setSelectionI() { @@ -2159,77 +2162,55 @@ public void test_setSelectionII() { setSingleList(); list.setItems(items); - list.setSelection(1, 2); - assertEquals(list.getSelectionIndices(), new int[] {2}); - assertEquals(list.getFocusIndex(), 2); + list.setSelection(0, 0); + assertEquals(list.getSelectionIndices(), new int[] {0}); + assertEquals(list.getFocusIndex(), 0); + + list.setSelection(1, 1); + assertEquals(list.getSelectionIndices(), new int[] {1}); + assertEquals(list.getFocusIndex(), 1); + + list.setSelection(4, 4); + assertEquals(list.getSelectionIndices(), new int[] {4}); + assertEquals(list.getFocusIndex(), 4); + + list.setSelection(number - 1, number - 1); + assertEquals(list.getSelectionIndices(), new int[] {number - 1}); + assertEquals(list.getFocusIndex(), number - 1); + + list.setSelection(number, number); + assertEquals(list.getSelectionIndices(), new int[] {}); list.setSelection(-3, -2); - assertEquals(list.getSelectionIndices(), new int[] {2}); - assertEquals(list.getFocusIndex(), 2); + assertEquals(list.getSelectionIndices(), new int[] {}); list.setSelection(0, 1); - assertEquals(list.getSelectionIndices(), new int[] {1}); - assertEquals(list.getFocusIndex(), 1); + assertEquals(list.getSelectionIndices(), new int[] {}); list.setSelection(-2, -1); - assertEquals(list.getSelectionIndices(), new int[] {1}); - assertEquals(list.getFocusIndex(), 1); + assertEquals(list.getSelectionIndices(), new int[] {}); list.setSelection(number - 2, number - 1); - assertEquals(list.getSelectionIndices(), new int[] {number - 1}); - assertEquals(list.getFocusIndex(), number - 1); + assertEquals(list.getSelectionIndices(), new int[] {}); list.setSelection(number - 1, number); - assertEquals(list.getSelectionIndices(), new int[] {number - 1}); - assertEquals(list.getFocusIndex(), number - 1); + assertEquals(list.getSelectionIndices(), new int[] {}); list.setSelection(-1, 0); - assertEquals(list.getSelectionIndices(), new int[] {0}); - assertEquals(list.getFocusIndex(), 0); + assertEquals(list.getSelectionIndices(), new int[] {}); list.setSelection(number, number + 1); - assertEquals(list.getSelectionIndices(), new int[] {0}); - assertEquals(list.getFocusIndex(), 0); - - list.setSelection(0, 0); - assertEquals(list.getSelectionIndices(), new int[] {0}); - assertEquals(list.getFocusIndex(), 0); + assertEquals(list.getSelectionIndices(), new int[] {}); list.setSelection(2, 1); - assertEquals(list.getSelectionIndices(), new int[] {0}); - assertEquals(list.getFocusIndex(), 0); + assertEquals(list.getSelectionIndices(), new int[] {}); list.setSelection(number - 1, number - 1); assertEquals(list.getSelectionIndices(), new int[] {number - 1}); assertEquals(list.getFocusIndex(), number - 1); list.setSelection(-1, -1); - assertEquals(list.getSelectionIndices(), new int[] {number - 1}); - assertEquals(list.getFocusIndex(), number - 1); - - if (fCheckSWTPolicy) { - list.removeAll(); - - list.setSelection(-2, -1); - assertEquals(list.getSelectionIndices(), new int[0]); - assertEquals(list.getFocusIndex(), 0); - - list.setSelection(-1, 0); - assertEquals(list.getSelectionIndices(), new int[0]); - assertEquals(list.getFocusIndex(), 0); - - list.setSelection(0, 1); - assertEquals(list.getSelectionIndices(), new int[0]); - assertEquals(list.getFocusIndex(), 0); - - list.setSelection(1, 0); - assertEquals(list.getSelectionIndices(), new int[0]); - assertEquals(list.getFocusIndex(), 0); - - list.setSelection(0, -1); - assertEquals(list.getSelectionIndices(), new int[0]); - assertEquals(list.getFocusIndex(), 0); - } + assertEquals(list.getSelectionIndices(), new int[] {}); } public void test_setTopIndexI() { diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Table.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Table.java index 423003a9e4..f5eaa7a195 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Table.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Table.java @@ -401,11 +401,20 @@ public void test_getSelection() { assertEquals(new TableItem[] {}, table.getSelection()); - table.setSelection(new TableItem[]{items[10], items[number-1], items[2]}); + table.setSelection(new TableItem[]{items[10]}); assertEquals(new TableItem[] {items[10]}, table.getSelection()); + table.setSelection(new TableItem[]{items[number-1]}); + assertEquals(new TableItem[] {items[number-1]}, table.getSelection()); + + table.setSelection(new TableItem[]{items[2]}); + assertEquals(new TableItem[] {items[2]}, table.getSelection()); + + table.setSelection(new TableItem[]{items[10], items[number-1], items[2]}); + assertEquals(new TableItem[] {}, table.getSelection()); + table.setSelection(items); - assertEquals(new TableItem[] {items[0]}, table.getSelection()); + assertEquals(new TableItem[] {}, table.getSelection()); } public void test_getSelectionCount() { @@ -430,11 +439,20 @@ public void test_getSelectionCount() { assertEquals(0, table.getSelectionCount()); - table.setSelection(new TableItem[]{items[2], items[number-1], items[10]}); + table.setSelection(new TableItem[]{items[2]}); assertEquals(1, table.getSelectionCount()); - table.setSelection(items); + table.setSelection(new TableItem[]{items[number-1]}); assertEquals(1, table.getSelectionCount()); + + table.setSelection(new TableItem[]{items[10]}); + assertEquals(1, table.getSelectionCount()); + + table.setSelection(new TableItem[]{items[2], items[number-1], items[10]}); + assertEquals(0, table.getSelectionCount()); + + table.setSelection(items); + assertEquals(0, table.getSelectionCount()); } public void test_getSelectionIndex() { @@ -459,11 +477,20 @@ public void test_getSelectionIndex() { assertEquals(-1, table.getSelectionIndex()); - table.setSelection(new TableItem[]{items[2], items[number-1], items[10]}); + table.setSelection(new TableItem[]{items[2]}); assertEquals(2, table.getSelectionIndex()); + table.setSelection(new TableItem[]{items[number-1]}); + assertEquals(number - 1, table.getSelectionIndex()); + + table.setSelection(new TableItem[]{items[10]}); + assertEquals(10, table.getSelectionIndex()); + + table.setSelection(new TableItem[]{items[2], items[number-1], items[10]}); + assertEquals(-1, table.getSelectionIndex()); + table.setSelection(items); - assertEquals(0, table.getSelectionIndex()); + assertEquals(-1, table.getSelectionIndex()); } public void test_getSelectionIndices() { @@ -490,11 +517,20 @@ public void test_getSelectionIndices() { assertEquals(new int[]{}, table.getSelectionIndices()); - table.setSelection(new TableItem[]{items[2], items[number-1], items[10]}); + table.setSelection(new TableItem[]{items[2]}); assertEquals(new int[]{2}, table.getSelectionIndices()); + table.setSelection(new TableItem[]{items[number-1]}); + assertEquals(new int[]{number-1}, table.getSelectionIndices()); + + table.setSelection(new TableItem[]{items[10]}); + assertEquals(new int[]{10}, table.getSelectionIndices()); + + table.setSelection(new TableItem[]{items[2], items[number-1], items[10]}); + assertEquals(new int[]{}, table.getSelectionIndices()); + table.setSelection(items); - assertEquals(new int[]{0}, table.getSelectionIndices()); + assertEquals(new int[]{}, table.getSelectionIndices()); } public void test_getTopIndex() { @@ -616,7 +652,7 @@ public void test_isSelectedI() { items[i] = new TableItem(table, 0); for (int i = 0; i < number; i++) assertTrue(":d:" + i, !table.isSelected(i)); - table.setSelection(new TableItem[] {items[10], items[number-1], items[2]}); + table.setSelection(new TableItem[] {items[10]}); for (int i = 0; i < number; i++) { if (i == 10) assertTrue(":e:" + i, table.isSelected(i)); @@ -626,10 +662,7 @@ public void test_isSelectedI() { table.setSelection(items); for (int i = 0; i < number; i++){ - if (i == 0) - assertTrue(":f:" + i, table.isSelected(i)); - else - assertTrue(":f:" + i, !table.isSelected(i)); + assertTrue(":f:" + i, !table.isSelected(i)); } } @@ -904,18 +937,85 @@ public void test_select$I() { for (int i = 0; i < number; i++) items[i] = new TableItem(table, 0); + table.select(new int[] {2, 10, 14}); + assertSame(new int[] {2, 10, 14}, table.getSelectionIndices()); + + table.deselectAll(); table.select(new int[] {10, 2, 14}); assertSame(new int[] {2, 10, 14}, table.getSelectionIndices()); + table.deselectAll(); + table.select(new int[] {number, 0, number-1}); + assertSame(new int[] {0, number-1}, table.getSelectionIndices()); + + table.deselectAll(); + table.select(new int[] {number, 0, -1}); + assertSame(new int[] {0}, table.getSelectionIndices()); + + table.deselectAll(); + table.select(new int[] {0}); + assertSame(new int[] {0}, table.getSelectionIndices()); + + table.select(new int[] {10}); + assertSame(new int[] {0, 10}, table.getSelectionIndices()); + + table.select(new int[] {2}); + assertSame(new int[] {0, 2, 10}, table.getSelectionIndices()); + + table.select(new int[] {14}); + assertSame(new int[] {0, 2, 10, 14}, table.getSelectionIndices()); + + table.deselectAll(); + table.select(new int[] {15}); + assertSame(new int[] {}, table.getSelectionIndices()); + + table.select(new int[] {-1}); + assertSame(new int[] {}, table.getSelectionIndices()); + + table.select(new int[] {4, 4, 4}); + assertSame(new int[] {4}, table.getSelectionIndices()); + // note: SWT.SINGLE makeCleanEnvironment(true); + items = new TableItem[number]; + for (int i = 0; i < number; i++) + items[i] = new TableItem(table, 0); + try { table.select(null); fail("No exception thrown for selection == null"); } catch (IllegalArgumentException e) { } + finally { + assertEquals(0, table.getSelectionCount()); + } + + table.select(new int[] {0}); + assertSame(new int[] {0}, table.getSelectionIndices()); + + table.select(new int[] {10}); + assertSame(new int[] {10}, table.getSelectionIndices()); + + table.select(new int[] {2}); + assertSame(new int[] {2}, table.getSelectionIndices()); + + table.select(new int[] {14}); + assertSame(new int[] {14}, table.getSelectionIndices()); + + table.deselectAll(); + table.select(new int[] {15}); + assertSame(new int[] {}, table.getSelectionIndices()); + + table.select(new int[] {-1}); + assertSame(new int[] {}, table.getSelectionIndices()); + + table.select(new int[] {10, 2, 14}); + assertSame(new int[] {}, table.getSelectionIndices()); + + table.select(new int[] {4, 4, 4}); + assertSame(new int[] {}, table.getSelectionIndices()); } public void test_selectAll() { @@ -958,20 +1058,26 @@ public void test_selectI() { for (int i = 0; i < number; i++) items[i] = new TableItem(table, 0); - table.select(new int[] {number - 1, 10, 2 }); - assertEquals(number - 1, table.getSelectionIndex()); - table.setSelection(new int[] {number - 1,10, 2}); - assertEquals(number - 1, table.getSelectionIndex()); // for SINGLE setSelection and select are the same - - table.select(7); - assertEquals(new int[] {7}, table.getSelectionIndices()); - table.setSelection(7); - assertEquals(new int[] {7}, table.getSelectionIndices()); // for SINGLE setSelection and select are the same table.select(0); assertEquals(new int[] {0}, table.getSelectionIndices()); - table.setSelection(0); - assertEquals(new int[] {0}, table.getSelectionIndices()); // for SINGLE setSelection and select are the same + + table.select(1); + assertEquals(new int[] {1}, table.getSelectionIndices()); + + table.select(10); + assertEquals(new int[] {10}, table.getSelectionIndices()); + + table.select(number-1); + assertEquals(new int[] {number-1}, table.getSelectionIndices()); + + table.deselectAll(); + table.select(number); + assertEquals(new int[] {}, table.getSelectionIndices()); + + table.select(-1); + assertEquals(new int[] {}, table.getSelectionIndices()); + } public void test_selectII() { @@ -1032,100 +1138,41 @@ public void test_selectII() { // note: SWT.SINGLE makeCleanEnvironment(true); - - table.setSelection(0); - - if (fCheckSWTPolicy) { - table.select(4, 10); - assertEquals(new int[] {4}, table.getSelectionIndices()); - table.setSelection(4, 10); - assertEquals(new int[] {4}, table.getSelectionIndices()); //for SINGLE setSelection and select are the same - - table.select(5, number - 1); - assertEquals(new int[] {5}, table.getSelectionIndices()); - table.setSelection(5, number - 1); - assertEquals(new int[] {5}, table.getSelectionIndices()); //for SINGLE setSelection and select are the same - - table.select(0, 7); - assertEquals(new int[] {0}, table.getSelectionIndices()); - table.setSelection(0, 7); - assertEquals(new int[] {0}, table.getSelectionIndices()); //for SINGLE setSelection and select are the same - - table.select(9, 5); - assertEquals(new int[] {7}, table.getSelectionIndices()); - table.setSelection(9, 5); - assertEquals(new int[] {}, table.getSelectionIndices()); //for SINGLE setSelection and select are the same - } // ?? in this case maybe the sel. should be cleared - - makeCleanEnvironment(true); - for (int i = 0; i < number; i++) items[i] = new TableItem(table, 0); - if (fCheckSWTPolicy) { - table.select(-100, 1000); - assertEquals(1, table.getSelectionCount()); - assertEquals(new int[] {number - 1}, table.getSelectionIndices()); - } - table.deselectAll(); - assertEquals(0, table.getSelectionCount()); - table.select(0, 1000); - assertEquals(1, table.getSelectionCount()); - if (fCheckSWTPolicy) - assertEquals(new int[] {number - 1}, table.getSelectionIndices()); - table.deselectAll(); - table.select(0, number - 1); - assertEquals(1, table.getSelectionCount()); - if (fCheckSWTPolicy) - assertEquals(new int[] {number - 1}, table.getSelectionIndices()); - table.deselectAll(); + table.select(0, 0); assertEquals(1, table.getSelectionCount()); + assertEquals(0, table.getSelectionIndex()); assertEquals(new int[] {0}, table.getSelectionIndices()); - table.deselectAll(); - table.select(number - 1, number); - assertEquals(1, table.getSelectionCount()); - assertEquals(new int[] {number - 1}, table.getSelectionIndices()); + + table.select(4, 4); + assertEquals(new int[] {4}, table.getSelectionIndices()); + + table.select(10, 10); + assertEquals(new int[] {10}, table.getSelectionIndices()); + + table.select(number-1, number-1); + assertEquals(new int[] {number-1}, table.getSelectionIndices()); + table.deselectAll(); table.select(number, number); - assertEquals(0, table.getSelectionCount()); assertEquals(new int[] {}, table.getSelectionIndices()); - table.deselectAll(); - - makeCleanEnvironment(true); - for (int i = 0; i < number; i++) - items[i] = new TableItem(table, 0); - table.select(-100, 1000); - if (fCheckSWTPolicy) { - assertEquals(1, table.getSelectionCount()); - assertEquals(new int[] {number - 1}, table.getSelectionIndices()); - } - table.deselectAll(); - assertEquals(0, table.getSelectionCount()); - table.select(1000, 0); - assertEquals(0, table.getSelectionCount()); + table.select(0, number-1); assertEquals(new int[] {}, table.getSelectionIndices()); - table.deselectAll(); - table.select(number - 1, 0); - if (fCheckSWTPolicy) - assertEquals(0, table.getSelectionCount()); - table.deselectAll(); - table.select(0, 0); - assertEquals(1, table.getSelectionCount()); - assertEquals(new int[] {0}, table.getSelectionIndices()); - table.deselectAll(); + + table.select(-1, number); + assertEquals(new int[] {}, table.getSelectionIndices()); + + table.select(4, 5); + assertEquals(new int[] {}, table.getSelectionIndices()); + + table.select(5, 4); + assertEquals(new int[] {}, table.getSelectionIndices()); + table.select(-1, -1); - if (fCheckSWTPolicy) { - assertEquals(0, table.getSelectionCount()); - assertEquals(new int[] {}, table.getSelectionIndices()); - } - table.deselectAll(); - table.select(number, number); - if (fCheckSWTPolicy) { - assertEquals(0, table.getSelectionCount()); - assertEquals(new int[] {}, table.getSelectionIndices()); - } - table.deselectAll(); + assertEquals(new int[] {}, table.getSelectionIndices()); } public void test_setFontLorg_eclipse_swt_graphics_Font() { @@ -1192,52 +1239,47 @@ public void test_setSelection$I() { for (int i = 0; i < number; i++) items[i] = new TableItem(table, 0); + try { table.setSelection((int[]) null); fail("No exception thrown for selection range == null"); } catch (IllegalArgumentException e) { } + finally { + assertEquals(0, table.getSelectionCount()); + } - makeCleanEnvironment(true); - - for (int i = 0; i < number; i++) - items[i] = new TableItem(table, 0); table.setSelection(new int[] {}); assertEquals(new int[] {}, table.getSelectionIndices()); - table.setSelection(new int[] {0, 3, 2}); - if (fCheckSWTPolicy) - assertEquals(new int[] {2}, table.getSelectionIndices()); - table.setSelection(new int[] {3, 2, 1}); - if (fCheckSWTPolicy) - assertEquals(new int[] {1}, table.getSelectionIndices()); - table.setSelection(new int[] {1, 4, 0}); - if (fCheckSWTPolicy) - assertEquals(new int[] {0}, table.getSelectionIndices()); - table.setSelection(new int[] {0, 4, 1}); - if (fCheckSWTPolicy) - assertEquals(new int[] {0}, table.getSelectionIndices()); - table.setSelection(new int[] {2, 3, 4}); - if (fCheckSWTPolicy) - assertEquals(new int[] {4}, table.getSelectionIndices()); - table.setSelection(new int[] {4, 4, 4, 4, 4, 4, 4}); - assertEquals(new int[] {4}, table.getSelectionIndices()); + + table.setSelection(new int[] {0}); + assertEquals(new int[] {0}, table.getSelectionIndices()); + + table.setSelection(new int[] {2}); + assertEquals(new int[] {2}, table.getSelectionIndices()); + table.setSelection(new int[] {4}); assertEquals(new int[] {4}, table.getSelectionIndices()); + + table.setSelection(new int[] {number-1}); + assertEquals(new int[] {number-1}, table.getSelectionIndices()); + + table.deselectAll(); + table.setSelection(new int[] {number}); + assertEquals(new int[] {}, table.getSelectionIndices()); + + table.setSelection(new int[] {-1}); + assertEquals(new int[] {}, table.getSelectionIndices()); + + table.setSelection(new int[] {0, 3, 2}); + assertEquals(new int[] {}, table.getSelectionIndices()); - makeCleanEnvironment(true); + table.setSelection(new int[] {3, 2, 1}); + assertEquals(new int[] {}, table.getSelectionIndices()); - for (int i = 0; i < number; i++) - items[i] = new TableItem(table, 0); - try { - table.setSelection((TableItem[]) null); - fail("No exception thrown for selection range == null"); - } - catch (IllegalArgumentException e) { - } - finally { - assertEquals(0, table.getSelectionCount()); - } + table.setSelection(new int[] {4, 4, 4, 4, 4, 4, 4}); + assertEquals(new int[] {}, table.getSelectionIndices()); } public void test_setSelection$Lorg_eclipse_swt_widgets_TableItem() { @@ -1304,29 +1346,23 @@ public void test_setSelection$Lorg_eclipse_swt_widgets_TableItem() { assertEquals(0, table.getSelectionCount()); table.setSelection(new TableItem[]{items[0], items[3], items[2]}); - assertEquals(new TableItem[]{items[0]}, table.getSelection()); + assertEquals(new TableItem[]{}, table.getSelection()); table.setSelection(new TableItem[]{items[3], items[2], items[1]}); - assertEquals(new TableItem[]{items[3]}, table.getSelection()); + assertEquals(new TableItem[]{}, table.getSelection()); table.setSelection(new TableItem[]{items[1], items[4], items[0]}); - assertEquals(new TableItem[]{items[1]}, table.getSelection()); + assertEquals(new TableItem[]{}, table.getSelection()); table.setSelection(new TableItem[]{items[0], items[4], items[0]}); - assertEquals(new TableItem[]{items[0]}, table.getSelection()); + assertEquals(new TableItem[]{}, table.getSelection()); table.setSelection(new TableItem[]{items[2], items[3], items[4]}); - assertEquals(new TableItem[]{items[2]}, table.getSelection()); - - table.setSelection(new TableItem[]{items[4], items[4], items[4], items[4], items[4], items[4]}); - assertEquals(new TableItem[]{items[4]}, table.getSelection()); + assertEquals(new TableItem[]{}, table.getSelection()); table.setSelection(new TableItem[]{items[4]}); assertEquals(new TableItem[]{items[4]}, table.getSelection()); - for (int i = 0; i < number; i++) - items[i] = new TableItem(table, 0); - table.setSelection(new TableItem[] {items[0]}); assertEquals(new TableItem[] {items[0]}, table.getSelection()); @@ -1341,6 +1377,9 @@ public void test_setSelection$Lorg_eclipse_swt_widgets_TableItem() { table.setSelection(new TableItem[] {items[1]}); assertEquals(new TableItem[] {items[1]}, table.getSelection()); + + table.setSelection(new TableItem[]{items[4], items[4], items[4], items[4], items[4], items[4]}); + assertEquals(new TableItem[]{}, table.getSelection()); } public void test_setSelectionI() { @@ -1571,4 +1610,4 @@ private void makeCleanEnvironment(boolean singleMode) { table = new Table(shell, SWT.SINGLE); setWidget(table); } -} +}
\ No newline at end of file diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java index ea8ad0a8d8..b5e81e1202 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Tree.java @@ -141,7 +141,7 @@ public void test_getParentItem() { } public void test_getSelection() { - warnUnimpl("Test test_getSelection not written"); + // Tested in setSelection. } public void test_getSelectionCount() { @@ -154,11 +154,20 @@ public void test_getSelectionCount() { assertEquals(0, tree.getSelectionCount()); - tree.setSelection(new TreeItem[]{items[2], items[number-1], items[10]}); + tree.setSelection(new TreeItem[]{items[2]}); assertEquals(1, tree.getSelectionCount()); - tree.setSelection(items); + tree.setSelection(new TreeItem[]{items[number-1]}); + assertEquals(1, tree.getSelectionCount()); + + tree.setSelection(new TreeItem[]{items[10]}); assertEquals(1, tree.getSelectionCount()); + + tree.setSelection(new TreeItem[]{items[2], items[number-1], items[10]}); + assertEquals(0, tree.getSelectionCount()); + + tree.setSelection(items); + assertEquals(0, tree.getSelectionCount()); } public void test_getTopItem() { @@ -167,12 +176,15 @@ public void test_getTopItem() { public void test_removeAll() { tree.removeAll(); + assertEquals(0, tree.getItemCount()); int number = 20; TreeItem[] items = new TreeItem[number]; for (int i = 0; i < number; i++) { items[i] = new TreeItem(tree, 0); } + assertEquals(number, tree.getItemCount()); + tree.removeAll(); assertEquals(0, tree.getItemCount()); } @@ -319,13 +331,22 @@ public void test_setSelection$Lorg_eclipse_swt_widgets_TreeItem() { for (int i = 0; i < number; i++) items[i] = new TreeItem(tree, 0); - assertEquals(":a:", new TreeItem[] {}, tree.getSelection()); + assertEquals(new TreeItem[] {}, tree.getSelection()); + tree.setSelection(new TreeItem[]{items[10]}); + assertEquals(new TreeItem[] {items[10]}, tree.getSelection()); + + tree.setSelection(new TreeItem[]{items[number-1]}); + assertEquals(new TreeItem[] {items[number-1]}, tree.getSelection()); + + tree.setSelection(new TreeItem[]{items[2]}); + assertEquals(new TreeItem[] {items[2]}, tree.getSelection()); + tree.setSelection(new TreeItem[]{items[10], items[number-1], items[2]}); - assertEquals(":b:", new TreeItem[] {items[10]}, tree.getSelection()); + assertEquals(new TreeItem[] {}, tree.getSelection()); tree.setSelection(items); - assertEquals(":c:", new TreeItem[] {items[0]}, tree.getSelection()); + assertEquals(new TreeItem[] {}, tree.getSelection()); makeCleanEnvironment(true); //single-selection tree @@ -352,33 +373,26 @@ public void test_setSelection$Lorg_eclipse_swt_widgets_TreeItem() { assertEquals(0, tree.getSelectionCount()); tree.setSelection(new TreeItem[]{items[0], items[3], items[2]}); - assertEquals(":b:", new TreeItem[]{items[0]}, tree.getSelection()); + assertEquals(":b:", new TreeItem[]{}, tree.getSelection()); tree.setSelection(new TreeItem[]{items[3], items[2], items[1]}); - assertEquals(":c:", new TreeItem[]{items[3]}, tree.getSelection()); + assertEquals(":c:", new TreeItem[]{}, tree.getSelection()); tree.setSelection(new TreeItem[]{items[1], items[4], items[0]}); - assertEquals(":d:", new TreeItem[]{items[1]}, tree.getSelection()); + assertEquals(":d:", new TreeItem[]{}, tree.getSelection()); tree.setSelection(new TreeItem[]{items[0], items[4], items[0]}); - assertEquals(":e:", new TreeItem[]{items[0]}, tree.getSelection()); + assertEquals(":e:", new TreeItem[]{}, tree.getSelection()); tree.setSelection(new TreeItem[]{items[2], items[3], items[4]}); - assertEquals(":f:", new TreeItem[]{items[2]}, tree.getSelection()); + assertEquals(":f:", new TreeItem[]{}, tree.getSelection()); tree.setSelection(new TreeItem[]{items[4], items[4], items[4], items[4], items[4], items[4]}); - assertEquals(":g:", new TreeItem[]{items[4]}, tree.getSelection()); + assertEquals(":g:", new TreeItem[]{}, tree.getSelection()); tree.setSelection(new TreeItem[]{items[4]}); assertEquals(":h:", new TreeItem[]{items[4]}, tree.getSelection()); - makeCleanEnvironment(true); //single-selection tree - - number = 5; - items = new TreeItem[number]; - for (int i = 0; i < number; i++) - items[i] = new TreeItem(tree, 0); - tree.setSelection(new TreeItem[] {items[0]}); assertEquals(":a:", new TreeItem[] {items[0]}, tree.getSelection()); @@ -549,4 +563,4 @@ private void makeCleanEnvironment(boolean single) { tree = new Tree(shell, single?SWT.SINGLE:SWT.MULTI); setWidget(tree); } -} +}
\ No newline at end of file |