Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 "java/ProguardRules.h" |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 18 | #include "link/Linkers.h" |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 19 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 20 | #include "io/StringStream.h" |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 21 | #include "test/Test.h" |
| 22 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 23 | using ::aapt::io::StringOutputStream; |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 24 | using ::testing::HasSubstr; |
| 25 | using ::testing::Not; |
| 26 | |
| 27 | namespace aapt { |
| 28 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 29 | std::string GetKeepSetString(const proguard::KeepSet& set) { |
| 30 | std::string out; |
| 31 | StringOutputStream sout(&out); |
| 32 | proguard::WriteKeepSet(set, &sout); |
| 33 | sout.Flush(); |
| 34 | return out; |
| 35 | } |
| 36 | |
Jake Wharton | ab660a7 | 2018-06-08 17:56:55 -0400 | [diff] [blame] | 37 | TEST(ProguardRulesTest, ManifestRuleDefaultConstructorOnly) { |
| 38 | std::unique_ptr<xml::XmlResource> manifest = test::BuildXmlDom(R"( |
| 39 | <manifest xmlns:android="http://schemas.android.com/apk/res/android"> |
| 40 | <application android:backupAgent="com.foo.BarBackupAgent"> |
| 41 | <activity android:name="com.foo.BarActivity"/> |
| 42 | <service android:name="com.foo.BarService"/> |
| 43 | <receiver android:name="com.foo.BarReceiver"/> |
| 44 | <provider android:name="com.foo.BarProvider"/> |
| 45 | </application> |
| 46 | <instrumentation android:name="com.foo.BarInstrumentation"/> |
| 47 | </manifest>)"); |
| 48 | |
| 49 | proguard::KeepSet set; |
| 50 | ASSERT_TRUE(proguard::CollectProguardRulesForManifest(manifest.get(), &set, false)); |
| 51 | |
| 52 | std::string actual = GetKeepSetString(set); |
| 53 | |
| 54 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarBackupAgent { <init>(); }")); |
| 55 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarActivity { <init>(); }")); |
| 56 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarService { <init>(); }")); |
| 57 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarReceiver { <init>(); }")); |
| 58 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarProvider { <init>(); }")); |
| 59 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.BarInstrumentation { <init>(); }")); |
| 60 | } |
| 61 | |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 62 | TEST(ProguardRulesTest, FragmentNameRuleIsEmitted) { |
| 63 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 64 | std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( |
| 65 | <fragment xmlns:android="http://schemas.android.com/apk/res/android" |
| 66 | android:name="com.foo.Bar"/>)"); |
| 67 | layout->file.name = test::ParseNameOrDie("layout/foo"); |
| 68 | |
| 69 | proguard::KeepSet set; |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 70 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), layout.get(), &set)); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 71 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 72 | std::string actual = GetKeepSetString(set); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 73 | |
Jake Wharton | 420785e | 2018-06-11 15:40:48 -0400 | [diff] [blame^] | 74 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | TEST(ProguardRulesTest, FragmentClassRuleIsEmitted) { |
| 78 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 79 | std::unique_ptr<xml::XmlResource> layout = |
| 80 | test::BuildXmlDom(R"(<fragment class="com.foo.Bar"/>)"); |
| 81 | layout->file.name = test::ParseNameOrDie("layout/foo"); |
| 82 | |
| 83 | proguard::KeepSet set; |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 84 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), layout.get(), &set)); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 85 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 86 | std::string actual = GetKeepSetString(set); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 87 | |
Jake Wharton | 420785e | 2018-06-11 15:40:48 -0400 | [diff] [blame^] | 88 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | TEST(ProguardRulesTest, FragmentNameAndClassRulesAreEmitted) { |
| 92 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 93 | std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( |
| 94 | <fragment xmlns:android="http://schemas.android.com/apk/res/android" |
| 95 | android:name="com.foo.Baz" |
| 96 | class="com.foo.Bar"/>)"); |
| 97 | layout->file.name = test::ParseNameOrDie("layout/foo"); |
| 98 | |
| 99 | proguard::KeepSet set; |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 100 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), layout.get(), &set)); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 101 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 102 | std::string actual = GetKeepSetString(set); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 103 | |
Jake Wharton | 420785e | 2018-06-11 15:40:48 -0400 | [diff] [blame^] | 104 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
| 105 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Baz { <init>(...); }")); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 108 | TEST(ProguardRulesTest, NavigationFragmentNameAndClassRulesAreEmitted) { |
| 109 | std::unique_ptr<IAaptContext> context = test::ContextBuilder() |
| 110 | .SetCompilationPackage("com.base").Build(); |
| 111 | std::unique_ptr<xml::XmlResource> navigation = test::BuildXmlDom(R"( |
| 112 | <navigation |
| 113 | xmlns:android="http://schemas.android.com/apk/res/android" |
| 114 | xmlns:app="http://schemas.android.com/apk/res-auto"> |
| 115 | <custom android:id="@id/foo" |
| 116 | android:name="com.package.Foo"/> |
| 117 | <fragment android:id="@id/bar" |
| 118 | android:name="com.package.Bar"> |
| 119 | <nested android:id="@id/nested" |
| 120 | android:name=".Nested"/> |
| 121 | </fragment> |
| 122 | </navigation> |
| 123 | )"); |
| 124 | |
| 125 | navigation->file.name = test::ParseNameOrDie("navigation/graph.xml"); |
| 126 | |
| 127 | proguard::KeepSet set; |
| 128 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), navigation.get(), &set)); |
| 129 | |
| 130 | std::string actual = GetKeepSetString(set); |
Jake Wharton | 420785e | 2018-06-11 15:40:48 -0400 | [diff] [blame^] | 131 | EXPECT_THAT(actual, HasSubstr("-keep class com.package.Foo { <init>(...); }")); |
| 132 | EXPECT_THAT(actual, HasSubstr("-keep class com.package.Bar { <init>(...); }")); |
| 133 | EXPECT_THAT(actual, HasSubstr("-keep class com.base.Nested { <init>(...); }")); |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 136 | TEST(ProguardRulesTest, CustomViewRulesAreEmitted) { |
| 137 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 138 | std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( |
| 139 | <View xmlns:android="http://schemas.android.com/apk/res/android"> |
| 140 | <com.foo.Bar /> |
| 141 | </View>)"); |
| 142 | layout->file.name = test::ParseNameOrDie("layout/foo"); |
| 143 | |
| 144 | proguard::KeepSet set; |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 145 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), layout.get(), &set)); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 146 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 147 | std::string actual = GetKeepSetString(set); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 148 | |
Jake Wharton | 420785e | 2018-06-11 15:40:48 -0400 | [diff] [blame^] | 149 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | TEST(ProguardRulesTest, IncludedLayoutRulesAreConditional) { |
| 153 | std::unique_ptr<xml::XmlResource> bar_layout = test::BuildXmlDom(R"( |
| 154 | <View xmlns:android="http://schemas.android.com/apk/res/android"> |
| 155 | <com.foo.Bar /> |
| 156 | </View>)"); |
| 157 | bar_layout->file.name = test::ParseNameOrDie("com.foo:layout/bar"); |
| 158 | |
| 159 | ResourceTable table; |
| 160 | StdErrDiagnostics errDiagnostics; |
| 161 | table.AddResource(bar_layout->file.name, ConfigDescription::DefaultConfig(), "", |
| 162 | util::make_unique<FileReference>(), &errDiagnostics); |
| 163 | |
| 164 | std::unique_ptr<IAaptContext> context = |
| 165 | test::ContextBuilder() |
| 166 | .SetCompilationPackage("com.foo") |
| 167 | .AddSymbolSource(util::make_unique<ResourceTableSymbolSource>(&table)) |
| 168 | .Build(); |
| 169 | |
| 170 | std::unique_ptr<xml::XmlResource> foo_layout = test::BuildXmlDom(R"( |
| 171 | <View xmlns:android="http://schemas.android.com/apk/res/android"> |
| 172 | <include layout="@layout/bar" /> |
| 173 | </View>)"); |
| 174 | foo_layout->file.name = test::ParseNameOrDie("com.foo:layout/foo"); |
| 175 | |
| 176 | XmlReferenceLinker xml_linker; |
| 177 | ASSERT_TRUE(xml_linker.Consume(context.get(), bar_layout.get())); |
| 178 | ASSERT_TRUE(xml_linker.Consume(context.get(), foo_layout.get())); |
| 179 | |
| 180 | proguard::KeepSet set = proguard::KeepSet(true); |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 181 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), bar_layout.get(), &set)); |
| 182 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), foo_layout.get(), &set)); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 183 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 184 | std::string actual = GetKeepSetString(set); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 185 | |
Adam Koski | 09ef94e | 2017-11-10 11:15:55 -0800 | [diff] [blame] | 186 | EXPECT_THAT(actual, HasSubstr("-if class **.R$layout")); |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 187 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 188 | EXPECT_THAT(actual, HasSubstr("int foo")); |
| 189 | EXPECT_THAT(actual, HasSubstr("int bar")); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | TEST(ProguardRulesTest, AliasedLayoutRulesAreConditional) { |
| 193 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 194 | std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( |
| 195 | <View xmlns:android="http://schemas.android.com/apk/res/android"> |
| 196 | <com.foo.Bar /> |
| 197 | </View>)"); |
| 198 | layout->file.name = test::ParseNameOrDie("layout/foo"); |
| 199 | |
| 200 | proguard::KeepSet set = proguard::KeepSet(true); |
| 201 | set.AddReference({test::ParseNameOrDie("layout/bar"), {}}, layout->file.name); |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 202 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), layout.get(), &set)); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 203 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 204 | std::string actual = GetKeepSetString(set); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 205 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 206 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
Adam Koski | 09ef94e | 2017-11-10 11:15:55 -0800 | [diff] [blame] | 207 | EXPECT_THAT(actual, HasSubstr("-if class **.R$layout")); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 208 | EXPECT_THAT(actual, HasSubstr("int foo")); |
| 209 | EXPECT_THAT(actual, HasSubstr("int bar")); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | TEST(ProguardRulesTest, NonLayoutReferencesAreUnconditional) { |
| 213 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 214 | std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( |
| 215 | <View xmlns:android="http://schemas.android.com/apk/res/android"> |
| 216 | <com.foo.Bar /> |
| 217 | </View>)"); |
| 218 | layout->file.name = test::ParseNameOrDie("layout/foo"); |
| 219 | |
| 220 | proguard::KeepSet set = proguard::KeepSet(true); |
| 221 | set.AddReference({test::ParseNameOrDie("style/MyStyle"), {}}, layout->file.name); |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 222 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), layout.get(), &set)); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 223 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 224 | std::string actual = GetKeepSetString(set); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 225 | |
Adam Koski | 09ef94e | 2017-11-10 11:15:55 -0800 | [diff] [blame] | 226 | EXPECT_THAT(actual, Not(HasSubstr("-if"))); |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 227 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
Adam Koski | dc21dea | 2017-07-21 10:55:27 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 230 | TEST(ProguardRulesTest, ViewOnClickRuleIsEmitted) { |
| 231 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 232 | std::unique_ptr<xml::XmlResource> layout = test::BuildXmlDom(R"( |
| 233 | <View xmlns:android="http://schemas.android.com/apk/res/android" |
| 234 | android:onClick="bar_method" />)"); |
| 235 | layout->file.name = test::ParseNameOrDie("layout/foo"); |
| 236 | |
| 237 | proguard::KeepSet set; |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 238 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), layout.get(), &set)); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 239 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 240 | std::string actual = GetKeepSetString(set); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 241 | |
Jake Wharton | 420785e | 2018-06-11 15:40:48 -0400 | [diff] [blame^] | 242 | EXPECT_THAT(actual, HasSubstr("-keepclassmembers class * { *** bar_method(...); }")); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | TEST(ProguardRulesTest, MenuRulesAreEmitted) { |
| 246 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 247 | std::unique_ptr<xml::XmlResource> menu = test::BuildXmlDom(R"( |
| 248 | <menu xmlns:android="http://schemas.android.com/apk/res/android"> |
| 249 | <item android:onClick="on_click" |
| 250 | android:actionViewClass="com.foo.Bar" |
| 251 | android:actionProviderClass="com.foo.Baz" |
| 252 | android:name="com.foo.Bat" /> |
| 253 | </menu>)"); |
| 254 | menu->file.name = test::ParseNameOrDie("menu/foo"); |
| 255 | |
| 256 | proguard::KeepSet set; |
Ryan Mitchell | 9a2f6e6 | 2018-05-23 14:23:18 -0700 | [diff] [blame] | 257 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), menu.get(), &set)); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 258 | |
Adam Lesinski | a693c4a | 2017-11-09 11:29:39 -0800 | [diff] [blame] | 259 | std::string actual = GetKeepSetString(set); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 260 | |
Jake Wharton | 420785e | 2018-06-11 15:40:48 -0400 | [diff] [blame^] | 261 | EXPECT_THAT(actual, HasSubstr("-keepclassmembers class * { *** on_click(...); }")); |
| 262 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
| 263 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Baz { <init>(...); }")); |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 264 | EXPECT_THAT(actual, Not(HasSubstr("com.foo.Bat"))); |
| 265 | } |
| 266 | |
Jake Wharton | 420785e | 2018-06-11 15:40:48 -0400 | [diff] [blame^] | 267 | TEST(ProguardRulesTest, TransitionPathMotionRulesAreEmitted) { |
| 268 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 269 | std::unique_ptr<xml::XmlResource> transition = test::BuildXmlDom(R"( |
| 270 | <changeBounds> |
| 271 | <pathMotion class="com.foo.Bar"/> |
| 272 | </changeBounds>)"); |
| 273 | transition->file.name = test::ParseNameOrDie("transition/foo"); |
| 274 | |
| 275 | proguard::KeepSet set; |
| 276 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), transition.get(), &set)); |
| 277 | |
| 278 | std::string actual = GetKeepSetString(set); |
| 279 | |
| 280 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
| 281 | } |
| 282 | |
| 283 | TEST(ProguardRulesTest, TransitionRulesAreEmitted) { |
| 284 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 285 | std::unique_ptr<xml::XmlResource> transitionSet = test::BuildXmlDom(R"( |
| 286 | <transitionSet> |
| 287 | <transition class="com.foo.Bar"/> |
| 288 | </transitionSet>)"); |
| 289 | transitionSet->file.name = test::ParseNameOrDie("transition/foo"); |
| 290 | |
| 291 | proguard::KeepSet set; |
| 292 | ASSERT_TRUE(proguard::CollectProguardRules(context.get(), transitionSet.get(), &set)); |
| 293 | |
| 294 | std::string actual = GetKeepSetString(set); |
| 295 | |
| 296 | EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }")); |
| 297 | } |
| 298 | |
Adam Lesinski | f762df2 | 2017-06-26 16:39:03 -0700 | [diff] [blame] | 299 | } // namespace aapt |