package org.eclipse.swt.tests.junit;
/*
* (c) Copyright IBM Corp. 2000, 2002. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
import junit.framework.*;
import junit.textui.*;
/**
* Automated Test Suite for class org.eclipse.swt.widgets.Table
*
* @see org.eclipse.swt.widgets.Table
*/
public class Test_org_eclipse_swt_widgets_Table extends Test_org_eclipse_swt_widgets_Composite {
protected Table table;
public Test_org_eclipse_swt_widgets_Table(String name) {
super(name);
}
public static void main(String[] args) {
TestRunner.run(suite());
}
protected void setUp() {
super.setUp();
makeCleanEnvironment(false); // by default, use multi-select table.
}
protected void tearDown() {
super.tearDown();
}
/**
* (Re)initializes table. This is called from setUp before each test
* method is invoked, but also inside the test methods themselves to
* re-initialize the environment for a fresh test.
*
* Basically a shim for coalescing the old test methods (several test
* methods testing the same target method) into a single test method for
* every target method. This way the original tests should work with little
* modification, as long as this method is called before each test.
*
* Caveat: the Widget TestCase defines the tearDown method, will assert that
* the main widget (defined by the last call to setWidget) has been disposed.
* So using this inside test methods means that only the widget created by
* the last call to this method will be tested for this.
*
* @param int Value to pass as the second parameter to the Table constructor
*/
private void makeCleanEnvironment(boolean singleMode) {
// this method must be private or protected so the auto-gen tool keeps it
if ( singleMode == false )
table = new Table(shell, SWT.MULTI);
else
table = new Table(shell, SWT.SINGLE);
setWidget(table);
}
public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI(){
if (fCheckSwtNullExceptions) {
Table newTable;
try {
newTable = new Table(null, 0);
fail("No exception thrown for parent == null");
}
catch (IllegalArgumentException e) {
}
}
}
public void test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener() {
warnUnimpl("Test test_addSelectionListenerLorg_eclipse_swt_events_SelectionListener not written");
}
public void test_checkSubclass() {
warnUnimpl("Test test_checkSubclass not written");
}
public void test_computeSizeIIZ() {
warnUnimpl("Test test_computeSizeIIZ not written");
}
public void test_deselect$I(){
int number = 15;
TableItem[] items = new TableItem[number];
for (int i = 0; i < number; i++)
items[i] = new TableItem(table, 0);
table.select(new int[] {0, 3});
assertEquals(2, table.getSelectionCount());
table.deselect(new int[] {1, 2});
assertEquals(2, table.getSelectionCount());
table.deselect(new int[] {1, 3, 5});
assertEquals(1, table.getSelectionCount());
table.deselect(new int[] {9, 3, 0});
assertEquals(0, table.getSelectionCount());
makeCleanEnvironment(false);
items = new TableItem[number];
for (int i = 0; i < number; i++)
items[i] = new TableItem(table, 0);
table.selectAll();
assertEquals(number, table.getSelectionCount());
try{
table.deselect(null);
fail("No exception thrown for selection == null");
}
catch (IllegalArgumentException e) {
}
assertEquals(number, table.getSelectionCount());
table.selectAll();
table.deselect(new int[] {});
assertEquals(number, table.getSelectionCount());
table.selectAll();
table.deselect(new int[] {-1, 100, -1000});
assertEquals(number, table.getSelectionCount());
table.selectAll();
table.deselect(new int[] {2, -1, 1, 100, 2});
assertEquals(number-2, table.getSelectionCount());
table.deselect(new int[] {2, -1, 1, 100, 2});
assertEquals(number-2, table.getSelectionCount());
table.deselect(new int[] {2, -1, 3, 100, 2});
assertEquals(number-3, table.getSelectionCount());
}
public void test_deselectI(){
int number = 15;
TableItem[] items = new TableItem[number];
for (int i = 0; i < number; i++) {
items[i] = new TableItem(table, 0);
}
assertEquals(0, table.getSelectionCount());
table.deselect(0);
assertEquals(0, table.getSelectionCount());
table.select(new int[] {0, 3, 6});
assertEquals(3, table.getSelectionCount());
table.deselect(0);
assertEquals(2, table.getSelectionCount());
table.deselect(0);
assertEquals(2, table.getSelectionCount());
table.deselect(5);
|