directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159207 - in directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives: ./ PrimitivesTest.java
Date Sun, 27 Mar 2005 23:08:47 GMT
Author: elecharny
Date: Sun Mar 27 15:08:47 2005
New Revision: 159207

URL: http://svn.apache.org/viewcvs?view=rev&rev=159207
Log:
added a Junit test on primitives

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

Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/PrimitivesTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/PrimitivesTest.java?view=auto&rev=159207
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/PrimitivesTest.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/primitives/PrimitivesTest.java
Sun Mar 27 15:08:47 2005
@@ -0,0 +1,129 @@
+/*
+ *   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 junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.DecoderException;
+import org.apache.asn1.ldap.codec.primitives.IntegerDecoder;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+
+/**
+ * Test the Primitives
+ *
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ */
+public class PrimitivesTest extends TestCase
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** DOCUMENT ME! */
+    private static Logger log = Logger.getLogger( PrimitivesTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * DOCUMENT ME!
+     */
+    public void testIntegerPrimitive()
+    {
+
+        try
+        {
+
+            Value value = new Value();
+
+            value.init(1);
+            value.setData( new byte[] { 0x00 } ); // res = 0
+            Assert.assertEquals( 0, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(1);
+            value.setData( new byte[] { 0x01 } ); // res = 1
+            Assert.assertEquals( 1, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(1);
+            value.setData( new byte[] { ( byte ) 0xFF } ); // res = 255
+            Assert.assertEquals( 255, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(2);
+            value.setData( new byte[] { 0x00, 0x01 } ); // res = 1
+            Assert.assertEquals( 1, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(2);
+            value.setData( new byte[] { 0x01, 0x00 } ); // res = 256
+            Assert.assertEquals( 256, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(2);
+            value.setData( new byte[] { 0x01, 0x01 } ); // res = 257
+            Assert.assertEquals( 257, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(2);
+            value.setData( new byte[] { 0x01, ( byte ) 0xFF } ); // res = 511
+            Assert.assertEquals( 511, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(2);
+            value.setData( new byte[] { 0x02, 0x00 } ); // res = 512
+            Assert.assertEquals( 512, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(2);
+            value.setData( new byte[] { ( byte ) 0xFF, ( byte ) 0xFF } ); // res = 65535
+            Assert.assertEquals( 65535, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(4);
+            value.setData(
+                new byte[] { ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF }
); // res = 2^32 - 1 = -1
+            Assert.assertEquals( -1, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(4);
+            value.setData(
+                new byte[] { ( byte ) 0x7F, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF }
); // res = 2^31 - 1 = MaxInt
+            Assert.assertEquals( Integer.MAX_VALUE, IntegerDecoder.parse( value ) );
+            value.reset();
+
+            value.init(4);
+            value.setData(
+                new byte[] { ( byte ) 0x80, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00 }
); // res = 2^31 = MinInt
+            Assert.assertEquals( Integer.MIN_VALUE, IntegerDecoder.parse( value ) );
+            value.reset();
+        }
+        catch ( DecoderException de )
+        {
+
+        }
+    }
+} // end class TLVTagDecoderTest



Mime
View raw message