blob: a7a1013fd80954201de2859e76312c588acbf692 [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -07001/*
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 Lesinskid0f116b2016-07-08 15:00:32 -070018#include "test/Test.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070019
20namespace aapt {
21
22TEST(PrivateAttributeMoverTest, MovePrivateAttributes) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070023 std::unique_ptr<IAaptContext> context = test::ContextBuilder().build();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070024
Adam Lesinskicacb28f2016-10-19 12:18:14 -070025 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 Lesinski1ab598f2015-08-14 14:26:04 -070036
Adam Lesinskicacb28f2016-10-19 12:18:14 -070037 PrivateAttributeMover mover;
38 ASSERT_TRUE(mover.consume(context.get(), table.get()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070039
Adam Lesinskicacb28f2016-10-19 12:18:14 -070040 ResourceTablePackage* package = table->findPackage("android");
41 ASSERT_NE(package, nullptr);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070042
Adam Lesinskicacb28f2016-10-19 12:18:14 -070043 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 Lesinski1ab598f2015-08-14 14:26:04 -070048
Adam Lesinskicacb28f2016-10-19 12:18:14 -070049 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 Lesinski1ab598f2015-08-14 14:26:04 -070054}
55
Adam Lesinskicacb28f2016-10-19 12:18:14 -070056TEST(PrivateAttributeMoverTest,
57 LeavePrivateAttributesWhenNoPublicAttributesDefined) {
58 std::unique_ptr<IAaptContext> context = test::ContextBuilder().build();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070059
Adam Lesinskicacb28f2016-10-19 12:18:14 -070060 std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
61 .addSimple("android:attr/privateA")
62 .addSimple("android:attr/privateB")
63 .build();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070064
Adam Lesinskicacb28f2016-10-19 12:18:14 -070065 PrivateAttributeMover mover;
66 ASSERT_TRUE(mover.consume(context.get(), table.get()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070067
Adam Lesinskicacb28f2016-10-19 12:18:14 -070068 ResourceTablePackage* package = table->findPackage("android");
69 ASSERT_NE(package, nullptr);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070070
Adam Lesinskicacb28f2016-10-19 12:18:14 -070071 ResourceTableType* type = package->findType(ResourceType::kAttr);
72 ASSERT_NE(type, nullptr);
73 ASSERT_EQ(type->entries.size(), 2u);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070074
Adam Lesinskicacb28f2016-10-19 12:18:14 -070075 type = package->findType(ResourceType::kAttrPrivate);
76 ASSERT_EQ(type, nullptr);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070077}
78
Adam Lesinskicacb28f2016-10-19 12:18:14 -070079} // namespace aapt