• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
18 
19 #include "test/Test.h"
20 
21 namespace aapt {
22 
TEST(ResourceTableSymbolSourceTest,FindSymbols)23 TEST(ResourceTableSymbolSourceTest, FindSymbols) {
24   std::unique_ptr<ResourceTable> table =
25       test::ResourceTableBuilder()
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();
31 
32   ResourceTableSymbolSource symbol_source(table.get());
33   EXPECT_NE(nullptr, symbol_source.FindByName(test::ParseNameOrDie("android:id/foo")));
34   EXPECT_NE(nullptr, symbol_source.FindByName(test::ParseNameOrDie("android:id/bar")));
35 
36   std::unique_ptr<SymbolTable::Symbol> s =
37       symbol_source.FindByName(test::ParseNameOrDie("android:attr/foo"));
38   ASSERT_NE(nullptr, s);
39   EXPECT_NE(nullptr, s->attribute);
40 }
41 
TEST(ResourceTableSymbolSourceTest,FindPrivateAttrSymbol)42 TEST(ResourceTableSymbolSourceTest, FindPrivateAttrSymbol) {
43   std::unique_ptr<ResourceTable> table =
44       test::ResourceTableBuilder()
45           .AddValue("android:^attr-private/foo", ResourceId(0x01010000),
46                     test::AttributeBuilder().Build())
47           .Build();
48 
49   ResourceTableSymbolSource symbol_source(table.get());
50   std::unique_ptr<SymbolTable::Symbol> s =
51       symbol_source.FindByName(test::ParseNameOrDie("android:attr/foo"));
52   ASSERT_NE(nullptr, s);
53   EXPECT_NE(nullptr, s->attribute);
54 }
55 
TEST(SymbolTableTest,FindByName)56 TEST(SymbolTableTest, FindByName) {
57   std::unique_ptr<ResourceTable> table =
58       test::ResourceTableBuilder()
59           .AddSimple("com.android.app:id/foo")
60           .AddSimple("com.android.app:id/" + NameMangler::MangleEntry("com.android.lib", "foo"))
61           .Build();
62 
63   NameMangler mangler(NameManglerPolicy{"com.android.app", {"com.android.lib"}});
64   SymbolTable symbol_table(&mangler);
65   symbol_table.AppendSource(util::make_unique<ResourceTableSymbolSource>(table.get()));
66 
67   EXPECT_NE(nullptr, symbol_table.FindByName(test::ParseNameOrDie("id/foo")));
68   EXPECT_NE(nullptr, symbol_table.FindByName(test::ParseNameOrDie("com.android.lib:id/foo")));
69 }
70 
71 }  // namespace aapt
72