blob: 90c4922625be00ca5b79a575efe73092eb75d8ee [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 Lesinskice5e56e2016-10-21 17:56:45 -070018
Adam Lesinskid0f116b2016-07-08 15:00:32 -070019#include "test/Test.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070020
21namespace aapt {
22
23TEST(PrivateAttributeMoverTest, MovePrivateAttributes) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070024 std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070025
Adam Lesinskicacb28f2016-10-19 12:18:14 -070026 std::unique_ptr<ResourceTable> table =
27 test::ResourceTableBuilder()
Adam Lesinskice5e56e2016-10-21 17:56:45 -070028 .AddSimple("android:attr/publicA")
29 .AddSimple("android:attr/privateA")
30 .AddSimple("android:attr/publicB")
31 .AddSimple("android:attr/privateB")
32 .SetSymbolState("android:attr/publicA", ResourceId(0x01010000),
Adam Lesinskicacb28f2016-10-19 12:18:14 -070033 SymbolState::kPublic)
Adam Lesinskice5e56e2016-10-21 17:56:45 -070034 .SetSymbolState("android:attr/publicB", ResourceId(0x01010000),
Adam Lesinskicacb28f2016-10-19 12:18:14 -070035 SymbolState::kPublic)
Adam Lesinskice5e56e2016-10-21 17:56:45 -070036 .Build();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070037
Adam Lesinskicacb28f2016-10-19 12:18:14 -070038 PrivateAttributeMover mover;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070039 ASSERT_TRUE(mover.Consume(context.get(), table.get()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070040
Adam Lesinskice5e56e2016-10-21 17:56:45 -070041 ResourceTablePackage* package = table->FindPackage("android");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070042 ASSERT_NE(package, nullptr);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070043
Adam Lesinskice5e56e2016-10-21 17:56:45 -070044 ResourceTableType* type = package->FindType(ResourceType::kAttr);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070045 ASSERT_NE(type, nullptr);
46 ASSERT_EQ(type->entries.size(), 2u);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070047 EXPECT_NE(type->FindEntry("publicA"), nullptr);
48 EXPECT_NE(type->FindEntry("publicB"), nullptr);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070049
Adam Lesinskice5e56e2016-10-21 17:56:45 -070050 type = package->FindType(ResourceType::kAttrPrivate);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070051 ASSERT_NE(type, nullptr);
52 ASSERT_EQ(type->entries.size(), 2u);
Adam Lesinskice5e56e2016-10-21 17:56:45 -070053 EXPECT_NE(type->FindEntry("privateA"), nullptr);
54 EXPECT_NE(type->FindEntry("privateB"), nullptr);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070055}
56
Adam Lesinskicacb28f2016-10-19 12:18:14 -070057TEST(PrivateAttributeMoverTest,
58 LeavePrivateAttributesWhenNoPublicAttributesDefined) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070059 std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070060
Adam Lesinskicacb28f2016-10-19 12:18:14 -070061 std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
Adam Lesinskice5e56e2016-10-21 17:56:45 -070062 .AddSimple("android:attr/privateA")
63 .AddSimple("android:attr/privateB")
64 .Build();
Adam Lesinski1ab598f2015-08-14 14:26:04 -070065
Adam Lesinskicacb28f2016-10-19 12:18:14 -070066 PrivateAttributeMover mover;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070067 ASSERT_TRUE(mover.Consume(context.get(), table.get()));
Adam Lesinski1ab598f2015-08-14 14:26:04 -070068
Adam Lesinskice5e56e2016-10-21 17:56:45 -070069 ResourceTablePackage* package = table->FindPackage("android");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070070 ASSERT_NE(package, nullptr);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070071
Adam Lesinskice5e56e2016-10-21 17:56:45 -070072 ResourceTableType* type = package->FindType(ResourceType::kAttr);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070073 ASSERT_NE(type, nullptr);
74 ASSERT_EQ(type->entries.size(), 2u);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070075
Adam Lesinskice5e56e2016-10-21 17:56:45 -070076 type = package->FindType(ResourceType::kAttrPrivate);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070077 ASSERT_EQ(type, nullptr);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070078}
79
Adam Lesinskicacb28f2016-10-19 12:18:14 -070080} // namespace aapt