diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-11 12:11:54 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-11 12:11:54 -0700 |
commit | ab28398a565e5ce8a56cdfd50ac6226e5317cf66 (patch) | |
tree | 589d7add2659de2974805a9def858204999f1fa7 /prefs | |
parent | 7a237c50c718d326c49da2a449ba6eb0c668837a (diff) | |
download | libcore-ab28398a565e5ce8a56cdfd50ac6226e5317cf66.zip libcore-ab28398a565e5ce8a56cdfd50ac6226e5317cf66.tar.gz libcore-ab28398a565e5ce8a56cdfd50ac6226e5317cf66.tar.bz2 |
auto import from //branches/cupcake/...@137873
Diffstat (limited to 'prefs')
3 files changed, 110 insertions, 86 deletions
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java index f53a579..80f663c 100644 --- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java +++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java @@ -49,24 +49,18 @@ public class AbstractPreferencesTest extends TestCase { protected void setUp() throws Exception { super.setUp(); + Preferences.systemRoot().clear(); + Preferences.userRoot().clear(); + parent = (AbstractPreferences) Preferences.userNodeForPackage(this.getClass()); -/* - String str[] = parent.childrenNames(); - for (int i = 0; i < str.length; i++) { - System.out.print(str[i] + " "); - } - System.out.println(); -/**/ + pref = (AbstractPreferences) parent.node(nodeName); } protected void tearDown() throws Exception { -/* String str[] = parent.childrenNames(); - for (int i = 0; i < str.length; i++) { - System.out.print(str[i] + " "); - } - System.out.println();/**/ parent.removeNode(); + Preferences.systemRoot().clear(); + Preferences.userRoot().clear(); super.tearDown(); } diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java index a5deaed..3e1a377 100644 --- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java +++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java @@ -17,17 +17,13 @@ package org.apache.harmony.prefs.tests.java.util.prefs; import dalvik.annotation.AndroidOnly; -import dalvik.annotation.BrokenTest; -import dalvik.annotation.KnownFailure; import dalvik.annotation.TestTargetClass; import dalvik.annotation.TestTargets; import dalvik.annotation.TestLevel; import dalvik.annotation.TestTargetNew; import java.io.FilePermission; -import java.io.IOException; import java.security.Permission; -import java.util.prefs.AbstractPreferences; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; @@ -36,28 +32,15 @@ import junit.framework.TestCase; @TestTargetClass(java.util.prefs.Preferences.class) public class FilePreferencesImplTest extends TestCase { - private String prevFactory; - private Preferences uroot; - private Preferences sroot; - public FilePreferencesImplTest() { super(); } - protected void setUp() throws Exception { - // prevFactory = System.getProperty("java.util.prefs.PreferencesFactory"); - // System.setProperty("java.util.prefs.PreferencesFactory", "java.util.prefs.FilePreferencesFactoryImpl"); - - // uroot = (AbstractPreferences) Preferences.userRoot(); - uroot = Preferences.userRoot(); - sroot = Preferences.systemRoot(); + @Override + protected void setUp(){ } - - protected void tearDown() throws Exception { - // if (prevFactory != null) - // System.setProperty("java.util.prefs.PreferencesFactory", prevFactory); - uroot = null; - sroot = null; + @Override + protected void tearDown(){ } @TestTargets({ @@ -80,7 +63,8 @@ public class FilePreferencesImplTest extends TestCase { args = {} ) }) - public void testPutGet() throws IOException, BackingStoreException { + public void testUserPutGet() throws BackingStoreException { + Preferences uroot = Preferences.userRoot().node("test"); uroot.put("ukey1", "value1"); assertEquals("value1", uroot.get("ukey1", null)); String[] names = uroot.keys(); @@ -96,7 +80,30 @@ public class FilePreferencesImplTest extends TestCase { uroot.clear(); names = uroot.keys(); assertEquals(0, names.length); + } + @TestTargets({ + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Exceptions checking missed, but method is abstract, probably it is OK", + method = "put", + args = {java.lang.String.class, java.lang.String.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Exceptions checking missed, but method is abstract, probably it is OK", + method = "get", + args = {java.lang.String.class, java.lang.String.class} + ), + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Exceptions checking missed, but method is abstract, probably it is OK", + method = "keys", + args = {} + ) + }) + public void testSystemPutGet() throws BackingStoreException { + Preferences sroot = Preferences.systemRoot().node("test"); sroot.put("skey1", "value1"); assertEquals("value1", sroot.get("skey1", null)); sroot.put("\u4e2d key1", "\u4e2d value1"); @@ -109,68 +116,74 @@ public class FilePreferencesImplTest extends TestCase { method = "childrenNames", args = {} ) - @AndroidOnly("Checking of childNames.length doesn't pass on RI because of " + - "it depends on .userPrefs properties.") - @KnownFailure("This test fails on emulator. " + - "java.util.prefs.BackingStoreException is thrown during calling of" + - "childrenNames() method.") - public void testChildNodes() throws Exception { - + public void testUserChildNodes() throws Exception { + Preferences uroot = Preferences.userRoot().node("test"); + Preferences child1 = uroot.node("child1"); Preferences child2 = uroot.node("\u4e2d child2"); Preferences grandchild = child1.node("grand"); assertNotNull(grandchild); String[] childNames = uroot.childrenNames(); - for (int i = 0; i < childNames.length; i++) { - System.out.println("test:" + childNames[i]); - } - assertEquals(4, childNames.length); + assertContains(childNames, "child1"); + assertContains(childNames, "\u4e2d child2"); + assertNotContains(childNames, "grand"); childNames = child1.childrenNames(); - assertEquals(1, childNames.length); - for (int i = 0; i < childNames.length; i++) { - System.out.println(childNames[i]); - } + assertContains(childNames, "grand"); childNames = child2.childrenNames(); assertEquals(0, childNames.length); - for (int i = 0; i < childNames.length; i++) { - System.out.println(childNames[i]); - } child1.removeNode(); childNames = uroot.childrenNames(); - assertEquals(3, childNames.length); - for (int i = 0; i < childNames.length; i++) { - System.out.println(childNames[i]); - } - // child2.removeNode(); - // childNames = uroot.childrenNames(); - // assertEquals(0, childNames.length); + assertNotContains(childNames, "child1"); + assertContains(childNames, "\u4e2d child2"); + assertNotContains(childNames, "grand"); - child1 = sroot.node("child1"); - child2 = sroot.node("child2"); - grandchild = child1.node("grand"); + child2.removeNode(); + childNames = uroot.childrenNames(); + assertNotContains(childNames, "child1"); + assertNotContains(childNames, "\u4e2d child2"); + assertNotContains(childNames, "grand"); + } - childNames = sroot.childrenNames(); + @TestTargetNew( + level = TestLevel.PARTIAL, + notes = "Exceptions checking missed, but method is abstract, probably it is OK", + method = "childrenNames", + args = {} + ) + @AndroidOnly("It seems like the RI can't remove nodes created in the system root.") + public void testSystemChildNodes() throws Exception { + Preferences sroot = Preferences.systemRoot().node("test"); - for (int i = 0; i < childNames.length; i++) { - System.out.println(childNames[i]); - } - // assertEquals(2, childNames.length); + Preferences child1 = sroot.node("child1"); + Preferences child2 = sroot.node("child2"); + Preferences grandchild = child1.node("grand"); + + String[] childNames = sroot.childrenNames(); + assertContains(childNames, "child1"); + assertContains(childNames, "child2"); + assertNotContains(childNames, "grand"); childNames = child1.childrenNames(); assertEquals(1, childNames.length); - for (int i = 0; i < childNames.length; i++) { - System.out.println(childNames[i]); - } childNames = child2.childrenNames(); assertEquals(0, childNames.length); - for (int i = 0; i < childNames.length; i++) { - System.out.println(childNames[i]); - } + + child1.removeNode(); + childNames = sroot.childrenNames(); + assertNotContains(childNames, "child1"); + assertContains(childNames, "child2"); + assertNotContains(childNames, "grand"); + + child2.removeNode(); + childNames = sroot.childrenNames(); + assertNotContains(childNames, "child1"); + assertNotContains(childNames, "child2"); + assertNotContains(childNames, "grand"); } @TestTargets({ @@ -206,6 +219,8 @@ public class FilePreferencesImplTest extends TestCase { ) }) public void testSecurityException() throws BackingStoreException { + Preferences uroot = Preferences.userRoot().node("test"); + Preferences child1 = uroot.node("child1"); MockFileSecurityManager manager = new MockFileSecurityManager(); manager.install(); @@ -248,6 +263,23 @@ public class FilePreferencesImplTest extends TestCase { } } + private void assertContains(String[] childNames, String name) { + for (String childName : childNames) { + if (childName == name) { + return; + } + } + fail("No child with name " + name + " was found. It was expected to exist."); + } + + private void assertNotContains(String[] childNames, String name) { + for (String childName : childNames) { + if (childName == name) { + fail("Child with name " + name + " was found. This was unexpected."); + } + } + } + static class MockFileSecurityManager extends SecurityManager { SecurityManager dflt; diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java index 2221cc5..9d526d6 100644 --- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java +++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java @@ -45,6 +45,9 @@ import java.util.prefs.Preferences; @TestTargetClass(Preferences.class) public class PreferencesTest extends TestCase { + private String oldJavaHome; + private String oldUserHome; + MockSecurityManager manager = new MockSecurityManager(); MockInputStream stream = null; @@ -77,18 +80,10 @@ public class PreferencesTest extends TestCase { "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\"><preferences><root type=\"user\"><map></map></root></preferences>" .getBytes("UTF-8")); stream = new MockInputStream(in); - - String userHome = System.getProperty("user.home"); - if (userHome != null) { - File userHomeDir = new File(userHome); - if (!userHomeDir.isDirectory() || !userHomeDir.canWrite()) { - userHome = null; - } - } - if (userHome == null) { - System.setProperty("user.home", System.getProperty("java.io.tmpdir")); - } - + + Preferences.systemRoot().clear(); + Preferences.userRoot().clear(); + Preferences p = Preferences.userNodeForPackage(Preferences.class); p.clear(); try { @@ -109,6 +104,9 @@ public class PreferencesTest extends TestCase { p.removeNode(); } catch (BackingStoreException e) { } + + Preferences.systemRoot().clear(); + Preferences.userRoot().clear(); } @TestTargetNew( @@ -146,7 +144,7 @@ public class PreferencesTest extends TestCase { } try { - p = Preferences.userNodeForPackage(null); + p = Preferences.systemNodeForPackage(null); fail("NullPointerException has not been thrown"); } catch (NullPointerException e) { // expected |