/*
test %I% %E%
@bug 6315717
@summary presses buttons in all permutations and verifies modifiers
@author Andrei Dmitriev : area=awt.mouse
@run main ModifierPermutation
*/
//package modifierpermutation;
/*
The test will try to press-release every button present on the mouse in different order.
Here are some abbreviations:
BUTTON1 press = P1
BUTTON2 press = P2 etc.
BUTTON1 release = R1
BUTTON2 release = R2 etc.
Only sequences alike below are possible : <P1, P2, R2, R1>.
Sequences like <P1, P2, R1, R2> will not be covered by this test due to its probable complexity.
*/
public class ModifierPermutation {
static boolean failed = false;
/*
* Because of some problems with BUTTONx_MASK
* (they are not ordered. Instead, their values are: 16 8 4)
* We have to use array [1..n] and make every permutation on its
* containment. After each permutation, make the same thing with
* array of buttons and array of expected modifiers.
*/
//all button masks
static int [] affectedButtonsToPressRelease;
// static int [] buttonsToRelease;
// static int [] modifiersToVerifyOnPressRelease;
static Frame f;
static {
for (int i = 0; i < BUTTONSNUMBER; i++){
mouseButtons[i] = InputEvent.getMaskForButton(i+1); //then change first three elements here to BUTTONx_MASK
}
//mouseButtons initially has following values : 16 8 4.
/* mouseButtons[0] = InputEvent.BUTTON1_MASK;
mouseButtons[1] = InputEvent.BUTTON2_MASK;
mouseButtons[2] = InputEvent.BUTTON3_MASK;
*/
}
init();
try {
} catch (Exception e){
e.printStackTrace();
throw new RuntimeException("Test failed.", e);
}
robot.mouseMove(f.getLocationOnScreen().x + f.getWidth()/2, f.getLocationOnScreen().y + f.getHeight()/2);
//Top limit is the factorial of the number of existing buttons
//now we will press 2 up to maximum buttons and release them in different order and listen for
// PRESSED events and check it's ExModifiers
//Now get the slice of affected buttons
// modifiersToVerifyOnPressRelease = Arrays.copyOf(mouseButtons, buttonsToPressNumber);
//Now press all these buttons in the order as they are in array affectedButtonsToPressRelease
//And release all these buttons in back order.
// nextPermutation(i, buttonsToRelease);
//TODO: press buttons and release them backward
//All I have to add is :
// pressAllButtons(affectedButtonsToPressRelease);
// releaseAllButtonsBackwardOrder(affectedButtonsToPressRelease);
}
// PermutationGenerator.nextPermutation(k, mouseButtonsDown);
// dumpArray("mouseButtonsDown (step="+k+")", mouseButtonsDown);
}
}
private static void init(){
adapterTest1 = new CheckingAdapter();
f = new Frame("Robot presses mouse here");
f.setVisible(true);
}
public static int factorial(int t){
if (t <=1 ) {
return 1;
} else {
return t*factorial(t-1);
}
}
// use this variable to get current button on EDT in checkModifiers()
static volatile int currentButtonIndexUnderAction;
if (failed) {
throw new RuntimeException("PRESSED_EVENT is not filled with correct values. Review messaage above.");
}
// robot.delay(100);
}
}
// robot.delay(100);
}
}
System.out.println("checkModifiers. currentButtonIndexUnderAction ="+currentButtonIndexUnderAction);
for (int i = 0; i<= currentButtonIndexUnderAction; i++){
System.out.println("ERROR["+i+"]: PRESSED_EVENT is not filled with correct values. affectedButtonsToPressRelease[i]= "+affectedButtonsToPressRelease[i] +" Event = "+e);
ModifierPermutation.failed = true;
} else {
System.out.println("CORRECT["+i+"]: affectedButtonsToPressRelease[i]= "+affectedButtonsToPressRelease[i]+ " Event = "+e);
}
}
}
/*======================================================================*/
public static void dumpValues(int button, int modifiers, int modifiersStandard, int modifiersEx, int modifiersExStandard){
System.out.println("Button = "+button + "Modifiers = "+ modifiers + " standard = "+ modifiersStandard);
}
}
}
int i;
int leftEl = 0;
int rightEl = 0;
while (i>=0) {
leftEl = i;
// System.out.println("leftEl = "+leftEl);
break;
}
i--;
}
while (i>=0) {
rightEl = i;
// System.out.println("rightEl = "+rightEl);
break;
}
i--;
}
// System.out.println("sort");
}
}
}
System.out.println("CheckModifiersOnRelease. currentButtonIndexUnderAction ="+currentButtonIndexUnderAction);
System.out.println("ERROR["+i+"]: RELEASED_EVENT is not filled with correct values. affectedButtonsToPressRelease[i]= "+affectedButtonsToPressRelease[i] +" Event = "+e);
ModifierPermutation.failed = true;
} else {
System.out.println("CORRECT["+i+"]: affectedButtonsToPressRelease[i]= "+affectedButtonsToPressRelease[i]+ " Event = "+e);
}
}
}
System.out.println("CheckModifiersOnClick. currentButtonIndexUnderAction ="+currentButtonIndexUnderAction);
//Actually the same as in checkModifiersOnRelease()
System.out.println("ERROR["+i+"]: CLICK_EVENT is not filled with correct values. affectedButtonsToPressRelease[i]= "+affectedButtonsToPressRelease[i] +" Event = "+e);
ModifierPermutation.failed = true;
} else {
System.out.println("CORRECT["+i+"]: affectedButtonsToPressRelease[i]= "+affectedButtonsToPressRelease[i]+ " Event = "+e);
}
}
}
}
///~ ModifierPermutation clas
/* A class that invoke appropriate verification
* routine with current modifier.
*/
public CheckingAdapter(){}
}
}
}
}
// A class that could make a standard permutation with no regard to the
// values of array passed in.
// It uses a buttonIndicesToPermutate array with [1..N] values to perform
// these permutations.
//Note that nextPermutation is a static method and you can't keep track
// of more the single permutation sequence.
/*
class PermutationGenerator{
final static int BUTTONSNUMBER = MouseInfo.getNumberOfButtons();
static int [] buttonIndicesToPermutate = new int [BUTTONSNUMBER];;
public PermutationGenerator(){
for (int i = 0; i < BUTTONSNUMBER; i++){
buttonIndicesToPermutate[i] = i+1; //fill it with [1..N] values
}
}
public static void nextPermutation(int step, int []array){
if (array.length != buttonIndicesToPermutate.length) {
throw new IllegalArgumentException("Array should have length equals to mouse buttons number.");
}
int i;
int leftEl = 0;
int rightEl = 0;
i = array.length - 2;
while (i>=0) {
if (buttonIndicesToPermutate[i] < buttonIndicesToPermutate[i+1]){
leftEl = i;
// System.out.println("leftEl = "+leftEl);
break;
}
i--;
}
i = array.length - 1;
while (i>=0) {
if (buttonIndicesToPermutate[i] >buttonIndicesToPermutate[leftEl]) {
rightEl = i;
// System.out.println("rightEl = "+rightEl);
break;
}
i--;
}
swapElements(array, leftEl, rightEl);
swapElements(buttonIndicesToPermutate, leftEl, rightEl);
if (leftEl + 2 < array.length){
// System.out.println("sort");
//need to make our own sorting because arraysort makes this on actual values in array...
Arrays.sort(array, leftEl + 1 , array.length);
Arrays.sort(buttonIndicesToPermutate, leftEl + 1 , buttonIndicesToPermutate.length);
// sortArray(array, leftEl + 1 , array.length);
}
}
public static void swapElements(int [] array, int leftEl, int rightEl){
int tmp = array[leftEl];
array[leftEl] = array[rightEl];
array[rightEl] = tmp;
}
}
*/