Added and updated test cases in CTS.
Added and updated test cases in CTS for improving the code coverage
for android.graphics package.
Change-Id: Id701213b77055ae737c4a92cf81c4eb8ac75f6fc
diff --git a/tests/res/drawable/typeface_test.png b/tests/res/drawable/typeface_test.png
new file mode 100644
index 0000000..c337f5f
--- /dev/null
+++ b/tests/res/drawable/typeface_test.png
Binary files differ
diff --git a/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java b/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
index fdffd51..6a836e0 100755
--- a/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
@@ -30,6 +30,7 @@
import android.os.ParcelFileDescriptor;
import android.test.InstrumentationTestCase;
import android.util.DisplayMetrics;
+import android.util.TypedValue;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -107,6 +108,24 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
+ method = "decodeResourceStream",
+ args = {android.content.res.Resources.class, android.util.TypedValue.class,
+ java.io.InputStream.class, android.graphics.Rect.class,
+ android.graphics.BitmapFactory.Options.class}
+ )
+ public void testDecodeResourceStream() {
+ InputStream is = obtainInputStream();
+ Rect r = new Rect(1, 1, 1, 1);
+ TypedValue value = new TypedValue();
+ Bitmap b = BitmapFactory.decodeResourceStream(mRes, value, is, r, mOpt1);
+ assertNotNull(b);
+ // Test the bitmap size
+ assertEquals(START_HEIGHT, b.getHeight());
+ assertEquals(START_WIDTH, b.getWidth());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
method = "decodeByteArray",
args = {byte[].class, int.class, int.class, android.graphics.BitmapFactory.Options.class}
)
diff --git a/tests/tests/graphics/src/android/graphics/cts/BitmapRegionDecoderTest.java b/tests/tests/graphics/src/android/graphics/cts/BitmapRegionDecoderTest.java
index 5cda2cb..abbba4b 100755
--- a/tests/tests/graphics/src/android/graphics/cts/BitmapRegionDecoderTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/BitmapRegionDecoderTest.java
@@ -34,6 +34,7 @@
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -258,15 +259,23 @@
}
}
- @TestTargetNew(
+ @TestTargets ({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "recycle",
+ args = {}
+ ),
+ @TestTargetNew(
level = TestLevel.COMPLETE,
- method = "recycle",
+ method = "isRecycled",
args = {}
- )
+ )
+ })
public void testRecycle() throws IOException {
InputStream is = obtainInputStream(RES_IDS[0]);
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, false);
decoder.recycle();
+ assertTrue(decoder.isRecycled());
try {
decoder.getWidth();
fail("Should throw an exception!");
diff --git a/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java b/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
index 7287834..f8d3ee9 100644
--- a/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
@@ -25,6 +25,7 @@
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
@@ -32,6 +33,7 @@
import android.graphics.Bitmap.Config;
import android.os.Parcel;
import android.test.AndroidTestCase;
+import android.util.DisplayMetrics;
import android.widget.cts.WidgetTestUtils;
import java.io.ByteArrayOutputStream;
@@ -788,6 +790,98 @@
mBitmap.equals(Bitmap.CREATOR.createFromParcel(p));
}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getScaledHeight",
+ args = {int.class}
+ )
+ public void testGetScaledHeight1() {
+ int dummyDensity = 5;
+ Bitmap ret = Bitmap.createBitmap(100, 200, Config.RGB_565);
+ int scaledHeight = scaleFromDensity(ret.getHeight(), ret.getDensity(), dummyDensity);
+ assertNotNull(ret);
+ assertEquals(scaledHeight, ret.getScaledHeight(dummyDensity));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getScaledHeight",
+ args = {android.util.DisplayMetrics.class}
+ )
+ public void testGetScaledHeight2() {
+ Bitmap ret = Bitmap.createBitmap(100, 200, Config.RGB_565);
+ DisplayMetrics metrics = new DisplayMetrics();
+ metrics = getContext().getResources().getDisplayMetrics();
+ int scaledHeight = scaleFromDensity(ret.getHeight(), ret.getDensity(), metrics.densityDpi);
+ assertEquals(scaledHeight, ret.getScaledHeight(metrics));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getScaledHeight",
+ args = {android.graphics.Canvas.class}
+ )
+ public void testGetScaledHeight3() {
+ Bitmap ret = Bitmap.createBitmap(100, 200, Config.RGB_565);
+ Bitmap mMutableBitmap = Bitmap.createBitmap(100, 200, Config.ARGB_8888);
+ Canvas mCanvas = new Canvas(mMutableBitmap);
+ // set Density
+ mCanvas.setDensity(DisplayMetrics.DENSITY_HIGH);
+ int scaledHeight = scaleFromDensity(
+ ret.getHeight(), ret.getDensity(), mCanvas.getDensity());
+ assertEquals(scaledHeight, ret.getScaledHeight(mCanvas));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getScaledWidth",
+ args = {android.graphics.Canvas.class}
+ )
+ public void testGetScaledWidth1() {
+ int dummyDensity = 5;
+ Bitmap ret = Bitmap.createBitmap(100, 200, Config.RGB_565);
+ int scaledWidth = scaleFromDensity(ret.getWidth(), ret.getDensity(), dummyDensity);
+ assertNotNull(ret);
+ assertEquals(scaledWidth, ret.getScaledWidth(dummyDensity));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getScaledWidth",
+ args = {android.util.DisplayMetrics.class}
+ )
+ public void testGetScaledWidth2() {
+ Bitmap ret = Bitmap.createBitmap(100, 200, Config.RGB_565);
+ DisplayMetrics metrics = new DisplayMetrics();
+ metrics = getContext().getResources().getDisplayMetrics();
+ int scaledWidth = scaleFromDensity(ret.getWidth(), ret.getDensity(), metrics.densityDpi);
+ assertEquals(scaledWidth, ret.getScaledWidth(metrics));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getScaledWidth",
+ args = {android.graphics.Canvas.class}
+ )
+ public void testGetScaledWidth3() {
+ Bitmap ret = Bitmap.createBitmap(100, 200, Config.RGB_565);
+ Bitmap mMutableBitmap = Bitmap.createBitmap(100, 200, Config.ARGB_8888);
+ Canvas mCanvas = new Canvas(mMutableBitmap);
+ // set Density
+ mCanvas.setDensity(DisplayMetrics.DENSITY_HIGH);
+ int scaledWidth = scaleFromDensity(ret.getWidth(), ret.getDensity(), mCanvas.getDensity());
+ assertEquals(scaledWidth, ret.getScaledWidth(mCanvas));
+ }
+
+ private int scaleFromDensity(int size, int sdensity, int tdensity) {
+ if (sdensity == Bitmap.DENSITY_NONE || sdensity == tdensity) {
+ return size;
+ }
+
+ // Scale by tdensity / sdensity, rounding up.
+ return ((size * tdensity) + (sdensity >> 1)) / sdensity;
+ }
+
private int[] createColors(int size){
int[] colors = new int[size];
diff --git a/tests/tests/graphics/src/android/graphics/cts/CanvasTest.java b/tests/tests/graphics/src/android/graphics/cts/CanvasTest.java
index 07612d4..5d3a174 100644
--- a/tests/tests/graphics/src/android/graphics/cts/CanvasTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/CanvasTest.java
@@ -21,6 +21,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
+import android.util.DisplayMetrics;
import android.graphics.DrawFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
@@ -1144,7 +1145,7 @@
args = {float.class, float.class, float.class, float.class}
)
public void testClipRect6() {
- assertTrue(mCanvas.clipRect(0, 0, 10, 31));
+ assertTrue(mCanvas.clipRect(0.5f, 0.5f, 10.5f, 31.5f));
}
@TestTargetNew(
@@ -2253,6 +2254,28 @@
mCanvas.drawPicture(p, dst);
}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setDensity",
+ args = {int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getDensity",
+ args = {android.util.DisplayMetrics.class}
+ )
+ })
+ public void testDensity() {
+ // set Density
+ mCanvas.setDensity(DisplayMetrics.DENSITY_DEFAULT);
+ assertEquals(DisplayMetrics.DENSITY_DEFAULT, mCanvas.getDensity());
+
+ // set Density
+ mCanvas.setDensity(DisplayMetrics.DENSITY_HIGH);
+ assertEquals(DisplayMetrics.DENSITY_HIGH, mCanvas.getDensity());
+ }
+
private void preCompare() {
final float[] values = new float[FLOAT_ARRAY_LEN];
mCanvas.getMatrix().getValues(values);
diff --git a/tests/tests/graphics/src/android/graphics/cts/Interpolator_ResultTest.java b/tests/tests/graphics/src/android/graphics/cts/Interpolator_ResultTest.java
index 3c79581..82419db 100644
--- a/tests/tests/graphics/src/android/graphics/cts/Interpolator_ResultTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/Interpolator_ResultTest.java
@@ -18,6 +18,8 @@
import junit.framework.TestCase;
import android.graphics.Interpolator.Result;
+import android.graphics.Shader.TileMode;
+
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
@@ -31,8 +33,9 @@
args = {java.lang.String.class}
)
public void testValueOf() {
- // this enum type is tested in
- // android.graphics.InterpolatorTest#testTimeToValues1()
+ assertEquals(Result.FREEZE_START, Result.valueOf("FREEZE_START"));
+ assertEquals(Result.FREEZE_END, Result.valueOf("FREEZE_END"));
+ assertEquals(Result.NORMAL, Result.valueOf("NORMAL"));
}
@TestTargetNew(
@@ -41,8 +44,10 @@
args = {}
)
public void testValues() {
- // this enum type is tested in
- // android.graphics.InterpolatorTest#testTimeToValues1()
+ Result[] result = Result.values();
+ assertEquals(3, result.length);
+ assertEquals(Result.NORMAL, result[0]);
+ assertEquals(Result.FREEZE_START, result[1]);
+ assertEquals(Result.FREEZE_END, result[2]);
}
-
-}
+}
\ No newline at end of file
diff --git a/tests/tests/graphics/src/android/graphics/cts/NinePatchTest.java b/tests/tests/graphics/src/android/graphics/cts/NinePatchTest.java
index 041de94..d2b9af0 100644
--- a/tests/tests/graphics/src/android/graphics/cts/NinePatchTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/NinePatchTest.java
@@ -207,6 +207,18 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
+ method = "getDensity",
+ args = {}
+ )
+ public void testGetDensity() {
+ mBitmap.setDensity(11);
+ assertEquals(11, mNinePatch.getDensity());
+ mNinePatch = new NinePatch(mBitmap, mChunk, NAME);
+ assertEquals(mNinePatch.getDensity(), mBitmap.getDensity());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
method = "getTransparentRegion",
args = {android.graphics.Rect.class}
)
diff --git a/tests/tests/graphics/src/android/graphics/cts/PathMeasureTest.java b/tests/tests/graphics/src/android/graphics/cts/PathMeasureTest.java
index 614a44e..94e352a 100644
--- a/tests/tests/graphics/src/android/graphics/cts/PathMeasureTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/PathMeasureTest.java
@@ -157,6 +157,9 @@
mPath.addRect(1, 2, 3, 4, Path.Direction.CW);
mPathMeasure.setPath(mPath, true);
assertEquals(8f, mPathMeasure.getLength());
+ Path dst = new Path();
+ assertTrue(mPathMeasure.getSegment(0, mPathMeasure.getLength(), dst, true));
+ assertFalse(mPathMeasure.getSegment(mPathMeasure.getLength(), 0, dst, true));
}
@TestTargetNew(
diff --git a/tests/tests/graphics/src/android/graphics/cts/RectTest.java b/tests/tests/graphics/src/android/graphics/cts/RectTest.java
index 2176987..5eb788f 100644
--- a/tests/tests/graphics/src/android/graphics/cts/RectTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/RectTest.java
@@ -677,6 +677,30 @@
}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "flattenToString",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "unflattenFromString",
+ args = {java.lang.String.class}
+ )
+ })
+ public void testFlattenToString() {
+ Rect mRect = new Rect(1, 2, 3, 4);
+ String flattenString = mRect.flattenToString();
+ assertNotNull(flattenString);
+ String unDefinedFormat = "TOPLEFT";
+ Rect rect = Rect.unflattenFromString(flattenString);
+ assertEquals(mRect, rect);
+ rect = null;
+ rect = Rect.unflattenFromString(unDefinedFormat);
+ assertNull(rect);
+ }
+
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "describeContents",
diff --git a/tests/tests/graphics/src/android/graphics/cts/Shader_TileModeTest.java b/tests/tests/graphics/src/android/graphics/cts/Shader_TileModeTest.java
index 135bf36..4389032 100644
--- a/tests/tests/graphics/src/android/graphics/cts/Shader_TileModeTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/Shader_TileModeTest.java
@@ -18,6 +18,7 @@
import junit.framework.TestCase;
import android.graphics.Shader;
+import android.graphics.Shader.TileMode;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
@@ -26,18 +27,27 @@
@TestTargetClass(Shader.TileMode.class)
public class Shader_TileModeTest extends TestCase {
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- method = "values",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- method = "valueOf",
- args = {java.lang.String.class}
- )
- })
- public void testTileMode() {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "valueOf",
+ args = {java.lang.String.class}
+ )
+ public void testValueOf() {
+ assertEquals(TileMode.CLAMP, TileMode.valueOf("CLAMP"));
+ assertEquals(TileMode.MIRROR, TileMode.valueOf("MIRROR"));
+ assertEquals(TileMode.REPEAT, TileMode.valueOf("REPEAT"));
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "values",
+ args = {}
+ )
+ public void testValues() {
+ TileMode[] tileMode = TileMode.values();
+ assertEquals(3, tileMode.length);
+ assertEquals(TileMode.CLAMP, tileMode[0]);
+ assertEquals(TileMode.REPEAT, tileMode[1]);
+ assertEquals(TileMode.MIRROR, tileMode[2]);
}
}
diff --git a/tests/tests/graphics/src/android/graphics/cts/TypefaceTest.java b/tests/tests/graphics/src/android/graphics/cts/TypefaceTest.java
index c861b3e..1af26af 100755
--- a/tests/tests/graphics/src/android/graphics/cts/TypefaceTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/TypefaceTest.java
@@ -16,14 +16,34 @@
package android.graphics.cts;
+import com.android.cts.stub.R;
+
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
import android.graphics.Typeface;
+import android.content.res.AssetFileDescriptor;
+import android.content.res.AssetManager;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Typeface;
+import android.graphics.Bitmap.Config;
+import android.os.ParcelFileDescriptor;
import android.test.AndroidTestCase;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
@TestTargetClass(android.graphics.Typeface.class)
public class TypefaceTest extends AndroidTestCase {
@@ -165,5 +185,131 @@
Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "samplefont.ttf");
assertNotNull(typeface);
+
+ Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+ bitmap.eraseColor(Color.BLACK);
+ Canvas canvas = new Canvas(bitmap);
+ Paint p = new Paint();
+ p.setTypeface(typeface);
+ p.setColor(Color.WHITE);
+ p.setTextAlign(Paint.Align.CENTER);
+ p.setTextSize(50);
+ p.setFlags(0); // clear all flags (not sure what defaults flags are set)
+ canvas.drawText("test", bitmap.getWidth() / 2, 3 * bitmap.getHeight() / 4 , p);
+
+ BitmapFactory.Options opt = new BitmapFactory.Options();
+ opt.inScaled = false;
+ Bitmap expected = BitmapFactory.decodeResource(
+ getContext().getResources(), R.drawable.typeface_test, opt);
+ assertEquals(expected.getWidth(), bitmap.getWidth());
+ assertEquals(expected.getHeight(), bitmap.getHeight());
+ for (int y = 0; y < bitmap.getHeight(); y++) {
+ for (int x = 0; x < bitmap.getWidth(); x++) {
+ assertEquals(expected.getPixel(x, y), bitmap.getPixel(x, y));
+ }
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "createFromFile",
+ args = {java.io.File.class}
+ )
+ public void testCreateFromFile1() throws IOException {
+ // input abnormal params.
+ try {
+ Typeface.createFromFile((File)null);
+ fail("Should throw a NullPointerException.");
+ } catch (NullPointerException e) {
+ // except here
+ }
+ File file = new File(obtainPath());
+ Typeface typeface = Typeface.createFromFile(file);
+ assertNotNull(typeface);
+
+ Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+ bitmap.eraseColor(Color.BLACK);
+ Canvas canvas = new Canvas(bitmap);
+ Paint p = new Paint();
+ p.setTypeface(typeface);
+ p.setColor(Color.WHITE);
+ p.setTextAlign(Paint.Align.CENTER);
+ p.setTextSize(50);
+ p.setFlags(0); // clear all flags (not sure what defaults flags are set)
+ canvas.drawText("test", bitmap.getWidth() / 2, 3 * bitmap.getHeight() / 4, p);
+
+ BitmapFactory.Options opt = new BitmapFactory.Options();
+ opt.inScaled = false;
+ Bitmap expected = BitmapFactory.decodeResource(getContext().getResources(),
+ R.drawable.typeface_test, opt);
+ assertEquals(expected.getWidth(), bitmap.getWidth());
+ assertEquals(expected.getHeight(), bitmap.getHeight());
+ for (int y = 0; y < bitmap.getHeight(); y++) {
+ for (int x = 0; x < bitmap.getWidth(); x++) {
+ assertEquals(expected.getPixel(x, y), bitmap.getPixel(x, y));
+ }
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "createFromFile",
+ args = {java.lang.String.class}
+ )
+ public void testCreateFromFile2() throws IOException {
+ // input abnormal params.
+ try {
+ Typeface.createFromFile((String)null);
+ fail("Should throw a NullPointerException.");
+ } catch (NullPointerException e) {
+ // except here
+ }
+
+ Typeface typeface = Typeface.createFromFile(obtainPath());
+ assertNotNull(typeface);
+
+ Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+ bitmap.eraseColor(Color.BLACK);
+ Canvas canvas = new Canvas(bitmap);
+ Paint p = new Paint();
+ p.setTypeface(typeface);
+ p.setColor(Color.WHITE);
+ p.setTextAlign(Paint.Align.CENTER);
+ p.setTextSize(50);
+ p.setFlags(0); // clear all flags (not sure what defaults flags are set)
+ canvas.drawText("test", bitmap.getWidth() / 2, 3 * bitmap.getHeight() / 4, p);
+
+ BitmapFactory.Options opt = new BitmapFactory.Options();
+ opt.inScaled = false;
+ Bitmap expected = BitmapFactory.decodeResource(getContext().getResources(),
+ R.drawable.typeface_test, opt);
+ assertEquals(expected.getWidth(), bitmap.getWidth());
+ assertEquals(expected.getHeight(), bitmap.getHeight());
+ for (int y = 0; y < bitmap.getHeight(); y++) {
+ for (int x = 0; x < bitmap.getWidth(); x++) {
+ assertEquals(expected.getPixel(x, y), bitmap.getPixel(x, y));
+ }
+ }
+ }
+
+ private String obtainPath() throws IOException {
+ File dir = getContext().getFilesDir();
+ dir.mkdirs();
+ File file = new File(dir, "test.jpg");
+ if (!file.createNewFile()) {
+ if (!file.exists()) {
+ fail("Failed to create new File!");
+ }
+ }
+ InputStream is = getContext().getAssets().open("samplefont.ttf");
+ FileOutputStream fOutput = new FileOutputStream(file);
+ byte[] dataBuffer = new byte[1024];
+ int readLength = 0;
+ while ((readLength = is.read(dataBuffer)) != -1) {
+ fOutput.write(dataBuffer, 0, readLength);
+ }
+ is.close();
+ fOutput.close();
+ return (file.getPath());
}
}
diff --git a/tests/tests/graphics/src/android/graphics/cts/YuvImageTest.java b/tests/tests/graphics/src/android/graphics/cts/YuvImageTest.java
index 6613e92..eb0b21f 100755
--- a/tests/tests/graphics/src/android/graphics/cts/YuvImageTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/YuvImageTest.java
@@ -203,6 +203,56 @@
}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getHeight",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getWidth",
+ args = {}
+ )
+ })
+ public void testGetHeight() {
+ generateTestBitmaps(WIDTH, HEIGHT);
+ YuvImage image = generateYuvImage(ImageFormat.YUY2, mTestBitmaps[0], 0);
+ assertEquals(mTestBitmaps[0].getHeight(), image.getHeight());
+ assertEquals(mTestBitmaps[0].getWidth(), image.getWidth());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getYuvData",
+ args = {}
+ )
+ public void testGetYuvData() {
+ generateTestBitmaps(WIDTH, HEIGHT);
+ int width = mTestBitmaps[0].getWidth();
+ int height = mTestBitmaps[0].getHeight();
+ int stride = width;
+ int[] argb = new int[stride * height];
+ mTestBitmaps[0].getPixels(argb, 0, stride, 0, 0, width, height);
+ byte[] yuv = convertArgbsToYuvs(argb, stride, height, ImageFormat.NV21);
+ int[] strides = new int[] {
+ stride, stride
+ };
+ YuvImage image = new YuvImage(yuv, ImageFormat.NV21, width, height, strides);
+ assertEquals(yuv, image.getYuvData());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "getYuvFormat",
+ args = {}
+ )
+ public void testGetYuvFormat() {
+ generateTestBitmaps(WIDTH, HEIGHT);
+ YuvImage image = generateYuvImage(ImageFormat.YUY2, mTestBitmaps[0], 0);
+ assertEquals(ImageFormat.YUY2, image.getYuvFormat());
+ }
+
private void generateTestBitmaps(int width, int height) {
Bitmap dst = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(dst);
@@ -220,7 +270,7 @@
int width = bitmap.getWidth();
int height = bitmap.getHeight();
- int stride = width + paddings;;
+ int stride = width + paddings;
YuvImage image = null;
int[] argb = new int [stride * height];
@@ -251,7 +301,6 @@
Rect expectedRect = sameRect ? actualRect : rect1;
expected = Bitmap.createBitmap(testBitmap, expectedRect.left, expectedRect.top, expectedRect.width(), expectedRect.height());
-
compareBitmaps(expected, actual, mMseMargin, sameRect);
}
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java
index a27aa9d..5e9e88d 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java
@@ -41,6 +41,7 @@
import android.graphics.drawable.Drawable.ConstantState;
import android.test.InstrumentationTestCase;
import android.util.AttributeSet;
+import android.util.DisplayMetrics;
import android.view.Gravity;
import java.io.ByteArrayInputStream;
@@ -67,20 +68,40 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "BitmapDrawable",
+ args = {android.content.res.Resources.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "BitmapDrawable",
args = {android.graphics.Bitmap.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "BitmapDrawable",
+ args = {android.content.res.Resources.class, android.graphics.Bitmap.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "BitmapDrawable",
args = {java.lang.String.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "BitmapDrawable",
+ args = {android.content.res.Resources.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "BitmapDrawable",
args = {java.io.InputStream.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
+ method = "BitmapDrawable",
+ args = {android.content.res.Resources.class, java.io.InputStream.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
method = "getPaint",
args = {}
),
@@ -108,6 +129,10 @@
bitmapDrawable.getPaint().getFlags());
assertEquals(bitmap, bitmapDrawable.getBitmap());
+ new BitmapDrawable(mContext.getResources());
+
+ new BitmapDrawable(mContext.getResources(), bitmap);
+
new BitmapDrawable(mContext.getFilesDir().getPath());
new BitmapDrawable(new ByteArrayInputStream("test constructor".getBytes()));
@@ -115,8 +140,12 @@
// exceptional test
new BitmapDrawable((Bitmap) null);
+ new BitmapDrawable(mContext.getResources(), (String) null);
+
new BitmapDrawable((String) null);
+ new BitmapDrawable(mContext.getResources(), (InputStream) null);
+
new BitmapDrawable((InputStream) null);
}
@@ -416,6 +445,38 @@
assertEquals(48, bitmapDrawable.getIntrinsicHeight());
}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setTargetDensity",
+ args = {android.graphics.Canvas.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setTargetDensity",
+ args = {android.util.DisplayMetrics.class}
+ )
+ })
+ @SuppressWarnings("deprecation")
+ public void testSetTargetDensity() {
+ BitmapDrawable bitmapDrawable = new BitmapDrawable();
+
+ Bitmap bitmap = Bitmap.createBitmap(200, 300, Config.RGB_565);
+ Canvas canvas = new Canvas(bitmap);
+ bitmapDrawable = new BitmapDrawable(bitmap);
+ bitmapDrawable.setTargetDensity(canvas.getDensity());
+ assertEquals(200, bitmapDrawable.getIntrinsicWidth());
+ assertEquals(300, bitmapDrawable.getIntrinsicHeight());
+
+ DisplayMetrics disMetrics = new DisplayMetrics();
+ disMetrics = getInstrumentation().getTargetContext().getResources().getDisplayMetrics();
+ InputStream source = mContext.getResources().openRawResource(R.drawable.size_48x48);
+ bitmapDrawable = new BitmapDrawable(source);
+ bitmapDrawable.setTargetDensity(disMetrics.densityDpi);
+ assertEquals(48, bitmapDrawable.getIntrinsicWidth());
+ assertEquals(48, bitmapDrawable.getIntrinsicHeight());
+ }
+
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "inflate",
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java
index 9d586d9..4d37508 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java
@@ -29,6 +29,7 @@
import android.content.ContentResolver;
import android.content.res.Resources;
+import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.PixelFormat;
@@ -40,6 +41,7 @@
import android.test.AndroidTestCase;
import android.util.AttributeSet;
import android.util.StateSet;
+import android.util.TypedValue;
import android.util.Xml;
import java.io.File;
@@ -236,6 +238,116 @@
@TestTargetNew(
level = TestLevel.COMPLETE,
+ method = "createFromResourceStream",
+ args = {android.content.res.Resources.class, android.util.TypedValue.class,
+ java.io.InputStream.class, java.lang.String.class}
+ )
+ public void testCreateFromResourceStream1() throws FileNotFoundException, IOException {
+ FileInputStream inputEmptyStream = null;
+ FileInputStream inputStream = null;
+ File imageFile = null;
+ OutputStream outputEmptyStream = null;
+
+ assertNull(Drawable.createFromResourceStream(null, null, inputStream, "test.bmp"));
+
+ File emptyFile = new File(mContext.getFilesDir(), "tempemptyimage.jpg");
+
+ // write some random data.
+ try {
+ outputEmptyStream = new FileOutputStream(emptyFile);
+ outputEmptyStream.write(10);
+
+ inputEmptyStream = new FileInputStream(emptyFile);
+ assertNull(Drawable.createFromResourceStream(mResources, null, inputEmptyStream,
+ "Sample"));
+
+ imageFile = new File(mContext.getFilesDir(), "tempimage.jpg");
+
+ writeSampleImage(imageFile);
+
+ inputStream = new FileInputStream(imageFile);
+ final TypedValue value = new TypedValue();
+ assertNotNull(Drawable.createFromResourceStream(mResources, value, inputStream,
+ "Sample"));
+ } finally {
+
+ if (null != outputEmptyStream) {
+ outputEmptyStream.close();
+ }
+ if (null != inputEmptyStream) {
+ inputEmptyStream.close();
+ }
+ if (null != inputStream) {
+ inputStream.close();
+ }
+ if (emptyFile.exists()) {
+ assertTrue(emptyFile.delete());
+ }
+ if (imageFile.exists()) {
+ assertTrue(imageFile.delete());
+ }
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "createFromResourceStream",
+ args = {android.content.res.Resources.class, android.util.TypedValue.class,
+ java.io.InputStream.class, java.lang.String.class,
+ android.graphics.BitmapFactory.Options.class}
+ )
+ public void testCreateFromResourceStream2() throws FileNotFoundException, IOException {
+ FileInputStream inputEmptyStream = null;
+ FileInputStream inputStream = null;
+ File imageFile = null;
+ OutputStream outputEmptyStream = null;
+
+ BitmapFactory.Options opt = new BitmapFactory.Options();
+ opt.inScaled = false;
+
+ assertNull(Drawable.createFromResourceStream(null, null, inputStream, "test.bmp", opt));
+
+ File emptyFile = new File(mContext.getFilesDir(), "tempemptyimage.jpg");
+
+ // write some random data.
+ try {
+ outputEmptyStream = new FileOutputStream(emptyFile);
+ outputEmptyStream.write(10);
+
+ inputEmptyStream = new FileInputStream(emptyFile);
+ assertNull(Drawable.createFromResourceStream(mResources, null, inputEmptyStream,
+ "Sample", opt));
+
+ imageFile = new File(mContext.getFilesDir(), "tempimage.jpg");
+
+ writeSampleImage(imageFile);
+
+ inputStream = new FileInputStream(imageFile);
+ final TypedValue value = new TypedValue();
+ assertNotNull(Drawable.createFromResourceStream(mResources, value, inputStream,
+ "Sample", opt));
+ } finally {
+
+ if (null != outputEmptyStream) {
+ outputEmptyStream.close();
+ }
+ if (null != inputEmptyStream) {
+ inputEmptyStream.close();
+ }
+ if (null != inputStream) {
+ inputStream.close();
+ }
+ if (emptyFile.exists()) {
+ assertTrue(emptyFile.delete());
+ }
+ if (imageFile.exists()) {
+ assertTrue(imageFile.delete());
+ }
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
method = "createFromXml",
args = {android.content.res.Resources.class, org.xmlpull.v1.XmlPullParser.class}
)
diff --git a/tests/tests/graphics/src/android/graphics/drawable/shapes/cts/ShapeTest.java b/tests/tests/graphics/src/android/graphics/drawable/shapes/cts/ShapeTest.java
index 10c4022..99bde2f 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/shapes/cts/ShapeTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/shapes/cts/ShapeTest.java
@@ -21,14 +21,25 @@
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
+import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
+import android.graphics.RectF;
+import android.graphics.Bitmap.Config;
+import android.graphics.Paint.Style;
+import android.graphics.drawable.shapes.RoundRectShape;
import android.graphics.drawable.shapes.Shape;
import junit.framework.TestCase;
@TestTargetClass(android.graphics.drawable.shapes.Shape.class)
public class ShapeTest extends TestCase {
+ private static final int TEST_WIDTH = 100;
+ private static final int TEST_HEIGHT = 200;
+
+ private static final int TEST_COLOR_1 = 0xFF00FF00;
+ private static final int TEST_COLOR_2 = 0xFFFF0000;
+
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
@@ -114,7 +125,30 @@
args = {}
)
public void testHasAlpha() {
- assertTrue(new MockShape().hasAlpha());
+ Shape shape = new MockShape();
+ assertTrue(shape.hasAlpha());
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "draw",
+ args = {android.graphics.Canvas.class, android.graphics.Paint.class}
+ )
+ public void testDraw() {
+ Shape shape = new MockShape();
+ Bitmap bitmap = Bitmap.createBitmap(TEST_WIDTH, TEST_HEIGHT, Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+ Paint paint = new Paint();
+ paint.setStyle(Style.FILL);
+ paint.setColor(TEST_COLOR_1);
+ shape.resize(TEST_WIDTH, TEST_HEIGHT);
+
+ shape.draw(canvas, paint);
+ assertEquals(0, bitmap.getPixel(0, 0));
+
+ paint.setColor(TEST_COLOR_2);
+ shape.draw(canvas, paint);
+ assertEquals(0, bitmap.getPixel(0, 0));
}
private static class MockShape extends Shape {
diff --git a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
index 70b108e..ee0b025 100644
--- a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
@@ -395,6 +395,40 @@
assertTrue(mOnInfoCalled);
}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setMaxDuration",
+ args = {int.class}
+ )
+ public void testSetMaxDuration() throws Exception {
+ mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
+ mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
+ mMediaRecorder.setMaxDuration(0);
+ mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
+ mMediaRecorder.prepare();
+ mMediaRecorder.start();
+ Thread.sleep(RECORD_TIME * 30);
+ mMediaRecorder.stop();
+ checkOutputExist();
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ method = "setMaxFileSize",
+ args = {int.class}
+ )
+ public void testSetMaxFileSize() throws Exception {
+ mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
+ mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
+ mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
+ mMediaRecorder.setMaxFileSize(0);
+ mMediaRecorder.prepare();
+ mMediaRecorder.start();
+ Thread.sleep(RECORD_TIME * 30);
+ mMediaRecorder.stop();
+ checkOutputExist();
+ }
+
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,