1 /*
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 
25 using testing::Contains;
26 using testing::Eq;
27 
28 namespace aapt {
29 
30 bool ParseConfig(const std::string&, IAaptContext*, OptimizeOptions*);
31 
32 using OptimizeTest = CommandTestFixture;
33 
TEST_F(OptimizeTest,ParseConfigWithNoCollapseExemptions)34 TEST_F(OptimizeTest, ParseConfigWithNoCollapseExemptions) {
35   const std::string& content = R"(
36 string/foo#no_collapse
37 dimen/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 
TEST_F(OptimizeTest,ParseConfigWithNoObfuscateExemptions)51 TEST_F(OptimizeTest, ParseConfigWithNoObfuscateExemptions) {
52   const std::string& content = R"(
53 string/foo#no_obfuscate
54 dimen/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
69