Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/pivotal/robolectric into ro…
Browse files Browse the repository at this point in the history
…bo-staging
  • Loading branch information
Wenhui Yao committed Oct 1, 2012
2 parents aa04a45 + 82530f1 commit ed0782d
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 37 deletions.
6 changes: 3 additions & 3 deletions build.xml
Expand Up @@ -217,13 +217,13 @@

<target name="maven-install-jars" description="Install the jar files that Maven can't find for itself">
<exec executable="mvn">
<arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=${sdk.dir}/add-ons/addon_google_apis_google_inc_10/libs/maps.jar" />
<arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=${sdk.dir}/add-ons/addon_google_apis_google_inc_16/libs/maps.jar" />
</exec>
<exec executable="mvn">
<arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=${sdk.dir}/add-ons/addon-google_apis-google_inc_-10/libs/maps.jar" />
<arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=${sdk.dir}/add-ons/addon-google_apis-google_inc_-16/libs/maps.jar" />
</exec>
<exec executable="mvn">
<arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=${sdk.dir}/add-ons/addon-google_apis-google-10/libs/maps.jar" />
<arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=${sdk.dir}/add-ons/addon-google_apis-google-16/libs/maps.jar" />
</exec>
</target>

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/android/webkit/TestWebSettings.java
Expand Up @@ -29,22 +29,18 @@ public class TestWebSettings extends WebSettings {
public TestWebSettings() {
}

@Override
public boolean getAllowFileAccessFromFileURLs() {
return allowFileAccessFromFile;
}

@Override
public boolean getAllowUniversalAccessFromFileURLs() {
return allowUniversalAccessFromFile;
}

@Override
public void setAllowFileAccessFromFileURLs(boolean allow) {
allowFileAccessFromFile = allow;
}

@Override
public void setAllowUniversalAccessFromFileURLs(boolean allow) {
allowUniversalAccessFromFile = allow;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/xtremelabs/robolectric/Robolectric.java
Expand Up @@ -74,6 +74,7 @@

public class Robolectric {
public static Application application;
public static final int DEFAULT_SDK_VERSION = 16;

public static <T> T newInstanceOf(Class<T> clazz) {
return RobolectricInternals.newInstanceOf(clazz);
Expand Down
Expand Up @@ -14,6 +14,7 @@
import java.util.List;

import static android.content.pm.ApplicationInfo.*;
import static com.xtremelabs.robolectric.Robolectric.DEFAULT_SDK_VERSION;

public class RobolectricConfig {
private final File androidManifestFile;
Expand Down Expand Up @@ -92,13 +93,13 @@ private void parseAndroidManifest() {
Integer minSdkVer = getTagAttributeIntValue(manifestDocument, "uses-sdk", "android:minSdkVersion");
Integer sdkVer = getTagAttributeIntValue(manifestDocument, "uses-sdk", "android:targetSdkVersion");
if (minSdkVer == null) {
minSdkVersion = 10;
minSdkVersion = DEFAULT_SDK_VERSION;
minSdkVersionSpecified = false;
} else {
minSdkVersion = minSdkVer;
}
if (sdkVer == null) {
sdkVersion = 10;
sdkVersion = DEFAULT_SDK_VERSION;
sdkVersionSpecified = false;
} else {
sdkVersion = sdkVer;
Expand Down
Expand Up @@ -39,7 +39,7 @@ public static Bitmap decodeResource(Resources res, int id, BitmapFactory.Options
shadowOf(bitmap).setLoadedFromResourceId(id);
return bitmap;
}

private static String getResourceName(int id) {
return shadowOf(Robolectric.application).getResourceLoader().getNameForId(id);
}
Expand Down Expand Up @@ -98,8 +98,10 @@ public static Bitmap create(String name, BitmapFactory.Options options) {

shadowBitmap.setWidth(widthAndHeight.x);
shadowBitmap.setHeight(widthAndHeight.y);
options.outWidth = widthAndHeight.x;
options.outHeight = widthAndHeight.y;
if (options != null) {
options.outWidth = widthAndHeight.x;
options.outHeight = widthAndHeight.y;
}
return bitmap;
}

Expand All @@ -116,6 +118,7 @@ public static void provideWidthAndHeightHints(String file, int width, int height
}

private static String stringify(BitmapFactory.Options options) {
if (options == null) return "";
List<String> opts = new ArrayList<String>();

if (options.inJustDecodeBounds) opts.add("inJustDecodeBounds");
Expand Down
Expand Up @@ -15,9 +15,9 @@
@SuppressWarnings({"UnusedDeclaration"})
@Implements(BluetoothAdapter.class)
public class ShadowBluetoothAdapter {

private Set<BluetoothDevice> bondedDevices = new HashSet<BluetoothDevice>();
private boolean isDiscovering;
private String address;

@Implementation
public static BluetoothAdapter getDefaultAdapter() {
Expand Down Expand Up @@ -50,4 +50,12 @@ public boolean isDiscovering() {
return isDiscovering;
}

@Implementation
public String getAddress() {
return this.address;
}

public void setAddress(String address) {
this.address = address;
}
}
Expand Up @@ -202,8 +202,13 @@ public Intent putExtras(Intent src) {

@Implementation
public Bundle getExtras() {
if (extras.isEmpty()) {
return null;
}

Bundle bundle = new Bundle();
((ShadowBundle) Robolectric.shadowOf_(bundle)).map.putAll(extras);
Map<String, Object> map = ((ShadowBundle) Robolectric.shadowOf_(bundle)).map;
map.putAll(extras);
return bundle;
}

Expand Down
Expand Up @@ -119,7 +119,7 @@ public long insertWithOnConflict(String table, String nullColumnHack,
resultSet.close();
return result;
} catch (SQLException e) {
throw new android.database.SQLException(e.getLocalizedMessage(), e);
throw new android.database.SQLException(e.getLocalizedMessage());
}
}

Expand Down
Expand Up @@ -44,7 +44,7 @@ public void setup() throws Exception {
@Test
public void testProcessResourceXml() throws Exception {
assertTrue("drawable/rainbow", resourceLoader.documents.containsKey("drawable/rainbow"));
assertEquals("documents.size", 116, resourceLoader.documents.size());
assertEquals("documents.size", 218, resourceLoader.documents.size());
}

@Test
Expand Down
@@ -1,34 +1,33 @@
package com.xtremelabs.robolectric.res;


import static com.xtremelabs.robolectric.util.TestUtil.resourceFile;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;

import android.view.MenuItem;

import com.xtremelabs.robolectric.R;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.WithTestDefaultsRunner;
import com.xtremelabs.robolectric.tester.android.view.TestMenu;
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.xtremelabs.robolectric.Robolectric.DEFAULT_SDK_VERSION;
import static com.xtremelabs.robolectric.util.TestUtil.resourceFile;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@RunWith(WithTestDefaultsRunner.class)
public class MenuResourceLoaderTest {

@Test
public void shouldInflateComplexMenu() throws Exception {
ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("menu"));
ResourceLoader resourceLoader = new ResourceLoader(DEFAULT_SDK_VERSION, R.class, resourceFile("res"), resourceFile("menu"));
TestMenu testMenu = new TestMenu();
resourceLoader.inflateMenu(Robolectric.application, R.menu.test_withchilds, testMenu);
assertThat(testMenu.size(), equalTo(4));
}

@Test
public void shouldParseSubItemCorrectly() throws Exception {
ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("menu"));
ResourceLoader resourceLoader = new ResourceLoader(DEFAULT_SDK_VERSION, R.class, resourceFile("res"), resourceFile("menu"));
TestMenu testMenu = new TestMenu();
resourceLoader.inflateMenu(Robolectric.application, R.menu.test_withchilds, testMenu);
MenuItem mi = testMenu.findItem(R.id.test_submenu_1);
Expand Down
Expand Up @@ -13,6 +13,7 @@

import java.io.File;

import static com.xtremelabs.robolectric.Robolectric.DEFAULT_SDK_VERSION;
import static com.xtremelabs.robolectric.util.TestUtil.resourceFile;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
Expand All @@ -26,7 +27,7 @@ public void shouldUseFileSystemSeparatorWhenEvaluatingLayoutDirectories() throws

@Test
public void shouldLoadSystemResources() throws Exception {
ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("assets"));
ResourceLoader resourceLoader = new ResourceLoader(DEFAULT_SDK_VERSION, R.class, resourceFile("res"), resourceFile("assets"));
String stringValue = resourceLoader.getStringValue(android.R.string.copy);
assertEquals("Copy", stringValue);

Expand All @@ -36,36 +37,36 @@ public void shouldLoadSystemResources() throws Exception {

@Test
public void shouldLoadLocalResources() throws Exception {
ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("assets"));
ResourceLoader resourceLoader = new ResourceLoader(DEFAULT_SDK_VERSION, R.class, resourceFile("res"), resourceFile("assets"));
String stringValue = resourceLoader.getStringValue(R.string.copy);
assertEquals("Local Copy", stringValue);
}

@Test(expected=I18nException.class)
public void shouldThrowExceptionOnI18nStrictModeInflateView() throws Exception {
ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("layout"));
ResourceLoader resourceLoader = new ResourceLoader(DEFAULT_SDK_VERSION, R.class, resourceFile("res"), resourceFile("layout"));
resourceLoader.setStrictI18n(true);
ViewGroup vg = new FrameLayout(Robolectric.application);
resourceLoader.inflateView(Robolectric.application, R.layout.text_views, vg);
}

@Test(expected=I18nException.class)
public void shouldThrowExceptionOnI18nStrictModeInflateMenu() throws Exception {
ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("menu"));
ResourceLoader resourceLoader = new ResourceLoader(DEFAULT_SDK_VERSION, R.class, resourceFile("res"), resourceFile("menu"));
resourceLoader.setStrictI18n(true);
resourceLoader.inflateMenu(Robolectric.application, R.menu.test, null);
}

@Test(expected=I18nException.class)
public void shouldThrowExceptionOnI18nStrictModeInflatePreferences() throws Exception {
ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("xml"));
ResourceLoader resourceLoader = new ResourceLoader(DEFAULT_SDK_VERSION, R.class, resourceFile("res"), resourceFile("xml"));
resourceLoader.setStrictI18n(true);
resourceLoader.inflatePreferences(Robolectric.application, R.xml.preferences);
}

@Test
public void testChoosesLayoutBasedOnSearchPath_respectsOrderOfPath() throws Exception {
ResourceLoader resourceLoader = new ResourceLoader(10, R.class, resourceFile("res"), resourceFile("layout"));
ResourceLoader resourceLoader = new ResourceLoader(DEFAULT_SDK_VERSION, R.class, resourceFile("res"), resourceFile("layout"));
resourceLoader.setLayoutQualifierSearchPath("does-not-exist", "land", "xlarge");
ViewGroup viewGroup = new FrameLayout(Robolectric.application);
ViewGroup view = (ViewGroup) resourceLoader.inflateView(Robolectric.application, R.layout.different_screen_sizes, viewGroup);
Expand Down
Expand Up @@ -48,6 +48,15 @@ public void decodeStream_shouldSetDescription() throws Exception {
assertEquals(100, bitmap.getHeight());
}

@Test
public void decodeStream_shouldSetDescriptionWithNullOptions() throws Exception {
InputStream inputStream = Robolectric.application.getContentResolver().openInputStream(Uri.parse("content:/path"));
Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, null);
assertEquals("Bitmap for content:/path", shadowOf(bitmap).getDescription());
assertEquals(100, bitmap.getWidth());
assertEquals(100, bitmap.getHeight());
}

@Test
public void decodeResource_shouldGetWidthAndHeightFromHints() throws Exception {
ShadowBitmapFactory.provideWidthAndHeightHints(R.drawable.an_image, 123, 456);
Expand All @@ -65,7 +74,7 @@ public void decodeResource_canTakeOptions() throws Exception {
Bitmap bitmap = BitmapFactory.decodeResource(Robolectric.application.getResources(), R.drawable.an_image, options);
assertEquals(true, shadowOf(bitmap).getDescription().contains("inSampleSize=100"));
}

@Test
public void decodeFile_shouldGetWidthAndHeightFromHints() throws Exception {
ShadowBitmapFactory.provideWidthAndHeightHints("/some/file.jpg", 123, 456);
Expand Down
@@ -0,0 +1,19 @@
package com.xtremelabs.robolectric.shadows;

import android.bluetooth.BluetoothAdapter;
import com.xtremelabs.robolectric.WithTestDefaultsRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.xtremelabs.robolectric.Robolectric.shadowOf;
import static junit.framework.Assert.assertEquals;

@RunWith(WithTestDefaultsRunner.class)
public class BluetoothAdapterTest {
@Test
public void canGetAndSetAddress() throws Exception {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
shadowOf(adapter).setAddress("expected");
assertEquals("expected", adapter.getAddress());
}
}
Expand Up @@ -30,6 +30,13 @@

@RunWith(WithTestDefaultsRunner.class)
public class IntentTest {

@Test
public void testGetExtraReturnsNull_whenThereAreNoExtrasAdded() throws Exception {
Intent intent = new Intent();
assertEquals(intent.getExtras(), null);
}

@Test
public void testStringExtra() throws Exception {
Intent intent = new Intent();
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import static com.xtremelabs.robolectric.Robolectric.DEFAULT_SDK_VERSION;
import static com.xtremelabs.robolectric.Robolectric.shadowOf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
Expand All @@ -40,7 +41,7 @@ public class ViewGroupTest {
@Before
public void setUp() throws Exception {
context = new Application();
ShadowApplication.bind(context, new ResourceLoader(10, R.class, null, null));
ShadowApplication.bind(context, new ResourceLoader(DEFAULT_SDK_VERSION, R.class, null, null));

root = new FrameLayout(context);

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/xtremelabs/robolectric/util/TestUtil.java
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.Properties;

import static com.xtremelabs.robolectric.Robolectric.DEFAULT_SDK_VERSION;
import static org.junit.Assert.assertTrue;

public abstract class TestUtil {
Expand Down Expand Up @@ -90,6 +91,6 @@ public static File getSystemResourceDir(String... paths) throws Exception {
sdkDir = localProperties.getProperty("sdk.dir");
}

return file(new File(sdkDir, "platforms/android-10/data/res/"), paths);
return file(new File(sdkDir, "platforms/android-" + DEFAULT_SDK_VERSION + "/data/res/"), paths);
}
}
2 changes: 1 addition & 1 deletion src/test/resources/TestAndroidManifest.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xtremelabs.robolectric">
<uses-sdk android:targetSdkVersion="10"/>
<uses-sdk android:targetSdkVersion="16"/>
</manifest>

0 comments on commit ed0782d

Please sign in to comment.