1194d2514e818128c478c2b8e693715affa324ee9Scott Su/* 2194d2514e818128c478c2b8e693715affa324ee9Scott Su * Copyright (C) 2008 The Android Open Source Project 3194d2514e818128c478c2b8e693715affa324ee9Scott Su * 4194d2514e818128c478c2b8e693715affa324ee9Scott Su * Licensed under the Apache License, Version 2.0 (the "License"); 5194d2514e818128c478c2b8e693715affa324ee9Scott Su * you may not use this file except in compliance with the License. 6194d2514e818128c478c2b8e693715affa324ee9Scott Su * You may obtain a copy of the License at 7194d2514e818128c478c2b8e693715affa324ee9Scott Su * 8194d2514e818128c478c2b8e693715affa324ee9Scott Su * http://www.apache.org/licenses/LICENSE-2.0 9194d2514e818128c478c2b8e693715affa324ee9Scott Su * 10194d2514e818128c478c2b8e693715affa324ee9Scott Su * Unless required by applicable law or agreed to in writing, software 11194d2514e818128c478c2b8e693715affa324ee9Scott Su * distributed under the License is distributed on an "AS IS" BASIS, 12194d2514e818128c478c2b8e693715affa324ee9Scott Su * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13194d2514e818128c478c2b8e693715affa324ee9Scott Su * See the License for the specific language governing permissions and 14194d2514e818128c478c2b8e693715affa324ee9Scott Su * limitations under the License. 15194d2514e818128c478c2b8e693715affa324ee9Scott Su */ 16194d2514e818128c478c2b8e693715affa324ee9Scott Su 17194d2514e818128c478c2b8e693715affa324ee9Scott Supackage android.text.style.cts; 18194d2514e818128c478c2b8e693715affa324ee9Scott Su 19194d2514e818128c478c2b8e693715affa324ee9Scott Suimport com.android.cts.stub.R; 20194d2514e818128c478c2b8e693715affa324ee9Scott Su 21194d2514e818128c478c2b8e693715affa324ee9Scott Su 22194d2514e818128c478c2b8e693715affa324ee9Scott Suimport android.content.Context; 23194d2514e818128c478c2b8e693715affa324ee9Scott Suimport android.graphics.Bitmap; 24194d2514e818128c478c2b8e693715affa324ee9Scott Suimport android.graphics.drawable.BitmapDrawable; 25194d2514e818128c478c2b8e693715affa324ee9Scott Suimport android.graphics.drawable.Drawable; 26194d2514e818128c478c2b8e693715affa324ee9Scott Suimport android.net.Uri; 27194d2514e818128c478c2b8e693715affa324ee9Scott Suimport android.test.AndroidTestCase; 28194d2514e818128c478c2b8e693715affa324ee9Scott Suimport android.text.style.DynamicDrawableSpan; 29194d2514e818128c478c2b8e693715affa324ee9Scott Suimport android.text.style.ImageSpan; 30194d2514e818128c478c2b8e693715affa324ee9Scott Suimport android.widget.cts.WidgetTestUtils; 31194d2514e818128c478c2b8e693715affa324ee9Scott Su 32194d2514e818128c478c2b8e693715affa324ee9Scott Supublic class ImageSpanTest extends AndroidTestCase { 33194d2514e818128c478c2b8e693715affa324ee9Scott Su public void testConstructor() { 34194d2514e818128c478c2b8e693715affa324ee9Scott Su int width = 80; 35194d2514e818128c478c2b8e693715affa324ee9Scott Su int height = 120; 36194d2514e818128c478c2b8e693715affa324ee9Scott Su int[] color = new int[width * height]; 37194d2514e818128c478c2b8e693715affa324ee9Scott Su Bitmap b = Bitmap.createBitmap(color, width, height, Bitmap.Config.RGB_565); 38194d2514e818128c478c2b8e693715affa324ee9Scott Su 39194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(b); 40194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(b, DynamicDrawableSpan.ALIGN_BOTTOM); 41194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(b, DynamicDrawableSpan.ALIGN_BASELINE); 42194d2514e818128c478c2b8e693715affa324ee9Scott Su 43194d2514e818128c478c2b8e693715affa324ee9Scott Su Drawable d = mContext.getResources().getDrawable(R.drawable.pass); 44194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(d); 45194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM); 46194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(d, DynamicDrawableSpan.ALIGN_BASELINE); 47194d2514e818128c478c2b8e693715affa324ee9Scott Su 48194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(d, "cts test."); 49194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(d, "cts test.", DynamicDrawableSpan.ALIGN_BOTTOM); 50194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(d, "cts test.", DynamicDrawableSpan.ALIGN_BASELINE); 51194d2514e818128c478c2b8e693715affa324ee9Scott Su 52194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(mContext, Uri.parse("content://user/a/b")); 53194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(mContext, Uri.parse("content://user/a/b"), 54194d2514e818128c478c2b8e693715affa324ee9Scott Su DynamicDrawableSpan.ALIGN_BOTTOM); 55194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(mContext, Uri.parse("content://user/a/b"), 56194d2514e818128c478c2b8e693715affa324ee9Scott Su DynamicDrawableSpan.ALIGN_BASELINE); 57194d2514e818128c478c2b8e693715affa324ee9Scott Su 58194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(mContext, R.drawable.pass); 59194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(mContext, R.drawable.pass, DynamicDrawableSpan.ALIGN_BOTTOM); 60194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan(mContext, R.drawable.pass, DynamicDrawableSpan.ALIGN_BASELINE); 61194d2514e818128c478c2b8e693715affa324ee9Scott Su 62194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan((Bitmap) null); 63194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan((Drawable) null); 64194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan((Drawable) null, (String) null); 65194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan((Context) null, -1); 66194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan((Bitmap) null, -1); 67194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan((Drawable) null, -1); 68194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan((Drawable) null, (String) null, -1); 69194d2514e818128c478c2b8e693715affa324ee9Scott Su new ImageSpan((Context) null, -1, -1); 70194d2514e818128c478c2b8e693715affa324ee9Scott Su } 71194d2514e818128c478c2b8e693715affa324ee9Scott Su 72194d2514e818128c478c2b8e693715affa324ee9Scott Su public void testGetSource() { 73194d2514e818128c478c2b8e693715affa324ee9Scott Su Drawable d = mContext.getResources().getDrawable(R.drawable.pass); 74194d2514e818128c478c2b8e693715affa324ee9Scott Su 75194d2514e818128c478c2b8e693715affa324ee9Scott Su ImageSpan imageSpan = new ImageSpan(d); 76194d2514e818128c478c2b8e693715affa324ee9Scott Su assertNull(imageSpan.getSource()); 77194d2514e818128c478c2b8e693715affa324ee9Scott Su 78194d2514e818128c478c2b8e693715affa324ee9Scott Su String source = "cts test."; 79194d2514e818128c478c2b8e693715affa324ee9Scott Su imageSpan = new ImageSpan(d, source); 80194d2514e818128c478c2b8e693715affa324ee9Scott Su assertEquals(source, imageSpan.getSource()); 81194d2514e818128c478c2b8e693715affa324ee9Scott Su 82194d2514e818128c478c2b8e693715affa324ee9Scott Su source = "content://user/a/b"; 83194d2514e818128c478c2b8e693715affa324ee9Scott Su imageSpan = new ImageSpan(mContext, Uri.parse(source)); 84194d2514e818128c478c2b8e693715affa324ee9Scott Su assertEquals(source, imageSpan.getSource()); 85194d2514e818128c478c2b8e693715affa324ee9Scott Su } 86194d2514e818128c478c2b8e693715affa324ee9Scott Su 87194d2514e818128c478c2b8e693715affa324ee9Scott Su public void testGetDrawable() { 88194d2514e818128c478c2b8e693715affa324ee9Scott Su Drawable drawable = mContext.getResources().getDrawable(R.drawable.pass); 89194d2514e818128c478c2b8e693715affa324ee9Scott Su 90194d2514e818128c478c2b8e693715affa324ee9Scott Su ImageSpan imageSpan = new ImageSpan(drawable); 91194d2514e818128c478c2b8e693715affa324ee9Scott Su assertSame(drawable, imageSpan.getDrawable()); 92194d2514e818128c478c2b8e693715affa324ee9Scott Su 93194d2514e818128c478c2b8e693715affa324ee9Scott Su BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; 94194d2514e818128c478c2b8e693715affa324ee9Scott Su imageSpan = new ImageSpan(mContext, R.drawable.pass); 95194d2514e818128c478c2b8e693715affa324ee9Scott Su BitmapDrawable resultDrawable = (BitmapDrawable) imageSpan.getDrawable(); 96194d2514e818128c478c2b8e693715affa324ee9Scott Su WidgetTestUtils.assertEquals(bitmapDrawable.getBitmap(), resultDrawable.getBitmap()); 97194d2514e818128c478c2b8e693715affa324ee9Scott Su 98194d2514e818128c478c2b8e693715affa324ee9Scott Su imageSpan = new ImageSpan(mContext, Uri.parse("unknown uri.")); 99194d2514e818128c478c2b8e693715affa324ee9Scott Su assertNull(imageSpan.getDrawable()); 100194d2514e818128c478c2b8e693715affa324ee9Scott Su 101194d2514e818128c478c2b8e693715affa324ee9Scott Su imageSpan = new ImageSpan((Context) null, -1); 102194d2514e818128c478c2b8e693715affa324ee9Scott Su assertNull(imageSpan.getDrawable()); 103194d2514e818128c478c2b8e693715affa324ee9Scott Su } 104194d2514e818128c478c2b8e693715affa324ee9Scott Su} 105