You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 15:57:17 UTC
svn commit: r386087 [32/45] - in /incubator/harmony/enhanced/classlib/trunk:
make/ make/patternsets/ modules/jndi/ modules/jndi/META-INF/
modules/jndi/make/ modules/jndi/make/common/ modules/jndi/src/
modules/jndi/src/main/ modules/jndi/src/main/java/ ...
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockAbstractPreferences.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockAbstractPreferences.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockAbstractPreferences.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockAbstractPreferences.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,243 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.prefs;
+
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.Set;
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.BackingStoreException;
+
+public class MockAbstractPreferences extends AbstractPreferences {
+ static final int NORMAL = 0;
+
+ static final int backingException = 1;
+
+ static final int runtimeException = 2;
+
+ static final int returnNull = 3;
+
+ int result = NORMAL;
+
+ Properties attr = new Properties();
+
+ HashMap childs = new HashMap();
+
+ private int flushedTimes;
+
+ private int syncTimes;
+
+ protected MockAbstractPreferences(AbstractPreferences parent, String name) {
+ this(parent, name, false);
+
+ }
+
+ protected MockAbstractPreferences(AbstractPreferences parent, String name,
+ boolean newNode) {
+ super(parent, name);
+ super.newNode = newNode;
+ if (parent instanceof MockAbstractPreferences) {
+ ((MockAbstractPreferences) parent).addChild(this);
+ }
+ }
+
+ public int getFlushedTimes() {
+ return flushedTimes;
+ }
+
+ public void resetFlushedTimes() {
+ flushedTimes = 0;
+ }
+
+ public int getSyncTimes() {
+ return syncTimes;
+ }
+
+ public void resetSyncTimes() {
+ syncTimes = 0;
+ }
+
+ private void addChild(MockAbstractPreferences c) {
+ childs.put(c.name(), c);
+ }
+
+ public void setResult(int r) {
+ result = r;
+ }
+
+ public Object lock() {
+ return lock;
+ }
+
+ protected String[] childrenNamesSpi() throws BackingStoreException {
+ checkException();
+ if (result == returnNull)
+ return null;
+ String[] r = new String[childs.size()];
+ childs.keySet().toArray(r);
+ return r;
+ }
+
+ private void checkException() throws BackingStoreException {
+ switch (result) {
+ case NORMAL:
+ return;
+ case backingException:
+ throw new BackingStoreException("test");
+ case runtimeException:
+ throw new MockRuntimeException("test");
+ }
+ }
+
+ public AbstractPreferences publicChildSpi(String name) {
+ return childSpi(name);
+ }
+
+ protected AbstractPreferences childSpi(String name) {
+ try {
+ checkException();
+ } catch (BackingStoreException e) {
+ }
+ if (result == returnNull)
+ return null;
+ AbstractPreferences r = (AbstractPreferences) childs.get(name);
+ if (r == null) {
+ r = new MockAbstractPreferences(this, name, true);
+
+ }
+ return r;
+ }
+
+ protected void flushSpi() throws BackingStoreException {
+ checkException();
+ flushedTimes++;
+ }
+
+ protected String getSpi(String key) {
+ try {
+ checkException();
+ } catch (BackingStoreException e) {
+ }
+ if (null == key) {
+ return null;
+ }
+ return result == returnNull ? null : attr.getProperty(key);
+ }
+
+ protected String[] keysSpi() throws BackingStoreException {
+ checkException();
+ Set keys = attr.keySet();
+ String[] results = new String[keys.size()];
+ keys.toArray(results);
+ return result == returnNull ? null : results;
+ }
+
+ protected void putSpi(String name, String value) {
+ try {
+ checkException();
+ } catch (BackingStoreException e) {
+ }
+ if (name == null || value == null) {
+ return;
+ }
+ attr.put(name, value);
+ }
+
+ protected void removeNodeSpi() throws BackingStoreException {
+ checkException();
+ ((MockAbstractPreferences) parent()).childs.remove(name());
+ }
+
+ protected void removeSpi(String key) {
+ try {
+ checkException();
+ } catch (BackingStoreException e) {
+ }
+ if (null == key) {
+ return;
+ }
+ attr.remove(key);
+ }
+
+ protected void syncSpi() throws BackingStoreException {
+ checkException();
+ syncTimes++;
+ }
+
+ public boolean getNewNode() {
+ return newNode;
+ }
+
+ public Object getLock() {
+ return lock;
+ }
+
+ public void protectedAbstractMethod() {
+ try {
+ childrenNamesSpi();
+ } catch (BackingStoreException e) {
+ }
+ childSpi("mock");
+ try {
+ flushSpi();
+ } catch (BackingStoreException e1) {
+ }
+ getSpi(null);
+ isRemoved();
+ try {
+ keysSpi();
+ } catch (BackingStoreException e2) {
+ }
+ putSpi(null, null);
+ try {
+ removeNodeSpi();
+ } catch (BackingStoreException e3) {
+ }
+ removeSpi(null);
+ try {
+ syncSpi();
+ } catch (BackingStoreException e4) {
+ }
+ }
+
+ public boolean isRemovedImpl() {
+ return super.isRemoved();
+ }
+
+ public AbstractPreferences getChildImpl(String name)
+ throws BackingStoreException {
+ return super.getChild(name);
+ }
+
+ public AbstractPreferences[] cachedChildrenImpl() {
+ return super.cachedChildren();
+ }
+
+}
+
+class MockRuntimeException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public MockRuntimeException(String s) {
+ super(s);
+ }
+
+ public MockRuntimeException() {
+ super();
+ }
+}
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockPreferencesFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockPreferencesFactory.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockPreferencesFactory.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockPreferencesFactory.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,41 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.prefs;
+
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferencesFactory;
+
+/**
+ *
+ */
+public class MockPreferencesFactory implements PreferencesFactory {
+ static MockAbstractPreferences userRoot = new MockAbstractPreferences(null,
+ "");
+
+ static MockAbstractPreferences systemRoot = new MockAbstractPreferences(
+ null, "");
+
+ public MockPreferencesFactory() {
+ }
+
+ public Preferences userRoot() {
+ return userRoot;
+ }
+
+ public Preferences systemRoot() {
+ return systemRoot;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockSecurityManager.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockSecurityManager.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockSecurityManager.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/MockSecurityManager.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,59 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.prefs;
+
+import java.security.Permission;
+
+/**
+ * utility class for java.util.prefs test
+ *
+ */
+class MockSecurityManager extends SecurityManager {
+
+ SecurityManager dflt;
+
+ public MockSecurityManager() {
+ super();
+ dflt = System.getSecurityManager();
+ }
+
+ public void install() {
+ System.setSecurityManager(this);
+ }
+
+ public void restoreDefault() {
+ System.setSecurityManager(dflt);
+ }
+
+ public void checkPermission(Permission perm) {
+ if (perm instanceof RuntimePermission
+ && perm.getName().equals("preferences")) {
+ throw new SecurityException();
+ } else if (dflt != null) {
+ dflt.checkPermission(perm);
+ }
+ }
+
+ public void checkPermission(Permission perm, Object ctx) {
+ if (perm instanceof RuntimePermission
+ && perm.getName().equals("preferences")) {
+ throw new SecurityException();
+ } else if (dflt != null) {
+ dflt.checkPermission(perm, ctx);
+ }
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/NodeChangeEventTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/NodeChangeEventTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/NodeChangeEventTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/NodeChangeEventTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,62 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.prefs;
+
+import java.io.NotSerializableException;
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.Preferences;
+
+import junit.framework.TestCase;
+import tests.util.SerializationTester;
+
+/**
+ *
+ */
+public class NodeChangeEventTest extends TestCase {
+
+ NodeChangeEvent event;
+
+ public void testConstructor() {
+ event = new NodeChangeEvent(Preferences.systemRoot(), Preferences
+ .userRoot());
+ assertSame(Preferences.systemRoot(), event.getParent());
+ assertSame(Preferences.userRoot(), event.getChild());
+ assertSame(Preferences.systemRoot(), event.getSource());
+ }
+
+ public void testConstructorNullParam() {
+ try {
+ event = new NodeChangeEvent(null, Preferences.userRoot());
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+
+ event = new NodeChangeEvent(Preferences.systemRoot(), null);
+ assertSame(Preferences.systemRoot(), event.getParent());
+ assertNull(event.getChild());
+ assertSame(Preferences.systemRoot(), event.getSource());
+ }
+
+ public void testSerialization() throws Exception {
+ try {
+ SerializationTester.writeObject(new NodeChangeEvent(Preferences
+ .systemRoot(), null), "test.txt");
+ fail();
+ } catch (NotSerializableException e) {
+ }
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/NodeChangeListenerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/NodeChangeListenerTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/NodeChangeListenerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/NodeChangeListenerTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,66 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.prefs;
+
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.NodeChangeListener;
+import java.util.prefs.Preferences;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class NodeChangeListenerTest extends TestCase {
+
+ NodeChangeListener l;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ l = new NodeChangeListenerImpl();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testChildAdded() {
+ l.childAdded(new NodeChangeEvent(Preferences.userRoot(), Preferences
+ .userRoot()));
+ }
+
+ public void testChildRemoved() {
+ l.childRemoved(new NodeChangeEvent(Preferences.userRoot(), Preferences
+ .userRoot()));
+ }
+
+ public static class NodeChangeListenerImpl implements NodeChangeListener {
+
+ public void childAdded(NodeChangeEvent e) {
+ }
+
+ public void childRemoved(NodeChangeEvent e) {
+ }
+
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferenceChangeEventTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferenceChangeEventTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferenceChangeEventTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferenceChangeEventTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,87 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.prefs;
+
+import java.io.NotSerializableException;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.Preferences;
+
+import tests.util.SerializationTester;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class PreferenceChangeEventTest extends TestCase {
+
+ PreferenceChangeEvent event;
+
+ public void testPreferenceChangeEventException() {
+ try {
+ event = new PreferenceChangeEvent(null, "key", "value");
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testConstructorNullValue() {
+ event = new PreferenceChangeEvent(Preferences.userRoot(), "key", null);
+ assertEquals("key", event.getKey());
+ assertNull(event.getNewValue());
+ assertSame(Preferences.userRoot(), event.getNode());
+ assertSame(Preferences.userRoot(), event.getSource());
+
+ event = new PreferenceChangeEvent(Preferences.userRoot(), "", null);
+ assertEquals("", event.getKey());
+ assertNull(event.getNewValue());
+ assertSame(Preferences.userRoot(), event.getNode());
+ assertSame(Preferences.userRoot(), event.getSource());
+
+ event = new PreferenceChangeEvent(Preferences.userRoot(), null, "value");
+ assertNull(event.getKey());
+ assertEquals("value", event.getNewValue());
+ assertSame(Preferences.userRoot(), event.getNode());
+ assertSame(Preferences.userRoot(), event.getSource());
+
+ event = new PreferenceChangeEvent(Preferences.userRoot(), null, "");
+ assertNull(event.getKey());
+ assertEquals("", event.getNewValue());
+ assertSame(Preferences.userRoot(), event.getNode());
+ assertSame(Preferences.userRoot(), event.getSource());
+ }
+
+ public void testConstructor() {
+ event = new PreferenceChangeEvent(Preferences.userRoot(), "key",
+ "value");
+ assertEquals("key", event.getKey());
+ assertEquals("value", event.getNewValue());
+ assertSame(Preferences.userRoot(), event.getNode());
+ assertSame(Preferences.userRoot(), event.getSource());
+ }
+
+ public void testSerialization() throws Exception {
+ event = new PreferenceChangeEvent(Preferences.userRoot(), "key",
+ "value");
+ try {
+ SerializationTester.writeObject(event, "test.txt");
+ fail();
+ } catch (NotSerializableException e) {
+ }
+
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferenceChangeListenerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferenceChangeListenerTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferenceChangeListenerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferenceChangeListenerTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,51 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.prefs;
+
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.Preferences;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class PreferenceChangeListenerTest extends TestCase {
+
+ PreferenceChangeListener l;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ l = new PreferenceChangeListenerImpl();
+ }
+
+ public void testPreferenceChange() {
+ l.preferenceChange(new PreferenceChangeEvent(Preferences.userRoot(),
+ "", ""));
+ }
+
+ public static class PreferenceChangeListenerImpl implements
+ PreferenceChangeListener {
+ public void preferenceChange(PreferenceChangeEvent pce) {
+ }
+
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferencesFactoryTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferencesFactoryTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferencesFactoryTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferencesFactoryTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,58 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.prefs;
+
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferencesFactory;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class PreferencesFactoryTest extends TestCase {
+
+ PreferencesFactory f;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ f = new PreferencesFactoryImpl();
+ }
+
+ public void testUserRoot() {
+ f.userRoot();
+ }
+
+ public void testSystemRoot() {
+ f.systemRoot();
+ }
+
+ public static class PreferencesFactoryImpl implements PreferencesFactory {
+
+ public Preferences userRoot() {
+ return null;
+ }
+
+ public Preferences systemRoot() {
+ return null;
+ }
+
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferencesTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferencesTest.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferencesTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/PreferencesTest.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,511 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.prefs;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.StringBufferInputStream;
+import java.net.MalformedURLException;
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.InvalidPreferencesFormatException;
+import java.util.prefs.NodeChangeListener;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.Preferences;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class PreferencesTest extends TestCase {
+
+ MockSecurityManager manager = new MockSecurityManager();
+
+ MockInputStream stream = null;
+
+ InputStream in;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ in = new StringBufferInputStream(
+ "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\"><preferences><root type=\"user\"><map></map></root></preferences>");
+ stream = new MockInputStream(in);
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ stream.close();
+ }
+
+ public void testSystemNodeForPackage() throws BackingStoreException {
+ Preferences p = Preferences.systemNodeForPackage(Object.class);
+ assertEquals("/java/lang", p.absolutePath());
+ assertTrue(p instanceof AbstractPreferences);
+ Preferences root = Preferences.systemRoot();
+ Preferences parent = root.node("java");
+ assertSame(parent, p.parent());
+ assertFalse(p.isUserNode());
+ assertEquals("lang", p.name());
+ assertEquals("System Preference Node: " + p.absolutePath(), p
+ .toString());
+ assertEquals(0, p.childrenNames().length);
+ assertEquals(p.keys().length, 0);
+ parent.removeNode();
+ try {
+ p = Preferences.userNodeForPackage(null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ }
+
+ public void testSystemRoot() throws BackingStoreException {
+ Preferences p = Preferences.systemRoot();
+ assertTrue(p instanceof AbstractPreferences);
+ assertEquals("/", p.absolutePath());
+ assertSame(null, p.parent());
+ assertFalse(p.isUserNode());
+ assertEquals("", p.name());
+ assertEquals("System Preference Node: " + p.absolutePath(), p
+ .toString());
+ // assertEquals(0, p.childrenNames().length);
+ // assertEquals(p.keys().length, 0);
+ }
+
+ public void testConsts() {
+ assertEquals(80, Preferences.MAX_KEY_LENGTH);
+ assertEquals(80, Preferences.MAX_NAME_LENGTH);
+ assertEquals(8192, Preferences.MAX_VALUE_LENGTH);
+ }
+
+ public void testUserNodeForPackage() throws BackingStoreException {
+ Preferences p = Preferences.userNodeForPackage(Object.class);
+ assertEquals("/java/lang", p.absolutePath());
+ assertTrue(p instanceof AbstractPreferences);
+ Preferences root = Preferences.userRoot();
+ Preferences parent = root.node("java");
+ assertSame(parent, p.parent());
+ assertTrue(p.isUserNode());
+ assertEquals("lang", p.name());
+ assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
+ assertEquals(0, p.childrenNames().length);
+ assertEquals(p.keys().length, 0);
+
+ try {
+ p = Preferences.userNodeForPackage(null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ }
+
+ public void testUserRoot() throws BackingStoreException {
+ Preferences p = Preferences.userRoot();
+ assertTrue(p instanceof AbstractPreferences);
+ assertEquals("/", p.absolutePath());
+ assertSame(null, p.parent());
+ assertTrue(p.isUserNode());
+ assertEquals("", p.name());
+ assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
+ // assertEquals(0, p.childrenNames().length);
+ // assertEquals(p.keys().length, 0);
+ }
+
+ public void testImportPreferences() throws Exception {
+ Preferences prefs = null;
+ try {
+ prefs = Preferences.userNodeForPackage(PreferencesTest.class);
+ // assertEquals(0, prefs.childrenNames().length);
+ // assertFalse(prefs.nodeExists("mock/child/grandson"));
+
+ prefs.put("prefskey", "oldvalue");
+ prefs.put("prefskey2", "oldvalue2");
+ in = PreferencesTest.class.getResourceAsStream("userprefs.xml");
+ Preferences.importPreferences(in);
+
+ prefs = Preferences.userNodeForPackage(PreferencesTest.class);
+ assertEquals(1, prefs.childrenNames().length);
+ assertTrue(prefs.nodeExists("mock/child/grandson"));
+ assertEquals("newvalue", prefs.get("prefskey", null));
+ assertEquals("oldvalue2", prefs.get("prefskey2", null));
+ assertEquals("newvalue3", prefs.get("prefskey3", null));
+
+ in = PreferencesTest.class
+ .getResourceAsStream("userprefs-badform.xml");
+ try {
+ Preferences.importPreferences(in);
+ fail();
+ } catch (InvalidPreferencesFormatException e) {
+ }
+
+ in = PreferencesTest.class
+ .getResourceAsStream("userprefs-badtype.xml");
+ try {
+ Preferences.importPreferences(in);
+ fail();
+ } catch (InvalidPreferencesFormatException e) {
+ }
+
+ in = PreferencesTest.class
+ .getResourceAsStream("userprefs-badencoding.xml");
+ try {
+ Preferences.importPreferences(in);
+ fail();
+ } catch (InvalidPreferencesFormatException e) {
+ }
+
+ in = PreferencesTest.class
+ .getResourceAsStream("userprefs-higherversion.xml");
+ try {
+ Preferences.importPreferences(in);
+ fail();
+ } catch (InvalidPreferencesFormatException e) {
+ }
+
+ in = PreferencesTest.class
+ .getResourceAsStream("userprefs-ascii.xml");
+ Preferences.importPreferences(in);
+ prefs = Preferences.userNodeForPackage(PreferencesTest.class);
+ } finally {
+ try {
+ prefs = Preferences.userRoot().node("tests");
+ prefs.removeNode();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ public void testImportPreferencesException() throws Exception {
+ try {
+ Preferences.importPreferences(null);
+ fail();
+ } catch (MalformedURLException e) {
+ }
+
+ byte[] source = new byte[0];
+ InputStream in = new ByteArrayInputStream(source);
+ try {
+ Preferences.importPreferences(in);
+ fail();
+ } catch (InvalidPreferencesFormatException e) {
+ }
+
+ stream.setResult(MockInputStream.exception);
+ try {
+ Preferences.importPreferences(stream);
+ fail();
+ } catch (IOException e) {
+ }
+
+ stream.setResult(MockInputStream.runtimeException);
+ try {
+ Preferences.importPreferences(stream);
+ fail();
+ } catch (RuntimeException e) {
+ }
+ }
+
+ public void testSecurity() throws InvalidPreferencesFormatException,
+ IOException {
+ try {
+ manager.install();
+ try {
+ Preferences.userRoot();
+ fail();
+ } catch (SecurityException e) {
+ }
+ try {
+ Preferences.systemRoot();
+ fail();
+ } catch (SecurityException e) {
+ }
+ try {
+ Preferences.userNodeForPackage(null);
+ fail();
+ } catch (SecurityException e) {
+ }
+
+ try {
+ Preferences.systemNodeForPackage(null);
+ fail();
+ } catch (SecurityException e) {
+ }
+
+ try {
+ Preferences.importPreferences(stream);
+ fail();
+ } catch (SecurityException e) {
+ }
+ } finally {
+ manager.restoreDefault();
+ }
+ }
+
+ public void testAbstractMethods() {
+ Preferences p = new MockPreferences();
+ p.absolutePath();
+ try {
+ p.childrenNames();
+ } catch (BackingStoreException e4) {
+ }
+ try {
+ p.clear();
+ } catch (BackingStoreException e5) {
+ }
+ try {
+ p.exportNode(null);
+ } catch (IOException e6) {
+ } catch (BackingStoreException e6) {
+ }
+ try {
+ p.exportSubtree(null);
+ } catch (IOException e7) {
+ } catch (BackingStoreException e7) {
+ }
+ try {
+ p.flush();
+ } catch (BackingStoreException e8) {
+ }
+ p.get(null, null);
+ p.getBoolean(null, false);
+ p.getByteArray(null, null);
+ p.getFloat(null, 0.1f);
+ p.getDouble(null, 0.1);
+ p.getInt(null, 1);
+ p.getLong(null, 1l);
+ p.isUserNode();
+ try {
+ p.keys();
+ } catch (BackingStoreException e) {
+ }
+ p.name();
+ p.node(null);
+ try {
+ p.nodeExists(null);
+ } catch (BackingStoreException e1) {
+ }
+ p.parent();
+ p.put(null, null);
+ p.putBoolean(null, false);
+ p.putByteArray(null, null);
+ p.putDouble(null, 1);
+ p.putFloat(null, 1f);
+ p.putInt(null, 1);
+ p.putLong(null, 1l);
+ p.remove(null);
+ try {
+ p.removeNode();
+ } catch (BackingStoreException e2) {
+ }
+ p.addNodeChangeListener(null);
+ p.addPreferenceChangeListener(null);
+ p.removeNodeChangeListener(null);
+ p.removePreferenceChangeListener(null);
+ try {
+ p.sync();
+ } catch (BackingStoreException e3) {
+ }
+ p.toString();
+ }
+
+ static class MockInputStream extends InputStream {
+
+ static final int normal = 0;
+
+ static final int exception = 1;
+
+ static final int runtimeException = 2;
+
+ int result = normal;
+
+ InputStream wrapper;
+
+ public void setResult(int i) {
+ result = i;
+ }
+
+ private void checkException() throws IOException {
+ switch (result) {
+ case normal:
+ return;
+ case exception:
+ throw new IOException("test");
+ case runtimeException:
+ throw new RuntimeException("test");
+ }
+ }
+
+ public MockInputStream(InputStream in) {
+ wrapper = in;
+ }
+
+ public int read() throws IOException {
+ checkException();
+ return wrapper.read();
+ }
+ }
+
+ static class MockPreferences extends Preferences {
+
+ public MockPreferences() {
+ super();
+ }
+
+ public String absolutePath() {
+ return null;
+ }
+
+ public String[] childrenNames() throws BackingStoreException {
+ return null;
+ }
+
+ public void clear() throws BackingStoreException {
+ }
+
+ public void exportNode(OutputStream ostream) throws IOException,
+ BackingStoreException {
+ }
+
+ public void exportSubtree(OutputStream ostream) throws IOException,
+ BackingStoreException {
+ }
+
+ public void flush() throws BackingStoreException {
+ }
+
+ public String get(String key, String deflt) {
+ return null;
+ }
+
+ public boolean getBoolean(String key, boolean deflt) {
+ return false;
+ }
+
+ public byte[] getByteArray(String key, byte[] deflt) {
+ return null;
+ }
+
+ public double getDouble(String key, double deflt) {
+ return 0;
+ }
+
+ public float getFloat(String key, float deflt) {
+ return 0;
+ }
+
+ public int getInt(String key, int deflt) {
+ return 0;
+ }
+
+ public long getLong(String key, long deflt) {
+ return 0;
+ }
+
+ public boolean isUserNode() {
+ return false;
+ }
+
+ public String[] keys() throws BackingStoreException {
+ return null;
+ }
+
+ public String name() {
+ return null;
+ }
+
+ public Preferences node(String name) {
+ return null;
+ }
+
+ public boolean nodeExists(String name) throws BackingStoreException {
+ return false;
+ }
+
+ public Preferences parent() {
+ return null;
+ }
+
+ public void put(String key, String value) {
+
+ }
+
+ public void putBoolean(String key, boolean value) {
+
+ }
+
+ public void putByteArray(String key, byte[] value) {
+
+ }
+
+ public void putDouble(String key, double value) {
+
+ }
+
+ public void putFloat(String key, float value) {
+
+ }
+
+ public void putInt(String key, int value) {
+
+ }
+
+ public void putLong(String key, long value) {
+
+ }
+
+ public void remove(String key) {
+
+ }
+
+ public void removeNode() throws BackingStoreException {
+
+ }
+
+ public void addNodeChangeListener(NodeChangeListener ncl) {
+
+ }
+
+ public void addPreferenceChangeListener(PreferenceChangeListener pcl) {
+
+ }
+
+ public void removeNodeChangeListener(NodeChangeListener ncl) {
+
+ }
+
+ public void removePreferenceChangeListener(PreferenceChangeListener pcl) {
+
+ }
+
+ public void sync() throws BackingStoreException {
+
+ }
+
+ public String toString() {
+ return null;
+ }
+
+ }
+
+}
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/preferences.dtd
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/preferences.dtd?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/preferences.dtd (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/preferences.dtd Wed Mar 15 06:55:38 2006
@@ -0,0 +1,39 @@
+<!-- $$COPYRIGHT$$[2005]$$ -->
+
+<!-- DTD for a Preferences tree. -->
+
+<!-- The preferences element is at the root of an XML document
+ representing a Preferences tree. -->
+<!ELEMENT preferences (root)>
+
+<!-- The preferences element contains an optional version attribute,
+ which specifies version of DTD. -->
+<!ATTLIST preferences EXTERNAL_XML_VERSION CDATA "0.0" >
+
+<!-- The root element has a map representing the root's preferences
+ (if any), and one node for each child of the root (if any). -->
+<!ELEMENT root (map, node*) >
+
+<!-- Additionally, the root contains a type attribute, which
+ specifies whether it's the system or user root. -->
+<!ATTLIST root
+ type (system|user) #REQUIRED >
+
+<!-- Each node has a map representing its preferences (if any),
+ and one node for each child (if any). -->
+
+<!ELEMENT node (map, node*) >
+
+<!-- Additionally, each node has a name attribute -->
+<!ATTLIST node
+ name CDATA #REQUIRED >
+
+<!-- A map represents the preferences stored at a node (if any). -->
+<!ELEMENT map (entry*) >
+
+<!-- An entry represents a single preference, which is simply
+ a key-value pair. -->
+<!ELEMENT entry EMPTY >
+<!ATTLIST entry
+ key CDATA #REQUIRED
+ value CDATA #REQUIRED >
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-ascii.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-ascii.xml?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-ascii.xml (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-ascii.xml Wed Mar 15 06:55:38 2006
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="ascii"?>
+
+<!-- Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. -->
+
+<!DOCTYPE preferences SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>
+
+<preferences EXTERNAL_XML_VERSION="1.0">
+ <root type="user">
+ <map />
+ <node name="tests">
+ <map />
+ <node name="api">
+ <map />
+ <node name="java">
+ <map />
+ <node name="util">
+ <map />
+ <node name="prefs">
+ <map>
+ <entry key="prefskey3" value="newvalue3" />
+ </map>
+ <node name="mock">
+ <map />
+ <node name="child">
+ <map>
+ <entry key="key2" value="value2" />
+ </map>
+ <node name="grandson">
+ <map>
+ <entry key="key3" value="value3" />
+ </map>
+ <node name="grandgrandson">
+ <map>
+ <entry key="key4" value="value4" />
+ </map>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </root>
+</preferences>
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badencoding.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badencoding.xml?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badencoding.xml (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badencoding.xml Wed Mar 15 06:55:38 2006
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="badencoding"?>
+
+<!-- Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. -->
+
+<!DOCTYPE preferences SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>
+
+<preferences EXTERNAL_XML_VERSION="1.0">
+ <root type="user">
+ <map />
+ <node name="tests">
+ <map />
+ <node name="api">
+ <map />
+ <node name="java">
+ <map />
+ <node name="util">
+ <map />
+ <node name="prefs">
+ <map>
+ <entry key="prefskey" value="newvalue" />
+ <entry key="prefskey3" value="newvalue3" />
+ </map>
+ <node name="mock">
+ <map />
+ <node name="child">
+ <map>
+ <entry key="key2" value="value2" />
+ </map>
+ <node name="grandson">
+ <map>
+ <entry key="key3" value="value3" />
+ </map>
+ <node name="grandgrandson">
+ <map>
+ <entry key="key4" value="value4" />
+ </map>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </root>
+</preferences>
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badform.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badform.xml?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badform.xml (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badform.xml Wed Mar 15 06:55:38 2006
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. -->
+
+<!DOCTYPE preferences SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>
+
+<preferences EXTERNAL_XML_VERSION="1.0">
+ <root type="user">
+ <map />
+ <node name="java">
+ <map />
+ <node name="util">
+ <map />
+ <node name="prefs">
+ <map />
+ <node name="mock">
+ <map />
+ <node name="child">
+ <map>
+ <entry key="key2" value="value2" />
+ </map>
+ <node name="grandson">
+ <map>
+ <entry key="key3" value="value3" />
+ </map>
+ <node name="grandgrandson">
+ <map>
+ <entry key="key4" value="value4" />
+ </map>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </root>
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badtype.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badtype.xml?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badtype.xml (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-badtype.xml Wed Mar 15 06:55:38 2006
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. -->
+
+<!DOCTYPE preferences SYSTEM 'preferences.dtd'>
+
+<preferences EXTERNAL_XML_VERSION="1.0">
+ <root type="user">
+ <map />
+ <node name="tests">
+ <map />
+ <node name="api">
+ <map />
+ <node name="java">
+ <map />
+ <node name="util">
+ <map />
+ <node name="prefs">
+ <map>
+ <entry key="prefskey" value="newvalue" />
+ <entry key="prefskey3" value="newvalue3" />
+ </map>
+ <node name="mock">
+ <map />
+ <node name="child">
+ <map>
+ <entry key="key2" value="value2" />
+ </map>
+ <node name="grandson">
+ <map>
+ <entry key="key3" value="value3" />
+ </map>
+ <node name="grandgrandson">
+ <map>
+ <entry key="key4" value="value4" />
+ </map>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </root>
+</preferences>
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-higherversion.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-higherversion.xml?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-higherversion.xml (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs-higherversion.xml Wed Mar 15 06:55:38 2006
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. -->
+
+<!DOCTYPE preferences SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>
+
+<preferences EXTERNAL_XML_VERSION="1.1">
+ <root type="user">
+ <map />
+ <node name="tests">
+ <map />
+ <node name="api">
+ <map />
+ <node name="java">
+ <map />
+ <node name="util">
+ <map />
+ <node name="prefs">
+ <map>
+ <entry key="prefskey" value="newvalue" />
+ <entry key="prefskey3" value="newvalue3" />
+ </map>
+ <node name="mock">
+ <map />
+ <node name="child">
+ <map>
+ <entry key="key2" value="value2" />
+ </map>
+ <node name="grandson">
+ <map>
+ <entry key="key3" value="value3" />
+ </map>
+ <node name="grandgrandson">
+ <map>
+ <entry key="key4" value="value4" />
+ </map>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </root>
+</preferences>
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs.xml
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs.xml?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs.xml (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/api/java/util/prefs/userprefs.xml Wed Mar 15 06:55:38 2006
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. -->
+
+<!DOCTYPE preferences SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>
+
+<preferences EXTERNAL_XML_VERSION="1.0">
+ <root type="user">
+ <map />
+ <node name="tests">
+ <map />
+ <node name="api">
+ <map />
+ <node name="java">
+ <map />
+ <node name="util">
+ <map />
+ <node name="prefs">
+ <map>
+ <entry key="prefskey" value="newvalue" />
+ <entry key="prefskey3" value="newvalue3" />
+ </map>
+ <node name="mock">
+ <map />
+ <node name="child">
+ <map>
+ <entry key="key2" value="value2" />
+ </map>
+ <node name="grandson">
+ <map>
+ <entry key="key3" value="value3" />
+ </map>
+ <node name="grandgrandson">
+ <map>
+ <entry key="key4" value="value4" />
+ </map>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+ </root>
+</preferences>
Added: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/prefs/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/prefs/AllTests.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/prefs/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/tests/prefs/AllTests.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,38 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.prefs;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all tests for the Prefs project.
+ *
+ */
+public class AllTests {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("All Prefs test suites");
+ // $JUnit-BEGIN$
+ suite.addTest(tests.api.java.util.prefs.AllTests.suite());
+ // $JUnit-END$
+ return suite;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/AllTests.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/AllTests.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,40 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.regex;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("API test suite for java.util.regex");
+ // $JUnit-BEGIN$
+ suite.addTestSuite(PatternTests.class);
+ suite.addTestSuite(ModeTests.class);
+ suite.addTestSuite(PatternSyntaxExceptionTests.class);
+ suite.addTestSuite(PatternErrorTests.class);
+ suite.addTestSuite(SplitTests.class);
+ suite.addTestSuite(ReplaceTests.class);
+ suite.addTestSuite(MatcherTests.class);
+ // $JUnit-END$
+ return suite;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/MatcherTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/MatcherTests.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/MatcherTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/MatcherTests.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,248 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.regex;
+
+import junit.framework.TestCase;
+import java.util.regex.*;
+
+/**
+ * Tests Matcher methods
+ *
+ */
+public class MatcherTests extends TestCase {
+ public void test_toString() {
+ Pattern p = Pattern.compile("foo");
+ Matcher m = p.matcher("bar");
+ assertTrue(Pattern.matches("java.util.regex.Matcher@[0-9a-fA-F]*", m
+ .toString()));
+ }
+
+ public void testErrorConditions() {
+ Pattern p;
+ Matcher m;
+ boolean errFound;
+ try {
+ // Test match cursors in absence of a match
+ p = Pattern.compile("foo");
+ m = p.matcher("bar");
+ assertFalse(m.matches());
+
+ errFound = false;
+ try {
+ m.start();
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.end();
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.group();
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.start(1);
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.end(1);
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.group(1);
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ // Test match cursors in absence of a match
+ p = Pattern.compile("(foo[0-9])(bar[a-z])");
+ m = p.matcher("foo1barzfoo2baryfoozbar5");
+
+ assertTrue(m.find());
+ assertTrue(m.start() == 0);
+ assertTrue(m.end() == 8);
+ assertTrue(m.start(1) == 0);
+ assertTrue(m.end(1) == 4);
+ assertTrue(m.start(2) == 4);
+ assertTrue(m.end(2) == 8);
+ errFound = false;
+ try {
+ m.start(3);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.end(3);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.group(3);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.start(-1);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.end(-1);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.group(-1);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ assertTrue(m.find());
+ assertTrue(m.start() == 8);
+ assertTrue(m.end() == 16);
+ assertTrue(m.start(1) == 8);
+ assertTrue(m.end(1) == 12);
+ assertTrue(m.start(2) == 12);
+ assertTrue(m.end(2) == 16);
+ errFound = false;
+ try {
+ m.start(3);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.end(3);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.group(3);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.start(-1);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.end(-1);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ errFound = false;
+ try {
+ m.group(-1);
+ } catch (IndexOutOfBoundsException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ assertFalse(m.find());
+ errFound = false;
+ try {
+ m.start(3);
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.end(3);
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.group(3);
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.start(-1);
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.end(-1);
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+
+ errFound = false;
+ try {
+ m.group(-1);
+ } catch (IllegalStateException e) {
+ errFound = true;
+ }
+ assertTrue(errFound);
+ } catch (PatternSyntaxException e) {
+ fail();
+ }
+ }
+}
+
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/ModeTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/ModeTests.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/ModeTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/ModeTests.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,165 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.regex;
+
+import junit.framework.TestCase;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Tests Pattern compilation modes and modes triggered in pattern strings
+ *
+ */
+public class ModeTests extends TestCase {
+ public void testCase() {
+ Pattern p;
+ Matcher m;
+
+ try {
+ p = Pattern.compile("([a-z]+)[0-9]+");
+ } catch (PatternSyntaxException e) {
+ assertFalse(true);
+ return;
+ }
+
+ m = p.matcher("cAT123#dog345");
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("dog"));
+ assertFalse(m.find());
+
+ try {
+ p = Pattern.compile("([a-z]+)[0-9]+", Pattern.CASE_INSENSITIVE);
+ } catch (PatternSyntaxException e) {
+ assertFalse(true);
+ return;
+ }
+
+ m = p.matcher("cAt123#doG345");
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("cAt"));
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("doG"));
+ assertFalse(m.find());
+
+ try {
+ p = Pattern.compile("(?i)([a-z]+)[0-9]+");
+ } catch (PatternSyntaxException e) {
+ assertFalse(true);
+ return;
+ }
+
+ m = p.matcher("cAt123#doG345");
+ assertTrue(m.find());
+ System.out.println(m.group());
+ System.out.println(m.group(1));
+ assertTrue(m.group(1).equals("cAt"));
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("doG"));
+ assertFalse(m.find());
+ }
+
+ public void testMultiline() {
+ Pattern p;
+ Matcher m;
+
+ try {
+ p = Pattern.compile("^foo");
+ } catch (PatternSyntaxException e) {
+ assertFalse(true);
+ return;
+ }
+
+ m = p.matcher("foobar");
+ assertTrue(m.find());
+ assertTrue(m.start() == 0 && m.end() == 3);
+ assertFalse(m.find());
+
+ m = p.matcher("barfoo");
+ assertFalse(m.find());
+
+ try {
+ p = Pattern.compile("foo$");
+ } catch (PatternSyntaxException e) {
+ assertFalse(true);
+ return;
+ }
+
+ m = p.matcher("foobar");
+ assertFalse(m.find());
+
+ m = p.matcher("barfoo");
+ assertTrue(m.find());
+ assertTrue(m.start() == 3 && m.end() == 6);
+ assertFalse(m.find());
+
+ try {
+ p = Pattern.compile("^foo([0-9]*)", Pattern.MULTILINE);
+ } catch (PatternSyntaxException e) {
+ assertFalse(true);
+ return;
+ }
+
+ m = p.matcher("foo1bar\nfoo2foo3\nbarfoo4");
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("1"));
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("2"));
+ assertFalse(m.find());
+
+ try {
+ p = Pattern.compile("foo([0-9]*)$", Pattern.MULTILINE);
+ } catch (PatternSyntaxException e) {
+ assertFalse(true);
+ return;
+ }
+
+ m = p.matcher("foo1bar\nfoo2foo3\nbarfoo4");
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("3"));
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("4"));
+ assertFalse(m.find());
+
+ try {
+ p = Pattern.compile("(?m)^foo([0-9]*)");
+ } catch (PatternSyntaxException e) {
+ assertFalse(true);
+ return;
+ }
+
+ m = p.matcher("foo1bar\nfoo2foo3\nbarfoo4");
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("1"));
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("2"));
+ assertFalse(m.find());
+
+ try {
+ p = Pattern.compile("(?m)foo([0-9]*)$");
+ } catch (PatternSyntaxException e) {
+ assertFalse(true);
+ return;
+ }
+
+ m = p.matcher("foo1bar\nfoo2foo3\nbarfoo4");
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("3"));
+ assertTrue(m.find());
+ assertTrue(m.group(1).equals("4"));
+ assertFalse(m.find());
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternErrorTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternErrorTests.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternErrorTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternErrorTests.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,96 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.regex;
+
+import java.util.regex.Pattern;
+import junit.framework.TestCase;
+
+/**
+ * Test boundary and error conditions in java.util.regex.Pattern
+ *
+ */
+public class PatternErrorTests extends TestCase {
+ public void testCompileErrors() {
+ boolean validException = false;
+
+ // null regex string - should get NullPointerException
+ try {
+ Pattern.compile(null);
+ } catch (NullPointerException e) {
+ // This is the expected exception
+ validException = true;
+ } catch (Exception e) {
+ fail();
+ }
+ assertTrue(validException);
+
+ // empty regex string - no exception should be thrown
+ try {
+ Pattern.compile("");
+ } catch (Exception e) {
+ fail();
+ }
+
+ // note: invalid regex syntax checked in PatternSyntaxExceptionTests
+
+ // flags = 0 should raise no exception
+ int flags = 0;
+ try {
+ Pattern.compile("foo", flags);
+ } catch (Exception e) {
+ fail();
+ }
+
+ // check that all valid flags accepted without exception
+ flags |= Pattern.UNIX_LINES;
+ flags |= Pattern.CASE_INSENSITIVE;
+ flags |= Pattern.MULTILINE;
+ flags |= Pattern.CANON_EQ;
+ flags |= Pattern.COMMENTS;
+ flags |= Pattern.DOTALL;
+ flags |= Pattern.UNICODE_CASE;
+ try {
+ Pattern.compile("foo", flags);
+ } catch (Exception e) {
+ fail();
+ }
+
+ // add invalid flags - should get IllegalArgumentException
+ /*
+ * TODO: Inconsistency between the reference JDK behaviour and spec - exception is
+ * not thrown
+ */
+ /*
+ * Valid test is:
+ * flags |= 0xFFFFFFFF;
+ * try {
+ * Pattern.compile("foo",flags);
+ * } catch (IllegalArgumentException e) {
+ * // This is the expected exception
+ * } catch (Exception e) {
+ * fail();
+ * }
+ */
+ /* Workaround test is: */
+ flags |= 0xFFFFFFFF;
+ try {
+ Pattern.compile("foo", flags);
+ } catch (Exception e) {
+ // No exception expected to match incorrect the reference behaviour
+ fail();
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternSyntaxExceptionTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternSyntaxExceptionTests.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternSyntaxExceptionTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternSyntaxExceptionTests.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,57 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.api.java.util.regex;
+
+import junit.framework.TestCase;
+
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * TODO Type description
+ *
+ */
+public class PatternSyntaxExceptionTests extends TestCase {
+ public void testCase() {
+ String regex;
+ regex = "(";
+ try {
+ Pattern.compile(regex);
+ } catch (PatternSyntaxException e) {
+ assertTrue(e.getDescription().equals("')' is expected."));
+ // The reference JDK index:
+ // assertTrue(e.getIndex() == 1);
+ assertTrue(e.getIndex() == 0);
+ assertTrue(e.getMessage().equals(
+ "')' is expected. near index 0\r\n(\r\n^"));
+ assertTrue(e.getPattern().equals(regex));
+ }
+
+ regex = "[4-";
+ try {
+ Pattern.compile(regex);
+ } catch (PatternSyntaxException e) {
+ assertTrue(e.getDescription().equals(
+ "Unexpected end of the pattern in a character class."));
+ assertTrue(e.getIndex() == 3);
+ assertTrue(e
+ .getMessage()
+ .equals(
+ "Unexpected end of the pattern in a character class. near index 3\r\n[4-\r\n ^"));
+ assertTrue(e.getPattern().equals(regex));
+ }
+ }
+}