XmlIdCollector_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 "compile/XmlIdCollector.h" 181ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 19cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski#include <algorithm> 201ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 21ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski#include "test/Test.h" 22ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 231ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinskinamespace aapt { 241ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 251ab598f46c3ff520a67f9d80194847741f3467abAdam LesinskiTEST(XmlIdCollectorTest, CollectsIds) { 26ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); 271ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 28ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski std::unique_ptr<xml::XmlResource> doc = test::BuildXmlDom(R"EOF( 291ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski <View xmlns:android="http://schemas.android.com/apk/res/android" 301ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski android:id="@+id/foo" 311ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski text="@+id/bar"> 321ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski <SubView android:id="@+id/car" 331ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski class="@+id/bar"/> 341ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski </View>)EOF"); 351ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 36cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski XmlIdCollector collector; 37ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski ASSERT_TRUE(collector.Consume(context.get(), doc.get())); 381ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 39cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski EXPECT_EQ( 40ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 1, std::count(doc->file.exported_symbols.begin(), 41ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski doc->file.exported_symbols.end(), 42ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski SourcedResourceName{test::ParseNameOrDie("id/foo"), 3u})); 431ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 44cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski EXPECT_EQ( 45ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 1, std::count(doc->file.exported_symbols.begin(), 46ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski doc->file.exported_symbols.end(), 47ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski SourcedResourceName{test::ParseNameOrDie("id/bar"), 3u})); 481ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 49cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski EXPECT_EQ( 50ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski 1, std::count(doc->file.exported_symbols.begin(), 51ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski doc->file.exported_symbols.end(), 52ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski SourcedResourceName{test::ParseNameOrDie("id/car"), 6u})); 531ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski} 541ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 551ab598f46c3ff520a67f9d80194847741f3467abAdam LesinskiTEST(XmlIdCollectorTest, DontCollectNonIds) { 56ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); 571ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 58cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski std::unique_ptr<xml::XmlResource> doc = 59ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski test::BuildXmlDom("<View foo=\"@+string/foo\"/>"); 601ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 61cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski XmlIdCollector collector; 62ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski ASSERT_TRUE(collector.Consume(context.get(), doc.get())); 631ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 64ce5e56e243d262a9b65459c3bd0bb9eaadd40628Adam Lesinski EXPECT_TRUE(doc->file.exported_symbols.empty()); 651ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski} 661ab598f46c3ff520a67f9d80194847741f3467abAdam Lesinski 67cacb28f2d60858106e2819cc7d95a65e8bda890bAdam Lesinski} // namespace aapt 68