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