Permalink
Browse files

Merge branch 'master' of github.com:pivotal/robolectric

  • Loading branch information...
2 parents dc05cf6 + a688379 commit f3643505ffe5953b3486f4c6a3dcdbde048b5df0 Phil Goodwin committed Oct 12, 2012
@@ -384,6 +384,8 @@ public static void logMissingInvokedShadowMethods() {
ShadowRadioGroup.class,
ShadowRatingBar.class,
ShadowRect.class,
+ ShadowRelativeLayout.class,
+ ShadowRelativeLayoutParams.class,
ShadowResolveInfo.class,
ShadowRemoteCallbackList.class,
ShadowRemoteViews.class,
@@ -0,0 +1,21 @@
+package com.xtremelabs.robolectric.shadows;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.ViewGroup;
+import android.widget.RelativeLayout;
+import com.xtremelabs.robolectric.internal.Implements;
+import com.xtremelabs.robolectric.tester.android.util.TestAttributeSet;
+
+@Implements(RelativeLayout.class)
+public class ShadowRelativeLayout extends ShadowViewGroup {
+
+ public void __constructor__(Context context) {
+ __constructor__(context, new TestAttributeSet(), 0);
+ }
+
+ public void __constructor__(Context context, AttributeSet attributeSet, int defStyle) {
+ setLayoutParams(new ViewGroup.MarginLayoutParams(0, 0));
+ super.__constructor__(context, attributeSet, defStyle);
+ }
+}
@@ -0,0 +1,29 @@
+package com.xtremelabs.robolectric.shadows;
+
+import android.widget.RelativeLayout;
+import com.xtremelabs.robolectric.internal.Implementation;
+import com.xtremelabs.robolectric.internal.Implements;
+
+/**
+ * Shadow for {@link android.view.ViewGroup.MarginLayoutParams} that simulates its implementation.
+ */
+@SuppressWarnings("UnusedDeclaration")
+@Implements(RelativeLayout.LayoutParams.class)
+public class ShadowRelativeLayoutParams extends ShadowLayoutParams {
+ int rules[] = new int[16]; // not the right way to do this
+
+ @Implementation
+ public void addRule(int verb) {
+ addRule(verb, -1);
+ }
+
+ @Implementation
+ public void addRule(int verb, int anchor) {
+ rules[verb] = anchor;
+ }
+
+ @Implementation
+ public int[] getRules() {
+ return rules;
+ }
+}
@@ -77,11 +77,12 @@ public void addView(View child, int width, int height) {
@Implementation
public void addView(View child, ViewGroup.LayoutParams params) {
- ((ViewGroup) realView).addView(child, -1);
+ ((ViewGroup) realView).addView(child, -1, params);
}
@Implementation
public void addView(View child, int index, ViewGroup.LayoutParams params) {
+ child.setLayoutParams(params);
((ViewGroup) realView).addView(child, index);
}
@@ -0,0 +1,28 @@
+package com.xtremelabs.robolectric.shadows;
+
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
+import com.xtremelabs.robolectric.Robolectric;
+import com.xtremelabs.robolectric.WithTestDefaultsRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Arrays;
+
+import static junit.framework.Assert.assertTrue;
+
+@RunWith(WithTestDefaultsRunner.class)
+public class RelativeLayoutTest {
+
+ @Test
+ public void getRules_shouldShowAddRuleData() throws Exception {
+ ImageView imageView = new ImageView(Robolectric.application);
+ RelativeLayout layout = new RelativeLayout(Robolectric.application);
+ layout.addView(imageView, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+ RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
+ layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
+ layoutParams.addRule(RelativeLayout.ALIGN_TOP, 1234);
+ assertTrue(Arrays.equals(new int[] { 0, 0, 0, 0, 0, 0, 1234, 0, 0, 0, 0, -1, 0, 0, 0, 0 }, layoutParams.getRules()));
+ }
+}
@@ -6,6 +6,7 @@
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.FrameLayout;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import com.xtremelabs.robolectric.R;
import com.xtremelabs.robolectric.Robolectric;
@@ -25,7 +26,10 @@
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
@RunWith(WithTestDefaultsRunner.class)
public class ViewGroupTest {
@@ -219,4 +223,16 @@ public void dump_shouldDumpStructure() throws Exception {
" </FrameLayout>\n" +
"</FrameLayout>\n", out.toString());
}
+
+ @Test
+ public void addViewWithLayoutParams_shouldStoreLayoutParams() throws Exception {
+ FrameLayout.LayoutParams layoutParams1 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ FrameLayout.LayoutParams layoutParams2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ ImageView child1 = new ImageView(Robolectric.application);
+ ImageView child2 = new ImageView(Robolectric.application);
+ root.addView(child1, layoutParams1);
+ root.addView(child2, 1, layoutParams2);
+ assertSame(layoutParams1, child1.getLayoutParams());
+ assertSame(layoutParams2, child2.getLayoutParams());
+ }
}

0 comments on commit f364350

Please sign in to comment.