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.assertParcelSane 22 import org.junit.Assert.assertEquals 23 import org.junit.Test 24 import org.junit.runner.RunWith 25 26 private const val NO_LIFETIME: Long = -1L 27 28 @RunWith(AndroidJUnit4::class) 29 @SmallTest 30 class RaEventTest { 31 @Test testConstructorAndParcelnull32 fun testConstructorAndParcel() { 33 var raEvent = RaEvent.Builder().build() 34 assertEquals(NO_LIFETIME, raEvent.routerLifetime) 35 assertEquals(NO_LIFETIME, raEvent.prefixValidLifetime) 36 assertEquals(NO_LIFETIME, raEvent.prefixPreferredLifetime) 37 assertEquals(NO_LIFETIME, raEvent.routeInfoLifetime) 38 assertEquals(NO_LIFETIME, raEvent.rdnssLifetime) 39 assertEquals(NO_LIFETIME, raEvent.dnsslLifetime) 40 41 raEvent = RaEvent.Builder() 42 .updateRouterLifetime(1) 43 .updatePrefixValidLifetime(2) 44 .updatePrefixPreferredLifetime(3) 45 .updateRouteInfoLifetime(4) 46 .updateRdnssLifetime(5) 47 .updateDnsslLifetime(6) 48 .build() 49 assertEquals(1, raEvent.routerLifetime) 50 assertEquals(2, raEvent.prefixValidLifetime) 51 assertEquals(3, raEvent.prefixPreferredLifetime) 52 assertEquals(4, raEvent.routeInfoLifetime) 53 assertEquals(5, raEvent.rdnssLifetime) 54 assertEquals(6, raEvent.dnsslLifetime) 55 56 raEvent = RaEvent.Builder() 57 .updateRouterLifetime(Long.MIN_VALUE) 58 .updateRouterLifetime(Long.MAX_VALUE) 59 .build() 60 assertEquals(Long.MIN_VALUE, raEvent.routerLifetime) 61 62 raEvent = RaEvent(1, 2, 3, 4, 5, 6) 63 assertEquals(1, raEvent.routerLifetime) 64 assertEquals(2, raEvent.prefixValidLifetime) 65 assertEquals(3, raEvent.prefixPreferredLifetime) 66 assertEquals(4, raEvent.routeInfoLifetime) 67 assertEquals(5, raEvent.rdnssLifetime) 68 assertEquals(6, raEvent.dnsslLifetime) 69 70 assertParcelSane(raEvent, 6) 71 } 72 } 73