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