Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 "process/SymbolTable.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 18 | |
Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 19 | #include "test/Test.h" |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 20 | |
| 21 | namespace aapt { |
| 22 | |
Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 23 | TEST(ResourceTableSymbolSourceTest, FindSymbols) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 24 | std::unique_ptr<ResourceTable> table = |
| 25 | test::ResourceTableBuilder() |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 26 | .AddSimple("android:id/foo", ResourceId(0x01020000)) |
| 27 | .AddSimple("android:id/bar") |
| 28 | .AddValue("android:attr/foo", ResourceId(0x01010000), |
| 29 | test::AttributeBuilder().Build()) |
| 30 | .Build(); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 31 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 32 | ResourceTableSymbolSource symbol_source(table.get()); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 33 | EXPECT_NE(nullptr, |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 34 | symbol_source.FindByName(test::ParseNameOrDie("android:id/foo"))); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 35 | EXPECT_NE(nullptr, |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 36 | symbol_source.FindByName(test::ParseNameOrDie("android:id/bar"))); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 37 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 38 | std::unique_ptr<SymbolTable::Symbol> s = |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 39 | symbol_source.FindByName(test::ParseNameOrDie("android:attr/foo")); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 40 | ASSERT_NE(nullptr, s); |
| 41 | EXPECT_NE(nullptr, s->attribute); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Adam Lesinski | 64587af | 2016-02-18 18:33:06 -0800 | [diff] [blame] | 44 | TEST(ResourceTableSymbolSourceTest, FindPrivateAttrSymbol) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 45 | std::unique_ptr<ResourceTable> table = |
| 46 | test::ResourceTableBuilder() |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 47 | .AddValue("android:^attr-private/foo", ResourceId(0x01010000), |
| 48 | test::AttributeBuilder().Build()) |
| 49 | .Build(); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 50 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 51 | ResourceTableSymbolSource symbol_source(table.get()); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 52 | std::unique_ptr<SymbolTable::Symbol> s = |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 53 | symbol_source.FindByName(test::ParseNameOrDie("android:attr/foo")); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 54 | ASSERT_NE(nullptr, s); |
| 55 | EXPECT_NE(nullptr, s->attribute); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Adam Lesinski | ceb9b2f | 2017-02-16 12:05:42 -0800 | [diff] [blame^] | 58 | TEST(SymbolTableTest, FindByName) { |
| 59 | std::unique_ptr<ResourceTable> table = |
| 60 | test::ResourceTableBuilder() |
| 61 | .AddSimple("com.android.app:id/foo") |
| 62 | .AddSimple("com.android.app:id/" + NameMangler::MangleEntry("com.android.lib", "foo")) |
| 63 | .Build(); |
| 64 | |
| 65 | NameMangler mangler(NameManglerPolicy{"com.android.app", {"com.android.lib"}}); |
| 66 | SymbolTable symbol_table(&mangler); |
| 67 | symbol_table.AppendSource(util::make_unique<ResourceTableSymbolSource>(table.get())); |
| 68 | |
| 69 | EXPECT_NE(nullptr, symbol_table.FindByName(test::ParseNameOrDie("id/foo"))); |
| 70 | EXPECT_NE(nullptr, symbol_table.FindByName(test::ParseNameOrDie("com.android.lib:id/foo"))); |
| 71 | } |
| 72 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 73 | } // namespace aapt |