diff --git a/apps/calendars/pom.xml b/apps/calendars/pom.xml new file mode 100644 index 00000000..f388824b --- /dev/null +++ b/apps/calendars/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + calendars + calendars + 1 + + calendars + + + org.graalvm.tests.integration + parent + 1.0.0-SNAPSHOT + ../../pom.xml + + + + 3.2.0 + + + + calendars + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + calendar.Main + + + + + + + diff --git a/apps/calendars/src/main/java/calendar/Main.java b/apps/calendars/src/main/java/calendar/Main.java new file mode 100644 index 00000000..13347007 --- /dev/null +++ b/apps/calendars/src/main/java/calendar/Main.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023, Red Hat Inc. All rights reserved. + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package calendar; + +import java.util.Calendar; +import java.util.Locale; + +/** + * @author Severin Gehwolf + */ +public class Main { + + private static void doCalTest(String type) { + Calendar cal = new Calendar.Builder() + .setCalendarType(type) + .setFields(Calendar.YEAR, 1, Calendar.DAY_OF_YEAR, 1) + .build(); + int year = cal.get(Calendar.YEAR); + String t = cal.getCalendarType(); + int dayOfYear = cal.get(Calendar.DAY_OF_YEAR); + System.out.printf("Year: %d, dayOfYear: %d, type: %s%n", year, dayOfYear, t); + } + + public static void main(String[] args) { + Locale.setDefault(Locale.US); // Don't rely on the default locale of the system. + String[] types = new String[] { "japanese", "buddhist", "gregory" }; + for (String t : types) { + doCalTest(t); + } + } +} diff --git a/pom.xml b/pom.xml index c1137339..85f1d1d9 100755 --- a/pom.xml +++ b/pom.xml @@ -98,6 +98,7 @@ apps/debug-symbols-smoke apps/quarkus-spöklik-encoding apps/quarkus-vertx + apps/calendars diff --git a/testsuite/src/it/java/org/graalvm/tests/integration/AppReproducersTest.java b/testsuite/src/it/java/org/graalvm/tests/integration/AppReproducersTest.java index e41df88b..81787898 100644 --- a/testsuite/src/it/java/org/graalvm/tests/integration/AppReproducersTest.java +++ b/testsuite/src/it/java/org/graalvm/tests/integration/AppReproducersTest.java @@ -745,6 +745,46 @@ public void timezonesBakedIn(TestInfo testInfo) throws IOException, InterruptedE cleanup(process, cn, mn, report, app, processLog); } } + + @Test + @Tag("calendars") + @IfMandrelVersion(min = "22.3.5") // The fix for this test is in 22.3.5 and better + public void calendarsBakedIn(TestInfo testInfo) throws IOException, InterruptedException { + final Apps app = Apps.CALENDARS; + LOGGER.info("Testing app: " + app); + Process process = null; + File processLog = null; + final StringBuilder report = new StringBuilder(); + final File appDir = Path.of(BASE_DIR, app.dir).toFile(); + final String cn = testInfo.getTestClass().get().getCanonicalName(); + final String mn = testInfo.getTestMethod().get().getName(); + try { + // Cleanup + cleanTarget(app); + Files.createDirectories(Paths.get(appDir.getAbsolutePath() + File.separator + "logs")); + + // Build + processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile(); + + builderRoutine(app, report, cn, mn, appDir, processLog); + + LOGGER.info("Running..."); + List cmd = getRunCommand(app.buildAndRunCmds.cmds[app.buildAndRunCmds.cmds.length - 1]); + process = runCommand(cmd, appDir, processLog, app); + assertNotNull(process, "The test application failed to run. Check " + getLogsDir(cn, mn) + File.separator + processLog.getName()); + process.waitFor(5, TimeUnit.SECONDS); + Logs.appendln(report, appDir.getAbsolutePath()); + Logs.appendlnSection(report, String.join(" ", cmd)); + + final Pattern p = Pattern.compile(".*Year: (?:1|1086), dayOfYear: 1, type: (?:japanese|buddhist|gregory).*"); + assertTrue(searchLogLines(p, processLog, Charset.defaultCharset()), "Expected pattern " + p.toString() + " was not found in the log."); + + processStopper(process, false); + Logs.checkLog(cn, mn, app, processLog); + } finally { + cleanup(process, cn, mn, report, app, processLog); + } + } @Test @Tag("jdk-17") diff --git a/testsuite/src/it/java/org/graalvm/tests/integration/utils/Apps.java b/testsuite/src/it/java/org/graalvm/tests/integration/utils/Apps.java index 1466339d..3987dfd8 100755 --- a/testsuite/src/it/java/org/graalvm/tests/integration/utils/Apps.java +++ b/testsuite/src/it/java/org/graalvm/tests/integration/utils/Apps.java @@ -89,6 +89,11 @@ public enum Apps { WhitelistLogLines.NONE, BuildAndRunCmds.TIMEZONES, ContainerNames.NONE), + CALENDARS("apps" + File.separator + "calendars", + URLContent.NONE, + WhitelistLogLines.NONE, + BuildAndRunCmds.CALENDARS, + ContainerNames.NONE), RECORDANNOTATIONS("apps" + File.separator + "recordannotations", URLContent.NONE, WhitelistLogLines.NONE, diff --git a/testsuite/src/it/java/org/graalvm/tests/integration/utils/BuildAndRunCmds.java b/testsuite/src/it/java/org/graalvm/tests/integration/utils/BuildAndRunCmds.java index ddbfab42..60f298c9 100755 --- a/testsuite/src/it/java/org/graalvm/tests/integration/utils/BuildAndRunCmds.java +++ b/testsuite/src/it/java/org/graalvm/tests/integration/utils/BuildAndRunCmds.java @@ -155,6 +155,11 @@ public enum BuildAndRunCmds { new String[]{"native-image", "-J-Duser.country=CA", "-J-Duser.language=fr", "-jar", "target/timezones.jar", "target/timezones"}, new String[]{IS_THIS_WINDOWS ? "target\\timezones.exe" : "./target/timezones"} }), + CALENDARS(new String[][]{ + new String[]{"mvn", "package"}, + new String[]{"native-image", "--link-at-build-time=calendar.Main", "-jar", "target/calendars.jar", "target/calendars"}, + new String[]{IS_THIS_WINDOWS ? "target\\calendars.exe" : "./target/calendars"} + }), RECORDANNOTATIONS(new String[][]{ new String[]{"mvn", "package"}, new String[]{"native-image", "--no-fallback", "-jar", "target/recordannotations.jar", "target/recordannotations"},