Skip to content

Commit 26fec81

Browse files
Adding Tests
1 parent cf3a74e commit 26fec81

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Cursor.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.eclipse.swt.graphics.ImageData;
2929
import org.eclipse.swt.graphics.ImageDataProvider;
3030
import org.eclipse.swt.graphics.ImageLoader;
31+
import org.eclipse.swt.graphics.PaletteData;
32+
import org.eclipse.swt.graphics.RGB;
3133
import org.eclipse.swt.widgets.Display;
3234
import org.junit.Before;
3335
import org.junit.Test;
@@ -172,6 +174,74 @@ public void test_ConstructorWithImageDataProvider() {
172174
}
173175
}
174176

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+
175245
@Test
176246
public void test_equalsLjava_lang_Object() {
177247
/* Note: Two cursors are only considered equal if their handles are equal.

0 commit comments

Comments
 (0)