Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame^] | 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/Builders.h" |
| 19 | #include "test/Context.h" |
| 20 | |
| 21 | #include <gtest/gtest.h> |
| 22 | |
| 23 | namespace aapt { |
| 24 | |
| 25 | TEST(SymbolTableWrapperTest, FindSymbolsWithIds) { |
| 26 | std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder() |
| 27 | .addSimple(u"@android:id/foo", ResourceId(0x01020000)) |
| 28 | .addSimple(u"@android:id/bar") |
| 29 | .addValue(u"@android:attr/foo", ResourceId(0x01010000), |
| 30 | test::AttributeBuilder().build()) |
| 31 | .build(); |
| 32 | |
| 33 | SymbolTableWrapper symbolTable(table.get()); |
| 34 | EXPECT_NE(symbolTable.findByName(test::parseNameOrDie(u"@android:id/foo")), nullptr); |
| 35 | EXPECT_EQ(symbolTable.findByName(test::parseNameOrDie(u"@android:id/bar")), nullptr); |
| 36 | |
| 37 | const ISymbolTable::Symbol* s = symbolTable.findByName( |
| 38 | test::parseNameOrDie(u"@android:attr/foo")); |
| 39 | ASSERT_NE(s, nullptr); |
| 40 | EXPECT_NE(s->attribute, nullptr); |
| 41 | } |
| 42 | |
| 43 | TEST(SymbolTableWrapperTest, FindPrivateAttrSymbol) { |
| 44 | std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder() |
| 45 | .addValue(u"@android:^attr-private/foo", ResourceId(0x01010000), |
| 46 | test::AttributeBuilder().build()) |
| 47 | .build(); |
| 48 | |
| 49 | SymbolTableWrapper symbolTable(table.get()); |
| 50 | const ISymbolTable::Symbol* s = symbolTable.findByName( |
| 51 | test::parseNameOrDie(u"@android:attr/foo")); |
| 52 | ASSERT_NE(s, nullptr); |
| 53 | EXPECT_NE(s->attribute, nullptr); |
| 54 | } |
| 55 | |
| 56 | } // namespace aapt |