Skip to content

Commit 0a65341

Browse files
committed
Ensure that CTabItems are rendered
A regression test for #3260 where tabs fail to render if `NSView.setClipsToBounds()` is omited before scheduling redraw. This test fails to reproduce the problem, but is useful as rendering is not tested at all in this suite.
1 parent a4a774c commit 0a65341

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
package org.eclipse.swt.tests.junit;
1515

1616

17+
import static org.eclipse.swt.tests.junit.SwtTestUtil.hasPixel;
18+
import static org.eclipse.swt.tests.junit.SwtTestUtil.openShell;
19+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1720
import static org.junit.jupiter.api.Assertions.assertEquals;
1821
import static org.junit.jupiter.api.Assertions.assertFalse;
1922
import static org.junit.jupiter.api.Assertions.assertNotNull;
2023
import static org.junit.jupiter.api.Assertions.assertNull;
2124
import static org.junit.jupiter.api.Assertions.assertThrows;
22-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2325
import static org.junit.jupiter.api.Assertions.assertTrue;
2426
import static org.junit.jupiter.api.Assertions.fail;
2527

@@ -62,6 +64,8 @@
6264
import org.junit.jupiter.api.Disabled;
6365
import org.junit.jupiter.api.Tag;
6466
import org.junit.jupiter.api.Test;
67+
import org.junit.jupiter.params.ParameterizedTest;
68+
import org.junit.jupiter.params.provider.CsvSource;
6569

6670
/**
6771
* Automated Test Suite for class org.eclipse.swt.custom.CTabFolder
@@ -110,6 +114,8 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() {
110114

111115
/* custom */
112116
protected CTabFolder ctabFolder;
117+
private static final Color RED = new Color(255, 0, 0);
118+
private static final Color BLUE = new Color(0, 0, 255);
113119

114120
/**
115121
* Dispose all widgets in shell and create a new empty {@link CTabFolder}.
@@ -1049,4 +1055,46 @@ public void test_dirtyIndicator_closesWhenCloseEnabled() {
10491055
}
10501056
}
10511057

1058+
1059+
@ParameterizedTest
1060+
@CsvSource(value = {"false,1", "false,2", "true,1", "true,2"})
1061+
public void test_tabsAreRendered(boolean nestComposite, int activateTab) {
1062+
Composite parent = shell;
1063+
Control[] children = shell.getChildren();
1064+
for (Control child : children) {
1065+
child.dispose();
1066+
}
1067+
if (nestComposite) {
1068+
parent = new Composite(parent, SWT.NONE);
1069+
parent.setLayout(new FillLayout());
1070+
}
1071+
ctabFolder = new CTabFolder(parent, SWT.NONE);
1072+
setWidget(ctabFolder);
1073+
shell.setSize(800, 400);
1074+
ctabFolder.setBackground(RED);
1075+
ctabFolder.setForeground(BLUE);
1076+
ctabFolder.setSelectionForeground(BLUE);
1077+
CTabItem tab = createTabItem(1);
1078+
openShell(shell);
1079+
processEvents();
1080+
Rectangle bounds = tab.getBounds();
1081+
assertTrue(hasPixel(ctabFolder, BLUE, bounds));
1082+
tab = createTabItem(2);
1083+
ctabFolder.setSelection(activateTab);
1084+
SwtTestUtil.processEvents();
1085+
bounds = tab.getBounds();
1086+
assertTrue(hasPixel(ctabFolder, BLUE, bounds));
1087+
tab.dispose();
1088+
SwtTestUtil.processEvents();
1089+
assertFalse(hasPixel(ctabFolder, BLUE, bounds));
1090+
}
1091+
1092+
private CTabItem createTabItem(int i) {
1093+
CTabItem item = new CTabItem(ctabFolder, SWT.CLOSE);
1094+
item.setText("█".repeat(10));
1095+
Label content = new Label(ctabFolder, SWT.NONE);
1096+
content.setText("Content " + i);
1097+
item.setControl(content);
1098+
return item;
1099+
}
10521100
}

0 commit comments

Comments
 (0)