Search in sources :

Example 1 with ImageFileNameProvider

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

the class Test_org_eclipse_swt_graphics_Image method test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvider.

@Test
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvider() {
    // Null provider
    ImageFileNameProvider provider = null;
    try {
        Image image = new Image(display, provider);
        image.dispose();
        fail("No exception thrown for file name == null");
    } catch (IllegalArgumentException e) {
        assertSWTProblem("Incorrect exception thrown for provider == null", SWT.ERROR_NULL_ARGUMENT, e);
    }
    // Invalid provider
    provider = zoom -> null;
    try {
        Image image = new Image(display, provider);
        image.dispose();
        fail("No exception thrown for non-existent file name");
    } catch (IllegalArgumentException e) {
        assertSWTProblem("Incorrect exception thrown for provider == null", SWT.ERROR_INVALID_ARGUMENT, e);
    }
    // Valid provider
    Image image = new Image(display, imageFileNameProvider);
    image.dispose();
    // Corrupt Image provider
    provider = zoom -> {
        String fileName;
        switch(zoom) {
            case 100:
                fileName = "corrupt.png";
                break;
            case 150:
                fileName = "corrupt.png";
                break;
            case 200:
                fileName = "corrupt.png";
                break;
            default:
                return null;
        }
        return getPath(fileName);
    };
    try {
        image = new Image(display, provider);
        image.dispose();
        fail("No exception thrown for corrupt image file.");
    } catch (SWTException e) {
        assertSWTProblem("Incorrect exception thrown for provider with corrupt images", SWT.ERROR_INVALID_IMAGE, e);
    }
    // Valid provider only 100% zoom
    provider = zoom -> {
        String fileName;
        switch(zoom) {
            case 100:
                fileName = "collapseall.png";
                break;
            case 150:
            case 200:
            default:
                return null;
        }
        return getPath(fileName);
    };
    image = new Image(display, provider);
    image.dispose();
}
Also used : SWTException(org.eclipse.swt.SWTException) ImageFileNameProvider(org.eclipse.swt.graphics.ImageFileNameProvider) Image(org.eclipse.swt.graphics.Image) Test(org.junit.Test)

Aggregations

SWTException (org.eclipse.swt.SWTException)1 Image (org.eclipse.swt.graphics.Image)1 ImageFileNameProvider (org.eclipse.swt.graphics.ImageFileNameProvider)1 Test (org.junit.Test)1