Merge "Revert "Libcore: Make java.security.Provider compile-time initializable""
diff --git a/luni/src/test/java/libcore/java/lang/OldSystemTest.java b/luni/src/test/java/libcore/java/lang/OldSystemTest.java
index dc5741f..ad7151d 100644
--- a/luni/src/test/java/libcore/java/lang/OldSystemTest.java
+++ b/luni/src/test/java/libcore/java/lang/OldSystemTest.java
@@ -257,13 +257,9 @@
public void test_gc() {
Runtime rt = Runtime.getRuntime();
- Vector<StringBuffer> vec = new Vector<StringBuffer>();
- long beforeTest = rt.totalMemory() - rt.freeMemory();
- while (rt.totalMemory() - rt.freeMemory() < beforeTest * 2) {
- vec.add(new StringBuffer(1000));
- }
+ byte[] data = new byte[2 * 1024 * 1024];
long beforeGC = rt.totalMemory() - rt.freeMemory();
- vec = null;
+ data = null;
System.gc();
System.runFinalization();
long afterGC = rt.totalMemory() - rt.freeMemory();
diff --git a/ojluni/src/main/java/java/lang/String.java b/ojluni/src/main/java/java/lang/String.java
index 2d985ca..115890e 100644
--- a/ojluni/src/main/java/java/lang/String.java
+++ b/ojluni/src/main/java/java/lang/String.java
@@ -536,7 +536,7 @@
* object.
*/
public int length() {
- final boolean STRING_COMPRESSION_ENABLED = false;
+ final boolean STRING_COMPRESSION_ENABLED = true;
if (STRING_COMPRESSION_ENABLED) {
// For the compression purposes (save the characters as 8-bit if all characters
// are ASCII), the least significant bit of "count" is used as the compression flag.
diff --git a/ojluni/src/main/java/java/time/chrono/JapaneseChronology.java b/ojluni/src/main/java/java/time/chrono/JapaneseChronology.java
index 15f7d84..29e503e 100644
--- a/ojluni/src/main/java/java/time/chrono/JapaneseChronology.java
+++ b/ojluni/src/main/java/java/time/chrono/JapaneseChronology.java
@@ -132,7 +132,7 @@
private static final Locale LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese");
static Calendar createCalendar() {
- return Calendar.getJapanesImperialInstance(TimeZone.getDefault(), LOCALE);
+ return Calendar.getJapaneseImperialInstance(TimeZone.getDefault(), LOCALE);
}
/**
diff --git a/ojluni/src/main/java/java/util/Calendar.java b/ojluni/src/main/java/java/util/Calendar.java
index 6f8b9a9..8593403 100644
--- a/ojluni/src/main/java/java/util/Calendar.java
+++ b/ojluni/src/main/java/java/util/Calendar.java
@@ -1489,7 +1489,15 @@
setWeekDefinition(MONDAY, 4);
cal = gcal;
break;
- // Android-changed: removed support for "buddhist" and "japanese".
+// Android-changed BEGIN: removed support for "buddhist" and "japanese".
+// case "buddhist":
+// cal = new BuddhistCalendar(zone, locale);
+// cal.clear();
+// break;
+// case "japanese":
+// cal = new JapaneseImperialCalendar(zone, locale, true);
+// break;
+// Android-changed END: removed support for "buddhist" and "japanese".
default:
throw new IllegalArgumentException("unknown calendar type: " + type);
}
@@ -1586,6 +1594,7 @@
*/
protected Calendar(TimeZone zone, Locale aLocale)
{
+ // Android-added BEGIN: Allow aLocale == null
// http://b/16938922.
//
// TODO: This is for backwards compatibility only. Seems like a better idea to throw
@@ -1593,6 +1602,7 @@
if (aLocale == null) {
aLocale = Locale.getDefault();
}
+ // Android-added END: Allow aLocale == null
fields = new int[FIELD_COUNT];
isSet = new boolean[FIELD_COUNT];
stamp = new int[FIELD_COUNT];
@@ -1656,18 +1666,22 @@
return createCalendar(zone, aLocale);
}
+ // Android-added BEGIN: add getJapaneseImperialInstance()
/**
* Create a Japanese Imperial Calendar.
* @hide
*/
- public static Calendar getJapanesImperialInstance(TimeZone zone, Locale aLocale) {
+ public static Calendar getJapaneseImperialInstance(TimeZone zone, Locale aLocale) {
return new JapaneseImperialCalendar(zone, aLocale);
}
+ // Android-added END: add getJapaneseImperialInstance()
private static Calendar createCalendar(TimeZone zone,
Locale aLocale)
{
+ // Android-changed BEGIN: only support GregorianCalendar here
return new GregorianCalendar(zone, aLocale);
+ // Android-changed END: only support GregorianCalendar here
}
/**
@@ -1758,7 +1772,12 @@
public void setTimeInMillis(long millis) {
// If we don't need to recalculate the calendar field values,
// do nothing.
+// Android-changed BEGIN: Removed ZoneInfo support
if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet) {
+// if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
+// && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
+// Android-changed END: Removed ZoneInfo support
+
return;
}
time = millis;
@@ -2041,11 +2060,13 @@
* @since 1.6
*/
public String getDisplayName(int field, int style, Locale locale) {
- // Android-changed: Android has traditionally treated ALL_STYLES as SHORT, even though
+ // Android-changed BEGIN: Treat ALL_STYLES as SHORT
+ // Android has traditionally treated ALL_STYLES as SHORT, even though
// it's not documented to be a valid value for style.
if (style == ALL_STYLES) {
style = SHORT;
}
+ // Android-changed END: Treat ALL_STYLES as SHORT
if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
ERA_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
return null;
@@ -2139,6 +2160,7 @@
ERA_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
return null;
}
+ // Android-added: Add complete() here to fix leniency, see http://b/35382060
complete();
String calendarType = getCalendarType();
@@ -2186,10 +2208,12 @@
baseStyle < minStyle || baseStyle > maxStyle) {
throw new IllegalArgumentException();
}
- // Android-changed: 3 is not a valid base style (1, 2 and 4 are, though), throw if used.
+ // Android-added BEGIN: Check for invalid baseStyle == 3
+ // 3 is not a valid base style (unlike 1, 2 and 4). Throw if used.
if (baseStyle == 3) {
throw new IllegalArgumentException();
}
+ // Android-added END: Check for invalid baseStyle == 3
if (locale == null) {
throw new NullPointerException();
}
diff --git a/ojluni/src/main/java/java/util/Formatter.java b/ojluni/src/main/java/java/util/Formatter.java
index ca1b990..43d5043 100644
--- a/ojluni/src/main/java/java/util/Formatter.java
+++ b/ojluni/src/main/java/java/util/Formatter.java
@@ -2710,6 +2710,7 @@
if (s != null) {
try {
// Android-changed: FormatSpecifierParser passes in correct String.
+ // index = Integer.parseInt(s.substring(0, s.length() - 1));
index = Integer.parseInt(s);
} catch (NumberFormatException x) {
assert(false);
@@ -2757,6 +2758,8 @@
precision = -1;
if (s != null) {
try {
+ // Android-changed: FormatSpecifierParser passes in correct String.
+ // precision = Integer.parseInt(s.substring(1));
precision = Integer.parseInt(s);
if (precision < 0)
throw new IllegalFormatPrecisionException(precision);
@@ -2789,7 +2792,7 @@
return c;
}
- // Android-changed: FormatSpecifierParser passes in the values instead of a Matcher.
+ // Android-changed BEGIN: FormatSpecifierParser passes in the values instead of a Matcher.
FormatSpecifier(String indexStr, String flagsStr, String widthStr,
String precisionStr, String tTStr, String convStr) {
int idx = 1;
@@ -2806,7 +2809,7 @@
}
conversion(convStr);
-
+ // Android-changed END: FormatSpecifierParser passes in the values instead of a Matcher.
if (dt)
checkDateTime();
else if (Conversion.isGeneral(c))
@@ -2998,6 +3001,7 @@
s = s.substring(0, precision);
if (f.contains(Flags.UPPERCASE)) {
// Android-changed: Use provided locale instead of default, if it is non-null.
+ // s = s.toUpperCase();
s = s.toUpperCase(l != null ? l : Locale.getDefault());
}
a.append(justify(s));
@@ -3369,12 +3373,13 @@
newW = adjustWidth(width - exp.length - 1, f, neg);
localizedMagnitude(sb, mant, f, newW, l);
- // Android-changed: Use localized exponent separator for %e.
+ // Android-changed BEGIN: Use localized exponent separator for %e.
Locale separatorLocale = (l != null) ? l : Locale.getDefault();
LocaleData localeData = LocaleData.get(separatorLocale);
sb.append(f.contains(Flags.UPPERCASE) ?
localeData.exponentSeparator.toUpperCase(separatorLocale) :
localeData.exponentSeparator.toLowerCase(separatorLocale));
+ // Android-changed END: Use localized exponent separator for %e.
Flags flags = f.dup().remove(Flags.GROUP);
char sign = exp[0];
@@ -4455,14 +4460,14 @@
grpSep = dfs.getGroupingSeparator();
DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(l);
grpSize = df.getGroupingSize();
- // Android-changed: http://b/33245708 : Some locales have a group separator but
- // also patterns without groups. If we do not clear the group separator in these
- // cases a divide by zero is thrown when determining where to place the
- // separators.
+ // Android-changed BEGIN: http://b/33245708
+ // Some locales have a group separator but also patterns without groups.
+ // If we do not clear the group separator in these cases a divide by zero
+ // is thrown when determining where to place the separators.
if (!df.isGroupingUsed() || df.getGroupingSize() == 0) {
grpSep = '\0';
}
- // Android-changed: end http://b/33245708.
+ // Android-changed END: http://b/33245708.
}
}
diff --git a/ojluni/src/main/java/java/util/GregorianCalendar.java b/ojluni/src/main/java/java/util/GregorianCalendar.java
index 3d8a7c79..15c7652 100644
--- a/ojluni/src/main/java/java/util/GregorianCalendar.java
+++ b/ojluni/src/main/java/java/util/GregorianCalendar.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -739,10 +739,12 @@
gdate = (BaseCalendar.Date) gcal.newCalendarDate(getZone());
}
+ // Android-added BEGIN
GregorianCalendar(long milliseconds) {
this();
setTimeInMillis(milliseconds);
}
+ // Android-added END
/////////////////
// Public methods
@@ -1078,8 +1080,7 @@
}
fd += delta; // fd is the expected fixed date after the calculation
-
- // Android changed: move time zone related calculation to separate method.
+ // Android-changed BEGIN: time zone related calculation via helper methods
// Calculate the time in the UTC time zone.
long utcTime = (fd - EPOCH_OFFSET) * ONE_DAY + timeOfDay;
@@ -1092,6 +1093,7 @@
// Update the time and recompute the fields.
setTimeInMillis(millis);
+ // Android-changed END: time zone related calculation via helper methods
}
}
@@ -2344,9 +2346,12 @@
}
if (tzMask != (ZONE_OFFSET_MASK|DST_OFFSET_MASK)) {
if (tz instanceof ZoneInfo) {
- // Android changed: libcore ZoneInfo uses different method to get offsets.
+ // Android changed BEGIN: use libcore.util.ZoneInfo
+ // The method name to get offsets differs from sun.util.calendar.ZoneInfo
+ // zoneOffset = ((ZoneInfo)tz).getOffsets(time, zoneOffsets);
ZoneInfo zoneInfo = (ZoneInfo) tz;
zoneOffset = zoneInfo.getOffsetsByUtcTime(time, zoneOffsets);
+ // Android-changed END: use libcore.util.ZoneInfo
} else {
zoneOffset = tz.getOffset(time);
zoneOffsets[0] = tz.getRawOffset();
@@ -2796,11 +2801,11 @@
// We use the TimeZone object, unless the user has explicitly set the ZONE_OFFSET
// or DST_OFFSET fields; then we use those fields.
TimeZone zone = getZone();
- // Android changed: move time zone related calculation to separate method.
-
+ // Android-changed BEGIN: time zone related calculation via helper methods
int tzMask = fieldMask & (ZONE_OFFSET_MASK|DST_OFFSET_MASK);
millis = adjustForZoneAndDaylightSavingsTime(tzMask, millis, zone);
+ // Android-changed END: time zone related calculation via helper methods
// Set this calendar's time in milliseconds
time = millis;
@@ -2823,6 +2828,7 @@
setFieldsNormalized(mask);
}
+ // Android-added BEGIN: helper methods for time zone related calculation
/**
* Calculates the time in milliseconds that this calendar represents using the UTC time,
* timezone information (specifically Daylight Savings Time (DST) rules, if any) and knowledge
@@ -2992,6 +2998,7 @@
}
return dstOffset;
}
+ // Android-added END: helper methods for time zone related calculation
/**
* Computes the fixed date under either the Gregorian or the
diff --git a/ojluni/src/test/java/nio/file/TestUtil.java b/ojluni/src/test/java/nio/file/TestUtil.java
new file mode 100644
index 0000000..2d102fd
--- /dev/null
+++ b/ojluni/src/test/java/nio/file/TestUtil.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+// Android-changed: Adapted from jdk/test/java/nio/file/TestUtil.java
+// Android-changed: Added package & made methods public
+package test.java.nio.file;
+
+import java.nio.file.*;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Random;
+import java.io.IOException;
+
+public class TestUtil {
+ private TestUtil() {
+ }
+
+ static public Path createTemporaryDirectory(String where) throws IOException {
+ Path dir = FileSystems.getDefault().getPath(where);
+ return Files.createTempDirectory(dir, "name");
+ }
+
+ static public Path createTemporaryDirectory() throws IOException {
+ return Files.createTempDirectory("name");
+ }
+
+ static public void removeAll(Path dir) throws IOException {
+ Files.walkFileTree(dir, new FileVisitor<Path>() {
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
+ return FileVisitResult.CONTINUE;
+ }
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
+ try {
+ Files.delete(file);
+ } catch (IOException x) {
+ System.err.format("Unable to delete %s: %s\n", file, x);
+ }
+ return FileVisitResult.CONTINUE;
+ }
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
+ try {
+ Files.delete(dir);
+ } catch (IOException x) {
+ System.err.format("Unable to delete %s: %s\n", dir, x);
+ }
+ return FileVisitResult.CONTINUE;
+ }
+ @Override
+ public FileVisitResult visitFileFailed(Path file, IOException exc) {
+ System.err.format("Unable to visit %s: %s\n", file, exc);
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ }
+
+ static public void deleteUnchecked(Path file) {
+ try {
+ Files.delete(file);
+ } catch (IOException exc) {
+ System.err.format("Unable to delete %s: %s\n", file, exc);
+ }
+ }
+
+ /**
+ * Creates a directory tree in the given directory so that the total
+ * size of the path is more than 2k in size. This is used for long
+ * path tests on Windows.
+ */
+ static public Path createDirectoryWithLongPath(Path dir)
+ throws IOException
+ {
+ StringBuilder sb = new StringBuilder();
+ for (int i=0; i<240; i++) {
+ sb.append('A');
+ }
+ String name = sb.toString();
+ do {
+ dir = dir.resolve(name).resolve(".");
+ Files.createDirectory(dir);
+ } while (dir.toString().length() < 2048);
+ return dir;
+ }
+
+ /**
+ * Returns true if symbolic links are supported
+ */
+ static public boolean supportsLinks(Path dir) {
+ Path link = dir.resolve("testlink");
+ Path target = dir.resolve("testtarget");
+ try {
+ Files.createSymbolicLink(link, target);
+ Files.delete(link);
+ return true;
+ } catch (UnsupportedOperationException x) {
+ return false;
+ } catch (IOException x) {
+ return false;
+ }
+ }
+}
diff --git a/ojluni/src/test/java/nio/file/attribute/AclEntryEmptySetTest.java b/ojluni/src/test/java/nio/file/attribute/AclEntryEmptySetTest.java
new file mode 100644
index 0000000..7f0c17b
--- /dev/null
+++ b/ojluni/src/test/java/nio/file/attribute/AclEntryEmptySetTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 7076310
+ * @summary Test AclEntry.Builder setFlags and setPermissions with empty sets
+ */
+// Android-changed: Adapted from
+// jdk/test/java/nio/file/attribute/AclEntry/EmptySet.java
+// Android-changed: Added package & Test import
+package test.java.nio.file.attribute;
+import org.testng.annotations.Test;
+
+import java.nio.file.attribute.*;
+import java.util.*;
+
+/*
+ * Test for bug 7076310 "(file) AclEntry.Builder setFlags throws
+ * IllegalArgumentException if set argument is empty"
+ * The bug is only applies when the given Set is NOT an instance of EnumSet.
+ *
+ * The setPermissions method also has the same problem.
+ */
+// Android-changed: Renamed from "EmptySet"
+public class AclEntryEmptySetTest {
+
+ // Android-changed: Removed args & added @Test
+ @Test
+ public static void main() {
+ Set<AclEntryFlag> flags = new HashSet<>();
+ AclEntry.newBuilder().setFlags(flags);
+
+ Set<AclEntryPermission> perms = new HashSet<>();
+ AclEntry.newBuilder().setPermissions(perms);
+ }
+}
diff --git a/ojluni/src/test/java/nio/file/attribute/AclFileAttributeViewTest.java b/ojluni/src/test/java/nio/file/attribute/AclFileAttributeViewTest.java
new file mode 100644
index 0000000..262aa81
--- /dev/null
+++ b/ojluni/src/test/java/nio/file/attribute/AclFileAttributeViewTest.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 4313887 6838333 6891404
+ * @summary Unit test for java.nio.file.attribute.AclFileAttribueView
+ * @library ../..
+ */
+// Android-changed: Adapted from
+// jdk/test/java/nio/file/attribute/AclFileAttributeView/Basic.java
+// Android-changed: Added package & Test import
+package test.java.nio.file.attribute;
+import org.testng.annotations.Test;
+import test.java.nio.file.TestUtil;
+
+import java.nio.file.*;
+import java.nio.file.attribute.*;
+import java.io.IOException;
+import java.util.*;
+
+import static java.nio.file.attribute.AclEntryType.*;
+import static java.nio.file.attribute.AclEntryPermission.*;
+import static java.nio.file.attribute.AclEntryFlag.*;
+
+// Android-changed: Renamed from "Basic"
+public class AclFileAttributeViewTest {
+
+ static void printAcl(List<AclEntry> acl) {
+ for (AclEntry entry: acl) {
+ System.out.format(" %s%n", entry);
+ }
+ }
+
+ // sanity check read and writing ACL
+ static void testReadWrite(Path dir) throws IOException {
+ Path file = dir.resolve("foo");
+ if (Files.notExists(file))
+ Files.createFile(file);
+
+ AclFileAttributeView view =
+ Files.getFileAttributeView(file, AclFileAttributeView.class);
+
+ // print existing ACL
+ List<AclEntry> acl = view.getAcl();
+ System.out.println(" -- current ACL --");
+ printAcl(acl);
+
+ // insert entry to grant owner read access
+ UserPrincipal owner = view.getOwner();
+ AclEntry entry = AclEntry.newBuilder()
+ .setType(ALLOW)
+ .setPrincipal(owner)
+ .setPermissions(READ_DATA, READ_ATTRIBUTES)
+ .build();
+ System.out.println(" -- insert (entry 0) --");
+ System.out.format(" %s%n", entry);
+ acl.add(0, entry);
+ view.setAcl(acl);
+
+ // re-ACL and check entry
+ List<AclEntry> newacl = view.getAcl();
+ System.out.println(" -- current ACL --");
+ printAcl(acl);
+ if (!newacl.get(0).equals(entry)) {
+ throw new RuntimeException("Entry 0 is not expected");
+ }
+
+ // if PosixFileAttributeView then repeat test with OWNER@
+ if (Files.getFileStore(file).supportsFileAttributeView("posix")) {
+ owner = file.getFileSystem().getUserPrincipalLookupService()
+ .lookupPrincipalByName("OWNER@");
+ entry = AclEntry.newBuilder(entry).setPrincipal(owner).build();
+
+ System.out.println(" -- replace (entry 0) --");
+ System.out.format(" %s%n", entry);
+
+ acl.set(0, entry);
+ view.setAcl(acl);
+ newacl = view.getAcl();
+ System.out.println(" -- current ACL --");
+ printAcl(acl);
+ if (!newacl.get(0).equals(entry)) {
+ throw new RuntimeException("Entry 0 is not expected");
+ }
+ }
+ }
+
+ static FileAttribute<List<AclEntry>> asAclAttribute(final List<AclEntry> acl) {
+ return new FileAttribute<List<AclEntry>>() {
+ public String name() { return "acl:acl"; }
+ public List<AclEntry> value() { return acl; }
+ };
+ }
+
+ static void assertEquals(List<AclEntry> actual, List<AclEntry> expected) {
+ if (!actual.equals(expected)) {
+ System.err.format("Actual: %s\n", actual);
+ System.err.format("Expected: %s\n", expected);
+ throw new RuntimeException("ACL not expected");
+ }
+ }
+
+ // sanity check create a file or directory with initial ACL
+ static void testCreateFile(Path dir) throws IOException {
+ UserPrincipal user = Files.getOwner(dir);
+ AclFileAttributeView view;
+
+ // create file with initial ACL
+ System.out.println("-- create file with initial ACL --");
+ Path file = dir.resolve("gus");
+ List<AclEntry> fileAcl = Arrays.asList(
+ AclEntry.newBuilder()
+ .setType(AclEntryType.ALLOW)
+ .setPrincipal(user)
+ .setPermissions(SYNCHRONIZE, READ_DATA, WRITE_DATA,
+ READ_ATTRIBUTES, READ_ACL, WRITE_ATTRIBUTES, DELETE)
+ .build());
+ Files.createFile(file, asAclAttribute(fileAcl));
+ view = Files.getFileAttributeView(file, AclFileAttributeView.class);
+ assertEquals(view.getAcl(), fileAcl);
+
+ // create directory with initial ACL
+ System.out.println("-- create directory with initial ACL --");
+ Path subdir = dir.resolve("stuff");
+ List<AclEntry> dirAcl = Arrays.asList(
+ AclEntry.newBuilder()
+ .setType(AclEntryType.ALLOW)
+ .setPrincipal(user)
+ .setPermissions(SYNCHRONIZE, ADD_FILE, DELETE)
+ .build(),
+ AclEntry.newBuilder(fileAcl.get(0))
+ .setFlags(FILE_INHERIT)
+ .build());
+ Files.createDirectory(subdir, asAclAttribute(dirAcl));
+ view = Files.getFileAttributeView(subdir, AclFileAttributeView.class);
+ assertEquals(view.getAcl(), dirAcl);
+ }
+
+ // Android-changed: Removed args & added @Test
+ @Test
+ public static void main() throws IOException {
+ // use work directory rather than system temporary directory to
+ // improve chances that ACLs are supported
+ Path dir = Paths.get("./work" + new Random().nextInt());
+ Files.createDirectory(dir);
+ try {
+ if (!Files.getFileStore(dir).supportsFileAttributeView("acl")) {
+ System.out.println("ACLs not supported - test skipped!");
+ return;
+ }
+ testReadWrite(dir);
+
+ // only currently feasible on Windows
+ if (System.getProperty("os.name").startsWith("Windows"))
+ testCreateFile(dir);
+
+ } finally {
+ TestUtil.removeAll(dir);
+ }
+ }
+}
diff --git a/ojluni/src/test/java/nio/file/attribute/BasicFileAttributeViewCreationTimeTest.java b/ojluni/src/test/java/nio/file/attribute/BasicFileAttributeViewCreationTimeTest.java
new file mode 100644
index 0000000..b393981
--- /dev/null
+++ b/ojluni/src/test/java/nio/file/attribute/BasicFileAttributeViewCreationTimeTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 8011536
+ * @summary Basic test for creationTime attribute on platforms/file systems
+ * that support it.
+ * @library ../..
+ */
+// Android-changed: Adapted from
+// jdk/test/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java
+// Android-changed: Added package & Test import
+package test.java.nio.file.attribute;
+import org.testng.annotations.Test;
+import test.java.nio.file.TestUtil;
+
+import java.nio.file.Path;
+import java.nio.file.Files;
+import java.nio.file.attribute.*;
+import java.time.Instant;
+import java.io.IOException;
+
+// Android-changed: Renamed from "CreationTime"
+public class BasicFileAttributeViewCreationTimeTest {
+
+ private static final java.io.PrintStream err = System.err;
+
+ /**
+ * Reads the creationTime attribute
+ */
+ private static FileTime creationTime(Path file) throws IOException {
+ return Files.readAttributes(file, BasicFileAttributes.class).creationTime();
+ }
+
+ /**
+ * Sets the creationTime attribute
+ */
+ private static void setCreationTime(Path file, FileTime time) throws IOException {
+ BasicFileAttributeView view =
+ Files.getFileAttributeView(file, BasicFileAttributeView.class);
+ view.setTimes(null, null, time);
+ }
+
+ static void test(Path top) throws IOException {
+ Path file = Files.createFile(top.resolve("foo"));
+
+ /**
+ * Check that creationTime reported
+ */
+ FileTime creationTime = creationTime(file);
+ Instant now = Instant.now();
+ if (Math.abs(creationTime.toMillis()-now.toEpochMilli()) > 10000L) {
+ err.println("File creation time reported as: " + creationTime);
+ throw new RuntimeException("Expected to be close to: " + now);
+ }
+
+ /**
+ * Is the creationTime attribute supported here?
+ */
+ boolean supportsCreationTimeRead = false;
+ boolean supportsCreationTimeWrite = false;
+ String os = System.getProperty("os.name");
+ if (os.contains("OS X") && Files.getFileStore(file).type().equals("hfs")) {
+ supportsCreationTimeRead = true;
+ } else if (os.startsWith("Windows")) {
+ String type = Files.getFileStore(file).type();
+ if (type.equals("NTFS") || type.equals("FAT")) {
+ supportsCreationTimeRead = true;
+ supportsCreationTimeWrite = true;
+ }
+ }
+
+ /**
+ * If the creation-time attribute is supported then change the file's
+ * last modified and check that it doesn't change the creation-time.
+ */
+ if (supportsCreationTimeRead) {
+ // change modified time by +1 hour
+ Instant plusHour = Instant.now().plusSeconds(60L * 60L);
+ Files.setLastModifiedTime(file, FileTime.from(plusHour));
+ FileTime current = creationTime(file);
+ if (!current.equals(creationTime))
+ throw new RuntimeException("Creation time should not have changed");
+ }
+
+ /**
+ * If the creation-time attribute is supported and can be changed then
+ * check that the change is effective.
+ */
+ if (supportsCreationTimeWrite) {
+ // change creation time by -1 hour
+ Instant minusHour = Instant.now().minusSeconds(60L * 60L);
+ creationTime = FileTime.from(minusHour);
+ setCreationTime(file, creationTime);
+ FileTime current = creationTime(file);
+ if (Math.abs(creationTime.toMillis()-current.toMillis()) > 1000L)
+ throw new RuntimeException("Creation time not changed");
+ }
+ }
+
+ // Android-changed: Removed args & added @Test
+ @Test
+ public static void main() throws IOException {
+ // create temporary directory to run tests
+ Path dir = TestUtil.createTemporaryDirectory();
+ try {
+ test(dir);
+ } finally {
+ TestUtil.removeAll(dir);
+ }
+ }
+}
diff --git a/ojluni/src/test/java/nio/file/attribute/BasicFileAttributeViewTest.java b/ojluni/src/test/java/nio/file/attribute/BasicFileAttributeViewTest.java
new file mode 100644
index 0000000..82f4e0e
--- /dev/null
+++ b/ojluni/src/test/java/nio/file/attribute/BasicFileAttributeViewTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 4313887 6838333
+ * @summary Unit test for java.nio.file.attribute.BasicFileAttributeView
+ * @library ../..
+ */
+// Android-changed: Adapted from
+// jdk/test/java/nio/file/attribute/BasicFileAttributeView/Basic.java
+// Android-changed: Added package & Test import
+package test.java.nio.file.attribute;
+import org.testng.annotations.Test;
+import test.java.nio.file.TestUtil;
+
+import java.nio.file.*;
+import java.nio.file.attribute.*;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+import java.io.*;
+
+// Android-changed: Renamed from "Basic"
+public class BasicFileAttributeViewTest {
+
+ static void check(boolean okay, String msg) {
+ if (!okay)
+ throw new RuntimeException(msg);
+ }
+
+ static void checkAttributesOfDirectory(Path dir)
+ throws IOException
+ {
+ BasicFileAttributes attrs = Files.readAttributes(dir, BasicFileAttributes.class);
+ check(attrs.isDirectory(), "is a directory");
+ check(!attrs.isRegularFile(), "is not a regular file");
+ check(!attrs.isSymbolicLink(), "is not a link");
+ check(!attrs.isOther(), "is not other");
+
+ // last-modified-time should match java.io.File in seconds
+ File f = new File(dir.toString());
+ check(f.lastModified()/1000 == attrs.lastModifiedTime().to(TimeUnit.SECONDS),
+ "last-modified time should be the same");
+ }
+
+ static void checkAttributesOfFile(Path dir, Path file)
+ throws IOException
+ {
+ BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
+ check(attrs.isRegularFile(), "is a regular file");
+ check(!attrs.isDirectory(), "is not a directory");
+ check(!attrs.isSymbolicLink(), "is not a link");
+ check(!attrs.isOther(), "is not other");
+
+ // size and last-modified-time should match java.io.File in seconds
+ File f = new File(file.toString());
+ check(f.length() == attrs.size(), "size should be the same");
+ check(f.lastModified()/1000 == attrs.lastModifiedTime().to(TimeUnit.SECONDS),
+ "last-modified time should be the same");
+
+ // copy last-modified time from directory to file,
+ // re-read attribtues, and check they match
+ BasicFileAttributeView view =
+ Files.getFileAttributeView(file, BasicFileAttributeView.class);
+ BasicFileAttributes dirAttrs = Files.readAttributes(dir, BasicFileAttributes.class);
+ view.setTimes(dirAttrs.lastModifiedTime(), null, null);
+
+ attrs = view.readAttributes();
+ check(attrs.lastModifiedTime().equals(dirAttrs.lastModifiedTime()),
+ "last-modified time should be equal");
+
+ // security tests
+ check (!(attrs instanceof PosixFileAttributes),
+ "should not be able to cast to PosixFileAttributes");
+ }
+
+ static void checkAttributesOfLink(Path link)
+ throws IOException
+ {
+ BasicFileAttributes attrs =
+ Files.readAttributes(link, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
+ check(attrs.isSymbolicLink(), "is a link");
+ check(!attrs.isDirectory(), "is a directory");
+ check(!attrs.isRegularFile(), "is not a regular file");
+ check(!attrs.isOther(), "is not other");
+ }
+
+ static void attributeReadWriteTests(Path dir)
+ throws IOException
+ {
+ // create file
+ Path file = dir.resolve("foo");
+ try (OutputStream out = Files.newOutputStream(file)) {
+ out.write("this is not an empty file".getBytes("UTF-8"));
+ }
+
+ // check attributes of directory and file
+ checkAttributesOfDirectory(dir);
+ checkAttributesOfFile(dir, file);
+
+ // symbolic links may be supported
+ Path link = dir.resolve("link");
+ try {
+ Files.createSymbolicLink(link, file);
+ } catch (UnsupportedOperationException x) {
+ return;
+ } catch (IOException x) {
+ return;
+ }
+ checkAttributesOfLink(link);
+ }
+
+ // Android-changed: Removed args & added @Test
+ @Test
+ public static void main() throws IOException {
+ // create temporary directory to run tests
+ Path dir = TestUtil.createTemporaryDirectory();
+ try {
+ attributeReadWriteTests(dir);
+ } finally {
+ TestUtil.removeAll(dir);
+ }
+ }
+}
diff --git a/ojluni/src/test/java/nio/file/attribute/DosFileAttributeViewTest.java b/ojluni/src/test/java/nio/file/attribute/DosFileAttributeViewTest.java
new file mode 100644
index 0000000..8386a31
--- /dev/null
+++ b/ojluni/src/test/java/nio/file/attribute/DosFileAttributeViewTest.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 4313887 6838333
+ * @summary Unit test for java.nio.file.attribute.DosFileAttributeView
+ * @library ../..
+ */
+// Android-changed: Adapted from
+// jdk/test/java/nio/file/attribute/DosFileAttributeView/Basic.java
+// Android-changed: Added package & Test import
+package test.java.nio.file.attribute;
+import org.testng.annotations.Test;
+import test.java.nio.file.TestUtil;
+
+import java.nio.file.*;
+import static java.nio.file.LinkOption.*;
+import java.nio.file.attribute.*;
+import java.util.*;
+import java.io.IOException;
+
+// Android-changed: Renamed from "Basic"
+public class DosFileAttributeViewTest {
+
+ static void check(boolean okay) {
+ if (!okay)
+ throw new RuntimeException("Test failed");
+ }
+
+ // exercise each setter/getter method, leaving all attributes unset
+ static void testAttributes(DosFileAttributeView view) throws IOException {
+ view.setReadOnly(true);
+ check(view.readAttributes().isReadOnly());
+ view.setReadOnly(false);
+ check(!view.readAttributes().isReadOnly());
+ view.setHidden(true);
+ check(view.readAttributes().isHidden());
+ view.setHidden(false);
+ check(!view.readAttributes().isHidden());
+ view.setArchive(true);
+ check(view.readAttributes().isArchive());
+ view.setArchive(false);
+ check(!view.readAttributes().isArchive());
+ view.setSystem(true);
+ check(view.readAttributes().isSystem());
+ view.setSystem(false);
+ check(!view.readAttributes().isSystem());
+ }
+
+ // set the value of all attributes
+ static void setAll(DosFileAttributeView view, boolean value)
+ throws IOException
+ {
+ view.setReadOnly(value);
+ view.setHidden(value);
+ view.setArchive(value);
+ view.setSystem(value);
+ }
+
+ // read and write FAT attributes
+ static void readWriteTests(Path dir) throws IOException {
+
+ // create "foo" and test that we can read/write each FAT attribute
+ Path file = Files.createFile(dir.resolve("foo"));
+ try {
+ testAttributes(Files.getFileAttributeView(file, DosFileAttributeView.class));
+
+ // Following tests use a symbolic link so skip if not supported
+ if (!TestUtil.supportsLinks(dir))
+ return;
+
+ Path link = dir.resolve("link");
+ Files.createSymbolicLink(link, file);
+
+ // test following links
+ testAttributes(Files.getFileAttributeView(link, DosFileAttributeView.class));
+
+ // test not following links
+ try {
+ try {
+ testAttributes(Files
+ .getFileAttributeView(link, DosFileAttributeView.class, NOFOLLOW_LINKS));
+ } catch (IOException x) {
+ // access to link attributes not supported
+ return;
+ }
+
+ // set all attributes on link
+ // run test on target of link (which leaves them all un-set)
+ // check that attributes of link remain all set
+ setAll(Files
+ .getFileAttributeView(link, DosFileAttributeView.class, NOFOLLOW_LINKS), true);
+ testAttributes(Files
+ .getFileAttributeView(link, DosFileAttributeView.class));
+ DosFileAttributes attrs =
+ Files.getFileAttributeView(link, DosFileAttributeView.class, NOFOLLOW_LINKS)
+ .readAttributes();
+ check(attrs.isReadOnly());
+ check(attrs.isHidden());
+ check(attrs.isArchive());
+ check(attrs.isSystem());
+ setAll(Files
+ .getFileAttributeView(link, DosFileAttributeView.class, NOFOLLOW_LINKS), false);
+
+ // set all attributes on target
+ // run test on link (which leaves them all un-set)
+ // check that attributes of target remain all set
+ setAll(Files.getFileAttributeView(link, DosFileAttributeView.class), true);
+ testAttributes(Files
+ .getFileAttributeView(link, DosFileAttributeView.class, NOFOLLOW_LINKS));
+ attrs = Files.getFileAttributeView(link, DosFileAttributeView.class).readAttributes();
+ check(attrs.isReadOnly());
+ check(attrs.isHidden());
+ check(attrs.isArchive());
+ check(attrs.isSystem());
+ setAll(Files.getFileAttributeView(link, DosFileAttributeView.class), false);
+ } finally {
+ TestUtil.deleteUnchecked(link);
+ }
+ } finally {
+ TestUtil.deleteUnchecked(file);
+ }
+ }
+
+ // Android-changed: Removed args & added @Test
+ @Test
+ public static void main() throws IOException {
+ // create temporary directory to run tests
+ Path dir = TestUtil.createTemporaryDirectory();
+
+ try {
+ // skip test if DOS file attributes not supported
+ if (!Files.getFileStore(dir).supportsFileAttributeView("dos")) {
+ System.out.println("DOS file attribute not supported.");
+ return;
+ }
+ readWriteTests(dir);
+ } finally {
+ TestUtil.removeAll(dir);
+ }
+ }
+}
diff --git a/ojluni/src/test/java/nio/file/attribute/FileTimeTest.java b/ojluni/src/test/java/nio/file/attribute/FileTimeTest.java
new file mode 100644
index 0000000..43c5d61
--- /dev/null
+++ b/ojluni/src/test/java/nio/file/attribute/FileTimeTest.java
@@ -0,0 +1,352 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 6844313 8011647
+ * @summary Unit test for java.nio.file.FileTime
+ */
+// Android-changed: Adapted from
+// jdk/test/java/nio/file/attribute/FileTime/Basic.java
+// Android-changed: Added package & Test import
+package test.java.nio.file.attribute;
+import org.testng.annotations.Test;
+
+import java.nio.file.attribute.FileTime;
+import java.time.Instant;
+import java.util.concurrent.TimeUnit;
+import static java.util.concurrent.TimeUnit.*;
+import java.util.Random;
+import java.util.EnumSet;
+
+// Android-changed: Renamed from "Basic"
+public class FileTimeTest {
+
+ static final Random rand = new Random();
+
+ // Android-changed: Removed args & added @Test
+ @Test
+ public static void main() {
+ long now = System.currentTimeMillis();
+ long tomorrowInDays = TimeUnit.DAYS.convert(now, MILLISECONDS) + 1;
+ long yesterdayInDays = TimeUnit.DAYS.convert(now, MILLISECONDS) - 1;
+
+ Instant nowInstant = Instant.ofEpochMilli(now);
+
+ // equals
+ eq(now, MILLISECONDS, now, MILLISECONDS);
+ eq(now, MILLISECONDS, now*1000L, MICROSECONDS);
+ neq(now, MILLISECONDS, 0, MILLISECONDS);
+ neq(now, MILLISECONDS, 0, MICROSECONDS);
+
+ eq(nowInstant, now, MILLISECONDS);
+ eq(nowInstant, now*1000L, MICROSECONDS);
+ neq(nowInstant, 0, MILLISECONDS);
+ neq(nowInstant, 0, MICROSECONDS);
+
+ // compareTo
+ cmp(now, MILLISECONDS, now, MILLISECONDS, 0);
+ cmp(now, MILLISECONDS, now*1000L, MICROSECONDS, 0);
+ cmp(now, MILLISECONDS, now-1234, MILLISECONDS, 1);
+ cmp(now, MILLISECONDS, now+1234, MILLISECONDS, -1);
+
+ cmp(tomorrowInDays, DAYS, now, MILLISECONDS, 1);
+ cmp(now, MILLISECONDS, tomorrowInDays, DAYS, -1);
+ cmp(yesterdayInDays, DAYS, now, MILLISECONDS, -1);
+ cmp(now, MILLISECONDS, yesterdayInDays, DAYS, 1);
+ cmp(yesterdayInDays, DAYS, now, MILLISECONDS, -1);
+
+ cmp(Long.MAX_VALUE, DAYS, Long.MAX_VALUE, NANOSECONDS, 1);
+ cmp(Long.MAX_VALUE, DAYS, Long.MIN_VALUE, NANOSECONDS, 1);
+ cmp(Long.MIN_VALUE, DAYS, Long.MIN_VALUE, NANOSECONDS, -1);
+ cmp(Long.MIN_VALUE, DAYS, Long.MAX_VALUE, NANOSECONDS, -1);
+
+ cmp(Instant.MIN, Long.MIN_VALUE, DAYS, 1);
+ cmp(Instant.MIN, Long.MIN_VALUE, HOURS, 1);
+ cmp(Instant.MIN, Long.MIN_VALUE, MINUTES, 1);
+ cmp(Instant.MIN, Long.MIN_VALUE, SECONDS, 1);
+ cmp(Instant.MIN, Instant.MIN.getEpochSecond() - 1, SECONDS, 1);
+ cmp(Instant.MIN, Instant.MIN.getEpochSecond() - 100, SECONDS, 1);
+ cmp(Instant.MIN, Instant.MIN.getEpochSecond(), SECONDS, 0);
+
+ cmp(Instant.MAX, Long.MAX_VALUE, DAYS, -1);
+ cmp(Instant.MAX, Long.MAX_VALUE, HOURS, -1);
+ cmp(Instant.MAX, Long.MAX_VALUE, MINUTES, -1);
+ cmp(Instant.MAX, Long.MAX_VALUE, SECONDS, -1);
+ cmp(Instant.MAX, Instant.MAX.getEpochSecond() + 1, SECONDS, -1);
+ cmp(Instant.MAX, Instant.MAX.getEpochSecond() + 100, SECONDS, -1);
+ cmp(Instant.MAX, Instant.MAX.getEpochSecond(), SECONDS, 0);
+
+ cmp(nowInstant, now, MILLISECONDS, 0);
+ cmp(nowInstant, now*1000L, MICROSECONDS, 0);
+ cmp(nowInstant, now-1234, MILLISECONDS, 1);
+ cmp(nowInstant, now+1234, MILLISECONDS, -1);
+ cmp(nowInstant, tomorrowInDays, DAYS, -1);
+ cmp(nowInstant, yesterdayInDays, DAYS, 1);
+
+ // to(TimeUnit)
+ to(MILLISECONDS.convert(1, DAYS) - 1, MILLISECONDS);
+ to(MILLISECONDS.convert(1, DAYS) + 0, MILLISECONDS);
+ to(MILLISECONDS.convert(1, DAYS) + 1, MILLISECONDS);
+ to(1, MILLISECONDS);
+ to(0, MILLISECONDS);
+ to(1, MILLISECONDS);
+ to(MILLISECONDS.convert(-1, DAYS) - 1, MILLISECONDS);
+ to(MILLISECONDS.convert(-1, DAYS) + 0, MILLISECONDS);
+ to(MILLISECONDS.convert(-1, DAYS) + 1, MILLISECONDS);
+ for (TimeUnit unit: TimeUnit.values()) {
+ for (int i=0; i<100; i++) { to(rand.nextLong(), unit); }
+ to(Long.MIN_VALUE, unit);
+ to(Long.MAX_VALUE, unit);
+ }
+
+ // toInstant()
+ int N = 1000;
+ for (TimeUnit unit : EnumSet.allOf(TimeUnit.class)) {
+ for (int i = 0; i < N; i++) {
+ long value = rand.nextLong();
+ FileTime ft = FileTime.from(value, unit);
+ Instant instant = ft.toInstant();
+ if (instant != Instant.MIN && instant != Instant.MAX) {
+ eqTime(value, unit, instant);
+ }
+ }
+ }
+ for (TimeUnit unit : EnumSet.allOf(TimeUnit.class)) {
+ long value = Long.MIN_VALUE;
+ FileTime ft = FileTime.from(value, unit);
+ Instant instant = ft.toInstant();
+ if (unit.compareTo(TimeUnit.SECONDS) < 0) {
+ eqTime(value, unit, instant);
+ } else if (!instant.equals(Instant.MIN)) {
+ throw new RuntimeException("should overflow to MIN");
+ }
+ value = Long.MAX_VALUE;
+ ft = FileTime.from(value, unit);
+ instant = ft.toInstant();
+ if (unit.compareTo(TimeUnit.SECONDS) < 0) {
+ eqTime(value, unit, instant);
+ } else if (!instant.equals(Instant.MAX)) {
+ throw new RuntimeException("should overflow to MAX");
+ }
+ }
+
+ // from(Instant)
+ final long MAX_SECOND = 31556889864403199L;
+ for (int i = 0; i < N; i++) {
+ long v = rand.nextLong();
+ long secs = v % MAX_SECOND;
+ Instant instant = Instant.ofEpochSecond(secs, rand.nextInt(1000_000_000));
+ FileTime ft = FileTime.from(instant);
+ if (!ft.toInstant().equals(instant) || ft.to(SECONDS) != secs) {
+ throw new RuntimeException("from(Instant) failed");
+ }
+ long millis = v;
+ instant = Instant.ofEpochMilli(millis);
+ ft = FileTime.from(instant);
+ if (!ft.toInstant().equals(instant) ||
+ ft.toMillis() != instant.toEpochMilli()) {
+ throw new RuntimeException("from(Instant) failed");
+ }
+ long nanos = v;
+ ft = FileTime.from(nanos, NANOSECONDS);
+ secs = nanos / 1000_000_000;
+ nanos = nanos % 1000_000_000;
+ instant = Instant.ofEpochSecond(secs, nanos);
+ if (!ft.equals(FileTime.from(instant))) {
+ throw new RuntimeException("from(Instant) failed");
+ }
+ }
+
+ // toString
+ ts(1L, DAYS, "1970-01-02T00:00:00Z");
+ ts(1L, HOURS, "1970-01-01T01:00:00Z");
+ ts(1L, MINUTES, "1970-01-01T00:01:00Z");
+ ts(1L, SECONDS, "1970-01-01T00:00:01Z");
+ ts(1L, MILLISECONDS, "1970-01-01T00:00:00.001Z");
+ ts(1L, MICROSECONDS, "1970-01-01T00:00:00.000001Z");
+ ts(1L, NANOSECONDS, "1970-01-01T00:00:00.000000001Z");
+ ts(999999999L, NANOSECONDS, "1970-01-01T00:00:00.999999999Z");
+ ts(9999999999L, NANOSECONDS, "1970-01-01T00:00:09.999999999Z");
+
+ ts(-1L, DAYS, "1969-12-31T00:00:00Z");
+ ts(-1L, HOURS, "1969-12-31T23:00:00Z");
+ ts(-1L, MINUTES, "1969-12-31T23:59:00Z");
+ ts(-1L, SECONDS, "1969-12-31T23:59:59Z");
+ ts(-1L, MILLISECONDS, "1969-12-31T23:59:59.999Z");
+ ts(-1L, MICROSECONDS, "1969-12-31T23:59:59.999999Z");
+ ts(-1L, NANOSECONDS, "1969-12-31T23:59:59.999999999Z");
+ ts(-999999999L, NANOSECONDS, "1969-12-31T23:59:59.000000001Z");
+ ts(-9999999999L, NANOSECONDS, "1969-12-31T23:59:50.000000001Z");
+
+ ts(-62135596799999L, MILLISECONDS, "0001-01-01T00:00:00.001Z");
+ ts(-62135596800000L, MILLISECONDS, "0001-01-01T00:00:00Z");
+ ts(-62135596800001L, MILLISECONDS, "-0001-12-31T23:59:59.999Z");
+
+ ts(253402300799999L, MILLISECONDS, "9999-12-31T23:59:59.999Z");
+ ts(-377642044800001L, MILLISECONDS, "-9999-12-31T23:59:59.999Z");
+
+ // NTFS epoch in usec.
+ ts(-11644473600000000L, MICROSECONDS, "1601-01-01T00:00:00Z");
+
+ ts(Instant.MIN, "-1000000001-01-01T00:00:00Z");
+ ts(Instant.MAX, "1000000000-12-31T23:59:59.999999999Z");
+
+ try {
+ FileTime.from(0L, null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException npe) { }
+ try {
+ FileTime.from(null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException npe) { }
+
+ FileTime time = FileTime.fromMillis(now);
+ if (time.equals(null))
+ throw new RuntimeException("should not be equal to null");
+ try {
+ time.compareTo(null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException npe) { }
+
+ // Instant + toMilli() overflow
+ overflow(Long.MAX_VALUE,
+ FileTime.from(Instant.MAX).toMillis());
+ overflow(Long.MAX_VALUE,
+ FileTime.from(Instant.ofEpochSecond(Long.MAX_VALUE / 1000 + 1))
+ .toMillis());
+ overflow(Long.MIN_VALUE,
+ FileTime.from(Instant.MIN).toMillis());
+ overflow(Long.MIN_VALUE,
+ FileTime.from(Instant.ofEpochSecond(Long.MIN_VALUE / 1000 - 1))
+ .toMillis());
+
+ // Instant + to(TimeUnit) overflow
+ overflow(Long.MAX_VALUE,
+ FileTime.from(Instant.ofEpochSecond(Long.MAX_VALUE / 1000 + 1))
+ .to(MILLISECONDS));
+ overflow(Long.MAX_VALUE,
+ FileTime.from(Instant.ofEpochSecond(Long.MAX_VALUE / 1000,
+ MILLISECONDS.toNanos(1000)))
+ .to(MILLISECONDS));
+ overflow(Long.MIN_VALUE,
+ FileTime.from(Instant.ofEpochSecond(Long.MIN_VALUE / 1000 - 1))
+ .to(MILLISECONDS));
+ overflow(Long.MIN_VALUE,
+ FileTime.from(Instant.ofEpochSecond(Long.MIN_VALUE / 1000,
+ -MILLISECONDS.toNanos(1)))
+ .to(MILLISECONDS));
+ }
+
+ static void overflow(long minmax, long v) {
+ if (v != minmax)
+ throw new RuntimeException("saturates to Long.MIN/MAX_VALUE expected");
+ }
+
+ static void cmp(long v1, TimeUnit u1, long v2, TimeUnit u2, int expected) {
+ int result = FileTime.from(v1, u1).compareTo(FileTime.from(v2, u2));
+ if (result != expected)
+ throw new RuntimeException("unexpected order");
+ }
+
+ static void cmp(Instant ins, long v2, TimeUnit u2, int expected) {
+ int result = FileTime.from(ins).compareTo(FileTime.from(v2, u2));
+ if (result != expected)
+ throw new RuntimeException("unexpected order");
+ }
+
+ static void eq(long v1, TimeUnit u1, long v2, TimeUnit u2) {
+ FileTime t1 = FileTime.from(v1, u1);
+ FileTime t2 = FileTime.from(v2, u2);
+ if (!t1.equals(t2))
+ throw new RuntimeException("not equal");
+ if (t1.hashCode() != t2.hashCode())
+ throw new RuntimeException("hashCodes should be equal");
+ }
+
+ static void eq(Instant ins, long v2, TimeUnit u2) {
+ FileTime t1 = FileTime.from(ins);
+ FileTime t2 = FileTime.from(v2, u2);
+ if (!t1.equals(t2))
+ throw new RuntimeException("not equal");
+ if (t1.hashCode() != t2.hashCode())
+ throw new RuntimeException("hashCodes should be equal");
+ }
+
+ static void eqTime(long value, TimeUnit unit, Instant instant) {
+ long secs = SECONDS.convert(value, unit);
+ long nanos = NANOSECONDS.convert(value - unit.convert(secs, SECONDS), unit);
+ if (nanos < 0) { // normalize nanoOfSecond to positive
+ secs -= 1;
+ nanos += 1000_000_000;
+ }
+ if (secs != instant.getEpochSecond() || (int)nanos != instant.getNano()) {
+ System.err.println(" ins=" + instant);
+ throw new RuntimeException("ft and instant are not the same time point");
+ }
+ }
+
+ static void neq(long v1, TimeUnit u1, long v2, TimeUnit u2) {
+ FileTime t1 = FileTime.from(v1, u1);
+ FileTime t2 = FileTime.from(v2, u2);
+ if (t1.equals(t2))
+ throw new RuntimeException("should not be equal");
+ }
+
+ static void neq(Instant ins, long v2, TimeUnit u2) {
+ FileTime t1 = FileTime.from(ins);
+ FileTime t2 = FileTime.from(v2, u2);
+ if (t1.equals(t2))
+ throw new RuntimeException("should not be equal");
+ }
+
+ static void to(long v, TimeUnit unit) {
+ FileTime t = FileTime.from(v, unit);
+ for (TimeUnit u: TimeUnit.values()) {
+ long result = t.to(u);
+ long expected = u.convert(v, unit);
+ if (result != expected) {
+ throw new RuntimeException("unexpected result");
+ }
+ }
+ }
+
+ static void ts(long v, TimeUnit unit, String expected) {
+ String result = FileTime.from(v, unit).toString();
+ if (!result.equals(expected)) {
+ System.err.format("FileTime.from(%d, %s).toString() failed\n", v, unit);
+ System.err.format("Expected: %s\n", expected);
+ System.err.format(" Got: %s\n", result);
+ throw new RuntimeException();
+ }
+ }
+
+ static void ts(Instant instant, String expected) {
+ String result = FileTime.from(instant).toString();
+ if (!result.equals(expected)) {
+ System.err.format("FileTime.from(%s).toString() failed\n", instant);
+ System.err.format("Expected: %s\n", expected);
+ System.err.format(" Got: %s\n", result);
+ throw new RuntimeException();
+ }
+ }
+}
diff --git a/ojluni/src/test/java/nio/file/attribute/PosixFileAttributeViewTest.java b/ojluni/src/test/java/nio/file/attribute/PosixFileAttributeViewTest.java
new file mode 100644
index 0000000..7825837
--- /dev/null
+++ b/ojluni/src/test/java/nio/file/attribute/PosixFileAttributeViewTest.java
@@ -0,0 +1,406 @@
+/*
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 4313887 6838333
+ * @summary Unit test for java.nio.file.attribute.PosixFileAttributeView
+ * @library ../..
+ */
+// Android-changed: Adapted from
+// jdk/test/java/nio/file/attribute/PosixFileAttributeView/Basic.java
+// Android-changed: Added package & Test import
+package test.java.nio.file.attribute;
+import org.testng.annotations.Test;
+import test.java.nio.file.TestUtil;
+
+import java.nio.file.*;
+import static java.nio.file.LinkOption.*;
+import java.nio.file.attribute.*;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * Unit test for PosixFileAttributeView, passing silently if this attribute
+ * view is not available.
+ */
+
+// Android-changed: Renamed from "Basic"
+public class PosixFileAttributeViewTest {
+
+ /**
+ * Use view to update permission to the given mode and check that the
+ * permissions have been updated.
+ */
+ static void testPermissions(Path file, String mode) throws IOException {
+ System.out.format("change mode: %s\n", mode);
+ Set<PosixFilePermission> perms = PosixFilePermissions.fromString(mode);
+
+ // change permissions and re-read them.
+ Files.setPosixFilePermissions(file, perms);
+ Set<PosixFilePermission> current = Files.getPosixFilePermissions(file);
+ if (!current.equals(perms)) {
+ throw new RuntimeException("Actual permissions: " +
+ PosixFilePermissions.toString(current) + ", expected: " +
+ PosixFilePermissions.toString(perms));
+ }
+
+ // repeat test using setAttribute/getAttribute
+ Files.setAttribute(file, "posix:permissions", perms);
+ current = (Set<PosixFilePermission>)Files.getAttribute(file, "posix:permissions");
+ if (!current.equals(perms)) {
+ throw new RuntimeException("Actual permissions: " +
+ PosixFilePermissions.toString(current) + ", expected: " +
+ PosixFilePermissions.toString(perms));
+ }
+ }
+
+ /**
+ * Check that the actual permissions of a file match or make it more
+ * secure than requested
+ */
+ static void checkSecure(Set<PosixFilePermission> requested,
+ Set<PosixFilePermission> actual)
+ {
+ for (PosixFilePermission perm: actual) {
+ if (!requested.contains(perm)) {
+ throw new RuntimeException("Actual permissions: " +
+ PosixFilePermissions.toString(actual) + ", requested: " +
+ PosixFilePermissions.toString(requested) +
+ " - file is less secure than requested");
+ }
+ }
+ }
+
+ /**
+ * Create file with given mode and check that the file is created with a
+ * mode that is not less secure
+ */
+ static void createWithPermissions(Path file,
+ String mode)
+ throws IOException
+ {
+ Set<PosixFilePermission> requested = PosixFilePermissions.fromString(mode);
+ FileAttribute<Set<PosixFilePermission>> attr =
+ PosixFilePermissions.asFileAttribute(requested);
+ System.out.format("create file with mode: %s\n", mode);
+ Files.createFile(file, attr);
+ try {
+ checkSecure(requested,
+ Files.getFileAttributeView(file, PosixFileAttributeView.class)
+ .readAttributes()
+ .permissions());
+ } finally {
+ Files.delete(file);
+ }
+
+ System.out.format("create directory with mode: %s\n", mode);
+ Files.createDirectory(file, attr);
+ try {
+ checkSecure(requested,
+ Files.getFileAttributeView(file, PosixFileAttributeView.class)
+ .readAttributes()
+ .permissions());
+ } finally {
+ Files.delete(file);
+ }
+ }
+
+ /**
+ * Test the setPermissions/permissions methods.
+ */
+ static void permissionTests(Path dir)
+ throws IOException
+ {
+ System.out.println("-- Permission Tests --");
+
+ // create file and test updating and reading its permissions
+ Path file = dir.resolve("foo");
+ System.out.format("create %s\n", file);
+ Files.createFile(file);
+ try {
+ // get initial permissions so that we can restore them later
+ PosixFileAttributeView view =
+ Files.getFileAttributeView(file, PosixFileAttributeView.class);
+ Set<PosixFilePermission> save = view.readAttributes()
+ .permissions();
+
+ // test various modes
+ try {
+ testPermissions(file, "---------");
+ testPermissions(file, "r--------");
+ testPermissions(file, "-w-------");
+ testPermissions(file, "--x------");
+ testPermissions(file, "rwx------");
+ testPermissions(file, "---r-----");
+ testPermissions(file, "----w----");
+ testPermissions(file, "-----x---");
+ testPermissions(file, "---rwx---");
+ testPermissions(file, "------r--");
+ testPermissions(file, "-------w-");
+ testPermissions(file, "--------x");
+ testPermissions(file, "------rwx");
+ testPermissions(file, "r--r-----");
+ testPermissions(file, "r--r--r--");
+ testPermissions(file, "rw-rw----");
+ testPermissions(file, "rwxrwx---");
+ testPermissions(file, "rw-rw-r--");
+ testPermissions(file, "r-xr-x---");
+ testPermissions(file, "r-xr-xr-x");
+ testPermissions(file, "rwxrwxrwx");
+ } finally {
+ view.setPermissions(save);
+ }
+ } finally {
+ Files.delete(file);
+ }
+
+ // create link (to file that doesn't exist) and test reading of
+ // permissions
+ if (TestUtil.supportsLinks(dir)) {
+ Path link = dir.resolve("link");
+ System.out.format("create link %s\n", link);
+ Files.createSymbolicLink(link, file);
+ try {
+ PosixFileAttributes attrs =
+ Files.getFileAttributeView(link,
+ PosixFileAttributeView.class,
+ NOFOLLOW_LINKS)
+ .readAttributes();
+ if (!attrs.isSymbolicLink()) {
+ throw new RuntimeException("not a link");
+ }
+ } finally {
+ Files.delete(link);
+ }
+ }
+
+ System.out.println("OKAY");
+ }
+
+ /**
+ * Test creating a file and directory with initial permissios
+ */
+ static void createTests(Path dir)
+ throws IOException
+ {
+ System.out.println("-- Create Tests --");
+
+ Path file = dir.resolve("foo");
+
+ createWithPermissions(file, "---------");
+ createWithPermissions(file, "r--------");
+ createWithPermissions(file, "-w-------");
+ createWithPermissions(file, "--x------");
+ createWithPermissions(file, "rwx------");
+ createWithPermissions(file, "---r-----");
+ createWithPermissions(file, "----w----");
+ createWithPermissions(file, "-----x---");
+ createWithPermissions(file, "---rwx---");
+ createWithPermissions(file, "------r--");
+ createWithPermissions(file, "-------w-");
+ createWithPermissions(file, "--------x");
+ createWithPermissions(file, "------rwx");
+ createWithPermissions(file, "r--r-----");
+ createWithPermissions(file, "r--r--r--");
+ createWithPermissions(file, "rw-rw----");
+ createWithPermissions(file, "rwxrwx---");
+ createWithPermissions(file, "rw-rw-r--");
+ createWithPermissions(file, "r-xr-x---");
+ createWithPermissions(file, "r-xr-xr-x");
+ createWithPermissions(file, "rwxrwxrwx");
+
+ System.out.println("OKAY");
+ }
+
+ /**
+ * Test setOwner/setGroup methods - this test simply exercises the
+ * methods to avoid configuration.
+ */
+ static void ownerTests(Path dir)
+ throws IOException
+ {
+ System.out.println("-- Owner Tests --");
+
+ Path file = dir.resolve("gus");
+ System.out.format("create %s\n", file);
+
+ Files.createFile(file);
+ try {
+
+ // read attributes of directory to get owner/group
+ PosixFileAttributeView view =
+ Files.getFileAttributeView(file, PosixFileAttributeView.class);
+ PosixFileAttributes attrs = view.readAttributes();
+
+ // set to existing owner/group
+ view.setOwner(attrs.owner());
+ view.setGroup(attrs.group());
+
+ // repeat test using set/getAttribute
+ UserPrincipal owner = (UserPrincipal)Files.getAttribute(file, "posix:owner");
+ Files.setAttribute(file, "posix:owner", owner);
+ UserPrincipal group = (UserPrincipal)Files.getAttribute(file, "posix:group");
+ Files.setAttribute(file, "posix:group", group);
+
+ } finally {
+ Files.delete(file);
+ }
+
+ System.out.println("OKAY");
+ }
+
+ /**
+ * Test the lookupPrincipalByName/lookupPrincipalByGroupName methods
+ */
+ static void lookupPrincipalTests(Path dir)
+ throws IOException
+ {
+ System.out.println("-- Lookup UserPrincipal Tests --");
+
+ UserPrincipalLookupService lookupService = dir.getFileSystem()
+ .getUserPrincipalLookupService();
+
+ // read attributes of directory to get owner/group
+ PosixFileAttributes attrs = Files.readAttributes(dir, PosixFileAttributes.class);
+
+ // lookup owner and check it matches file's owner
+ System.out.format("lookup: %s\n", attrs.owner().getName());
+ try {
+ UserPrincipal owner = lookupService.lookupPrincipalByName(attrs.owner().getName());
+ if (owner instanceof GroupPrincipal)
+ throw new RuntimeException("owner is a group?");
+ if (!owner.equals(attrs.owner()))
+ throw new RuntimeException("owner different from file owner");
+ } catch (UserPrincipalNotFoundException x) {
+ System.out.println("user not found - test skipped");
+ }
+
+ // lookup group and check it matches file's group-owner
+ System.out.format("lookup group: %s\n", attrs.group().getName());
+ try {
+ GroupPrincipal group = lookupService.lookupPrincipalByGroupName(attrs.group().getName());
+ if (!group.equals(attrs.group()))
+ throw new RuntimeException("group different from file group-owner");
+ } catch (UserPrincipalNotFoundException x) {
+ System.out.println("group not found - test skipped");
+ }
+
+ // test that UserPrincipalNotFoundException is thrown
+ String invalidPrincipal = "scumbag99";
+ try {
+ System.out.format("lookup: %s\n", invalidPrincipal);
+ lookupService.lookupPrincipalByName(invalidPrincipal);
+ throw new RuntimeException("'" + invalidPrincipal + "' is a valid user?");
+ } catch (UserPrincipalNotFoundException x) {
+ }
+ try {
+ System.out.format("lookup group: %s\n", invalidPrincipal);
+ lookupService.lookupPrincipalByGroupName("idonotexist");
+ throw new RuntimeException("'" + invalidPrincipal + "' is a valid group?");
+ } catch (UserPrincipalNotFoundException x) {
+ }
+ System.out.println("OKAY");
+ }
+
+ /**
+ * Test various exceptions are thrown as expected
+ */
+ @SuppressWarnings("unchecked")
+ static void exceptionsTests(Path dir)
+ throws IOException
+ {
+ System.out.println("-- Exceptions --");
+
+ PosixFileAttributeView view =
+ Files.getFileAttributeView(dir,PosixFileAttributeView.class);
+
+ // NullPointerException
+ try {
+ view.setOwner(null);
+ throw new RuntimeException("NullPointerException not thrown");
+ } catch (NullPointerException x) {
+ }
+ try {
+ view.setGroup(null);
+ throw new RuntimeException("NullPointerException not thrown");
+ } catch (NullPointerException x) {
+ }
+
+ UserPrincipalLookupService lookupService = dir.getFileSystem()
+ .getUserPrincipalLookupService();
+ try {
+ lookupService.lookupPrincipalByName(null);
+ throw new RuntimeException("NullPointerException not thrown");
+ } catch (NullPointerException x) {
+ }
+ try {
+ lookupService.lookupPrincipalByGroupName(null);
+ throw new RuntimeException("NullPointerException not thrown");
+ } catch (NullPointerException x) {
+ }
+ try {
+ view.setPermissions(null);
+ throw new RuntimeException("NullPointerException not thrown");
+ } catch (NullPointerException x) {
+ }
+ try {
+ Set<PosixFilePermission> perms = new HashSet<>();
+ perms.add(null);
+ view.setPermissions(perms);
+ throw new RuntimeException("NullPointerException not thrown");
+ } catch (NullPointerException x) {
+ }
+
+ // ClassCastException
+ try {
+ Set perms = new HashSet(); // raw type
+ perms.add(new Object());
+ view.setPermissions(perms);
+ throw new RuntimeException("ClassCastException not thrown");
+ } catch (ClassCastException x) {
+ }
+
+ System.out.println("OKAY");
+ }
+
+ // Android-changed: Removed args & added @Test
+ @Test
+ public static void main() throws IOException {
+ Path dir = TestUtil.createTemporaryDirectory();
+ try {
+ if (!Files.getFileStore(dir).supportsFileAttributeView("posix")) {
+ System.out.println("PosixFileAttributeView not supported");
+ return;
+ }
+
+ permissionTests(dir);
+ createTests(dir);
+ ownerTests(dir);
+ lookupPrincipalTests(dir);
+ exceptionsTests(dir);
+
+ } finally {
+ TestUtil.removeAll(dir);
+ }
+ }
+}
diff --git a/ojluni/src/test/java/nio/file/attribute/UserDefinedFileAttributeViewTest.java b/ojluni/src/test/java/nio/file/attribute/UserDefinedFileAttributeViewTest.java
new file mode 100644
index 0000000..6fb3c78
--- /dev/null
+++ b/ojluni/src/test/java/nio/file/attribute/UserDefinedFileAttributeViewTest.java
@@ -0,0 +1,288 @@
+/*
+ * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 4313887 6838333
+ * @summary Unit test for java.nio.file.attribute.UserDefinedFileAttributeView
+ * @library ../..
+ */
+// Android-changed: Adapted from
+// jdk/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java
+// Android-changed: Added package & Test import
+package test.java.nio.file.attribute;
+import org.testng.annotations.Test;
+import test.java.nio.file.TestUtil;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.file.*;
+import static java.nio.file.LinkOption.*;
+import java.nio.file.attribute.*;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Random;
+import java.io.IOException;
+
+// Android-changed: Renamed from "Basic"
+public class UserDefinedFileAttributeViewTest {
+
+ private static Random rand = new Random();
+
+ private static final String ATTR_NAME = "mime_type";
+ private static final String ATTR_VALUE = "text/plain";
+ private static final String ATTR_VALUE2 = "text/html";
+
+ static interface Task {
+ void run() throws Exception;
+ }
+
+ static void tryCatch(Class<? extends Throwable> ex, Task task) {
+ boolean caught = false;
+ try {
+ task.run();
+ } catch (Throwable x) {
+ if (ex.isAssignableFrom(x.getClass())) {
+ caught = true;
+ } else {
+ throw new RuntimeException(x);
+ }
+ }
+ if (!caught)
+ throw new RuntimeException(ex.getName() + " expected");
+ }
+
+ static void expectNullPointerException(Task task) {
+ tryCatch(NullPointerException.class, task);
+ }
+
+ static boolean hasAttribute(UserDefinedFileAttributeView view, String attr)
+ throws IOException
+ {
+ for (String name: view.list()) {
+ if (name.equals(ATTR_NAME))
+ return true;
+ }
+ return false;
+ }
+
+ static void test(Path file, LinkOption... options) throws IOException {
+ final UserDefinedFileAttributeView view =
+ Files.getFileAttributeView(file, UserDefinedFileAttributeView.class, options);
+ ByteBuffer buf = rand.nextBoolean() ?
+ ByteBuffer.allocate(100) : ByteBuffer.allocateDirect(100);
+
+ // Test: write
+ buf.put(ATTR_VALUE.getBytes()).flip();
+ int size = buf.remaining();
+ int nwrote = view.write(ATTR_NAME, buf);
+ if (nwrote != size)
+ throw new RuntimeException("Unexpected number of bytes written");
+
+ // Test: size
+ if (view.size(ATTR_NAME) != size)
+ throw new RuntimeException("Unexpected size");
+
+ // Test: read
+ buf.clear();
+ int nread = view.read(ATTR_NAME, buf);
+ if (nread != size)
+ throw new RuntimeException("Unexpected number of bytes read");
+ buf.flip();
+ String value = Charset.defaultCharset().decode(buf).toString();
+ if (!value.equals(ATTR_VALUE))
+ throw new RuntimeException("Unexpected attribute value");
+
+ // Test: read with insufficient space
+ tryCatch(IOException.class, new Task() {
+ public void run() throws IOException {
+ view.read(ATTR_NAME, ByteBuffer.allocateDirect(1));
+ }});
+
+ // Test: replace value
+ buf.clear();
+ buf.put(ATTR_VALUE2.getBytes()).flip();
+ size = buf.remaining();
+ view.write(ATTR_NAME, buf);
+ if (view.size(ATTR_NAME) != size)
+ throw new RuntimeException("Unexpected size");
+
+ // Test: list
+ if (!hasAttribute(view, ATTR_NAME))
+ throw new RuntimeException("Attribute name not in list");
+
+ // Test: delete
+ view.delete(ATTR_NAME);
+ if (hasAttribute(view, ATTR_NAME))
+ throw new RuntimeException("Attribute name in list");
+
+ // Test: dynamic access
+ String name = "user:" + ATTR_NAME;
+ byte[] valueAsBytes = ATTR_VALUE.getBytes();
+ Files.setAttribute(file, name, valueAsBytes);
+ byte[] actualAsBytes = (byte[])Files.getAttribute(file, name);
+ if (!Arrays.equals(valueAsBytes, actualAsBytes))
+ throw new RuntimeException("Unexpected attribute value");
+ Map<String,?> map = Files.readAttributes(file, name);
+ if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME)))
+ throw new RuntimeException("Unexpected attribute value");
+ map = Files.readAttributes(file, "user:*");
+ if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME)))
+ throw new RuntimeException("Unexpected attribute value");
+ }
+
+ static void miscTests(final Path file) throws IOException {
+ final UserDefinedFileAttributeView view =
+ Files.getFileAttributeView(file, UserDefinedFileAttributeView.class);
+ view.write(ATTR_NAME, ByteBuffer.wrap(ATTR_VALUE.getBytes()));
+
+ // NullPointerException
+ final ByteBuffer buf = ByteBuffer.allocate(100);
+
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ view.read(null, buf);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ view.read(ATTR_NAME, null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ view.write(null, buf);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ view.write(ATTR_NAME, null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ view.size(null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ view.delete(null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ Files.getAttribute(file, null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ Files.getAttribute(file, "user:" + ATTR_NAME, (LinkOption[])null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ Files.setAttribute(file, "user:" + ATTR_NAME, null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ Files.setAttribute(file, null, new byte[0]);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ Files.setAttribute(file, "user: " + ATTR_NAME, new byte[0], (LinkOption[])null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ Files.readAttributes(file, (String)null);
+ }});
+ expectNullPointerException(new Task() {
+ public void run() throws IOException {
+ Files.readAttributes(file, "*", (LinkOption[])null);
+ }});
+
+ // Read-only buffer
+ tryCatch(IllegalArgumentException.class, new Task() {
+ public void run() throws IOException {
+ ByteBuffer buf = ByteBuffer.wrap(ATTR_VALUE.getBytes()).asReadOnlyBuffer();
+ view.write(ATTR_NAME, buf);
+ buf.flip();
+ view.read(ATTR_NAME, buf);
+ }});
+
+ // Zero bytes remaining
+ tryCatch(IOException.class, new Task() {
+ public void run() throws IOException {
+ ByteBuffer buf = buf = ByteBuffer.allocateDirect(100);
+ buf.position(buf.capacity());
+ view.read(ATTR_NAME, buf);
+ }});
+ }
+
+ // Android-changed: Removed args & added @Test
+ @Test
+ public static void main() throws IOException {
+ // create temporary directory to run tests
+ Path dir = TestUtil.createTemporaryDirectory();
+ try {
+ if (!Files.getFileStore(dir).supportsFileAttributeView("user")) {
+ System.out.println("UserDefinedFileAttributeView not supported - skip test");
+ return;
+ }
+
+ // test access to user defined attributes of regular file
+ Path file = dir.resolve("foo.html");
+ Files.createFile(file);
+ try {
+ test(file);
+ } finally {
+ Files.delete(file);
+ }
+
+ // test access to user defined attributes of directory
+ Path subdir = dir.resolve("foo");
+ Files.createDirectory(subdir);
+ try {
+ test(subdir);
+ } finally {
+ Files.delete(subdir);
+ }
+
+ // test access to user defined attributes of sym link
+ if (TestUtil.supportsLinks(dir)) {
+ Path target = dir.resolve("doesnotexist");
+ Path link = dir.resolve("link");
+ Files.createSymbolicLink(link, target);
+ try {
+ test(link, NOFOLLOW_LINKS);
+ } catch (IOException x) {
+ // access to attributes of sym link may not be supported
+ } finally {
+ Files.delete(link);
+ }
+ }
+
+ // misc. tests
+ try {
+ file = dir.resolve("foo.txt");
+ Files.createFile(file);
+ miscTests(dir);
+ } finally {
+ Files.delete(file);
+ }
+
+ } finally {
+ TestUtil.removeAll(dir);
+ }
+ }
+ }
diff --git a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java
index 1ef3a5b..23ef184 100644
--- a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java
+++ b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java
@@ -99,7 +99,7 @@
assertEquals(locale.toString(), "ja_JP_#u-ca-japanese", "Unexpected locale");
// Android changed: Android doesn't return the Japanese Imperial Calendar from getInstance.
- Calendar cal = java.util.Calendar.getJapanesImperialInstance(TimeZone.getDefault(), locale);
+ Calendar cal = Calendar.getJapaneseImperialInstance(TimeZone.getDefault(), locale);
assertEquals(cal.getCalendarType(), "japanese", "Unexpected calendar type");
JapaneseDate jDate = JapaneseChronology.INSTANCE.date(isoStartDate);
diff --git a/ojluni/src/test/java/time/test/java/util/TestFormatter.java b/ojluni/src/test/java/time/test/java/util/TestFormatter.java
index afd5fc4..05cb2e7 100644
--- a/ojluni/src/test/java/time/test/java/util/TestFormatter.java
+++ b/ojluni/src/test/java/time/test/java/util/TestFormatter.java
@@ -111,7 +111,7 @@
TimeZone tz = TimeZone.getTimeZone(zdt.getZone());
Calendar cal;
if (calLocale.getLanguage().equals("ja")) {
- cal = Calendar.getJapanesImperialInstance(tz, calLocale);
+ cal = Calendar.getJapaneseImperialInstance(tz, calLocale);
} else {
cal = Calendar.getInstance(tz, calLocale);
}
diff --git a/tzdata/update2/src/main/libcore/tzdata/update2/TimeZoneBundleInstaller.java b/tzdata/update2/src/main/libcore/tzdata/update2/TimeZoneDistroInstaller.java
similarity index 98%
rename from tzdata/update2/src/main/libcore/tzdata/update2/TimeZoneBundleInstaller.java
rename to tzdata/update2/src/main/libcore/tzdata/update2/TimeZoneDistroInstaller.java
index d08bb1d..1b56ebf 100644
--- a/tzdata/update2/src/main/libcore/tzdata/update2/TimeZoneBundleInstaller.java
+++ b/tzdata/update2/src/main/libcore/tzdata/update2/TimeZoneDistroInstaller.java
@@ -26,8 +26,7 @@
* A distro-validation / extraction class. Separate from the services code that uses it for easier
* testing. This class is not thread-safe: callers are expected to handle mutual exclusion.
*/
-// TODO(nfuller) Rename to TimeZoneDistroInstaller
-public final class TimeZoneBundleInstaller {
+public final class TimeZoneDistroInstaller {
/** {@link #installWithErrorCode(byte[])} result code: Success. */
public final static int INSTALL_SUCCESS = 0;
/** {@link #installWithErrorCode(byte[])} result code: Distro corrupt. */
@@ -49,7 +48,7 @@
private final File currentTzDataDir;
private final File workingDir;
- public TimeZoneBundleInstaller(String logTag, File systemTzDataFile, File installDir) {
+ public TimeZoneDistroInstaller(String logTag, File systemTzDataFile, File installDir) {
this.logTag = logTag;
this.systemTzDataFile = systemTzDataFile;
oldTzDataDir = new File(installDir, OLD_TZ_DATA_DIR_NAME);
diff --git a/tzdata/update2/src/test/libcore/tzdata/update2/TimeZoneBundleInstallerTest.java b/tzdata/update2/src/test/libcore/tzdata/update2/TimeZoneDistroInstallerTest.java
similarity index 92%
rename from tzdata/update2/src/test/libcore/tzdata/update2/TimeZoneBundleInstallerTest.java
rename to tzdata/update2/src/test/libcore/tzdata/update2/TimeZoneDistroInstallerTest.java
index 088e7cb..6ae0e56 100644
--- a/tzdata/update2/src/test/libcore/tzdata/update2/TimeZoneBundleInstallerTest.java
+++ b/tzdata/update2/src/test/libcore/tzdata/update2/TimeZoneDistroInstallerTest.java
@@ -34,9 +34,9 @@
import libcore.tzdata.update2.tools.TimeZoneDistroBuilder;
/**
- * Tests for {@link TimeZoneBundleInstaller}.
+ * Tests for {@link TimeZoneDistroInstaller}.
*/
-public class TimeZoneBundleInstallerTest extends TestCase {
+public class TimeZoneDistroInstallerTest extends TestCase {
// OLDER_RULES_VERSION < SYSTEM_RULES_VERSION < NEW_RULES_VERSION < NEWER_RULES_VERSION
private static final String OLDER_RULES_VERSION = "2030a";
@@ -44,7 +44,7 @@
private static final String NEW_RULES_VERSION = "2030c";
private static final String NEWER_RULES_VERSION = "2030d";
- private TimeZoneBundleInstaller installer;
+ private TimeZoneDistroInstaller installer;
private File tempDir;
private File testInstallDir;
private File testSystemTzDataDir;
@@ -61,8 +61,8 @@
byte[] systemTzDataBytes = createTzData(SYSTEM_RULES_VERSION);
createFile(testSystemTzDataFile, systemTzDataBytes);
- installer = new TimeZoneBundleInstaller(
- "TimeZoneBundleInstallerTest", testSystemTzDataFile, testInstallDir);
+ installer = new TimeZoneDistroInstaller(
+ "TimeZoneDistroInstallerTest", testSystemTzDataFile, testInstallDir);
}
private static File createDirectory(String prefix) throws Exception {
@@ -89,8 +89,8 @@
/** Tests the an update on a device will fail if the /system tzdata file cannot be found. */
public void testInstall_badSystemFile() throws Exception {
File doesNotExist = new File(testSystemTzDataDir, "doesNotExist");
- TimeZoneBundleInstaller brokenSystemInstaller = new TimeZoneBundleInstaller(
- "TimeZoneBundleInstallerTest", doesNotExist, testInstallDir);
+ TimeZoneDistroInstaller brokenSystemInstaller = new TimeZoneDistroInstaller(
+ "TimeZoneDistroInstallerTest", doesNotExist, testInstallDir);
TimeZoneDistro tzData = createValidTimeZoneDistro(NEW_RULES_VERSION, 1);
try {
@@ -106,7 +106,7 @@
TimeZoneDistro distro = createValidTimeZoneDistro(NEW_RULES_VERSION, 1);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_SUCCESS,
+ TimeZoneDistroInstaller.INSTALL_SUCCESS,
installer.installWithErrorCode(distro.getBytes()));
assertDistroInstalled(distro);
}
@@ -117,7 +117,7 @@
public void testInstall_successfulFirstUpdate_sameVersionAsSystem() throws Exception {
TimeZoneDistro distro = createValidTimeZoneDistro(SYSTEM_RULES_VERSION, 1);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_SUCCESS,
+ TimeZoneDistroInstaller.INSTALL_SUCCESS,
installer.installWithErrorCode(distro.getBytes()));
assertDistroInstalled(distro);
}
@@ -128,7 +128,7 @@
public void testInstall_unsuccessfulFirstUpdate_olderVersionThanSystem() throws Exception {
TimeZoneDistro distro = createValidTimeZoneDistro(OLDER_RULES_VERSION, 1);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_FAIL_RULES_TOO_OLD,
+ TimeZoneDistroInstaller.INSTALL_FAIL_RULES_TOO_OLD,
installer.installWithErrorCode(distro.getBytes()));
assertNoContentInstalled();
}
@@ -139,19 +139,19 @@
public void testInstall_successfulFollowOnUpdate_newerVersion() throws Exception {
TimeZoneDistro distro1 = createValidTimeZoneDistro(NEW_RULES_VERSION, 1);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_SUCCESS,
+ TimeZoneDistroInstaller.INSTALL_SUCCESS,
installer.installWithErrorCode(distro1.getBytes()));
assertDistroInstalled(distro1);
TimeZoneDistro distro2 = createValidTimeZoneDistro(NEW_RULES_VERSION, 2);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_SUCCESS,
+ TimeZoneDistroInstaller.INSTALL_SUCCESS,
installer.installWithErrorCode(distro2.getBytes()));
assertDistroInstalled(distro2);
TimeZoneDistro distro3 = createValidTimeZoneDistro(NEWER_RULES_VERSION, 1);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_SUCCESS,
+ TimeZoneDistroInstaller.INSTALL_SUCCESS,
installer.installWithErrorCode(distro3.getBytes()));
assertDistroInstalled(distro3);
}
@@ -163,13 +163,13 @@
public void testInstall_unsuccessfulFollowOnUpdate_olderVersion() throws Exception {
TimeZoneDistro distro1 = createValidTimeZoneDistro(NEW_RULES_VERSION, 2);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_SUCCESS,
+ TimeZoneDistroInstaller.INSTALL_SUCCESS,
installer.installWithErrorCode(distro1.getBytes()));
assertDistroInstalled(distro1);
TimeZoneDistro distro2 = createValidTimeZoneDistro(OLDER_RULES_VERSION, 1);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_FAIL_RULES_TOO_OLD,
+ TimeZoneDistroInstaller.INSTALL_FAIL_RULES_TOO_OLD,
installer.installWithErrorCode(distro2.getBytes()));
assertDistroInstalled(distro1);
}
@@ -178,7 +178,7 @@
public void testInstall_missingTzDataFile() throws Exception {
TimeZoneDistro installedDistro = createValidTimeZoneDistro(NEW_RULES_VERSION, 1);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_SUCCESS,
+ TimeZoneDistroInstaller.INSTALL_SUCCESS,
installer.installWithErrorCode(installedDistro.getBytes()));
assertDistroInstalled(installedDistro);
@@ -187,7 +187,7 @@
.clearTzDataForTests()
.buildUnvalidated();
assertEquals(
- TimeZoneBundleInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
+ TimeZoneDistroInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
installer.installWithErrorCode(incompleteDistro.getBytes()));
assertDistroInstalled(installedDistro);
}
@@ -196,7 +196,7 @@
public void testInstall_missingIcuFile() throws Exception {
TimeZoneDistro installedDistro = createValidTimeZoneDistro(NEW_RULES_VERSION, 1);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_SUCCESS,
+ TimeZoneDistroInstaller.INSTALL_SUCCESS,
installer.installWithErrorCode(installedDistro.getBytes()));
assertDistroInstalled(installedDistro);
@@ -205,7 +205,7 @@
.clearIcuDataForTests()
.buildUnvalidated();
assertEquals(
- TimeZoneBundleInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
+ TimeZoneDistroInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
installer.installWithErrorCode(incompleteDistro.getBytes()));
assertDistroInstalled(installedDistro);
}
@@ -220,7 +220,7 @@
TimeZoneDistro distro = createValidTimeZoneDistro(NEW_RULES_VERSION, 1);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_SUCCESS,
+ TimeZoneDistroInstaller.INSTALL_SUCCESS,
installer.installWithErrorCode(distro.getBytes()));
assertDistroInstalled(distro);
}
@@ -234,7 +234,7 @@
.clearVersionForTests()
.buildUnvalidated();
assertEquals(
- TimeZoneBundleInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
+ TimeZoneDistroInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
installer.installWithErrorCode(distro.getBytes()));
assertNoContentInstalled();
}
@@ -248,7 +248,7 @@
.replaceFormatVersionForTests(2, 1)
.buildUnvalidated();
assertEquals(
- TimeZoneBundleInstaller.INSTALL_FAIL_BAD_DISTRO_FORMAT_VERSION,
+ TimeZoneDistroInstaller.INSTALL_FAIL_BAD_DISTRO_FORMAT_VERSION,
installer.installWithErrorCode(distro.getBytes()));
assertNoContentInstalled();
}
@@ -265,7 +265,7 @@
TimeZoneDistro distro = createTimeZoneDistroWithVersionBytes(invalidFormatVersionBytes);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
+ TimeZoneDistroInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
installer.installWithErrorCode(distro.getBytes()));
assertNoContentInstalled();
}
@@ -281,7 +281,7 @@
TimeZoneDistro distro = createTimeZoneDistroWithVersionBytes(invalidRevisionBytes);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
+ TimeZoneDistroInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
installer.installWithErrorCode(distro.getBytes()));
assertNoContentInstalled();
}
@@ -297,7 +297,7 @@
TimeZoneDistro distro = createTimeZoneDistroWithVersionBytes(invalidRulesVersionBytes);
assertEquals(
- TimeZoneBundleInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
+ TimeZoneDistroInstaller.INSTALL_FAIL_BAD_DISTRO_STRUCTURE,
installer.installWithErrorCode(distro.getBytes()));
assertNoContentInstalled();
}