changeset 7226:619b6657bf41

RT-37474 [Monocle] Shift-backspace generates an undefined key code Reviewed-by: kselle
author Daniel Blaukopf <daniel.blaukopf@oracle.com>
date Tue, 10 Jun 2014 08:45:29 +0300
parents 7cbfb3021f40
children 8e8843aaaff2
files modules/graphics/src/main/java/com/sun/glass/ui/monocle/util/IntSet.java tests/system/src/test/java/com/sun/glass/ui/monocle/IntSetTest.java tests/system/src/test/java/com/sun/glass/ui/monocle/input/USKeyboardTest.java
diffstat 3 files changed, 227 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/util/IntSet.java	Tue Jun 10 16:07:31 2014 +1200
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/util/IntSet.java	Tue Jun 10 08:45:29 2014 +0300
@@ -42,7 +42,6 @@
                 elements = Arrays.copyOf(elements, size * 2);
             }
             if (insertionPoint != size) {
-            } else {
                 System.arraycopy(elements, insertionPoint,
                                  elements, insertionPoint + 1,
                                  size - insertionPoint);
@@ -124,7 +123,7 @@
 
     /** Copies the contents of this set to the target set. */
     public void copyTo(IntSet target) {
-        if (target.elements.length > size) {
+        if (target.elements.length < size) {
             target.elements = Arrays.copyOf(elements, elements.length);
         } else {
             System.arraycopy(elements, 0, target.elements, 0, size);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/system/src/test/java/com/sun/glass/ui/monocle/IntSetTest.java	Tue Jun 10 08:45:29 2014 +0300
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.glass.ui.monocle;
+
+import com.sun.glass.ui.monocle.util.IntSet;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@RunWith(Parameterized.class)
+public class IntSetTest {
+
+    private Integer[] array;
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        Integer[][] sets = {
+                { 1 },
+                { 1, 2 },
+                { 1, 2, 3},
+                { 1, 1 },
+                { 1, 1, 1 },
+                { 1, 1, 2 },
+        };
+        return Arrays.asList(sets).stream()
+                .map(d -> new Object[] { d })
+                .collect(Collectors.toList());
+    }
+
+    public IntSetTest(Integer[] array) {
+        this.array = array;
+    }
+
+    private int[] getIntSetAsArray(IntSet s) {
+        int[] a = new int[s.size()];
+        for (int i = 0; i < s.size(); i++) {
+            a[i] = s.get(i);
+        }
+        Arrays.sort(a);
+        return a;
+    }
+
+    private int[] getHashSetAsArray(Set<Integer> set) {
+        return set.stream().sorted().mapToInt(x -> x).toArray();
+    }
+
+    private void assertSet(Set<Integer> expected, IntSet actual) {
+        Assert.assertArrayEquals(
+                "Expected: " + expected + ", found " + actual,
+                getHashSetAsArray(expected),
+                getIntSetAsArray(actual));
+    }
+
+    @Test
+    public void testAddInOrderRemoveInOrder() {
+        IntSet set = new IntSet();
+        Set<Integer> hashSet = new HashSet<>();
+        assertSet(hashSet, set);
+        for (int i = 0; i < array.length; i++) {
+            set.addInt(array[i]);
+            hashSet.add(array[i]);
+            assertSet(hashSet, set);
+        }
+        for (int i = 0; i < array.length; i++) {
+            set.removeInt(array[i]);
+            hashSet.remove(array[i]);
+            assertSet(hashSet, set);
+        }
+    }
+
+    @Test
+    public void testAddInOrderRemoveInReverse() {
+        IntSet set = new IntSet();
+        Set<Integer> hashSet = new HashSet<>();
+        assertSet(hashSet, set);
+        for (int i = 0; i < array.length; i++) {
+            set.addInt(array[i]);
+            hashSet.add(array[i]);
+            assertSet(hashSet, set);
+        }
+        for (int i = array.length - 1; i >= 0; i--) {
+            set.removeInt(array[i]);
+            hashSet.remove(array[i]);
+            assertSet(hashSet, set);
+        }
+    }
+
+    @Test
+    public void testAddInReverseRemoveInOrder() {
+        IntSet set = new IntSet();
+        Set<Integer> hashSet = new HashSet<>();
+        assertSet(hashSet, set);
+        for (int i = array.length - 1; i >= 0; i--) {
+            set.addInt(array[i]);
+            hashSet.add(array[i]);
+            assertSet(hashSet, set);
+        }
+        for (int i = 0; i < array.length; i++) {
+            set.removeInt(array[i]);
+            hashSet.remove(array[i]);
+            assertSet(hashSet, set);
+        }
+    }
+
+    @Test
+    public void testAddInReverseRemoveInReverse() {
+        IntSet set = new IntSet();
+        Set<Integer> hashSet = new HashSet<>();
+        assertSet(hashSet, set);
+        for (int i = array.length - 1; i >= 0; i--) {
+            set.addInt(array[i]);
+            hashSet.add(array[i]);
+            assertSet(hashSet, set);
+        }
+        for (int i = array.length - 1; i >= 0; i--) {
+            set.removeInt(array[i]);
+            hashSet.remove(array[i]);
+            assertSet(hashSet, set);
+        }
+    }
+
+}
--- a/tests/system/src/test/java/com/sun/glass/ui/monocle/input/USKeyboardTest.java	Tue Jun 10 16:07:31 2014 +1200
+++ b/tests/system/src/test/java/com/sun/glass/ui/monocle/input/USKeyboardTest.java	Tue Jun 10 08:45:29 2014 +0300
@@ -26,7 +26,7 @@
 package com.sun.glass.ui.monocle.input;
 
 import org.junit.After;
-import org.junit.Assume;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -200,4 +200,77 @@
         TestLog.waitForLog("Key released: DIGIT3");
     }
 
+    @Test
+    public void testBackspace() throws Exception {
+        TestApplication.showFullScreenScene();
+        TestApplication.addKeyListeners();
+        ui.processLine("OPEN");
+        ui.processLine("EVBIT EV_KEY");
+        ui.processLine("EVBIT EV_SYN");
+        ui.processLine("KEYBIT KEY_BACKSPACE");
+        ui.processLine("KEYBIT KEY_LEFTSHIFT");
+        ui.processLine("KEYBIT KEY_CAPSLOCK");
+        ui.processLine("PROPERTY ID_INPUT_KEYBOARD 1");
+        ui.processLine("CREATE");
+
+        ui.processLine("EV_KEY KEY_BACKSPACE 1");
+        ui.processLine("EV_SYN");
+        TestLog.waitForLog("Key pressed: BACK_SPACE");
+        ui.processLine("EV_KEY KEY_BACKSPACE 0");
+        ui.processLine("EV_SYN");
+        TestLog.waitForLog("Key released: BACK_SPACE");
+        Assert.assertEquals(0l, TestLog.countLogContaining("Key typed"));
+
+        TestLog.reset();
+        ui.processLine("EV_KEY KEY_LEFTSHIFT 1");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_BACKSPACE 1");
+        ui.processLine("EV_SYN");
+        TestLog.waitForLog("Key pressed: BACK_SPACE");
+        ui.processLine("EV_KEY KEY_BACKSPACE 0");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_LEFTSHIFT 0");
+        ui.processLine("EV_SYN");
+        TestLog.waitForLog("Key released: BACK_SPACE");
+        Assert.assertEquals(0l, TestLog.countLogContaining("Key typed"));
+
+        TestLog.reset();
+        ui.processLine("EV_KEY KEY_CAPSLOCK 1");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_CAPSLOCK 0");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_BACKSPACE 1");
+        ui.processLine("EV_SYN");
+        TestLog.waitForLog("Key pressed: BACK_SPACE");
+        ui.processLine("EV_KEY KEY_BACKSPACE 0");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_CAPSLOCK 1");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_CAPSLOCK 0");
+        ui.processLine("EV_SYN");
+        TestLog.waitForLog("Key released: BACK_SPACE");
+        Assert.assertEquals(0l, TestLog.countLogContaining("Key typed"));
+
+        TestLog.reset();
+        ui.processLine("EV_KEY KEY_CAPSLOCK 1");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_CAPSLOCK 0");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_LEFTSHIFT 1");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_BACKSPACE 1");
+        ui.processLine("EV_SYN");
+        TestLog.waitForLog("Key pressed: BACK_SPACE");
+        ui.processLine("EV_KEY KEY_BACKSPACE 0");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_LEFTSHIFT 0");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_CAPSLOCK 1");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY KEY_CAPSLOCK 0");
+        ui.processLine("EV_SYN");
+        TestLog.waitForLog("Key released: BACK_SPACE");
+        Assert.assertEquals(0l, TestLog.countLogContaining("Key typed"));
+    }
+
 }