Adam Lesinski | 34a1687 | 2018-02-23 16:18:10 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "link/NoDefaultResourceRemover.h" |
| 18 | |
| 19 | #include "test/Test.h" |
| 20 | |
| 21 | namespace aapt { |
| 22 | |
| 23 | TEST(NoDefaultResourceRemoverTest, RemoveEntryWithNoDefaultAndOnlyLocales) { |
| 24 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 25 | std::unique_ptr<ResourceTable> table = |
| 26 | test::ResourceTableBuilder() |
| 27 | .SetPackageId("android", 0x01) |
| 28 | .AddSimple("android:string/foo") |
| 29 | .AddSimple("android:string/foo", test::ParseConfigOrDie("en-rGB")) |
| 30 | .AddSimple("android:string/foo", test::ParseConfigOrDie("fr-rFR")) |
| 31 | .AddSimple("android:string/bar", test::ParseConfigOrDie("en-rGB")) |
| 32 | .AddSimple("android:string/bar", test::ParseConfigOrDie("fr-rFR")) |
| 33 | .AddSimple("android:string/bat", test::ParseConfigOrDie("en-rGB-xhdpi")) |
| 34 | .AddSimple("android:string/bat", test::ParseConfigOrDie("fr-rFR-hdpi")) |
| 35 | .AddSimple("android:string/baz", test::ParseConfigOrDie("en-rGB")) |
| 36 | .AddSimple("android:string/baz", test::ParseConfigOrDie("fr-rFR")) |
| 37 | .SetSymbolState("android:string/baz", ResourceId(0x01020002), Visibility::Level::kPublic) |
| 38 | .Build(); |
| 39 | |
| 40 | NoDefaultResourceRemover remover; |
| 41 | ASSERT_TRUE(remover.Consume(context.get(), table.get())); |
| 42 | |
| 43 | EXPECT_TRUE(table->FindResource(test::ParseNameOrDie("android:string/foo"))); |
| 44 | EXPECT_FALSE(table->FindResource(test::ParseNameOrDie("android:string/bar"))); |
| 45 | EXPECT_TRUE(table->FindResource(test::ParseNameOrDie("android:string/bat"))); |
| 46 | EXPECT_TRUE(table->FindResource(test::ParseNameOrDie("android:string/baz"))); |
| 47 | } |
| 48 | |
| 49 | } // namespace aapt |