| // Copyright (c) 2023, 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.androidresources; |
| |
| import com.android.tools.r8.TestBase; |
| import com.android.tools.r8.TestParameters; |
| import com.android.tools.r8.androidresources.AndroidResourceTestingUtils.AndroidTestResource; |
| import com.android.tools.r8.androidresources.AndroidResourceTestingUtils.AndroidTestResourceBuilder; |
| import com.android.tools.r8.utils.BooleanUtils; |
| import java.nio.file.Path; |
| import java.util.List; |
| import org.junit.Test; |
| import org.junit.rules.TemporaryFolder; |
| import org.junit.runner.RunWith; |
| import org.junit.runners.Parameterized; |
| import org.junit.runners.Parameterized.Parameter; |
| import org.junit.runners.Parameterized.Parameters; |
| |
| @RunWith(Parameterized.class) |
| public class ResourceNameWithDotsRegressionTest extends TestBase { |
| |
| @Parameter(0) |
| public TestParameters parameters; |
| |
| @Parameter(1) |
| public boolean debug; |
| |
| @Parameter(2) |
| public boolean optimized; |
| |
| @Parameters(name = "{0}, debug: {1}, optimized: {2}") |
| public static List<Object[]> data() { |
| return buildParameters( |
| getTestParameters().withDefaultDexRuntime().withAllApiLevels().build(), |
| BooleanUtils.values(), |
| BooleanUtils.values()); |
| } |
| |
| public static AndroidTestResource getTestResources(TemporaryFolder temp) throws Exception { |
| return new AndroidTestResourceBuilder() |
| .withSimpleManifestAndAppNameString() |
| .addStringValue("foo.bar", "the foobar string") |
| .build(temp); |
| } |
| |
| @Test |
| public void testR8() throws Exception { |
| AndroidTestResource testResources = getTestResources(temp); |
| Path resourcesClass = AndroidResourceTestingUtils.resourcesClassAsDex(temp); |
| byte[] withAnroidResourcesReference = |
| AndroidResourceTestingUtils.transformResourcesReferences(FooBar.class); |
| testForR8(parameters.getBackend()) |
| .setMinApi(parameters) |
| .addProgramClassFileData(withAnroidResourcesReference) |
| .addRunClasspathFiles(resourcesClass) |
| .addAndroidResources(testResources) |
| .addKeepMainRule(FooBar.class) |
| .compile() |
| .inspectShrunkenResources( |
| resourceTableInspector -> { |
| resourceTableInspector.assertContainsResourceWithName("string", "foo.bar"); |
| }) |
| .run(parameters.getRuntime(), FooBar.class) |
| .assertSuccess(); |
| } |
| |
| public static class FooBar { |
| |
| public static void main(String[] args) { |
| if (System.currentTimeMillis() == 0) { |
| Resources resources = new Resources(); |
| resources.getIdentifier("foo.bar", "string", "mypackage"); |
| } |
| } |
| } |
| } |