Home | History | Annotate | Download | only in link
      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 "link/Linkers.h"
     18 #include "test/Builders.h"
     19 #include "test/Context.h"
     20 
     21 #include <gtest/gtest.h>
     22 
     23 namespace aapt {
     24 
     25 TEST(PrivateAttributeMoverTest, MovePrivateAttributes) {
     26     std::unique_ptr<IAaptContext> context = test::ContextBuilder().build();
     27 
     28     std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
     29             .addSimple(u"@android:attr/publicA")
     30             .addSimple(u"@android:attr/privateA")
     31             .addSimple(u"@android:attr/publicB")
     32             .addSimple(u"@android:attr/privateB")
     33             .setSymbolState(u"@android:attr/publicA", ResourceId(0x01010000), SymbolState::kPublic)
     34             .setSymbolState(u"@android:attr/publicB", ResourceId(0x01010000), SymbolState::kPublic)
     35             .build();
     36 
     37     PrivateAttributeMover mover;
     38     ASSERT_TRUE(mover.consume(context.get(), table.get()));
     39 
     40     ResourceTablePackage* package = table->findPackage(u"android");
     41     ASSERT_NE(package, nullptr);
     42 
     43     ResourceTableType* type = package->findType(ResourceType::kAttr);
     44     ASSERT_NE(type, nullptr);
     45     ASSERT_EQ(type->entries.size(), 2u);
     46     EXPECT_NE(type->findEntry(u"publicA"), nullptr);
     47     EXPECT_NE(type->findEntry(u"publicB"), nullptr);
     48 
     49     type = package->findType(ResourceType::kAttrPrivate);
     50     ASSERT_NE(type, nullptr);
     51     ASSERT_EQ(type->entries.size(), 2u);
     52     EXPECT_NE(type->findEntry(u"privateA"), nullptr);
     53     EXPECT_NE(type->findEntry(u"privateB"), nullptr);
     54 }
     55 
     56 TEST(PrivateAttributeMoverTest, LeavePrivateAttributesWhenNoPublicAttributesDefined) {
     57     std::unique_ptr<IAaptContext> context = test::ContextBuilder().build();
     58 
     59     std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
     60             .addSimple(u"@android:attr/privateA")
     61             .addSimple(u"@android:attr/privateB")
     62             .build();
     63 
     64     PrivateAttributeMover mover;
     65     ASSERT_TRUE(mover.consume(context.get(), table.get()));
     66 
     67     ResourceTablePackage* package = table->findPackage(u"android");
     68     ASSERT_NE(package, nullptr);
     69 
     70     ResourceTableType* type = package->findType(ResourceType::kAttr);
     71     ASSERT_NE(type, nullptr);
     72     ASSERT_EQ(type->entries.size(), 2u);
     73 
     74     type = package->findType(ResourceType::kAttrPrivate);
     75     ASSERT_EQ(type, nullptr);
     76 }
     77 
     78 } // namespace aapt
     79