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    private static final String PERSIST_KEY = "persist.sys.testkey";
27
28    @SmallTest
29    public void testStressPersistPropertyConsistency() throws Exception {
30        for (int i = 0; i < 100; ++i) {
31            SystemProperties.set(PERSIST_KEY, Long.toString(i));
32            long ret = SystemProperties.getLong(PERSIST_KEY, -1);
33            assertEquals(i, ret);
34        }
35    }
36
37    @SmallTest
38    public void testStressMemoryPropertyConsistency() throws Exception {
39        for (int i = 0; i < 100; ++i) {
40            SystemProperties.set(KEY, Long.toString(i));
41            long ret = SystemProperties.getLong(KEY, -1);
42            assertEquals(i, ret);
43        }
44    }
45
46    @SmallTest
47    public void testProperties() throws Exception {
48        String value;
49
50        SystemProperties.set(KEY, "");
51        value = SystemProperties.get(KEY, "default");
52        assertEquals("default", value);
53
54        SystemProperties.set(KEY, "SA");
55        value = SystemProperties.get(KEY, "default");
56        assertEquals("SA", value);
57
58        value = SystemProperties.get(KEY);
59        assertEquals("SA", value);
60
61        SystemProperties.set(KEY, "");
62        value = SystemProperties.get(KEY, "default");
63        assertEquals("default", value);
64
65        value = SystemProperties.get(KEY);
66        assertEquals("", value);
67    }
68}
69