diff options
author | Neal Nguyen <tommyn@google.com> | 2010-01-13 10:42:43 -0800 |
---|---|---|
committer | Neal Nguyen <tommyn@google.com> | 2010-01-29 13:35:51 -0800 |
commit | 1a44d5dcabc18cd5ef111f732ccff91683a1a093 (patch) | |
tree | e370267a65ba54a43e3026ff9b282cc4e3dad869 /graphics | |
parent | 35ec7863e18ce3d242010b76a50df5a8c285325b (diff) | |
download | frameworks_base-1a44d5dcabc18cd5ef111f732ccff91683a1a093.zip frameworks_base-1a44d5dcabc18cd5ef111f732ccff91683a1a093.tar.gz frameworks_base-1a44d5dcabc18cd5ef111f732ccff91683a1a093.tar.bz2 |
Phase 2 of test cleanup: moving test files from AndroidTests closer to their sources.
Most of these are file moves; a couple notable exceptions are the changes due to the move, and fixing up test code:
- database/DatabaseCursorTest.java
- database/DatabaseStatementTest.java
- net/UriTest.java
Diffstat (limited to 'graphics')
13 files changed, 900 insertions, 0 deletions
diff --git a/graphics/tests/graphicstests/Android.mk b/graphics/tests/graphicstests/Android.mk new file mode 100644 index 0000000..1845395 --- /dev/null +++ b/graphics/tests/graphicstests/Android.mk @@ -0,0 +1,14 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +# We only want this apk build for tests. +LOCAL_MODULE_TAGS := tests + +# Include all test java files. +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_JAVA_LIBRARIES := android.test.runner +LOCAL_PACKAGE_NAME := FrameworksGraphicsTests + +include $(BUILD_PACKAGE) + diff --git a/graphics/tests/graphicstests/AndroidManifest.xml b/graphics/tests/graphicstests/AndroidManifest.xml new file mode 100644 index 0000000..5fb5959 --- /dev/null +++ b/graphics/tests/graphicstests/AndroidManifest.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2008 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.frameworks.graphicstests"> + <uses-permission android:name="android.permission.RECEIVE_SMS"/> + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.READ_CONTACTS" /> + <uses-permission android:name="android.permission.WRITE_CONTACTS" /> + <uses-permission android:name="android.permission.WAKE_LOCK" /> + <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" /> + <uses-permission android:name="android.permission.WRITE_APN_SETTINGS" /> + <uses-permission android:name="android.permission.BROADCAST_STICKY" /> + + + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation + android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.android.frameworks.graphicstests" + android:label="Frameworks Graphics Tests" /> +</manifest> diff --git a/graphics/tests/graphicstests/res/drawable/test128x96.png b/graphics/tests/graphicstests/res/drawable/test128x96.png Binary files differnew file mode 100644 index 0000000..28dc925 --- /dev/null +++ b/graphics/tests/graphicstests/res/drawable/test128x96.png diff --git a/graphics/tests/graphicstests/res/drawable/test16x12.png b/graphics/tests/graphicstests/res/drawable/test16x12.png Binary files differnew file mode 100644 index 0000000..1a3c7e5 --- /dev/null +++ b/graphics/tests/graphicstests/res/drawable/test16x12.png diff --git a/graphics/tests/graphicstests/res/drawable/test256x192.png b/graphics/tests/graphicstests/res/drawable/test256x192.png Binary files differnew file mode 100644 index 0000000..ce8ee04 --- /dev/null +++ b/graphics/tests/graphicstests/res/drawable/test256x192.png diff --git a/graphics/tests/graphicstests/res/drawable/test320x240.png b/graphics/tests/graphicstests/res/drawable/test320x240.png Binary files differnew file mode 100644 index 0000000..9b5800d --- /dev/null +++ b/graphics/tests/graphicstests/res/drawable/test320x240.png diff --git a/graphics/tests/graphicstests/res/drawable/test32x24.png b/graphics/tests/graphicstests/res/drawable/test32x24.png Binary files differnew file mode 100644 index 0000000..76bab75 --- /dev/null +++ b/graphics/tests/graphicstests/res/drawable/test32x24.png diff --git a/graphics/tests/graphicstests/res/drawable/test64x48.png b/graphics/tests/graphicstests/res/drawable/test64x48.png Binary files differnew file mode 100644 index 0000000..9119613 --- /dev/null +++ b/graphics/tests/graphicstests/res/drawable/test64x48.png diff --git a/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java b/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java new file mode 100644 index 0000000..6734bb7 --- /dev/null +++ b/graphics/tests/graphicstests/src/android/graphics/BitmapTest.java @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import android.graphics.Bitmap; +import android.graphics.Color; +import android.test.suitebuilder.annotation.SmallTest; +import junit.framework.TestCase; + + +public class BitmapTest extends TestCase { + + @SmallTest + public void testBasic() throws Exception { + Bitmap bm1 = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888); + Bitmap bm2 = Bitmap.createBitmap(100, 200, Bitmap.Config.RGB_565); + Bitmap bm3 = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_4444); + + assertTrue("mutability", bm1.isMutable()); + assertTrue("mutability", bm2.isMutable()); + assertTrue("mutability", bm3.isMutable()); + + assertEquals("width", 100, bm1.getWidth()); + assertEquals("width", 100, bm2.getWidth()); + assertEquals("width", 100, bm3.getWidth()); + + assertEquals("rowbytes", 400, bm1.getRowBytes()); + assertEquals("rowbytes", 200, bm2.getRowBytes()); + assertEquals("rowbytes", 200, bm3.getRowBytes()); + + assertEquals("height", 200, bm1.getHeight()); + assertEquals("height", 200, bm2.getHeight()); + assertEquals("height", 200, bm3.getHeight()); + + assertTrue("hasAlpha", bm1.hasAlpha()); + assertFalse("hasAlpha", bm2.hasAlpha()); + assertTrue("hasAlpha", bm3.hasAlpha()); + + assertTrue("getConfig", bm1.getConfig() == Bitmap.Config.ARGB_8888); + assertTrue("getConfig", bm2.getConfig() == Bitmap.Config.RGB_565); + assertTrue("getConfig", bm3.getConfig() == Bitmap.Config.ARGB_4444); + } + + @SmallTest + public void testMutability() throws Exception { + Bitmap bm1 = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888); + Bitmap bm2 = Bitmap.createBitmap(new int[100 * 200], 100, 200, + Bitmap.Config.ARGB_8888); + + assertTrue("mutability", bm1.isMutable()); + assertFalse("mutability", bm2.isMutable()); + + bm1.eraseColor(0); + + try { + bm2.eraseColor(0); + fail("eraseColor should throw exception"); + } catch (IllegalStateException ex) { + // safe to catch and ignore this + } + } + + @SmallTest + public void testGetPixelsWithAlpha() throws Exception { + int[] colors = new int[100]; + for (int i = 0; i < 100; i++) { + colors[i] = (0xFF << 24) | (i << 16) | (i << 8) | i; + } + + Bitmap bm = Bitmap.createBitmap(colors, 10, 10, + Bitmap.Config.ARGB_8888); + + int[] pixels = new int[100]; + bm.getPixels(pixels, 0, 10, 0, 0, 10, 10); + for (int i = 0; i < 100; i++) { + int p = bm.getPixel(i % 10, i / 10); + assertEquals("getPixels", p, pixels[i]); + } + + for (int i = 0; i < 100; i++) { + int p = bm.getPixel(i % 10, i / 10); + assertEquals("getPixel", p, colors[i]); + assertEquals("pixel value", p, + ((0xFF << 24) | (i << 16) | (i << 8) | i)); + } + + } + + @SmallTest + public void testGetPixelsWithoutAlpha() throws Exception { + int[] colors = new int[100]; + for (int i = 0; i < 100; i++) { + colors[i] = (0xFF << 24) | (i << 16) | (i << 8) | i; + } + + Bitmap bm = Bitmap.createBitmap(colors, 10, 10, Bitmap.Config.RGB_565); + + int[] pixels = new int[100]; + bm.getPixels(pixels, 0, 10, 0, 0, 10, 10); + for (int i = 0; i < 100; i++) { + int p = bm.getPixel(i % 10, i / 10); + assertEquals("getPixels", p, pixels[i]); + } + } + + @SmallTest + public void testSetPixelsWithAlpha() throws Exception { + int[] colors = new int[100]; + for (int i = 0; i < 100; i++) { + colors[i] = (0xFF << 24) | (i << 16) | (i << 8) | i; + } + + Bitmap.Config config = Bitmap.Config.ARGB_8888; + Bitmap bm1 = Bitmap.createBitmap(colors, 10, 10, config); + Bitmap bm2 = Bitmap.createBitmap(10, 10, config); + + for (int i = 0; i < 100; i++) { + bm2.setPixel(i % 10, i / 10, colors[i]); + } + + for (int i = 0; i < 100; i++) { + assertEquals("setPixel", + bm1.getPixel(i % 10, i / 10), bm2.getPixel(i % 10, i / 10)); + } + + for (int i = 0; i < 100; i++) { + assertEquals("setPixel value", + bm1.getPixel(i % 10, i / 10), colors[i]); + } + } + + @SmallTest + public void testSetPixelsWithoutAlpha() throws Exception { + int[] colors = new int[100]; + for (int i = 0; i < 100; i++) { + colors[i] = (0xFF << 24) | (i << 16) | (i << 8) | i; + } + + Bitmap.Config config = Bitmap.Config.RGB_565; + Bitmap bm1 = Bitmap.createBitmap(colors, 10, 10, config); + Bitmap bm2 = Bitmap.createBitmap(10, 10, config); + + for (int i = 0; i < 100; i++) { + bm2.setPixel(i % 10, i / 10, colors[i]); + } + + for (int i = 0; i < 100; i++) { + assertEquals("setPixel", bm1.getPixel(i % 10, i / 10), + bm2.getPixel(i % 10, i / 10)); + } + } + + private static int computePrePostMul(int alpha, int comp) { + if (alpha == 0) { + return 0; + } + int premul = Math.round(alpha * comp / 255.f); + int unpre = Math.round(255.0f * premul / alpha); + return unpre; + } + + @SmallTest + public void testSetPixelsWithNonOpaqueAlpha() throws Exception { + int[] colors = new int[256]; + for (int i = 0; i < 256; i++) { + colors[i] = (i << 24) | (0xFF << 16) | (0x80 << 8) | 0; + } + + Bitmap.Config config = Bitmap.Config.ARGB_8888; + + // create a bitmap with the color array specified + Bitmap bm1 = Bitmap.createBitmap(colors, 16, 16, config); + + // create a bitmap with no colors, but then call setPixels + Bitmap bm2 = Bitmap.createBitmap(16, 16, config); + bm2.setPixels(colors, 0, 16, 0, 0, 16, 16); + + // now check that we did a good job returning the unpremultiplied alpha + final int tolerance = 1; + for (int i = 0; i < 256; i++) { + int c0 = colors[i]; + int c1 = bm1.getPixel(i % 16, i / 16); + int c2 = bm2.getPixel(i % 16, i / 16); + + // these two should always be identical + assertEquals("getPixel", c1, c2); + + // comparing the original (c0) with the returned color is tricky, + // since it gets premultiplied during the set(), and unpremultiplied + // by the get(). + int a0 = Color.alpha(c0); + int a1 = Color.alpha(c1); + assertEquals("alpha", a0, a1); + + int r0 = Color.red(c0); + int r1 = Color.red(c1); + int rr = computePrePostMul(a0, r0); + assertTrue("red", Math.abs(rr - r1) <= tolerance); + + int g0 = Color.green(c0); + int g1 = Color.green(c1); + int gg = computePrePostMul(a0, g0); + assertTrue("green", Math.abs(gg - g1) <= tolerance); + + int b0 = Color.blue(c0); + int b1 = Color.blue(c1); + int bb = computePrePostMul(a0, b0); + assertTrue("blue", Math.abs(bb - b1) <= tolerance); + + if (false) { + int cc = Color.argb(a0, rr, gg, bb); + android.util.Log.d("skia", "original " + Integer.toHexString(c0) + + " set+get " + Integer.toHexString(c1) + + " local " + Integer.toHexString(cc)); + } + } + } +} diff --git a/graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java b/graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java new file mode 100644 index 0000000..f60ac7b --- /dev/null +++ b/graphics/tests/graphicstests/src/android/graphics/GraphicsPerformanceTests.java @@ -0,0 +1,450 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import junit.framework.Assert; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.test.AndroidTestCase; +import android.test.PerformanceTestCase; +import android.test.suitebuilder.annotation.Suppress; +import android.util.Log; + +import com.android.frameworks.graphicstests.R; + +/** + * Graphics Performance Tests + * + */ +//We don't want to run these perf tests in the continuous build. +@Suppress +public class GraphicsPerformanceTests { + private static final String TAG = "GfxPerf"; + public static String[] children() { + return new String[] { + // test decoding bitmaps of various sizes + DecodeBitmapTest.class.getName(), + + // odd-sized bitmap drawing tests + DrawBitmap7x7.class.getName(), + DrawBitmap15x15.class.getName(), + DrawBitmap31x31.class.getName(), + DrawBitmap63x63.class.getName(), + DrawBitmap127x127.class.getName(), + DrawBitmap319x239.class.getName(), + DrawBitmap319x479.class.getName(), + + // even-sized bitmap drawing tests + DrawBitmap8x8.class.getName(), + DrawBitmap16x16.class.getName(), + DrawBitmap32x32.class.getName(), + DrawBitmap64x64.class.getName(), + DrawBitmap128x128.class.getName(), + DrawBitmap320x240.class.getName(), + DrawBitmap320x480.class.getName()}; + } + + /** + * Base class for all graphics tests + * + */ + public static abstract class GraphicsTestBase extends AndroidTestCase + implements PerformanceTestCase { + /** Target "screen" (bitmap) width and height */ + private static final int DEFAULT_ITERATIONS = 1; + private static final int SCREEN_WIDTH = 320; + private static final int SCREEN_HEIGHT = 480; + + /** Number of iterations to pass back to harness. Subclass should override */ + protected int mIterations = 1; + + /** Bitmap we allocate and draw to */ + protected Bitmap mDestBitmap; + + /** Canvas of drawing routines */ + protected Canvas mCanvas; + + /** Style and color information (uses defaults) */ + protected Paint mPaint; + + @Override + public void setUp() throws Exception { + super.setUp(); + // Create drawable bitmap for rendering into + mDestBitmap = Bitmap.createBitmap(SCREEN_WIDTH, SCREEN_HEIGHT, + Bitmap.Config.RGB_565); + // Set of drawing routines + mCanvas = new Canvas(mDestBitmap); + // Styles + mPaint = new Paint(); + // Ask subclass for number of iterations + mIterations = getIterations(); + } + + // A reasonable default + public int getIterations() { + return DEFAULT_ITERATIONS; + } + + public boolean isPerformanceOnly() { + return true; + } + + public int startPerformance(Intermediates intermediates) { + intermediates.setInternalIterations(mIterations * 10); + return 0; + } + } + + /** + * Tests time to decode a number of sizes of images. + */ + public static class DecodeBitmapTest extends GraphicsTestBase { + /** Number of times to run this test */ + private static final int DECODE_ITERATIONS = 10; + + /** Used to access package bitmap images */ + private Resources mResources; + + @Override + public void setUp() throws Exception { + super.setUp(); + + // For bitmap resources + Context context = getContext(); + Assert.assertNotNull(context); + mResources = context.getResources(); + Assert.assertNotNull(mResources); + } + + @Override + public int getIterations() { + return DECODE_ITERATIONS; + } + + public void testDecodeBitmap() { + for (int i = 0; i < DECODE_ITERATIONS; i++) { + BitmapFactory.decodeResource(mResources, R.drawable.test16x12); + BitmapFactory.decodeResource(mResources, R.drawable.test32x24); + BitmapFactory.decodeResource(mResources, R.drawable.test64x48); + BitmapFactory.decodeResource(mResources, R.drawable.test128x96); + BitmapFactory.decodeResource(mResources, R.drawable.test256x192); + BitmapFactory.decodeResource(mResources, R.drawable.test320x240); + } + } + } + + /** + * Base class for bitmap drawing tests + * + */ + public static abstract class DrawBitmapTest extends GraphicsTestBase { + /** Number of times to run each draw test */ + private static final int ITERATIONS = 1000; + + /** Bitmap to draw. Allocated by subclass's createBitmap() function. */ + private Bitmap mBitmap; + + @Override + public void setUp() throws Exception { + super.setUp(); + + // Invoke subclass's method to create the bitmap + mBitmap = createBitmap(); + } + + public int getIterations() { + return ITERATIONS; + } + + // Generic abstract function to create bitmap for any given subclass + public abstract Bitmap createBitmap(); + + // Provide convenience test code for all subsequent classes. + // Note: Though it would be convenient to declare all of the test*() methods here + // and just inherit them, our test harness doesn't support it. So we replicate + // a bit of code in each derived test case. + public void drawBitmapEven() { + for (int i = 0; i < ITERATIONS; i++) { + mCanvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint); + } + } + + public void drawBitmapOdd() { + for (int i = 0; i < ITERATIONS; i++) { + mCanvas.drawBitmap(mBitmap, 1.0f, 0.0f, mPaint); + } + } + } + + + /** + * Test drawing of 7x7 image + */ + public static class DrawBitmap7x7 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(7, 7, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 15x15 image + */ + public static class DrawBitmap15x15 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(15, 15, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 31x31 image + */ + public static class DrawBitmap31x31 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(31, 31, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 63x63 image + */ + public static class DrawBitmap63x63 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(63, 63, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 127x127 image + */ + public static class DrawBitmap127x127 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(127, 127, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 319x239 image + */ + public static class DrawBitmap319x239 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(319, 239, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 319x479 image + */ + public static class DrawBitmap319x479 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(319, 479, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 8x8 image + */ + public static class DrawBitmap8x8 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(8, 8, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 16x16 image + */ + public static class DrawBitmap16x16 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(16, 16, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 32x32 image + */ + public static class DrawBitmap32x32 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(32, 32, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 64x64 image + */ + public static class DrawBitmap64x64 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(64, 64, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 128x128 image + */ + public static class DrawBitmap128x128 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(128, 128, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 320x240 image + */ + public static class DrawBitmap320x240 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(320, 240, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } + + /** + * Test drawing of 320x480 image + */ + public static class DrawBitmap320x480 extends DrawBitmapTest { + + public Bitmap createBitmap() { + return Bitmap.createBitmap(320, 480, Bitmap.Config.RGB_565); + } + + public void testDrawBitmapEven() { + drawBitmapEven(); + } + + public void testDrawBitmapOdd() { + drawBitmapOdd(); + } + } +} diff --git a/graphics/tests/graphicstests/src/android/graphics/GraphicsTests.java b/graphics/tests/graphicstests/src/android/graphics/GraphicsTests.java new file mode 100644 index 0000000..8d01ea7 --- /dev/null +++ b/graphics/tests/graphicstests/src/android/graphics/GraphicsTests.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import junit.framework.TestSuite; + +public class GraphicsTests { + public static TestSuite suite() { + TestSuite suite = new TestSuite(GraphicsTests.class.getName()); + + suite.addTestSuite(BitmapTest.class); + suite.addTestSuite(TypefaceTest.class); + return suite; + } +} diff --git a/graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java b/graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java new file mode 100644 index 0000000..84bdc56 --- /dev/null +++ b/graphics/tests/graphicstests/src/android/graphics/ThreadBitmapTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import junit.framework.TestCase; +import android.graphics.Bitmap; +import android.test.suitebuilder.annotation.LargeTest; + +public class ThreadBitmapTest extends TestCase { + + @Override + protected void setUp() throws Exception { + } + + @LargeTest + public void testCreation() { + for (int i = 0; i < 200; i++) { + + new MThread().start(); + } + } + + class MThread extends Thread { + public Bitmap b; + + public MThread() { + b = Bitmap.createBitmap(300, 300, Bitmap.Config.RGB_565); + } + + public void run() {} + } +} + diff --git a/graphics/tests/graphicstests/src/android/graphics/TypefaceTest.java b/graphics/tests/graphicstests/src/android/graphics/TypefaceTest.java new file mode 100644 index 0000000..334fddf --- /dev/null +++ b/graphics/tests/graphicstests/src/android/graphics/TypefaceTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import android.graphics.Paint; +import android.graphics.Typeface; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.SmallTest; +import junit.framework.TestCase; + + +public class TypefaceTest extends TestCase { + + // create array of all std faces + private final Typeface[] mFaces = new Typeface[] { + Typeface.create(Typeface.SANS_SERIF, 0), + Typeface.create(Typeface.SANS_SERIF, 1), + Typeface.create(Typeface.SERIF, 0), + Typeface.create(Typeface.SERIF, 1), + Typeface.create(Typeface.SERIF, 2), + Typeface.create(Typeface.SERIF, 3), + Typeface.create(Typeface.MONOSPACE, 0) + }; + + @SmallTest + public void testBasic() throws Exception { + assertTrue("basic", Typeface.DEFAULT != null); + assertTrue("basic", Typeface.DEFAULT_BOLD != null); + assertTrue("basic", Typeface.SANS_SERIF != null); + assertTrue("basic", Typeface.SERIF != null); + assertTrue("basic", Typeface.MONOSPACE != null); + } + + @SmallTest + public void testUnique() throws Exception { + final int n = mFaces.length; + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + assertTrue("unique", mFaces[i] != mFaces[j]); + } + } + } + + @SmallTest + public void testStyles() throws Exception { + assertTrue("style", mFaces[0].getStyle() == Typeface.NORMAL); + assertTrue("style", mFaces[1].getStyle() == Typeface.BOLD); + assertTrue("style", mFaces[2].getStyle() == Typeface.NORMAL); + assertTrue("style", mFaces[3].getStyle() == Typeface.BOLD); + assertTrue("style", mFaces[4].getStyle() == Typeface.ITALIC); + assertTrue("style", mFaces[5].getStyle() == Typeface.BOLD_ITALIC); + assertTrue("style", mFaces[6].getStyle() == Typeface.NORMAL); + } + + @MediumTest + public void testUniformY() throws Exception { + Paint p = new Paint(); + final int n = mFaces.length; + for (int i = 1; i <= 36; i++) { + p.setTextSize(i); + float ascent = 0; + float descent = 0; + for (int j = 0; j < n; j++) { + p.setTypeface(mFaces[j]); + Paint.FontMetrics fm = p.getFontMetrics(); + if (j == 0) { + ascent = fm.ascent; + descent = fm.descent; + } else { + assertTrue("fontMetrics", fm.ascent == ascent); + assertTrue("fontMetrics", fm.descent == descent); + } + } + } + } + +} |