blob: 3d8e28b7afd47bbec529100677338155766ea89c [file] [log] [blame]
sherman4dd25ba2009-08-13 15:01:18 -07001#!/bin/sh
2
3#
4# Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
5# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6#
7# This code is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License version 2 only, as
9# published by the Free Software Foundation.
10#
11# This code is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14# version 2 for more details (a copy is included in the LICENSE file that
15# accompanied this code).
16#
17# You should have received a copy of the GNU General Public License version
18# 2 along with this work; if not, write to the Free Software Foundation,
19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22# CA 95054 USA or visit www.sun.com if you need additional information or
23# have any questions.
24#
25
26# @test
27# @bug 4991526 6514993
28# @summary Unit test for Preferences jar providers
29#
30# @build PrefsSpi
31# @run shell PrefsSpi.sh
32# @author Martin Buchholz
33
34# Command-line usage: sh PrefsSpi.sh /path/to/build
35
36if [ -z "$TESTJAVA" ]; then
37 if [ $# -lt 1 ]; then exit 1; fi
38 TESTJAVA="$1"; shift
39 TESTSRC="`pwd`"
40 TESTCLASSES="`pwd`"
41fi
42
43 java="$TESTJAVA/bin/java"
44javac="$TESTJAVA/bin/javac"
45 jar="$TESTJAVA/bin/jar"
46
47Die() { printf "%s\n" "$*"; exit 1; }
48
49Sys() {
50 printf "%s\n" "$*"; "$@"; rc="$?";
51 test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc";
52}
53
54cat > StubPreferences.java <<'EOF'
55import java.util.prefs.*;
56
57public class StubPreferences extends AbstractPreferences {
58 public StubPreferences() { super(null, ""); }
59 public String getSpi(String x) { return null; }
60 public void putSpi(String x, String y) { }
61 public void removeSpi(String x) { }
62 public AbstractPreferences childSpi(String x) { return null; }
63 public void removeNodeSpi() { }
64 public String[] keysSpi() { return null; }
65 public String[] childrenNamesSpi() { return null; }
66 public void syncSpi() { }
67 public void flushSpi() { }
68}
69EOF
70
71cat > StubPreferencesFactory.java <<'EOF'
72import java.util.prefs.*;
73
74public class StubPreferencesFactory implements PreferencesFactory {
75 public Preferences userRoot() { return new StubPreferences(); }
76 public Preferences systemRoot() { return new StubPreferences(); }
77}
78EOF
79
80Sys rm -rf jarDir extDir
81Sys mkdir -p jarDir/META-INF/services extDir
82echo "StubPreferencesFactory" \
83 > "jarDir/META-INF/services/java.util.prefs.PreferencesFactory"
84Sys "$javac" -d jarDir StubPreferencesFactory.java StubPreferences.java
85
86(cd jarDir && "$jar" "cf" "../extDir/PrefsSpi.jar" ".")
87
88case "`uname`" in Windows*|CYGWIN* ) CPS=';';; *) CPS=':';; esac
89
90Sys "$java" "-cp" "$TESTCLASSES${CPS}extDir/PrefsSpi.jar" \
91 -Djava.util.prefs.PreferencesFactory=StubPreferencesFactory \
92 PrefsSpi "StubPreferences"
93Sys "$java" "-cp" "$TESTCLASSES" \
94 PrefsSpi "java.util.prefs.*"
95Sys "$java" "-cp" "$TESTCLASSES${CPS}extDir/PrefsSpi.jar" \
96 PrefsSpi "StubPreferences"
97Sys "$java" "-cp" "$TESTCLASSES" "-Djava.ext.dirs=extDir" \
98 PrefsSpi "StubPreferences"
99
100rm -rf jarDir extDir