Search in sources :

Example 1 with ImageLoaderListener

use of org.eclipse.swt.graphics.ImageLoaderListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_ImageLoader method test_addImageLoaderListenerLorg_eclipse_swt_graphics_ImageLoaderListener.

@Test
public void test_addImageLoaderListenerLorg_eclipse_swt_graphics_ImageLoaderListener() {
    ImageLoader loader = new ImageLoader();
    ImageLoaderListener loaderListener = e -> loaderListenerCalled = true;
    try {
        loader.addImageLoaderListener(null);
        fail("No exception thrown for addImageLoaderListener with null argument");
    } catch (IllegalArgumentException e) {
    }
    assertFalse(":a:", loader.hasListeners());
    loader.addImageLoaderListener(loaderListener);
    assertTrue(":b:", loader.hasListeners());
    loaderListenerCalled = false;
    try (InputStream stream = SwtTestUtil.class.getResourceAsStream("interlaced_target.png")) {
        loader.load(stream);
    } catch (IOException e) {
    }
    assertTrue(":c:", loaderListenerCalled);
    loaderListenerCalled = false;
    try (InputStream stream = SwtTestUtil.class.getResourceAsStream("target.png")) {
        loader.load(stream);
    } catch (IOException e) {
    }
    assertFalse(":d:", loaderListenerCalled);
    loaderListenerCalled = false;
    loader.notifyListeners(new ImageLoaderEvent(loader, loader.data[0], 0, true));
    assertTrue(":e:", loaderListenerCalled);
    loader.removeImageLoaderListener(loaderListener);
    assertFalse(":f:", loader.hasListeners());
}
Also used : ImageLoader(org.eclipse.swt.graphics.ImageLoader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertTrue(org.junit.Assert.assertTrue) Assert.fail(org.junit.Assert.fail) IOException(java.io.IOException) SWTException(org.eclipse.swt.SWTException) ImageLoaderEvent(org.eclipse.swt.graphics.ImageLoaderEvent) ImageLoaderListener(org.eclipse.swt.graphics.ImageLoaderListener) Test(org.junit.Test) InputStream(java.io.InputStream) ImageLoaderEvent(org.eclipse.swt.graphics.ImageLoaderEvent) InputStream(java.io.InputStream) ImageLoaderListener(org.eclipse.swt.graphics.ImageLoaderListener) IOException(java.io.IOException) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SWTException (org.eclipse.swt.SWTException)1 ImageLoader (org.eclipse.swt.graphics.ImageLoader)1 ImageLoaderEvent (org.eclipse.swt.graphics.ImageLoaderEvent)1 ImageLoaderListener (org.eclipse.swt.graphics.ImageLoaderListener)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Test (org.junit.Test)1