blob: 6b50afe8324dc714c4db7d8b7a860d665379d5ba [file] [log] [blame]
// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.desugar;
import static org.objectweb.asm.Opcodes.V1_4;
import static org.objectweb.asm.Opcodes.V1_5;
import static org.objectweb.asm.Opcodes.V1_6;
import static org.objectweb.asm.Opcodes.V1_7;
import static org.objectweb.asm.Opcodes.V1_8;
import static org.objectweb.asm.Opcodes.V9;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.google.common.collect.ImmutableList;
import java.nio.file.Path;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class DesugarToClassFileInputCfVersion extends TestBase {
@Parameters(name = "{0}, input Cf version: {1}")
public static List<Object[]> data() {
return buildParameters(
getTestParameters().withAllRuntimes().withAllApiLevelsAlsoForCf().build(),
ImmutableList.of(V1_4, V1_5, V1_6, V1_7, V1_8, V9));
}
private final TestParameters parameters;
private final int cfVersion;
public DesugarToClassFileInputCfVersion(TestParameters parameters, int cfVersion) {
this.parameters = parameters;
this.cfVersion = cfVersion;
}
@Test
public void test() throws Exception {
// Use D8 to desugar with Java classfile output.
Path jar =
testForD8(Backend.CF)
.addProgramClassFileData(transformer(TestClass.class).setVersion(cfVersion).transform())
.setMinApi(parameters.getApiLevel())
.compile()
.writeToZip();
if (parameters.getRuntime().isCf()) {
// Run on the JVM given that Cf version is supported. When we desugar we now target 1.7 (51).
testForJvm()
.addProgramFiles(jar)
.run(parameters.getRuntime(), TestClass.class)
.assertSuccessWithOutputLines("Hello, world!");
} else {
assert parameters.getRuntime().isDex();
// Convert to DEX without desugaring.
testForD8()
.addProgramFiles(jar)
.setMinApi(parameters.getApiLevel())
.disableDesugaring()
.run(parameters.getRuntime(), TestClass.class)
.assertSuccessWithOutputLines("Hello, world!");
}
}
static class TestClass {
public static void main(String[] args) {
if (System.currentTimeMillis() > 0) {
System.out.println("Hello, world!");
}
}
}
}