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 */ 16package com.android.server.devicepolicy; 17 18import android.test.AndroidTestCase; 19 20/** 21 * Test for {@link DevicePolicyConstants}. 22 * 23 m FrameworksServicesTests && 24 adb install \ 25 -r ${ANDROID_PRODUCT_OUT}/data/app/FrameworksServicesTests/FrameworksServicesTests.apk && 26 adb shell am instrument -e class com.android.server.devicepolicy.DevicePolicyConstantsTest \ 27 -w com.android.frameworks.servicestests 28 29 30 -w com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner 31 */ 32public class DevicePolicyConstantsTest extends AndroidTestCase { 33 private static final String TAG = "DevicePolicyConstantsTest"; 34 35 public void testDefaultValues() throws Exception { 36 final DevicePolicyConstants constants = DevicePolicyConstants.loadFromString(""); 37 38 assertEquals(1 * 60 * 60, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC); 39 assertEquals(24 * 60 * 60, constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC); 40 assertEquals(2.0, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE); 41 } 42 43 public void testCustomValues() throws Exception { 44 final DevicePolicyConstants constants = DevicePolicyConstants.loadFromString( 45 "das_died_service_reconnect_backoff_sec=10," 46 + "das_died_service_reconnect_backoff_increase=1.25," 47 + "das_died_service_reconnect_max_backoff_sec=15" 48 ); 49 50 assertEquals(10, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC); 51 assertEquals(15, constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC); 52 assertEquals(1.25, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE); 53 } 54 55 public void testMinMax() throws Exception { 56 final DevicePolicyConstants constants = DevicePolicyConstants.loadFromString( 57 "das_died_service_reconnect_backoff_sec=3," 58 + "das_died_service_reconnect_backoff_increase=.25," 59 + "das_died_service_reconnect_max_backoff_sec=1" 60 ); 61 62 assertEquals(5, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC); 63 assertEquals(5, constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC); 64 assertEquals(1.0, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE); 65 } 66} 67