1#
2# Copyright (c) 2003, 2016, 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# Utilities for shell tests
25
26: ${TESTSRC=.} ${TESTCLASSES=.}
27  java="${TESTJAVA+${TESTJAVA}/bin/}java"
28 javac="${TESTJAVA+${TESTJAVA}/bin/}javac"
29   jar="${TESTJAVA+${TESTJAVA}/bin/}jar"
30jimage="${TESTJAVA+${TESTJAVA}/bin/}jimage"
31
32case `uname -s` in
33  Windows*|CYGWIN*)
34    WindowsOnly() { "$@"; }
35    UnixOnly() { :; }
36    PS=";" ;;
37  *)
38    UnixOnly() { "$@"; }
39    WindowsOnly() { :; }
40    PS=":";;
41esac
42
43failed=""
44Fail() { echo "FAIL: $1"; failed="${failed}."; }
45
46Die() { printf "%s\n" "$*"; exit 1; }
47
48Sys() {
49    printf "%s\n" "$*"; "$@"; rc="$?";
50    test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc";
51}
52
53CheckFiles() {
54    for f in "$@"; do test -r "$f" || Die "File $f not found"; done
55}
56
57Report() {
58    test "$#" != 2 && Die "Usage: Report success|failure rc"
59
60    if   test "$1" = "success" -a "$2" = 0; then
61        echo "PASS: succeeded as expected"
62    elif test "$1" = "failure" -a "$2" != 0; then
63        echo "PASS: failed as expected"
64    elif test "$1" = "success" -a "$2" != 0; then
65        Fail "test failed unexpectedly"
66    elif test "$1" = "failure" -a "$2" = 0; then
67        Fail "test succeeded unexpectedly"
68    else
69        Die "Usage: Report success|failure rc"
70    fi
71}
72
73MkManifestWithClassPath() {
74    (echo "Manifest-Version: 1.0"; echo "Class-Path: $*") > MANIFEST.MF
75}
76
77HorizontalRule() {
78    echo "-----------------------------------------------------------------"
79}
80
81Test() {
82    HorizontalRule
83    expectedResult="$1"; shift
84    printf "%s\n" "$*"
85    "$@"
86    Report "$expectedResult" "$?"
87}
88
89Failure() { Test failure "$@"; }
90Success() { Test success "$@"; }
91
92Bottom() {
93    test "$#" = 1 -a "$1" = "Line" || Die "Usage: Bottom Line"
94
95    if test -n "$failed"; then
96        count=`printf "%s" "$failed" | wc -c | tr -d ' '`
97        echo "FAIL: $count tests failed"
98        exit 1
99    else
100        echo "PASS: all tests gave expected results"
101        exit 0
102    fi
103}
104
105BadJarFile() {
106    for jarfilename in "$@"; do pwd > "$jarfilename"; done
107}
108
109
110#----------------------------------------------------------------
111# Foil message localization
112#----------------------------------------------------------------
113DiagnosticsInEnglishPlease() {
114    LANG="C" LC_ALL="C" LC_MESSAGES="C"; export LANG LC_ALL LC_MESSAGES
115}
116