Skip to content

Commit ad924f9

Browse files
author
jossonsmith
committed
Add Label tests, in which discover a bug that incorrect ignoring
super constructors like public GridData() { super(); }
1 parent 33c54cd commit ad924f9

File tree

1 file changed

+90
-0
lines changed
  • tests/net.sf.j2s.test.swt/src/net/sf/j2s/test/swt/ajunit

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*******************************************************************************
2+
* Java2Script Pacemaker (http://j2s.sourceforge.net)
3+
*
4+
* Copyright (c) 2006 ognize.com and others.
5+
* All rights reserved. This program and the accompanying materials
6+
* are made available under the terms of the Eclipse Public License v1.0
7+
* which accompanies this distribution, and is available at
8+
* http://www.eclipse.org/legal/epl-v10.html
9+
*
10+
* Contributors:
11+
* ognize.com - initial API and implementation
12+
*******************************************************************************/
13+
14+
package net.sf.j2s.test.swt.ajunit;
15+
16+
import net.sf.j2s.ajax.junit.AsyncSWT;
17+
import net.sf.j2s.ajax.junit.AsyncTestCase;
18+
import net.sf.j2s.ajax.junit.AsyncTestRunnable;
19+
import net.sf.j2s.ajax.junit.AsyncTestRunner;
20+
import org.eclipse.swt.SWT;
21+
import org.eclipse.swt.graphics.Color;
22+
import org.eclipse.swt.graphics.Point;
23+
import org.eclipse.swt.layout.GridData;
24+
import org.eclipse.swt.layout.GridLayout;
25+
import org.eclipse.swt.widgets.Display;
26+
import org.eclipse.swt.widgets.Label;
27+
import org.eclipse.swt.widgets.Shell;
28+
29+
/**
30+
* @author josson smith
31+
*
32+
* 2006-8-1
33+
*/
34+
public class LabelTest extends AsyncTestCase {
35+
36+
public void testEmpty() {
37+
Display display = new Display ();
38+
Shell shell = new Shell(display);
39+
shell.setLayout(new GridLayout());
40+
new Label(shell, SWT.BORDER).setText("Hello");
41+
shell.pack();
42+
shell.open ();
43+
//while (!shell.isDisposed ()) {
44+
// if (!display.readAndDispatch ()) display.sleep ();
45+
//}
46+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
47+
public void run() {
48+
assertTrue(true);
49+
}
50+
});
51+
display.dispose ();
52+
}
53+
54+
public void testLabelSize() {
55+
Display display = new Display ();
56+
Shell shell = new Shell(display);
57+
shell.setLayout(new GridLayout());
58+
final Label lbl = new Label(shell, SWT.BORDER);
59+
lbl.setText("Hello");
60+
61+
final Label label0 = new Label(shell, SWT.BORDER);
62+
label0.setText("Hel\r\n\tlo &World");
63+
final Label label2 = new Label(shell, SWT.BORDER);
64+
label2.setText("Hel\r\nlo &Wor&&ld");
65+
label2.setAlignment(SWT.RIGHT);
66+
label2.setForeground(new Color(display, 255, 0, 0));
67+
label2.setEnabled(false);
68+
label2.setLayoutData(new GridData(250, 50));
69+
shell.pack();
70+
shell.open ();
71+
72+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
73+
public void run() {
74+
assertEquals(lbl.getSize(), new Point(25, 15));
75+
}
76+
});
77+
display.dispose ();
78+
}
79+
80+
/**
81+
* ATTENTION: Always run me as SWT Application or Java2Script Application.
82+
* Running me as JUnit Test or Java2Script Unit Test won't work for these
83+
* asynchronous unit tests!
84+
*
85+
* @param args
86+
*/
87+
public static void main(String[] args) {
88+
AsyncTestRunner.asyncRun (LabelTest.class);
89+
}
90+
}

0 commit comments

Comments
 (0)