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 static android.net.NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS; 20 import static android.net.NetworkCapabilities.REDACT_NONE; 21 22 import static com.android.testutils.ParcelUtils.assertParcelSane; 23 24 import static org.junit.Assert.assertEquals; 25 import static org.junit.Assert.assertNotEquals; 26 27 import android.os.Build; 28 29 import androidx.test.filters.SmallTest; 30 31 import com.android.testutils.DevSdkIgnoreRule; 32 import com.android.testutils.DevSdkIgnoreRunner; 33 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 37 @RunWith(DevSdkIgnoreRunner.class) 38 @SmallTest 39 @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R) 40 public class VpnTransportInfoTest { 41 42 @Test testParceling()43 public void testParceling() { 44 VpnTransportInfo v = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM, "12345"); 45 assertParcelSane(v, 2 /* fieldCount */); 46 } 47 48 @Test testEqualsAndHashCode()49 public void testEqualsAndHashCode() { 50 String session1 = "12345"; 51 String session2 = "6789"; 52 VpnTransportInfo v11 = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM, session1); 53 VpnTransportInfo v12 = new VpnTransportInfo(VpnManager.TYPE_VPN_SERVICE, session1); 54 VpnTransportInfo v13 = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM, session1); 55 VpnTransportInfo v14 = new VpnTransportInfo(VpnManager.TYPE_VPN_LEGACY, session1); 56 VpnTransportInfo v15 = new VpnTransportInfo(VpnManager.TYPE_VPN_OEM, session1); 57 VpnTransportInfo v21 = new VpnTransportInfo(VpnManager.TYPE_VPN_LEGACY, session2); 58 59 VpnTransportInfo v31 = v11.makeCopy(REDACT_FOR_NETWORK_SETTINGS); 60 VpnTransportInfo v32 = v13.makeCopy(REDACT_FOR_NETWORK_SETTINGS); 61 62 assertNotEquals(v11, v12); 63 assertNotEquals(v13, v14); 64 assertNotEquals(v14, v15); 65 assertNotEquals(v14, v21); 66 67 assertEquals(v11, v13); 68 assertEquals(v31, v32); 69 assertEquals(v11.hashCode(), v13.hashCode()); 70 assertEquals(REDACT_FOR_NETWORK_SETTINGS, v32.getApplicableRedactions()); 71 assertEquals(session1, v15.makeCopy(REDACT_NONE).getSessionId()); 72 } 73 } 74