1 #
   2 # Copyright (c) 2015, 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 # @test
  24 # @bug 8055160
  25 # @summary Unit test for javax.accessibility.AccessibilitySPI
  26 #
  27 # @build Load FooProvider BarProvider UnusedProvider
  28 # @run shell basic.sh
  29 
  30 # Command-line usage: sh basic.sh /path/to/build
  31 
  32 if [ -z "$TESTJAVA" ]; then
  33   if [ $# -lt 1 ]; then exit 1; fi
  34   TESTJAVA="$1"
  35   TESTSRC=`pwd`
  36   TESTCLASSES="`pwd`"
  37 fi
  38 
  39 JAVA="$TESTJAVA/bin/java"
  40 
  41 OS=`uname -s`
  42 case "$OS" in
  43     SunOS | Darwin | AIX )
  44       FS='/'
  45       SEP=':' ;;
  46     Linux )
  47       FS='/'
  48       SEP=':' ;;
  49     * )
  50       FS='\\'
  51       SEP='\;' ;;
  52 esac
  53 
  54 TESTD=x.test
  55 rm -rf $TESTD
  56 mkdir -p $TESTD
  57 
  58 mv $TESTCLASSES/FooProvider.class $TESTD
  59 mv $TESTCLASSES/BarProvider.class $TESTD
  60 mv $TESTCLASSES/UnusedProvider.class $TESTD
  61 mkdir -p $TESTD/META-INF/services
  62 echo FooProvider >$TESTD/META-INF/services/javax.accessibility.AccessibilityProvider
  63 echo BarProvider >>$TESTD/META-INF/services/javax.accessibility.AccessibilityProvider
  64 echo UnusedProvider >>$TESTD/META-INF/services/javax.accessibility.AccessibilityProvider
  65 
  66 
  67 failures=0
  68 
  69 go() {
  70   CP="$TESTCLASSES$SEP$TESTD"
  71   echo ''
  72   sh -xc "$JAVA $SECURITY_MANAGER -Djavax.accessibility.assistive_technologies=$PROVIDER1$COMMA$PROVIDER2 -cp $CP Load $1 $2 $3" 2>&1
  73   if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
  74 }
  75 
  76 # find one provider
  77 PROVIDER1="FooProvider"
  78 go pass $PROVIDER1
  79 
  80 # start using security manager
  81 SECURITY_MANAGER="-Djava.security.manager -Djava.security.policy=$TESTSRC/accessibilityProvider.sp"
  82 
  83 # find one provider (with security manager)
  84 go pass $PROVIDER1
  85 SECURITY_MANAGER=
  86 
  87 # fail if no provider found
  88 PROVIDER1="NoProvider"
  89 go fail $PROVIDER1
  90 
  91 # setup for two providers
  92 COMMA=","
  93 
  94 # find two providers, both exist
  95 PROVIDER1="FooProvider"
  96 PROVIDER2="BarProvider"
  97 go pass $PROVIDER1 $PROVIDER2
  98 
  99 # find two providers, where second one doesn't exist
 100 PROVIDER1="FooProvider"
 101 PROVIDER2="NoProvider"
 102 go fail $PROVIDER1 $PROVIDER2
 103 
 104 # find two providers, where first one doesn't exist
 105 PROVIDER1="NoProvider"
 106 PROVIDER2="BarProvider"
 107 go fail $PROVIDER1 $PROVIDER2
 108 
 109 echo ''
 110 if [ $failures -gt 0 ];
 111   then echo "$failures case(s) failed";
 112   else echo "All cases passed"; fi
 113 exit $failures
 114