Skip to content

Commit

Permalink
8193547: Regression automated test '/open/test/jdk/java/awt/Toolkit/D…
Browse files Browse the repository at this point in the history
…esktopProperties/rfe4758438.java' fails

Reviewed-by: serb
  • Loading branch information
Alexander Zvegintsev committed Dec 14, 2022
1 parent 0dce5b8 commit c05dbac
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 53 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Expand Up @@ -426,7 +426,6 @@ java/awt/SplashScreen/MultiResolutionSplash/unix/UnixMultiResolutionSplashTest.j
java/awt/Robot/AcceptExtraMouseButtons/AcceptExtraMouseButtons.java 7107528 linux-all,macosx-all
java/awt/Mouse/MouseDragEvent/MouseDraggedTest.java 8080676 linux-all
java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersInKeyEvent.java 8157147 linux-all,windows-all,macosx-all
java/awt/Toolkit/DesktopProperties/rfe4758438.java 8193547 linux-all
java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java 6847163
java/awt/xembed/server/RunTestXEmbed.java 7034201 linux-all
java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsDocModalTest.java 8164473 linux-all
Expand Down
114 changes: 77 additions & 37 deletions test/jdk/java/awt/Toolkit/DesktopProperties/rfe4758438.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2022, 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
Expand Down Expand Up @@ -30,6 +30,7 @@
* @test
* @key headful
* @bug 4758438
* @requires os.family == "linux"
* @summary Testcase to check the implementation of RFE 4758438
* The RFE suggests that the GNOME desktop properties
* should be made accessible through the
Expand All @@ -43,44 +44,58 @@ public class rfe4758438 implements PropertyChangeListener {

enum PROPS {
drag_threshold(
"org.gnome.desktop.peripherals.mouse 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.desktop.peripherals.mouse 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",
null,
"/desktop/gnome/interface/cursor_blink",
"gnome.Net/CursorBlink",
"bool",
new String[]{"true","false"}),
cursor_blink_time(
"org.gnome.desktop.interface cursor-blink-time",
null,
"/desktop/gnome/interface/cursor_blink_time",
"gnome.Net/CursorBlinkTime",
"int",
new String[]{"1000","1500"}),
gtk_theme(
"org.gnome.desktop.interface gtk-theme",
null,
"/desktop/gnome/interface/gtk_theme",
"gnome.Net/ThemeName",
"string",
new String[]{"Crux","Simple"});

public final String gsettings;
public final String gsettingsFallback;
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){
PROPS(
String gsettings,
String gsettingsFallback,
String gconftool,
String java,
String type,
String[] values
){
this.gsettings = gsettings;
this.gsettingsFallback = gsettingsFallback;
this.gconftool = gconftool;
this.java = java;
this.type = type;
Expand All @@ -90,10 +105,10 @@ enum PROPS {

static boolean useGsettings;
static String tool;
Toolkit toolkit = Toolkit.getDefaultToolkit();
final Toolkit toolkit = Toolkit.getDefaultToolkit();
String changedProperty;
Object changedValue;
Object lock = new Object();
final Object lock = new Object();

/**
* Implementation of PropertyChangeListener method
Expand All @@ -105,7 +120,7 @@ public void propertyChange(PropertyChangeEvent event) {
synchronized(lock) {
try {
lock.notifyAll();
} catch (Exception e) {
} catch (Exception ignored) {
}
}
}
Expand All @@ -132,6 +147,34 @@ void doTest() throws Exception {
System.out.println("Test passed");
}

String prepareCommand(PROPS property, boolean useMain) {
//Create the command to execute
StringBuffer sb = new StringBuffer(tool);
if (useGsettings) {
sb.append(" set ");
sb.append( useMain
? property.gsettings
: property.gsettingsFallback
);
sb.append(" ");
} else {
sb.append(" --set --type=");
sb.append(property.type);
sb.append(" ");
sb.append(property.gconftool);
sb.append(" ");
}
return sb.toString();
}

int doTestCommand(String cmd) throws Exception {
//Initialize the variables and execute the command
changedProperty = "";
changedValue = null;

return executeCommand(cmd);
}

/**
* Do the test for each property. Find the current value
* of the property, set the property to a value not equal
Expand All @@ -146,67 +189,64 @@ void doTest(PROPS property) throws Exception {

//For boolean type values, getDesktopProperty method returns Integer objects
if (property.type.equals("bool")) {
if (obj.equals(new Integer(1))) {
obj = new String("true");
if (obj.equals(1)) {
obj = "true";
} else {
obj = new String("false");
obj = "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());
String tempCommand = prepareCommand(property, true);

//Initialize the variables and execute the command
changedProperty = "";
changedValue = null;
if (executeCommand(sb.toString()) != 0)
throw new RuntimeException("Could not execute the command");
int retVal = doTestCommand(tempCommand + value);

if (retVal != 0) {
if (useGsettings && property.gsettingsFallback != null) {
System.out.printf("Failed:\n\t%s\nTrying fallback:\n\t", tempCommand);
tempCommand = prepareCommand(property, false);
System.out.println(tempCommand);

retVal = doTestCommand(tempCommand + value);
}

if (retVal != 0) {
throw new RuntimeException("Could not execute the command");
}
}

synchronized(lock) {
try {
lock.wait(5000);
} catch (Exception e) {
} catch (Exception ignored) {
}
}

if (property.type.equals("bool")) {
if (changedValue.equals(new Integer(1))) {
changedValue = new String("true");
if (changedValue.equals(1)) {
changedValue = "true";
} else {
changedValue = new String("false");
changedValue = "false";
}
}

//Check if the event got triggered
if (!changedProperty.equals(property.java)) {
//Reset the property
executeCommand(tempCommand + obj.toString());
executeCommand(tempCommand + obj);
throw new RuntimeException("PropertyChangedEvent did not occur for " + property.java);
} else if (!changedValue.toString().equals(value.toString())) {
//Reset the property
executeCommand(tempCommand + obj.toString());
executeCommand(tempCommand + obj);
throw new RuntimeException("New value of the property is different from " +
"the value supplied");
}

//Reset the property
executeCommand(tempCommand + obj.toString());
executeCommand(tempCommand + obj);
}

/**
Expand All @@ -231,9 +271,9 @@ int executeCommand(String command) throws Exception {
stderr.append((char) es.read());

if (stdout.length() > 0)
System.out.println(stdout.toString());
System.out.println(stdout);
if (stderr.length() > 0)
System.err.println(stderr.toString());
System.err.println(stderr);
return process.exitValue();
}
}
41 changes: 26 additions & 15 deletions test/jdk/java/awt/Toolkit/DesktopProperties/rfe4758438.sh
@@ -1,4 +1,4 @@
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2014, 2022, 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
Expand Down Expand Up @@ -28,32 +28,39 @@ OS=`uname`

case "$OS" in
Linux* )
GNOMESID=`pgrep gnome-session`
GNOMESID=`pgrep gnome-session | head -n1`

printf "\n/* gnome-session environ\n"
cat "/proc/$GNOMESID/environ" | tr '\0' '\n'
printf "\n*/\n\n"

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

XDG_CURRENT_DESKTOP=`grep -z XDG_CURRENT_DESKTOP /proc/$GNOMESID/environ | cut -d= -f2-`
export XDG_CURRENT_DESKTOP
;;
* )
echo "This Feature is not to be tested on $OS"
exit 0
;;
esac

if [ ${GNOME_DESKTOP_SESSION_ID:-nonset} = "nonset" ];
printf "\n/* Test env:\n\n"
env
printf "\n*/\n\n"

XDG_GNOME=$(echo $XDG_CURRENT_DESKTOP | grep -i gnome)

if [ -z "$XDG_GNOME" ] \
&& [ ${GNOME_DESKTOP_SESSION_ID:-nonset} = "nonset" ] \
&& [ ${GNOME_SESSION_NAME:-nonset} = "nonset" ]
then
if [ ${GNOME_SESSION_NAME:-nonset} = "nonset" ];
then
echo "This test should run under Gnome"
exit 0
fi
echo "This test should run under Gnome"
exit 0
fi

SCHEMAS=`gsettings list-schemas | wc -l`
Expand All @@ -70,7 +77,11 @@ fi
cd ${TESTSRC}
echo $PWD
echo "${TESTJAVA}/bin/javac -d ${TESTCLASSES} rfe4758438.java"

set -e
${TESTJAVA}/bin/javac -d ${TESTCLASSES} rfe4758438.java
set +e


cd ${TESTCLASSES}
${TESTJAVA}/bin/java -DuseGsettings=${USE_GSETTINGS} -Dtool=${TOOL} ${TESTVMOPTS} rfe4758438
Expand Down

1 comment on commit c05dbac

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.