M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@ -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)

View File

@ -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>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@color/testcolor1"/>
<item android:color="@color/testcolor2"/>
</selector>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@color/testcolor1"/>
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
**
** Copyright 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.
*/
-->
<resources>
<color name="testcolor1">#ff00ff00</color>
<color name="testcolor2">#ffff0000</color>
<color name="failColor">#ff0000ff</color>
</resources>

View File

@ -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));
}
}
}
}

View File

@ -0,0 +1,69 @@
/*
* 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 com.android.frameworks.graphicstests.R;
import android.content.res.Resources;
import android.content.res.ColorStateList;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
/**
* Tests of {@link android.graphics.ColorStateList}
*/
public class ColorStateListTest extends AndroidTestCase {
private Resources mResources;
private int mFailureColor;
@Override
protected void setUp() throws Exception {
super.setUp();
mResources = mContext.getResources();
mFailureColor = mResources.getColor(R.color.failColor);
}
@SmallTest
public void testStateIsInList() throws Exception {
ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
int[] focusedState = {android.R.attr.state_focused};
int focusColor = colorStateList.getColorForState(focusedState, R.color.failColor);
assertEquals(mResources.getColor(R.color.testcolor1), focusColor);
}
@SmallTest
public void testEmptyState() throws Exception {
ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
int[] emptyState = {};
int defaultColor = colorStateList.getColorForState(emptyState, mFailureColor);
assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
}
@SmallTest
public void testGetColor() throws Exception {
int defaultColor = mResources.getColor(R.color.color1);
assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
}
@SmallTest
public void testGetColorWhenListHasNoDefault() throws Exception {
int defaultColor = mResources.getColor(R.color.color_no_default);
assertEquals(mResources.getColor(R.color.testcolor1), defaultColor);
}
}

View File

@ -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();
}
}
}

View File

@ -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;
}
}

View File

@ -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() {}
}
}

View File

@ -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);
}
}
}
}
}

View File

@ -0,0 +1,98 @@
/*
* 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.drawable;
import junit.framework.TestCase;
import android.R;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.util.StateSet;
import android.view.MockView;
/**
* Tests for StateListDrawable
*
*/
public class StateListDrawableTest extends TestCase {
private StateListDrawable slDrawable;
private MockDrawable mockFocusedDrawable;
private MockDrawable mockCheckedDrawable;
private MockView mockView;
private MockDrawable mockDefaultDrawable;
// Re-enable tests when we are running in the framework-test directory which allows
// access to package private access for MockView
public void broken_testFocusScenarioSetStringWildcardFirst() throws Exception {
int focusedStateSet[] = {R.attr.state_focused};
int checkedStateSet[] = {R.attr.state_checked};
slDrawable.addState(StateSet.WILD_CARD,
mockDefaultDrawable);
slDrawable.addState(checkedStateSet, mockCheckedDrawable);
slDrawable.addState(focusedStateSet, mockFocusedDrawable);
mockView.requestFocus();
mockView.getBackground().draw(null);
assertTrue(mockDefaultDrawable.wasDrawn);
}
public void broken_testFocusScenarioStateSetWildcardLast() throws Exception {
int focusedStateSet[] = {R.attr.state_focused};
int checkedStateSet[] = {R.attr.state_checked};
slDrawable.addState(checkedStateSet, mockCheckedDrawable);
slDrawable.addState(focusedStateSet, mockFocusedDrawable);
slDrawable.addState(StateSet.WILD_CARD,
mockDefaultDrawable);
mockView.requestFocus();
mockView.getBackground().draw(null);
assertTrue(mockFocusedDrawable.wasDrawn);
}
protected void setUp() throws Exception {
super.setUp();
slDrawable = new StateListDrawable();
mockFocusedDrawable = new MockDrawable();
mockCheckedDrawable = new MockDrawable();
mockDefaultDrawable = new MockDrawable();
mockView = new MockView();
mockView.setBackgroundDrawable(slDrawable);
}
static class MockDrawable extends Drawable {
public boolean wasDrawn = false;
public void draw(Canvas canvas) {
wasDrawn = true;
}
public void setAlpha(int alpha) {
}
public void setColorFilter(ColorFilter cf) {
}
public int getOpacity() {
return android.graphics.PixelFormat.UNKNOWN;
}
}
}

View File

@ -0,0 +1,25 @@
/*
* 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.view;
/**
* Mock View class for testing
*/
public class MockView extends View{
}