LogTest.java revision 1a44d5dcabc18cd5ef111f732ccff91683a1a093
1package android.util; 2 3import junit.framework.Assert; 4import junit.framework.TestCase; 5 6import android.os.SystemProperties; 7import android.test.PerformanceTestCase; 8import android.test.suitebuilder.annotation.Suppress; 9import android.util.Log; 10 11//This is an empty TestCase. 12@Suppress 13public class LogTest extends TestCase { 14 private static final String PROPERTY_TAG = "log.tag.LogTest"; 15 private static final String LOG_TAG = "LogTest"; 16 17 18 // TODO: remove this test once we uncomment out the following test. 19 public void testLogTestDummy() { 20 return; 21 } 22 23 24 /* TODO: This test is commented out because we will not be able to set properities. Fix the test. 25 public void testIsLoggable() { 26 // First clear any SystemProperty setting for our test key. 27 SystemProperties.set(PROPERTY_TAG, null); 28 29 String value = SystemProperties.get(PROPERTY_TAG); 30 Assert.assertTrue(value == null || value.length() == 0); 31 32 // Check to make sure that all levels expect for INFO, WARN, ERROR, and ASSERT are loggable. 33 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.VERBOSE)); 34 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.DEBUG)); 35 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.INFO)); 36 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.WARN)); 37 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ERROR)); 38 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ASSERT)); 39 40 // Set the log level to be VERBOSE for this tag. 41 SystemProperties.set(PROPERTY_TAG, "VERBOSE"); 42 43 // Test to make sure all log levels >= VERBOSE are loggable. 44 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.VERBOSE)); 45 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.DEBUG)); 46 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.INFO)); 47 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.WARN)); 48 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ERROR)); 49 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ASSERT)); 50 51 // Set the log level to be DEBUG for this tag. 52 SystemProperties.set(PROPERTY_TAG, "DEBUG"); 53 54 // Test to make sure all log levels >= DEBUG are loggable. 55 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.VERBOSE)); 56 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.DEBUG)); 57 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.INFO)); 58 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.WARN)); 59 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ERROR)); 60 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ASSERT)); 61 62 // Set the log level to be INFO for this tag. 63 SystemProperties.set(PROPERTY_TAG, "INFO"); 64 65 // Test to make sure all log levels >= INFO are loggable. 66 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.VERBOSE)); 67 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.DEBUG)); 68 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.INFO)); 69 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.WARN)); 70 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ERROR)); 71 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ASSERT)); 72 73 // Set the log level to be WARN for this tag. 74 SystemProperties.set(PROPERTY_TAG, "WARN"); 75 76 // Test to make sure all log levels >= WARN are loggable. 77 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.VERBOSE)); 78 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.DEBUG)); 79 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.INFO)); 80 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.WARN)); 81 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ERROR)); 82 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ASSERT)); 83 84 // Set the log level to be ERROR for this tag. 85 SystemProperties.set(PROPERTY_TAG, "ERROR"); 86 87 // Test to make sure all log levels >= ERROR are loggable. 88 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.VERBOSE)); 89 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.DEBUG)); 90 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.INFO)); 91 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.WARN)); 92 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ERROR)); 93 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ASSERT)); 94 95 // Set the log level to be ASSERT for this tag. 96 SystemProperties.set(PROPERTY_TAG, "ASSERT"); 97 98 // Test to make sure all log levels >= ASSERT are loggable. 99 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.VERBOSE)); 100 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.DEBUG)); 101 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.INFO)); 102 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.WARN)); 103 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.ERROR)); 104 Assert.assertTrue(Log.isLoggable(LOG_TAG, Log.ASSERT)); 105 106 // Set the log level to be SUPPRESS for this tag. 107 SystemProperties.set(PROPERTY_TAG, "SUPPRESS"); 108 109 // Test to make sure all log levels >= ASSERT are loggable. 110 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.VERBOSE)); 111 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.DEBUG)); 112 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.INFO)); 113 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.WARN)); 114 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.ERROR)); 115 Assert.assertFalse(Log.isLoggable(LOG_TAG, Log.ASSERT)); 116 } 117 */ 118 119 public static class PerformanceTest extends TestCase implements PerformanceTestCase { 120 private static final int ITERATIONS = 1000; 121 122 @Override 123 public void setUp() { 124 SystemProperties.set(LOG_TAG, "VERBOSE"); 125 } 126 127 public boolean isPerformanceOnly() { 128 return true; 129 } 130 131 public int startPerformance(PerformanceTestCase.Intermediates intermediates) { 132 intermediates.setInternalIterations(ITERATIONS * 10); 133 return 0; 134 } 135 136 public void testIsLoggable() { 137 boolean canLog = false; 138 for (int i = ITERATIONS - 1; i >= 0; i--) { 139 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 140 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 141 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 142 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 143 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 144 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 145 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 146 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 147 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 148 canLog = Log.isLoggable(LOG_TAG, Log.VERBOSE); 149 } 150 } 151 } 152} 153