SymbolTable_test.cpp revision ce5e56e243d262a9b65459c3bd0bb9eaadd40628
11ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski/* 21ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * Copyright (C) 2015 The Android Open Source Project 31ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * 41ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * Licensed under the Apache License, Version 2.0 (the "License"); 51ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * you may not use this file except in compliance with the License. 61ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * You may obtain a copy of the License at 71ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * 81ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * http://www.apache.org/licenses/LICENSE-2.0 91ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * 101ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * Unless required by applicable law or agreed to in writing, software 111ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * distributed under the License is distributed on an "AS IS" BASIS, 121ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * See the License for the specific language governing permissions and 141ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski * limitations under the License. 151ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski */ 161ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 171ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski#include "process/SymbolTable.h" 18ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 1964587af8179affd38ee26543b748f2d63b7f67bbAdam Lesinski#include "test/Test.h" 201ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 211ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinskinamespace aapt { 221ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 2364587af8179affd38ee26543b748f2d63b7f67bbAdam LesinskiTEST(ResourceTableSymbolSourceTest, FindSymbols) { 24cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski std::unique_ptr<ResourceTable> table = 25cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski test::ResourceTableBuilder() 26ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski .AddSimple("android:id/foo", ResourceId(0x01020000)) 27ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski .AddSimple("android:id/bar") 28ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski .AddValue("android:attr/foo", ResourceId(0x01010000), 29ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski test::AttributeBuilder().Build()) 30ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski .Build(); 31cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski 32ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski ResourceTableSymbolSource symbol_source(table.get()); 33cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski EXPECT_NE(nullptr, 34ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski symbol_source.FindByName(test::ParseNameOrDie("android:id/foo"))); 35cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski EXPECT_NE(nullptr, 36ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski symbol_source.FindByName(test::ParseNameOrDie("android:id/bar"))); 37cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski 38cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski std::unique_ptr<SymbolTable::Symbol> s = 39ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski symbol_source.FindByName(test::ParseNameOrDie("android:attr/foo")); 40cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski ASSERT_NE(nullptr, s); 41cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski EXPECT_NE(nullptr, s->attribute); 421ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski} 431ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 4464587af8179affd38ee26543b748f2d63b7f67bbAdam LesinskiTEST(ResourceTableSymbolSourceTest, FindPrivateAttrSymbol) { 45cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski std::unique_ptr<ResourceTable> table = 46cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski test::ResourceTableBuilder() 47ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski .AddValue("android:^attr-private/foo", ResourceId(0x01010000), 48ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski test::AttributeBuilder().Build()) 49ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski .Build(); 50cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski 51ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski ResourceTableSymbolSource symbol_source(table.get()); 52cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski std::unique_ptr<SymbolTable::Symbol> s = 53ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski symbol_source.FindByName(test::ParseNameOrDie("android:attr/foo")); 54cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski ASSERT_NE(nullptr, s); 55cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski EXPECT_NE(nullptr, s->attribute); 561ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski} 571ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 58cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski} // namespace aapt 59