1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.smartspace.cts; 17 18 import static com.google.common.truth.Truth.assertThat; 19 20 import android.app.smartspace.uitemplatedata.Icon; 21 import android.graphics.Bitmap; 22 import android.os.Parcel; 23 24 import androidx.test.runner.AndroidJUnit4; 25 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 /** 30 * Tests for {@link Icon} 31 * 32 * atest CtsSmartspaceServiceTestCases 33 */ 34 @RunWith(AndroidJUnit4.class) 35 public class IconTest { 36 37 private static final String TAG = "IconTest"; 38 39 @Test testCreateIcon()40 public void testCreateIcon() { 41 android.graphics.drawable.Icon icon = android.graphics.drawable.Icon.createWithBitmap( 42 Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8)); 43 Icon smartspaceIcon = new Icon.Builder(icon).setContentDescription( 44 "test content").setShouldTint(false).build(); 45 46 assertThat(smartspaceIcon.getIcon()).isEqualTo(icon); 47 assertThat(smartspaceIcon.getContentDescription()).isEqualTo("test content"); 48 assertThat(smartspaceIcon.shouldTint()).isFalse(); 49 50 Parcel parcel = Parcel.obtain(); 51 parcel.setDataPosition(0); 52 smartspaceIcon.writeToParcel(parcel, 0); 53 parcel.setDataPosition(0); 54 Icon copyIcon = Icon.CREATOR.createFromParcel(parcel); 55 assertThat(smartspaceIcon).isEqualTo(copyIcon); 56 parcel.recycle(); 57 } 58 } 59