blob: 0071f9e353e1ef28c7ec0b2ba31be9e3a9a15b40 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001#
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
43if [ "${TESTJAVA}" = "" ]
44then
45 echo "TESTJAVA not set. Test cannot execute. Failed."
46 exit 1
47fi
48
49if [ "${TESTSRC}" = "" ]
50then
51 echo "TESTSRC not set. Test cannot execute. Failed."
52 exit 1
53fi
54
55if [ "${TESTCLASSES}" = "" ]
56then
57 echo "TESTCLASSES not set. Test cannot execute. Failed."
58 exit 1
59fi
60
61# All preconditions are met; run the tests
62
63OS=`uname -s`;
64# Set classpath separator
65case "$OS" in
66 Windows* | CYGWIN* )
67 SEP=";"
68 ;;
69
70 * )
71 SEP=":"
72esac
73
74# Copy "hyphen.class" to "-.class"
75
76COPYHYPHEN="cp ${TESTSRC}/classes/hyphen.class ${TESTCLASSES}/-.class"
77$COPYHYPHEN
78
79COPYCOMMA="cp ${TESTSRC}/classes/comma.class ${TESTCLASSES}/,.class"
80$COPYCOMMA
81
82COPYPERIOD="cp ${TESTSRC}/classes/period.class ${TESTCLASSES}/..class"
83$COPYPERIOD
84
85COPYLEFTSQUARE="cp ${TESTSRC}/classes/left-square.class ${TESTCLASSES}/[.class"
86$COPYLEFTSQUARE
87
88COPYRIGHTSQUARE="cp ${TESTSRC}/classes/right-square.class ${TESTCLASSES}/].class"
89$COPYRIGHTSQUARE
90
91COPYPLUS="cp ${TESTSRC}/classes/plus.class ${TESTCLASSES}/+.class"
92$COPYPLUS
93
94COPYSEMICOLON="cp ${TESTSRC}/classes/semicolon.class ${TESTCLASSES}/;.class"
95$COPYSEMICOLON
96
97JAVA="$TESTJAVA/bin/java -classpath ${TESTSRC}/classes${SEP}${TESTCLASSES}"
98
99$JAVA NonJavaNames
100RESULT=$?
101
102case "$RESULT" in
103 0 )
104 exit 0;
105 ;;
106
107 * )
108 exit 1
109esac
110