1 /* 2 * Copyright (C) 2009 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 17 package android.view.inputmethod.cts; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertNotNull; 21 22 import android.os.Parcel; 23 import android.view.inputmethod.CompletionInfo; 24 25 import androidx.test.filters.SmallTest; 26 import androidx.test.runner.AndroidJUnit4; 27 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @SmallTest 32 @RunWith(AndroidJUnit4.class) 33 public class CompletionInfoTest { 34 private static final int ID = 1; 35 private static final int POSITION = 1; 36 private static final String TEXT = "CompletionInfoText"; 37 private static final String LABEL = "CompletionInfoLabel"; 38 39 @Test 40 public void testCompletionInfo() { 41 new CompletionInfo(ID, POSITION, TEXT); 42 CompletionInfo info = new CompletionInfo(ID, POSITION, TEXT, LABEL); 43 assertCompletionInfo(info); 44 45 assertEquals(0, info.describeContents()); 46 assertNotNull(info.toString()); 47 48 Parcel p = Parcel.obtain(); 49 info.writeToParcel(p, 0); 50 p.setDataPosition(0); 51 CompletionInfo targetInfo = CompletionInfo.CREATOR.createFromParcel(p); 52 p.recycle(); 53 assertCompletionInfo(targetInfo); 54 } 55 56 private void assertCompletionInfo(CompletionInfo info) { 57 assertEquals(ID, info.getId()); 58 assertEquals(POSITION, info.getPosition()); 59 assertEquals(TEXT, info.getText().toString()); 60 assertEquals(LABEL, info.getLabel().toString()); 61 } 62 } 63