1 /* 2 * Copyright (C) 2017 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 package com.android.server.devicepolicy; 17 18 import static com.google.common.truth.Truth.assertThat; 19 20 import android.test.suitebuilder.annotation.SmallTest; 21 22 import org.junit.Test; 23 24 /** 25 * Test for {@link DevicePolicyConstants}. 26 * 27 * <p>Run this test with: 28 * 29 * {@code atest FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyConstantsTest} 30 */ 31 @SmallTest 32 public class DevicePolicyConstantsTest { 33 private static final String TAG = "DevicePolicyConstantsTest"; 34 35 @Test testDefaultValues()36 public void testDefaultValues() throws Exception { 37 final DevicePolicyConstants constants = DevicePolicyConstants.loadFromString(""); 38 39 assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC).isEqualTo(1 * 60 * 60); 40 assertThat(constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC).isEqualTo(24 * 60 * 60); 41 assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE).isWithin(1.0e-10).of(2.0); 42 } 43 44 @Test testCustomValues()45 public void testCustomValues() throws Exception { 46 final DevicePolicyConstants constants = DevicePolicyConstants.loadFromString( 47 "das_died_service_reconnect_backoff_sec=10," 48 + "das_died_service_reconnect_backoff_increase=1.25," 49 + "das_died_service_reconnect_max_backoff_sec=15" 50 ); 51 52 assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC).isEqualTo(10); 53 assertThat(constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC).isEqualTo(15); 54 assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE).isWithin(1.0e-10) 55 .of(1.25); 56 } 57 58 @Test testMinMax()59 public void testMinMax() throws Exception { 60 final DevicePolicyConstants constants = DevicePolicyConstants.loadFromString( 61 "das_died_service_reconnect_backoff_sec=3," 62 + "das_died_service_reconnect_backoff_increase=.25," 63 + "das_died_service_reconnect_max_backoff_sec=1" 64 ); 65 66 assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC).isEqualTo(5); 67 assertThat(constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC).isEqualTo(5); 68 assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE).isWithin(1.0e-10).of(1.0); 69 } 70 } 71