OSDN Git Service

AI 143466: Bringing the logging tests down to zero failures.
authorJorg Pleumann <>
Mon, 30 Mar 2009 11:29:44 +0000 (04:29 -0700)
committerThe Android Open Source Project <initial-contribution@android.com>
Mon, 30 Mar 2009 11:29:44 +0000 (04:29 -0700)
  BUG=1285921

Automated import of CL 143466

libcore/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java
libcore/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java
libcore/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/XMLFormatterTest.java

index 0702d51..cf608bc 100644 (file)
@@ -19,16 +19,6 @@ package org.apache.harmony.logging.tests.java.util.logging;
 
 
 
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream;
-import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper;
-
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.IOException;
@@ -45,6 +35,17 @@ import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 import java.util.logging.LoggingPermission;
 
+import junit.framework.TestCase;
+
+import org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream;
+import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper;
+
+import dalvik.annotation.SideEffect;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
 /**
  * 
  * add/get logger(dot)
@@ -464,18 +465,28 @@ public class LogManagerTest extends TestCase {
         assertSame(global, Logger.global);
         assertSame(root, global.getParent());
 
+        Logger oldGlobal = global;
+        Logger oldRoot = root;
+        
         // root properties
         manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
+        
+        global = manager.getLogger("global");
+        root = manager.getLogger("");
+
+        assertSame(oldGlobal, global);
+        assertSame(oldRoot, root);
+        
         assertNull(root.getFilter());
         assertEquals(2, root.getHandlers().length);
         assertEquals(Level.FINE, root.getLevel());
         assertEquals("", root.getName());
         assertSame(root.getParent(), null);
-        // This test sometimes fails if other tests are run before this one.
+        assertTrue(root.getUseParentHandlers());
+        
+        // The following two fail if other tests are run before this one.
         assertNull(root.getResourceBundle());
         assertNull(root.getResourceBundleName());
-        assertTrue(root.getUseParentHandlers());
-
     }
 
     /*
index ca288dd..3a06078 100644 (file)
 
 package org.apache.harmony.logging.tests.java.util.logging;
 
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper;
-
-import tests.util.CallVerificationStack;
-
 import java.security.Permission;
 import java.util.Locale;
 import java.util.MissingResourceException;
@@ -43,6 +30,17 @@ import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 import java.util.logging.LoggingPermission;
 
+import junit.framework.TestCase;
+
+import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper;
+
+import tests.util.CallVerificationStack;
+import dalvik.annotation.SideEffect;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
 /**
  * Test suite for the class java.util.logging.Logger.
  */
@@ -75,6 +73,7 @@ public class LoggerTest extends TestCase {
      */
     protected void setUp() throws Exception {
         super.setUp();
+        LogManager.getLogManager().reset();
         oldLocale = Locale.getDefault();
         Locale.setDefault(new Locale("zh", "CN"));
         sharedLogger = new MockLogger("SharedLogger", VALID_RESOURCE_BUNDLE);
@@ -433,10 +432,6 @@ public class LoggerTest extends TestCase {
         method = "getLogger",
         args = {java.lang.String.class}
     )
-    @BrokenTest("This fails on RI and Android." +
-            "getResourceBundle and getResourceBundleName methods return " +
-            "null on RI for Logger with empty string name. On the RI " + 
-            "getHandlers() returns a non empty array.")
     public void testGetLogger_Empty() {
         assertNotNull(LogManager.getLogManager().getLogger(""));
         Logger log = Logger.getLogger("");
@@ -611,9 +606,6 @@ public class LoggerTest extends TestCase {
         method = "getLogger",
         args = {java.lang.String.class, java.lang.String.class}
     )
-    @KnownFailure("IllegalArgumentException is thrown instead of " +
-            "MissingResourceException if resource bundle with specified " +
-            "name can't be found.")
     public void testGetLoggerWithRes_InvalidResourceBundle() {
 
         assertNull(LogManager.getLogManager().getLogger(
@@ -763,6 +755,7 @@ public class LoggerTest extends TestCase {
         method = "getLogger",
         args = {java.lang.String.class, java.lang.String.class}
     )
+    @SideEffect("Attaches ResourceBundle to anonymous logger; irreversible")
     public void testGetLoggerWithRes_Empty() {
         Logger log = Logger.getLogger("", VALID_RESOURCE_BUNDLE);
         assertSame(log, LogManager.getLogManager().getLogger(""));
index 917a898..90c93c9 100644 (file)
@@ -72,7 +72,11 @@ public class XMLFormatterTest extends TestCase {
             args = {java.util.logging.Handler.class}
         )
     })
-    public void testXMLFormatter() {
+    public void testXMLFormatter() throws SecurityException,
+            UnsupportedEncodingException {
+
+        handler.setEncoding("UTF-8");
+
         String result = formatter.getHead(handler);
         int headPos = result
                 .indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");