Skip to content

Commit

Permalink
Migrate win32 unit tests to JUnit 5 and reduce test visibility eclips…
Browse files Browse the repository at this point in the history
…e-platform#1298

This migrates the unit tests placed in the SWT win32 production
fragments to JUnit 5. The visibility of the test classes is reduced to
`packaged protected` as allowed by JUnit 5.

Fixes eclipse-platform#1298
  • Loading branch information
HeikoKlare authored and ShahzaibIbrahim committed Jul 3, 2024
1 parent 9c19c04 commit dae8216
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import org.eclipse.swt.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.widgets.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public class GCWin32Tests extends Win32AutoscaleTestBase {
class GCWin32Tests extends Win32AutoscaleTestBase {

@Test
public void gcZoomLevelMustChangeOnShellZoomChange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gdip.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public class PathWin32Tests extends Win32AutoscaleTestBase {
class PathWin32Tests extends Win32AutoscaleTestBase {

int zoom = 100;
int scaledZoom = 200;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import static org.junit.Assert.assertEquals;

import org.eclipse.swt.internal.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public class TextLayoutWin32Tests extends Win32AutoscaleTestBase {
class TextLayoutWin32Tests extends Win32AutoscaleTestBase {
final static String text = "This is a text for testing.";

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
*******************************************************************************/
package org.eclipse.swt.graphics;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gdip.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public class TransformWin32Tests extends Win32AutoscaleTestBase {
class TransformWin32Tests extends Win32AutoscaleTestBase {

@Test
public void testShouldHaveDifferentHandlesAtDifferentZoomLevels() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,28 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.junit.jupiter.api.*;

public class DefaultSWTFontRegistryTests {
class DefaultSWTFontRegistryTests {
private static String TEST_FONT = "Helvetica";
private Display display;
private SWTFontRegistry fontRegistry;

@BeforeClass
@BeforeAll
public static void assumeIsFittingPlatform() {
PlatformSpecificExecution.assumeIsFittingPlatform();
}

@Before
@BeforeEach
public void setUp() {
this.display = Display.getDefault();
this.fontRegistry = new DefaultSWTFontRegistry(display);
}

@After
@AfterEach
public void tearDown() {
if (this.fontRegistry != null) {
this.fontRegistry.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,28 @@
*******************************************************************************/
package org.eclipse.swt.internal;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.junit.jupiter.api.*;

public class ScalingSWTFontRegistryTests {
class ScalingSWTFontRegistryTests {
private static String TEST_FONT = "Helvetica";
private SWTFontRegistry fontRegistry;

@BeforeClass
@BeforeAll
public static void assumeIsFittingPlatform() {
PlatformSpecificExecution.assumeIsFittingPlatform();
}

@Before
@BeforeEach
public void setUp() {
this.fontRegistry = new ScalingSWTFontRegistry(Display.getDefault());
}

@After
@AfterEach
public void tearDown() {
if (this.fontRegistry != null) {
this.fontRegistry.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.junit.*;
import org.junit.jupiter.api.*;

public abstract class Win32AutoscaleTestBase {
protected Display display;
protected Shell shell;
private boolean autoScaleOnRuntime;

@BeforeClass
@BeforeAll
public static void assumeIsFittingPlatform() {
PlatformSpecificExecution.assumeIsFittingPlatform();
}

@Before
@BeforeEach
public void setUpTest() {
autoScaleOnRuntime = DPITestUtil.isAutoScaleOnRuntimeActive();
display = Display.getDefault();
autoScaleOnRuntime(true);
shell = new Shell(display);
}

@After
@AfterEach
public void tearDownTest() {
if (shell != null) {
shell.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@
*******************************************************************************/
package org.eclipse.swt.widgets;


import static org.junit.Assert.*;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.junit.*;
import org.junit.jupiter.api.*;

/**
* Automated Tests for class org.eclipse.swt.widgets.Control
* for Windows specific behavior
*
* @see org.eclipse.swt.widgets.Control
*/
public class ControlWin32Tests extends Win32AutoscaleTestBase {
class ControlWin32Tests extends Win32AutoscaleTestBase {

@Test
public void testScaleFontCorrectlyInAutoScaleSzenario() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.win32.*;
import org.eclipse.swt.layout.*;
import org.junit.*;

public class WidgetWin32Tests extends Win32AutoscaleTestBase {
class WidgetWin32Tests extends Win32AutoscaleTestBase {

@Test
public void testWidgetZoomShouldChangeOnZoomLevelChange() {
Expand All @@ -24,10 +23,9 @@ public void testWidgetZoomShouldChangeOnZoomLevelChange() {
button.setText("Widget Test");
button.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_CYAN));
shell.open();
assertEquals("The initial zoom is wrong", zoom, button.getZoom()); // pre-condition
assertEquals("The initial zoom is wrong", zoom, button.getZoom()); //pre-condition
changeDPIZoom(scaledZoom);
assertEquals("The Zoom Level should be updated for button on zoom change event on its shell", scaledZoom,
button.getZoom());
assertEquals("The Zoom Level should be updated for button on zoom change event on its shell", scaledZoom, button.getZoom());
}

@Test
Expand All @@ -51,7 +49,7 @@ public void testButtonPointsAfterZooming() throws NoSuchMethodException, Illegal

Assert.assertEquals("Width should be half in points after zooming to 200", p1.x, p2.x * 2);
Assert.assertEquals("Height should be half in points after zooming to 200", p1.y, p2.y * 2);
}
}

@Test
public void testImagePixelsWithDoubleZoomLevel() {
Expand Down

0 comments on commit dae8216

Please sign in to comment.