Improve tests for ProGuard rules, add transition tests
Test: make aapt2_tests Change-Id: If3300a9f82ad90189b74aab03c0d7f649e74e3f3
This commit is contained in:
@@ -71,7 +71,7 @@ TEST(ProguardRulesTest, FragmentNameRuleIsEmitted) {
|
||||
|
||||
std::string actual = GetKeepSetString(set);
|
||||
|
||||
EXPECT_THAT(actual, HasSubstr("com.foo.Bar"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, FragmentClassRuleIsEmitted) {
|
||||
@@ -85,7 +85,7 @@ TEST(ProguardRulesTest, FragmentClassRuleIsEmitted) {
|
||||
|
||||
std::string actual = GetKeepSetString(set);
|
||||
|
||||
EXPECT_THAT(actual, HasSubstr("com.foo.Bar"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, FragmentNameAndClassRulesAreEmitted) {
|
||||
@@ -101,8 +101,8 @@ TEST(ProguardRulesTest, FragmentNameAndClassRulesAreEmitted) {
|
||||
|
||||
std::string actual = GetKeepSetString(set);
|
||||
|
||||
EXPECT_THAT(actual, HasSubstr("com.foo.Bar"));
|
||||
EXPECT_THAT(actual, HasSubstr("com.foo.Baz"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Baz { <init>(...); }"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, NavigationFragmentNameAndClassRulesAreEmitted) {
|
||||
@@ -128,9 +128,9 @@ TEST(ProguardRulesTest, NavigationFragmentNameAndClassRulesAreEmitted) {
|
||||
ASSERT_TRUE(proguard::CollectProguardRules(context.get(), navigation.get(), &set));
|
||||
|
||||
std::string actual = GetKeepSetString(set);
|
||||
EXPECT_THAT(actual, HasSubstr("com.package.Foo"));
|
||||
EXPECT_THAT(actual, HasSubstr("com.package.Bar"));
|
||||
EXPECT_THAT(actual, HasSubstr("com.base.Nested"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.package.Foo { <init>(...); }"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.package.Bar { <init>(...); }"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.base.Nested { <init>(...); }"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, CustomViewRulesAreEmitted) {
|
||||
@@ -146,7 +146,7 @@ TEST(ProguardRulesTest, CustomViewRulesAreEmitted) {
|
||||
|
||||
std::string actual = GetKeepSetString(set);
|
||||
|
||||
EXPECT_THAT(actual, HasSubstr("com.foo.Bar"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, IncludedLayoutRulesAreConditional) {
|
||||
@@ -187,7 +187,6 @@ TEST(ProguardRulesTest, IncludedLayoutRulesAreConditional) {
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }"));
|
||||
EXPECT_THAT(actual, HasSubstr("int foo"));
|
||||
EXPECT_THAT(actual, HasSubstr("int bar"));
|
||||
EXPECT_THAT(actual, HasSubstr("com.foo.Bar"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, AliasedLayoutRulesAreConditional) {
|
||||
@@ -208,7 +207,6 @@ TEST(ProguardRulesTest, AliasedLayoutRulesAreConditional) {
|
||||
EXPECT_THAT(actual, HasSubstr("-if class **.R$layout"));
|
||||
EXPECT_THAT(actual, HasSubstr("int foo"));
|
||||
EXPECT_THAT(actual, HasSubstr("int bar"));
|
||||
EXPECT_THAT(actual, HasSubstr("com.foo.Bar"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, NonLayoutReferencesAreUnconditional) {
|
||||
@@ -241,7 +239,7 @@ TEST(ProguardRulesTest, ViewOnClickRuleIsEmitted) {
|
||||
|
||||
std::string actual = GetKeepSetString(set);
|
||||
|
||||
EXPECT_THAT(actual, HasSubstr("bar_method"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keepclassmembers class * { *** bar_method(...); }"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, MenuRulesAreEmitted) {
|
||||
@@ -260,10 +258,42 @@ TEST(ProguardRulesTest, MenuRulesAreEmitted) {
|
||||
|
||||
std::string actual = GetKeepSetString(set);
|
||||
|
||||
EXPECT_THAT(actual, HasSubstr("on_click"));
|
||||
EXPECT_THAT(actual, HasSubstr("com.foo.Bar"));
|
||||
EXPECT_THAT(actual, HasSubstr("com.foo.Baz"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keepclassmembers class * { *** on_click(...); }"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }"));
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Baz { <init>(...); }"));
|
||||
EXPECT_THAT(actual, Not(HasSubstr("com.foo.Bat")));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, TransitionPathMotionRulesAreEmitted) {
|
||||
std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
|
||||
std::unique_ptr<xml::XmlResource> transition = test::BuildXmlDom(R"(
|
||||
<changeBounds>
|
||||
<pathMotion class="com.foo.Bar"/>
|
||||
</changeBounds>)");
|
||||
transition->file.name = test::ParseNameOrDie("transition/foo");
|
||||
|
||||
proguard::KeepSet set;
|
||||
ASSERT_TRUE(proguard::CollectProguardRules(context.get(), transition.get(), &set));
|
||||
|
||||
std::string actual = GetKeepSetString(set);
|
||||
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, TransitionRulesAreEmitted) {
|
||||
std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
|
||||
std::unique_ptr<xml::XmlResource> transitionSet = test::BuildXmlDom(R"(
|
||||
<transitionSet>
|
||||
<transition class="com.foo.Bar"/>
|
||||
</transitionSet>)");
|
||||
transitionSet->file.name = test::ParseNameOrDie("transition/foo");
|
||||
|
||||
proguard::KeepSet set;
|
||||
ASSERT_TRUE(proguard::CollectProguardRules(context.get(), transitionSet.get(), &set));
|
||||
|
||||
std::string actual = GetKeepSetString(set);
|
||||
|
||||
EXPECT_THAT(actual, HasSubstr("-keep class com.foo.Bar { <init>(...); }"));
|
||||
}
|
||||
|
||||
} // namespace aapt
|
||||
|
||||
Reference in New Issue
Block a user