-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Remove Classic Desugar Tests (with a global exclusion config)"
This reverts commit 5767cba.
- Loading branch information
Showing
51 changed files
with
4,352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/com/google/devtools/build/android/desugar/covariantreturn/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
load("@rules_java//java:defs.bzl", "java_test") | ||
|
||
# Description: | ||
# Tests for the Java 8 desugaring tool for Android. | ||
package( | ||
default_testonly = 1, | ||
default_visibility = ["//src/test/java/com/google/devtools/build/android/desugar:__subpackages__"], | ||
) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
java_test( | ||
name = "NioBufferRefConverterTest", | ||
size = "medium", | ||
srcs = ["NioBufferRefConverterTest.java"], | ||
data = [ | ||
":nio_buffer_invocations_src", | ||
"//src/tools/android/java/com/google/devtools/build/android/desugar/testing/junit:android_jar_for_testing", | ||
"//src/tools/android/java/com/google/devtools/build/android/desugar/testing/junit:jacoco_agent_jar", | ||
], | ||
jvm_flags = [ | ||
"-Dinput_srcs='$(locations :nio_buffer_invocations_src)'", | ||
"-Djdk.internal.lambda.dumpProxyClasses=$$(mktemp -d)", | ||
"-Dandroid_runtime_jar=$(location //src/tools/android/java/com/google/devtools/build/android/desugar/testing/junit:android_jar_for_testing)", | ||
"-Djacoco_agent_jar=$(location //src/tools/android/java/com/google/devtools/build/android/desugar/testing/junit:jacoco_agent_jar)", | ||
], | ||
test_class = "com.google.devtools.build.android.desugar.covariantreturn.NioBufferRefConverterTest", | ||
deps = [ | ||
"//src/tools/android/java/com/google/devtools/build/android/desugar/testing/junit:desugar_rule", | ||
"//third_party:asm", | ||
"//third_party:asm-tree", | ||
"//third_party:guava", | ||
"//third_party:guava-testlib", | ||
"//third_party:jsr330_inject", | ||
"//third_party:junit4", | ||
"//third_party:truth", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "nio_buffer_invocations_src", | ||
srcs = ["NioBufferInvocations.java"], | ||
) | ||
|
||
filegroup( | ||
name = "srcs", | ||
testonly = 0, | ||
srcs = glob(["**"]), | ||
) |
59 changes: 59 additions & 0 deletions
59
.../java/com/google/devtools/build/android/desugar/covariantreturn/NioBufferInvocations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2020 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.devtools.build.android.desugar.covariantreturn; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.CharBuffer; | ||
import java.nio.DoubleBuffer; | ||
import java.nio.FloatBuffer; | ||
import java.nio.IntBuffer; | ||
import java.nio.LongBuffer; | ||
import java.nio.ShortBuffer; | ||
|
||
/** Test source for {@link NioBufferRefConverterTest}. */ | ||
public final class NioBufferInvocations { | ||
|
||
public static IntBuffer getIntBufferPosition(IntBuffer buffer, int position) { | ||
return buffer.position(position); | ||
} | ||
|
||
public static CharBuffer getCharBufferPosition(CharBuffer buffer, int position) { | ||
return buffer.position(position); | ||
} | ||
|
||
public static FloatBuffer getFloatBufferPosition(FloatBuffer buffer, int position) { | ||
return buffer.position(position); | ||
} | ||
|
||
public static DoubleBuffer getDoubleBufferPosition(DoubleBuffer buffer, int position) { | ||
return buffer.position(position); | ||
} | ||
|
||
public static ShortBuffer getShortBufferPosition(ShortBuffer buffer, int position) { | ||
return buffer.position(position); | ||
} | ||
|
||
public static LongBuffer getLongBufferPosition(LongBuffer buffer, int position) { | ||
return buffer.position(position); | ||
} | ||
|
||
public static ByteBuffer getByteBufferPosition(ByteBuffer buffer, int position) { | ||
return buffer.position(position); | ||
} | ||
|
||
private NioBufferInvocations() {} | ||
} |
213 changes: 213 additions & 0 deletions
213
.../com/google/devtools/build/android/desugar/covariantreturn/NioBufferRefConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
/* | ||
* Copyright 2020 The Bazel Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.devtools.build.android.desugar.covariantreturn; | ||
|
||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.objectweb.asm.tree.AbstractInsnNode.METHOD_INSN; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Iterables; | ||
import com.google.devtools.build.android.desugar.testing.junit.AsmNode; | ||
import com.google.devtools.build.android.desugar.testing.junit.DesugarRule; | ||
import com.google.devtools.build.android.desugar.testing.junit.DesugarRunner; | ||
import com.google.devtools.build.android.desugar.testing.junit.JdkSuppress; | ||
import com.google.devtools.build.android.desugar.testing.junit.JdkVersion; | ||
import com.google.devtools.build.android.desugar.testing.junit.RuntimeMethodHandle; | ||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.nio.ByteBuffer; | ||
import java.nio.CharBuffer; | ||
import java.nio.DoubleBuffer; | ||
import java.nio.FloatBuffer; | ||
import java.nio.IntBuffer; | ||
import java.nio.LongBuffer; | ||
import java.nio.ShortBuffer; | ||
import java.nio.charset.Charset; | ||
import java.util.Arrays; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.AbstractInsnNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.TypeInsnNode; | ||
|
||
/** Functional Tests for {@link NioBufferRefConverter}. */ | ||
@RunWith(DesugarRunner.class) | ||
@JdkSuppress(minJdkVersion = JdkVersion.V11) | ||
public class NioBufferRefConverterTest { | ||
|
||
@Rule | ||
public final DesugarRule desugarRule = | ||
DesugarRule.builder(this, MethodHandles.lookup()) | ||
.addSourceInputsFromJvmFlag("input_srcs") | ||
.addJavacOptions("--release 11") | ||
.addCommandOptions("desugar_nest_based_private_access", "true") | ||
.addCommandOptions("allow_empty_bootclasspath", "true") | ||
.addCommandOptions("core_library", "true") | ||
.setWorkingJavaPackage("com.google.devtools.build.android.desugar.covariantreturn") | ||
.build(); | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_beforeDesugar( | ||
@AsmNode(className = "NioBufferInvocations", memberName = "getByteBufferPosition", round = 0) | ||
MethodNode before) { | ||
ImmutableList<AbstractInsnNode> methodInvocations = | ||
Arrays.stream(before.instructions.toArray()) | ||
.filter(insnNode -> insnNode.getType() == METHOD_INSN) | ||
.collect(toImmutableList()); | ||
|
||
assertThat(methodInvocations).hasSize(1); | ||
MethodInsnNode methodInsnNode = (MethodInsnNode) Iterables.getOnlyElement(methodInvocations); | ||
|
||
assertThat(methodInsnNode.owner).isEqualTo("java/nio/ByteBuffer"); | ||
assertThat(methodInsnNode.name).isEqualTo("position"); | ||
assertThat(methodInsnNode.desc).isEqualTo("(I)Ljava/nio/ByteBuffer;"); | ||
|
||
assertThat(methodInsnNode.getNext().getOpcode()).isEqualTo(Opcodes.ARETURN); | ||
} | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_afterDesugar( | ||
@AsmNode(className = "NioBufferInvocations", memberName = "getByteBufferPosition", round = 1) | ||
MethodNode after) { | ||
ImmutableList<AbstractInsnNode> methodInvocations = | ||
Arrays.stream(after.instructions.toArray()) | ||
.filter(insnNode -> insnNode.getType() == METHOD_INSN) | ||
.collect(toImmutableList()); | ||
|
||
assertThat(methodInvocations).hasSize(1); | ||
MethodInsnNode methodInsnNode = (MethodInsnNode) Iterables.getOnlyElement(methodInvocations); | ||
|
||
assertThat(methodInsnNode.owner).isEqualTo("java/nio/ByteBuffer"); | ||
assertThat(methodInsnNode.name).isEqualTo("position"); | ||
assertThat(methodInsnNode.desc).isEqualTo("(I)Ljava/nio/Buffer;"); | ||
|
||
TypeInsnNode typeInsnNode = (TypeInsnNode) methodInsnNode.getNext(); | ||
assertThat(typeInsnNode.getOpcode()).isEqualTo(Opcodes.CHECKCAST); | ||
assertThat(typeInsnNode.desc).isEqualTo("java/nio/ByteBuffer"); | ||
|
||
assertThat(typeInsnNode.getNext().getOpcode()).isEqualTo(Opcodes.ARETURN); | ||
} | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_beforeDesugarInvocation( | ||
@RuntimeMethodHandle( | ||
className = "NioBufferInvocations", | ||
memberName = "getByteBufferPosition", | ||
round = 0) | ||
MethodHandle before) | ||
throws Throwable { | ||
ByteBuffer buffer = ByteBuffer.wrap("random text".getBytes(Charset.defaultCharset())); | ||
int expectedPos = 2; | ||
|
||
ByteBuffer result = (ByteBuffer) before.invoke(buffer, expectedPos); | ||
assertThat(result.position()).isEqualTo(expectedPos); | ||
} | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_afterDesugarInvocationOfByteBufferMethod( | ||
@RuntimeMethodHandle(className = "NioBufferInvocations", memberName = "getByteBufferPosition") | ||
MethodHandle after) | ||
throws Throwable { | ||
ByteBuffer buffer = ByteBuffer.wrap("random text".getBytes(Charset.defaultCharset())); | ||
int expectedPos = 2; | ||
|
||
ByteBuffer result = (ByteBuffer) after.invoke(buffer, expectedPos); | ||
assertThat(result.position()).isEqualTo(expectedPos); | ||
} | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_afterDesugarInvocationOfCharBufferMethod( | ||
@RuntimeMethodHandle(className = "NioBufferInvocations", memberName = "getCharBufferPosition") | ||
MethodHandle after) | ||
throws Throwable { | ||
CharBuffer buffer = CharBuffer.wrap("random text".toCharArray()); | ||
int expectedPos = 2; | ||
|
||
CharBuffer result = (CharBuffer) after.invoke(buffer, expectedPos); | ||
assertThat(result.position()).isEqualTo(expectedPos); | ||
} | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_afterDesugarInvocationOfIntBufferMethod( | ||
@RuntimeMethodHandle(className = "NioBufferInvocations", memberName = "getIntBufferPosition") | ||
MethodHandle after) | ||
throws Throwable { | ||
IntBuffer buffer = IntBuffer.wrap(new int[] {10, 20, 30}); | ||
int expectedPos = 2; | ||
|
||
IntBuffer result = (IntBuffer) after.invoke(buffer, expectedPos); | ||
assertThat(result.position()).isEqualTo(expectedPos); | ||
} | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_afterDesugarInvocationOfFloatBufferMethod( | ||
@RuntimeMethodHandle( | ||
className = "NioBufferInvocations", | ||
memberName = "getFloatBufferPosition") | ||
MethodHandle after) | ||
throws Throwable { | ||
FloatBuffer buffer = FloatBuffer.wrap(new float[] {10f, 20f, 30f}); | ||
int expectedPos = 2; | ||
|
||
FloatBuffer result = (FloatBuffer) after.invoke(buffer, expectedPos); | ||
assertThat(result.position()).isEqualTo(expectedPos); | ||
} | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_afterDesugarInvocationOfDoubleBufferMethod( | ||
@RuntimeMethodHandle( | ||
className = "NioBufferInvocations", | ||
memberName = "getDoubleBufferPosition") | ||
MethodHandle after) | ||
throws Throwable { | ||
DoubleBuffer buffer = DoubleBuffer.wrap(new double[] {10.0, 20.0, 30.0}); | ||
int expectedPos = 2; | ||
|
||
DoubleBuffer result = (DoubleBuffer) after.invoke(buffer, expectedPos); | ||
assertThat(result.position()).isEqualTo(expectedPos); | ||
} | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_afterDesugarInvocationOfShortBufferMethod( | ||
@RuntimeMethodHandle( | ||
className = "NioBufferInvocations", | ||
memberName = "getShortBufferPosition") | ||
MethodHandle after) | ||
throws Throwable { | ||
ShortBuffer buffer = ShortBuffer.wrap(new short[] {10, 20, 30}); | ||
int expectedPos = 2; | ||
|
||
ShortBuffer result = (ShortBuffer) after.invoke(buffer, expectedPos); | ||
assertThat(result.position()).isEqualTo(expectedPos); | ||
} | ||
|
||
@Test | ||
public void methodOfNioBufferWithCovariantTypes_afterDesugarInvocationOfLongBufferMethod( | ||
@RuntimeMethodHandle(className = "NioBufferInvocations", memberName = "getLongBufferPosition") | ||
MethodHandle after) | ||
throws Throwable { | ||
LongBuffer buffer = LongBuffer.wrap(new long[] {10L, 20L, 30L}); | ||
int expectedPos = 2; | ||
|
||
LongBuffer result = (LongBuffer) after.invoke(buffer, expectedPos); | ||
assertThat(result.position()).isEqualTo(expectedPos); | ||
} | ||
} |
Oops, something went wrong.