• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.ConnectivityModuleTest
22 import com.android.testutils.DevSdkIgnoreRule
23 import com.android.testutils.DevSdkIgnoreRunner
24 import com.android.testutils.assertParcelingIsLossless
25 import org.junit.Test
26 import org.junit.runner.RunWith
27 import kotlin.test.assertEquals
28 
29 private const val TEST_OWNER_UID = 123
30 private const val TEST_IFACE = "test_tun0"
31 private val TEST_IFACE_LIST = listOf("wlan0", "rmnet_data0", "eth0")
32 
33 @SmallTest
34 @RunWith(DevSdkIgnoreRunner::class)
35 @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R)
36 @ConnectivityModuleTest
37 class UnderlyingNetworkInfoTest {
38     @Test
testParcelUnparcelnull39     fun testParcelUnparcel() {
40         val testInfo = UnderlyingNetworkInfo(TEST_OWNER_UID, TEST_IFACE, TEST_IFACE_LIST)
41         assertEquals(TEST_OWNER_UID, testInfo.getOwnerUid())
42         assertEquals(TEST_IFACE, testInfo.getInterface())
43         assertEquals(TEST_IFACE_LIST, testInfo.getUnderlyingInterfaces())
44         assertParcelingIsLossless(testInfo)
45 
46         val emptyInfo = UnderlyingNetworkInfo(0, String(), listOf())
47         assertEquals(0, emptyInfo.getOwnerUid())
48         assertEquals(String(), emptyInfo.getInterface())
49         assertEquals(listOf(), emptyInfo.getUnderlyingInterfaces())
50         assertParcelingIsLossless(emptyInfo)
51     }
52 }