Skip to content

Commit 43b3c88

Browse files
author
jossonsmith
committed
ProgressBar improved with help of asynchronous JUnit tests.
Support SWT.INDETERMINATE and non-SWT.SMOOTH in ProgressBar.
1 parent b39758b commit 43b3c88

1 file changed

Lines changed: 246 additions & 0 deletions

File tree

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
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.graphics.Rectangle;
23+
import org.eclipse.swt.layout.FillLayout;
24+
import org.eclipse.swt.layout.GridLayout;
25+
import org.eclipse.swt.widgets.Display;
26+
import org.eclipse.swt.widgets.ProgressBar;
27+
import org.eclipse.swt.widgets.Shell;
28+
29+
/**
30+
* @author josson smith
31+
*
32+
* 2006-8-1
33+
*/
34+
public class ProgressBarTest extends AsyncTestCase {
35+
36+
public void testDefaultSize() {
37+
Display display = new Display ();
38+
Shell shell = new Shell(display);
39+
shell.setLayout(new GridLayout());
40+
final ProgressBar progressD = new ProgressBar(shell, SWT.NONE);
41+
final ProgressBar progressB = new ProgressBar(shell, SWT.BORDER);
42+
final ProgressBar progressV = new ProgressBar(shell, SWT.VERTICAL);
43+
final ProgressBar progressS = new ProgressBar(shell, SWT.SMOOTH);
44+
shell.pack();
45+
shell.open ();
46+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
47+
public void run() {
48+
System.out.println(progressD.getSize());
49+
System.out.println(progressB.getSize());
50+
System.out.println(progressV.getSize());
51+
System.out.println(progressS.getSize());
52+
53+
assertEquals(progressD.getSize(), new Point(162, 18));
54+
assertEquals(progressB.getSize(), new Point(162, 18));
55+
assertEquals(progressV.getSize(), new Point(18, 162));
56+
assertEquals(progressS.getSize(), new Point(162, 18));
57+
}
58+
});
59+
display.dispose ();
60+
}
61+
62+
63+
public void testFilledSize() {
64+
Display display = new Display ();
65+
Shell shell = new Shell(display);
66+
shell.setLayout(new FillLayout());
67+
final ProgressBar progressD = new ProgressBar(shell, SWT.NONE);
68+
final ProgressBar progressB = new ProgressBar(shell, SWT.BORDER);
69+
final ProgressBar progressV = new ProgressBar(shell, SWT.VERTICAL);
70+
final ProgressBar progressS = new ProgressBar(shell, SWT.SMOOTH);
71+
shell.setSize(240, 135);
72+
shell.open ();
73+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
74+
public void run() {
75+
System.out.println(progressD.getSize());
76+
System.out.println(progressB.getSize());
77+
System.out.println(progressV.getSize());
78+
System.out.println(progressS.getSize());
79+
80+
assertEquals(progressD.getSize(), new Point(58, 107));
81+
assertEquals(progressB.getSize(), new Point(58, 107));
82+
assertEquals(progressV.getSize(), new Point(58, 107));
83+
assertEquals(progressS.getSize(), new Point(58, 107));
84+
}
85+
});
86+
display.dispose ();
87+
}
88+
89+
90+
public void testDefaultBounds() {
91+
Display display = new Display ();
92+
Shell shell = new Shell(display);
93+
shell.setLayout(new GridLayout());
94+
final ProgressBar progressD = new ProgressBar(shell, SWT.NONE);
95+
final ProgressBar progressB = new ProgressBar(shell, SWT.BORDER);
96+
final ProgressBar progressV = new ProgressBar(shell, SWT.VERTICAL);
97+
final ProgressBar progressS = new ProgressBar(shell, SWT.SMOOTH);
98+
shell.pack();
99+
shell.open ();
100+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
101+
public void run() {
102+
System.out.println(progressD.getBounds());
103+
System.out.println(progressB.getBounds());
104+
System.out.println(progressV.getBounds());
105+
System.out.println(progressS.getBounds());
106+
107+
assertEquals(progressD.getBounds(), new Rectangle(5, 5, 162, 18));
108+
assertEquals(progressB.getBounds(), new Rectangle(5, 28, 162, 18));
109+
assertEquals(progressV.getBounds(), new Rectangle(5, 51,18, 162));
110+
assertEquals(progressS.getBounds(), new Rectangle(5, 218, 162, 18));
111+
}
112+
});
113+
display.dispose ();
114+
}
115+
116+
117+
public void testFilledBounds() {
118+
Display display = new Display ();
119+
Shell shell = new Shell(display);
120+
shell.setLayout(new FillLayout());
121+
final ProgressBar progressD = new ProgressBar(shell, SWT.NONE);
122+
final ProgressBar progressB = new ProgressBar(shell, SWT.BORDER);
123+
final ProgressBar progressV = new ProgressBar(shell, SWT.VERTICAL);
124+
final ProgressBar progressS = new ProgressBar(shell, SWT.SMOOTH);
125+
shell.setSize(240, 135);
126+
shell.open ();
127+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
128+
public void run() {
129+
System.out.println(progressD.getBounds());
130+
System.out.println(progressB.getBounds());
131+
System.out.println(progressV.getBounds());
132+
System.out.println(progressS.getBounds());
133+
134+
assertEquals(progressD.getBounds(), new Rectangle(0, 0, 58, 107));
135+
assertEquals(progressB.getBounds(), new Rectangle(58, 0, 58, 107));
136+
assertEquals(progressV.getBounds(), new Rectangle(116, 0, 58, 107));
137+
assertEquals(progressS.getBounds(), new Rectangle(174, 0, 58, 107));
138+
}
139+
});
140+
display.dispose ();
141+
}
142+
143+
public void testDefaultValue() {
144+
Display display = new Display ();
145+
Shell shell = new Shell(display);
146+
shell.setLayout(new GridLayout());
147+
final ProgressBar progressD = new ProgressBar(shell, SWT.NONE);
148+
final ProgressBar progressB = new ProgressBar(shell, SWT.BORDER);
149+
final ProgressBar progressV = new ProgressBar(shell, SWT.VERTICAL);
150+
final ProgressBar progressS = new ProgressBar(shell, SWT.SMOOTH);
151+
shell.pack();
152+
shell.open ();
153+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
154+
public void run() {
155+
System.out.println(progressD.getMaximum());
156+
System.out.println(progressB.getMaximum());
157+
System.out.println(progressV.getMaximum());
158+
System.out.println(progressS.getMaximum());
159+
160+
assertEquals(progressD.getMaximum(), 100);
161+
assertEquals(progressB.getMaximum(), 100);
162+
assertEquals(progressV.getMaximum(), 100);
163+
assertEquals(progressS.getMaximum(), 100);
164+
}
165+
});
166+
display.dispose ();
167+
}
168+
169+
170+
public void testSelectionValue() {
171+
Display display = new Display ();
172+
Shell shell = new Shell(display);
173+
shell.setLayout(new GridLayout());
174+
final ProgressBar progressD = new ProgressBar(shell, SWT.NONE);
175+
final ProgressBar progressB = new ProgressBar(shell, SWT.BORDER);
176+
final ProgressBar progressV = new ProgressBar(shell, SWT.VERTICAL);
177+
final ProgressBar progressS = new ProgressBar(shell, SWT.SMOOTH);
178+
shell.pack();
179+
shell.open ();
180+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
181+
public void run() {
182+
progressD.setSelection(20);
183+
progressB.setSelection(120);
184+
progressV.setSelection(-20);
185+
progressS.setSelection(100);
186+
187+
assertEquals(progressD.getSelection(), 20);
188+
assertEquals(progressB.getSelection(), 100);
189+
assertEquals(progressV.getSelection(), 0);
190+
assertEquals(progressS.getSelection(), 100);
191+
}
192+
});
193+
display.dispose ();
194+
}
195+
196+
197+
public void testMaximumValue() {
198+
Display display = new Display ();
199+
Shell shell = new Shell(display);
200+
shell.setLayout(new GridLayout());
201+
final ProgressBar progressD = new ProgressBar(shell, SWT.NONE);
202+
final ProgressBar progressB = new ProgressBar(shell, SWT.BORDER);
203+
final ProgressBar progressV = new ProgressBar(shell, SWT.VERTICAL);
204+
final ProgressBar progressS = new ProgressBar(shell, SWT.SMOOTH);
205+
final ProgressBar progressX = new ProgressBar(shell, SWT.INDETERMINATE);
206+
new ProgressBar(shell, SWT.SMOOTH | SWT.INDETERMINATE);
207+
new ProgressBar(shell, SWT.VERTICAL | SWT.INDETERMINATE);
208+
shell.pack();
209+
shell.open ();
210+
//AsyncSWT.setShellAutoClose(false);
211+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
212+
public void run() {
213+
progressD.setSelection(20);
214+
progressB.setSelection(-20);
215+
progressV.setSelection(120);
216+
progressS.setSelection(100);
217+
progressX.setSelection(5);
218+
219+
progressD.setMaximum(40);
220+
progressB.setMaximum(-80);
221+
progressV.setMaximum(250);
222+
progressS.setMaximum(50);
223+
224+
assertEquals("Default", progressD.getSelection(), 20);
225+
assertEquals("Border", progressB.getSelection(), 0);
226+
assertEquals("Vertical", progressV.getSelection(), 100);
227+
assertEquals("Smooth", progressS.getSelection(), 50);
228+
assertEquals("Indeterminate", progressX.getSelection(), 5);
229+
230+
}
231+
});
232+
display.dispose ();
233+
}
234+
235+
/**
236+
* ATTENTION: Always run me as SWT Application or Java2Script Application.
237+
* Running me as JUnit Test or Java2Script Unit Test won't work for these
238+
* asynchronous unit tests!
239+
*
240+
* @param args
241+
*/
242+
public static void main(String[] args) {
243+
// AsyncSWT.setShellAutoClose(false);
244+
AsyncTestRunner.asyncRun (ProgressBarTest.class);
245+
}
246+
}

0 commit comments

Comments
 (0)