Skip to content

Commit

Permalink
Apparently styles can specify a parent of "Null".
Browse files Browse the repository at this point in the history
  • Loading branch information
xian committed Sep 12, 2016
1 parent 205b93d commit c28aa51
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Expand Up @@ -75,7 +75,7 @@ private static boolean hasParent(StyleData style) {
private StyleData getParent(StyleData style) {
String parent = getParentStyleName(style);

if (parent == null) return null;
if (parent == null || "Null".equals(parent)) return null;

if (parent.startsWith("@")) parent = parent.substring(1);

Expand Down
9 changes: 5 additions & 4 deletions robolectric/src/test/java/org/robolectric/R.java
Expand Up @@ -346,11 +346,12 @@ public static final class style {
public static final int Sized = 0x11007;
public static final int Gastropod = 0x11008;
public static final int Theme_ThirdTheme = 0x11009;
public static final int Theme_MyTheme = 0x1100a;
public static final int MyBlackTheme = 0x1100b;
public static final int MyBlueTheme = 0x1100c;
public static final int Theme_MyThemeWithEmptyParent = 0x1100a;
public static final int Theme_MyThemeWithNullStringParent = 0x1100b;
public static final int MyBlackTheme = 0x1100c;
public static final int MyBlueTheme = 0x1100d;

public static final int IndirectButtonStyle = 0x1100d;
public static final int IndirectButtonStyle = 0x1100e;
}

public static final class fraction {
Expand Down
Expand Up @@ -132,10 +132,17 @@ public class ShadowThemeTest {
TestActivity activity = Robolectric.setupActivity(TestActivityWithAnotherTheme.class);
Style style = shadowOf(activity.getAssets()).resolveStyle(
null,
R.style.Theme_MyTheme);
R.style.Theme_MyThemeWithEmptyParent);
assertThat(style.getAttrValue(new ResName("android", "attr", "background"))).isNull();
}

@Test public void whenAThemeHasNullStringParentAttr_shouldHaveNoParent() throws Exception {
TestActivity activity = Robolectric.setupActivity(TestActivityWithAnotherTheme.class);
Style style = shadowOf(activity.getAssets()).resolveStyle(
null,
R.style.Theme_MyThemeWithNullStringParent);
assertThat(style.getAttrValue(new ResName("android", "attr", "background"))).isNull();
}

@Test public void shouldApplyParentStylesFromAttrs() throws Exception {
TestActivity activity = Robolectric.setupActivity(TestActivityWithAnotherTheme.class);
Expand Down
3 changes: 2 additions & 1 deletion robolectric/src/test/resources/res/values/themes.xml
Expand Up @@ -20,7 +20,8 @@
<item name="someLayoutTwo">?someLayoutOne</item>
</style>

<style name="Theme.MyTheme" parent=""/>
<style name="Theme.MyThemeWithEmptyParent" parent=""/>
<style name="Theme.MyThemeWithNullStringParent" parent="Null"/>

<style name="Widget.Robolectric.Button" parent="@android:style/Widget.Button">
<item name="android:background">#ff00ff00</item>
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-resources.rb
Expand Up @@ -4,7 +4,7 @@
# add/change/remove resources in the src/test/resources/res folder.
#

path_to_r = "../robolectric/src/test/java/org/robolectric/R.java"
path_to_r = File.expand_path("../../robolectric/src/test/java/org/robolectric/R.java", __FILE__)
if path_to_r =~ /^\/path\/to/
raise "please change the path to this file!"
else
Expand Down

0 comments on commit c28aa51

Please sign in to comment.