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/09/24 16:37:05 UTC

svn commit: r291306 - /directory/asn1/trunk/ber-new/src/test/org/apache/asn1new/ber/tlv/ValueTest.java

Author: elecharny
Date: Sat Sep 24 07:37:02 2005
New Revision: 291306

URL: http://svn.apache.org/viewcvs?rev=291306&view=rev
Log:
Added a testCase to validate the Integer ASN.1 conversion

Modified:
    directory/asn1/trunk/ber-new/src/test/org/apache/asn1new/ber/tlv/ValueTest.java

Modified: directory/asn1/trunk/ber-new/src/test/org/apache/asn1new/ber/tlv/ValueTest.java
URL: http://svn.apache.org/viewcvs/directory/asn1/trunk/ber-new/src/test/org/apache/asn1new/ber/tlv/ValueTest.java?rev=291306&r1=291305&r2=291306&view=diff
==============================================================================
--- directory/asn1/trunk/ber-new/src/test/org/apache/asn1new/ber/tlv/ValueTest.java (original)
+++ directory/asn1/trunk/ber-new/src/test/org/apache/asn1new/ber/tlv/ValueTest.java Sat Sep 24 07:37:02 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.asn1new.ber.tlv;
 
+import java.math.BigInteger;
+
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
@@ -30,14 +32,61 @@
      */
     public void testValueGetNbBytes() 
     {
-        Assert.assertEquals(1, Value.getNbBytes(0));
-        Assert.assertEquals(1, Value.getNbBytes(1));
-        Assert.assertEquals(1, Value.getNbBytes(255));
-        Assert.assertEquals(2, Value.getNbBytes(256));
-        Assert.assertEquals(2, Value.getNbBytes(65535));
-        Assert.assertEquals(3, Value.getNbBytes(65536));
-        Assert.assertEquals(3, Value.getNbBytes(16777215));
-        Assert.assertEquals(4, Value.getNbBytes(16777216));
-        Assert.assertEquals(4, Value.getNbBytes(-1));
+        Assert.assertEquals(1, Value.getNbBytes( 0 ) );
+        Assert.assertEquals(1, Value.getNbBytes( 1 ) );
+        Assert.assertEquals(2, Value.getNbBytes( 255 ) );
+        Assert.assertEquals(2, Value.getNbBytes( 256 ) );
+        Assert.assertEquals(3, Value.getNbBytes( 65535 ) );
+        Assert.assertEquals(3, Value.getNbBytes( 65536 ) );
+        Assert.assertEquals(4, Value.getNbBytes( 16777215 ) );
+        Assert.assertEquals(4, Value.getNbBytes( 16777216 ) );
+        Assert.assertEquals(1, Value.getNbBytes( -1 ) );
+    }
+    
+    public void testEncodeInt2Bytes()
+    {
+        byte[] encoded = Value.getBytes( 128 );
+        
+        Assert.assertEquals( 0x00, encoded[0] );
+        Assert.assertEquals( (byte)0x80, encoded[1] );
+
+        encoded = Value.getBytes( -27066 );
+        
+        Assert.assertEquals( (byte)0x96, (byte)encoded[0] );
+        Assert.assertEquals( 0x46, encoded[1] );
+        
+    }
+
+    public void testEncodeInt3Bytes()
+    {
+
+        byte[] encoded = Value.getBytes( 32787 );
+        
+        Assert.assertEquals( 0x00, encoded[0] );
+        Assert.assertEquals( (byte)0x80, encoded[1] );
+        Assert.assertEquals( (byte)0x13, encoded[2] );
+    }
+    
+    public void testEncodeInt()
+    {
+        byte[] encoded = null;
+        int[] testedInt = new int[] { Integer.MIN_VALUE, -2147483647, -16777216, -16777215, -8388608, 
+                -8388607, -65536, -65535, -32768, -32767, -256, -255, -128, -127, -1, 0,
+                1, 127, 128, 255, 256, 32767, 32768, 65535, 65536, 8388607, 8388608, 16777215, 16777216,
+                Integer.MAX_VALUE};
+        
+        for ( int i = 0; i < testedInt.length; i++)
+        {
+            encoded = Value.getBytes( testedInt[i] );
+            
+            int value = new BigInteger( encoded ).intValue(); 
+            
+            Assert.assertEquals(testedInt[i], value );
+        }
+    }
+    
+    public void testEncodeInt5Bytes()
+    {
+
     }
 }