blob: 7e2d47665c85b083277d290836ee49593c8bd549 [file] [log] [blame]
Alexandria Cornwall77788eb2016-09-06 15:16:49 -07001/*
2 * Copyright (C) 2016 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 "ResourceTable.h"
18#include "link/Linkers.h"
19#include "test/Test.h"
20
21namespace aapt {
22
23TEST(ResourceDeduperTest, SameValuesAreDeduped) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070024 std::unique_ptr<IAaptContext> context = test::ContextBuilder().build();
25 const ConfigDescription defaultConfig = {};
26 const ConfigDescription enConfig = test::parseConfigOrDie("en");
27 const ConfigDescription enV21Config = test::parseConfigOrDie("en-v21");
28 // Chosen because this configuration is compatible with en.
29 const ConfigDescription landConfig = test::parseConfigOrDie("land");
Alexandria Cornwall77788eb2016-09-06 15:16:49 -070030
Adam Lesinskicacb28f2016-10-19 12:18:14 -070031 std::unique_ptr<ResourceTable> table =
32 test::ResourceTableBuilder()
33 .addString("android:string/dedupe", ResourceId{}, defaultConfig,
34 "dedupe")
35 .addString("android:string/dedupe", ResourceId{}, enConfig, "dedupe")
36 .addString("android:string/dedupe", ResourceId{}, landConfig,
37 "dedupe")
38 .addString("android:string/dedupe2", ResourceId{}, defaultConfig,
39 "dedupe")
40 .addString("android:string/dedupe2", ResourceId{}, enConfig, "dedupe")
41 .addString("android:string/dedupe2", ResourceId{}, enV21Config,
42 "keep")
43 .addString("android:string/dedupe2", ResourceId{}, landConfig,
44 "dedupe")
45 .build();
Alexandria Cornwall77788eb2016-09-06 15:16:49 -070046
Adam Lesinskicacb28f2016-10-19 12:18:14 -070047 ASSERT_TRUE(ResourceDeduper().consume(context.get(), table.get()));
48 EXPECT_EQ(nullptr, test::getValueForConfig<String>(
49 table.get(), "android:string/dedupe", enConfig));
50 EXPECT_EQ(nullptr, test::getValueForConfig<String>(
51 table.get(), "android:string/dedupe", landConfig));
52 EXPECT_EQ(nullptr, test::getValueForConfig<String>(
53 table.get(), "android:string/dedupe2", enConfig));
54 EXPECT_NE(nullptr, test::getValueForConfig<String>(
55 table.get(), "android:string/dedupe2", enV21Config));
Alexandria Cornwall77788eb2016-09-06 15:16:49 -070056}
57
58TEST(ResourceDeduperTest, DifferentValuesAreKept) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070059 std::unique_ptr<IAaptContext> context = test::ContextBuilder().build();
60 const ConfigDescription defaultConfig = {};
61 const ConfigDescription enConfig = test::parseConfigOrDie("en");
62 const ConfigDescription enV21Config = test::parseConfigOrDie("en-v21");
63 // Chosen because this configuration is compatible with en.
64 const ConfigDescription landConfig = test::parseConfigOrDie("land");
Alexandria Cornwall77788eb2016-09-06 15:16:49 -070065
Adam Lesinskicacb28f2016-10-19 12:18:14 -070066 std::unique_ptr<ResourceTable> table =
67 test::ResourceTableBuilder()
68 .addString("android:string/keep", ResourceId{}, defaultConfig, "keep")
69 .addString("android:string/keep", ResourceId{}, enConfig, "keep")
70 .addString("android:string/keep", ResourceId{}, enV21Config, "keep2")
71 .addString("android:string/keep", ResourceId{}, landConfig, "keep2")
72 .build();
Alexandria Cornwall77788eb2016-09-06 15:16:49 -070073
Adam Lesinskicacb28f2016-10-19 12:18:14 -070074 ASSERT_TRUE(ResourceDeduper().consume(context.get(), table.get()));
75 EXPECT_NE(nullptr, test::getValueForConfig<String>(
76 table.get(), "android:string/keep", enConfig));
77 EXPECT_NE(nullptr, test::getValueForConfig<String>(
78 table.get(), "android:string/keep", enV21Config));
79 EXPECT_NE(nullptr, test::getValueForConfig<String>(
80 table.get(), "android:string/keep", landConfig));
Alexandria Cornwall77788eb2016-09-06 15:16:49 -070081}
82
83} // namespace aapt