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