Search in sources :

Example 21 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_Region method test_intersectLorg_eclipse_swt_graphics_Rectangle.

@Test
public void test_intersectLorg_eclipse_swt_graphics_Rectangle() {
    Rectangle rect1 = new Rectangle(0, 0, 48, 24);
    Rectangle rect2 = new Rectangle(0, 0, 48, 24);
    Rectangle rect3 = new Rectangle(10, 10, 10, 10);
    Rectangle rect4 = new Rectangle(48, 24, 10, 10);
    Rectangle rect5 = new Rectangle(24, 20, 24, 10);
    Region reg = new Region(display);
    reg.dispose();
    try {
        reg.intersect(rect1);
        fail("no exception thrown on disposed region");
    } catch (SWTException e) {
    }
    reg = new Region(display);
    reg.intersect(rect1);
    if (!reg.isEmpty()) {
        reg.dispose();
        fail("intersect failed for empty region");
    }
    reg.add(rect1);
    reg.intersect(rect2);
    Rectangle box = reg.getBounds();
    if (!box.equals(rect1)) {
        reg.dispose();
        fail("intersect failed 1");
    }
    reg.intersect(rect3);
    box = reg.getBounds();
    if (!box.equals(rect3)) {
        reg.dispose();
        fail("intersect failed 2");
    }
    reg.intersect(rect4);
    if (!reg.isEmpty()) {
        reg.dispose();
        fail("intersect failed 3");
    }
    reg.add(rect1.union(rect4));
    reg.intersect(rect5);
    box = reg.getBounds();
    if (!box.equals(rect5)) {
        reg.dispose();
        fail("intersect failed 4");
    }
    reg.dispose();
    reg = new Region(display);
    reg.add(rect1);
    reg.add(rect4);
    reg.intersect(rect5);
    box = reg.getBounds();
    if (!box.equals(new Rectangle(24, 20, 24, 4))) {
        reg.dispose();
        fail("intersect failed 5");
    }
    reg.dispose();
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 22 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_Region method test_subtractLorg_eclipse_swt_graphics_Region.

@Test
public void test_subtractLorg_eclipse_swt_graphics_Region() {
    Region reg1 = new Region(display);
    reg1.add(new Rectangle(0, 0, 50, 25));
    Region reg = new Region(display);
    reg.dispose();
    try {
        reg.subtract(reg1);
        reg1.dispose();
        fail("no exception thrown on disposed region");
    } catch (SWTException e) {
    }
    reg = new Region(display);
    reg.subtract(reg1);
    if (!reg.isEmpty()) {
        reg.dispose();
        reg1.dispose();
        fail("subtract failed for empty region");
    }
    Region reg2 = new Region(display);
    reg2.add(new Rectangle(0, 0, 50, 25));
    reg.add(reg1);
    reg.subtract(reg2);
    if (!reg.isEmpty()) {
        reg.dispose();
        reg1.dispose();
        reg2.dispose();
        fail("subtract failed 1");
    }
    reg2.dispose();
    Region reg3 = new Region(display);
    reg3.add(new Rectangle(10, 10, 10, 10));
    reg.add(reg1);
    reg.subtract(reg3);
    Rectangle box = reg.getBounds();
    if (!box.equals(reg1.getBounds())) {
        reg.dispose();
        reg1.dispose();
        reg3.dispose();
        fail("subtract failed 2");
    }
    reg3.dispose();
    Region reg4 = new Region(display);
    reg4.add(new Rectangle(50, 25, 10, 10));
    reg.subtract(reg4);
    box = reg.getBounds();
    if (!box.equals(reg1.getBounds())) {
        reg.dispose();
        reg1.dispose();
        reg4.dispose();
        fail("subtract failed 3");
    }
    Region reg5 = new Region(display);
    reg5.add(new Rectangle(0, 0, 60, 20));
    reg.add(reg1.getBounds().union(reg4.getBounds()));
    reg.subtract(reg5);
    box = reg.getBounds();
    if (!box.equals(new Rectangle(0, 20, 60, 15))) {
        reg.dispose();
        reg1.dispose();
        reg4.dispose();
        reg5.dispose();
        fail("subtract failed 4");
    }
    reg.dispose();
    reg = new Region(display);
    reg.add(reg1);
    reg.add(reg4);
    reg.subtract(reg5);
    box = reg.getBounds();
    if (!box.equals(new Rectangle(0, 20, 60, 15))) {
        reg.dispose();
        reg1.dispose();
        reg4.dispose();
        reg5.dispose();
        fail("subtract failed 5");
    }
    reg.dispose();
    reg1.dispose();
    reg4.dispose();
    reg5.dispose();
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 23 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_Region method test_subtractLorg_eclipse_swt_graphics_Rectangle.

@Test
public void test_subtractLorg_eclipse_swt_graphics_Rectangle() {
    Rectangle rect1 = new Rectangle(0, 0, 50, 25);
    Rectangle rect2 = new Rectangle(0, 0, 50, 25);
    Rectangle rect3 = new Rectangle(10, 10, 10, 10);
    Rectangle rect4 = new Rectangle(50, 25, 10, 10);
    Rectangle rect5 = new Rectangle(0, 0, 60, 20);
    Region reg = new Region(display);
    reg.dispose();
    try {
        reg.subtract(rect1);
        fail("no exception thrown on disposed region");
    } catch (SWTException e) {
    }
    reg = new Region(display);
    reg.subtract(rect1);
    if (!reg.isEmpty()) {
        reg.dispose();
        fail("subtract failed for empty region");
    }
    reg.add(rect1);
    reg.subtract(rect2);
    if (!reg.isEmpty()) {
        reg.dispose();
        fail("subtract failed 1");
    }
    reg.add(rect1);
    reg.subtract(rect3);
    Rectangle box = reg.getBounds();
    if (!box.equals(rect1)) {
        reg.dispose();
        fail("subtract failed 2");
    }
    reg.subtract(rect4);
    box = reg.getBounds();
    if (!box.equals(rect1)) {
        reg.dispose();
        fail("subtract failed 3");
    }
    reg.add(rect1.union(rect4));
    reg.subtract(rect5);
    box = reg.getBounds();
    if (!box.equals(new Rectangle(0, 20, 60, 15))) {
        reg.dispose();
        fail("subtract failed 4");
    }
    reg.dispose();
    reg = new Region(display);
    reg.add(rect1);
    reg.add(rect4);
    reg.subtract(rect5);
    box = reg.getBounds();
    if (!box.equals(new Rectangle(0, 20, 60, 15))) {
        reg.dispose();
        fail("subtract failed 5");
    }
    reg.dispose();
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 24 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_Region method test_intersectLorg_eclipse_swt_graphics_Region.

@Test
public void test_intersectLorg_eclipse_swt_graphics_Region() {
    Region reg = new Region(display);
    Region reg1 = new Region(display);
    reg1.add(new Rectangle(0, 0, 48, 24));
    reg.dispose();
    try {
        reg.intersect(reg1);
        reg1.dispose();
        fail("no exception thrown on disposed region");
    } catch (SWTException e) {
    }
    reg = new Region(display);
    reg.intersect(reg1);
    if (!reg.isEmpty()) {
        reg.dispose();
        reg1.dispose();
        fail("intersect failed for empty region");
    }
    Region reg2 = new Region(display);
    reg2.add(new Rectangle(0, 0, 48, 24));
    reg.add(reg1);
    reg.intersect(reg2);
    Rectangle box = reg.getBounds();
    if (!box.equals(reg1.getBounds())) {
        reg.dispose();
        reg1.dispose();
        reg2.dispose();
        fail("intersect failed 1");
    }
    reg2.dispose();
    Region reg3 = new Region(display);
    reg3.add(new Rectangle(10, 10, 10, 10));
    reg.intersect(reg3);
    box = reg.getBounds();
    if (!box.equals(reg3.getBounds())) {
        reg.dispose();
        reg1.dispose();
        reg3.dispose();
        fail("intersect failed 2");
    }
    reg3.dispose();
    Region reg4 = new Region(display);
    reg4.add(new Rectangle(48, 24, 10, 10));
    reg.intersect(reg4);
    if (!reg.isEmpty()) {
        reg.dispose();
        reg1.dispose();
        reg4.dispose();
        fail("intersect failed 3");
    }
    Region reg5 = new Region(display);
    reg5.add(new Rectangle(24, 20, 24, 10));
    reg.add(reg1.getBounds().union(reg4.getBounds()));
    reg.intersect(reg5);
    box = reg.getBounds();
    if (!box.equals(reg5.getBounds())) {
        reg.dispose();
        reg1.dispose();
        reg4.dispose();
        fail("intersect failed 4");
    }
    reg.dispose();
    reg = new Region(display);
    reg.add(reg1);
    reg.add(reg4);
    reg.intersect(reg5);
    box = reg.getBounds();
    if (!box.equals(new Rectangle(24, 20, 24, 4))) {
        reg.dispose();
        reg1.dispose();
        reg4.dispose();
        fail("intersect failed 5");
    }
    reg.dispose();
    reg1.dispose();
    reg4.dispose();
    reg5.dispose();
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 25 with SWTException

use of org.eclipse.swt.SWTException in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Table method test_setColumnOrder$I.

@Test
public void test_setColumnOrder$I() {
    assertArrayEquals(table.getColumnOrder(), new int[0]);
    table.setColumnOrder(new int[0]);
    assertArrayEquals(table.getColumnOrder(), new int[0]);
    try {
        table.setColumnOrder(null);
        fail("No exception thrown for null argument");
    } catch (IllegalArgumentException ex) {
    }
    try {
        table.setColumnOrder(new int[1]);
        fail("No exception thrown for invalid argument");
    } catch (IllegalArgumentException ex) {
    }
    TableColumn column0 = new TableColumn(table, SWT.NONE);
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    assertArrayEquals(table.getColumnOrder(), new int[] { 0, 1, 2 });
    try {
        table.setColumnOrder(null);
        fail("No exception thrown for null argument");
    } catch (IllegalArgumentException ex) {
    }
    try {
        table.setColumnOrder(new int[0]);
        fail("No exception thrown for invalid argument");
    } catch (IllegalArgumentException ex) {
    }
    try {
        table.setColumnOrder(new int[] { 0, 1 });
        fail("No exception thrown for invalid argument");
    } catch (IllegalArgumentException ex) {
    }
    try {
        table.setColumnOrder(new int[] { 0, 1, 2, 3 });
        fail("No exception thrown for invalid argument");
    } catch (IllegalArgumentException ex) {
    }
    try {
        table.setColumnOrder(new int[] { 0, 0, 1 });
        fail("No exception thrown for invalid argument");
    } catch (IllegalArgumentException ex) {
    }
    try {
        table.setColumnOrder(new int[] { 3, 0, 1 });
        fail("No exception thrown for invalid argument");
    } catch (IllegalArgumentException ex) {
    }
    table.setColumnOrder(new int[] { 2, 1, 0 });
    assertArrayEquals(table.getColumnOrder(), new int[] { 2, 1, 0 });
    column2.dispose();
    assertArrayEquals(table.getColumnOrder(), new int[] { 1, 0 });
    try {
        table.setColumnOrder(new int[] { 0, 1, 2 });
        fail("No exception thrown for invalid argument");
    } catch (IllegalArgumentException ex) {
    }
    column1.dispose();
    assertArrayEquals(table.getColumnOrder(), new int[] { 0 });
    column0.dispose();
    assertArrayEquals(table.getColumnOrder(), new int[0]);
    try {
        table.setColumnOrder(new int[1]);
        fail("No exception thrown for invalid argument");
    } catch (IllegalArgumentException ex) {
    }
    Table table2 = new Table(table.getParent(), SWT.NONE);
    table2.dispose();
    try {
        table2.getColumnOrder();
        fail("No exception thrown for widget is Disposed");
    } catch (SWTException ex) {
    }
    try {
        table2.setColumnOrder(new int[0]);
        fail("No exception thrown for widget is Disposed");
    } catch (SWTException ex) {
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) SWTException(org.eclipse.swt.SWTException) TableColumn(org.eclipse.swt.widgets.TableColumn) Test(org.junit.Test)

Aggregations

SWTException (org.eclipse.swt.SWTException)57 Test (org.junit.Test)29 Image (org.eclipse.swt.graphics.Image)21 Rectangle (org.eclipse.swt.graphics.Rectangle)14 ImageData (org.eclipse.swt.graphics.ImageData)13 IOException (java.io.IOException)8 Region (org.eclipse.swt.graphics.Region)8 Display (org.eclipse.swt.widgets.Display)8 SWTError (org.eclipse.swt.SWTError)7 PaletteData (org.eclipse.swt.graphics.PaletteData)7 RGB (org.eclipse.swt.graphics.RGB)7 InputStream (java.io.InputStream)6 Point (org.eclipse.swt.graphics.Point)6 MessageBox (org.eclipse.swt.widgets.MessageBox)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Cursor (org.eclipse.swt.graphics.Cursor)4 ImageLoader (org.eclipse.swt.graphics.ImageLoader)4 FileDialog (org.eclipse.swt.widgets.FileDialog)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Shell (org.eclipse.swt.widgets.Shell)3