blob: 34f31be3d0db3ec92b67f5f0e49d81587efbe4c0 [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()
24 .addSimple(u"@android:id/foo", ResourceId(0x01020000))
25 .addSimple(u"@android:id/bar")
26 .addValue(u"@android:attr/foo", ResourceId(0x01010000),
27 test::AttributeBuilder().build())
28 .build();
29
Adam Lesinski64587af2016-02-18 18:33:06 -080030 ResourceTableSymbolSource symbolSource(table.get());
31 EXPECT_NE(nullptr, symbolSource.findByName(test::parseNameOrDie(u"@android:id/foo")));
32 EXPECT_NE(nullptr, symbolSource.findByName(test::parseNameOrDie(u"@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 Lesinski1ab598f2015-08-14 14:26:04 -070035 test::parseNameOrDie(u"@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()
42 .addValue(u"@android:^attr-private/foo", ResourceId(0x01010000),
43 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 Lesinski1ab598f2015-08-14 14:26:04 -070048 test::parseNameOrDie(u"@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