diff options
author | Chiao Cheng <chiaocheng@google.com> | 2012-10-16 13:21:10 -0700 |
---|---|---|
committer | Chiao Cheng <chiaocheng@google.com> | 2012-10-16 13:21:10 -0700 |
commit | c36c3196c594b992cec8b5de1a3dba7556648804 (patch) | |
tree | c03d19497388c78226f90e31309290c4b81dc4b4 /tests | |
parent | 439c352a9a23bdb89e43a8977eb0ae30f4e88824 (diff) | |
download | android_packages_apps_ContactsCommon-c36c3196c594b992cec8b5de1a3dba7556648804.tar.gz android_packages_apps_ContactsCommon-c36c3196c594b992cec8b5de1a3dba7556648804.tar.bz2 android_packages_apps_ContactsCommon-c36c3196c594b992cec8b5de1a3dba7556648804.zip |
Adding ContactPhotoManager and dependent classes.
Moved from People package so it can be shared by dialer.
Bug: 6993891
Change-Id: I85268c040498621a324c459ce237a51b30e7d3a4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Android.mk | 1 | ||||
-rwxr-xr-x | tests/bin/test.sh | 3 | ||||
-rw-r--r-- | tests/src/com/android/contacts/common/util/BitmapUtilTests.java | 123 |
3 files changed, 127 insertions, 0 deletions
diff --git a/tests/Android.mk b/tests/Android.mk index 4ae1a0d1..c4f961f9 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -34,5 +34,6 @@ LOCAL_AAPT_FLAGS := \ LOCAL_STATIC_JAVA_LIBRARIES += com.android.contacts.common.test com.android.phone.shared LOCAL_PACKAGE_NAME := ContactsCommonTests +LOCAL_INSTRUMENTATION_FOR := com.android.contacts.common include $(BUILD_PACKAGE) diff --git a/tests/bin/test.sh b/tests/bin/test.sh new file mode 100755 index 00000000..f0d3666a --- /dev/null +++ b/tests/bin/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +adb shell am instrument -w com.android.contacts.common.unittest/android.test.InstrumentationTestRunner diff --git a/tests/src/com/android/contacts/common/util/BitmapUtilTests.java b/tests/src/com/android/contacts/common/util/BitmapUtilTests.java new file mode 100644 index 00000000..94394b1e --- /dev/null +++ b/tests/src/com/android/contacts/common/util/BitmapUtilTests.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2012 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 com.android.contacts.common.util; + +import android.graphics.Bitmap; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.contacts.common.util.BitmapUtil; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * Tests for {@link com.android.contacts.common.util.BitmapUtil}. + */ +@SmallTest +public class BitmapUtilTests extends AndroidTestCase { + public void testGetSmallerExtentFromBytes1() throws Exception { + assertEquals(100, BitmapUtil.getSmallerExtentFromBytes(createJpegRawData(100, 100))); + assertEquals(100, BitmapUtil.getSmallerExtentFromBytes(createPngRawData(100, 100))); + } + + public void testGetSmallerExtentFromBytes2() throws Exception { + assertEquals(50, BitmapUtil.getSmallerExtentFromBytes(createJpegRawData(200, 50))); + assertEquals(50, BitmapUtil.getSmallerExtentFromBytes(createPngRawData(200, 50))); + } + + public void testGetSmallerExtentFromBytes3() throws Exception { + assertEquals(40, BitmapUtil.getSmallerExtentFromBytes(createJpegRawData(40, 150))); + assertEquals(40, BitmapUtil.getSmallerExtentFromBytes(createPngRawData(40, 150))); + } + + public void testFindOptimalSampleSizeExact() throws Exception { + assertEquals(1, BitmapUtil.findOptimalSampleSize(512, 512)); + } + + public void testFindOptimalSampleSizeBigger() throws Exception { + assertEquals(1, BitmapUtil.findOptimalSampleSize(512, 1024)); + } + + public void testFindOptimalSampleSizeSmaller1() throws Exception { + assertEquals(2, BitmapUtil.findOptimalSampleSize(512, 256)); + } + + public void testFindOptimalSampleSizeSmaller2() throws Exception { + assertEquals(2, BitmapUtil.findOptimalSampleSize(512, 230)); + } + + public void testFindOptimalSampleSizeSmaller3() throws Exception { + assertEquals(4, BitmapUtil.findOptimalSampleSize(512, 129)); + } + + public void testFindOptimalSampleSizeSmaller4() throws Exception { + assertEquals(4, BitmapUtil.findOptimalSampleSize(512, 128)); + } + + public void testFindOptimalSampleSizeUnknownOriginal() throws Exception { + assertEquals(1, BitmapUtil.findOptimalSampleSize(-1, 128)); + } + + public void testFindOptimalSampleSizeUnknownTarget() throws Exception { + assertEquals(1, BitmapUtil.findOptimalSampleSize(128, -1)); + } + + public void testDecodeWithSampleSize1() throws IOException { + assertBitmapSize(128, 64, BitmapUtil.decodeBitmapFromBytes(createJpegRawData(128, 64), 1)); + assertBitmapSize(128, 64, BitmapUtil.decodeBitmapFromBytes(createPngRawData(128, 64), 1)); + } + + public void testDecodeWithSampleSize2() throws IOException { + assertBitmapSize(64, 32, BitmapUtil.decodeBitmapFromBytes(createJpegRawData(128, 64), 2)); + assertBitmapSize(64, 32, BitmapUtil.decodeBitmapFromBytes(createPngRawData(128, 64), 2)); + } + + public void testDecodeWithSampleSize2a() throws IOException { + assertBitmapSize(25, 20, BitmapUtil.decodeBitmapFromBytes(createJpegRawData(50, 40), 2)); + assertBitmapSize(25, 20, BitmapUtil.decodeBitmapFromBytes(createPngRawData(50, 40), 2)); + } + + public void testDecodeWithSampleSize4() throws IOException { + assertBitmapSize(32, 16, BitmapUtil.decodeBitmapFromBytes(createJpegRawData(128, 64), 4)); + assertBitmapSize(32, 16, BitmapUtil.decodeBitmapFromBytes(createPngRawData(128, 64), 4)); + } + + private void assertBitmapSize(int expectedWidth, int expectedHeight, Bitmap bitmap) { + assertEquals(expectedWidth, bitmap.getWidth()); + assertEquals(expectedHeight, bitmap.getHeight()); + } + + private byte[] createJpegRawData(int sourceWidth, int sourceHeight) throws IOException { + return createRawData(Bitmap.CompressFormat.JPEG, sourceWidth, sourceHeight); + } + + private byte[] createPngRawData(int sourceWidth, int sourceHeight) throws IOException { + return createRawData(Bitmap.CompressFormat.PNG, sourceWidth, sourceHeight); + } + + private byte[] createRawData(Bitmap.CompressFormat format, int sourceWidth, + int sourceHeight) throws IOException { + // Create a temp bitmap as our source + Bitmap b = Bitmap.createBitmap(sourceWidth, sourceHeight, Bitmap.Config.ARGB_8888); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + b.compress(format, 50, outputStream); + final byte[] data = outputStream.toByteArray(); + outputStream.close(); + return data; + } +} |