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 @@ -14,7 +14,7 @@

package org.eclipse.swt.tests.graphics;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@Suite
@SelectClasses({
Test_org_eclipse_swt_browser_Browser.class,
Test_org_eclipse_swt_browser_Browser_IE.class
})
public class AllBrowserTests {
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
Test_org_eclipse_swt_widgets_Composite.class, //
Test_org_eclipse_swt_widgets_CoolBar.class, //
// Failing test: Test_org_eclipse_swt_widgets_CoolItem.class, //
Test_org_eclipse_swt_widgets_DateTime.class, //
Test_org_eclipse_swt_widgets_DateTime_Style_CALENDAR.class, //
Test_org_eclipse_swt_widgets_DateTime_Style_DATE.class, //
Test_org_eclipse_swt_widgets_DateTime_Style_TIME.class, //
Test_org_eclipse_swt_widgets_DirectoryDialog.class, //
Test_org_eclipse_swt_widgets_Event.class, //
Test_org_eclipse_swt_widgets_ExpandBar.class, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
*******************************************************************************/
package org.eclipse.swt.tests.junit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.function.BiFunction;

Expand Down Expand Up @@ -64,12 +64,12 @@ public static void assertImagesNotEqual(ImageData[] expected, ImageData[] actual
public static void assertImagesEqual(ImageData[] expected, ImageData[] actual) {
assertNotNull(expected);
assertNotNull(actual);
assertEquals("Different number of frames.", expected.length, actual.length);
assertEquals(expected.length, actual.length, "Different number of frames.");
BiFunction<String, Integer, String> formatMsg = (msg, i) -> expected.length == 1 ? msg + "."
: msg + " in frame " + i + ".";
for (int i = 0; i < expected.length; i++) {
assertEquals(formatMsg.apply("Different width", i), expected[i].width, actual[i].width);
assertEquals(formatMsg.apply("Different height", i), expected[i].height, actual[i].height);
assertEquals(expected[i].width, actual[i].width, formatMsg.apply("Different width", i));
assertEquals(expected[i].height, actual[i].height, formatMsg.apply("Different height", i));
// improve performance in case the frame has a global fixed alpha value
int expectedFixAlpha = getEffectiveAlpha(expected[i], -1, -1);
int actualFixAlpha = getEffectiveAlpha(actual[i], -1, -1);
Expand All @@ -79,15 +79,15 @@ public static void assertImagesEqual(ImageData[] expected, ImageData[] actual) {
expected[i].getPixels(0, y, expected[i].width, expectedLine, 0);
actual[i].getPixels(0, y, actual[i].width, actualLine, 0);
for (int x = 0; x < expected[i].width; x++) {
assertEquals(formatMsg.apply("Different color at x=" + x + ", y=" + y, i),
expected[i].palette.getRGB(expectedLine[x]), actual[i].palette.getRGB(actualLine[x]));
assertEquals(expected[i].palette.getRGB(expectedLine[x]), actual[i].palette.getRGB(actualLine[x]),
formatMsg.apply("Different color at x=" + x + ", y=" + y, i));
int expectedAlpha = expectedFixAlpha < 0 ? getEffectiveAlpha(expected[i], x, y) : expectedFixAlpha;
int actualAlpha = actualFixAlpha < 0 ? getEffectiveAlpha(actual[i], x, y) : actualFixAlpha;
if (expectedAlpha != actualAlpha) {
assertEquals(formatMsg.apply("Different alpha at x=" + x + ", y=" + y, i), expectedAlpha,
actualAlpha);
assertEquals(expectedAlpha, actualAlpha,
formatMsg.apply("Different alpha at x=" + x + ", y=" + y, i));
}
assertNotEquals(formatMsg.apply("Invalid alpha at x=" + x + ", y=" + y, i), -1, actualAlpha);
assertNotEquals(-1, actualAlpha, formatMsg.apply("Invalid alpha at x=" + x + ", y=" + y, i));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
package org.eclipse.swt.tests.junit;

import static org.eclipse.swt.tests.junit.SwtTestUtil.assertSWTProblem;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
package org.eclipse.swt.tests.junit;


import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -49,7 +47,6 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.test.Screenshots;
import org.junit.rules.TemporaryFolder;

public class SwtTestUtil {
/**
Expand Down Expand Up @@ -130,19 +127,19 @@ public class SwtTestUtil {
public static void assertSWTProblem(String message, int expectedCode, Throwable actualThrowable) {
if (actualThrowable instanceof SWTError) {
SWTError error = (SWTError) actualThrowable;
assertEquals(message, expectedCode, error.code);
assertEquals(expectedCode, error.code, message);
} else if (actualThrowable instanceof SWTException) {
SWTException exception = (SWTException) actualThrowable;
assertEquals(message, expectedCode, exception.code);
assertEquals(expectedCode, exception.code, message);
} else {
try {
SWT.error(expectedCode);
} catch (Throwable expectedThrowable) {
if (actualThrowable.getMessage().length() > expectedThrowable.getMessage().length()) {
assertTrue(message, actualThrowable.getMessage().startsWith(expectedThrowable.getMessage()));
assertTrue(actualThrowable.getMessage().startsWith(expectedThrowable.getMessage()), message);
}
else {
assertEquals(message, expectedThrowable.getMessage(), actualThrowable.getMessage());
assertEquals(expectedThrowable.getMessage(), actualThrowable.getMessage(), message);
}
}
}
Expand Down Expand Up @@ -369,7 +366,7 @@ public static void assertSimilarBrightness(String message, int expected, int act
// 2) and ensure brightness is within 12.5% of the range.
double expectedIntensity = getBrightness(expected);
double actualIntensity = getBrightness(actual);
assertEquals(message, expectedIntensity, actualIntensity, 255f / 8);
assertEquals(expectedIntensity, actualIntensity, 255f / 8, message);
}
}

Expand Down Expand Up @@ -478,7 +475,7 @@ public static void waitShellActivate(Runnable trigger, Shell shell) {
// Something went wrong? Get more info to diagnose
Screenshots.takeScreenshot(SwtTestUtil.class, "waitShellActivate-" + System.currentTimeMillis());
dumpShellState(System.out);
assertThat("Shell did not activate", shell.getDisplay().getActiveShell(), is(shell));
assertEquals(shell.getDisplay().getActiveShell(), shell, "Shell did not activate");
fail("SWT.Activate was not received but Shell is (incorrectly?) reported active");
}

Expand Down Expand Up @@ -586,13 +583,12 @@ public static boolean hasPixelNotMatching(Image image, Color nonMatchingColor, R
return false;
}

public static Path getPath(String fileName, TemporaryFolder tempFolder) {
Path path = tempFolder.getRoot().toPath();
Path filePath = path.resolve("image-resources").resolve(Path.of(fileName));
return getPath(fileName, filePath);
public static Path getPath(String fileName, Path tempFolder) {
Path filePath = tempFolder.resolve("image-resources").resolve(Path.of(fileName));
return copyFile(fileName, filePath);
}

public static Path getPath(String sourceFilename, Path destinationPath) {
public static Path copyFile(String sourceFilename, Path destinationPath) {
if (!Files.isRegularFile(destinationPath)) {
// Extract resource on the classpath to a temporary file to ensure it's
// available as plain file, even if this bundle is packed as jar
Expand Down
Loading
Loading