SystemPropertiesTest.java revision c91437d38ae14a20046de47831eb0f9bfd329af7
1/* 2 * Copyright (C) 2011 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 17package android.os; 18 19import junit.framework.TestCase; 20 21import android.os.SystemProperties; 22import android.test.suitebuilder.annotation.SmallTest; 23 24public class SystemPropertiesTest extends TestCase { 25 private static final String KEY = "sys.testkey"; 26 @SmallTest 27 public void testLongSequencialProperties() throws Exception { 28 for (int i = 0; i < 100; ++i) { 29 SystemProperties.set(KEY, Long.toString(i)); 30 long ret = SystemProperties.getLong(KEY, -1); 31 assertEquals(i, ret); 32 } 33 } 34 35 @SmallTest 36 public void testProperties() throws Exception { 37 String value; 38 39 SystemProperties.set(KEY, ""); 40 value = SystemProperties.get(KEY, "default"); 41 assertEquals("default", value); 42 43 SystemProperties.set(KEY, "SA"); 44 value = SystemProperties.get(KEY, "default"); 45 assertEquals("SA", value); 46 47 value = SystemProperties.get(KEY); 48 assertEquals("SA", value); 49 50 SystemProperties.set(KEY, ""); 51 value = SystemProperties.get(KEY, "default"); 52 assertEquals("default", value); 53 54 value = SystemProperties.get(KEY); 55 assertEquals("", value); 56 } 57} 58