blob: 9ea0786cbc8ec06a3991aad6625a5b136960dc45 [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -07001/*
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 Lesinskice5e56e2016-10-21 17:56:45 -070018
Adam Lesinski64587af2016-02-18 18:33:06 -080019#include "test/Test.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070020
21namespace aapt {
22
Adam Lesinski64587af2016-02-18 18:33:06 -080023TEST(ResourceTableSymbolSourceTest, FindSymbols) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070024 std::unique_ptr<ResourceTable> table =
25 test::ResourceTableBuilder()
Adam Lesinskice5e56e2016-10-21 17:56:45 -070026 .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 Lesinski1ab598f2015-08-14 14:26:04 -070031
Adam Lesinskice5e56e2016-10-21 17:56:45 -070032 ResourceTableSymbolSource symbol_source(table.get());
Adam Lesinskicacb28f2016-10-19 12:18:14 -070033 EXPECT_NE(nullptr,
Adam Lesinskice5e56e2016-10-21 17:56:45 -070034 symbol_source.FindByName(test::ParseNameOrDie("android:id/foo")));
Adam Lesinskicacb28f2016-10-19 12:18:14 -070035 EXPECT_NE(nullptr,
Adam Lesinskice5e56e2016-10-21 17:56:45 -070036 symbol_source.FindByName(test::ParseNameOrDie("android:id/bar")));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070037
Adam Lesinskicacb28f2016-10-19 12:18:14 -070038 std::unique_ptr<SymbolTable::Symbol> s =
Adam Lesinskice5e56e2016-10-21 17:56:45 -070039 symbol_source.FindByName(test::ParseNameOrDie("android:attr/foo"));
Adam Lesinskicacb28f2016-10-19 12:18:14 -070040 ASSERT_NE(nullptr, s);
41 EXPECT_NE(nullptr, s->attribute);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070042}
43
Adam Lesinski64587af2016-02-18 18:33:06 -080044TEST(ResourceTableSymbolSourceTest, FindPrivateAttrSymbol) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070045 std::unique_ptr<ResourceTable> table =
46 test::ResourceTableBuilder()
Adam Lesinskice5e56e2016-10-21 17:56:45 -070047 .AddValue("android:^attr-private/foo", ResourceId(0x01010000),
48 test::AttributeBuilder().Build())
49 .Build();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070050
Adam Lesinskice5e56e2016-10-21 17:56:45 -070051 ResourceTableSymbolSource symbol_source(table.get());
Adam Lesinskicacb28f2016-10-19 12:18:14 -070052 std::unique_ptr<SymbolTable::Symbol> s =
Adam Lesinskice5e56e2016-10-21 17:56:45 -070053 symbol_source.FindByName(test::ParseNameOrDie("android:attr/foo"));
Adam Lesinskicacb28f2016-10-19 12:18:14 -070054 ASSERT_NE(nullptr, s);
55 EXPECT_NE(nullptr, s->attribute);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070056}
57
Adam Lesinskicacb28f2016-10-19 12:18:14 -070058} // namespace aapt