1 /*
2  * Copyright (C) 2021 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.net
18 
19 import android.os.Build
20 import androidx.test.filters.SmallTest
21 import com.android.testutils.DevSdkIgnoreRule
22 import com.android.testutils.DevSdkIgnoreRunner
23 import com.android.testutils.assertParcelingIsLossless
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 import kotlin.test.assertEquals
27 
28 private const val TEST_OWNER_UID = 123
29 private const val TEST_IFACE = "test_tun0"
30 private val TEST_IFACE_LIST = listOf("wlan0", "rmnet_data0", "eth0")
31 
32 @SmallTest
33 @RunWith(DevSdkIgnoreRunner::class)
34 @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R)
35 class UnderlyingNetworkInfoTest {
36     @Test
37     fun testParcelUnparcel() {
38         val testInfo = UnderlyingNetworkInfo(TEST_OWNER_UID, TEST_IFACE, TEST_IFACE_LIST)
39         assertEquals(TEST_OWNER_UID, testInfo.getOwnerUid())
40         assertEquals(TEST_IFACE, testInfo.getInterface())
41         assertEquals(TEST_IFACE_LIST, testInfo.getUnderlyingInterfaces())
42         assertParcelingIsLossless(testInfo)
43 
44         val emptyInfo = UnderlyingNetworkInfo(0, String(), listOf())
45         assertEquals(0, emptyInfo.getOwnerUid())
46         assertEquals(String(), emptyInfo.getInterface())
47         assertEquals(listOf(), emptyInfo.getUnderlyingInterfaces())
48         assertParcelingIsLossless(emptyInfo)
49     }
50 }