diff options
9 files changed, 133 insertions, 22 deletions
diff --git a/api/current.txt b/api/current.txt index a61a7234788..b23f9d24a14 100644 --- a/api/current.txt +++ b/api/current.txt @@ -2880,7 +2880,7 @@ package java.lang { } public enum Character.UnicodeScript { - method @NonNull public static java.lang.Character.UnicodeScript forName(@NonNull String); + method @NonNull public static final java.lang.Character.UnicodeScript forName(@NonNull String); method @NonNull public static java.lang.Character.UnicodeScript of(int); enum_constant public static final java.lang.Character.UnicodeScript ADLAM; enum_constant public static final java.lang.Character.UnicodeScript AHOM; @@ -12099,6 +12099,7 @@ package java.time.chrono { method public static java.time.chrono.HijrahDate of(int, int, int); method public java.time.chrono.HijrahDate plus(java.time.temporal.TemporalAmount); method public java.time.chrono.HijrahDate plus(long, java.time.temporal.TemporalUnit); + method public String toString(); method public java.time.chrono.ChronoPeriod until(java.time.chrono.ChronoLocalDate); method public long until(java.time.temporal.Temporal, java.time.temporal.TemporalUnit); method public java.time.chrono.HijrahDate with(java.time.temporal.TemporalField, long); @@ -12184,6 +12185,7 @@ package java.time.chrono { method public static java.time.chrono.JapaneseDate of(int, int, int); method public java.time.chrono.JapaneseDate plus(java.time.temporal.TemporalAmount); method public java.time.chrono.JapaneseDate plus(long, java.time.temporal.TemporalUnit); + method public String toString(); method public java.time.chrono.ChronoPeriod until(java.time.chrono.ChronoLocalDate); method public long until(java.time.temporal.Temporal, java.time.temporal.TemporalUnit); method public java.time.chrono.JapaneseDate with(java.time.temporal.TemporalField, long); @@ -12241,6 +12243,7 @@ package java.time.chrono { method public static java.time.chrono.MinguoDate of(int, int, int); method public java.time.chrono.MinguoDate plus(java.time.temporal.TemporalAmount); method public java.time.chrono.MinguoDate plus(long, java.time.temporal.TemporalUnit); + method public String toString(); method public java.time.chrono.ChronoPeriod until(java.time.chrono.ChronoLocalDate); method public long until(java.time.temporal.Temporal, java.time.temporal.TemporalUnit); method public java.time.chrono.MinguoDate with(java.time.temporal.TemporalField, long); @@ -12293,6 +12296,7 @@ package java.time.chrono { method public static java.time.chrono.ThaiBuddhistDate of(int, int, int); method public java.time.chrono.ThaiBuddhistDate plus(java.time.temporal.TemporalAmount); method public java.time.chrono.ThaiBuddhistDate plus(long, java.time.temporal.TemporalUnit); + method public String toString(); method public java.time.chrono.ChronoPeriod until(java.time.chrono.ChronoLocalDate); method public long until(java.time.temporal.Temporal, java.time.temporal.TemporalUnit); method public java.time.chrono.ThaiBuddhistDate with(java.time.temporal.TemporalField, long); diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatTest.java index aca5247e8b6..d0f7430df01 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/DecimalFormatTest.java @@ -2053,7 +2053,8 @@ public class DecimalFormatTest extends TestCase { char current; // BigInteger. - iterator = new DecimalFormat().formatToCharacterIterator(new BigInteger("123456789")); + iterator = NumberFormat.getInstance(Locale.US) + .formatToCharacterIterator(new BigInteger("123456789")); runStarts = new int[] { 0, 0, 0, 3, 4, 4, 4, 7, 8, 8, 8 }; runLimits = new int[] { 3, 3, 3, 4, 7, 7, 7, 8, 11, 11, 11 }; result = "123,456,789"; @@ -2068,7 +2069,7 @@ public class DecimalFormatTest extends TestCase { assertEquals(11, iterator.getEndIndex()); // For BigDecimal with multiplier test. - DecimalFormat df = new DecimalFormat(); + DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.US); df.setMultiplier(10); iterator = df.formatToCharacterIterator(new BigDecimal("12345678901234567890")); result = "123,456,789,012,345,678,900"; @@ -2079,7 +2080,7 @@ public class DecimalFormatTest extends TestCase { } // For BigDecimal with multiplier test. - df = new DecimalFormat(); + df = (DecimalFormat) NumberFormat.getInstance(Locale.US); df.setMultiplier(-1); df.setMaximumFractionDigits(20); iterator = df.formatToCharacterIterator(new BigDecimal("1.23456789012345678901")); @@ -2090,7 +2091,8 @@ public class DecimalFormatTest extends TestCase { current = iterator.next(); } - iterator = new DecimalFormat().formatToCharacterIterator(new BigDecimal("1.23456789E301")); + iterator = NumberFormat.getInstance(Locale.US) + .formatToCharacterIterator(new BigDecimal("1.23456789E301")); runStarts = new int[] { 0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11, 11, 11, 14 }; runLimits = new int[] { 2, 2, 3, 6, 6, 6, 7, 10, 10, 10, 11, 14, 14, 14, 15 }; result = "12,345,678,900,"; // 000,000,000,000.... @@ -2104,7 +2106,8 @@ public class DecimalFormatTest extends TestCase { assertEquals(0, iterator.getBeginIndex()); assertEquals(402, iterator.getEndIndex()); - iterator = new DecimalFormat().formatToCharacterIterator(new BigDecimal("1.2345678E4")); + iterator = NumberFormat.getInstance(Locale.US) + .formatToCharacterIterator(new BigDecimal("1.2345678E4")); runStarts = new int[] { 0, 0, 2, 3, 3, 3, 6, 7, 7, 7 }; runLimits = new int[] { 2, 2, 3, 6, 6, 6, 7, 10, 10, 10 }; result = "12,345.678"; @@ -2128,7 +2131,8 @@ public class DecimalFormatTest extends TestCase { Number number = new BigDecimal("1.23456789E1234"); assertEquals("1.23456789E+1234", number.toString()); - iterator = new DecimalFormat().formatToCharacterIterator(number); + iterator = NumberFormat.getInstance(Locale.US) + .formatToCharacterIterator(number); runStarts = new int[] { 0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11, 11, 11, 14 }; runLimits = new int[] { 2, 2, 3, 6, 6, 6, 7, 10, 10, 10, 11, 14, 14, 14, 15 }; result = "12,345,678,900,"; // 000,000,000,000.... diff --git a/luni/src/main/java/libcore/net/NetworkSecurityPolicy.java b/luni/src/main/java/libcore/net/NetworkSecurityPolicy.java index aa7cde08301..f161747568d 100644 --- a/luni/src/main/java/libcore/net/NetworkSecurityPolicy.java +++ b/luni/src/main/java/libcore/net/NetworkSecurityPolicy.java @@ -48,7 +48,6 @@ public abstract class NetworkSecurityPolicy { * @hide */ @SystemApi(client = MODULE_LIBRARIES) - @libcore.api.IntraCoreApi public NetworkSecurityPolicy() { } diff --git a/luni/src/test/java/libcore/java/net/SocketTest.java b/luni/src/test/java/libcore/java/net/SocketTest.java index 8bb21eebd52..dca55a6f0c5 100644 --- a/luni/src/test/java/libcore/java/net/SocketTest.java +++ b/luni/src/test/java/libcore/java/net/SocketTest.java @@ -16,6 +16,23 @@ package libcore.java.net; +import static android.system.OsConstants.AF_INET; +import static android.system.OsConstants.AF_INET6; +import static android.system.OsConstants.SOCK_DGRAM; + +import static java.util.stream.Collectors.joining; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import android.system.ErrnoException; +import android.system.Os; + import java.io.FileDescriptor; import java.io.IOException; import java.io.InputStream; @@ -48,11 +65,16 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import libcore.junit.junit3.TestCaseWithRules; import libcore.junit.util.ResourceLeakageDetector; + +import org.junit.Ignore; import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.junit.rules.TestRule; - -public class SocketTest extends TestCaseWithRules { +@RunWith(JUnit4.class) +public class SocketTest { @Rule public TestRule resourceLeakageDetectorRule = ResourceLeakageDetector.getRule(); @@ -72,6 +94,7 @@ public class SocketTest extends TestCaseWithRules { private static final int INET_ECN_MASK = 0x3; // See http://b/2980559. + @Test public void test_close() throws Exception { Socket s = new Socket(); s.close(); @@ -84,6 +107,7 @@ public class SocketTest extends TestCaseWithRules { * This means they give incorrect results on closed sockets (as well * as requiring an unnecessary call into native code). */ + @Test public void test_getLocalAddress_after_close() throws Exception { Socket s = new Socket(); try { @@ -104,6 +128,7 @@ public class SocketTest extends TestCaseWithRules { } // http://code.google.com/p/android/issues/detail?id=7935 + @Test public void test_newSocket_connection_refused() throws Exception { try { new Socket("localhost", 80); @@ -114,6 +139,7 @@ public class SocketTest extends TestCaseWithRules { // http://code.google.com/p/android/issues/detail?id=3123 // http://code.google.com/p/android/issues/detail?id=1933 + @Test public void test_socketLocalAndRemoteAddresses() throws Exception { checkSocketLocalAndRemoteAddresses(false); checkSocketLocalAndRemoteAddresses(true); @@ -247,6 +273,7 @@ public class SocketTest extends TestCaseWithRules { // SocketOptions.setOption has weird behavior for setSoLinger/SO_LINGER. // This test ensures we do what the RI does. + @Test public void test_SocketOptions_setOption() throws Exception { MySocketImpl impl = new MySocketImpl(); Socket s = new MySocket(impl); @@ -295,6 +322,7 @@ public class SocketTest extends TestCaseWithRules { assertEquals(sockImpl.value, value); } + @Test public void test_setTrafficClass() throws Exception { try (Socket s = new Socket()) { for (int i = 0; i <= 255; ++i) { @@ -310,6 +338,7 @@ public class SocketTest extends TestCaseWithRules { } } + @Test public void testReadAfterClose() throws Exception { MockServer server = new MockServer(); server.enqueue(new byte[]{5, 3}, 0); @@ -332,6 +361,7 @@ public class SocketTest extends TestCaseWithRules { server.shutdown(); } + @Test public void testWriteAfterClose() throws Exception { MockServer server = new MockServer(); server.enqueue(new byte[0], 3); @@ -352,6 +382,7 @@ public class SocketTest extends TestCaseWithRules { } // http://b/5534202 + @Test public void testAvailable() throws Exception { for (int i = 0; i < 100; i++) { assertAvailableReturnsZeroAfterSocketReadsAllData(); @@ -389,6 +420,7 @@ public class SocketTest extends TestCaseWithRules { serverSocket.close(); } + @Test public void testInitialState() throws Exception { Socket s = new Socket(); try { @@ -408,6 +440,7 @@ public class SocketTest extends TestCaseWithRules { } } + @Test public void testStateAfterClose() throws Exception { Socket s = new Socket(); s.bind(new InetSocketAddress(Inet4Address.getLocalHost(), 0)); @@ -425,6 +458,7 @@ public class SocketTest extends TestCaseWithRules { assertEquals(boundAddress.getPort(), localAddressAfterClose.getPort()); } + @Test public void testCloseDuringConnect() throws Exception { // This address is reserved for documentation: should never be reachable and therefore // is expected to produce block behavior when attempting to connect(). @@ -481,6 +515,7 @@ public class SocketTest extends TestCaseWithRules { } // http://b/29092095 + @Test public void testSocketWithProxySet() throws Exception { ProxySelector ps = ProxySelector.getDefault(); try { @@ -508,6 +543,7 @@ public class SocketTest extends TestCaseWithRules { // b/25805791 + b/26470377 + @Test public void testFileDescriptorStaysSame() throws Exception { // SocketImplementation FileDescriptor object shouldn't change after calling // bind (and many other methods). @@ -571,6 +607,7 @@ public class SocketTest extends TestCaseWithRules { } // b/26354315 + @Test public void testDoNotCallCloseFromSocketCtor() { // Original openJdk7 Socket implementation may call Socket#close() inside a constructor. // In this case, classes that extend Socket wont be fully constructed when they @@ -635,6 +672,8 @@ public class SocketTest extends TestCaseWithRules { } // b/30007735 + @Ignore("b/292238663") + @Test public void testSocketTestAllAddresses() throws Exception { checkLoopbackHost(); diff --git a/luni/src/test/java/libcore/java/nio/CharBufferTest.java b/luni/src/test/java/libcore/java/nio/CharBufferTest.java index 26e57783655..4b90444135f 100644 --- a/luni/src/test/java/libcore/java/nio/CharBufferTest.java +++ b/luni/src/test/java/libcore/java/nio/CharBufferTest.java @@ -54,4 +54,12 @@ public class CharBufferTest extends TestCase { assertEquals((int) low, cb.codePoints().toArray()[1]); // Unmatched surrogate. assertEquals((int) '0', cb.codePoints().toArray()[2]); } + + public void testEmpty() { + String s = "Hello\n\tworld"; + CharBuffer cb = CharBuffer.allocate(0); + assertTrue(cb.isEmpty()); + cb = cb.allocate(32).append(s); + assertFalse(cb.isEmpty()); + } } diff --git a/luni/src/test/java/libcore/java/nio/channels/MembershipKeyTest.java b/luni/src/test/java/libcore/java/nio/channels/MembershipKeyTest.java index 427789d48f4..42c15600222 100644 --- a/luni/src/test/java/libcore/java/nio/channels/MembershipKeyTest.java +++ b/luni/src/test/java/libcore/java/nio/channels/MembershipKeyTest.java @@ -33,24 +33,25 @@ import java.nio.channels.MembershipKey; public class MembershipKeyTest extends TestCase { - private MembershipKey key; - private final int PORT = 5000; private final String TEST_MESSAGE = "hello"; + private static final InetAddress MULTICAST_ADDRESS = getMulticastAddress(); + private static final NetworkInterface NETWORK_INTERFACE = getNetworkInterface(); + + private MembershipKey key; + private int port = -1; private DatagramChannel client; - private InetAddress sourceAddress = Inet4Address.LOOPBACK; - private final static InetAddress MULTICAST_ADDRESS = getMulticastAddress(); - private final static NetworkInterface NETWORK_INTERFACE = getNetworkInterface(); + private final InetAddress sourceAddress = Inet4Address.LOOPBACK; private void init(boolean withSource) throws Exception { client = DatagramChannel.open(StandardProtocolFamily.INET) - .bind(new InetSocketAddress(Inet4Address.ANY, PORT)); + .bind(new InetSocketAddress(Inet4Address.ANY, 0)); client.configureBlocking(false); - if (withSource) { key = client.join(MULTICAST_ADDRESS, NETWORK_INTERFACE, sourceAddress); } else { key = client.join(MULTICAST_ADDRESS, NETWORK_INTERFACE); } + port = client.socket().getLocalPort(); } @Override @@ -107,7 +108,7 @@ public class MembershipKeyTest extends TestCase { assertEquals(TEST_MESSAGE.length(), dc .bind(new InetSocketAddress(Inet4Address.LOOPBACK, 0)) .send(ByteBuffer.wrap(TEST_MESSAGE.getBytes()), - new InetSocketAddress(MULTICAST_ADDRESS, PORT))); + new InetSocketAddress(MULTICAST_ADDRESS, port))); } ByteBuffer buffer = ByteBuffer.allocate(1048); @@ -173,7 +174,7 @@ public class MembershipKeyTest extends TestCase { assertEquals(TEST_MESSAGE.length(), dc .bind(new InetSocketAddress(Inet4Address.LOOPBACK, 0)) .send(ByteBuffer.wrap(TEST_MESSAGE.getBytes()), - new InetSocketAddress(MULTICAST_ADDRESS, PORT))); + new InetSocketAddress(MULTICAST_ADDRESS, port))); } ByteBuffer buffer = ByteBuffer.allocate(1048); @@ -223,14 +224,14 @@ public class MembershipKeyTest extends TestCase { .bind(new InetSocketAddress(Inet4Address.LOOPBACK, 0)) .setOption(StandardSocketOptions.IP_MULTICAST_LOOP, true /* enable loop */) .send(ByteBuffer.wrap(TEST_MESSAGE.getBytes()), - new InetSocketAddress(MULTICAST_ADDRESS, PORT))); + new InetSocketAddress(MULTICAST_ADDRESS, port))); } ByteBuffer buffer = ByteBuffer.allocate(1048); client.receive(buffer); buffer.flip(); int limits = buffer.limit(); - byte bytes[] = new byte[limits]; + byte[] bytes = new byte[limits]; buffer.get(bytes, 0, limits); String receivedMessage = new String(bytes); assertEquals(TEST_MESSAGE, receivedMessage); diff --git a/luni/src/test/java/libcore/java/time/format/DateTimeFormatterBuilderTest.java b/luni/src/test/java/libcore/java/time/format/DateTimeFormatterBuilderTest.java index 215f4837fac..653ca937b57 100644 --- a/luni/src/test/java/libcore/java/time/format/DateTimeFormatterBuilderTest.java +++ b/luni/src/test/java/libcore/java/time/format/DateTimeFormatterBuilderTest.java @@ -25,8 +25,10 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; +import java.time.format.TextStyle; import java.time.temporal.TemporalQueries; import java.util.Locale; +import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -89,4 +91,29 @@ public class DateTimeFormatterBuilderTest { assertEquals(ZoneOffset.ofHours(1), formatter.parse("+01:00").query(TemporalQueries.zoneId())); } + + @Test + public void test_appendGenericZoneText() { + DateTimeFormatter formatter = new DateTimeFormatterBuilder() + .appendGenericZoneText(TextStyle.FULL) + .toFormatter(Locale.US); + + assertEquals("Pacific Time", formatter.format( + ZonedDateTime.now(ZoneId.of("America/Los_Angeles")))); + + formatter = new DateTimeFormatterBuilder() + .appendGenericZoneText(TextStyle.SHORT) + .toFormatter(Locale.US); + + assertEquals("PT", formatter.format( + ZonedDateTime.now(ZoneId.of("America/Los_Angeles")))); + + formatter = new DateTimeFormatterBuilder() + .appendGenericZoneText(TextStyle.FULL, Set.of(ZoneId.of("America/Los_Angeles"))) + .toFormatter(Locale.US); + + // "America/Los_Angeles" is expected because the zone is in the preferred set. + assertEquals(ZoneId.of("America/Los_Angeles"), + formatter.parse("Pacific Time").query(TemporalQueries.zoneId())); + } } diff --git a/mmodules/intracoreapi/api/intra/current.txt b/mmodules/intracoreapi/api/intra/current.txt index ca1b6748768..003c067cfb7 100644 --- a/mmodules/intracoreapi/api/intra/current.txt +++ b/mmodules/intracoreapi/api/intra/current.txt @@ -127,7 +127,6 @@ package libcore.io { package libcore.net { @libcore.api.IntraCoreApi public abstract class NetworkSecurityPolicy { - ctor @libcore.api.IntraCoreApi public NetworkSecurityPolicy(); method @libcore.api.IntraCoreApi public static libcore.net.NetworkSecurityPolicy getInstance(); method @libcore.api.IntraCoreApi public abstract boolean isCertificateTransparencyVerificationRequired(String); } diff --git a/ojluni/src/test/java/nio/file/Path/PathOps.java b/ojluni/src/test/java/nio/file/Path/PathOps.java index 6c262231547..b2daa7787e6 100644 --- a/ojluni/src/test/java/nio/file/Path/PathOps.java +++ b/ojluni/src/test/java/nio/file/Path/PathOps.java @@ -27,6 +27,7 @@ */ package test.java.nio.file.Path; +import java.net.URI; import java.nio.file.FileSystems; import java.nio.file.InvalidPathException; import java.nio.file.Path; @@ -47,6 +48,14 @@ public class PathOps { } } + private PathOps(URI uri) { + try { + path = Path.of(uri); + } catch (Exception x) { + exc = x; + } + } + void checkPath() { if (path == null) { throw new InternalError("path is null"); @@ -480,6 +489,27 @@ public class PathOps { .name("bar"); } + // BEGIN Android-added: Tests for of(). + static PathOps testOf(String first) { + try { + return new PathOps(new URI (first)); + } catch (Exception e) { + return null; + } + } + + @Test + public static void doOfTests() { + Path cwd = Paths.get("").toAbsolutePath(); + + // construction + testOf("file:///foo/") + .string("/foo"); + testOf("file:///foo/bar/gus/") + .string("/foo/bar/gus"); + } + // END Android-added: Tests for of(). + @Test public static void npes() { try { |