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