|
28 | 28 | import org.eclipse.swt.graphics.ImageData;
|
29 | 29 | import org.eclipse.swt.graphics.ImageDataProvider;
|
30 | 30 | import org.eclipse.swt.graphics.ImageLoader;
|
| 31 | +import org.eclipse.swt.graphics.PaletteData; |
| 32 | +import org.eclipse.swt.graphics.RGB; |
31 | 33 | import org.eclipse.swt.widgets.Display;
|
32 | 34 | import org.junit.Before;
|
33 | 35 | import org.junit.Test;
|
@@ -172,6 +174,74 @@ public void test_ConstructorWithImageDataProvider() {
|
172 | 174 | }
|
173 | 175 | }
|
174 | 176 |
|
| 177 | +@Test |
| 178 | +public void test_InvalidArgumentsForAllConstructors() { |
| 179 | + ImageData source = new ImageData(16, 16, 1, new PaletteData(new RGB[]{new RGB(0, 0, 0)})); |
| 180 | + ImageData mask = new ImageData(16, 16, 1, new PaletteData(new RGB[]{new RGB(0, 0, 0)})); |
| 181 | + |
| 182 | + try { |
| 183 | + Cursor cursor = new Cursor(Display.getDefault(), -99); |
| 184 | + cursor.dispose(); |
| 185 | + fail("No exception thrown when wrong style was provided"); |
| 186 | + } catch (IllegalArgumentException e) { |
| 187 | + } |
| 188 | + |
| 189 | + try { |
| 190 | + Cursor cursorFromImageAndMask = new Cursor(Display.getDefault(), null, mask, 0, 0); |
| 191 | + cursorFromImageAndMask.dispose(); |
| 192 | + fail("No exception thrown when source is null"); |
| 193 | + } catch (IllegalArgumentException e) { |
| 194 | + } |
| 195 | + |
| 196 | + try { |
| 197 | + Cursor cursorFromImageAndMask1 = new Cursor(Display.getDefault(), source, null, 0, 0); |
| 198 | + cursorFromImageAndMask1.dispose(); |
| 199 | + fail("No exception thrown when mask is null and source doesn't heve a mask"); |
| 200 | + } catch (IllegalArgumentException e) { |
| 201 | + } |
| 202 | + |
| 203 | + try { |
| 204 | + ImageData source32 = new ImageData(32, 32, 1, new PaletteData(new RGB[]{new RGB(0, 0, 0)})); |
| 205 | + ImageData mask16 = new ImageData(16, 16, 1, new PaletteData(new RGB[]{new RGB(0, 0, 0)})); |
| 206 | + Cursor cursorFromImageAndMask2 = new Cursor(Display.getDefault(), source32, mask16, 0, 0); |
| 207 | + cursorFromImageAndMask2.dispose(); |
| 208 | + fail("No exception thrown when source and the mask are not the same size"); |
| 209 | + } catch (IllegalArgumentException e) { |
| 210 | + } |
| 211 | + |
| 212 | + try { |
| 213 | + Cursor cursorFromImageAndMask3 = new Cursor(Display.getDefault(), source, mask, 18, 18); |
| 214 | + cursorFromImageAndMask3.dispose(); |
| 215 | + fail("No exception thrown when hotspot is outside the bounds of the image"); |
| 216 | + } catch (IllegalArgumentException e) { |
| 217 | + } |
| 218 | + |
| 219 | + try { |
| 220 | + ImageData nullImageData = null; |
| 221 | + Cursor cursorFromSourceOnly= new Cursor(Display.getDefault(), nullImageData, 0, 0); |
| 222 | + cursorFromSourceOnly.dispose(); |
| 223 | + fail("No exception thrown when source image data is null"); |
| 224 | + } catch (IllegalArgumentException e) { |
| 225 | + } |
| 226 | + |
| 227 | + try { |
| 228 | + ImageDataProvider provider = null; |
| 229 | + Cursor cursorFromProvider = new Cursor(Display.getDefault(), provider, 0, 0); |
| 230 | + cursorFromProvider.dispose(); |
| 231 | + fail("No exception thrown when ImageDataProvider is null"); |
| 232 | + } catch (IllegalArgumentException e) { |
| 233 | + } |
| 234 | + |
| 235 | + try { |
| 236 | + ImageData nullSource = null; |
| 237 | + ImageDataProvider provider = zoom -> nullSource; |
| 238 | + Cursor cursorFromProvider = new Cursor(Display.getDefault(), provider, 0, 0); |
| 239 | + cursorFromProvider.dispose(); |
| 240 | + fail("No exception thrown when source is null in ImageDataProvider"); |
| 241 | + } catch (IllegalArgumentException e) { |
| 242 | + } |
| 243 | +} |
| 244 | + |
175 | 245 | @Test
|
176 | 246 | public void test_equalsLjava_lang_Object() {
|
177 | 247 | /* Note: Two cursors are only considered equal if their handles are equal.
|
|
0 commit comments