You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/05/09 23:21:00 UTC

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

Author: elecharny
Date: Mon May  9 14:20:59 2005
New Revision: 169361

URL: http://svn.apache.org/viewcvs?rev=169361&view=rev
Log:
Added some more tests, especially those that check the new methods.

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

Modified: 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=169361&r1=169360&r2=169361&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/OIDTest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/OIDTest.java Mon May  9 14:20:59 2005
@@ -41,7 +41,7 @@
 
         try
         {
-            oid.setOID( null );
+            oid.setOID( ( byte[] ) null );
             Assert.fail( "Should not reach this point ..." );
         }
         catch ( DecoderException de )
@@ -84,19 +84,19 @@
             for ( int i = 1; i < 27; i++ )
             {
                 oid.setOID( new byte[] { 0x00, ( byte ) i } );
-                Assert.assertEquals( "0.0." + i, oid.getOID() );
+                Assert.assertEquals( "0.0." + i, oid.toString() );
             }
 
             // itu-t(0), question(1)
             oid.setOID( new byte[] { 0x01 } );
-            Assert.assertEquals( "0.1", oid.getOID() );
+            Assert.assertEquals( "0.1", oid.toString() );
 
             // 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() );
+                Assert.assertEquals( "0.2." + i, oid.toString() );
             }
 
             // itu-t(0), network-operator(3), operator(2023 .. 41363)
@@ -107,7 +107,7 @@
                 {
                     oid.setOID(
                         new byte[] { 0x03, ( byte ) ( ( i / 128 ) | 0x0080 ), ( byte ) ( i % 128 ) } );
-                    Assert.assertEquals( "0.3." + i, oid.getOID() );
+                    Assert.assertEquals( "0.3." + i, oid.toString() );
                 }
                 else
                 {
@@ -117,7 +117,7 @@
                             0x03, ( byte ) ( ( i / ( 128 * 128 ) ) | 0x0080 ),
                             ( byte ) ( ( ( i / 128 ) % 128 ) | 0x0080 ), ( byte ) ( i % 128 )
                         } );
-                    Assert.assertEquals( "0.3." + i, oid.getOID() );
+                    Assert.assertEquals( "0.3." + i, oid.toString() );
 
                 }
             }
@@ -141,19 +141,19 @@
 
             // iso(1), standard(0)
             oid.setOID( new byte[] { 40 + 0 } );
-            Assert.assertEquals( "1.0", oid.getOID() );
+            Assert.assertEquals( "1.0", oid.toString() );
 
             // iso(1), registration-authority(1)
             oid.setOID( new byte[] { 40 + 1 } );
-            Assert.assertEquals( "1.1", oid.getOID() );
+            Assert.assertEquals( "1.1", oid.toString() );
 
             // iso(1), member-body(2)
             oid.setOID( new byte[] { 40 + 2 } );
-            Assert.assertEquals( "1.2", oid.getOID() );
+            Assert.assertEquals( "1.2", oid.toString() );
 
             // iso(1), identified-organization(3) | org(3) | organization(3)
             oid.setOID( new byte[] { 40 + 3 } );
-            Assert.assertEquals( "1.3", oid.getOID() );
+            Assert.assertEquals( "1.3", oid.toString() );
         }
         catch ( DecoderException de )
         {
@@ -174,24 +174,29 @@
 
             // joint-iso-itu-t(2), presentation(0)
             oid.setOID( new byte[] { 80 + 0 } );
-            Assert.assertEquals( "2.0", oid.getOID() );
+            Assert.assertEquals( "2.0", oid.toString() );
 
             // joint-iso-itu-t(2), asn1(1)
             oid.setOID( new byte[] { 80 + 1 } );
-            Assert.assertEquals( "2.1", oid.getOID() );
+            Assert.assertEquals( "2.1", oid.toString() );
 
             // joint-iso-itu-t(2), association-control(2)
             oid.setOID( new byte[] { 80 + 2 } );
-            Assert.assertEquals( "2.2", oid.getOID() );
+            Assert.assertEquals( "2.2", oid.toString() );
 
             // joint-iso-itu-t(2), reliable-transfer(3)
             oid.setOID( new byte[] { 80 + 3 } );
-            Assert.assertEquals( "2.3", oid.getOID() );
+            Assert.assertEquals( "2.3", oid.toString() );
 
             // ...
             // joint-iso-itu-t(2), upu(40)
             oid.setOID( new byte[] { 80 + 40 } );
-            Assert.assertEquals( "2.40", oid.getOID() );
+            Assert.assertEquals( "2.40", oid.toString() );
+
+            // ...
+            // joint-iso-itu-t(2), xxx(100)
+            oid.setOID( new byte[] { ( byte ) ( 0x81 ), 0x34 } );
+            Assert.assertEquals( "2.100", oid.toString() );
         }
         catch ( DecoderException de )
         {
@@ -200,6 +205,137 @@
     }
 
     /**
+     * Test valid String OIDs
+     */
+    public void testOidStringGood()
+    {
+
+        OID oid = new OID();
+
+        try
+        {
+            oid.setOID( "0.0" );
+            Assert.assertEquals( "0.0", oid.toString() );
+
+            oid.setOID( "0.0.0.0.0" );
+            Assert.assertEquals( "0.0.0.0.0", oid.toString() );
+
+            oid.setOID( "0.1.2.3.4" );
+            Assert.assertEquals( "0.1.2.3.4", oid.toString() );
+
+            oid.setOID( "2.123456" );
+            Assert.assertEquals( "2.123456", oid.toString() );
+
+            oid.setOID( "1.2.840.113554.1.2.2" );
+            Assert.assertEquals( "1.2.840.113554.1.2.2", oid.toString() );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.fail();
+        }
+    }
+
+    /**
+     * Test invalid String OIDs
+     */
+    public void testOidStringBad()
+    {
+
+        OID oid = new OID();
+
+        try
+        {
+            oid.setOID( "0" );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0." );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "." );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0.1.2." );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "3.1" );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0..1" );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0..12" );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0.a.2" );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "0.123456" );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+        try
+        {
+            oid.setOID( "1.123456" );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+
+    }
+
+    /**
      * Test Spnego OID
      */
     public void testOidSpnego()
@@ -211,7 +347,7 @@
         {
             oid.setOID( new byte[] { 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02 } );
 
-            Assert.assertEquals( "1.3.6.1.5.5.2", oid.getOID() );
+            Assert.assertEquals( "1.3.6.1.5.5.2", oid.toString() );
         }
         catch ( DecoderException de )
         {
@@ -236,7 +372,43 @@
                     0x02
                 } );
 
-            Assert.assertEquals( "1.2.840.113554.1.2.2", oid.getOID() );
+            Assert.assertEquals( "1.2.840.113554.1.2.2", oid.toString() );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.fail();
+        }
+    }
+
+    /**
+     * Test OIDs bytes
+     */
+    public void testOidBytes()
+    {
+        OID oid = new OID();
+        OID oid2 = new OID();
+
+        try
+        {
+            oid.setOID( "0.0" );
+            oid2.setOID(oid.getOID());
+            Assert.assertEquals( oid.toString(), oid2.toString());
+
+            oid.setOID( "0.0.0.0.0" );
+            oid2.setOID(oid.getOID());
+            Assert.assertEquals( oid.toString(), oid2.toString());
+
+            oid.setOID( "0.1.2.3.4" );
+            oid2.setOID(oid.getOID());
+            Assert.assertEquals( oid.toString(), oid2.toString());
+
+            oid.setOID( "2.123456" );
+            oid2.setOID(oid.getOID());
+            Assert.assertEquals( oid.toString(), oid2.toString());
+
+            oid.setOID( "1.2.840.113554.1.2.2" );
+            oid2.setOID(oid.getOID());
+            Assert.assertEquals( oid.toString(), oid2.toString());
         }
         catch ( DecoderException de )
         {