diff options
author | Carolyn MacLeod <carolyn> | 2008-01-29 16:41:57 +0000 |
---|---|---|
committer | Carolyn MacLeod <carolyn> | 2008-01-29 16:41:57 +0000 |
commit | 4102fdcf3ccacda6c1d64a2cea030a4503d7a339 (patch) | |
tree | 3b8dc99b801b16ea9a4c9cbfd94795dc3a7fd03b /tests | |
parent | fe260d54c4731861d4b67096b0a0278dfb8bbb94 (diff) | |
download | eclipse.platform.swt-4102fdcf3ccacda6c1d64a2cea030a4503d7a339.tar.gz eclipse.platform.swt-4102fdcf3ccacda6c1d64a2cea030a4503d7a339.tar.xz eclipse.platform.swt-4102fdcf3ccacda6c1d64a2cea030a4503d7a339.zip |
71478 - ImageData constructor accepts incomplete pixel data
Diffstat (limited to 'tests')
-rw-r--r-- | tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_ImageData.java | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_ImageData.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_ImageData.java index ed73528e49..e28c5d486b 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_ImageData.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_ImageData.java @@ -56,7 +56,7 @@ public void test_ConstructorIIILorg_eclipse_swt_graphics_PaletteData() { } try { - new ImageData(1, 1, 1, null, 0, new byte[] {}); + new ImageData(1, 1, 1, null, 0, new byte[] {0, 0x4f, 0x4f, 0}); fail("No exception thrown for paletteData == null"); } catch (IllegalArgumentException e) { } @@ -74,20 +74,22 @@ public void test_ConstructorIIILorg_eclipse_swt_graphics_PaletteData() { } public void test_ConstructorIIILorg_eclipse_swt_graphics_PaletteDataI$B() { + byte[] validData = new byte[] {0, 0x4f, 0x4f, 0}; + try { - new ImageData(-1, 1, 1, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, new byte[] {}); + new ImageData(-1, 1, 1, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, validData); fail("No exception thrown for width < 0"); } catch (IllegalArgumentException e) { } try { - new ImageData(1, -1, 1, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, new byte[] {}); + new ImageData(1, -1, 1, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, validData); fail("No exception thrown for height < 0"); } catch (IllegalArgumentException e) { } try { - new ImageData(1, 1, 1, null, 0, new byte[] {}); + new ImageData(1, 1, 1, null, 0, validData); fail("No exception thrown for paletteData == null"); } catch (IllegalArgumentException e) { } @@ -99,26 +101,44 @@ public void test_ConstructorIIILorg_eclipse_swt_graphics_PaletteDataI$B() { } try { - new ImageData(1, 1, 3, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, new byte[] {}); + new ImageData(1, 1, 1, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, new byte[] {}); + fail("No exception thrown for data array too small"); + } catch (IllegalArgumentException e) { + } + + try { + new ImageData(1, 1, 16, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, new byte[] {0x4f}); + fail("No exception thrown for data array too small"); + } catch (IllegalArgumentException e) { + } + + try { + new ImageData(1, 1, 32, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, new byte[] {0x4f, 0x4f}); + fail("No exception thrown for data array too small"); + } catch (IllegalArgumentException e) { + } + + try { + new ImageData(2, 2, 8, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, new byte[] {0x4f, 0x4f, 0x4f}); + fail("No exception thrown for data array too small"); + } catch (IllegalArgumentException e) { + } + + try { + new ImageData(1, 1, 3, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, validData); fail("No exception thrown for unsupported depth"); } catch (IllegalArgumentException e) { } + // verify all valid depths int[] validDepths = {1, 2, 4, 8, 16, 24, 32}; for (int i = 0; i < validDepths.length; i++) { - new ImageData(1, 1, validDepths[i], new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, new byte[] {}); - } - - // illegal argument, data is null - try { - new ImageData(1, 1, 8, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 4, null); - fail("No exception thrown for null data"); - } catch (IllegalArgumentException e) { + new ImageData(1, 1, validDepths[i], new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 1, validData); } - // divide by zero exception if scanlinePad == 0 + // verify no divide by zero exception if scanlinePad == 0 try { - new ImageData(1, 1, 8, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 0, new byte[] {}); + new ImageData(1, 1, 8, new PaletteData(new RGB[] {new RGB(0, 0, 0)}), 0, validData); fail("No exception thrown for scanlinePad == 0"); } catch (IllegalArgumentException e) { } |