Skip to content

Commit 1f17a10

Browse files
author
jossonsmith
committed
Update testcases
1 parent 60b1956 commit 1f17a10

File tree

5 files changed

+541
-3
lines changed

5 files changed

+541
-3
lines changed
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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.Point;
22+
import org.eclipse.swt.layout.FillLayout;
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.Shell;
27+
import org.eclipse.swt.widgets.Text;
28+
29+
/**
30+
* @author josson smith
31+
*
32+
* 2006-8-1
33+
*/
34+
public class TextTest extends AsyncTestCase {
35+
36+
public void testMultiTextStringSize() {
37+
Display display = new Display ();
38+
final Shell shell = new Shell(display);
39+
shell.setLayout(new GridLayout());
40+
final Text txt0 = new Text(shell, SWT.WRAP | SWT.MULTI);
41+
txt0.setText("423424x fww");
42+
final Text txt1 = new Text(shell, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI);
43+
txt1.setText("42999xxxxxxxx xx");
44+
txt1.setLayoutData(new GridData(120, 20));
45+
final Text txt2 = new Text(shell, SWT.BORDER | SWT.MULTI);
46+
txt2.setText(" ");
47+
final Text txt3 = new Text(shell, SWT.FLAT | SWT.MULTI);
48+
txt3.setText("-----=2 ===---===");
49+
final Text txt4 = new Text(shell, SWT.WRAP | SWT.FLAT | SWT.MULTI);
50+
txt4.setText("-----=2== =---===");
51+
final Text txt5 = new Text(shell, SWT.NONE | SWT.MULTI);
52+
txt5.setText("---- -=2===---== =");
53+
shell.pack();
54+
shell.open ();
55+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
56+
public void run() {
57+
System.out.println(txt0.getSize());
58+
System.out.println(txt1.getSize());
59+
System.out.println(txt2.getSize());
60+
System.out.println(txt3.getSize());
61+
System.out.println(txt4.getSize());
62+
System.out.println(txt5.getSize());
63+
assertEquals(txt0.getSize(), new Point(71, 13));
64+
assertEquals(txt1.getSize(), new Point(132, 26));
65+
assertEquals(txt2.getSize(), new Point(15, 19));
66+
assertEquals(txt3.getSize(), new Point(103, 13));
67+
assertEquals(txt4.getSize(), new Point(103, 13));
68+
assertEquals(txt5.getSize(), new Point(106, 13));
69+
}
70+
});
71+
display.dispose ();
72+
//AsyncSWT.setShellAutoClose(true);
73+
}
74+
75+
public void testTextStringSize() {
76+
Display display = new Display ();
77+
final Shell shell = new Shell(display);
78+
shell.setLayout(new GridLayout());
79+
final Text txt0 = new Text(shell, SWT.WRAP);
80+
txt0.setText("423424xfww");
81+
final Text txt1 = new Text(shell, SWT.BORDER | SWT.READ_ONLY);
82+
txt1.setText("42999xxx");
83+
txt1.setLayoutData(new GridData(120, 20));
84+
final Text txt2 = new Text(shell, SWT.BORDER);
85+
txt2.setText(" ");
86+
final Text txt3 = new Text(shell, SWT.FLAT);
87+
txt3.setText("-----=2===---===");
88+
final Text txt4 = new Text(shell, SWT.WRAP | SWT.FLAT);
89+
txt4.setText("-----=2===---===");
90+
final Text txt5 = new Text(shell, SWT.NONE);
91+
txt5.setText("-----=2===---===");
92+
shell.pack();
93+
shell.open ();
94+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
95+
public void run() {
96+
System.out.println(txt0.getSize());
97+
System.out.println(txt1.getSize());
98+
System.out.println(txt2.getSize());
99+
System.out.println(txt3.getSize());
100+
System.out.println(txt4.getSize());
101+
System.out.println(txt5.getSize());
102+
assertEquals(txt0.getSize(), new Point(68, 13));
103+
assertEquals(txt1.getSize(), new Point(127, 26));
104+
assertEquals(txt2.getSize(), new Point(10, 19));
105+
assertEquals(txt3.getSize(), new Point(95, 13));
106+
assertEquals(txt4.getSize(), new Point(100, 13));
107+
assertEquals(txt5.getSize(), new Point(95, 13));
108+
}
109+
});
110+
display.dispose ();
111+
//AsyncSWT.setShellAutoClose(true);
112+
}
113+
114+
public void testTextSize() {
115+
Display display = new Display ();
116+
final Shell shell = new Shell(display);
117+
shell.setLayout(new GridLayout());
118+
final Text txt1 = new Text(shell, SWT.BORDER | SWT.READ_ONLY);
119+
txt1.setLayoutData(new GridData(120, 20));
120+
final Text txt0 = new Text(shell, SWT.WRAP);
121+
final Text txt2 = new Text(shell, SWT.BORDER);
122+
final Text txt3 = new Text(shell, SWT.FLAT);
123+
shell.pack();
124+
shell.open ();
125+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
126+
public void run() {
127+
System.out.println(txt0.getSize());
128+
System.out.println(txt1.getSize());
129+
System.out.println(txt2.getSize());
130+
System.out.println(txt3.getSize());
131+
assertEquals(txt0.getSize(), new Point(70, 13));
132+
assertEquals(txt1.getSize(), new Point(127, 26));
133+
assertEquals(txt2.getSize(), new Point(71, 19));
134+
assertEquals(txt3.getSize(), new Point(65, 13));
135+
}
136+
});
137+
display.dispose ();
138+
//AsyncSWT.setShellAutoClose(true);
139+
}
140+
141+
public void testFilledTextSize() {
142+
Display display = new Display ();
143+
final Shell shell = new Shell(display);
144+
shell.setLayout(new FillLayout());
145+
final Text txt1 = new Text(shell, SWT.NONE);
146+
final Text txt2 = new Text(shell, SWT.BORDER);
147+
shell.pack();
148+
shell.open ();
149+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
150+
public void run() {
151+
System.out.println(txt1.getSize());
152+
System.out.println(txt2.getSize());
153+
assertEquals(txt1.getSize(), new Point(71, 19));
154+
assertEquals(txt2.getSize(), new Point(71, 19));
155+
}
156+
});
157+
display.dispose ();
158+
}
159+
160+
161+
public void testSetTextSize() {
162+
Display display = new Display ();
163+
final Shell shell = new Shell(display);
164+
shell.setLayout(new GridLayout());
165+
final Text txt1 = new Text(shell, SWT.NONE);
166+
txt1.setLayoutData(new GridData(120, 40));
167+
txt1.setEnabled(false);
168+
final Text txt2 = new Text(shell, SWT.BORDER);
169+
txt2.setLayoutData(new GridData(150, 50));
170+
final Text txt3 = new Text(shell, SWT.NONE);
171+
txt3.setLayoutData(new GridData(120, 30));
172+
final Text txt0 = new Text(shell, SWT.NONE);
173+
txt0.setLayoutData(new GridData(120, 24));
174+
final Text txt4 = new Text(shell, SWT.NONE);
175+
txt4.setLayoutData(new GridData(120, 20));
176+
final Text txt5 = new Text(shell, SWT.NONE);
177+
txt5.setLayoutData(new GridData(120, 10));
178+
final Text txt6 = new Text(shell, SWT.NONE);
179+
txt6.setLayoutData(new GridData(120, 16));
180+
shell.pack();
181+
shell.open ();
182+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
183+
public void run() {
184+
System.out.println(txt1.getSize());
185+
System.out.println(txt2.getSize());
186+
assertEquals(txt1.getSize(), new Point(121, 40));
187+
assertEquals(txt2.getSize(), new Point(157, 56));
188+
}
189+
});
190+
display.dispose ();
191+
}
192+
193+
public static void main(String[] args) {
194+
AsyncSWT.setShellAutoClose(false);
195+
AsyncTestRunner.asyncRun (TextTest.class);
196+
}
197+
}

tests/net.sf.j2s.test.swt/src/net/sf/j2s/test/swt/ajunit/TreeStructureTest2.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.eclipse.swt.SWT;
2121
import org.eclipse.swt.layout.FillLayout;
2222
import org.eclipse.swt.widgets.Display;
23+
import org.eclipse.swt.widgets.Event;
24+
import org.eclipse.swt.widgets.Listener;
2325
import org.eclipse.swt.widgets.Shell;
2426
import org.eclipse.swt.widgets.Tree;
2527
import org.eclipse.swt.widgets.TreeItem;
@@ -31,6 +33,89 @@
3133
*/
3234
public class TreeStructureTest2 extends AsyncTestCase {
3335

36+
public void testStruct6() {
37+
Display display = new Display ();
38+
Shell shell = new Shell (display);
39+
shell.setLayout(new FillLayout());
40+
final Tree tree = new Tree (shell, SWT.BORDER | SWT.CHECK);
41+
tree.setSize (100, 100);
42+
shell.setSize (300, 200);
43+
for (int i = 0; i < 4; i++) {
44+
TreeItem item = new TreeItem (tree, SWT.NONE);
45+
item.setText("Node." + (i + 1));
46+
if (i < 3) {
47+
TreeItem subitem = new TreeItem (item, SWT.NONE);
48+
subitem.setText("Node." + (i + 1) + ".1");
49+
}
50+
}
51+
52+
tree.addListener (SWT.Expand, new Listener () {
53+
public void handleEvent (final Event event) {
54+
final TreeItem root = (TreeItem) event.item;
55+
TreeItem [] items = root.getItems ();
56+
for (int i= 0; i<items.length; i++) {
57+
if (items [i].getData () != null) {
58+
return;
59+
}
60+
items [i].dispose ();
61+
}
62+
for (int i = 0; i < 3; i++) {
63+
TreeItem treeItem = new TreeItem (root, 0);
64+
treeItem.setText("New " + i);
65+
TreeItem subitem = new TreeItem (treeItem, SWT.NONE);
66+
subitem.setText("Node." + i + ".1");
67+
}
68+
root.setExpanded(true);
69+
}
70+
});
71+
shell.open ();
72+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
73+
public void run() {
74+
}
75+
});
76+
display.dispose ();
77+
}
78+
79+
public void testStruct5() {
80+
Display display = new Display ();
81+
Shell shell = new Shell (display);
82+
shell.setLayout(new FillLayout());
83+
final Tree tree = new Tree (shell, SWT.BORDER | SWT.CHECK);
84+
tree.setSize (100, 100);
85+
shell.setSize (300, 200);
86+
for (int i = 0; i < 4; i++) {
87+
TreeItem item = new TreeItem (tree, SWT.NONE);
88+
item.setText("Node." + (i + 1));
89+
if (i < 3) {
90+
TreeItem subitem = new TreeItem (item, SWT.NONE);
91+
subitem.setText("Node." + (i + 1) + ".1");
92+
}
93+
}
94+
95+
tree.addListener (SWT.Expand, new Listener () {
96+
public void handleEvent (final Event event) {
97+
final TreeItem root = (TreeItem) event.item;
98+
TreeItem [] items = root.getItems ();
99+
for (int i= 0; i<items.length; i++) {
100+
if (items [i].getData () != null) {
101+
return;
102+
}
103+
items [i].dispose ();
104+
}
105+
for (int i = 0; i < 3; i++) {
106+
TreeItem treeItem = new TreeItem (root, 0);
107+
treeItem.setText("New " + i);
108+
}
109+
root.setExpanded(true);
110+
}
111+
});
112+
shell.open ();
113+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
114+
public void run() {
115+
}
116+
});
117+
display.dispose ();
118+
}
34119

35120
public void testStruct4() {
36121
Display display = new Display ();

0 commit comments

Comments
 (0)