J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | # |
| 2 | # Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | # |
| 5 | # This code is free software; you can redistribute it and/or modify it |
| 6 | # under the terms of the GNU General Public License version 2 only, as |
| 7 | # published by the Free Software Foundation. |
| 8 | # |
| 9 | # This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | # version 2 for more details (a copy is included in the LICENSE file that |
| 13 | # accompanied this code). |
| 14 | # |
| 15 | # You should have received a copy of the GNU General Public License version |
| 16 | # 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | # |
| 19 | # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | # CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | # have any questions. |
| 22 | # |
| 23 | |
| 24 | # @test |
| 25 | # @bug 4952558 |
| 26 | # @summary Verify names that aren't legal Java names are accepted by forName. |
| 27 | # @author Joseph D. Darcy |
| 28 | # @compile -source 1.5 -target 1.5 NonJavaNames.java |
| 29 | # @run shell NonJavaNames.sh |
| 30 | |
| 31 | # This test uses hand-generated class files stored in the ./classes |
| 32 | # directory. After the renaming done below, those class files have |
| 33 | # single character names that are legal class names under class file |
| 34 | # version 49 but *not* legal Java language identifiers; e.g. "3" and |
| 35 | # "+". First, Z.java is compiled to Z.class using "-target 1.5." |
| 36 | # Next, to create a test class file, the appropriate name structures |
| 37 | # within the class files are updated, as is the "Hello world" string |
| 38 | # the class's main method prints out. If the definition of the |
| 39 | # semantics of "-target 1.5" changes, the test class files should be |
| 40 | # regenerated. |
| 41 | |
| 42 | # Verify directory context variables are set |
| 43 | if [ "${TESTJAVA}" = "" ] |
| 44 | then |
| 45 | echo "TESTJAVA not set. Test cannot execute. Failed." |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | if [ "${TESTSRC}" = "" ] |
| 50 | then |
| 51 | echo "TESTSRC not set. Test cannot execute. Failed." |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | if [ "${TESTCLASSES}" = "" ] |
| 56 | then |
| 57 | echo "TESTCLASSES not set. Test cannot execute. Failed." |
| 58 | exit 1 |
| 59 | fi |
| 60 | |
| 61 | # All preconditions are met; run the tests |
| 62 | |
| 63 | OS=`uname -s`; |
| 64 | # Set classpath separator |
| 65 | case "$OS" in |
| 66 | Windows* | CYGWIN* ) |
| 67 | SEP=";" |
| 68 | ;; |
| 69 | |
| 70 | * ) |
| 71 | SEP=":" |
| 72 | esac |
| 73 | |
| 74 | # Copy "hyphen.class" to "-.class" |
| 75 | |
| 76 | COPYHYPHEN="cp ${TESTSRC}/classes/hyphen.class ${TESTCLASSES}/-.class" |
| 77 | $COPYHYPHEN |
| 78 | |
| 79 | COPYCOMMA="cp ${TESTSRC}/classes/comma.class ${TESTCLASSES}/,.class" |
| 80 | $COPYCOMMA |
| 81 | |
| 82 | COPYPERIOD="cp ${TESTSRC}/classes/period.class ${TESTCLASSES}/..class" |
| 83 | $COPYPERIOD |
| 84 | |
| 85 | COPYLEFTSQUARE="cp ${TESTSRC}/classes/left-square.class ${TESTCLASSES}/[.class" |
| 86 | $COPYLEFTSQUARE |
| 87 | |
| 88 | COPYRIGHTSQUARE="cp ${TESTSRC}/classes/right-square.class ${TESTCLASSES}/].class" |
| 89 | $COPYRIGHTSQUARE |
| 90 | |
| 91 | COPYPLUS="cp ${TESTSRC}/classes/plus.class ${TESTCLASSES}/+.class" |
| 92 | $COPYPLUS |
| 93 | |
| 94 | COPYSEMICOLON="cp ${TESTSRC}/classes/semicolon.class ${TESTCLASSES}/;.class" |
| 95 | $COPYSEMICOLON |
| 96 | |
| 97 | JAVA="$TESTJAVA/bin/java -classpath ${TESTSRC}/classes${SEP}${TESTCLASSES}" |
| 98 | |
| 99 | $JAVA NonJavaNames |
| 100 | RESULT=$? |
| 101 | |
| 102 | case "$RESULT" in |
| 103 | 0 ) |
| 104 | exit 0; |
| 105 | ;; |
| 106 | |
| 107 | * ) |
| 108 | exit 1 |
| 109 | esac |
| 110 | |