All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.osmdroid.ContextResourceProxyTest Maven / Gradle / Ivy

There is a newer version: 5.2
Show newest version
/*
 * WARNING, All test cases exist in osmdroid-android-it/src/main/java (maven project)
 *
 * During build time (with gradle), these tests are copied from osmdroid-android-it to OpenStreetMapViewer/src/androidTest/java
 * DO NOT Modify files in OpenSteetMapViewer/src/androidTest. You will loose your changes when building!
 *
 */
package org.osmdroid;

import org.osmdroid.ResourceProxyImpl;
import java.nio.ByteBuffer;

import android.graphics.Bitmap;
import android.test.AndroidTestCase;

/**
 * @author Neil Boyd
 *
 */
public class ContextResourceProxyTest extends AndroidTestCase {

	public void test_getString() {
		final ResourceProxy rp = new ResourceProxyImpl(getContext());
		final String mapnik = rp.getString(ResourceProxy.string.map_mode);
		assertEquals("Got string okay", "Map Source", mapnik);
	}

	public void test_getBitmap() {
		final ResourceProxy rp = new ResourceProxyImpl(getContext());
		final Bitmap center = rp.getBitmap(ResourceProxy.bitmap.person);
		assertNotNull("Got bitmap okay", center);
	}

	public void test_getBitmap_compare_with_default() {
		final ResourceProxy contextResourceProxy = new ResourceProxyImpl(getContext());
		final Bitmap contextBitmap = contextResourceProxy.getBitmap(ResourceProxy.bitmap.person);

		final ResourceProxy defaultResourceProxy = new DefaultResourceProxyImpl(getContext());
		final Bitmap defaultBitmap = defaultResourceProxy.getBitmap(ResourceProxy.bitmap.person);
		// FIXME this throws an exception

		// compare a few things to see if they're the same bitmap
		assertEquals("Compare config", contextBitmap.getConfig(), defaultBitmap.getConfig());
		assertEquals("Compare width", contextBitmap.getWidth(), defaultBitmap.getWidth());
		assertEquals("Compare height", contextBitmap.getHeight(), defaultBitmap.getHeight());

		// compare the total thing
		final ByteBuffer bb1 = ByteBuffer.allocate(contextBitmap.getWidth()
				* contextBitmap.getHeight() * 4);
		contextBitmap.copyPixelsToBuffer(bb1);
		final ByteBuffer bb2 = ByteBuffer.allocate(defaultBitmap.getWidth()
				* defaultBitmap.getHeight() * 4);
		defaultBitmap.copyPixelsToBuffer(bb2);
		assertEquals("Compare pixels", bb1, bb2);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy