1 /*
2  * Copyright 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 
17 package android.uwb;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import android.content.AttributionSource;
22 import android.os.Parcel;
23 import android.os.Process;
24 
25 import androidx.test.ext.junit.runners.AndroidJUnit4;
26 import androidx.test.filters.SmallTest;
27 
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 
31 /**
32  * Test of {@link SessionHandle}.
33  */
34 @SmallTest
35 @RunWith(AndroidJUnit4.class)
36 public class SessionHandleTest {
37     private static final int UID = Process.myUid();
38     private static final String PACKAGE_NAME = "com.uwb.test";
39     private static final AttributionSource ATTRIBUTION_SOURCE =
40             new AttributionSource.Builder(UID).setPackageName(PACKAGE_NAME).build();
41     private static final int HANDLE_ID = 12;
42     private static final int PID = Process.myPid();
43 
44     @Test
testBasic()45     public void testBasic() {
46         SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID);
47         assertEquals(handle.getId(), HANDLE_ID);
48         assertEquals(handle.getPackageName(), PACKAGE_NAME);
49         assertEquals(handle.getUid(), UID);
50         assertEquals(handle.getPid(), PID);
51     }
52 
53     @Test
testParcel()54     public void testParcel() {
55         Parcel parcel = Parcel.obtain();
56         SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID);
57         handle.writeToParcel(parcel, 0);
58         parcel.setDataPosition(0);
59         SessionHandle fromParcel = SessionHandle.CREATOR.createFromParcel(parcel);
60         assertEquals(handle, fromParcel);
61     }
62 }
63