Author: elecharny
Date: Sat Mar 19 09:13:55 2005
New Revision: 158257
URL: http://svn.apache.org/viewcvs?view=rev&rev=158257
Log:
(re)creating directory (was supposed to be a move, but with subclipse...)
Added:
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/DNUtilsTest.java
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapDNTest.java
Added:
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/DNUtilsTest.java
URL:
http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/DNUtilsTest.java?view=auto&rev=158257
==============================================================================
---
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/DNUtilsTest.java
(added)
+++
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/DNUtilsTest.java
Sat Mar 19 09:13:55 2005
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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 org.apache.asn1.ldap.codec.utils;
+
+import org.apache.asn1.ldap.codec.utils.DNUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+
+/**
+ * Test the class DNUtils
+ */
+public class DNUtilsTest extends TestCase
+{
+ //~ Methods
------------------------------------------------------------------------------------
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsFull()
+ {
+ // Full compare
+ Assert.assertEquals( 6, DNUtils.areEquals( "azerty".getBytes(), 0,
"azerty" ) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsDiff()
+ {
+ // First character is !=
+ Assert.assertEquals( -1, DNUtils.areEquals( "azerty".getBytes(), 0,
"Azerty" ) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsEmpty()
+ {
+ // Compare to an empty string
+ Assert.assertEquals( -1, DNUtils.areEquals( "azerty".getBytes(), 0, ""
) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsFirstCharDiff()
+ {
+ // First character is !=
+ Assert.assertEquals( -1, DNUtils.areEquals( "azerty".getBytes(), 0,
"Azerty" ) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsMiddleCharDiff()
+ {
+ // First character is !=
+ Assert.assertEquals( -1, DNUtils.areEquals( "azerty".getBytes(), 0,
"azeRty" ) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsLastCharDiff()
+ {
+ // First character is !=
+ Assert.assertEquals( -1, DNUtils.areEquals( "azerty".getBytes(), 0,
"azertY" ) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsCharByChar()
+ {
+ // Index must be incremented after each comparison
+ Assert.assertEquals( 1, DNUtils.areEquals( "azerty".getBytes(), 0, "a"
) );
+ Assert.assertEquals( 2, DNUtils.areEquals( "azerty".getBytes(), 1, "z"
) );
+ Assert.assertEquals( 3, DNUtils.areEquals( "azerty".getBytes(), 2, "e"
) );
+ Assert.assertEquals( 4, DNUtils.areEquals( "azerty".getBytes(), 3, "r"
) );
+ Assert.assertEquals( 5, DNUtils.areEquals( "azerty".getBytes(), 4, "t"
) );
+ Assert.assertEquals( 6, DNUtils.areEquals( "azerty".getBytes(), 5, "y"
) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsTooShort()
+ {
+ // length too short
+ Assert.assertEquals( -1, DNUtils.areEquals( "azerty".getBytes(), 0,
"azertyiop" ) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsTooShortMiddle()
+ {
+ // length too short
+ Assert.assertEquals( -1, DNUtils.areEquals( "azerty".getBytes(), 0,
"ertyiop" ) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsLastChar()
+ {
+ // last character
+ Assert.assertEquals( 6, DNUtils.areEquals( "azerty".getBytes(), 5, "y"
) );
+ }
+
+ /**
+ * Test the DNUtils AreEquals method
+ */
+ public void testAreEqualsMiddle()
+ {
+ // In the middle
+ Assert.assertEquals( 4, DNUtils.areEquals( "azerty".getBytes(), 2,
"er" ) );
+ }
+}
Added:
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapDNTest.java
URL:
http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapDNTest.java?view=auto&rev=158257
==============================================================================
---
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapDNTest.java
(added)
+++
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/utils/LdapDNTest.java
Sat Mar 19 09:13:55 2005
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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 org.apache.asn1.ldap.codec.utils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1.ldap.codec.DecoderException;
+import org.apache.asn1.ldap.codec.utils.LdapDN;
+
+
+/**
+ * Test the class DNUtils
+ */
+public class LdapDNTest extends TestCase
+{
+ /**
+ * Test a null DN
+ */
+ public void testLdapDNNull() throws DecoderException
+ {
+ Assert.assertEquals("", LdapDN.parseDN(null) );
+ }
+
+ /**
+ * test an empty DN
+ */
+ public void testLdapDNEmpty() throws DecoderException
+ {
+ Assert.assertEquals("", LdapDN.parseDN("".getBytes()) );
+ }
+
+ /**
+ * test an empty DN
+ */
+ public void testLdapDN() throws DecoderException
+ {
+ Assert.assertEquals("", LdapDN.parseDN("".getBytes()) );
+ }
+
+ /**
+ * test a simple DN : a = b
+ */
+ public void testLdapDNSimple() throws DecoderException
+ {
+ Assert.assertEquals("a = b", LdapDN.parseDN("a = b".getBytes()) );
+ }
+
+ /**
+ * test a composite DN : a = b, d = e
+ */
+ public void testLdapDNComposite() throws DecoderException
+ {
+ Assert.assertEquals("a = b, c = d", LdapDN.parseDN("a = b, c =
d".getBytes()) );
+ }
+
+ /**
+ * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a
= b
+ */
+ public void testLdapDNCompositeWithSpace() throws DecoderException
+ {
+ Assert.assertEquals("a=b, a =b, a= b, a = b, a = b",
LdapDN.parseDN("a=b, a =b, a= b, a = b, a = b".getBytes()) );
+ }
+
+ /**
+ * test a composite DN with differents separators : a=b;c=d,e=f
+ * It should return a=b,c=d,e=f (the ';' is replaced by a ',')
+ */
+ public void testLdapDNCompositeSepators() throws DecoderException
+ {
+ Assert.assertEquals("a=b,c=d,e=f",
LdapDN.parseDN("a=b;c=d,e=f".getBytes()) );
+ }
+
+ /**
+ * test a simple DN with differents separators : a = b + c = d
+ */
+ public void testLdapDNSimpleMultivaluedAttribute() throws DecoderException
+ {
+ Assert.assertEquals("a = b + c = d", LdapDN.parseDN("a = b + c =
d".getBytes()) );
+ }
+
+ /**
+ * test a composite DN with differents separators : a=b+c=d, e=f + g=h +
i=j
+ */
+ public void testLdapDNCompositeMultivaluedAttribute() throws
DecoderException
+ {
+ Assert.assertEquals("a=b+c=d, e=f + g=h + i=j",
LdapDN.parseDN("a=b+c=d, e=f + g=h + i=j".getBytes()) );
+ }
+
+ /**
+ * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
+ */
+ public void testLdapDNOidUpper() throws DecoderException
+ {
+ Assert.assertEquals("OID.12.34.56 = azerty",
LdapDN.parseDN("OID.12.34.56 = azerty".getBytes()) );
+ }
+
+ /**
+ * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
+ */
+ public void testLdapDNOidLower() throws DecoderException
+ {
+ Assert.assertEquals("oid.12.34.56 = azerty",
LdapDN.parseDN("oid.12.34.56 = azerty".getBytes()) );
+ }
+
+ /**
+ * test a simple DN with an oid attribut wiithout oid prefix : 12.34.56 =
azerty
+ */
+ public void testLdapDNOidWithoutPrefix() throws DecoderException
+ {
+ Assert.assertEquals("12.34.56 = azerty", LdapDN.parseDN("12.34.56 =
azerty".getBytes()) );
+ }
+
+ /**
+ * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56
= azerty; 7.8 = test
+ */
+ public void testLdapDNCompositeOidWithoutPrefix() throws DecoderException
+ {
+ Assert.assertEquals("12.34.56 = azerty, 7.8 = test",
LdapDN.parseDN("12.34.56 = azerty; 7.8 = test".getBytes()) );
+ }
+
+ /**
+ * test a simple DN with pair char attribute value : a =
\,\=\+\<\>\#\;\\\"\A0\00"
+ */
+ public void testLdapDNPairCharAttributeValue() throws DecoderException
+ {
+ Assert.assertEquals("a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00",
LdapDN.parseDN("a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00".getBytes()) );
+ }
+
+ /**
+ * test a simple DN with hexString attribute value : a = #0010A0AAFF
+ */
+ public void testLdapDNHexStringAttributeValue() throws DecoderException
+ {
+ Assert.assertEquals("a = #0010A0AAFF", LdapDN.parseDN("a =
#0010A0AAFF".getBytes()) );
+ }
+
+ /**
+ * test a simple DN with quoted attribute value : a = "quoted \"value"
+ */
+ public void testLdapDNQuotedAttributeValue() throws DecoderException
+ {
+ Assert.assertEquals("a = quoted \\\"value", LdapDN.parseDN("a = quoted
\\\"value".getBytes()) );
+ }
+}