1 /* 2 * Copyright (C) 2008 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 import static org.junit.Assert.assertSame; 22 23 import android.os.Binder; 24 import android.os.Parcel; 25 import android.view.View; 26 import android.view.inputmethod.BaseInputConnection; 27 import android.view.inputmethod.InputBinding; 28 29 import androidx.test.InstrumentationRegistry; 30 import androidx.test.filters.SmallTest; 31 import androidx.test.runner.AndroidJUnit4; 32 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 36 @SmallTest 37 @RunWith(AndroidJUnit4.class) 38 public class InputBindingTest { 39 @Test 40 public void testInputBinding() { 41 View view = new View(InstrumentationRegistry.getTargetContext()); 42 BaseInputConnection bic = new BaseInputConnection(view, false); 43 Binder binder = new Binder(); 44 int uid = 1; 45 int pid = 2; 46 InputBinding inputBinding = new InputBinding(bic, binder, uid, pid); 47 new InputBinding(bic, inputBinding); 48 assertSame(bic, inputBinding.getConnection()); 49 assertSame(binder, inputBinding.getConnectionToken()); 50 assertEquals(uid, inputBinding.getUid()); 51 assertEquals(pid, inputBinding.getPid()); 52 53 assertNotNull(inputBinding.toString()); 54 assertEquals(0, inputBinding.describeContents()); 55 56 Parcel p = Parcel.obtain(); 57 inputBinding.writeToParcel(p, 0); 58 p.setDataPosition(0); 59 InputBinding target = InputBinding.CREATOR.createFromParcel(p); 60 assertEquals(uid, target.getUid()); 61 assertEquals(pid, target.getPid()); 62 assertSame(binder, target.getConnectionToken()); 63 64 p.recycle(); 65 } 66 } 67