| // 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.CfVm; |
| 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 UnusedRecordReflectionTest extends TestBase { |
| |
| private static final String RECORD_NAME = "UnusedRecordReflection"; |
| 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("null", "null"); |
| |
| private final TestParameters parameters; |
| |
| public UnusedRecordReflectionTest(TestParameters parameters) { |
| this.parameters = parameters; |
| } |
| |
| @Parameterized.Parameters(name = "{0}") |
| public static List<Object[]> data() { |
| return buildParameters( |
| getTestParameters() |
| .withCfRuntimesStartingFromIncluding(CfVm.JDK17) |
| .withDexRuntimes() |
| .withAllApiLevelsAlsoForCf() |
| .build()); |
| } |
| |
| @Test |
| public void testD8AndJvm() throws Exception { |
| if (parameters.isCfRuntime()) { |
| testForJvm() |
| .addProgramClassFileData(PROGRAM_DATA) |
| .run(parameters.getRuntime(), MAIN_TYPE) |
| .assertSuccessWithOutput(EXPECTED_RESULT); |
| } |
| testForD8(parameters.getBackend()) |
| .addProgramClassFileData(PROGRAM_DATA) |
| .setMinApi(parameters.getApiLevel()) |
| .compile() |
| .run(parameters.getRuntime(), MAIN_TYPE) |
| .assertSuccessWithOutput(EXPECTED_RESULT); |
| } |
| |
| @Test |
| public void testR8() throws Exception { |
| R8FullTestBuilder builder = |
| testForR8(parameters.getBackend()) |
| .addProgramClassFileData(PROGRAM_DATA) |
| .setMinApi(parameters.getApiLevel()) |
| .addKeepRules("-keep class records.UnusedRecordReflection { *; }") |
| .addKeepMainRule(MAIN_TYPE); |
| if (parameters.isCfRuntime()) { |
| builder |
| .addLibraryFiles(RecordTestUtils.getJdk15LibraryFiles(temp)) |
| .compile() |
| .inspect(RecordTestUtils::assertRecordsAreRecords) |
| .run(parameters.getRuntime(), MAIN_TYPE) |
| .assertSuccessWithOutput(EXPECTED_RESULT); |
| return; |
| } |
| builder.run(parameters.getRuntime(), MAIN_TYPE).assertSuccessWithOutput(EXPECTED_RESULT); |
| } |
| } |