directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r165407 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/OIDTest.java
Date Sat, 30 Apr 2005 13:02:39 GMT
Author: elecharny
Date: Sat Apr 30 06:02:39 2005
New Revision: 165407

URL: http://svn.apache.org/viewcvs?rev=165407&view=rev
Log:
Added a test case for OID.

Added:
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/OIDTest.java

Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/OIDTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/OIDTest.java?rev=165407&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/OIDTest.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/OIDTest.java
Sat Apr 30 06:02:39 2005
@@ -0,0 +1,218 @@
+/*
+ *   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.primitives;
+
+import org.apache.asn1.DecoderException;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class OIDTest extends TestCase {
+    
+    /**
+     * Test a null OID
+     */
+    public void testOidNull()
+    {
+        OID oid = new OID();
+        
+        try 
+        {
+            oid.setOID(null);
+            Assert.fail("Should not reach this point ...");
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+        }
+    }
+
+    /**
+     * Test an empty OID
+     */
+    public void testOidEmpty()
+    {
+        OID oid = new OID();
+        
+        try 
+        {
+            oid.setOID(new byte[]{});
+            Assert.fail("Should not reach this point ...");
+        }
+        catch (DecoderException de)
+        {
+            Assert.assertTrue(true);
+        }
+    }
+
+    /**
+     * Test itu-t OID tree
+     */
+    public void testOidItuT()
+    {
+        OID oid = new OID();
+        
+        try 
+        {
+            // itu-t(0), recommendation(0), series a-z (0..26) 
+            for ( int i = 1 ; i < 27 ; i ++ ) 
+            {
+                oid.setOID(new byte[]{0x00, (byte)i});
+                Assert.assertEquals("0.0." + i, oid.getOID());
+            }
+
+            // itu-t(0), question(1) 
+            oid.setOID(new byte[]{0x01});
+            Assert.assertEquals("0.1", oid.getOID());
+
+            // itu-t(0), administration(2), country(202 .. 748)
+            for ( int i = 202 ; i < 748 ; i ++ ) 
+            {
+                oid.setOID(new byte[]{0x02, (byte)((i / 128) | 0x0080), (byte)(i % 128)});
+                Assert.assertEquals("0.2." + i, oid.getOID());
+            }
+
+            // itu-t(0), network-operator(3), operator(2023 .. 41363)
+            for ( int i = 2023 ; i < 41363 ; i ++ ) 
+            {
+                if (i < 128*128)
+                {
+                    oid.setOID(new byte[]{0x03, (byte)((i / 128) | 0x0080), (byte)(i % 128)});
+                    Assert.assertEquals("0.3." + i, oid.getOID());
+                }
+                else
+                {
+                    oid.setOID(new byte[]{0x03, (byte)((i / (128*128)) | 0x0080), (byte)(((i
/ 128) % 128 ) | 0x0080), (byte)(i % 128)});
+                    Assert.assertEquals("0.3." + i, oid.getOID());
+                    
+                }
+            }
+        }
+        catch (DecoderException de)
+        {
+            Assert.fail();
+        }
+    }
+
+    /**
+     * Test iso OID tree
+     */
+    public void testOidIso()
+    {
+        OID oid = new OID();
+        
+        try 
+        {
+            // iso(1), standard(0) 
+            oid.setOID(new byte[]{40 + 0});
+            Assert.assertEquals("1.0", oid.getOID());
+
+            // iso(1), registration-authority(1) 
+            oid.setOID(new byte[]{40 + 1});
+            Assert.assertEquals("1.1", oid.getOID());
+
+            // iso(1), member-body(2)
+            oid.setOID(new byte[]{40 + 2});
+            Assert.assertEquals("1.2", oid.getOID());
+
+            // iso(1), identified-organization(3) | org(3) | organization(3) 
+            oid.setOID(new byte[]{40 + 3});
+            Assert.assertEquals("1.3", oid.getOID());
+        }
+        catch (DecoderException de)
+        {
+            Assert.fail();
+        }
+    }
+
+    /**
+     * Test joint-iso-itu-t OID tree
+     */
+    public void testOidJointIsoItuT()
+    {
+        OID oid = new OID();
+        
+        try 
+        {
+            // joint-iso-itu-t(2), presentation(0) 
+            oid.setOID(new byte[]{80 + 0});
+            Assert.assertEquals("2.0", oid.getOID());
+
+            // joint-iso-itu-t(2), asn1(1)   
+            oid.setOID(new byte[]{80 + 1});
+            Assert.assertEquals("2.1", oid.getOID());
+
+            // joint-iso-itu-t(2), association-control(2)
+            oid.setOID(new byte[]{80 + 2});
+            Assert.assertEquals("2.2", oid.getOID());
+
+            // joint-iso-itu-t(2), reliable-transfer(3)
+            oid.setOID(new byte[]{80 + 3});
+            Assert.assertEquals("2.3", oid.getOID());
+
+            // ...
+            // joint-iso-itu-t(2), upu(40)
+            oid.setOID(new byte[]{80 + 40});
+            Assert.assertEquals("2.40", oid.getOID());
+        }
+        catch (DecoderException de)
+        {
+            Assert.fail();
+        }
+    }
+
+    /**
+     * Test Spnego OID
+     */
+    public void testOidSpnego()
+    {
+        OID oid = new OID();
+        
+        try 
+        {
+            oid.setOID(new byte[]{0x2b, 0x06, 0x01, 0x05, 0x05, 0x02});
+            
+            Assert.assertEquals("1.3.6.1.5.5.2", oid.getOID());
+        }
+        catch (DecoderException de)
+        {
+            Assert.fail();
+        }
+    }
+
+    /**
+     * Test Kerberos V5 OID
+     */
+    public void testOidKerberosV5()
+    {
+        OID oid = new OID();
+        
+        try 
+        {
+            oid.setOID(new byte[]{0x2a, (byte)0x86, 0x48, (byte)0x86, (byte)0xf7, 0x12, 0x01,
0x02, 0x02});
+            
+            Assert.assertEquals("1.2.840.113554.1.2.2", oid.getOID());
+        }
+        catch (DecoderException de)
+        {
+            Assert.fail();
+        }
+    }
+}



Mime
View raw message