Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceI() {
@Test
public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_ImageDataLorg_eclipse_swt_graphics_ImageDataII() {
// Test new Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY)
int numFormats = SwtTestUtil.imageFormats.length;
String fileName = SwtTestUtil.imageFilenames[0];
for (int i=0; i<numFormats; i++) {
String format = SwtTestUtil.imageFormats[i];
for (String format : SwtTestUtil.imageFormats) {
ImageLoader loader = new ImageLoader();
try (InputStream stream = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) {
ImageData source = loader.load(stream)[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_io_InputStream

String firstFile = SwtTestUtil.invalidImageFilenames[0];
Display[] displays = { display, null };
for (int j = 0; j < displays.length; j++) {
for (Display display : displays) {
for (String format : SwtTestUtil.imageFormats) {
try (InputStream stream = SwtTestUtil.class.getResourceAsStream(firstFile + "." + format)) {
e = assertThrows(SWTException.class, () -> new Image(display, stream));
Expand Down Expand Up @@ -316,8 +316,7 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_String()
// create valid images
for (Display display : displays) {
for (String fileName : SwtTestUtil.imageFilenames) {
for (int i = 0; i < SwtTestUtil.imageFormats.length; i++) {
String format = SwtTestUtil.imageFormats[i];
for (String format : SwtTestUtil.imageFormats) {
String pathName = getPath(fileName + "." + format).toString();
Image image = new Image(display, pathName);
image.dispose();
Expand Down Expand Up @@ -868,10 +867,8 @@ public void test_toString() {
/** Test implementation **/

void getImageData1() {
int numFormats = SwtTestUtil.imageFormats.length;
String fileName = SwtTestUtil.imageFilenames[0];
for (int i=0; i<numFormats; i++) {
String format = SwtTestUtil.imageFormats[i];
for (String format : SwtTestUtil.imageFormats) {
try (InputStream stream = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) {
ImageData data1 = new ImageData(stream);
Image image = new Image(display, data1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -60,9 +59,10 @@ public void setUp() {
/**
* Tests {@link ImageData#blit}:
* creates a random image and tests over all combinations of depth,format,scale
* @throws Exception
*/
@Test
public void test_blit() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
public void test_blit() throws Exception {
List<BlitTestInfo> tests = new ArrayList<>();

// Compose a list of all supported formats
Expand Down Expand Up @@ -117,9 +117,10 @@ public void test_blit() throws NoSuchMethodException, SecurityException, Illegal
/**
* Tests {@link ImageData#blit}:
* Ensures that (MSB_FIRST, LSB_FIRST) round trip produces original.
* @throws Exception
*/
@Test
public void test_blit_MsbLsb() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
public void test_blit_MsbLsb() throws Exception {
List<BlitTestInfo> tests = new ArrayList<>();
{
for (int depth : indexedDepths) {
Expand Down Expand Up @@ -218,10 +219,8 @@ public void test_ConstructorLjava_io_InputStream() throws IOException {
assertThrows("No exception thrown for invalid InputStream", SWTException.class, () ->new ImageData(stream1));
}

int numFormats = SwtTestUtil.imageFormats.length;
String fileName = SwtTestUtil.imageFilenames[0];
for (int i=0; i<numFormats; i++) {
String format = SwtTestUtil.imageFormats[i];
for (String format : SwtTestUtil.imageFormats) {
try (InputStream stream2 = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) {
new ImageData(stream2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;

import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
Expand All @@ -49,30 +51,26 @@ public void test_Constructor() {
}

@Test
public void test_addImageLoaderListenerLorg_eclipse_swt_graphics_ImageLoaderListener() {
public void test_addImageLoaderListenerLorg_eclipse_swt_graphics_ImageLoaderListener() throws IOException {
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) {
}

assertThrows(IllegalArgumentException.class, () -> loader.addImageLoaderListener(null),
"No exception thrown for addImageLoaderListener with null argument");
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;
Expand All @@ -84,98 +82,70 @@ public void test_addImageLoaderListenerLorg_eclipse_swt_graphics_ImageLoaderList
}

@Test
public void test_loadLjava_io_InputStream() {
ImageLoader loader = new ImageLoader();
try (InputStream stream = null) {
loader.load(stream);
fail("No exception thrown for load inputStream == null");
} catch (IllegalArgumentException | IOException e) {
}
public void test_loadLjava_io_InputStream() throws IOException {
ImageLoader loader = new ImageLoader();
assertThrows(IllegalArgumentException.class, () -> loader.load((InputStream) null),
"No exception thrown for load inputStream == null");

try (InputStream stream = SwtTestUtil.class.getResourceAsStream("empty.txt")) {
loader.load(stream);
fail("No exception thrown for load from invalid inputStream");
} catch (IOException|SWTException e) {
}
try (InputStream stream = SwtTestUtil.class.getResourceAsStream("empty.txt")) {
assertThrows(SWTException.class, () -> loader.load(stream),
"No exception thrown for load from invalid inputStream");
}

int numFormats = SwtTestUtil.imageFormats.length;
String fileName = SwtTestUtil.imageFilenames[0];
for (int i = 0; i < numFormats; i++) {
String format = SwtTestUtil.imageFormats[i];
try (InputStream stream = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) {
loader.load(stream);
} catch (IOException e) {
}
String fileName = SwtTestUtil.imageFilenames[0];
for (String format : SwtTestUtil.imageFormats) {
try (InputStream stream = SwtTestUtil.class.getResourceAsStream(fileName + "." + format)) {
loader.load(stream);
}
}
}

@Test
public void test_loadLjava_lang_String() {
ImageLoader loader = new ImageLoader();
String filename = null;
try {
loader.load(filename);
fail("No exception thrown for load filename == null");
} catch (IllegalArgumentException e) {
}
assertThrows(IllegalArgumentException.class, () -> loader.load(filename),
"No exception thrown for load filename == null");
}

@Test
public void test_saveLjava_io_OutputStreamI() {
public void test_saveLjava_io_OutputStreamI() throws IOException {
ImageLoader loader = new ImageLoader();
ByteArrayOutputStream outStream = null;
try {
try {
loader.save(outStream, 0);
fail("No exception thrown for save outputStream == null");
} catch (IllegalArgumentException e) {
}

outStream = new ByteArrayOutputStream();
try {
loader.save(outStream, -1);
fail("No exception thrown for save to invalid outputStream format");
} catch (SWTException e) {
OutputStream outStream1 = null;
assertThrows(IllegalArgumentException.class, () -> loader.save(outStream1, 0),
"No exception thrown for save outputStream == null");

OutputStream outStream2 = new ByteArrayOutputStream();
assertThrows(SWTException.class, () -> loader.save(outStream2, -1),
"No exception thrown for save to invalid outputStream format");

boolean jpgSupported = Arrays.asList(SwtTestUtil.imageFormats).contains("jpg");
if (jpgSupported) {
String filename = SwtTestUtil.imageFilenames[0];
// must use jpg since save is not implemented yet in png format
String filetype = "jpg";
try (InputStream inStream = SwtTestUtil.class.getResourceAsStream(filename + "." + filetype)) {
loader.load(inStream);
}
boolean jpgSupported = false;
for (String imageFormat : SwtTestUtil.imageFormats) {
if (imageFormat.equals("jpg")) {
jpgSupported = true;
OutputStream outStream = new ByteArrayOutputStream();
int i = 0;
for (String format : SwtTestUtil.imageFormats) {
if (format.equals(filetype)) {
// save using the appropriate format
loader.save(outStream, i++);
break;
}
}
if (jpgSupported) {
String filename = SwtTestUtil.imageFilenames[0];
// must use jpg since save is not implemented yet in png format
String filetype = "jpg";
try (InputStream inStream = SwtTestUtil.class.getResourceAsStream(filename + "." + filetype)) {
loader.load(inStream);
} catch (IOException e) {}
for (int i = 0; i < SwtTestUtil.imageFormats.length; i++) {
if (SwtTestUtil.imageFormats[i].equals(filetype)) {
// save using the appropriate format
loader.save(outStream, i);
break;
}
}
}
} finally {
try {
outStream.close();
} catch (Exception e) {
}
}
}

@Test
public void test_saveLjava_lang_StringI() {
ImageLoader loader = new ImageLoader();
String filename = null;
try {
loader.save(filename, 0);
fail("No exception thrown for save filename == null");
} catch (IllegalArgumentException e) {
}
assertThrows(IllegalArgumentException.class, () -> loader.save(filename, 0),
"No exception thrown for save filename == null");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
Expand Down Expand Up @@ -123,9 +125,9 @@ public void test_setDefaultButtonLorg_eclipse_swt_widgets_Button() {
public void test_setImageLorg_eclipse_swt_graphics_Image() {
assertNull(":a:", decorations.getImage());
loadImages();
decorations.setImage(images[0]);
assertTrue(":b:", images[0] == decorations.getImage());
assertTrue(":c:", images[1] != decorations.getImage());
decorations.setImage(images.get(0));
assertTrue(":b:", images.get(0) == decorations.getImage());
assertTrue(":c:", images.get(1) != decorations.getImage());
decorations.setImage(null);
assertNull(":d:", decorations.getImage());
freeImages();
Expand Down Expand Up @@ -189,7 +191,7 @@ public void test_setVisibleZ() {

/* custom */
Decorations decorations;
Image[] images = new Image [SwtTestUtil.imageFormats.length*SwtTestUtil.imageFilenames.length];
private List<Image> images = new ArrayList<>();

@Override
protected void setWidget(Widget w) {
Expand All @@ -201,15 +203,10 @@ protected void setWidget(Widget w) {

// this method must be private or protected so the auto-gen tool keeps it
private void loadImages() {
int numFormats = SwtTestUtil.imageFormats.length;
int numFiles = SwtTestUtil.imageFilenames.length;
for (int i=0; i<numFormats; i++) {
String format = SwtTestUtil.imageFormats[i];
int index = i*numFiles;
for (int j=0; j<numFiles; j++){
String fileName = SwtTestUtil.imageFilenames[j];
for (String format : SwtTestUtil.imageFormats) {
for (String fileName : SwtTestUtil.imageFilenames) {
try (InputStream resource = this.getClass().getResourceAsStream(fileName + "." + format)) {
images [index+j] = new Image (shell.getDisplay(), resource);
images.add(new Image(shell.getDisplay(), resource));
} catch (IOException e) {
// continue;
}
Expand Down
Loading