1 /* 2 * Copyright (C) 2019 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.metrics; 18 19 import androidx.test.filters.SmallTest 20 import androidx.test.runner.AndroidJUnit4 21 import com.android.testutils.assertParcelingIsLossless 22 import org.junit.Assert.assertEquals 23 import org.junit.Assert.assertFalse 24 import org.junit.Assert.assertTrue 25 import org.junit.Test 26 import org.junit.runner.RunWith 27 28 @RunWith(AndroidJUnit4::class) 29 @SmallTest 30 class ApfProgramEventTest { hasFlagnull31 private infix fun Int.hasFlag(flag: Int) = (this and (1 shl flag)) != 0 32 33 @Test 34 fun testBuilderAndParcel() { 35 val apfProgramEvent = ApfProgramEvent.Builder() 36 .setLifetime(1) 37 .setActualLifetime(2) 38 .setFilteredRas(3) 39 .setCurrentRas(4) 40 .setProgramLength(5) 41 .setFlags(true, true) 42 .build() 43 44 assertEquals(1, apfProgramEvent.lifetime) 45 assertEquals(2, apfProgramEvent.actualLifetime) 46 assertEquals(3, apfProgramEvent.filteredRas) 47 assertEquals(4, apfProgramEvent.currentRas) 48 assertEquals(5, apfProgramEvent.programLength) 49 assertEquals(ApfProgramEvent.flagsFor(true, true), apfProgramEvent.flags) 50 51 assertParcelingIsLossless(apfProgramEvent) 52 } 53 54 @Test testFlagsFornull55 fun testFlagsFor() { 56 var flags = ApfProgramEvent.flagsFor(false, false) 57 assertFalse(flags hasFlag ApfProgramEvent.FLAG_HAS_IPV4_ADDRESS) 58 assertFalse(flags hasFlag ApfProgramEvent.FLAG_MULTICAST_FILTER_ON) 59 60 flags = ApfProgramEvent.flagsFor(true, false) 61 assertTrue(flags hasFlag ApfProgramEvent.FLAG_HAS_IPV4_ADDRESS) 62 assertFalse(flags hasFlag ApfProgramEvent.FLAG_MULTICAST_FILTER_ON) 63 64 flags = ApfProgramEvent.flagsFor(false, true) 65 assertFalse(flags hasFlag ApfProgramEvent.FLAG_HAS_IPV4_ADDRESS) 66 assertTrue(flags hasFlag ApfProgramEvent.FLAG_MULTICAST_FILTER_ON) 67 68 flags = ApfProgramEvent.flagsFor(true, true) 69 assertTrue(flags hasFlag ApfProgramEvent.FLAG_HAS_IPV4_ADDRESS) 70 assertTrue(flags hasFlag ApfProgramEvent.FLAG_MULTICAST_FILTER_ON) 71 } 72 } 73