diff options
author | Yan Yan <evitayan@google.com> | 2021-02-19 13:16:04 -0800 |
---|---|---|
committer | Yan Yan <evitayan@google.com> | 2021-02-23 10:39:17 -0800 |
commit | 2a9bfb281fadeb74ebaac43794c206e25e1ab873 (patch) | |
tree | 7d9bb5b46a96cd5a9b44ba4773303d6b170c8171 /tests/vcn | |
parent | bf16b6d3996dd2e0bf2fd8410712afc1eb63892f (diff) |
Support converting IkeTrafficSelector to/from PersistableBundle
Bug: 163604823
Test: FrameworksVcnTests(new tests added)
Change-Id: I7b2613d62fa555c3c1eb125a1d971771b954e9ca
Diffstat (limited to 'tests/vcn')
-rw-r--r-- | tests/vcn/java/android/net/vcn/persistablebundleutils/IkeTrafficSelectorUtilsTest.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/vcn/java/android/net/vcn/persistablebundleutils/IkeTrafficSelectorUtilsTest.java b/tests/vcn/java/android/net/vcn/persistablebundleutils/IkeTrafficSelectorUtilsTest.java new file mode 100644 index 000000000000..28cf38a2a583 --- /dev/null +++ b/tests/vcn/java/android/net/vcn/persistablebundleutils/IkeTrafficSelectorUtilsTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.vcn.persistablebundleutils; + +import static org.junit.Assert.assertEquals; + +import android.net.InetAddresses; +import android.net.ipsec.ike.IkeTrafficSelector; +import android.os.PersistableBundle; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.net.InetAddress; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class IkeTrafficSelectorUtilsTest { + private static final int START_PORT = 16; + private static final int END_PORT = 65520; + + private static final InetAddress IPV4_START_ADDRESS = + InetAddresses.parseNumericAddress("192.0.2.100"); + private static final InetAddress IPV4_END_ADDRESS = + InetAddresses.parseNumericAddress("192.0.2.101"); + + private static final InetAddress IPV6_START_ADDRESS = + InetAddresses.parseNumericAddress("2001:db8:2::100"); + private static final InetAddress IPV6_END_ADDRESS = + InetAddresses.parseNumericAddress("2001:db8:2::101"); + + private static void verifyPersistableBundleEncodeDecodeIsLossless(IkeTrafficSelector ts) { + final PersistableBundle bundle = IkeTrafficSelectorUtils.toPersistableBundle(ts); + final IkeTrafficSelector resultTs = IkeTrafficSelectorUtils.fromPersistableBundle(bundle); + assertEquals(ts, resultTs); + } + + @Test + public void testPersistableBundleEncodeDecodeIsLosslessIpv4Ts() throws Exception { + verifyPersistableBundleEncodeDecodeIsLossless( + new IkeTrafficSelector(START_PORT, END_PORT, IPV4_START_ADDRESS, IPV4_END_ADDRESS)); + } + + @Test + public void testPersistableBundleEncodeDecodeIsLosslessIpv6Ts() throws Exception { + verifyPersistableBundleEncodeDecodeIsLossless( + new IkeTrafficSelector(START_PORT, END_PORT, IPV6_START_ADDRESS, IPV6_END_ADDRESS)); + } +} |