SymbolTable_test.cpp revision cacb28f2d60858106e2819cc7d95a65e8bda890b
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#include "test/Test.h"
19
20namespace aapt {
21
22TEST(ResourceTableSymbolSourceTest, FindSymbols) {
23  std::unique_ptr<ResourceTable> table =
24      test::ResourceTableBuilder()
25          .addSimple("android:id/foo", ResourceId(0x01020000))
26          .addSimple("android:id/bar")
27          .addValue("android:attr/foo", ResourceId(0x01010000),
28                    test::AttributeBuilder().build())
29          .build();
30
31  ResourceTableSymbolSource symbolSource(table.get());
32  EXPECT_NE(nullptr,
33            symbolSource.findByName(test::parseNameOrDie("android:id/foo")));
34  EXPECT_NE(nullptr,
35            symbolSource.findByName(test::parseNameOrDie("android:id/bar")));
36
37  std::unique_ptr<SymbolTable::Symbol> s =
38      symbolSource.findByName(test::parseNameOrDie("android:attr/foo"));
39  ASSERT_NE(nullptr, s);
40  EXPECT_NE(nullptr, s->attribute);
41}
42
43TEST(ResourceTableSymbolSourceTest, FindPrivateAttrSymbol) {
44  std::unique_ptr<ResourceTable> table =
45      test::ResourceTableBuilder()
46          .addValue("android:^attr-private/foo", ResourceId(0x01010000),
47                    test::AttributeBuilder().build())
48          .build();
49
50  ResourceTableSymbolSource symbolSource(table.get());
51  std::unique_ptr<SymbolTable::Symbol> s =
52      symbolSource.findByName(test::parseNameOrDie("android:attr/foo"));
53  ASSERT_NE(nullptr, s);
54  EXPECT_NE(nullptr, s->attribute);
55}
56
57}  // namespace aapt
58