blob: 162635220cdd5c6b04f5d28ec490d63b07d55ade [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 Lesinski64587af2016-02-18 18:33:06 -080018#include "test/Test.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070019
20namespace aapt {
21
Adam Lesinski64587af2016-02-18 18:33:06 -080022TEST(ResourceTableSymbolSourceTest, FindSymbols) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -070023 std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
Adam Lesinski58a20a62016-07-25 17:56:58 -070024 .addSimple("android:id/foo", ResourceId(0x01020000))
25 .addSimple("android:id/bar")
26 .addValue("android:attr/foo", ResourceId(0x01010000),
Adam Lesinski1ab598f2015-08-14 14:26:04 -070027 test::AttributeBuilder().build())
28 .build();
29
Adam Lesinski64587af2016-02-18 18:33:06 -080030 ResourceTableSymbolSource symbolSource(table.get());
Adam Lesinski58a20a62016-07-25 17:56:58 -070031 EXPECT_NE(nullptr, symbolSource.findByName(test::parseNameOrDie("android:id/foo")));
32 EXPECT_NE(nullptr, symbolSource.findByName(test::parseNameOrDie("android:id/bar")));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070033
Adam Lesinski64587af2016-02-18 18:33:06 -080034 std::unique_ptr<SymbolTable::Symbol> s = symbolSource.findByName(
Adam Lesinski58a20a62016-07-25 17:56:58 -070035 test::parseNameOrDie("android:attr/foo"));
Adam Lesinski64587af2016-02-18 18:33:06 -080036 ASSERT_NE(nullptr, s);
37 EXPECT_NE(nullptr, s->attribute);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070038}
39
Adam Lesinski64587af2016-02-18 18:33:06 -080040TEST(ResourceTableSymbolSourceTest, FindPrivateAttrSymbol) {
Adam Lesinski1ab598f2015-08-14 14:26:04 -070041 std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
Adam Lesinski58a20a62016-07-25 17:56:58 -070042 .addValue("android:^attr-private/foo", ResourceId(0x01010000),
Adam Lesinski1ab598f2015-08-14 14:26:04 -070043 test::AttributeBuilder().build())
44 .build();
45
Adam Lesinski64587af2016-02-18 18:33:06 -080046 ResourceTableSymbolSource symbolSource(table.get());
47 std::unique_ptr<SymbolTable::Symbol> s = symbolSource.findByName(
Adam Lesinski58a20a62016-07-25 17:56:58 -070048 test::parseNameOrDie("android:attr/foo"));
Adam Lesinski64587af2016-02-18 18:33:06 -080049 ASSERT_NE(nullptr, s);
50 EXPECT_NE(nullptr, s->attribute);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070051}
52
53} // namespace aapt