blob: ac681e85b3d63f68541b836c60c2d4ff42142ef2 [file] [log] [blame]
Brian Changdcef8312019-09-13 11:38:32 -07001/*
2 * Copyright (C) 2019 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 "Optimize.h"
18
19#include "AppInfo.h"
20#include "Diagnostics.h"
21#include "LoadedApk.h"
22#include "Resource.h"
23#include "test/Test.h"
24
25using testing::Contains;
26using testing::Eq;
27
28namespace aapt {
29
30bool ParseConfig(const std::string&, IAaptContext*, OptimizeOptions*);
31
32using OptimizeTest = CommandTestFixture;
33
34TEST_F(OptimizeTest, ParseConfigWithNoCollapseExemptions) {
35 const std::string& content = R"(
36string/foo#no_collapse
37dimen/bar#no_collapse
38)";
39 aapt::test::Context context;
40 OptimizeOptions options;
41 ParseConfig(content, &context, &options);
42
43 const std::set<ResourceName>& name_collapse_exemptions =
44 options.table_flattener_options.name_collapse_exemptions;
45
46 ASSERT_THAT(name_collapse_exemptions.size(), Eq(2));
47 EXPECT_THAT(name_collapse_exemptions, Contains(ResourceName({}, ResourceType::kString, "foo")));
48 EXPECT_THAT(name_collapse_exemptions, Contains(ResourceName({}, ResourceType::kDimen, "bar")));
49}
50
51TEST_F(OptimizeTest, ParseConfigWithNoObfuscateExemptions) {
52 const std::string& content = R"(
53string/foo#no_obfuscate
54dimen/bar#no_obfuscate
55)";
56 aapt::test::Context context;
57 OptimizeOptions options;
58 ParseConfig(content, &context, &options);
59
60 const std::set<ResourceName>& name_collapse_exemptions =
61 options.table_flattener_options.name_collapse_exemptions;
62
63 ASSERT_THAT(name_collapse_exemptions.size(), Eq(2));
64 EXPECT_THAT(name_collapse_exemptions, Contains(ResourceName({}, ResourceType::kString, "foo")));
65 EXPECT_THAT(name_collapse_exemptions, Contains(ResourceName({}, ResourceType::kDimen, "bar")));
66}
67
68} // namespace aapt