blob: 3091b223cefb659f67fb3bb1b5746d89489b6ee1 [file] [log] [blame]
// Copyright (c) 2019, 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.desugaredlibrary.conversiontests;
import static com.android.tools.r8.desugar.desugaredlibrary.test.CompilationSpecification.DEFAULT_SPECIFICATIONS;
import static com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification.getJdk8Jdk11;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.desugar.desugaredlibrary.DesugaredLibraryTestBase;
import com.android.tools.r8.desugar.desugaredlibrary.test.CompilationSpecification;
import com.android.tools.r8.desugar.desugaredlibrary.test.CustomLibrarySpecification;
import com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification;
import com.android.tools.r8.utils.AndroidApiLevel;
import com.android.tools.r8.utils.StringUtils;
import java.time.MonthDay;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
// Longs and double take two stack indexes, this had to be dealt with in
// CfAPIConverter*WrapperCodeProvider (See stackIndex vs index), this class tests that the
// synthetic Cf code is correct.
@RunWith(Parameterized.class)
public class BasicLongDoubleConversionTest extends DesugaredLibraryTestBase {
private final TestParameters parameters;
private final LibraryDesugaringSpecification libraryDesugaringSpecification;
private final CompilationSpecification compilationSpecification;
private static final AndroidApiLevel MIN_SUPPORTED = AndroidApiLevel.O;
private static final String EXPECTED_RESULT = StringUtils.lines("--01-16");
@Parameters(name = "{0}, spec: {1}, {2}")
public static List<Object[]> data() {
return buildParameters(
getConversionParametersUpToExcluding(MIN_SUPPORTED),
getJdk8Jdk11(),
DEFAULT_SPECIFICATIONS);
}
public BasicLongDoubleConversionTest(
TestParameters parameters,
LibraryDesugaringSpecification libraryDesugaringSpecification,
CompilationSpecification compilationSpecification) {
this.parameters = parameters;
this.libraryDesugaringSpecification = libraryDesugaringSpecification;
this.compilationSpecification = compilationSpecification;
}
@Test
public void testRewrittenAPICalls() throws Exception {
testForDesugaredLibrary(parameters, libraryDesugaringSpecification, compilationSpecification)
.addProgramClasses(Executor.class)
.setCustomLibrarySpecification(
new CustomLibrarySpecification(CustomLibClass.class, MIN_SUPPORTED))
.addKeepMainRule(Executor.class)
.addOptionsModification(options -> options.testing.trackDesugaredAPIConversions = true)
.allowDiagnosticWarningMessages()
.run(parameters.getRuntime(), Executor.class)
.assertSuccessWithOutput(EXPECTED_RESULT);
}
static class Executor {
public static void main(String[] args) {
System.out.println(
CustomLibClass.mix(3L, 4L, MonthDay.of(1, 2), 5.0, 6.0, MonthDay.of(10, 20)));
}
}
// This class will be put at compilation time as library and on the runtime class path.
// This class is convenient for easy testing. Each method plays the role of methods in the
// platform APIs for which argument/return values need conversion.
static class CustomLibClass {
public static MonthDay mix(
long l1, long l2, MonthDay monthDay1, double d1, double d2, MonthDay monthDay2) {
return monthDay1.withDayOfMonth((int) (monthDay2.getDayOfMonth() + l1 - d1 + l2 - d2));
}
}
}