Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertThrows;

import com.google.common.annotations.J2ktIncompatible;
import java.io.ByteArrayOutputStream;
import java.util.Random;
import junit.framework.TestCase;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void testChar() {
hasher.assertBytes(new byte[] {1, 2});
}

@J2ktIncompatible // no UTF_16LE support
public void testString() {
Random random = new Random();
for (int i = 0; i < 100; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.common.hash;

import com.google.common.annotations.J2ktIncompatible;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.HashTestUtils.RandomHasherAction;
import java.io.ByteArrayOutputStream;
Expand All @@ -34,6 +35,7 @@ public class AbstractNonStreamingHashFunctionTest extends TestCase {
* and checks that their results are identical, no matter which newHasher version we used.
*/
public void testExhaustive() {
// TODO: b/484953702 - Split test so we can avoid StreamingVersion under J2KT.
List<Hasher> hashers =
ImmutableList.of(
new StreamingVersion().newHasher(),
Expand Down Expand Up @@ -93,6 +95,7 @@ private static void assertPutString(char[] chars) {
assertEquals(h1.hash(), h2.hash());
}

@J2ktIncompatible // AbstractStreamingHasher
static class StreamingVersion extends AbstractHashFunction {
@Override
public int bits() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static java.util.Collections.singleton;
import static org.junit.Assert.assertThrows;

import com.google.common.annotations.J2ktIncompatible;
import com.google.common.collect.Iterables;
import com.google.common.hash.HashTestUtils.RandomHasherAction;
import java.io.ByteArrayOutputStream;
Expand All @@ -38,6 +39,9 @@
*
* @author Dimitris Andreou
*/
// All tests use Sink, which uses the currently J2KT-incompatible AbstractStreamingHasher
// (Plus, testString in particular requires UTF_16LE support.)
@J2ktIncompatible
@NullUnmarked
public class AbstractStreamingHasherTest extends TestCase {
public void testBytes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertThrows;

import com.google.common.annotations.J2ktIncompatible;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableSet;
import com.google.common.hash.BloomFilterStrategies.LockFreeBitArray;
Expand All @@ -54,6 +55,7 @@
* @author Dimitris Andreou
*/
@NullUnmarked
@J2ktIncompatible
public class BloomFilterTest extends TestCase {
private static final int NUM_PUTS = 100_000;
private static final ThreadLocal<Random> random =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.google.common.hash.Hashing.ChecksumType.CRC_32;
import static com.google.common.truth.Truth.assertThat;

import com.google.common.annotations.J2ktIncompatible;
import java.util.zip.Checksum;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;
Expand All @@ -28,6 +29,7 @@
* @author Colin Decker
*/
@NullUnmarked
@J2ktIncompatible
public class ChecksumHashFunctionTest extends TestCase {

public void testCrc32_equalsChecksumValue() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.common.hash.Hashing.crc32c;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.annotations.J2ktIncompatible;
import java.util.Arrays;
import java.util.Random;
import junit.framework.TestCase;
Expand All @@ -29,6 +30,7 @@
* @author Kurt Alfred Kluever
*/
@NullUnmarked
@J2ktIncompatible
public class Crc32cHashFunctionTest extends TestCase {
public void testEmpty() {
assertCrc(0, new byte[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;

import com.google.common.annotations.J2ktIncompatible;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Ordering;
Expand All @@ -21,6 +22,7 @@
* @author kylemaddison@google.com (Kyle Maddison)
*/
@NullUnmarked
@J2ktIncompatible
public class Fingerprint2011Test extends TestCase {

// Length of the sample string to produce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import com.google.common.annotations.J2ktIncompatible;
import com.google.common.testing.EqualsTester;
import java.io.OutputStream;
import java.nio.ByteBuffer;
Expand All @@ -45,6 +46,7 @@
*
* @author Dimitris Andreou
*/
@J2ktIncompatible
@NullUnmarked
public class FunnelsTest extends TestCase {
public void testForBytes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

package com.google.common.hash;

import static com.google.common.hash.Hashing.sha1;
import static com.google.common.hash.Hashing.farmHashFingerprint64;
import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.junit.Assert.assertThrows;

import com.google.common.annotations.J2ktIncompatible;
import com.google.common.collect.ImmutableList;
import com.google.common.io.BaseEncoding;
import com.google.common.testing.ClassSanityTester;
Expand Down Expand Up @@ -178,16 +179,18 @@ public void testToString() {
assertThat(base16().lowerCase().encode(data)).isEqualTo("7f8005ff0e");
}

@J2ktIncompatible // ClassSanityTester
public void testHashCode_nulls() throws Exception {
sanityTester().testNulls();
}

@J2ktIncompatible // ClassSanityTester
public void testHashCode_equalsAndSerializable() throws Exception {
sanityTester().testEqualsAndSerializable();
}

public void testRoundTripHashCodeUsingBaseEncoding() {
HashCode hash1 = sha1().hashString("foo", US_ASCII);
HashCode hash1 = farmHashFingerprint64().hashString("foo", US_ASCII);
HashCode hash2 = HashCode.fromBytes(BaseEncoding.base16().lowerCase().decode(hash1.toString()));
assertEquals(hash1, hash2);
}
Expand Down Expand Up @@ -219,7 +222,7 @@ public void testObjectHashCodeWithSameLowOrderBytes() {
}

public void testRoundTripHashCodeUsingFromString() {
HashCode hash1 = sha1().hashString("foo", US_ASCII);
HashCode hash1 = farmHashFingerprint64().hashString("foo", US_ASCII);
HashCode hash2 = HashCode.fromString(hash1.toString());
assertEquals(hash1, hash2);
}
Expand All @@ -238,7 +241,7 @@ public void testFromStringFailsWithInvalidHexChar() {
}

public void testFromStringFailsWithUpperCaseString() {
String string = sha1().hashString("foo", US_ASCII).toString().toUpperCase();
String string = farmHashFingerprint64().hashString("foo", US_ASCII).toString().toUpperCase();
assertThrows(IllegalArgumentException.class, () -> HashCode.fromString(string));
}

Expand Down Expand Up @@ -310,6 +313,7 @@ public void testWriteBytesToUndersizedArrayShortMaxLength() {
assertThat(dest).isEqualTo(new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0x00});
}

@J2ktIncompatible // ClassSanityTester
private static ClassSanityTester.FactoryMethodReturnValueTester sanityTester() {
return new ClassSanityTester()
.setDefault(byte[].class, new byte[] {1, 2, 3, 4})
Expand Down Expand Up @@ -357,7 +361,7 @@ private static void assertReadableBytes(HashCode hashCode) {
private static class ExpectedHashCode {
final byte[] bytes;
final int asInt;
final Long asLong; // null means that asLong should throw an exception
final @Nullable Long asLong; // null means that asLong should throw an exception
final String toString;

ExpectedHashCode(byte[] bytes, int asInt, @Nullable Long asLong, String toString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static com.google.common.hash.Hashing.sha512;
import static com.google.common.hash.Hashing.sipHash24;

import com.google.common.annotations.J2ktIncompatible;
import org.jspecify.annotations.NullUnmarked;

/**
Expand All @@ -39,6 +40,7 @@
*/
@SuppressWarnings("deprecation") // We still need to test our deprecated APIs.
@NullUnmarked
@J2ktIncompatible
enum HashFunctionEnum {
ADLER32(adler32()),
CRC32(crc32()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ private static void assertHashLongEquivalence(HashFunction hashFunction, Random
assertEquals(hashFunction.hashLong(l), hashFunction.newHasher().putLong(l).hash());
}

// TODO: b/484953702 - Put a list in TestPlatform so that J2KT can omit some of these.
private static final ImmutableSet<Charset> CHARSETS =
ImmutableSet.of(ISO_8859_1, US_ASCII, UTF_16, UTF_16BE, UTF_16LE, UTF_8);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import com.google.common.annotations.J2ktIncompatible;
import com.google.common.testing.NullPointerTester;
import java.io.ByteArrayInputStream;
import java.util.Arrays;
Expand All @@ -33,6 +34,7 @@
* @author Qian Huang
*/
@NullUnmarked
@J2ktIncompatible
public class HashingInputStreamTest extends TestCase {
private Hasher hasher;
private HashFunction hashFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import com.google.common.annotations.J2ktIncompatible;
import com.google.common.testing.NullPointerTester;
import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
Expand All @@ -31,6 +32,7 @@
* @author Zoe Piepmeier
*/
@NullUnmarked
@J2ktIncompatible
public class HashingOutputStreamTest extends TestCase {
private Hasher hasher;
private HashFunction hashFunction;
Expand Down
Loading
Loading