14a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com/*
23484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org * Copyright (C) 2010 The Android Open Source Project
33484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org *
44a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com * Licensed under the Apache License, Version 2.0 (the "License");
5196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org * you may not use this file except in compliance with the License.
65de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org * You may obtain a copy of the License at
75de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org *
84a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com *      http://www.apache.org/licenses/LICENSE-2.0
94a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com *
104a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com * Unless required by applicable law or agreed to in writing, software
114a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com * distributed under the License is distributed on an "AS IS" BASIS,
124a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139f18d9111f676f2899d9aa2444130c985eb75395machenbach@chromium.org * See the License for the specific language governing permissions and
149f18d9111f676f2899d9aa2444130c985eb75395machenbach@chromium.org * limitations under the License.
154a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com */
164f99be9ff2091451687891a05d99cc31990de709hpayer@chromium.org
174a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.compackage android.graphics;
184a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com
194a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.comimport android.os.ParcelFileDescriptor;
20d4be0f0c0edfc0a0b46e745055c3dc497c0ffcb5verwaest@chromium.orgimport android.test.suitebuilder.annotation.SmallTest;
21c8cbc43a1fd5fda5d6a1e172f720cbd1215157c8machenbach@chromium.org
22c8cbc43a1fd5fda5d6a1e172f720cbd1215157c8machenbach@chromium.orgimport java.io.ByteArrayOutputStream;
23c8cbc43a1fd5fda5d6a1e172f720cbd1215157c8machenbach@chromium.orgimport java.io.FileDescriptor;
244a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com
254a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.comimport junit.framework.TestCase;
264a6c3279070e8f133607a74c08d8c08ac394ab98erik.corry@gmail.com
27
28public class BitmapFactoryTest extends TestCase {
29
30    // tests that we can decode bitmaps from MemoryFiles
31    @SmallTest
32    public void testBitmapParcelFileDescriptor() throws Exception {
33        Bitmap bitmap1 = Bitmap.createBitmap(
34                new int[] { Color.BLUE }, 1, 1, Bitmap.Config.RGB_565);
35        ByteArrayOutputStream out = new ByteArrayOutputStream();
36        bitmap1.compress(Bitmap.CompressFormat.PNG, 100, out);
37        ParcelFileDescriptor pfd = ParcelFileDescriptor.fromData(out.toByteArray(), null);
38        FileDescriptor fd = pfd.getFileDescriptor();
39        assertNotNull("Got null FileDescriptor", fd);
40        assertTrue("Got invalid FileDescriptor", fd.valid());
41        Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd);
42        assertNotNull("BitmapFactory returned null", bitmap);
43        assertEquals("Bitmap width", 1, bitmap.getWidth());
44        assertEquals("Bitmap height", 1, bitmap.getHeight());
45    }
46
47}
48