diff options
author | Paul Duffin <paulduffin@google.com> | 2015-02-27 10:51:44 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2015-05-29 15:36:23 +0100 |
commit | 5cab40b862c21656c2ace19596874eb3ffe1b649 (patch) | |
tree | 8f59555630f63a6e7916e4c1d31f5476a603a7ca /guava-tests | |
parent | 0c29232f9e0a18dc064d9f2859f7bff889729002 (diff) | |
download | guava-5cab40b862c21656c2ace19596874eb3ffe1b649.tar.gz |
Upgraded Guava to unmodified jdk5-backport-v17.0-post
This simply copies the Guava source for jdk5-backport-v17.0-post
straight from the github repository into this one.
See https://github.com/google/guava.git
Additional commits will be made which will allow this to compile
on Android.
BUG=19672715
Change-Id: If822daced0fc352f01bf9ecac1e994da08358f72
Diffstat (limited to 'guava-tests')
12 files changed, 52 insertions, 146 deletions
diff --git a/guava-tests/benchmark/com/google/common/primitives/UnsignedBytesBenchmark.java b/guava-tests/benchmark/com/google/common/primitives/UnsignedBytesBenchmark.java index 9b1cac270..19511fc10 100644 --- a/guava-tests/benchmark/com/google/common/primitives/UnsignedBytesBenchmark.java +++ b/guava-tests/benchmark/com/google/common/primitives/UnsignedBytesBenchmark.java @@ -36,6 +36,7 @@ public class UnsignedBytesBenchmark { private byte[] ba3; private byte[] ba4; private Comparator<byte[]> javaImpl; + private Comparator<byte[]> unsafeImpl; // 4, 8, 64, 1K, 1M, 1M (unaligned), 64M, 64M (unaligned) //@Param({"4", "8", "64", "1024", "1048576", "1048577", "6710884", "6710883"}) @@ -55,6 +56,8 @@ public class UnsignedBytesBenchmark { ba4[ba1.length - 1] = (byte) 42; javaImpl = UnsignedBytes.lexicographicalComparatorJavaImpl(); + unsafeImpl = + UnsignedBytes.LexicographicalComparatorHolder.UnsafeComparator.INSTANCE; } @Benchmark void longEqualJava(int reps) { @@ -65,6 +68,14 @@ public class UnsignedBytesBenchmark { } } + @Benchmark void longEqualUnsafe(int reps) { + for (int i = 0; i < reps; ++i) { + if (unsafeImpl.compare(ba1, ba2) != 0) { + throw new Error(); // deoptimization + } + } + } + @Benchmark void diffLastJava(int reps) { for (int i = 0; i < reps; ++i) { if (javaImpl.compare(ba3, ba4) == 0) { @@ -73,6 +84,14 @@ public class UnsignedBytesBenchmark { } } + @Benchmark void diffLastUnsafe(int reps) { + for (int i = 0; i < reps; ++i) { + if (unsafeImpl.compare(ba3, ba4) == 0) { + throw new Error(); // deoptimization + } + } + } + /* try { UnsignedBytesBenchmark bench = new UnsignedBytesBenchmark(); diff --git a/guava-tests/test/com/google/common/collect/ConstraintsTest.java b/guava-tests/test/com/google/common/collect/ConstraintsTest.java index 08a286651..cd24240df 100644 --- a/guava-tests/test/com/google/common/collect/ConstraintsTest.java +++ b/guava-tests/test/com/google/common/collect/ConstraintsTest.java @@ -20,8 +20,6 @@ import static java.util.Arrays.asList; import static org.truth0.Truth.ASSERT; import com.google.common.annotations.GwtCompatible; -import com.google.common.annotations.GwtIncompatible; -import com.google.common.testing.SerializableTester; import junit.framework.TestCase; @@ -41,7 +39,7 @@ import java.util.SortedSet; * @author Mike Bostock * @author Jared Levy */ -@GwtCompatible(emulated = true) +@GwtCompatible public class ConstraintsTest extends TestCase { private static final String TEST_ELEMENT = "test"; @@ -62,16 +60,6 @@ public class ConstraintsTest extends TestCase { } }; - public void testNotNull() { - Constraint<? super String> constraint = Constraints.notNull(); - assertSame(TEST_ELEMENT, constraint.checkElement(TEST_ELEMENT)); - try { - constraint.checkElement(null); - fail("NullPointerException expected"); - } catch (NullPointerException expected) {} - assertEquals("Not null", constraint.toString()); - } - public void testConstrainedCollectionLegal() { Collection<String> collection = Lists.newArrayList("foo", "bar"); Collection<String> constrained = Constraints.constrainedCollection( @@ -265,49 +253,6 @@ public class ConstraintsTest extends TestCase { ASSERT.that(list).has().exactly("foo", "bar").inOrder(); } - public void testConstrainedMultisetLegal() { - Multiset<String> multiset = HashMultiset.create(asList("foo", "bar")); - Multiset<String> constrained = Constraints.constrainedMultiset( - multiset, TEST_CONSTRAINT); - multiset.add(TEST_ELEMENT); - constrained.add("qux"); - constrained.addAll(asList("cat", "dog")); - constrained.add("cow", 2); - assertTrue(multiset.equals(constrained)); - assertTrue(constrained.equals(multiset)); - assertEquals(multiset.toString(), constrained.toString()); - assertEquals(multiset.hashCode(), constrained.hashCode()); - ASSERT.that(multiset).has().exactly( - "foo", "bar", TEST_ELEMENT, "qux", "cat", "dog", "cow", "cow"); - ASSERT.that(constrained).has().exactly( - "foo", "bar", TEST_ELEMENT, "qux", "cat", "dog", "cow", "cow"); - assertEquals(1, constrained.count("foo")); - assertEquals(1, constrained.remove("foo", 3)); - assertEquals(2, constrained.setCount("cow", 0)); - ASSERT.that(multiset).has().exactly("bar", TEST_ELEMENT, "qux", "cat", "dog"); - ASSERT.that(constrained).has().exactly("bar", TEST_ELEMENT, "qux", "cat", "dog"); - } - - public void testConstrainedMultisetIllegal() { - Multiset<String> multiset = HashMultiset.create(asList("foo", "bar")); - Multiset<String> constrained = Constraints.constrainedMultiset( - multiset, TEST_CONSTRAINT); - try { - constrained.add(TEST_ELEMENT); - fail("TestElementException expected"); - } catch (TestElementException expected) {} - try { - constrained.add(TEST_ELEMENT, 2); - fail("TestElementException expected"); - } catch (TestElementException expected) {} - try { - constrained.addAll(asList("baz", TEST_ELEMENT)); - fail("TestElementException expected"); - } catch (TestElementException expected) {} - ASSERT.that(constrained).has().exactly("foo", "bar"); - ASSERT.that(multiset).has().exactly("foo", "bar"); - } - public void testNefariousAddAll() { List<String> list = Lists.newArrayList("foo", "bar"); List<String> constrained = Constraints.constrainedList( @@ -345,10 +290,5 @@ public class ConstraintsTest extends TestCase { }; } - @GwtIncompatible("SerializableTester") - public void testSerialization() { - // TODO: Test serialization of constrained collections. - assertSame(Constraints.notNull(), - SerializableTester.reserialize(Constraints.notNull())); - } + // TODO: Test serialization of constrained collections. } diff --git a/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java b/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java index ee47a1bd4..cfcdff7bf 100644 --- a/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java +++ b/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java @@ -72,10 +72,10 @@ public class AbstractByteHasherTest extends TestCase { random.nextBytes(bytes); String s = new String(bytes, UTF_16LE.name()); // so all random strings are valid assertEquals( - new TestHasher().putString(s).hash(), + new TestHasher().putUnencodedChars(s).hash(), new TestHasher().putBytes(s.getBytes(UTF_16LE.name())).hash()); assertEquals( - new TestHasher().putString(s).hash(), + new TestHasher().putUnencodedChars(s).hash(), new TestHasher().putString(s, UTF_16LE).hash()); } } diff --git a/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java b/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java index e8a262ef2..a26be17dc 100644 --- a/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java +++ b/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java @@ -142,11 +142,6 @@ public class AbstractNonStreamingHashFunctionTest extends TestCase { } @Override - public HashCode hashString(CharSequence input) { - throw new UnsupportedOperationException(); - } - - @Override public HashCode hashString(CharSequence input, Charset charset) { throw new UnsupportedOperationException(); } diff --git a/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java b/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java index d4f2d2ec2..75eb13f37 100644 --- a/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java +++ b/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java @@ -93,10 +93,10 @@ public class AbstractStreamingHasherTest extends TestCase { random.nextBytes(bytes); String s = new String(bytes, UTF_16LE.name()); // so all random strings are valid assertEquals( - new Sink(4).putString(s).hash(), + new Sink(4).putUnencodedChars(s).hash(), new Sink(4).putBytes(s.getBytes(UTF_16LE.name())).hash()); assertEquals( - new Sink(4).putString(s).hash(), + new Sink(4).putUnencodedChars(s).hash(), new Sink(4).putString(s, UTF_16LE).hash()); } } @@ -265,11 +265,6 @@ public class AbstractStreamingHasherTest extends TestCase { } @Override - public HashCode hashString(CharSequence input) { - throw new UnsupportedOperationException(); - } - - @Override public HashCode hashString(CharSequence input, Charset charset) { throw new UnsupportedOperationException(); } diff --git a/guava-tests/test/com/google/common/hash/HashCodeTest.java b/guava-tests/test/com/google/common/hash/HashCodeTest.java index 121d983a4..196ef0267 100644 --- a/guava-tests/test/com/google/common/hash/HashCodeTest.java +++ b/guava-tests/test/com/google/common/hash/HashCodeTest.java @@ -18,6 +18,7 @@ package com.google.common.hash; import static com.google.common.io.BaseEncoding.base16; +import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import com.google.common.io.BaseEncoding; import com.google.common.jdk5backport.Arrays; @@ -168,7 +169,7 @@ public class HashCodeTest extends TestCase { } public void testRoundTripHashCodeUsingBaseEncoding() { - HashCode hash1 = Hashing.sha1().hashString("foo"); + HashCode hash1 = Hashing.sha1().hashString("foo", Charsets.US_ASCII); HashCode hash2 = HashCode.fromBytes(BaseEncoding.base16().lowerCase().decode(hash1.toString())); assertEquals(hash1, hash2); @@ -201,18 +202,18 @@ public class HashCodeTest extends TestCase { } public void testRoundTripHashCodeUsingFromString() { - HashCode hash1 = Hashing.sha1().hashString("foo"); + HashCode hash1 = Hashing.sha1().hashString("foo", Charsets.US_ASCII); HashCode hash2 = HashCode.fromString(hash1.toString()); assertEquals(hash1, hash2); } public void testRoundTrip() { for (ExpectedHashCode expected : expectedHashCodes) { - String string = HashCodes.fromBytes(expected.bytes).toString(); + String string = HashCode.fromBytes(expected.bytes).toString(); assertEquals(expected.toString, string); assertEquals( expected.toString, - HashCodes.fromBytes( + HashCode.fromBytes( BaseEncoding.base16().lowerCase().decode(string)).toString()); } } @@ -226,7 +227,7 @@ public class HashCodeTest extends TestCase { } public void testFromStringFailsWithUpperCaseString() { - String string = Hashing.sha1().hashString("foo").toString().toUpperCase(); + String string = Hashing.sha1().hashString("foo", Charsets.US_ASCII).toString().toUpperCase(); try { HashCode.fromString(string); fail(); @@ -258,17 +259,17 @@ public class HashCodeTest extends TestCase { public void testIntWriteBytesTo() { byte[] dest = new byte[4]; - HashCodes.fromInt(42).writeBytesTo(dest, 0, 4); + HashCode.fromInt(42).writeBytesTo(dest, 0, 4); assertTrue(Arrays.equals( - HashCodes.fromInt(42).asBytes(), + HashCode.fromInt(42).asBytes(), dest)); } public void testLongWriteBytesTo() { byte[] dest = new byte[8]; - HashCodes.fromLong(42).writeBytesTo(dest, 0, 8); + HashCode.fromLong(42).writeBytesTo(dest, 0, 8); assertTrue(Arrays.equals( - HashCodes.fromLong(42).asBytes(), + HashCode.fromLong(42).asBytes(), dest)); } diff --git a/guava-tests/test/com/google/common/hash/HashingTest.java b/guava-tests/test/com/google/common/hash/HashingTest.java index 2f369f207..89a239755 100644 --- a/guava-tests/test/com/google/common/hash/HashingTest.java +++ b/guava-tests/test/com/google/common/hash/HashingTest.java @@ -150,13 +150,6 @@ public class HashingTest extends TestCase { HashTestUtils.assertInvariants(Hashing.goodFastHash(256)); } - public void testPadToLong() { - assertEquals(0x1111111111111111L, Hashing.padToLong(HashCodes.fromLong(0x1111111111111111L))); - assertEquals(0x9999999999999999L, Hashing.padToLong(HashCodes.fromLong(0x9999999999999999L))); - assertEquals(0x0000000011111111L, Hashing.padToLong(HashCodes.fromInt(0x11111111))); - assertEquals(0x0000000099999999L, Hashing.padToLong(HashCodes.fromInt(0x99999999))); - } - public void testConsistentHash_correctness() { long[] interestingValues = { -1, 0, 1, 2, Long.MAX_VALUE, Long.MIN_VALUE }; for (long h : interestingValues) { diff --git a/guava-tests/test/com/google/common/io/ByteStreamsTest.java b/guava-tests/test/com/google/common/io/ByteStreamsTest.java index 96a4ab09f..fc5b99d7d 100644 --- a/guava-tests/test/com/google/common/io/ByteStreamsTest.java +++ b/guava-tests/test/com/google/common/io/ByteStreamsTest.java @@ -31,8 +31,6 @@ import java.io.UnsupportedEncodingException; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; -import java.util.zip.CRC32; -import java.util.zip.Checksum; /** * Unit test for {@link ByteStreams}. @@ -386,21 +384,6 @@ public class ByteStreamsTest extends IoTestCase { assertEquals(bytes, out.toByteArray()); } - public void testChecksum() throws IOException { - InputSupplier<ByteArrayInputStream> asciiBytes = - ByteStreams.newInputStreamSupplier(ASCII.getBytes(Charsets.US_ASCII.name())); - InputSupplier<ByteArrayInputStream> i18nBytes = - ByteStreams.newInputStreamSupplier(I18N.getBytes(Charsets.UTF_8.name())); - - Checksum checksum = new CRC32(); - assertEquals(0L, checksum.getValue()); - assertEquals(3145994718L, ByteStreams.getChecksum(asciiBytes, checksum)); - assertEquals(0L, checksum.getValue()); - assertEquals(3145994718L, ByteStreams.getChecksum(asciiBytes, checksum)); - assertEquals(1138302340L, ByteStreams.getChecksum(i18nBytes, checksum)); - assertEquals(0L, checksum.getValue()); - } - public void testNewDataOutput_BAOS() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayDataOutput out = ByteStreams.newDataOutput(baos); diff --git a/guava-tests/test/com/google/common/io/CloseablesTest.java b/guava-tests/test/com/google/common/io/CloseablesTest.java index a4cd1bb0c..e564e3cd6 100644 --- a/guava-tests/test/com/google/common/io/CloseablesTest.java +++ b/guava-tests/test/com/google/common/io/CloseablesTest.java @@ -67,14 +67,6 @@ public class CloseablesTest extends TestCase { doClose(mockCloseable, false); } - public void testCloseQuietly_closeableWithEatenException() - throws IOException { - // make sure that no exception is thrown by CloseQuietly when the mock does - // throw an exception on close - setupCloseable(true); - Closeables.closeQuietly(mockCloseable); - } - public void testCloseQuietly_inputStreamWithEatenException() throws IOException { TestInputStream in = new TestInputStream( new ByteArrayInputStream(new byte[1]), TestOption.CLOSE_THROWS); @@ -91,7 +83,6 @@ public class CloseablesTest extends TestCase { public void testCloseNull() throws IOException { Closeables.close(null, true); Closeables.close(null, false); - Closeables.closeQuietly((Closeable) null); } public void testCloseQuietlyNull_inputStream() { diff --git a/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java b/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java index c74e8a215..575eb7e73 100644 --- a/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java +++ b/guava-tests/test/com/google/common/primitives/UnsignedBytesTest.java @@ -226,9 +226,9 @@ public class UnsignedBytesTest extends TestCase { public void testLexicographicalComparatorDefaultChoice() { Comparator<byte[]> defaultComparator = UnsignedBytes.lexicographicalComparator(); - Comparator<byte[]> pureJavaComparator = - UnsignedBytes.LexicographicalComparatorHolder.PureJavaComparator.INSTANCE; - assertSame(defaultComparator, pureJavaComparator); + Comparator<byte[]> unsafeComparator = + UnsignedBytes.LexicographicalComparatorHolder.UnsafeComparator.INSTANCE; + assertSame(defaultComparator, unsafeComparator); } public void testLexicographicalComparator() { diff --git a/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java b/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java index 147ed644e..1fc87566f 100644 --- a/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/ServiceManagerTest.java @@ -433,22 +433,6 @@ public class ServiceManagerTest extends TestCase { return delegate.stopAsync(); } - @Override public final ListenableFuture<State> start() { - return delegate.start(); - } - - @Override public final ListenableFuture<State> stop() { - return delegate.stop(); - } - - @Override public State startAndWait() { - return delegate.startAndWait(); - } - - @Override public State stopAndWait() { - return delegate.stopAndWait(); - } - @Override public final void awaitRunning() { delegate.awaitRunning(); } diff --git a/guava-tests/test/com/google/common/xml/XmlEscapersTest.java b/guava-tests/test/com/google/common/xml/XmlEscapersTest.java index 50529629d..148a71907 100644 --- a/guava-tests/test/com/google/common/xml/XmlEscapersTest.java +++ b/guava-tests/test/com/google/common/xml/XmlEscapersTest.java @@ -82,8 +82,8 @@ public class XmlEscapersTest extends TestCase { assertUnescaped(xmlEscaper, ch); } } else { - // and everything else is replaced with FFFD. - assertEscaping(xmlEscaper, "\uFFFD", ch); + // and everything else is removed. + assertEscaping(xmlEscaper, "", ch); } } @@ -109,13 +109,18 @@ public class XmlEscapersTest extends TestCase { } } - // Test that 0xFFFE and 0xFFFF are replaced with 0xFFFD - assertEscaping(xmlEscaper, "\uFFFD", '\uFFFE'); - assertEscaping(xmlEscaper, "\uFFFD", '\uFFFF'); + // TODO(user): Change once this escaper forbids \uFFFE and \uFFFF. - assertEquals("0xFFFE is forbidden and should be replaced during escaping", - "[\uFFFD]", xmlEscaper.escape("[\ufffe]")); - assertEquals("0xFFFF is forbidden and should be replaced during escaping", - "[\uFFFD]", xmlEscaper.escape("[\uffff]")); + assertUnescaped(xmlEscaper, '\uFFFE'); + assertUnescaped(xmlEscaper, '\uFFFF'); + + // Test that 0xFFFE and 0xFFFF are removed + // assertEscaping(xmlEscaper, "", '\uFFFE'); + // assertEscaping(xmlEscaper, "", '\uFFFF'); + + // assertEquals("0xFFFE is forbidden and should be removed during escaping", + // "[]", XmlEscapers.xmlEscaper().escape("[\ufffe]")); + // assertEquals("0xFFFF is forbidden and should be removed during escaping", + // "[]", XmlEscapers.xmlEscaper().escape("[\uffff]")); } } |