changeset 10412:db1d1894985c

8049694: Migrate functional AWT_DesktopProperties/Automated tests to OpenJDK Reviewed-by: azvegint, serb
author dermashov
date Mon, 21 Jul 2014 12:29:45 +0400
parents dfcf4b835abd
children 0e36fa13a95a
files test/java/awt/Toolkit/DesktopProperties/rfe4758438.java test/java/awt/Toolkit/DesktopProperties/rfe4758438.sh
diffstat 2 files changed, 321 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/Toolkit/DesktopProperties/rfe4758438.java	Mon Jul 21 12:29:45 2014 +0400
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2004, 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.
+ *
+ * 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.
+ */
+
+import java.awt.*;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.InputStream;
+
+/*
+ * @test
+ * @bug 4758438
+ * @summary Testcase to check the implementation of RFE 4758438
+ *          The RFE suggests that the GNOME desktop properties
+ *          should be made accessible through the
+ *          Toolkit.getDesktopProperty() API.
+ * @author Girish R (girish.ramachandran@sun.com)
+ * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
+ * @run shell rfe4758438.sh
+ */
+
+public class rfe4758438 implements PropertyChangeListener {
+
+    enum PROPS {
+        drag_threshold(
+                "org.gnome.settings-daemon.peripherals.mouse drag-threshold",
+                "/desktop/gnome/peripherals/mouse/drag_threshold",
+                "gnome.Net/DndDragThreshold",
+                "int",
+                new String[]{"5", "6"}),
+        double_click(
+                "org.gnome.settings-daemon.peripherals.mouse double-click",
+                "/desktop/gnome/peripherals/mouse/double_click",
+                "gnome.Net/DoubleClickTime",
+                "int",
+                new String[]{"200","300"}),
+        cursor_blink(
+                "org.gnome.desktop.interface cursor-blink",
+                "/desktop/gnome/interface/cursor_blink",
+                "gnome.Net/CursorBlink",
+                "bool",
+                new String[]{"true","false"}),
+        cursor_blink_time(
+                "org.gnome.desktop.interface cursor-blink-time",
+                "/desktop/gnome/interface/cursor_blink_time",
+                "gnome.Net/CursorBlinkTime",
+                "int",
+                new String[]{"1000","1500"}),
+        gtk_theme(
+                "org.gnome.desktop.interface gtk-theme",
+                "/desktop/gnome/interface/gtk_theme",
+                "gnome.Net/ThemeName",
+                "string",
+                new String[]{"Crux","Simple"});
+
+        public final String gsettings;
+        public final String gconftool;
+        public final String java;
+        public final String type;
+        public final String[] values;
+
+        PROPS(String gsettings, String gconftool, String java, String type, String[] values){
+            this.gsettings = gsettings;
+            this.gconftool = gconftool;
+            this.java = java;
+            this.type = type;
+            this.values = values;
+        }
+    }
+
+    static boolean useGsettings;
+    static String tool;
+    Toolkit toolkit = Toolkit.getDefaultToolkit();
+    String changedProperty;
+    Object changedValue;
+    Object lock = new Object();
+
+    /**
+     * Implementation of PropertyChangeListener method
+     */
+    public void propertyChange(PropertyChangeEvent event) {
+        changedProperty = event.getPropertyName();
+        changedValue = toolkit.getDesktopProperty(changedProperty);
+        System.out.println("Property "+changedProperty+" changed. Changed value: "+changedValue);
+        synchronized(lock) {
+            try {
+                lock.notifyAll();
+            } catch (Exception e) {
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        useGsettings = System.getProperty("useGsettings").equals("true");
+        tool = System.getProperty("tool");
+
+        String osName = System.getProperty("os.name");
+        if (!"Linux".equals(osName) && !"SunOS".equals(osName))
+            System.out.println("This test need not be run on this platform");
+        else
+            new rfe4758438().doTest();
+    }
+
+    void doTest() throws Exception {
+        for (PROPS p : PROPS.values())
+            toolkit.addPropertyChangeListener(p.java, this);
+
+        for (PROPS p : PROPS.values()) {
+            Thread.sleep(1000);
+            doTest(p);
+        }
+        System.out.println("Test passed");
+    }
+
+    /**
+     * Do the test for each property. Find the current value
+     * of the property, set the property to a value not equal
+     * to the current value, check if the propertyChange event
+     * is triggered. Reset the property to the actual value.
+     */
+    void doTest(PROPS property) throws Exception {
+        //Choose the test value which is not same as the current value
+        Object obj = toolkit.getDesktopProperty(property.java);
+        if (obj == null)
+            throw new RuntimeException("No such property available: " + property.java);
+
+        //For boolean type values, getDesktopProperty method returns Integer objects
+        if (property.type.equals("bool")) {
+            if (obj.equals(new Integer(1))) {
+                obj = new String("true");
+            } else {
+                obj = new String("false");
+            }
+        }
+        Object value = property.values[0];
+        if (obj.toString().equals(value)) {
+            value = property.values[1];
+        }
+
+        //Create the command to execute
+        StringBuffer sb = new StringBuffer(tool);
+        if (useGsettings) {
+            sb.append(" set ");
+            sb.append(property.gsettings);
+            sb.append(" ");
+        } else {
+            sb.append(" --set --type=");
+            sb.append(property.type);
+            sb.append(" ");
+            sb.append(property.gconftool);
+            sb.append(" ");
+        }
+        String tempCommand = sb.toString();
+        sb.append(value.toString());
+
+        //Initialize the variables and execute the command
+        changedProperty = "";
+        changedValue = null;
+        if (executeCommand(sb.toString()) != 0)
+            throw new RuntimeException("Could not execute the command");
+
+        synchronized(lock) {
+            try {
+                lock.wait(5000);
+            } catch (Exception e) {
+            }
+        }
+        if (property.type.equals("bool")) {
+            if (changedValue.equals(new Integer(1))) {
+                changedValue = new String("true");
+            } else {
+                changedValue = new String("false");
+            }
+        }
+
+        //Check if the event got triggered
+        if (!changedProperty.equals(property.java)) {
+            //Reset the property
+            executeCommand(tempCommand + obj.toString());
+            throw new RuntimeException("PropertyChangedEvent did not occur for " + property.java);
+        } else if (!changedValue.toString().equals(value.toString())) {
+            //Reset the property
+            executeCommand(tempCommand + obj.toString());
+            throw new RuntimeException("New value of the property is different from " +
+                                       "the value supplied");
+        }
+
+        //Reset the property
+        executeCommand(tempCommand + obj.toString());
+    }
+
+    /**
+     * Uses the gconftool-2 command to change the value of the property.
+     * Gets the output of the command and prints the output
+     */
+    int executeCommand(String command) throws Exception {
+        System.out.println("Executing " + command);
+        Process process = Runtime.getRuntime().exec(command);
+
+        InputStream is = process.getInputStream();
+        InputStream es = process.getErrorStream();
+        StringBuilder stdout = new StringBuilder();
+        StringBuilder stderr = new StringBuilder();
+
+        process.waitFor();
+
+        while (is.available() > 0)
+            stdout.append((char) is.read());
+
+        while (es.available() > 0)
+            stderr.append((char) es.read());
+
+        if (stdout.length() > 0)
+            System.out.println(stdout.toString());
+        if (stderr.length() > 0)
+            System.err.println(stderr.toString());
+        return process.exitValue();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/Toolkit/DesktopProperties/rfe4758438.sh	Mon Jul 21 12:29:45 2014 +0400
@@ -0,0 +1,83 @@
+# 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.
+#
+# 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.
+
+if [ -z "${TESTJAVA}" ]; then
+  echo "TESTJAVA undefined: can't continue."
+  exit 1
+fi
+
+OS=`uname`
+
+case "$OS" in
+    Linux* )
+        GNOMESID=`pgrep gnome-session`
+        DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$GNOMESID/environ | cut -d= -f2-`
+        export DBUS_SESSION_BUS_ADDRESS
+        DISPLAY=`grep -z DISPLAY /proc/$GNOMESID/environ | cut -d= -f2-`
+        export DISPLAY
+        ;;
+    Sun* )
+        GNOMESID=`pgrep gnome-session`
+        DBUS_SESSION_BUS_ADDRESS=`pargs -e $GNOMESID | grep DBUS_SESSION_BUS_ADDRESS | cut -d= -f2-`
+        export DBUS_SESSION_BUS_ADDRESS
+        DISPLAY=`pargs -e $GNOMESID | grep DISPLAY | cut -d= -f2-`
+        export DISPLAY
+        ;;
+    * )
+        echo "This Feature is not to be tested on $OS"
+        exit 0
+        ;;
+esac
+
+if [ ${GNOME_DESKTOP_SESSION_ID:-nonset} = "nonset" ];
+then
+    if [ ${GNOME_SESSION_NAME:-nonset} = "nonset" ];
+    then
+        echo "This test should run under Gnome"
+        exit 0
+    fi
+fi
+
+SCHEMAS=`gsettings list-schemas | wc -l`
+
+if [ $SCHEMAS -eq 0 ];
+then
+    TOOL=`which gconftool-2`
+    USE_GSETTINGS="false"
+else
+    TOOL=`which gsettings`
+    USE_GSETTINGS="true"
+fi
+
+cd ${TESTSRC}
+echo $PWD
+echo "${TESTJAVA}/bin/javac -d ${TESTCLASSES} rfe4758438.java"
+${TESTJAVA}/bin/javac -d ${TESTCLASSES} rfe4758438.java
+
+cd ${TESTCLASSES}
+${TESTJAVA}/bin/java -DuseGsettings=${USE_GSETTINGS} -Dtool=${TOOL} ${TESTVMOPTS} rfe4758438
+
+if [ $? -ne 0 ]
+then
+    echo "Test failed. See the error stream output"
+    exit 1
+fi
+exit 0