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 2007/11/20 15:43:29 UTC
svn commit: r596693 [4/9] - in /harmony/enhanced/classlib/branches/java6: ./
depends/jars/ depends/libs/build/ make/
modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/
modules/auth/src/main/java/common/org/apache/harmony/auth/jgss...
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParser.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParser.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParser.java Tue Nov 20 06:42:33 2007
@@ -32,14 +32,28 @@
private Filter filter;
- private String baseObject;
+ private String baseObject = "";
- private String host;
+ private String host = DEFAULT_HOST;
- private int port = -1;
+ private int port = DEFAULT_PORT;
+
+ private boolean hasAttributes = false;
+
+ private boolean hasScope = false;
+
+ private boolean hasFilter = false;
+
+ private boolean hasExtensions= false;
private boolean isEndEOF = false;
+ private static final int DEFAULT_PORT = 389;
+
+ private static final int DEFAULT_SSL_PORT = 636;
+
+ private static final String DEFAULT_HOST = "localhost";
+
public LdapUrlParser(String url) {
this(new StringReader(url));
isEndEOF = true;
@@ -82,6 +96,22 @@
return baseObject;
}
+ public boolean hasFilter() {
+ return hasFilter;
+ }
+
+ public boolean hasAttributes() {
+ return hasAttributes;
+ }
+
+ public boolean hasScope() {
+ return hasScope;
+ }
+
+ public boolean hasExtensions() {
+ return hasExtensions;
+ }
+
public static void main(String args[]) throws ParseException, FileNotFoundException {
LdapUrlParser parser = new LdapUrlParser(new FileInputStream("parser.url.test"));
// URLParser parser = new URLParser(System.in);
@@ -92,7 +122,11 @@
}
final public void parseURL() throws ParseException {
- jj_consume_token(SCHEME);
+ Token t;
+ t = jj_consume_token(SCHEME);
+ if (t.image.equals("ldaps://")) {
+ port = DEFAULT_SSL_PORT;
+ }
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case SCHEME:
case PRE_XTOKEN:
@@ -453,9 +487,10 @@
;
}
if (attrs.size() != 0) {
+ hasAttributes = true;
if (controls == null) {
// FIXME: test what default search parameter value is
- controls = new SearchControls(SearchControls.OBJECT_SCOPE, 0, 0, null, false, false);
+ controls = new SearchControls();
}
controls.setReturningAttributes((String[]) attrs.toArray(new String[0]));
}
@@ -481,9 +516,9 @@
case SCOPE:
t = jj_consume_token(SCOPE);
scope = t.image;
+ hasScope = true;
if (controls == null) {
- // FIXME: test what default search parameter value is
- controls = new SearchControls(SearchControls.OBJECT_SCOPE, 0, 0, null, false, false);
+ controls = new SearchControls();
}
if (scope.equals("base")) {
controls.setSearchScope(SearchControls.OBJECT_SCOPE);
@@ -526,6 +561,7 @@
value = value();
FilterParser parser = new FilterParser(new StringReader(value));
filter = parser.parse();
+ hasFilter = true;
break;
default:
jj_la1[21] = jj_gen;
@@ -544,6 +580,7 @@
final public void extensions() throws ParseException {
extension();
+ hasExtensions = true;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case COMMA:
label_6:
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/filter.g
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/filter.g?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/filter.g (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/filter.g Tue Nov 20 06:42:33 2007
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
options {
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/url.g
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/url.g?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/url.g (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/parser/url.g Tue Nov 20 06:42:33 2007
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
options {
STATIC = false;
@@ -39,14 +56,28 @@
private Filter filter;
- private String baseObject;
+ private String baseObject = "";
+
+ private String host = DEFAULT_HOST;
+
+ private int port = DEFAULT_PORT;
- private String host;
+ private boolean hasAttributes = false;
- private int port = -1;
+ private boolean hasScope = false;
+
+ private boolean hasFilter = false;
+
+ private boolean hasExtensions= false;
private boolean isEndEOF = false;
+ private static final int DEFAULT_PORT = 389;
+
+ private static final int DEFAULT_SSL_PORT = 636;
+
+ private static final String DEFAULT_HOST = "localhost";
+
public LdapUrlParser(String url) {
this(new StringReader(url));
isEndEOF = true;
@@ -89,6 +120,22 @@
return baseObject;
}
+ public boolean hasFilter() {
+ return hasFilter;
+ }
+
+ public boolean hasAttributes() {
+ return hasAttributes;
+ }
+
+ public boolean hasScope() {
+ return hasScope;
+ }
+
+ public boolean hasExtensions() {
+ return hasExtensions;
+ }
+
public static void main(String args[]) throws ParseException, FileNotFoundException {
LdapUrlParser parser = new LdapUrlParser(new FileInputStream("parser.url.test"));
// URLParser parser = new URLParser(System.in);
@@ -140,9 +187,16 @@
void parseURL():
- {}
{
- <SCHEME>
+ Token t;
+ }
+ {
+ t = <SCHEME>
+ {
+ if (t.image.equals("ldaps://")) {
+ port = DEFAULT_SSL_PORT;
+ }
+ }
[hostport()]
[<SLASH> [dn()
[<QUESTION_MARK> attributes()]]]
@@ -254,9 +308,10 @@
[(<COMMA> value = value() {attrs.add(value);})+]]
{
if (attrs.size() != 0) {
+ hasAttributes = true;
if (controls == null) {
// FIXME: test what default search parameter value is
- controls = new SearchControls(SearchControls.OBJECT_SCOPE, 0, 0, null, false, false);
+ controls = new SearchControls();
}
controls.setReturningAttributes((String[]) attrs.toArray(new String[0]));
}
@@ -279,9 +334,9 @@
[t = <SCOPE>
{
scope = t.image;
+ hasScope = true;
if (controls == null) {
- // FIXME: test what default search parameter value is
- controls = new SearchControls(SearchControls.OBJECT_SCOPE, 0, 0, null, false, false);
+ controls = new SearchControls();
}
if (scope.equals("base")) {
controls.setSearchScope(SearchControls.OBJECT_SCOPE);
@@ -305,13 +360,15 @@
{
FilterParser parser = new FilterParser(new StringReader(value));
filter = parser.parse();
+ hasFilter = true;
}]
[<QUESTION_MARK> extensions()]
}
+
void extensions():
{}
{
- extension() [(<COMMA> extension())+]
+ extension() {hasExtensions = true;} [(<COMMA> extension())+]
}
void extension():
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/AddOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/AddOpTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/AddOpTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/AddOpTest.java Tue Nov 20 06:42:33 2007
@@ -29,7 +29,7 @@
ASN1TestUtils.checkEncode(op.getRequest(), LdapASN1Constant.AddRequest);
- LdapAttribute attr = new LdapAttribute("attr1");
+ LdapAttribute attr = new LdapAttribute("attr1", null);
op.addAttribute(attr);
ASN1TestUtils.checkEncode(op.getRequest(), LdapASN1Constant.AddRequest);
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/BindOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/BindOpTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/BindOpTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/BindOpTest.java Tue Nov 20 06:42:33 2007
@@ -26,7 +26,7 @@
public void test_encodeValues_$LObject() {
String dn = "o=Entry";
String pwd = "secret";
- BindOp op = new BindOp(dn, pwd);
+ BindOp op = new BindOp(dn, pwd,null,null);
ASN1TestUtils.checkEncode(op.getRequest(), LdapASN1Constant.BindRequest);
}
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapAttributeTest.java Tue Nov 20 06:42:33 2007
@@ -17,7 +17,11 @@
package org.apache.harmony.jndi.provider.ldap;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.naming.NamingException;
+import javax.naming.directory.BasicAttribute;
import junit.framework.TestCase;
@@ -31,18 +35,67 @@
byte[] v1 = Utils.getBytes("value1");
byte[] v2 = Utils.getBytes("value2");
byte[] v3 = Utils.getBytes("value3");
- LdapAttribute attr = new LdapAttribute(id);
+ LdapAttribute attr = new LdapAttribute(id, null);
attr.add(v1);
attr.add(v2);
attr.add(v3);
ASN1TestUtils.checkEncode(attr, LdapASN1Constant.Attribute);
-
+
Object[] encoded = new Object[2];
attr.encodeValues(encoded);
- LdapAttribute decoded = new LdapAttribute("");
+ LdapAttribute decoded = new LdapAttribute("", null);
decoded.decodeValues(encoded);
-
+
assertEquals(attr.getID(), decoded.getID());
+ }
+
+ public void test_constructor_LAttribute() throws Exception {
+ BasicAttribute attr = new BasicAttribute("cn");
+ attr.add("test");
+ attr.add("harmony");
+ LdapAttribute la = new LdapAttribute(attr, null);
+
+ ASN1TestUtils.checkEncode(la, LdapASN1Constant.Attribute);
+
+ }
+
+ public void test_binary_attribute() throws Exception {
+ String id = "photo";
+ List<byte[]> valueList = new ArrayList<byte[]>();
+ byte[] bs = new byte[] { 0, 1, 2, 3, 4, 5 };
+ valueList.add(bs);
+ bs = Utils.getBytes("value");
+ valueList.add(bs);
+
+ Object[] values = new Object[] { Utils.getBytes(id), valueList };
+
+ LdapAttribute la = new LdapAttribute();
+ // 'photo' is binary attribute
+ la.decodeValues(values);
+
+ for (int i = 0; i < la.size(); ++i) {
+ assertTrue(la.get(i) instanceof byte[]);
+ }
+
+ id = "cn";
+ values = new Object[] { Utils.getBytes(id), valueList };
+ la = new LdapAttribute();
+ // 'cn' is not binary attribute, should return string value
+ la.decodeValues(values);
+
+ for (int i = 0; i < la.size(); ++i) {
+ assertTrue(la.get() instanceof String);
+ }
+
+ id = "cn;binary";
+ values = new Object[] { Utils.getBytes(id), valueList };
+ la = new LdapAttribute();
+ // 'cn;binary' is binary attribute
+ la.decodeValues(values);
+
+ for (int i = 0; i < la.size(); ++i) {
+ assertTrue(la.get() instanceof byte[]);
+ }
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapContextImplTest.java Tue Nov 20 06:42:33 2007
@@ -17,17 +17,53 @@
package org.apache.harmony.jndi.provider.ldap;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.InvalidNameException;
import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InvalidSearchFilterException;
+import javax.naming.directory.SearchControls;
+import javax.naming.ldap.BasicControl;
+import javax.naming.ldap.Control;
import javax.naming.ldap.LdapName;
import junit.framework.TestCase;
+import org.apache.harmony.jndi.internal.parser.AttributeTypeAndValuePair;
+
public class LdapContextImplTest extends TestCase {
private LdapContextImpl context;
+
+ public void test_getSchema() throws NamingException {
+ context = new LdapContextImpl(new MockLdapClient(), null, "");
+ try {
+ context.getSchema((Name) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ context.getSchema((String) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
public void test_composeName_LNameLName() throws Exception {
- context = new LdapContextImpl(new LdapClient(), null, "");
+ context = new LdapContextImpl(new MockLdapClient(), null, "");
Name name = new LdapName("cn=happy,dc=test");
Name prefix = new LdapName("o=harmony");
Name result = context.composeName(name, prefix);
@@ -63,4 +99,408 @@
assertTrue(result instanceof CompositeName);
assertEquals("bin/cn=ok/usr", result.toString());
}
+
+ public void test_list_LName() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "");
+
+ Name name = new LdapName("cn=test,o=harmony");
+ context.list(name);
+
+ SearchOp op = (SearchOp) client.getRequest();
+ assertEquals(name.toString(), op.getBaseObject());
+ assertFalse(op.isTypesOnly());
+ SearchControls controls = op.getControls();
+ assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
+ Filter filter = op.getFilter();
+ assertEquals(Filter.PRESENT_FILTER, filter.getType());
+ assertEquals("objectClass", (String) filter.getValue());
+
+ name = new CompositeName("usr/bin");
+ try {
+ context.list(name);
+ fail("should throws InvalidNameException");
+ } catch (InvalidNameException e) {
+ // expected
+ }
+ }
+
+ public void test_createSubcontext_LName() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "cn=test");
+
+ Name name = new LdapName("cn=add+dc=hello,o=harmony");
+ context.createSubcontext(name);
+
+ AddOp op = (AddOp) client.getRequest();
+ assertEquals("cn=add+dc=hello,o=harmony,cn=test", op.getEntry());
+ List<LdapAttribute> list = op.getAttributeList();
+
+ assertEquals(3, list.size());
+ Map<String, LdapAttribute> map = new HashMap<String, LdapAttribute>();
+ for (LdapAttribute attribute : list) {
+ map.put(attribute.getID(), attribute);
+ }
+
+ assertTrue(map.containsKey("objectClass"));
+ Attribute attr = map.get("objectClass");
+ assertEquals(2, attr.size());
+ assertTrue(attr.get(0) instanceof String);
+ assertTrue(attr.get(1) instanceof String);
+ assertTrue(attr.get(0).equals("top")
+ || attr.get(0).equals("javaContainer"));
+ assertTrue(attr.get(1).equals("top")
+ || attr.get(1).equals("javaContainer"));
+
+ assertTrue(map.containsKey("cn"));
+ attr = map.get("cn");
+ assertEquals(1, attr.size());
+ assertEquals("add", attr.get(0));
+
+ assertTrue(map.containsKey("dc"));
+ attr = map.get("dc");
+ assertEquals(1, attr.size());
+ assertEquals("hello", attr.get(0));
+ }
+
+ public void test_createSubcontext_LNameLAttributes() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "cn=test");
+
+ Name name = new LdapName("cn=add+dc=hello,o=harmony");
+ Attributes attrs = new BasicAttributes();
+ Attribute attr = new BasicAttribute("ou");
+ attr.add("harmony");
+ attr.add("apache");
+ attrs.put(attr);
+
+ context.createSubcontext(name, attrs);
+
+ AddOp op = (AddOp) client.getRequest();
+ assertEquals("cn=add+dc=hello,o=harmony,cn=test", op.getEntry());
+ List<LdapAttribute> list = op.getAttributeList();
+
+ assertEquals(3, list.size());
+ Map<String, LdapAttribute> map = new HashMap<String, LdapAttribute>();
+ for (LdapAttribute attribute : list) {
+ map.put(attribute.getID(), attribute);
+ }
+
+ assertTrue(map.containsKey("ou"));
+ attr = map.get("ou");
+ assertEquals(2, attr.size());
+ assertTrue(attr.get(0) instanceof String);
+ assertTrue(attr.get(1) instanceof String);
+ assertTrue(attr.get(0).equals("harmony")
+ || attr.get(0).equals("apache"));
+ assertTrue(attr.get(1).equals("harmony")
+ || attr.get(1).equals("apache"));
+
+ assertTrue(map.containsKey("cn"));
+ attr = map.get("cn");
+ assertEquals(1, attr.size());
+ assertEquals("add", attr.get(0));
+
+ assertTrue(map.containsKey("dc"));
+ attr = map.get("dc");
+ assertEquals(1, attr.size());
+ assertEquals("hello", attr.get(0));
+ }
+
+ public void test_getAttributes() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "cn=test");
+
+ Attributes attrs = context.getAttributes("o=apache");
+ SearchOp op = (SearchOp) client.getRequest();
+ assertEquals("o=apache,cn=test", op.getBaseObject());
+ SearchControls controls = op.getControls();
+ assertEquals(SearchControls.OBJECT_SCOPE, controls.getSearchScope());
+ assertNull(controls.getReturningAttributes());
+
+ Filter filter = op.getFilter();
+ assertEquals(Filter.PRESENT_FILTER, filter.getType());
+ assertEquals("objectClass", filter.getValue());
+
+ attrs = context.getAttributes("o=apache", new String[0]);
+ op = (SearchOp) client.getRequest();
+ assertEquals("o=apache,cn=test", op.getBaseObject());
+ controls = op.getControls();
+ assertEquals(SearchControls.OBJECT_SCOPE, controls.getSearchScope());
+ assertEquals(1, controls.getReturningAttributes().length);
+ assertEquals("1.1", controls.getReturningAttributes()[0]);
+ filter = op.getFilter();
+ assertEquals(Filter.PRESENT_FILTER, filter.getType());
+ assertEquals("objectClass", filter.getValue());
+ }
+
+ public void test_modifyAttributes() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "cn=test");
+
+ Attributes attributes = new BasicAttributes();
+ Attribute attr = new BasicAttribute("cn");
+ attr.add("hello");
+ attr.add("world");
+ attributes.put(attr);
+
+ context.modifyAttributes("o=apache", DirContext.ADD_ATTRIBUTE,
+ attributes);
+ try {
+ context.modifyAttributes("", null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ context.modifyAttributes("", -1, attributes);
+ fail("Should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ // TODO: add test for names not in same namespace
+ public void test_rename() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "cn=test");
+
+ context.rename("cn=what", "cn=how");
+
+ ModifyDNOp op = (ModifyDNOp) client.getRequest();
+ assertEquals("cn=what,cn=test", op.getEntry());
+ assertEquals("cn=how", op.getNewrdn());
+ assertEquals("cn=test", op.getNewSuperior());
+ assertEquals(true, op.isDeleteoldrdn());
+
+ Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+ env.put("java.naming.ldap.deleteRDN", "false");
+ context = new LdapContextImpl(client, env, "cn=test");
+
+ context.rename("cn=what,o=harmony", "o=apache");
+
+ op = (ModifyDNOp) client.getRequest();
+ assertEquals("cn=what,o=harmony,cn=test", op.getEntry());
+ assertEquals("o=apache", op.getNewrdn());
+ assertEquals("cn=test", op.getNewSuperior());
+ assertEquals(false, op.isDeleteoldrdn());
+
+ try {
+ context.rename(null, "cn=hello");
+ fail("should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ context.rename("cn=hello", null);
+ fail("should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void test_destroySubcontext() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "cn=test");
+ context.destroySubcontext("cn=bad");
+
+ DeleteOp op = (DeleteOp) client.getRequest();
+ assertEquals("cn=bad,cn=test", op.getDn());
+
+ try {
+ String name = null;
+ context.destroySubcontext(name);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void test_setRequestControls() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+ env.put(Context.REFERRAL, "follow");
+ context = new LdapContextImpl(client, env, "cn=test");
+
+ context.setRequestControls(null);
+ assertNull(context.getRequestControls());
+
+ Control[] controls = new Control[] { new BasicControl("0"),
+ new BasicControl("1"), new BasicControl("2"),
+ new BasicControl("3") };
+
+ context.setRequestControls(controls);
+
+ Control[] actual = context.getRequestControls();
+
+ assertEquals(controls.length, actual.length);
+ assertNotSame(controls, actual);
+
+ // Context.REFERRAL is 'ignore' add ManageDsaIT Control
+ env.put(Context.REFERRAL, "ignore");
+ context = new LdapContextImpl(client, env, "cn=test");
+ context.setRequestControls(null);
+ actual = context.getRequestControls();
+ assertEquals(1, actual.length);
+ assertEquals("2.16.840.1.113730.3.4.2", actual[0].getID());
+ assertNull(actual[0].getEncodedValue());
+ assertFalse(actual[0].isCritical());
+
+ context.setRequestControls(controls);
+ actual = context.getRequestControls();
+ assertEquals(controls.length + 1, actual.length);
+
+ // Context.REFERRAL is 'ignore', add ManageDsaIT Control
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "cn=test");
+ context.setRequestControls(null);
+ actual = context.getRequestControls();
+ assertEquals(1, actual.length);
+ assertEquals("2.16.840.1.113730.3.4.2", actual[0].getID());
+ assertNull(actual[0].getEncodedValue());
+ assertFalse(actual[0].isCritical());
+
+ context.setRequestControls(controls);
+ actual = context.getRequestControls();
+ assertEquals(controls.length + 1, actual.length);
+ }
+
+ public void test_search_LAttribute() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "cn=test");
+
+ Attributes attrs = new BasicAttributes();
+ attrs.put("cn", "hello");
+ Attribute attr = new BasicAttribute("o");
+ attr.add("harmony");
+ attr.add("apache");
+ attrs.put(attr);
+
+ context.search("cn=hello", attrs);
+
+ SearchOp op = (SearchOp) client.getRequest();
+ assertEquals("cn=hello,cn=test", op.getBaseObject());
+ SearchControls controls = op.getControls();
+ assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
+ assertEquals(0, controls.getCountLimit());
+ assertEquals(false, controls.getDerefLinkFlag());
+ assertEquals(false, controls.getReturningObjFlag());
+ assertEquals(null, controls.getReturningAttributes());
+
+ Filter filter = op.getFilter();
+ assertEquals(Filter.AND_FILTER, filter.getType());
+ List<Filter> children = filter.getChildren();
+
+ for (Filter f : children) {
+ assertEquals(Filter.EQUALITY_MATCH_FILTER, f.getType());
+ AttributeTypeAndValuePair pair = (AttributeTypeAndValuePair) f
+ .getValue();
+ if (pair.getType().equals("cn")) {
+ assertEquals("hello", pair.getValue());
+ } else {
+ assertEquals("o", pair.getType());
+ assertTrue(pair.getValue().equals("harmony")
+ || pair.getValue().equals("apache"));
+ }
+ }
+
+ String[] rtAttributes = new String[] { "cn", "o" };
+ context.search("cn=hello", attrs, rtAttributes);
+ op = (SearchOp) client.getRequest();
+ assertEquals("cn=hello,cn=test", op.getBaseObject());
+ controls = op.getControls();
+ String[] actual = controls.getReturningAttributes();
+
+ for (String attribute : rtAttributes) {
+ boolean found = false;
+ for (String s : actual) {
+ if (s.equals(attribute)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ fail("Attribute " + attribute + " not found.");
+ }
+ }
+ }
+
+ public void test_search_with_filter() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+ context = new LdapContextImpl(client, new Hashtable<Object, Object>(),
+ "cn=test");
+ SearchControls controls = new SearchControls();
+ controls.setCountLimit(100);
+ controls.setDerefLinkFlag(true);
+ controls.setReturningObjFlag(true);
+ controls.setTimeLimit(5);
+
+ context.search("test=search", "(objectClass=*)", controls);
+
+ SearchOp op = (SearchOp) client.getRequest();
+ assertEquals("test=search,cn=test", op.getBaseObject());
+ Filter filter = op.getFilter();
+ assertEquals(Filter.PRESENT_FILTER, filter.getType());
+ assertEquals("objectClass", filter.getValue());
+ assertEquals(controls.getCountLimit(), op.getControls().getCountLimit());
+ assertEquals(controls.getDerefLinkFlag(), op.getControls()
+ .getDerefLinkFlag());
+ assertEquals(controls.getReturningObjFlag(), op.getControls()
+ .getReturningObjFlag());
+ assertEquals(controls.getSearchScope(), op.getControls()
+ .getSearchScope());
+ assertEquals(controls.getTimeLimit(), op.getControls().getTimeLimit());
+
+ try {
+ context.search("test=search", "objectClass=*", controls);
+ fail("Should throw InvalidSearchFilterException");
+ } catch (InvalidSearchFilterException e) {
+ // expected
+ }
+
+ context.search("test=search", "(objectClass=*)", null);
+ op = (SearchOp) client.getRequest();
+ assertEquals(0, op.getControls().getCountLimit());
+ assertEquals(false, op.getControls().getDerefLinkFlag());
+ assertEquals(false, op.getControls().getReturningObjFlag());
+ assertEquals(SearchControls.ONELEVEL_SCOPE, op.getControls()
+ .getSearchScope());
+ assertEquals(0, op.getControls().getTimeLimit());
+ assertNull(controls.getReturningAttributes());
+ }
+
+ public void test_search_invalid_properties() throws Exception {
+ MockLdapClient client = new MockLdapClient();
+
+ Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+ env.put("java.naming.ldap.derefAliases", "error");
+ context = new LdapContextImpl(client, env, "cn=test");
+ try {
+ context.search("", null);
+ fail("Should throws IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ env = new Hashtable<Object, Object>();
+ env.put("java.naming.ldap.typesOnly", "error");
+ context = new LdapContextImpl(client, env, "cn=test");
+ try {
+ context.getAttributes("", null);
+ fail("Should throws IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
}
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapMessageTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapMessageTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapMessageTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/LdapMessageTest.java Tue Nov 20 06:42:33 2007
@@ -72,6 +72,14 @@
}
+ public void test_constructor() {
+ LdapMessage message = new LdapMessage(null);
+ assertNull(message.getControls());
+ assertNull(message.getResponseOp());
+ assertEquals(-1, message.getMessageId());
+ assertEquals(-1, message.getOperationIndex());
+ }
+
public void test_encodeValues_$LObject() {
LdapMessage message = new LdapMessage(
LdapASN1Constant.OP_ABANDON_REQUEST, new MockAbandonRequest(1),
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ModifyOpTest.java Tue Nov 20 06:42:33 2007
@@ -31,13 +31,13 @@
ASN1TestUtils.checkEncode(op, LdapASN1Constant.ModifyRequest);
- LdapAttribute attr = new LdapAttribute("attr1");
+ LdapAttribute attr = new LdapAttribute("attr1", null);
attr.add("value1");
attr.add("value2");
op.addModification(DirContext.ADD_ATTRIBUTE, attr);
- attr = new LdapAttribute("attr2");
+ attr = new LdapAttribute("attr2", null);
op.addModification(DirContext.REMOVE_ATTRIBUTE, attr);
ASN1TestUtils.checkEncode(op, LdapASN1Constant.ModifyRequest);
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/SearchOpTest.java Tue Nov 20 06:42:33 2007
@@ -17,6 +17,8 @@
package org.apache.harmony.jndi.provider.ldap;
+import java.util.Collection;
+
import javax.naming.directory.SearchControls;
import junit.framework.TestCase;
@@ -31,7 +33,14 @@
Filter filter = new Filter(7);
filter.setValue(Utils.getBytes("objectClass"));
SearchOp op = new SearchOp("test", controls, filter);
-
- ASN1TestUtils.checkEncode(op.getRequest(), LdapASN1Constant.SearchRequest);
+
+ ASN1TestUtils.checkEncode(op.getRequest(),
+ LdapASN1Constant.SearchRequest);
+
+ Object[] encoded = new Object[8];
+ op.encodeValues(encoded);
+ // return attributes is null, encode to empty collection
+ assertNull(controls.getReturningAttributes());
+ assertEquals(((Collection) encoded[7]).size(), 0);
}
}
Copied: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ext/StartTlsResponseImplTest.java (from r596647, harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ext/StartTlsResponseImplTest.java)
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ext/StartTlsResponseImplTest.java?p2=harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ext/StartTlsResponseImplTest.java&p1=harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ext/StartTlsResponseImplTest.java&r1=596647&r2=596693&rev=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ext/StartTlsResponseImplTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/ext/StartTlsResponseImplTest.java Tue Nov 20 06:42:33 2007
@@ -27,6 +27,7 @@
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
@@ -285,6 +286,16 @@
@Override
public void setWantClientAuth(boolean want) {
+ throw new Error("should not be here");
+ }
+
+ @Override
+ public SSLParameters getSSLParameters() {
+ throw new Error("should not be here");
+ }
+
+ @Override
+ public void setSSLParameters(SSLParameters params) {
throw new Error("should not be here");
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParserTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParserTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParserTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/provider/ldap/parser/LdapUrlParserTest.java Tue Nov 20 06:42:33 2007
@@ -37,57 +37,85 @@
}
public void test_parseURL() throws Exception {
- parser = new LdapUrlParser("ldap://192.168.1.3:389");
+ parser = new LdapUrlParser("ldap://192.168.1.3:666");
parser.parseURL();
- assertNull(parser.getBaseObject());
+ // default dn is empty
+ assertEquals("", parser.getBaseObject());
+ assertFalse(parser.hasFilter());
assertNull(parser.getFilter());
+ assertFalse(parser.hasAttributes());
+ assertFalse(parser.hasScope());
+ assertFalse(parser.hasExtensions());
assertNull(parser.getControls());
assertEquals("192.168.1.3", parser.getHost());
- assertEquals(389, parser.getPort());
+ assertEquals(666, parser.getPort());
parser = new LdapUrlParser("ldap://192.168.1.3/o=University,c=US");
parser.parseURL();
assertEquals("o=University,c=US", parser.getBaseObject());
+ assertFalse(parser.hasFilter());
assertNull(parser.getFilter());
+ assertFalse(parser.hasAttributes());
+ assertFalse(parser.hasScope());
+ assertFalse(parser.hasExtensions());
assertNull(parser.getControls());
assertEquals("192.168.1.3", parser.getHost());
+ // default port is 389
+ assertEquals(389, parser.getPort());
parser = new LdapUrlParser(
- "ldap://192.168.1.3/o=University,c=US?postalAddress");
+ "ldaps://192.168.1.3/o=University,c=US?postalAddress");
parser.parseURL();
assertEquals("o=University,c=US", parser.getBaseObject());
assertEquals("192.168.1.3", parser.getHost());
assertNotNull(parser.getControls());
+ assertTrue(parser.hasAttributes());
+ assertFalse(parser.hasScope());
+ assertFalse(parser.hasExtensions());
controls = parser.getControls();
- assertEquals(SearchControls.OBJECT_SCOPE, controls.getSearchScope());
+ assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
assertEquals(1, controls.getReturningAttributes().length);
assertEquals("postalAddress", controls.getReturningAttributes()[0]);
assertNull(parser.getFilter());
-
+ // default ssl port is 636
+ assertEquals(636, parser.getPort());
+
+
parser = new LdapUrlParser(
"ldap://192.168.1.3/o=University,c=US?postalAddress,o");
parser.parseURL();
assertEquals("o=University,c=US", parser.getBaseObject());
assertEquals("192.168.1.3", parser.getHost());
+ assertTrue(parser.hasAttributes());
assertNotNull(parser.getControls());
+ assertFalse(parser.hasScope());
+ assertFalse(parser.hasExtensions());
controls = parser.getControls();
- assertEquals(SearchControls.OBJECT_SCOPE, controls.getSearchScope());
+ assertEquals(SearchControls.ONELEVEL_SCOPE, controls.getSearchScope());
assertEquals(2, controls.getReturningAttributes().length);
assertEquals("postalAddress", controls.getReturningAttributes()[0]);
assertEquals("o", controls.getReturningAttributes()[1]);
assertNull(parser.getFilter());
-
+ // default port is 389
+ assertEquals(389, parser.getPort());
+
parser = new LdapUrlParser("ldap:///o=University,c=US");
parser.parseURL();
assertEquals("o=University,c=US", parser.getBaseObject());
assertNull(parser.getFilter());
assertNull(parser.getControls());
- assertNull(parser.getHost());
+ // default host is 'localhost'
+ assertEquals("localhost", parser.getHost());
+ // default port is 389
+ assertEquals(389, parser.getPort());
parser = new LdapUrlParser("ldap://192.168.1.3/o=University,c=US??sub");
parser.parseURL();
assertEquals("o=University,c=US", parser.getBaseObject());
assertEquals("192.168.1.3", parser.getHost());
+ assertFalse(parser.hasAttributes());
+ assertTrue(parser.hasScope());
+ assertFalse(parser.hasExtensions());
assertNotNull(parser.getControls());
controls = parser.getControls();
assertEquals(SearchControls.SUBTREE_SCOPE, controls.getSearchScope());
@@ -107,8 +135,12 @@
assertEquals("c=US", parser.getBaseObject());
assertEquals("192.168.1.3", parser.getHost());
assertNotNull(parser.getControls());
+ assertTrue(parser.hasAttributes());
+ assertTrue(parser.hasScope());
+ assertFalse(parser.hasExtensions());
controls = parser.getControls();
assertEquals(SearchControls.SUBTREE_SCOPE, controls.getSearchScope());
+ assertTrue(parser.hasFilter());
assertNotNull(parser.getFilter());
parser = new LdapUrlParser(
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/.classpath
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/.classpath?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/.classpath (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/.classpath Tue Nov 20 06:42:33 2007
@@ -6,7 +6,9 @@
<classpathentry output="bin/test" kind="src" path="src/test/api/unix"/>
<classpathentry output="bin/main" kind="src" path="src/main/resources"/>
<classpathentry output="bin/test" kind="src" path="src/test/resources"/>
- <classpathentry output="bin/test" kind="src" path="src/test/impl"/>
+ <classpathentry output="bin/test" kind="src" path="src/test/impl/windows"/>
+ <classpathentry output="bin/test" kind="src" path="src/test/impl/common"/>
+ <classpathentry output="bin/test" kind="src" path="src/test/impl/unix"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<accessrules>
<accessrule kind="accessible" pattern="**/*"/>
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/build.xml?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/build.xml (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/build.xml Tue Nov 20 06:42:33 2007
@@ -28,6 +28,8 @@
<property name="hy.luni.src.test.api.java.platform"
value="${hy.luni.src.test.api}/${hy.os.family}" />
+ <property name="hy.luni.src.test.impl.java.platform"
+ value="${hy.luni.src.test.impl}/${hy.os.family}" />
<fileset id="classes" dir="${hy.build}">
<or>
<present targetdir="${hy.luni.src.main.java}" />
@@ -298,42 +300,53 @@
</jar>
</target>
- <target name="compile-tests" depends="copy-test-resources">
- <compile-tests description="JUnit Tests" destdir="${hy.luni.bin.test}">
+ <!-- compile both api tests and impl tests-->
+ <target name="compile-tests" depends="compile-tests-api, compile-tests-impl" />
+
+ <target name="compile-tests-api" depends="copy-test-resources">
+ <compile-tests description="JUnit API Tests" destdir="${hy.luni.bin.test}/api">
<javac-elements>
<src>
<pathelement location="${hy.luni.src.test.api}/common" />
<pathelement location="${hy.luni.src.test.api.java.platform}" />
- <pathelement location="${hy.luni.src.test}/impl" />
</src>
<include name="**/*.java" />
</javac-elements>
</compile-tests>
</target>
+ <target name="compile-tests-impl" depends="copy-test-resources">
+ <compile-tests description="JUnit Impl tests" destdir="${hy.luni.bin.test}/impl">
+ <javac-elements>
+ <src>
+ <pathelement location="${hy.luni.src.test.impl}/common" />
+ <pathelement location="${hy.luni.src.test.impl.java.platform}" />
+ </src>
+ <include name="**/*.java" />
+ </javac-elements>
+ </compile-tests>
+ </target>
+
<target name="prepare-exclude">
<prepare-exclude-list moduleName="luni" dir="./make"
result="${luni.exclude.file}"/>
</target>
- <target name="run-tests">
- <run-tests description="JUnit Tests">
+ <!-- run both api tests and impl tests -->
+ <target name="run-tests" depends="run-tests-api, run-tests-impl" />
+
+ <target name="run-tests-api">
+ <run-tests description="JUnit API Tests">
<junit-elements>
<classpath>
- <pathelement path="${hy.luni.bin.test}"/>
+ <pathelement path="${hy.luni.bin.test}/api"/>
<pathelement path="${hy.luni.src.test.resources}"/>
<pathelement path="../../build/tests"/>
<fileset dir="${hy.hdk}/build/test/">
<include name="*.jar" />
</fileset>
</classpath>
- <!-- Required by various tests that set security manager etc -->
- <jvmarg value="-Djava.security.policy=../../support/src/test/resources/config/testing.policy" />
-
- <!-- Required for running the java.net unit tests -->
- <jvmarg value="-Dtest.ini.file=../../support/src/test/resources/config/localhosttest.ini" />
-
-
+
<batchtest todir="${hy.tests.reports}" haltonfailure="no" >
<fileset dir="${hy.luni.src.test.api}/common">
<!-- if ${test.case} -->
@@ -348,7 +361,41 @@
<!-- unless ${test.case} -->
<include name="**/*Test.java" unless="test.case" />
<excludesfile name="${luni.exclude.file}" unless="test.case" />
+ </fileset>
+ </batchtest>
+
+ </junit-elements>
+ </run-tests>
+ <antcall target="touch-failures-file" />
+ <antcall target="touch-errors-file" />
+ </target>
+
+ <target name="run-tests-impl">
+ <run-tests description="JUnit Impl Tests">
+ <junit-elements>
+ <classpath>
+ <pathelement path="${hy.luni.bin.test}/impl"/>
+ <pathelement path="${hy.luni.src.test.resources}"/>
+ <pathelement path="../../build/tests"/>
+ <fileset dir="${hy.hdk}/build/test/">
+ <include name="*.jar" />
</fileset>
+ </classpath>
+ <batchtest todir="${hy.tests.reports}" haltonfailure="no" >
+ <fileset dir="${hy.luni.src.test.impl}/common">
+ <!-- if ${test.case} -->
+ <include name="${converted.tc}" if="test.case" />
+ <!-- unless ${test.case} -->
+ <include name="**/*Test.java" unless="test.case" />
+ <excludesfile name="${luni.exclude.file}" unless="test.case" />
+ </fileset>
+ <fileset dir="${hy.luni.src.test.impl.java.platform}">
+ <!-- if ${test.case} -->
+ <include name="${converted.tc}" if="test.case" />
+ <!-- unless ${test.case} -->
+ <include name="**/*Test.java" unless="test.case" />
+ <excludesfile name="${luni.exclude.file}" unless="test.case" />
+ </fileset>
</batchtest>
</junit-elements>
@@ -438,6 +485,12 @@
<jvmarg line="${hy.test.vmargs}" />
<!-- Used by Support_Exec.execJava() -->
<jvmarg value="-Dhy.test.vmargs=${hy.test.vmargs}" />
+
+ <!-- Required by various tests that set security manager etc -->
+ <jvmarg value="-Djava.security.policy=../../support/src/test/resources/config/testing.policy" />
+
+ <!-- Required for running the java.net unit tests -->
+ <jvmarg value="-Dtest.ini.file=../../support/src/test/resources/config/localhosttest.ini" />
<junit-elements />
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.common?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.common (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/exclude.common Tue Nov 20 06:42:33 2007
@@ -1,7 +1,2 @@
tests/api/java/net/URLClassLoaderTest.java
tests/api/java/net/ExcludedProxyTest.java
-tests/api/java/util/CurrencyTest.java
-tests/api/java/util/FormatterTest.java
-tests/api/java/util/GregorianCalendarTest.java
-tests/api/java/util/LocaleTest.java
-tests/api/java/util/ScannerTest.java
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/make/hyproperties.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/make/hyproperties.xml?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/make/hyproperties.xml (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/make/hyproperties.xml Tue Nov 20 06:42:33 2007
@@ -28,6 +28,7 @@
</main>
<test location="src/test">
<api location="src/test/api" />
+ <impl location="src/test/impl" />
<resources location="src/test/resources" />
</test>
<natives location="src/natives" />
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/BufferedReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/BufferedReader.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/BufferedReader.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/BufferedReader.java Tue Nov 20 06:42:33 2007
@@ -299,8 +299,10 @@
* Answers a <code>String</code> representing the next line of text
* available in this BufferedReader. A line is represented by 0 or more
* characters followed by <code>'\n'</code>, <code>'\r'</code>,
- * <code>'\r\n'</code> or end of stream. The <code>String</code> does
- * not include the newline sequence.
+ * <code>'\r\n'</code> or end of stream. The <code>String</code> does not
+ * include the newline sequence.
+ * In EBCDIC systems, a new line can also be represented by the
+ * <code>'\u0085'</code> (NEL) character.
*
* @return the contents of the line or null if no characters were read
* before end of stream.
@@ -320,7 +322,7 @@
}
for (int charPos = pos; charPos < count; charPos++) {
char ch = buf[charPos];
- if (ch > '\r') {
+ if ((ch > '\r') && (ch != '\u0085')) {
continue;
}
if (ch == '\n') {
@@ -335,6 +337,11 @@
pos++;
}
return res;
+ } else if (ch == '\u0085') {
+ /* Also handle the EBCDIC NEL character */
+ String res = new String(buf, pos, charPos - pos);
+ pos = charPos + 1;
+ return res;
}
}
@@ -359,7 +366,7 @@
}
for (int charPos = pos; charPos < count; charPos++) {
if (eol == '\0') {
- if ((buf[charPos] == '\n' || buf[charPos] == '\r')) {
+ if ((buf[charPos] == '\n' || buf[charPos] == '\r') || (buf[charPos] == '\u0085')) {
eol = buf[charPos];
}
} else if (eol == '\r' && (buf[charPos] == '\n')) {
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/reflect/Proxy.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/reflect/Proxy.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/reflect/Proxy.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/lang/reflect/Proxy.java Tue Nov 20 06:42:33 2007
@@ -166,6 +166,7 @@
}
} else {
newClass = ref.get();
+ assert newClass != null;
}
return newClass;
}
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/URLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/URLConnection.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/URLConnection.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/net/URLConnection.java Tue Nov 20 06:42:33 2007
@@ -516,7 +516,7 @@
if (date == null) {
return defaultValue;
}
- return Util.parseDate(date);
+ return java.util.Date.parse(date);
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Calendar.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Calendar.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Calendar.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Calendar.java Tue Nov 20 06:42:33 2007
@@ -156,13 +156,12 @@
* the locale
*/
protected Calendar(TimeZone timezone, Locale locale) {
- this(timezone);
- com.ibm.icu.util.Calendar icuCalendar = com.ibm.icu.util.Calendar
- .getInstance(com.ibm.icu.util.SimpleTimeZone
- .getTimeZone(timezone.getID()), locale);
- setFirstDayOfWeek(icuCalendar.getFirstDayOfWeek());
- setMinimalDaysInFirstWeek(icuCalendar.getMinimalDaysInFirstWeek());
- }
+ this(timezone);
+ ResourceBundle bundle = Locale.getBundle("Locale", locale); //$NON-NLS-1$
+ setFirstDayOfWeek(((Integer) bundle.getObject("First_Day")).intValue()); //$NON-NLS-1$
+ setMinimalDaysInFirstWeek(((Integer) bundle.getObject("Minimal_Days")) //$NON-NLS-1$
+ .intValue());
+ }
/**
* Adds the specified amount to a Calendar field.
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Currency.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Currency.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Currency.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Currency.java Tue Nov 20 06:42:33 2007
@@ -19,6 +19,8 @@
import java.io.Serializable;
+import org.apache.harmony.luni.util.Msg;
+
/**
* This class represents a currency as identified in the ISO 4217 currency
* codes.
@@ -31,6 +33,10 @@
private String currencyCode;
+ private static String currencyVars = "EURO, HK, PREEURO"; //$NON-NLS-1$
+
+ private transient int defaultFractionDigits;
+
/**
* @param currencyCode
*/
@@ -54,7 +60,20 @@
Currency currency = codesToCurrencies.get(currencyCode);
if (currency == null) {
+ ResourceBundle bundle = Locale.getBundle(
+ "ISO4CurrenciesToDigits", Locale.getDefault()); //$NON-NLS-1$
currency = new Currency(currencyCode);
+
+ String defaultFractionDigits = null;
+ try {
+ defaultFractionDigits = bundle.getString(currencyCode);
+ } catch (MissingResourceException e) {
+ throw new IllegalArgumentException(
+ org.apache.harmony.luni.util.Msg.getString(
+ "K0322", currencyCode)); //$NON-NLS-1$
+ }
+ currency.defaultFractionDigits = Integer
+ .parseInt(defaultFractionDigits);
codesToCurrencies.put(currencyCode, currency);
}
@@ -72,11 +91,21 @@
* if the locale's country is not a supported ISO 3166 Country
*/
public static Currency getInstance(Locale locale) {
- com.ibm.icu.util.Currency currency = com.ibm.icu.util.Currency.getInstance(locale);
- if(currency == null) {
- return null;
+ String country = locale.getCountry();
+ String variant = locale.getVariant();
+ if (!variant.equals("") && currencyVars.indexOf(variant) > -1) { //$NON-NLS-1$
+ country = country + "_" + variant; //$NON-NLS-1$
+ }
+
+ ResourceBundle bundle = Locale.getBundle(
+ "ISO4Currencies", Locale.getDefault()); //$NON-NLS-1$
+ String currencyCode = null;
+ try {
+ currencyCode = bundle.getString(country);
+ } catch (MissingResourceException e) {
+ throw new IllegalArgumentException(Msg.getString(
+ "K0323", locale.toString())); //$NON-NLS-1$
}
- String currencyCode = currency.getCurrencyCode();
if (currencyCode.equals("None")) { //$NON-NLS-1$
return null;
@@ -132,7 +161,35 @@
if (locale.getCountry().equals("")) { //$NON-NLS-1$
return currencyCode;
}
- return com.ibm.icu.util.Currency.getInstance(currencyCode).getSymbol(locale);
+
+ // check in the Locale bundle first, if the local has the same currency
+ ResourceBundle bundle = Locale.getBundle("Locale", locale); //$NON-NLS-1$
+ if (((String) bundle.getObject("IntCurrencySymbol")) //$NON-NLS-1$
+ .equals(currencyCode)) {
+ return (String) bundle.getObject("CurrencySymbol"); //$NON-NLS-1$
+ }
+
+ // search for a Currency bundle
+ bundle = null;
+ try {
+ bundle = Locale.getBundle("Currency", locale); //$NON-NLS-1$
+ } catch (MissingResourceException e) {
+ return currencyCode;
+ }
+
+ // is the bundle found for a different country? (for instance the
+ // default locale's currency bundle)
+ if (!bundle.getLocale().getCountry().equals(locale.getCountry())) {
+ return currencyCode;
+ }
+
+ // check if the currency bundle for this locale
+ // has an entry for this currency
+ String result = (String) bundle.handleGetObject(currencyCode);
+ if (result != null) {
+ return result;
+ }
+ return currencyCode;
}
/**
@@ -143,7 +200,7 @@
* @return the default number of fraction digits for this currency
*/
public int getDefaultFractionDigits() {
- return com.ibm.icu.util.Currency.getInstance(currencyCode).getDefaultFractionDigits();
+ return defaultFractionDigits;
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Date.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Date.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Date.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Date.java Tue Nov 20 06:42:33 2007
@@ -378,7 +378,7 @@
int commentLevel = 0;
int offset = 0, length = string.length(), state = 0;
int year = -1, month = -1, date = -1;
- int hour = -1, minute = -1, second = -1, zoneOffset = 0;
+ int hour = -1, minute = -1, second = -1, zoneOffset = 0, minutesOffset =0;
boolean zone = false;
final int PAD = 0, LETTERS = 1, NUMBERS = 2;
StringBuffer buffer = new StringBuffer();
@@ -416,6 +416,14 @@
if (sign == '+' || sign == '-') {
if (zoneOffset == 0) {
zone = true;
+ if (next == ':') {
+ minutesOffset = sign == '-' ? -Integer
+ .parseInt(string.substring(offset,
+ offset + 2)) : Integer
+ .parseInt(string.substring(offset,
+ offset + 2));
+ offset += 2;
+ }
zoneOffset = sign == '-' ? -digit : digit;
sign = 0;
} else {
@@ -531,6 +539,7 @@
} else if (year < 100) {
year += 1900;
}
+ minute -= minutesOffset;
if (zone) {
if (zoneOffset >= 24 || zoneOffset <= -24) {
hour -= zoneOffset / 100;
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Locale.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Locale.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Locale.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Locale.java Tue Nov 20 06:42:33 2007
@@ -24,12 +24,14 @@
import java.io.ObjectStreamField;
import java.io.Serializable;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import org.apache.harmony.luni.internal.locale.Country;
+import org.apache.harmony.luni.internal.locale.Language;
import org.apache.harmony.luni.util.PriviAction;
-
-import com.ibm.icu.util.ULocale;
+import org.apache.harmony.luni.util.Util;
/**
* Locale represents a language/country/variant combination. It is an identifier
@@ -44,6 +46,8 @@
private static final long serialVersionUID = 9149081749638150636L;
+ private static volatile Locale[] availableLocales;
+
// Initialize a default which is used during static
// initialization of the default for the platform.
private static Locale defaultLocale = new Locale();
@@ -176,8 +180,6 @@
private transient String languageCode;
private transient String variantCode;
- private transient ULocale uLocale;
-
/**
* Constructs a default which is used during static initialization of the
* default for the platform.
@@ -222,14 +224,7 @@
if (language == null || country == null || variant == null) {
throw new NullPointerException();
}
- if(language.length() == 0 && country.length() == 0){
- languageCode = "";
- countryCode = "";
- variantCode = variant;
- return;
- }
- this.uLocale = new ULocale(language, country, variant);
- languageCode = uLocale.getLanguage();
+ languageCode = Util.toASCIILowerCase(language);
// Map new language codes to the obsolete language
// codes so the correct resource bundles will be used.
if (languageCode.equals("he")) {//$NON-NLS-1$
@@ -241,9 +236,9 @@
}
// countryCode is defined in ASCII character set
- countryCode = uLocale.getCountry();
+ countryCode = Util.toASCIIUpperCase(country);
- variantCode = uLocale.getVariant();
+ variantCode = variant;
}
/**
@@ -378,12 +373,15 @@
* @return an array of Locale
*/
public static Locale[] getAvailableLocales() {
- ULocale[] ulocales = ULocale.getAvailableLocales();
- Locale[] locales = new Locale[ulocales.length];
- for (int i = 0; i < locales.length; i++) {
- locales[i] = ulocales[i].toLocale();
+ if (availableLocales == null) {
+ availableLocales = AccessController
+ .doPrivileged(new PrivilegedAction<Locale[]>() {
+ public Locale[] run() {
+ return find("org/apache/harmony/luni/internal/locale/Locale_"); //$NON-NLS-1$
+ }
+ });
}
- return locales;
+ return availableLocales.clone();
}
/**
@@ -425,7 +423,24 @@
* @return a country name
*/
public String getDisplayCountry(Locale locale) {
- return ULocale.forLocale(this).getDisplayCountry(ULocale.forLocale(locale));
+ if (countryCode.length() == 0) {
+ return countryCode;
+ }
+ try {
+ // First try the specified locale
+ ResourceBundle bundle = getBundle("Country", locale); //$NON-NLS-1$
+ String result = (String) bundle.handleGetObject(countryCode);
+ if (result != null) {
+ return result;
+ }
+ // Now use the default locale
+ if (locale != Locale.getDefault()) {
+ bundle = getBundle("Country", Locale.getDefault()); //$NON-NLS-1$
+ }
+ return bundle.getString(countryCode);
+ } catch (MissingResourceException e) {
+ return countryCode;
+ }
}
/**
@@ -449,7 +464,24 @@
* @return a language name
*/
public String getDisplayLanguage(Locale locale) {
- return ULocale.forLocale(this).getDisplayLanguage(ULocale.forLocale(locale));
+ if (languageCode.length() == 0) {
+ return languageCode;
+ }
+ try {
+ // First try the specified locale
+ ResourceBundle bundle = getBundle("Language", locale); //$NON-NLS-1$
+ String result = (String) bundle.handleGetObject(languageCode);
+ if (result != null) {
+ return result;
+ }
+ // Now use the default locale
+ if (locale != Locale.getDefault()) {
+ bundle = getBundle("Language", Locale.getDefault()); //$NON-NLS-1$
+ }
+ return bundle.getString(languageCode);
+ } catch (MissingResourceException e) {
+ return languageCode;
+ }
}
/**
@@ -520,7 +552,31 @@
* @return a variant name
*/
public String getDisplayVariant(Locale locale) {
- return ULocale.forLocale(this).getDisplayVariant(ULocale.forLocale(locale));
+ if (variantCode.length() == 0) {
+ return variantCode;
+ }
+ ResourceBundle bundle;
+ try {
+ bundle = getBundle("Variant", locale); //$NON-NLS-1$
+ } catch (MissingResourceException e) {
+ return variantCode.replace('_', ',');
+ }
+
+ StringBuffer result = new StringBuffer();
+ StringTokenizer tokens = new StringTokenizer(variantCode, "_"); //$NON-NLS-1$
+ while (tokens.hasMoreTokens()) {
+ String code, variant = tokens.nextToken();
+ try {
+ code = bundle.getString(variant);
+ } catch (MissingResourceException e) {
+ code = variant;
+ }
+ result.append(code);
+ if (tokens.hasMoreTokens()) {
+ result.append(',');
+ }
+ }
+ return result.toString();
}
/**
@@ -533,7 +589,11 @@
* when there is no matching three letter ISO country code
*/
public String getISO3Country() throws MissingResourceException {
- return ULocale.forLocale(this).getISO3Country();
+ if (countryCode.length() == 0) {
+ return ""; //$NON-NLS-1$
+ }
+ ResourceBundle bundle = getBundle("ISO3Countries", this); //$NON-NLS-1$
+ return bundle.getString(countryCode);
}
/**
@@ -546,7 +606,11 @@
* when there is no matching three letter ISO language code
*/
public String getISO3Language() throws MissingResourceException {
- return ULocale.forLocale(this).getISO3Language();
+ if (languageCode.length() == 0) {
+ return ""; //$NON-NLS-1$
+ }
+ ResourceBundle bundle = getBundle("ISO3Languages", this); //$NON-NLS-1$
+ return bundle.getString(languageCode);
}
/**
@@ -556,7 +620,18 @@
* @return an array of String
*/
public static String[] getISOCountries() {
- return ULocale.getISOCountries();
+ ListResourceBundle bundle = new Country();
+
+ // To initialize the table
+ Enumeration<String> keys = bundle.getKeys();
+ int size = bundle.table.size();
+ String[] result = new String[size];
+ int index = 0;
+ while (keys.hasMoreElements()) {
+ String element = keys.nextElement();
+ result[index++] = element;
+ }
+ return result;
}
/**
@@ -566,7 +641,14 @@
* @return an array of String
*/
public static String[] getISOLanguages() {
- return ULocale.getISOLanguages();
+ ListResourceBundle bundle = new Language();
+ Enumeration<String> keys = bundle.getKeys(); // to initialize the table
+ String[] result = new String[bundle.table.size()];
+ int index = 0;
+ while (keys.hasMoreElements()) {
+ result[index++] = keys.nextElement();
+ }
+ return result;
}
/**
@@ -645,6 +727,15 @@
result.append(variantCode);
}
return result.toString();
+ }
+
+ static ResourceBundle getBundle(final String clName, final Locale locale) {
+ return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
+ public ResourceBundle run() {
+ return ResourceBundle.getBundle("org.apache.harmony.luni.internal.locale." //$NON-NLS-1$
+ + clName, locale);
+ }
+ });
}
private static final ObjectStreamField[] serialPersistentFields = {
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TimeZone.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TimeZone.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TimeZone.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TimeZone.java Tue Nov 20 06:42:33 2007
@@ -20,7 +20,6 @@
import java.io.Serializable;
import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.text.DateFormatSymbols;
import org.apache.harmony.luni.util.PriviAction;
@@ -222,8 +221,9 @@
String[][] zones = data.getZoneStrings();
for (int i = 0; i < zones.length; i++) {
if (id.equals(zones[i][0])) {
- return style == SHORT ? zones[i][useDaylight ? 4 : 2]
+ String res = style == SHORT ? zones[i][useDaylight ? 4 : 2]
: zones[i][useDaylight ? 3 : 1];
+ return res == null ? "" : res;
}
}
int offset = getRawOffset();
@@ -446,27 +446,8 @@
*/
public static synchronized void setDefault(TimeZone timezone) {
if (timezone != null) {
- final com.ibm.icu.util.TimeZone icuTZ = com.ibm.icu.util.TimeZone
- .getTimeZone(timezone.getID());
-
- AccessController
- .doPrivileged(new PrivilegedAction<java.lang.reflect.Field>() {
- public java.lang.reflect.Field run() {
- java.lang.reflect.Field field = null;
- try {
- field = com.ibm.icu.util.TimeZone.class
- .getDeclaredField("defaultZone");
- field.setAccessible(true);
- field.set("defaultZone", icuTZ);
- } catch (Exception e) {
- return null;
- }
- return field;
- }
- });
-
- Default = timezone;
- return;
+ Default = timezone;
+ return;
}
String zone = AccessController.doPrivileged(new PriviAction<String>(
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/fltparse.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/fltparse.c?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/fltparse.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/fltparse.c Tue Nov 20 06:42:33 2007
@@ -22,7 +22,7 @@
#include "harmonyglob.h"
#include "exceptions.h"
-#if defined(LINUX) || defined(ZOS)
+#if defined(LINUX) || defined(FREEBSD) || defined(ZOS)
#define USE_LL
#endif
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c Tue Nov 20 06:42:33 2007
@@ -23,7 +23,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
-#if defined(FREEBSD) || defined(ZOS)
+#if defined(FREEBSD) || defined(AIX) || defined(ZOS)
#include <sys/types.h>
#include <sys/socket.h>
#else
@@ -244,6 +244,19 @@
if(hysocketP == NULL)
return -1;
socket = hysocketP->sock;
+#if defined(AIX) || defined(ZOS)
+ {
+ struct sf_parms parms;
+ parms.file_descriptor = (int)fd;
+ parms.file_offset = (off64_t)offset;
+ parms.file_bytes = count;
+ parms.header_data = 0;
+ parms.header_length = 0;
+ parms.trailer_data = 0;
+ parms.trailer_length = 0;
+ return send_file(&socket, &parms, 0);
+ }
+#else
/* Value of offset is checked in jint scope (checked in java layer)
The conversion here is to guarantee no value lost when converting offset to off_t
*/
@@ -252,5 +265,6 @@
return sendfile(socket,(int)fd,(off_t *)&off,(size_t)count);
#else
return sendfile(fd, socket, off, (size_t)count, NULL, NULL, 0);
+#endif
#endif
}
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/procimpl.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/procimpl.c?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/procimpl.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/unix/procimpl.c Tue Nov 20 06:42:33 2007
@@ -39,6 +39,14 @@
void
sleepFor (unsigned int nanoseconds)
{
+
+#if defined(AIX) || defined(ZOS)
+/* These platforms don't have nanosleep(). */
+
+ unsigned int microseconds = (nanoseconds+999) / 1000;
+ usleep(microseconds);
+
+#else /* other unix platforms */
struct timespec delay, remDelay;
delay.tv_sec = 0;
delay.tv_nsec = nanoseconds;
@@ -54,6 +62,7 @@
break; /* Oops the sleep didn't work ??? */
}
}
+#endif /* AIX or ZOS */
}
int
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/helpers.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/helpers.c?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/helpers.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/windows/helpers.c Tue Nov 20 06:42:33 2007
@@ -562,15 +562,81 @@
return getPlatformAttribute (env, path, FILE_ATTRIBUTE_READONLY);
}
+void
+convert_path_to_unicode(JNIEnv * env,const char *path,
+ wchar_t **pathW)
+{
+PORT_ACCESS_FROM_ENV (env);
+ int len = strlen(path);
+ int wlen;
+ char *canonicalpath;
+ int srcArrayCount=0;
+ int destArrayCount=0;
+ int slashCount=0; //record how many slashes it met.
+ int dotsCount=0; //record how many dots following a separator.
+ int *slashStack; //record position of every separator.
+ slashStack = jclmem_allocate_memory (env, len*sizeof(int));
+ canonicalpath = jclmem_allocate_memory (env, len+5);
+
+ strcpy(canonicalpath,"\\\\?\\");
+
+ for(srcArrayCount=0,destArrayCount=4;srcArrayCount<len;srcArrayCount++){
+ // the input path of this method has been parsed to absolute path already.
+ if(path[srcArrayCount]=='.'){
+ // count the dots following last separator.
+ if(dotsCount>0 || path[srcArrayCount-1]=='\\'){
+ dotsCount++;
+ continue;
+ }
+ }
+ // deal with the dots when we meet next separator.
+ if(path[srcArrayCount]=='\\'){
+ if(dotsCount == 1){
+ dotsCount = 0;
+ continue;
+ }else if (dotsCount > 1){
+ if(slashCount-2<0){
+ slashCount=2;
+ }
+ destArrayCount=slashStack[slashCount-2];
+ dotsCount = 0;
+ slashCount--;
+ }else{
+ while(canonicalpath[destArrayCount-1] == '.'){
+ destArrayCount--;
+ }
+ slashStack[slashCount++]=destArrayCount;
+ }
+ }
+ // for normal character.
+ while(dotsCount >0){
+ canonicalpath[destArrayCount++]='.';
+ dotsCount--;
+ }
+ canonicalpath[destArrayCount++]=path[srcArrayCount];
+ }
+ while(canonicalpath[destArrayCount-1] == '.'){
+ destArrayCount--;
+ }
+ canonicalpath[destArrayCount]='\0';
+ wlen = MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, 0);
+ *pathW = jclmem_allocate_memory (env, wlen*sizeof(wchar_t));
+ MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, wlen);
+ jclmem_free_memory (env, canonicalpath);
+ jclmem_free_memory (env, slashStack);
+}
+
/**
* Answer 1 if the path is write-only, 0 otherwise even in fail cases.
*/
I_32
getPlatformIsWriteOnly (JNIEnv * env, char *path)
{
- HANDLE fHandle = CreateFile(path, GENERIC_READ, FILE_SHARE_READ,
- NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ HANDLE fHandle;
+ wchar_t *pathW;
+ convert_path_to_unicode(env,path,&pathW);
+ fHandle = CreateFileW(pathW, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (fHandle == INVALID_HANDLE_VALUE) {
return 1;
}
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/JarURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/JarURLConnectionTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/JarURLConnectionTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/net/JarURLConnectionTest.java Tue Nov 20 06:42:33 2007
@@ -41,7 +41,7 @@
URLConnection uc;
- private static final URL BASE = JarURLConnectionTest.class.getClassLoader().getResource(JarURLConnectionTest.class.getPackage().getName().replace('.', File.separatorChar));
+ private static final URL BASE = JarURLConnectionTest.class.getClassLoader().getResource(".."+File.separatorChar+JarURLConnectionTest.class.getPackage().getName().replace('.', File.separatorChar));
/**
* @tests java.net.JarURLConnection#getAttributes()
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/DateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/DateTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/DateTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/tests/api/java/util/DateTest.java Tue Nov 20 06:42:33 2007
@@ -436,13 +436,12 @@
TimeZone tz = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("EST"));
try {
- Date d1 = new Date(0);
- assertTrue("Returned incorrect string: " + d1, d1.toString()
- .startsWith("Wed Dec 31 19:00:00")
- && d1.toString().endsWith("1969"));
- } finally {
- TimeZone.setDefault(tz);
- }
+ Date d1 = new Date(0);
+ assertTrue("Returned incorrect string: " + d1, d1.toString()
+ .equals("Wed Dec 31 19:00:00 EST 1969"));
+ } finally {
+ TimeZone.setDefault(tz);
+ }
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayout.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayout.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayout.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeLayout.java Tue Nov 20 06:42:33 2007
@@ -242,6 +242,9 @@
}
public int numBackwardsCallables() {
+ if(layout == "*") {
+ return 1; // TODO: complicated attributes (shouldn't be *'s at all...)
+ }
int num = 0;
String[] split = layout.split("\\(");
if(split.length > 0) {