blob: 47071a51bb733592939cc43fbc054dc35ddfe62e [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) {
24 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");
30
31 std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
32 .addString("android:string/dedupe", ResourceId{}, defaultConfig, "dedupe")
33 .addString("android:string/dedupe", ResourceId{}, enConfig, "dedupe")
34 .addString("android:string/dedupe", ResourceId{}, landConfig, "dedupe")
35 .addString("android:string/dedupe2", ResourceId{}, defaultConfig, "dedupe")
36 .addString("android:string/dedupe2", ResourceId{}, enConfig, "dedupe")
37 .addString("android:string/dedupe2", ResourceId{}, enV21Config, "keep")
38 .addString("android:string/dedupe2", ResourceId{}, landConfig, "dedupe")
39 .build();
40
41 ASSERT_TRUE(ResourceDeduper().consume(context.get(), table.get()));
42 EXPECT_EQ(
43 nullptr,
44 test::getValueForConfig<String>(table.get(), "android:string/dedupe", enConfig));
45 EXPECT_EQ(
46 nullptr,
47 test::getValueForConfig<String>(table.get(), "android:string/dedupe", landConfig));
48 EXPECT_EQ(
49 nullptr,
50 test::getValueForConfig<String>(table.get(), "android:string/dedupe2", enConfig));
51 EXPECT_NE(
52 nullptr,
53 test::getValueForConfig<String>(table.get(), "android:string/dedupe2", enV21Config));
54}
55
56TEST(ResourceDeduperTest, DifferentValuesAreKept) {
57 std::unique_ptr<IAaptContext> context = test::ContextBuilder().build();
58 const ConfigDescription defaultConfig = {};
59 const ConfigDescription enConfig = test::parseConfigOrDie("en");
60 const ConfigDescription enV21Config = test::parseConfigOrDie("en-v21");
61 // Chosen because this configuration is compatible with en.
62 const ConfigDescription landConfig = test::parseConfigOrDie("land");
63
64 std::unique_ptr<ResourceTable> table = test::ResourceTableBuilder()
65 .addString("android:string/keep", ResourceId{}, defaultConfig, "keep")
66 .addString("android:string/keep", ResourceId{}, enConfig, "keep")
67 .addString("android:string/keep", ResourceId{}, enV21Config, "keep2")
68 .addString("android:string/keep", ResourceId{}, landConfig, "keep2")
69 .build();
70
71 ASSERT_TRUE(ResourceDeduper().consume(context.get(), table.get()));
72 EXPECT_NE(
73 nullptr,
74 test::getValueForConfig<String>(table.get(), "android:string/keep", enConfig));
75 EXPECT_NE(
76 nullptr,
77 test::getValueForConfig<String>(table.get(), "android:string/keep", enV21Config));
78 EXPECT_NE(
79 nullptr,
80 test::getValueForConfig<String>(table.get(), "android:string/keep", landConfig));
81}
82
83} // namespace aapt