blob: c65809aea66fac9d141ae0d37cb8aec5b6360d32 [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.classmerging.vertical;
import com.android.tools.r8.NeverClassInline;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.classmerging.vertical.testclasses.NonReboundFieldAccessOnMergedClassTestClasses;
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 NonReboundFieldAccessOnMergedClassTest extends TestBase {
private final TestParameters parameters;
@Parameters(name = "{0}")
public static TestParametersCollection params() {
return getTestParameters().withAllRuntimesAndApiLevels().build();
}
public NonReboundFieldAccessOnMergedClassTest(TestParameters parameters) {
this.parameters = parameters;
}
@Test
public void test() throws Exception {
testForR8(parameters.getBackend())
.addInnerClasses(getClass())
.addInnerClasses(NonReboundFieldAccessOnMergedClassTestClasses.class)
.addKeepMainRule(Main.class)
.addVerticallyMergedClassesInspector(
inspector -> inspector.assertMergedIntoSubtype(C.class))
.enableNeverClassInliningAnnotations()
.enableNoVerticalClassMergingAnnotations()
.setMinApi(parameters.getApiLevel())
.compile()
.run(parameters.getRuntime(), Main.class)
.assertSuccessWithOutputLines("Hello world!");
}
static class Main {
public static void main(String[] args) {
C c = new D("Hello world!");
System.out.println(c.greeting);
}
}
static class C extends NonReboundFieldAccessOnMergedClassTestClasses.B {
public C(String greeting) {
super(greeting);
}
}
@NeverClassInline
static class D extends C {
public D(String greeting) {
super(greeting);
}
}
}