1 /* 2 * Copyright (C) 2008 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 17 package android.os.cts; 18 19 import android.os.SystemClock; 20 import android.test.AndroidTestCase; 21 22 public class SystemClockTest extends AndroidTestCase { 23 24 public void testCurrentThreadTimeMillis() throws InterruptedException { 25 26 long start = SystemClock.currentThreadTimeMillis(); 27 Thread.sleep(100); 28 long end = SystemClock.currentThreadTimeMillis(); 29 assertFalse(end - 100 >= start); 30 31 } 32 33 public void testElapsedRealtime() throws InterruptedException { 34 35 long start = SystemClock.elapsedRealtime(); 36 Thread.sleep(100); 37 long end = SystemClock.elapsedRealtime(); 38 assertTrue(end - 100 >= start); 39 40 } 41 42 public void testSetCurrentTimeMillis() { 43 44 long start = SystemClock.currentThreadTimeMillis(); 45 boolean actual = SystemClock.setCurrentTimeMillis(start + 10000); 46 assertFalse(actual); 47 // This test need to be done in permission test. 48 49 } 50 51 public void testSleep() { 52 53 long start = SystemClock.currentThreadTimeMillis(); 54 SystemClock.sleep(100); 55 long end = SystemClock.currentThreadTimeMillis(); 56 assertFalse(end - 100 >= start); 57 58 start = SystemClock.elapsedRealtime(); 59 SystemClock.sleep(100); 60 end = SystemClock.elapsedRealtime(); 61 assertTrue(end - 100 >= start); 62 63 start = SystemClock.uptimeMillis(); 64 SystemClock.sleep(100); 65 end = SystemClock.uptimeMillis(); 66 assertTrue(end - 100 >= start); 67 68 } 69 70 public void testUptimeMillis() throws InterruptedException { 71 72 long start = SystemClock.uptimeMillis(); 73 Thread.sleep(100); 74 long end = SystemClock.uptimeMillis(); 75 assertTrue(end - 100 >= start); 76 } 77 78 } 79