1 /*******************************************************************************
2  * Copyright (c) 2000, 2015 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.tests.junit;
15 
16 
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.fail;
19 
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.widgets.Scale;
22 import org.junit.Before;
23 import org.junit.Test;
24 
25 /**
26  * Automated Test Suite for class org.eclipse.swt.widgets.Scale
27  *
28  * @see org.eclipse.swt.widgets.Scale
29  */
30 public class Test_org_eclipse_swt_widgets_Scale extends Test_org_eclipse_swt_widgets_Control {
31 
32 @Override
33 @Before
setUp()34 public void setUp() {
35 	super.setUp();
36 	scale = new Scale(shell, 0);
37 	setWidget(scale);
38 }
39 
40 @Override
41 @Test
test_ConstructorLorg_eclipse_swt_widgets_CompositeI()42 public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() {
43 	try {
44 		scale = new Scale(null, 0);
45 		fail("No exception occurred"); //should never get here
46 	}
47 	catch (IllegalArgumentException e) {
48 	}
49 
50 	int[] cases = {0, SWT.HORIZONTAL, SWT.VERTICAL};
51 	for (int style : cases)
52 		scale = new Scale(shell, style);
53 }
54 
55 @Override
56 @Test
test_computeSizeIIZ()57 public void test_computeSizeIIZ() {
58 }
59 
60 @Test
test_setMaximumI()61 public void test_setMaximumI() {
62 
63 	int [][] testValues = getSetMaximumValues();
64 
65 	for (int[] intArray : testValues) {
66 		setDefaults();
67 		scale.setMaximum(intArray[0]);
68 		report("setMaximum", intArray[0], intArray[1], intArray[2], intArray[3]);
69 	}
70 }
71 
72 @Test
test_setMinimumI()73 public void test_setMinimumI() {
74 
75 
76 	int [][] testValues = getSetMinimumValues();
77 
78 	for (int[] intArray : testValues) {
79 		setDefaults();
80 		scale.setMinimum(intArray[0]);
81 		report("setMinimum", intArray[0], intArray[1], intArray[2], intArray[3]);
82 	}
83 }
84 
85 @Test
test_setSelectionI()86 public void test_setSelectionI() {
87 	int [][] testValues = getSetSelectionValues();
88 	for (int[] intArray : testValues) {
89 		setDefaults();
90 		scale.setSelection(intArray[0]);
91 		report("setSelection", intArray[0], intArray[1], intArray[2], intArray[3]);
92 	}
93 }
94 
95 /* custom */
96 @Override
97 @Test
test_setFontLorg_eclipse_swt_graphics_Font()98 public void test_setFontLorg_eclipse_swt_graphics_Font() {
99 	// overridden from Control because it does not make sense
100 	// to set the font of a Scale.
101 }
102 
103 Scale scale;
104 
105 // this method must be private or protected so the auto-gen tool keeps it
report(String call, int set, int minExpected, int maxExpected, int selectionExpected)106 private void report(String call, int set, int minExpected, int maxExpected, int selectionExpected) {
107 	//Uncomment these lines and comment out call to check() if you want the test to report all errors without
108 	//stopping.
109 
110 	//if (trackBar.getMinimum() != minExpected)
111 		//System.out.println(call + "(" + set + "): Minimum Expected: " + minExpected + "  Actual: " + trackBar.getMinimum());
112 	//if (trackBar.getMaximum() != maxExpected)
113 		//System.out.println(call + "(" + set + "): Maximum Expected: " + maxExpected + "  Actual: " + trackBar.getMaximum());
114 	//if (trackBar.getSelection() != selectionExpected)
115 		//System.out.println(call + "(" + set + "): Selection Expected: " + selectionExpected + "  Actual: " + trackBar.getSelection());
116 	check(minExpected, maxExpected, selectionExpected);
117 }
118 // this method must be private or protected so the auto-gen tool keeps it
check(int minExpected, int maxExpected, int selectionExpected)119 private void check(int minExpected, int maxExpected, int selectionExpected) {
120 	assertEquals(scale.getMaximum(), maxExpected);
121 	assertEquals(scale.getMinimum(), minExpected);
122 	assertEquals(scale.getSelection(), selectionExpected);
123 }
124 // this method must be private or protected so the auto-gen tool keeps it
getSetMinimumValues()125 private int[][] getSetMinimumValues() {
126 return new int[][] {
127 {-15, 10, 100, 50, },
128 {-14, 10, 100, 50, },
129 {-13, 10, 100, 50, },
130 {-12, 10, 100, 50, },
131 {-11, 10, 100, 50, },
132 {-10, 10, 100, 50, },
133 {-9, 10, 100, 50, },
134 {-8, 10, 100, 50, },
135 {-7, 10, 100, 50, },
136 {-6, 10, 100, 50, },
137 {-5, 10, 100, 50, },
138 {-4, 10, 100, 50, },
139 {-3, 10, 100, 50, },
140 {-2, 10, 100, 50, },
141 {-1, 10, 100, 50, },
142 {0, 0, 100, 50, },
143 {1, 1, 100, 50, },
144 {2, 2, 100, 50, },
145 {3, 3, 100, 50, },
146 {4, 4, 100, 50, },
147 {5, 5, 100, 50, },
148 {6, 6, 100, 50, },
149 {7, 7, 100, 50, },
150 {8, 8, 100, 50, },
151 {9, 9, 100, 50, },
152 {10, 10, 100, 50, },
153 {11, 11, 100, 50, },
154 {12, 12, 100, 50, },
155 {13, 13, 100, 50, },
156 {14, 14, 100, 50, },
157 {15, 15, 100, 50, },
158 {16, 16, 100, 50, },
159 {17, 17, 100, 50, },
160 {18, 18, 100, 50, },
161 {19, 19, 100, 50, },
162 {20, 20, 100, 50, },
163 {21, 21, 100, 50, },
164 {22, 22, 100, 50, },
165 {23, 23, 100, 50, },
166 {24, 24, 100, 50, },
167 {25, 25, 100, 50, },
168 {26, 26, 100, 50, },
169 {27, 27, 100, 50, },
170 {28, 28, 100, 50, },
171 {29, 29, 100, 50, },
172 {30, 30, 100, 50, },
173 {31, 31, 100, 50, },
174 {32, 32, 100, 50, },
175 {33, 33, 100, 50, },
176 {34, 34, 100, 50, },
177 {35, 35, 100, 50, },
178 {36, 36, 100, 50, },
179 {37, 37, 100, 50, },
180 {38, 38, 100, 50, },
181 {39, 39, 100, 50, },
182 {40, 40, 100, 50, },
183 {41, 41, 100, 50, },
184 {42, 42, 100, 50, },
185 {43, 43, 100, 50, },
186 {44, 44, 100, 50, },
187 {45, 45, 100, 50, },
188 {46, 46, 100, 50, },
189 {47, 47, 100, 50, },
190 {48, 48, 100, 50, },
191 {49, 49, 100, 50, },
192 {50, 50, 100, 50, },
193 {51, 51, 100, 51, },
194 {52, 52, 100, 52, },
195 {53, 53, 100, 53, },
196 {54, 54, 100, 54, },
197 {55, 55, 100, 55, },
198 {56, 56, 100, 56, },
199 {57, 57, 100, 57, },
200 {58, 58, 100, 58, },
201 {59, 59, 100, 59, },
202 {60, 60, 100, 60, },
203 {61, 61, 100, 61, },
204 {62, 62, 100, 62, },
205 {63, 63, 100, 63, },
206 {64, 64, 100, 64, },
207 {65, 65, 100, 65, },
208 {66, 66, 100, 66, },
209 {67, 67, 100, 67, },
210 {68, 68, 100, 68, },
211 {69, 69, 100, 69, },
212 {70, 70, 100, 70, },
213 {71, 71, 100, 71, },
214 {72, 72, 100, 72, },
215 {73, 73, 100, 73, },
216 {74, 74, 100, 74, },
217 {75, 75, 100, 75, },
218 {76, 76, 100, 76, },
219 {77, 77, 100, 77, },
220 {78, 78, 100, 78, },
221 {79, 79, 100, 79, },
222 {80, 80, 100, 80, },
223 {81, 81, 100, 81, },
224 {82, 82, 100, 82, },
225 {83, 83, 100, 83, },
226 {84, 84, 100, 84, },
227 {85, 85, 100, 85, },
228 {86, 86, 100, 86, },
229 {87, 87, 100, 87, },
230 {88, 88, 100, 88, },
231 {89, 89, 100, 89, },
232 {90, 90, 100, 90, },
233 {91, 91, 100, 91, },
234 {92, 92, 100, 92, },
235 {93, 93, 100, 93, },
236 {94, 94, 100, 94, },
237 {95, 95, 100, 95, },
238 {96, 96, 100, 96, },
239 {97, 97, 100, 97, },
240 {98, 98, 100, 98, },
241 {99, 99, 100, 99, },
242 {100, 10, 100, 50, },
243 {101, 10, 100, 50, },
244 {102, 10, 100, 50, },
245 {103, 10, 100, 50, },
246 {104, 10, 100, 50, },
247 {105, 10, 100, 50, },
248 {106, 10, 100, 50, },
249 {107, 10, 100, 50, },
250 {108, 10, 100, 50, },
251 {109, 10, 100, 50, },
252 {110, 10, 100, 50, },
253 {111, 10, 100, 50, },
254 {112, 10, 100, 50, },
255 {113, 10, 100, 50, },
256 {114, 10, 100, 50, },
257 {115, 10, 100, 50, },
258 {116, 10, 100, 50, },
259 {117, 10, 100, 50, },
260 {118, 10, 100, 50, },
261 {119, 10, 100, 50, },
262 {120, 10, 100, 50, },
263 {121, 10, 100, 50, },
264 {122, 10, 100, 50, },
265 {123, 10, 100, 50, },
266 {124, 10, 100, 50, },
267 };
268 }
269 // this method must be private or protected so the auto-gen tool keeps it
getSetMaximumValues()270 private int[][] getSetMaximumValues() {
271 return new int[][] {
272 {-15, 10, 100, 50, },
273 {-14, 10, 100, 50, },
274 {-13, 10, 100, 50, },
275 {-12, 10, 100, 50, },
276 {-11, 10, 100, 50, },
277 {-10, 10, 100, 50, },
278 {-9, 10, 100, 50, },
279 {-8, 10, 100, 50, },
280 {-7, 10, 100, 50, },
281 {-6, 10, 100, 50, },
282 {-5, 10, 100, 50, },
283 {-4, 10, 100, 50, },
284 {-3, 10, 100, 50, },
285 {-2, 10, 100, 50, },
286 {-1, 10, 100, 50, },
287 {0, 10, 100, 50, },
288 {1, 10, 100, 50, },
289 {2, 10, 100, 50, },
290 {3, 10, 100, 50, },
291 {4, 10, 100, 50, },
292 {5, 10, 100, 50, },
293 {6, 10, 100, 50, },
294 {7, 10, 100, 50, },
295 {8, 10, 100, 50, },
296 {9, 10, 100, 50, },
297 {10, 10, 100, 50, },
298 {11, 10, 11, 11, },
299 {12, 10, 12, 12, },
300 {13, 10, 13, 13, },
301 {14, 10, 14, 14, },
302 {15, 10, 15, 15, },
303 {16, 10, 16, 16, },
304 {17, 10, 17, 17, },
305 {18, 10, 18, 18, },
306 {19, 10, 19, 19, },
307 {20, 10, 20, 20, },
308 {21, 10, 21, 21, },
309 {22, 10, 22, 22, },
310 {23, 10, 23, 23, },
311 {24, 10, 24, 24, },
312 {25, 10, 25, 25, },
313 {26, 10, 26, 26, },
314 {27, 10, 27, 27, },
315 {28, 10, 28, 28, },
316 {29, 10, 29, 29, },
317 {30, 10, 30, 30, },
318 {31, 10, 31, 31, },
319 {32, 10, 32, 32, },
320 {33, 10, 33, 33, },
321 {34, 10, 34, 34, },
322 {35, 10, 35, 35, },
323 {36, 10, 36, 36, },
324 {37, 10, 37, 37, },
325 {38, 10, 38, 38, },
326 {39, 10, 39, 39, },
327 {40, 10, 40, 40, },
328 {41, 10, 41, 41, },
329 {42, 10, 42, 42, },
330 {43, 10, 43, 43, },
331 {44, 10, 44, 44, },
332 {45, 10, 45, 45, },
333 {46, 10, 46, 46, },
334 {47, 10, 47, 47, },
335 {48, 10, 48, 48, },
336 {49, 10, 49, 49, },
337 {50, 10, 50, 50, },
338 {51, 10, 51, 50, },
339 {52, 10, 52, 50, },
340 {53, 10, 53, 50, },
341 {54, 10, 54, 50, },
342 {55, 10, 55, 50, },
343 {56, 10, 56, 50, },
344 {57, 10, 57, 50, },
345 {58, 10, 58, 50, },
346 {59, 10, 59, 50, },
347 {60, 10, 60, 50, },
348 {61, 10, 61, 50, },
349 {62, 10, 62, 50, },
350 {63, 10, 63, 50, },
351 {64, 10, 64, 50, },
352 {65, 10, 65, 50, },
353 {66, 10, 66, 50, },
354 {67, 10, 67, 50, },
355 {68, 10, 68, 50, },
356 {69, 10, 69, 50, },
357 {70, 10, 70, 50, },
358 {71, 10, 71, 50, },
359 {72, 10, 72, 50, },
360 {73, 10, 73, 50, },
361 {74, 10, 74, 50, },
362 {75, 10, 75, 50, },
363 {76, 10, 76, 50, },
364 {77, 10, 77, 50, },
365 {78, 10, 78, 50, },
366 {79, 10, 79, 50, },
367 {80, 10, 80, 50, },
368 {81, 10, 81, 50, },
369 {82, 10, 82, 50, },
370 {83, 10, 83, 50, },
371 {84, 10, 84, 50, },
372 {85, 10, 85, 50, },
373 {86, 10, 86, 50, },
374 {87, 10, 87, 50, },
375 {88, 10, 88, 50, },
376 {89, 10, 89, 50, },
377 {90, 10, 90, 50, },
378 {91, 10, 91, 50, },
379 {92, 10, 92, 50, },
380 {93, 10, 93, 50, },
381 {94, 10, 94, 50, },
382 {95, 10, 95, 50, },
383 {96, 10, 96, 50, },
384 {97, 10, 97, 50, },
385 {98, 10, 98, 50, },
386 {99, 10, 99, 50, },
387 {100, 10, 100, 50, },
388 {101, 10, 101, 50, },
389 {102, 10, 102, 50, },
390 {103, 10, 103, 50, },
391 {104, 10, 104, 50, },
392 {105, 10, 105, 50, },
393 {106, 10, 106, 50, },
394 {107, 10, 107, 50, },
395 {108, 10, 108, 50, },
396 {109, 10, 109, 50, },
397 {110, 10, 110, 50, },
398 {111, 10, 111, 50, },
399 {112, 10, 112, 50, },
400 {113, 10, 113, 50, },
401 {114, 10, 114, 50, },
402 {115, 10, 115, 50, },
403 {116, 10, 116, 50, },
404 {117, 10, 117, 50, },
405 {118, 10, 118, 50, },
406 {119, 10, 119, 50, },
407 {120, 10, 120, 50, },
408 {121, 10, 121, 50, },
409 {122, 10, 122, 50, },
410 {123, 10, 123, 50, },
411 {124, 10, 124, 50, },
412 };
413 }
414 // this method must be private or protected so the auto-gen tool keeps it
setDefaults()415 private void setDefaults() {
416 	scale.setMaximum(100);
417 	scale.setMinimum(10);
418 	scale.setSelection(50);
419 }
420 // this method must be private or protected so the auto-gen tool keeps it
getSetSelectionValues()421 private int[][] getSetSelectionValues() {
422 return new int[][] {
423 {-15, 10, 100, 10, },
424 {-14, 10, 100, 10, },
425 {-13, 10, 100, 10, },
426 {-12, 10, 100, 10, },
427 {-11, 10, 100, 10, },
428 {-10, 10, 100, 10, },
429 {-9, 10, 100, 10, },
430 {-8, 10, 100, 10, },
431 {-7, 10, 100, 10, },
432 {-6, 10, 100, 10, },
433 {-5, 10, 100, 10, },
434 {-4, 10, 100, 10, },
435 {-3, 10, 100, 10, },
436 {-2, 10, 100, 10, },
437 {-1, 10, 100, 10, },
438 {0, 10, 100, 10, },
439 {1, 10, 100, 10, },
440 {2, 10, 100, 10, },
441 {3, 10, 100, 10, },
442 {4, 10, 100, 10, },
443 {5, 10, 100, 10, },
444 {6, 10, 100, 10, },
445 {7, 10, 100, 10, },
446 {8, 10, 100, 10, },
447 {9, 10, 100, 10, },
448 {10, 10, 100, 10, },
449 {11, 10, 100, 11, },
450 {12, 10, 100, 12, },
451 {13, 10, 100, 13, },
452 {14, 10, 100, 14, },
453 {15, 10, 100, 15, },
454 {16, 10, 100, 16, },
455 {17, 10, 100, 17, },
456 {18, 10, 100, 18, },
457 {19, 10, 100, 19, },
458 {20, 10, 100, 20, },
459 {21, 10, 100, 21, },
460 {22, 10, 100, 22, },
461 {23, 10, 100, 23, },
462 {24, 10, 100, 24, },
463 {25, 10, 100, 25, },
464 {26, 10, 100, 26, },
465 {27, 10, 100, 27, },
466 {28, 10, 100, 28, },
467 {29, 10, 100, 29, },
468 {30, 10, 100, 30, },
469 {31, 10, 100, 31, },
470 {32, 10, 100, 32, },
471 {33, 10, 100, 33, },
472 {34, 10, 100, 34, },
473 {35, 10, 100, 35, },
474 {36, 10, 100, 36, },
475 {37, 10, 100, 37, },
476 {38, 10, 100, 38, },
477 {39, 10, 100, 39, },
478 {40, 10, 100, 40, },
479 {41, 10, 100, 41, },
480 {42, 10, 100, 42, },
481 {43, 10, 100, 43, },
482 {44, 10, 100, 44, },
483 {45, 10, 100, 45, },
484 {46, 10, 100, 46, },
485 {47, 10, 100, 47, },
486 {48, 10, 100, 48, },
487 {49, 10, 100, 49, },
488 {50, 10, 100, 50, },
489 {51, 10, 100, 51, },
490 {52, 10, 100, 52, },
491 {53, 10, 100, 53, },
492 {54, 10, 100, 54, },
493 {55, 10, 100, 55, },
494 {56, 10, 100, 56, },
495 {57, 10, 100, 57, },
496 {58, 10, 100, 58, },
497 {59, 10, 100, 59, },
498 {60, 10, 100, 60, },
499 {61, 10, 100, 61, },
500 {62, 10, 100, 62, },
501 {63, 10, 100, 63, },
502 {64, 10, 100, 64, },
503 {65, 10, 100, 65, },
504 {66, 10, 100, 66, },
505 {67, 10, 100, 67, },
506 {68, 10, 100, 68, },
507 {69, 10, 100, 69, },
508 {70, 10, 100, 70, },
509 {71, 10, 100, 71, },
510 {72, 10, 100, 72, },
511 {73, 10, 100, 73, },
512 {74, 10, 100, 74, },
513 {75, 10, 100, 75, },
514 {76, 10, 100, 76, },
515 {77, 10, 100, 77, },
516 {78, 10, 100, 78, },
517 {79, 10, 100, 79, },
518 {80, 10, 100, 80, },
519 {81, 10, 100, 81, },
520 {82, 10, 100, 82, },
521 {83, 10, 100, 83, },
522 {84, 10, 100, 84, },
523 {85, 10, 100, 85, },
524 {86, 10, 100, 86, },
525 {87, 10, 100, 87, },
526 {88, 10, 100, 88, },
527 {89, 10, 100, 89, },
528 {90, 10, 100, 90, },
529 {91, 10, 100, 91, },
530 {92, 10, 100, 92, },
531 {93, 10, 100, 93, },
532 {94, 10, 100, 94, },
533 {95, 10, 100, 95, },
534 {96, 10, 100, 96, },
535 {97, 10, 100, 97, },
536 {98, 10, 100, 98, },
537 {99, 10, 100, 99, },
538 {100, 10, 100, 100, },
539 {101, 10, 100, 100, },
540 {102, 10, 100, 100, },
541 {103, 10, 100, 100, },
542 {104, 10, 100, 100, },
543 {105, 10, 100, 100, },
544 {106, 10, 100, 100, },
545 {107, 10, 100, 100, },
546 {108, 10, 100, 100, },
547 {109, 10, 100, 100, },
548 {110, 10, 100, 100, },
549 {111, 10, 100, 100, },
550 {112, 10, 100, 100, },
551 {113, 10, 100, 100, },
552 {114, 10, 100, 100, },
553 {115, 10, 100, 100, },
554 {116, 10, 100, 100, },
555 {117, 10, 100, 100, },
556 {118, 10, 100, 100, },
557 {119, 10, 100, 100, },
558 {120, 10, 100, 100, },
559 {121, 10, 100, 100, },
560 {122, 10, 100, 100, },
561 {123, 10, 100, 100, },
562 {124, 10, 100, 100, },
563 };
564 }
565 
566 @Test
test_consistency_KeySelection()567 public void test_consistency_KeySelection () {
568 	consistencyEvent(0, SWT.ARROW_RIGHT, 0, 0, ConsistencyUtility.KEY_PRESS);
569 }
570 
571 @Test
test_consistency_ThumbSelection()572 public void test_consistency_ThumbSelection () {
573 	consistencyEvent(9, 10, 1, 0, ConsistencyUtility.MOUSE_CLICK);
574 }
575 
576 @Test
test_consistency_TroughSelection()577 public void test_consistency_TroughSelection () {
578 	consistencyEvent(27, 10, 1, 0, ConsistencyUtility.MOUSE_CLICK);
579 }
580 
581 @Test
test_consistency_MenuDetect()582 public void test_consistency_MenuDetect () {
583 	consistencyEvent(27, 5, 3, 0, ConsistencyUtility.MOUSE_CLICK);
584 }
585 
586 @Test
test_consistency_DragDetect()587 public void test_consistency_DragDetect () {
588 	consistencyEvent(9, 5, 30, 10, ConsistencyUtility.MOUSE_DRAG);
589 }
590 
591 }
592