1#
2# Copyright (c) 2003, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20# or visit www.oracle.com if you need additional information or have any
21# 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 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 in the class
34# file but *not* legal Java language identifiers; e.g. "3" and "+".
35# First, Z.java is compiled to Z.class.  Next, to create a test class
36# file, the appropriate name structures within the class files are
37# updated, as is the "Hello world" string the class's main method
38# prints out.
39
40# Verify directory context variables are set
41if [ "${TESTJAVA}" = "" ]
42then
43  echo "TESTJAVA not set.  Test cannot execute.  Failed."
44  exit 1
45fi
46
47if [ "${TESTSRC}" = "" ]
48then
49  echo "TESTSRC not set.  Test cannot execute.  Failed."
50  exit 1
51fi
52
53if [ "${TESTCLASSES}" = "" ]
54then
55  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
56  exit 1
57fi
58
59# All preconditions are met; run the tests
60
61OS=`uname -s`;
62# Set classpath separator
63case "$OS" in
64        Windows* | CYGWIN* )
65	SEP=";"
66        ;;
67
68	* )
69	SEP=":"
70esac
71
72# Copy "hyphen.class" to "-.class"
73
74COPYHYPHEN="cp ${TESTSRC}/classes/hyphen.class ${TESTCLASSES}/-.class"
75$COPYHYPHEN
76
77COPYCOMMA="cp ${TESTSRC}/classes/comma.class ${TESTCLASSES}/,.class"
78$COPYCOMMA
79
80COPYPERIOD="cp ${TESTSRC}/classes/period.class ${TESTCLASSES}/..class"
81$COPYPERIOD
82
83COPYLEFTSQUARE="cp ${TESTSRC}/classes/left-square.class ${TESTCLASSES}/[.class"
84$COPYLEFTSQUARE
85
86COPYRIGHTSQUARE="cp ${TESTSRC}/classes/right-square.class ${TESTCLASSES}/].class"
87$COPYRIGHTSQUARE
88
89COPYPLUS="cp ${TESTSRC}/classes/plus.class ${TESTCLASSES}/+.class"
90$COPYPLUS
91
92COPYSEMICOLON="cp ${TESTSRC}/classes/semicolon.class ${TESTCLASSES}/;.class"
93$COPYSEMICOLON
94
95JAVA="$TESTJAVA/bin/java ${TESTVMOPTS} -classpath ${TESTSRC}/classes${SEP}${TESTCLASSES}"
96
97$JAVA NonJavaNames
98RESULT=$?
99
100case "$RESULT" in
101        0 )
102        exit 0;
103        ;;
104
105        * )
106        exit 1
107esac
108
109