summaryrefslogtreecommitdiff
path: root/tools/aapt2/optimize/ResourceDeduper_test.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-02-21 14:22:30 -0800
committerAdam Lesinski <adamlesinski@google.com>2017-02-22 11:41:55 -0800
commitd48944a745f9ed121e6bde22ef6feb3a44fbec39 (patch)
tree349c152caa68f1283535b2f9c49f5cd8a50eb59b /tools/aapt2/optimize/ResourceDeduper_test.cpp
parentceb9b2f80f853059233cdd29057f39a5960a74ae (diff)
AAPT2: Rename strip phase to optimize
- Allow resource deduping, version collapsing, and sparse resource encoding. Test: manual Change-Id: Ia4aa892ab5b06ba1d5ea4a6efb51b00bc3a980c4
Diffstat (limited to 'tools/aapt2/optimize/ResourceDeduper_test.cpp')
-rw-r--r--tools/aapt2/optimize/ResourceDeduper_test.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/tools/aapt2/optimize/ResourceDeduper_test.cpp b/tools/aapt2/optimize/ResourceDeduper_test.cpp
new file mode 100644
index 000000000000..4d00fa6efe37
--- /dev/null
+++ b/tools/aapt2/optimize/ResourceDeduper_test.cpp
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "optimize/ResourceDeduper.h"
+
+#include "ResourceTable.h"
+#include "test/Test.h"
+
+namespace aapt {
+
+TEST(ResourceDeduperTest, SameValuesAreDeduped) {
+ std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
+ const ConfigDescription default_config = {};
+ const ConfigDescription en_config = test::ParseConfigOrDie("en");
+ const ConfigDescription en_v21_config = test::ParseConfigOrDie("en-v21");
+ // Chosen because this configuration is compatible with en.
+ const ConfigDescription land_config = test::ParseConfigOrDie("land");
+
+ std::unique_ptr<ResourceTable> table =
+ test::ResourceTableBuilder()
+ .AddString("android:string/dedupe", ResourceId{}, default_config,
+ "dedupe")
+ .AddString("android:string/dedupe", ResourceId{}, en_config, "dedupe")
+ .AddString("android:string/dedupe", ResourceId{}, land_config,
+ "dedupe")
+ .AddString("android:string/dedupe2", ResourceId{}, default_config,
+ "dedupe")
+ .AddString("android:string/dedupe2", ResourceId{}, en_config,
+ "dedupe")
+ .AddString("android:string/dedupe2", ResourceId{}, en_v21_config,
+ "keep")
+ .AddString("android:string/dedupe2", ResourceId{}, land_config,
+ "dedupe")
+ .Build();
+
+ ASSERT_TRUE(ResourceDeduper().Consume(context.get(), table.get()));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<String>(
+ table.get(), "android:string/dedupe", en_config));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<String>(
+ table.get(), "android:string/dedupe", land_config));
+ EXPECT_EQ(nullptr, test::GetValueForConfig<String>(
+ table.get(), "android:string/dedupe2", en_config));
+ EXPECT_NE(nullptr, test::GetValueForConfig<String>(
+ table.get(), "android:string/dedupe2", en_v21_config));
+}
+
+TEST(ResourceDeduperTest, DifferentValuesAreKept) {
+ std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
+ const ConfigDescription default_config = {};
+ const ConfigDescription en_config = test::ParseConfigOrDie("en");
+ const ConfigDescription en_v21_config = test::ParseConfigOrDie("en-v21");
+ // Chosen because this configuration is compatible with en.
+ const ConfigDescription land_config = test::ParseConfigOrDie("land");
+
+ std::unique_ptr<ResourceTable> table =
+ test::ResourceTableBuilder()
+ .AddString("android:string/keep", ResourceId{}, default_config,
+ "keep")
+ .AddString("android:string/keep", ResourceId{}, en_config, "keep")
+ .AddString("android:string/keep", ResourceId{}, en_v21_config,
+ "keep2")
+ .AddString("android:string/keep", ResourceId{}, land_config, "keep2")
+ .Build();
+
+ ASSERT_TRUE(ResourceDeduper().Consume(context.get(), table.get()));
+ EXPECT_NE(nullptr, test::GetValueForConfig<String>(
+ table.get(), "android:string/keep", en_config));
+ EXPECT_NE(nullptr, test::GetValueForConfig<String>(
+ table.get(), "android:string/keep", en_v21_config));
+ EXPECT_NE(nullptr, test::GetValueForConfig<String>(
+ table.get(), "android:string/keep", land_config));
+}
+
+} // namespace aapt