jdk/test/java/util/ServiceLoader/basic.sh
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 12047 320a714614e9
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
# published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
# This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
# version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
# accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
# 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
#
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4662
diff changeset
    19
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4662
diff changeset
    20
# or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4662
diff changeset
    21
# questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
# @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
# @bug 4640520 6354623
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
# @summary Unit test for java.util.ServiceLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
# @build Basic Load FooService FooProvider1 FooProvider2 FooProvider3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
# @run shell basic.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
# Command-line usage: sh basic.sh /path/to/build
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
if [ -z "$TESTJAVA" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  if [ $# -lt 1 ]; then exit 1; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  TESTJAVA="$1"; shift
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  TESTSRC="`pwd`"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  TESTCLASSES="`pwd`"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
JAVA="$TESTJAVA/bin/java"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
JAR="$TESTJAVA/bin/jar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
OS=`uname -s`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
case "$OS" in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    SunOS )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
      SEP=':' ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    Linux )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
      SEP=':' ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    * )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
      SEP='\;' ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
esac
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
4662
49b8cbe45e6a 6911108: These tests do not work with CYGWIN: java/util
ohair
parents: 2
diff changeset
    53
JARD=x.jar
49b8cbe45e6a 6911108: These tests do not work with CYGWIN: java/util
ohair
parents: 2
diff changeset
    54
EXTD=x.ext
49b8cbe45e6a 6911108: These tests do not work with CYGWIN: java/util
ohair
parents: 2
diff changeset
    55
TESTD=x.test
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
if [ \! -d $EXTD ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    # Initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    echo Initializing...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    rm -rf $JARD $EXTD $TESTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    mkdir -p $JARD $EXTD $TESTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    for n in 2 3; do
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
      rm -rf $JARD/*; mkdir -p $JARD/META-INF/services
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      echo FooProvider$n \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
	>$JARD/META-INF/services/FooService
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
      cp $TESTCLASSES/FooProvider$n.class $JARD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      if [ $n = 3 ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        cp $TESTCLASSES/FooService.class $JARD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
      (cd $JARD; "$JAR" -cf ../p$n.jar *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    done
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    mv p3.jar $EXTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    cp $TESTCLASSES/Load.class $TESTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    cp $TESTCLASSES/FooService.class $TESTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    cp $TESTCLASSES/FooProvider1.class $TESTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    mkdir -p $TESTD/META-INF/services
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    echo FooProvider1 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      >$TESTD/META-INF/services/FooService
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    # This gives us:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    #   $TESTD: FooProvider1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    #   .     : FooProvider2, in p2.jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    #   $EXTD:  FooProvider3, in p3.jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
failures=0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
go() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  echo ''
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  cp="$1"; shift
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  if [ -z "$cp" ]; then cp="$TESTCLASSES"; else cp="$TESTCLASSES$SEP$cp"; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  vmargs="$1"; shift
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  sh -xc "'$JAVA' -cp $cp $vmargs $T $*" 2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
# Java-level tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
T=Basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
go ".${SEP}$TESTD${SEP}p2.jar" "-Djava.ext.dirs=$EXTD"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
# Success cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
T=Load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
go "$TESTD" "" FooProvider1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
go ".${SEP}p2.jar" "" FooProvider2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
go "" "-Djava.ext.dirs=$EXTD" FooProvider3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
go "$TESTD${SEP}p2.jar" "" FooProvider1 FooProvider2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
go "$TESTD" "-Djava.ext.dirs=$EXTD" FooProvider3 FooProvider1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
go "$TESTD${SEP}p2.jar" "-Djava.ext.dirs=$EXTD" \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  FooProvider3 FooProvider1 FooProvider2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
# Should only find the installed provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
go "$TESTD${SEP}p2.jar" "-Djava.ext.dirs=$EXTD" -i FooProvider3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
# Failure cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
mkdir -p x.meta/META-INF/services
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
# Simple failures
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
for p in FooProvider42 'blah blah' 9234 'X!' java.lang.Object; do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  echo $p >x.meta/META-INF/services/FooService
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  go ".${SEP}x.meta" "" fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
# Failures followed by successes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
echo FooProvider42 >x.meta/META-INF/services/FooService
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
go "$TESTD${SEP}x.meta" "" FooProvider1 fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
go "x.meta${SEP}$TESTD" "" fail FooProvider1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
go "$TESTD${SEP}x.meta${SEP}${SEP}p2.jar" "-Djava.ext.dirs=$EXTD" \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
  FooProvider3 FooProvider1 fail FooProvider2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
# Summary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
echo ''
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
if [ $failures -gt 0 ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  then echo "$failures case(s) failed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  else echo "All cases passed"; fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
exit $failures