1 /* 2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 @test %I% %E% 26 @bug 6315717 27 @summary verifies that modifiers are correct for standard (1, 2, 3, wheel) mouse buttons 28 @author Andrei Dmitriev : area=awt.mouse 29 @run main MouseModifiersUnitTest_Standard 30 */ 31 32 import java.awt.*; 33 import java.awt.event.*; 34 import java.util.HashMap; 35 import java.util.StringTokenizer; 36 import java.util.Vector; 37 38 //the test verifies: 39 // 1) verifies that modifiers are correct for standard (1, 2, 3) mouse buttons 40 // TODO: 2) verifies that modifiers are correct for wheel 41 // TODO: 3) 42 // Case1. the test posts BUTTONx_MASK and verifies that paramString() contains correct modifiers and exModifiers 43 // Case2. the test posts BUTTONx_DOWN_MASK and verifies that paramString() contains correct modifiers and exModifiers 44 // Case3. the test posts getMaskForButton(n) and verifies that paramString() contains correct modifiers and exModifiers 45 // repeat all cases with SHIFT/ALT/CTRL modifiers verify that paramString() contains correct modifiers and exModifiers 46 // I'm verifying button, modifiers and extModifiers for now. 47 48 public class MouseModifiersUnitTest_Standard { 49 static final int NONE = 0; 50 static final int SHIFT = 1; 51 static final int CTRL = 2; 52 static final int ALT = 3; 53 static boolean debug = true; //dump all errors (debug) or throw first(under jtreg) exception 54 static boolean autorun = false; //use robot or manual run 55 static int testModifier = NONE; 56 // static String testModifier = "NONE"; 57 static CheckingModifierAdapter adapterTest1; 58 static CheckingModifierAdapter adapterTest2; 59 static CheckingModifierAdapter adapterTest3; 60 static CheckingModifierAdapter adapterTest4; 61 static Frame f; 62 final static int [] mouseButtons = new int [] {MouseEvent.BUTTON1_MASK, MouseEvent.BUTTON2_MASK, MouseEvent.BUTTON3_MASK}; 63 // BUTTON1, 2, 3 press-release. 64 final static int [] modifiersStandardTestNONE = new int[] {MouseEvent.BUTTON1_MASK, MouseEvent.BUTTON1_MASK, MouseEvent.BUTTON1_MASK, 65 MouseEvent.BUTTON2_MASK, MouseEvent.BUTTON2_MASK, MouseEvent.BUTTON2_MASK, 66 MouseEvent.BUTTON3_MASK, MouseEvent.BUTTON3_MASK, MouseEvent.BUTTON3_MASK }; 67 final static int [] modifiersExStandardTestNONE = new int[] {MouseEvent.BUTTON1_DOWN_MASK, 0, 0, 68 MouseEvent.BUTTON2_DOWN_MASK, 0, 0, 69 MouseEvent.BUTTON3_DOWN_MASK, 0, 0}; 70 // BUTTON1, 2, 3 press-release with shift modifier 71 final static int [] modifiersStandardTestSHIFT = new int[] {MouseEvent.BUTTON1_MASK|InputEvent.SHIFT_MASK, MouseEvent.BUTTON1_MASK|InputEvent.SHIFT_MASK, MouseEvent.BUTTON1_MASK|InputEvent.SHIFT_MASK, 72 MouseEvent.BUTTON2_MASK|InputEvent.SHIFT_MASK, MouseEvent.BUTTON2_MASK|InputEvent.SHIFT_MASK, MouseEvent.BUTTON2_MASK|InputEvent.SHIFT_MASK, 73 MouseEvent.BUTTON3_MASK|InputEvent.SHIFT_MASK, MouseEvent.BUTTON3_MASK|InputEvent.SHIFT_MASK, MouseEvent.BUTTON3_MASK|InputEvent.SHIFT_MASK }; 74 final static int [] modifiersExStandardTestSHIFT = new int[] {MouseEvent.BUTTON1_DOWN_MASK|InputEvent.SHIFT_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK, 75 MouseEvent.BUTTON2_DOWN_MASK|InputEvent.SHIFT_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK, 76 MouseEvent.BUTTON3_DOWN_MASK|InputEvent.SHIFT_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK, InputEvent.SHIFT_DOWN_MASK}; 77 // BUTTON1, 2, 3 press-release with CTRL modifier 78 final static int [] modifiersStandardTestCTRL = new int[] {MouseEvent.BUTTON1_MASK|InputEvent.CTRL_MASK, MouseEvent.BUTTON1_MASK|InputEvent.CTRL_MASK, MouseEvent.BUTTON1_MASK|InputEvent.CTRL_MASK, 79 MouseEvent.BUTTON2_MASK|InputEvent.CTRL_MASK, MouseEvent.BUTTON2_MASK|InputEvent.CTRL_MASK, MouseEvent.BUTTON2_MASK|InputEvent.CTRL_MASK, 80 MouseEvent.BUTTON3_MASK|InputEvent.CTRL_MASK, MouseEvent.BUTTON3_MASK|InputEvent.CTRL_MASK, MouseEvent.BUTTON3_MASK|InputEvent.CTRL_MASK }; 81 final static int [] modifiersExStandardTestCTRL = new int[] {MouseEvent.BUTTON1_DOWN_MASK|InputEvent.CTRL_DOWN_MASK, InputEvent.CTRL_DOWN_MASK, InputEvent.CTRL_DOWN_MASK, 82 MouseEvent.BUTTON2_DOWN_MASK|InputEvent.CTRL_DOWN_MASK, InputEvent.CTRL_DOWN_MASK, InputEvent.CTRL_DOWN_MASK, 83 MouseEvent.BUTTON3_DOWN_MASK|InputEvent.CTRL_DOWN_MASK, InputEvent.CTRL_DOWN_MASK, InputEvent.CTRL_DOWN_MASK}; 84 85 // BUTTON1, 2, 3 press-release with ALT modifier 86 final static int [] modifiersStandardTestALT = new int[] {MouseEvent.BUTTON1_MASK|InputEvent.ALT_MASK, MouseEvent.BUTTON1_MASK|InputEvent.ALT_MASK, MouseEvent.BUTTON1_MASK|InputEvent.ALT_MASK, 87 MouseEvent.BUTTON2_MASK|InputEvent.ALT_MASK, MouseEvent.BUTTON2_MASK|InputEvent.ALT_MASK, MouseEvent.BUTTON2_MASK|InputEvent.ALT_MASK, 88 MouseEvent.BUTTON3_MASK|InputEvent.ALT_MASK, MouseEvent.BUTTON3_MASK|InputEvent.ALT_MASK, MouseEvent.BUTTON3_MASK|InputEvent.ALT_MASK }; 89 final static int [] modifiersExStandardTestALT = new int[] {MouseEvent.BUTTON1_DOWN_MASK|InputEvent.ALT_DOWN_MASK, InputEvent.ALT_DOWN_MASK, InputEvent.ALT_DOWN_MASK, 90 MouseEvent.BUTTON2_DOWN_MASK|InputEvent.ALT_DOWN_MASK, InputEvent.ALT_DOWN_MASK, InputEvent.ALT_DOWN_MASK, 91 MouseEvent.BUTTON3_DOWN_MASK|InputEvent.ALT_DOWN_MASK, InputEvent.ALT_DOWN_MASK, InputEvent.ALT_DOWN_MASK}; 92 93 static Robot robot; 94 95 public static void main(String s[]){ 96 initParams(s); 97 initAdapters(); 98 f = new Frame(); 99 final int [] modifiers = {InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK}; 100 final String [] modifierNames = {"InputEvent.SHIFT_MASK", "InputEvent.CTRL_MASK"}; 101 f.setLayout(new FlowLayout()); 102 f.addMouseWheelListener(new MouseWheelListener() { 103 public void mouseWheelMoved(MouseWheelEvent e) { 104 System.out.println("WHEEL "+e); 105 } 106 }); 107 f.setSize(300, 300); 108 f.setVisible(true); 109 110 try { 111 robot = new Robot(); 112 robot.delay(500); 113 robot.mouseMove(f.getLocationOnScreen().x + f.getWidth()/2, f.getLocationOnScreen().y + f.getHeight()/2); 114 if (autorun) { 115 //testing buttons 1, 2, 3 only 116 testPlainButtons(); 117 robot.delay(500); 118 119 //testing buttons 1, 2, 3 with SHIFT, CTRL, ALT keyboard modifiers 120 testButtonsWithShift(); 121 robot.delay(500); 122 123 testButtonsWithControl(); 124 robot.delay(500); 125 126 testButtonsWithAlt(); 127 robot.delay(500); 128 } else { 129 switch (testModifier){ 130 case SHIFT: 131 f.addMouseListener(adapterTest2); 132 break; 133 case CTRL: 134 f.addMouseListener(adapterTest3); 135 break; 136 case ALT: 137 f.addMouseListener(adapterTest4); 138 break; 139 default: //NONE inclusive 140 f.addMouseListener(adapterTest1); 141 } 142 } 143 } catch (Exception e){ 144 throw new RuntimeException("Test failed."); 145 } 146 147 } 148 149 public static void initAdapters(){ 150 adapterTest1 = new CheckingModifierAdapter(NONE); 151 adapterTest2 = new CheckingModifierAdapter(SHIFT); 152 adapterTest3 = new CheckingModifierAdapter(CTRL); 153 adapterTest4 = new CheckingModifierAdapter(ALT); 154 } 155 156 /*======================================================================*/ 157 public static void checkPressedModifiersTest(int testModifier, MouseEvent event){ 158 int [] curStandardModifiers = getStandardArray(testModifier); 159 int [] curStandardExModifiers = getStandardExArray(testModifier); 160 int button = event.getButton(); 161 int modifiers = event.getModifiers(); 162 int modifiersEx = event.getModifiersEx(); 163 int index = (button - 1)*3; 164 // int index = (button - 4)*3; 165 dumpValues(button, modifiers, curStandardModifiers[index], modifiersEx, curStandardExModifiers[index]); 166 if (modifiers != curStandardModifiers[index]){ 167 if (debug){ 168 System.out.println("Test failed : Pressed. modifiers != modifiersStandard"); 169 } else { 170 throw new RuntimeException("Test failed : Pressed. modifiers != modifiersStandard"); 171 } 172 } 173 174 if (modifiersEx != curStandardExModifiers[index]){ 175 // System.out.println(">>>>>>>>>>>>>>> Pressed. modifiersEx "+modifiersEx +" : "+!= curStandardExModifiers"); 176 if (debug){ 177 System.out.println("Test failed : Pressed. modifiersEx != curStandardExModifiers"); 178 } else { 179 throw new RuntimeException("Test failed : Pressed. modifiersEx != curStandardExModifiers"); 180 } 181 } 182 HashMap <String, String> paramStringElements = tokenizeParamString(event.paramString()); 183 System.out.println(event.paramString()); 184 checkButton(paramStringElements, button); 185 checkModifiers(testModifier, paramStringElements, button); 186 checkExtModifiersOnPress(testModifier, paramStringElements, button); 187 } 188 189 public static void checkButton(HashMap<String, String> h, int button){ 190 if (h.get("button") == null) { 191 throw new RuntimeException("Test failed : Clicked. button is absent in paramString()"); 192 } 193 if (Integer.parseInt(h.get("button")) != button) { 194 throw new RuntimeException("Test failed : Clicked. button in paramString() doesn't equal to button being pressed."); 195 } 196 } 197 198 public static void checkExtModifiersOnPress(int testModifier, HashMap h, int button){ 199 String ethalon = ""; 200 if (h.get("extModifiers") == null) { 201 System.out.println("Test failed : Pressed. extModifiers == null"); 202 throw new RuntimeException("Test failed : Pressed. extModifiers == null"); 203 } 204 switch (testModifier){ 205 case SHIFT:{ 206 ethalon = "Shift+"; 207 break; 208 } 209 case ALT:{ 210 ethalon = "Alt+"; 211 break; 212 } 213 case CTRL:{ 214 ethalon = "Ctrl+"; 215 break; 216 } 217 default: { 218 ethalon = ""; 219 } 220 ethalon = ethalon + "Button" +button; 221 222 if (!h.get("extModifiers").equals(ethalon)) { 223 System.out.println("Test failed : Pressed. extModifiers = " +h.get("extModifiers")+" instead of : "+ethalon); 224 throw new RuntimeException("Test failed : Pressed. extModifiers = " +h.get("extModifiers")+" instead of : "+ethalon); 225 } 226 } 227 } 228 229 230 231 public static void checkModifiers(int testModifier, HashMap<String, String> h, int button){ 232 // none of modifiers should be null 233 if (h.get("modifiers") == null) { 234 System.out.println("Test failed : modifiers == null"); 235 throw new RuntimeException("Test failed : modifiers == null"); 236 } 237 Vector <String> modifierElements = tokenizeModifiers(h.get("modifiers")); 238 //check that ButtonX is there 239 String buttonEthalon = "Button" + button; 240 if (modifierElements.contains(buttonEthalon)){ 241 modifierElements.remove(buttonEthalon); 242 } else { 243 System.out.println("Test failed : modifiers doesn't contain Button "+h.get("modifiers")); 244 throw new RuntimeException("Test failed : modifiers doesn't contain Button "+h.get("modifiers")); 245 } 246 247 248 //Check all explicitly pressed modifires 249 // boolean altIncluded = false; //don't duplicate Alt when ALT is pressed and BUTTON2_MASK. 250 String excplicitModifier = ""; 251 boolean altIncluded = false; 252 switch (testModifier){ 253 case SHIFT:{ 254 excplicitModifier = "Shift"; 255 break; 256 } 257 case ALT:{ 258 excplicitModifier = "Alt"; 259 altIncluded = true; //there should be only on "Alt" for two modifiers. So check it. 260 break; 261 } 262 case CTRL:{ 263 excplicitModifier = "Ctrl"; 264 break; 265 } 266 } 267 if (!excplicitModifier.equals("")){ 268 if (modifierElements.contains(excplicitModifier)){ 269 modifierElements.remove(excplicitModifier); 270 } else { 271 System.out.println("Test failed : modifiers doesn't contain explicit modifier "+excplicitModifier + " in "+ h.get("modifiers")); 272 throw new RuntimeException("Test failed : modifiers doesn't contain explicit modifier "+excplicitModifier + " in "+ h.get("modifiers")); 273 } 274 } 275 276 //Button 2 and 3 reports about Alt+Button2 and Meta+Button3 respectively. 277 //Check these values too 278 String extraModifiers = ""; 279 String extraModifiersButton3 = ""; 280 switch (button){ 281 //BUTTON1 with ALT reports about Alt+Button1+Button2. 282 //We should fix this but I would not change this. 283 case 1: { 284 //Alt+Button1+Button2: 285 // 1) we already handled "Alt" in excplicitModifier 286 // 2) we already took "Button1" in buttonEthalon 287 // 3) so "Button2" is only remained. 288 // This should only happen when ALT+Button1 is pressed 289 if (altIncluded){ 290 extraModifiers = "Button2"; 291 } 292 break; 293 } 294 case 2: { 295 //Alt+Button2 report about "Alt+Button2". 296 extraModifiers = "Alt"; 297 break; 298 } 299 case 3: { 300 //ALT+BUTTON3 reports about "Alt+Meta+Button2+Button3" 301 // This should only happen when ALT+Button3 is pressed 302 extraModifiers = "Meta"; 303 if (altIncluded){ 304 extraModifiersButton3 = "Button2"; 305 } 306 break; 307 } 308 }//switch 309 310 if (!extraModifiers.equals("")){ 311 if (modifierElements.contains(extraModifiers)){ 312 modifierElements.remove(extraModifiers); 313 } else { 314 //we may already removed "Alt" when filtered explicit modifiers. 315 //Here is no failure in this case. 316 if (!altIncluded) { 317 System.out.println("Test failed : modifiers doesn't contain a modifier from BUTTON2 or BUTTON3 "+extraModifiers + " in "+ h.get("modifiers")); 318 throw new RuntimeException("Test failed : modifiers doesn't contain a modifier from BUTTON2 or BUTTON3 "+extraModifiers + " in "+ h.get("modifiers")); 319 } 320 } 321 } 322 323 if (!extraModifiersButton3.equals("")){ 324 if (modifierElements.contains(extraModifiersButton3)){ 325 modifierElements.remove(extraModifiersButton3); 326 } else { 327 System.out.println("Test failed : modifiers doesn't contain a modifier from BUTTON2 or BUTTON3 "+extraModifiersButton3 + " in "+ h.get("modifiers")); 328 throw new RuntimeException("Test failed : modifiers doesn't contain a modifier from BUTTON2 or BUTTON3 "+extraModifiersButton3 + " in "+ h.get("modifiers")); 329 } 330 } 331 332 //the length of vector should now be zero 333 if (!modifierElements.isEmpty()){ 334 System.out.println("Test failed : there is some more elements in modifiers that shouldn't be there: "+h.get("modifiers")); 335 throw new RuntimeException("Test failed : there is some more elements in modifiers that shouldn't be there: "+h.get("modifiers")); 336 } 337 } 338 339 public static void checkExtModifiersOnReleaseClick(int testModifier, HashMap h, int button){ 340 String ethalon = ""; 341 switch (testModifier){ 342 case SHIFT:{ 343 ethalon = "Shift+"; 344 break; 345 } 346 case ALT:{ 347 ethalon = "Alt+"; 348 break; 349 } 350 case CTRL:{ 351 ethalon = "Ctrl+"; 352 break; 353 } 354 default: { 355 if (h.get("extModifiers") != null) { 356 System.out.println("Test failed : Released. extModifiers != null but no modifiers keys are pressed"); 357 throw new RuntimeException("Test failed : Released. extModifiers != null but no modifiers keys are pressed"); 358 } else { 359 //no modifiers 360 return; 361 } 362 } 363 } 364 if (h.get("extModifiers").equals(ethalon)) { 365 System.out.println("Test failed : Released. extModifiers = "+ h.get("extModifiers") +" instead of : "+ethalon); 366 throw new RuntimeException("Test failed : Released. extModifiers = "+ h.get("extModifiers") +" instead of : "+ethalon); 367 } 368 } 369 370 public static void checkReleasedModifiersTest(int testModifier, MouseEvent event){ 371 int [] curStandardModifiers = getStandardArray(testModifier); 372 int [] curStandardExModifiers = getStandardExArray(testModifier); 373 // int index = (button - 4)*3 + 1; 374 int button = event.getButton(); 375 int modifiers = event.getModifiers(); 376 int modifiersEx = event.getModifiersEx(); 377 int index = (button - 1)*3 + 1; 378 dumpValues(button, modifiers, curStandardModifiers[index], modifiersEx, curStandardExModifiers[index]); 379 if (modifiers != curStandardModifiers[index]){ 380 if (debug){ 381 System.out.println("Test failed : Released. modifiers != modifiersStandard"); 382 } else { 383 throw new RuntimeException("Test failed : Released. modifiers != modifiersStandard"); 384 } 385 } 386 if (modifiersEx != curStandardExModifiers[index]){ 387 if (debug){ 388 System.out.println("Test failed : Released. modifiersEx != curStandardExModifiers"); 389 } else { 390 throw new RuntimeException("Test failed : Released. modifiersEx != curStandardExModifiers"); 391 } 392 } 393 HashMap <String, String> paramStringElements = tokenizeParamString(event.paramString()); 394 System.out.println(event.paramString()); 395 checkButton(paramStringElements, button); 396 checkModifiers(testModifier, paramStringElements, button); 397 checkExtModifiersOnReleaseClick(testModifier, paramStringElements, button); 398 } 399 400 public static void checkClickedModifiersTest(int testModifier, MouseEvent event){ 401 int [] curStandardModifiers = getStandardArray(testModifier); 402 int [] curStandardExModifiers = getStandardExArray(testModifier); 403 // int index = (button - 4)*3 + 2; 404 int button = event.getButton(); 405 int modifiers = event.getModifiers(); 406 int modifiersEx = event.getModifiersEx(); 407 int index = (button - 1)*3 + 2; 408 dumpValues(button, modifiers, curStandardModifiers[index], modifiersEx, curStandardExModifiers[index]); 409 if (modifiers != curStandardModifiers[index]){ 410 if (debug){ 411 System.out.println("Test failed : Clicked. modifiers != modifiersStandard"); 412 } else { 413 throw new RuntimeException("Test failed : Clicked. modifiers != modifiersStandard"); 414 } 415 } 416 if (modifiersEx != curStandardExModifiers[index]){ 417 if (debug){ 418 System.out.println("Test failed : Clicked. modifiersEx != curStandardExModifiers"); 419 } else { 420 throw new RuntimeException("Test failed : Clicked. modifiersEx != curStandardExModifiers"); 421 } 422 } 423 HashMap <String, String> paramStringElements = tokenizeParamString(event.paramString()); 424 checkButton(paramStringElements, button); 425 checkModifiers(testModifier, paramStringElements, button); 426 checkExtModifiersOnReleaseClick(testModifier, paramStringElements, button); 427 } 428 /*======================================================================*/ 429 430 public static HashMap<String, String> tokenizeParamString(String param){ 431 HashMap <String, String> params = new HashMap<String, String>(); 432 StringTokenizer st = new StringTokenizer(param, ",="); 433 while (st.hasMoreTokens()){ 434 String tmp = st.nextToken(); 435 // System.out.println("PARSER : "+tmp); 436 if (tmp.equals("button") || 437 tmp.equals("modifiers") || 438 tmp.equals("extModifiers")) { 439 params.put(tmp, st.nextToken()); 440 } 441 } 442 return params; 443 } 444 445 public static Vector<String> tokenizeModifiers(String modifierList){ 446 Vector<String> modifiers = new Vector<String>(); 447 StringTokenizer st = new StringTokenizer(modifierList, "+"); 448 while (st.hasMoreTokens()){ 449 String tmp = st.nextToken(); 450 modifiers.addElement(tmp); 451 System.out.println("MODIFIER PARSER : "+tmp); 452 } 453 return modifiers; 454 } 455 456 457 //test BUTTON1, 2 and 3 without any modifiers keys 458 public static void testPlainButtons(){ 459 System.out.println("Testing buttons without modifiers."); 460 f.addMouseListener(adapterTest1); 461 for (int button : mouseButtons){ 462 robot.mousePress(button); 463 robot.delay(100); 464 robot.mouseRelease(button); 465 } 466 robot.delay(1000); 467 f.removeMouseListener(adapterTest1); 468 } 469 470 //test BUTTON1, 2 and 3 with SHIFT key 471 public static void testButtonsWithShift(){ 472 System.out.println("Testing buttons with SHIFT modifier."); 473 f.addMouseListener(adapterTest2); 474 475 for (int button : mouseButtons){ 476 robot.keyPress(KeyEvent.VK_SHIFT); 477 robot.mousePress(button); 478 robot.delay(100); 479 robot.mouseRelease(button); 480 robot.keyRelease(KeyEvent.VK_SHIFT); 481 } 482 robot.delay(1000); 483 f.removeMouseListener(adapterTest2); 484 } 485 486 //test BUTTON1, 2 and 3 with CTRL key 487 public static void testButtonsWithControl(){ 488 System.out.println("Testing buttons with CONTROL modifier."); 489 f.addMouseListener(adapterTest3); 490 for (int button : mouseButtons){ 491 robot.keyPress(KeyEvent.VK_CONTROL); 492 robot.mousePress(button); 493 robot.delay(100); 494 robot.mouseRelease(button); 495 robot.keyRelease(KeyEvent.VK_CONTROL); 496 } 497 robot.delay(1000); 498 f.removeMouseListener(adapterTest3); 499 } 500 501 //test BUTTON1, 2 and 3 with ALT key 502 public static void testButtonsWithAlt(){ 503 System.out.println("Testing buttons with ALT modifier."); 504 f.addMouseListener(adapterTest4); 505 for (int button : mouseButtons){ 506 robot.keyPress(KeyEvent.VK_ALT); 507 robot.mousePress(button); 508 robot.delay(100); 509 robot.mouseRelease(button); 510 robot.keyRelease(KeyEvent.VK_ALT); 511 } 512 robot.delay(1000); 513 f.removeMouseListener(adapterTest4); 514 } 515 516 public static void initParams(String []s){ 517 if (s.length != 3){ 518 autorun = true; 519 debug = false; 520 testModifier = NONE; 521 } else { 522 autorun = Boolean.valueOf(s[0]); 523 debug = Boolean.valueOf(s[1]); 524 525 if (s[2].equals("NONE")){ 526 testModifier = NONE; 527 } 528 if (s[2].equals("SHIFT")){ 529 testModifier = SHIFT; 530 } 531 if (s[2].equals("CTRL")){ 532 testModifier = CTRL; 533 } 534 if (s[2].equals("ALT")){ 535 testModifier = ALT; 536 } 537 } 538 System.out.println("Autorun : " +autorun); 539 System.out.println("Debug mode : " +debug); 540 System.out.println("Modifier to verify : " + testModifier); 541 } 542 543 public static void dumpValues(int button, int modifiers, int modifiersStandard, int modifiersEx, int modifiersExStandard){ 544 System.out.println("Button = "+button + "Modifiers = "+ modifiers + " standard = "+ modifiersStandard); 545 System.out.println(" ModifiersEx = "+ modifiersEx + " standardEx = "+ modifiersExStandard); 546 } 547 548 private static int[] getStandardExArray(int testModifier) { 549 int [] curStandardExModifiers; 550 switch (testModifier){ 551 case SHIFT: 552 curStandardExModifiers = modifiersExStandardTestSHIFT; 553 break; 554 case CTRL: 555 curStandardExModifiers = modifiersExStandardTestCTRL; 556 break; 557 case ALT: 558 curStandardExModifiers = modifiersExStandardTestALT; 559 break; 560 default: //NONE by default 561 curStandardExModifiers = modifiersExStandardTestNONE; 562 } 563 return curStandardExModifiers; 564 } 565 566 private static int[] getStandardArray(int testModifier) { 567 int [] curStandardModifiers; 568 switch (testModifier){ 569 case SHIFT: 570 curStandardModifiers = modifiersStandardTestSHIFT; 571 break; 572 case CTRL: 573 curStandardModifiers = modifiersStandardTestCTRL; 574 break; 575 case ALT: 576 curStandardModifiers = modifiersStandardTestALT; 577 break; 578 default: //NONE by default 579 curStandardModifiers = modifiersStandardTestNONE; 580 } 581 return curStandardModifiers; 582 } 583 584 } 585 586 587 /* A class that invoke appropriate verification 588 * routine with current modifier. 589 */ 590 class CheckingModifierAdapter extends MouseAdapter{ 591 int modifier; 592 public CheckingModifierAdapter(int modifier){ 593 this.modifier = modifier; 594 } 595 596 public void mousePressed(MouseEvent e) { 597 System.out.println("PRESSED "+e); 598 if (e.getButton() > MouseEvent.BUTTON3) { 599 System.out.println("Extra button affected. Skip."); 600 } else { 601 MouseModifiersUnitTest_Standard.checkPressedModifiersTest(modifier, e); // e.getButton(), e.getModifiers(), e.getModifiersEx(), 602 } 603 } 604 public void mouseReleased(MouseEvent e) { 605 System.out.println("RELEASED "+e); 606 if (e.getButton() > MouseEvent.BUTTON3) { 607 System.out.println("Extra button affected. Skip."); 608 } else { 609 MouseModifiersUnitTest_Standard.checkReleasedModifiersTest(modifier, e); // e.getButton(), e.getModifiers(), e.getModifiersEx() 610 } 611 } 612 public void mouseClicked(MouseEvent e) { 613 System.out.println("CLICKED "+e); 614 if (e.getButton() > MouseEvent.BUTTON3) { 615 System.out.println("Extra button affected. Skip."); 616 } else { 617 MouseModifiersUnitTest_Standard.checkClickedModifiersTest(modifier, e); //e.getButton(), e.getModifiers(), e.getModifiersEx() 618 } 619 } 620 } 621