blob: 7207f6db05595d5c509742e72f6155a67be5b108 [file] [log] [blame]
// Copyright (c) 2021, 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.records;
import com.android.tools.r8.R8FullTestBuilder;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestRuntime.CfRuntime;
import com.android.tools.r8.utils.InternalOptions.TestingOptions;
import com.android.tools.r8.utils.StringUtils;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class RecordInvokeCustomTest extends TestBase {
private static final String RECORD_NAME = "RecordInvokeCustom";
private static final byte[][] PROGRAM_DATA = RecordTestUtils.getProgramData(RECORD_NAME);
private static final String MAIN_TYPE = RecordTestUtils.getMainType(RECORD_NAME);
private static final String EXPECTED_RESULT =
StringUtils.lines(
"%s[]",
"true",
"true",
"true",
"true",
"true",
"false",
"true",
"true",
"false",
"false",
"%s[%s=Jane Doe, %s=42]");
private static final String EXPECTED_RESULT_D8 =
String.format(EXPECTED_RESULT, "Empty", "Person", "name", "age");
private static final String EXPECTED_RESULT_R8 =
String.format(EXPECTED_RESULT, "a", "b", "a", "b");
private final TestParameters parameters;
public RecordInvokeCustomTest(TestParameters parameters) {
this.parameters = parameters;
}
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> data() {
// TODO(b/174431251): This should be replaced with .withCfRuntimes(start = jdk17).
return buildParameters(
getTestParameters()
.withCustomRuntime(CfRuntime.getCheckedInJdk17())
.withDexRuntimes()
.withAllApiLevelsAlsoForCf()
.build());
}
@Test
public void testD8AndJvm() throws Exception {
if (parameters.isCfRuntime()) {
testForJvm()
.addProgramClassFileData(PROGRAM_DATA)
.run(parameters.getRuntime(), MAIN_TYPE)
.assertSuccessWithOutput(EXPECTED_RESULT_D8);
}
testForD8(parameters.getBackend())
.addProgramClassFileData(PROGRAM_DATA)
.setMinApi(parameters.getApiLevel())
.addOptionsModification(TestingOptions::allowExperimentClassFileVersion)
.compile()
.run(parameters.getRuntime(), MAIN_TYPE)
.assertSuccessWithOutput(EXPECTED_RESULT_D8);
}
@Test
public void testR8() throws Exception {
R8FullTestBuilder builder =
testForR8(parameters.getBackend())
.addProgramClassFileData(PROGRAM_DATA)
.setMinApi(parameters.getApiLevel())
.addKeepMainRule(MAIN_TYPE)
.addOptionsModification(TestingOptions::allowExperimentClassFileVersion);
if (parameters.isCfRuntime()) {
builder
.addLibraryFiles(RecordTestUtils.getJdk15LibraryFiles(temp))
.compile()
.inspect(RecordTestUtils::assertRecordsAreRecords)
.run(parameters.getRuntime(), MAIN_TYPE)
.assertSuccessWithOutput(EXPECTED_RESULT_R8);
return;
}
builder.run(parameters.getRuntime(), MAIN_TYPE).assertSuccessWithOutput(EXPECTED_RESULT_R8);
}
}