XmlIdCollector_test.cpp revision cacb28f2d60858106e2819cc7d95a65e8bda890b
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 "compile/XmlIdCollector.h" 18#include "test/Builders.h" 19#include "test/Context.h" 20 21#include <gtest/gtest.h> 22#include <algorithm> 23 24namespace aapt { 25 26TEST(XmlIdCollectorTest, CollectsIds) { 27 std::unique_ptr<IAaptContext> context = test::ContextBuilder().build(); 28 29 std::unique_ptr<xml::XmlResource> doc = test::buildXmlDom(R"EOF( 30 <View xmlns:android="http://schemas.android.com/apk/res/android" 31 android:id="@+id/foo" 32 text="@+id/bar"> 33 <SubView android:id="@+id/car" 34 class="@+id/bar"/> 35 </View>)EOF"); 36 37 XmlIdCollector collector; 38 ASSERT_TRUE(collector.consume(context.get(), doc.get())); 39 40 EXPECT_EQ( 41 1, std::count(doc->file.exportedSymbols.begin(), 42 doc->file.exportedSymbols.end(), 43 SourcedResourceName{test::parseNameOrDie("id/foo"), 3u})); 44 45 EXPECT_EQ( 46 1, std::count(doc->file.exportedSymbols.begin(), 47 doc->file.exportedSymbols.end(), 48 SourcedResourceName{test::parseNameOrDie("id/bar"), 3u})); 49 50 EXPECT_EQ( 51 1, std::count(doc->file.exportedSymbols.begin(), 52 doc->file.exportedSymbols.end(), 53 SourcedResourceName{test::parseNameOrDie("id/car"), 6u})); 54} 55 56TEST(XmlIdCollectorTest, DontCollectNonIds) { 57 std::unique_ptr<IAaptContext> context = test::ContextBuilder().build(); 58 59 std::unique_ptr<xml::XmlResource> doc = 60 test::buildXmlDom("<View foo=\"@+string/foo\"/>"); 61 62 XmlIdCollector collector; 63 ASSERT_TRUE(collector.consume(context.get(), doc.get())); 64 65 EXPECT_TRUE(doc->file.exportedSymbols.empty()); 66} 67 68} // namespace aapt 69