|
| 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.Scale; |
| 27 | +import org.eclipse.swt.widgets.Shell; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author josson smith |
| 31 | + * |
| 32 | + * 2006-8-1 |
| 33 | + */ |
| 34 | +public class ScaleTest 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 Scale scaleD = new Scale(shell, SWT.NONE); |
| 41 | + final Scale scaleB = new Scale(shell, SWT.BORDER); |
| 42 | + final Scale scaleV = new Scale(shell, SWT.VERTICAL); |
| 43 | + final Scale scaleS = new Scale(shell, SWT.SMOOTH); |
| 44 | + shell.pack(); |
| 45 | + shell.open (); |
| 46 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 47 | + public void run() { |
| 48 | + System.out.println(scaleD.getSize()); |
| 49 | + System.out.println(scaleB.getSize()); |
| 50 | + System.out.println(scaleV.getSize()); |
| 51 | + System.out.println(scaleS.getSize()); |
| 52 | + |
| 53 | + assertEquals(scaleD.getSize(), new Point(160, 41)); |
| 54 | + assertEquals(scaleB.getSize(), new Point(164, 45)); |
| 55 | + assertEquals(scaleV.getSize(), new Point(41, 160)); |
| 56 | + assertEquals(scaleS.getSize(), new Point(160, 41)); |
| 57 | + } |
| 58 | + }); |
| 59 | + display.dispose (); |
| 60 | + } |
| 61 | + |
| 62 | + |
| 63 | + public void xtestFilledSize() { |
| 64 | + Display display = new Display (); |
| 65 | + Shell shell = new Shell(display); |
| 66 | + shell.setLayout(new FillLayout()); |
| 67 | + final Scale scaleD = new Scale(shell, SWT.NONE); |
| 68 | + final Scale scaleB = new Scale(shell, SWT.BORDER); |
| 69 | + final Scale scaleV = new Scale(shell, SWT.VERTICAL); |
| 70 | + final Scale scaleS = new Scale(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(scaleD.getSize()); |
| 76 | + System.out.println(scaleB.getSize()); |
| 77 | + System.out.println(scaleV.getSize()); |
| 78 | + System.out.println(scaleS.getSize()); |
| 79 | + |
| 80 | + assertEquals(scaleD.getSize(), new Point(58, 107)); |
| 81 | + assertEquals(scaleB.getSize(), new Point(58, 107)); |
| 82 | + assertEquals(scaleV.getSize(), new Point(58, 107)); |
| 83 | + assertEquals(scaleS.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 Scale scaleD = new Scale(shell, SWT.NONE); |
| 95 | + final Scale scaleB = new Scale(shell, SWT.BORDER); |
| 96 | + final Scale scaleV = new Scale(shell, SWT.VERTICAL); |
| 97 | + final Scale scaleS = new Scale(shell, SWT.SMOOTH); |
| 98 | + shell.pack(); |
| 99 | + shell.open (); |
| 100 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 101 | + public void run() { |
| 102 | + System.out.println(scaleD.getBounds()); |
| 103 | + System.out.println(scaleB.getBounds()); |
| 104 | + System.out.println(scaleV.getBounds()); |
| 105 | + System.out.println(scaleS.getBounds()); |
| 106 | + |
| 107 | + assertEquals(scaleD.getBounds(), new Rectangle(5, 5, 160, 41)); |
| 108 | + assertEquals(scaleB.getBounds(), new Rectangle(5, 51, 164, 45)); |
| 109 | + assertEquals(scaleV.getBounds(), new Rectangle(5, 101, 41, 160)); |
| 110 | + assertEquals(scaleS.getBounds(), new Rectangle(5, 266, 160, 41)); |
| 111 | + } |
| 112 | + }); |
| 113 | + display.dispose (); |
| 114 | + } |
| 115 | + |
| 116 | + |
| 117 | + public void xtestFilledBounds() { |
| 118 | + Display display = new Display (); |
| 119 | + Shell shell = new Shell(display); |
| 120 | + shell.setLayout(new FillLayout()); |
| 121 | + final Scale scaleD = new Scale(shell, SWT.NONE); |
| 122 | + final Scale scaleB = new Scale(shell, SWT.BORDER); |
| 123 | + final Scale scaleV = new Scale(shell, SWT.VERTICAL); |
| 124 | + final Scale scaleS = new Scale(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(scaleD.getBounds()); |
| 130 | + System.out.println(scaleB.getBounds()); |
| 131 | + System.out.println(scaleV.getBounds()); |
| 132 | + System.out.println(scaleS.getBounds()); |
| 133 | + |
| 134 | + assertEquals(scaleD.getBounds(), new Rectangle(0, 0, 58, 107)); |
| 135 | + assertEquals(scaleB.getBounds(), new Rectangle(58, 0, 58, 107)); |
| 136 | + assertEquals(scaleV.getBounds(), new Rectangle(116, 0, 58, 107)); |
| 137 | + assertEquals(scaleS.getBounds(), new Rectangle(174, 0, 58, 107)); |
| 138 | + } |
| 139 | + }); |
| 140 | + display.dispose (); |
| 141 | + } |
| 142 | + |
| 143 | + public void xtestDefaultValue() { |
| 144 | + Display display = new Display (); |
| 145 | + Shell shell = new Shell(display); |
| 146 | + shell.setLayout(new GridLayout()); |
| 147 | + final Scale scaleD = new Scale(shell, SWT.NONE); |
| 148 | + final Scale scaleB = new Scale(shell, SWT.BORDER); |
| 149 | + final Scale scaleV = new Scale(shell, SWT.VERTICAL); |
| 150 | + final Scale scaleS = new Scale(shell, SWT.SMOOTH); |
| 151 | + shell.pack(); |
| 152 | + shell.open (); |
| 153 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 154 | + public void run() { |
| 155 | + System.out.println(scaleD.getMaximum()); |
| 156 | + System.out.println(scaleB.getMaximum()); |
| 157 | + System.out.println(scaleV.getMaximum()); |
| 158 | + System.out.println(scaleS.getMaximum()); |
| 159 | + |
| 160 | + assertEquals(scaleD.getMaximum(), 100); |
| 161 | + assertEquals(scaleB.getMaximum(), 100); |
| 162 | + assertEquals(scaleV.getMaximum(), 100); |
| 163 | + assertEquals(scaleS.getMaximum(), 100); |
| 164 | + } |
| 165 | + }); |
| 166 | + display.dispose (); |
| 167 | + } |
| 168 | + |
| 169 | + |
| 170 | + public void xtestSelectionValue() { |
| 171 | + Display display = new Display (); |
| 172 | + Shell shell = new Shell(display); |
| 173 | + shell.setLayout(new GridLayout()); |
| 174 | + final Scale scaleD = new Scale(shell, SWT.NONE); |
| 175 | + final Scale scaleB = new Scale(shell, SWT.BORDER); |
| 176 | + final Scale scaleV = new Scale(shell, SWT.VERTICAL); |
| 177 | + final Scale scaleS = new Scale(shell, SWT.SMOOTH); |
| 178 | + shell.pack(); |
| 179 | + shell.open (); |
| 180 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 181 | + public void run() { |
| 182 | + scaleD.setSelection(20); |
| 183 | + scaleB.setSelection(120); |
| 184 | + scaleV.setSelection(-20); |
| 185 | + scaleS.setSelection(100); |
| 186 | + |
| 187 | + assertEquals(scaleD.getSelection(), 20); |
| 188 | + assertEquals(scaleB.getSelection(), 100); |
| 189 | + assertEquals(scaleV.getSelection(), 0); |
| 190 | + assertEquals(scaleS.getSelection(), 100); |
| 191 | + } |
| 192 | + }); |
| 193 | + display.dispose (); |
| 194 | + } |
| 195 | + |
| 196 | + |
| 197 | + public void xtestMaximumValue() { |
| 198 | + Display display = new Display (); |
| 199 | + Shell shell = new Shell(display); |
| 200 | + shell.setLayout(new GridLayout()); |
| 201 | + final Scale scaleD = new Scale(shell, SWT.NONE); |
| 202 | + final Scale scaleB = new Scale(shell, SWT.BORDER); |
| 203 | + final Scale scaleV = new Scale(shell, SWT.VERTICAL); |
| 204 | + final Scale scaleS = new Scale(shell, SWT.SMOOTH); |
| 205 | + final Scale scaleX = new Scale(shell, SWT.INDETERMINATE); |
| 206 | + new Scale(shell, SWT.SMOOTH | SWT.INDETERMINATE); |
| 207 | + new Scale(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 | + scaleD.setSelection(20); |
| 214 | + scaleB.setSelection(-20); |
| 215 | + scaleV.setSelection(120); |
| 216 | + scaleS.setSelection(100); |
| 217 | + scaleX.setSelection(5); |
| 218 | + |
| 219 | + scaleD.setMaximum(40); |
| 220 | + scaleB.setMaximum(-80); |
| 221 | + scaleV.setMaximum(250); |
| 222 | + scaleS.setMaximum(50); |
| 223 | + |
| 224 | + assertEquals("Default", scaleD.getSelection(), 20); |
| 225 | + assertEquals("Border", scaleB.getSelection(), 0); |
| 226 | + assertEquals("Vertical", scaleV.getSelection(), 100); |
| 227 | + assertEquals("Smooth", scaleS.getSelection(), 50); |
| 228 | + assertEquals("Indeterminate", scaleX.getSelection(), 5); |
| 229 | + |
| 230 | + } |
| 231 | + }); |
| 232 | + display.dispose (); |
| 233 | + } |
| 234 | + |
| 235 | + |
| 236 | + public void xtestMinimumValue() { |
| 237 | + Display display = new Display (); |
| 238 | + Shell shell = new Shell(display); |
| 239 | + shell.setLayout(new GridLayout()); |
| 240 | + final Scale scaleD = new Scale(shell, SWT.NONE); |
| 241 | + final Scale scaleB = new Scale(shell, SWT.BORDER); |
| 242 | + final Scale scaleV = new Scale(shell, SWT.VERTICAL); |
| 243 | + final Scale scaleS = new Scale(shell, SWT.SMOOTH); |
| 244 | + final Scale scaleX = new Scale(shell, SWT.INDETERMINATE); |
| 245 | + //new Scale(shell, SWT.SMOOTH | SWT.INDETERMINATE); |
| 246 | + //new Scale(shell, SWT.VERTICAL | SWT.INDETERMINATE); |
| 247 | + shell.pack(); |
| 248 | + shell.open (); |
| 249 | + //AsyncSWT.setShellAutoClose(false); |
| 250 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 251 | + public void run() { |
| 252 | + scaleD.setSelection(20); |
| 253 | + scaleB.setSelection(-20); |
| 254 | + scaleV.setSelection(120); |
| 255 | + scaleS.setSelection(100); |
| 256 | + scaleX.setSelection(45); |
| 257 | + |
| 258 | + scaleD.setMinimum(40); |
| 259 | + scaleB.setMinimum(-80); |
| 260 | + scaleV.setMinimum(250); |
| 261 | + scaleS.setMinimum(50); |
| 262 | + scaleX.setMinimum(70); |
| 263 | + |
| 264 | + assertEquals("Default", scaleD.getSelection(), 40); |
| 265 | + assertEquals("Border", scaleB.getSelection(), 0); |
| 266 | + assertEquals("Vertical", scaleV.getSelection(), 100); |
| 267 | + assertEquals("Smooth", scaleS.getSelection(), 100); |
| 268 | + assertEquals("Indeterminate", scaleX.getSelection(), 70); |
| 269 | + |
| 270 | + } |
| 271 | + }); |
| 272 | + display.dispose (); |
| 273 | + } |
| 274 | + |
| 275 | + /** |
| 276 | + * ATTENTION: Always run me as SWT Application or Java2Script Application. |
| 277 | + * Running me as JUnit Test or Java2Script Unit Test won't work for these |
| 278 | + * asynchronous unit tests! |
| 279 | + * |
| 280 | + * @param args |
| 281 | + */ |
| 282 | + public static void main(String[] args) { |
| 283 | + AsyncSWT.setShellAutoClose(false); |
| 284 | + AsyncTestRunner.asyncRun (ScaleTest.class); |
| 285 | + } |
| 286 | +} |
0 commit comments