8076151: [TESTBUG] Test java/awt/FontClass/CreateFont/fileaccess/FontFile.java fails
authorpchopra
Fri, 10 Apr 2015 11:35:49 +0300
changeset 30454 5611c3a5e7da
parent 30453 0a9513d4c1bb
child 30455 17adc050898b
8076151: [TESTBUG] Test java/awt/FontClass/CreateFont/fileaccess/FontFile.java fails Reviewed-by: alexsch, azvegint
jdk/test/java/awt/FontClass/CreateFont/fileaccess/FontFile.java
jdk/test/java/awt/FontClass/CreateFont/fileaccess/TestFontFile.sh
--- a/jdk/test/java/awt/FontClass/CreateFont/fileaccess/FontFile.java	Thu Apr 09 18:09:55 2015 +0400
+++ b/jdk/test/java/awt/FontClass/CreateFont/fileaccess/FontFile.java	Fri Apr 10 11:35:49 2015 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, 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
@@ -25,6 +25,16 @@
  * @test
  * @bug 6652929
  * @summary verify handling of File.getPath()
+ * @compile FontFile.java
+ * @run shell TestFontFile.sh
+ */
+
+/*
+ * When using jtreg this test needs to be run by shell script,
+ * since otherwise jtreg reflectively invokes the main method
+ * and the codebase for the purposes of the security manager
+ * is that of the jtreg harness, not the codebase (class file location)
+ * of this program, thus access to read to that location is not available.
  */
 
 import java.awt.*;
@@ -34,10 +44,21 @@
     public static void main(String[] args) throws Exception {
         String sep = System.getProperty("file.separator");
         String fname = ".." + sep + "A.ttf";
-        String dir = System.getProperty("test.src");
+        //String dir = System.getProperty("test.src");
+        String dir = System.getenv("TESTSRC");
         if (dir != null) {
             fname = dir + sep + fname;
         }
+        //String classesDir = System.getProperty("test.classes");
+        String classesDir = System.getenv("TESTCLASSES");
+        System.out.println("classesDir="+classesDir);
+        String testfile = "somefile";
+        if (classesDir != null) {
+            testfile = classesDir + sep + testfile;
+        }
+        final String somefile = testfile;
+        System.out.println("somefile="+somefile);
+        System.out.println("userdir="+System.getProperty("user.dir"));
         final String name = fname;
         System.out.println("Will try to access " + name);
         if (!(new File(name)).canRead()) {
@@ -66,7 +87,7 @@
                             return name;
                         } else {
                             read = true;
-                            return "somefile";
+                            return somefile;
                         }
                     }
                     @Override public boolean canRead() {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/FontClass/CreateFont/fileaccess/TestFontFile.sh	Fri Apr 10 11:35:49 2015 +0300
@@ -0,0 +1,84 @@
+#
+# Copyright (c) 2015, 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.
+#
+
+#!/bin/sh
+
+if [ "${TESTSRC}" = "" ]
+then TESTSRC=.
+fi
+
+if [ "${TESTJAVA}" = "" ]
+then
+  PARENT=`dirname \`which java\``
+  TESTJAVA=`dirname ${PARENT}`
+  echo "TESTJAVA not set, selecting " ${TESTJAVA}
+  echo "If this is incorrect, try setting the variable manually."
+fi
+
+if [ "${TESTCLASSES}" = "" ]
+then
+  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
+  exit 1
+fi
+
+BIT_FLAG=""
+
+# set platform-dependent variables
+OS=`uname -s`
+case "$OS" in
+  SunOS | Linux | Darwin )
+    NULL=/dev/null
+    PS=":"
+    FS="/"
+    ## for solaris, linux it's HOME
+    FILE_LOCATION=$HOME
+    if [ -f ${FILE_LOCATION}${FS}JDK64BIT -a ${OS} = "SunOS" ]
+    then
+        BIT_FLAG=`cat ${FILE_LOCATION}${FS}JDK64BIT`
+    fi
+    ;;
+  Windows_* | CYGWIN* )
+    NULL=NUL
+    PS=";"
+    FS="\\"
+    ;;
+  * )
+    echo "Unrecognized system!"
+    exit 1;
+    ;;
+esac
+
+JEMMYPATH=${CPAPPEND}
+CLASSPATH=.${PS}${TESTCLASSES}${PS}${JEMMYPATH} ; export CLASSPATH
+
+THIS_DIR=`pwd`
+
+${TESTJAVA}${FS}bin${FS}java ${BIT_FLAG} -version
+
+${TESTJAVA}${FS}bin${FS}java ${BIT_FLAG} FontFile > test.out 2>&1
+
+STATUS=$?
+
+cat test.out
+
+exit $STATUS