directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r234224 - in /directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache: asn1/ asn1new/ asn1new/ber/ asn1new/ber/tlv/ asn1new/primitives/ asn1new/util/
Date Sun, 21 Aug 2005 15:00:20 GMT
Author: elecharny
Date: Sun Aug 21 08:00:13 2005
New Revision: 234224

URL: http://svn.apache.org/viewcvs?rev=234224&view=rev
Log:
renamed the ans1 directory to asn1new

Added:
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/ber/
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/ber/tlv/
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/ber/tlv/LengthTest.java
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/BitStringTest.java
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/OIDTest.java
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/PrimitivesTest.java
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java
Removed:
    directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1/

Added: directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/ber/tlv/LengthTest.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/ber/tlv/LengthTest.java?rev=234224&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/ber/tlv/LengthTest.java
(added)
+++ directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/ber/tlv/LengthTest.java
Sun Aug 21 08:00:13 2005
@@ -0,0 +1,64 @@
+/*
+ *   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.asn1new.ber.tlv;
+
+import java.util.Arrays;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * This class is used to test the Length class 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LengthTest extends TestCase {
+
+    /**
+     * Test the getNbBytes method
+     */
+    public void testLengthGetNbBytes() 
+    {
+        Assert.assertEquals(1, Length.getNbBytes(0));
+        Assert.assertEquals(1, Length.getNbBytes(1));
+        Assert.assertEquals(1, Length.getNbBytes(127));
+        Assert.assertEquals(2, Length.getNbBytes(128));
+        Assert.assertEquals(2, Length.getNbBytes(255));
+        Assert.assertEquals(3, Length.getNbBytes(256));
+        Assert.assertEquals(3, Length.getNbBytes(65535));
+        Assert.assertEquals(4, Length.getNbBytes(65536));
+        Assert.assertEquals(4, Length.getNbBytes(16777215));
+        Assert.assertEquals(5, Length.getNbBytes(16777216));
+        Assert.assertEquals(5, Length.getNbBytes(0xFFFFFFFF));
+    }
+
+    /**
+     * Test the getBytes method
+     */
+    public void testLengthGetBytes() 
+    {
+        assertTrue(Arrays.equals(new byte[]{0x01}, Length.getBytes(1)));
+        assertTrue(Arrays.equals(new byte[]{0x7F}, Length.getBytes(127)));
+        assertTrue(Arrays.equals(new byte[]{(byte)0x81, (byte)0x80}, Length.getBytes(128)));
+        assertTrue(Arrays.equals(new byte[]{(byte)0x81, (byte)0xFF}, Length.getBytes(255)));
+        assertTrue(Arrays.equals(new byte[]{(byte)0x82, 0x01, 0x00}, Length.getBytes(256)));
+        assertTrue(Arrays.equals(new byte[]{(byte)0x82, (byte)0xFF, (byte)0xFF}, Length.getBytes(65535)));
+        assertTrue(Arrays.equals(new byte[]{(byte)0x83, 0x01, 0x00, 0x00}, Length.getBytes(65536)));
+        assertTrue(Arrays.equals(new byte[]{(byte)0x83, (byte)0xFF, (byte)0xFF, (byte)0xFF},
Length.getBytes(16777215)));
+        assertTrue(Arrays.equals(new byte[]{(byte)0x84, 0x01, 0x00, 0x00, 0x00}, Length.getBytes(16777216)));
+        assertTrue(Arrays.equals(new byte[]{(byte)0x84, (byte)0xFF, (byte)0xFF, (byte)0xFF,
(byte)0xFF}, Length.getBytes(0xFFFFFFFF)));
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/BitStringTest.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/BitStringTest.java?rev=234224&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/BitStringTest.java
(added)
+++ directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/BitStringTest.java
Sun Aug 21 08:00:13 2005
@@ -0,0 +1,173 @@
+/*
+ *   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.asn1new.primitives;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1new.DecoderException;
+
+
+/**
+ * Test the Bit String primitive
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class BitStringTest extends TestCase
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Test a null BitString
+     */
+    public void testBitStringNull()
+    {
+
+        BitString bitString = new BitString();
+
+        bitString.setData( null );
+
+        try
+        {
+            bitString.getBit( 0 );
+            Assert.fail( "Should not reach this point ..." );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+    }
+
+    /**
+     * Test an empty BitString
+     */
+    public void testBitStringEmpty()
+    {
+
+        BitString bitString = new BitString();
+
+        bitString.setData( new byte[] {} );
+
+        try
+        {
+            bitString.getBit( 0 );
+            Assert.fail( "Should not reach this point ..." );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+    }
+
+    /**
+     * Test a single bit BitString BitString
+     */
+    public void testSingleBitBitString() throws DecoderException
+    {
+
+        BitString bitString = new BitString( 1 );
+
+        bitString.setData( new byte[] { 0x07, ( byte ) 0x80 } );
+
+        Assert.assertEquals( true, bitString.getBit( 0 ) );
+    }
+
+    /**
+     * Test a 32 bits BitString
+     */
+    public void test32BitsBitString() throws DecoderException
+    {
+
+        BitString bitString = new BitString( 32 );
+
+        bitString.setData(
+            new byte[] { 0x00, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF
} );
+
+        for ( int i = 0; i < 32; i++ )
+        {
+            Assert.assertEquals( true, bitString.getBit( i ) );
+        }
+    }
+
+    /**
+     * Test a 33 bits BitString
+     */
+    public void test33BitsBitString() throws DecoderException
+    {
+
+        BitString bitString = new BitString( 33 );
+
+        bitString.setData(
+            new byte[]
+            {
+                0x07, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte
) 0x80
+            } );
+
+        for ( int i = 0; i < 33; i++ )
+        {
+            Assert.assertEquals( true, bitString.getBit( i ) );
+        }
+
+        Assert.assertEquals( true, bitString.getBit( 32 ) );
+    }
+
+
+    /**
+     * Test all bits from 0 to 128 BitString
+     */
+    public void test0to128BitString() throws DecoderException
+    {
+
+        // bit number 14
+        BitString bitString14 = new BitString( 14 );
+
+        bitString14.setData( new byte[] { 0x02, ( byte ) 0xFF, ( byte ) 0xFC } );
+
+        for ( int i = 0; i < 14; i++ )
+        {
+            Assert.assertEquals( true, bitString14.getBit( i ) );
+        }
+
+        // bit number 31
+        BitString bitString31 = new BitString( 31 );
+
+        bitString31.setData(
+            new byte[] { 0x01, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFE
} );
+
+        for ( int i = 0; i < 31; i++ )
+        {
+            Assert.assertEquals( true, bitString31.getBit( i ) );
+        }
+
+        // bit number 128
+        BitString bitString128 = new BitString( 128 );
+
+        bitString128.setData(
+            new byte[]
+            {
+                0x00, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte
) 0xFF,
+                ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF,
+                ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF,
+                ( byte ) 0xFF
+            } );
+
+        for ( int i = 0; i < 128; i++ )
+        {
+            Assert.assertEquals( true, bitString128.getBit( i ) );
+        }
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/OIDTest.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/OIDTest.java?rev=234224&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/OIDTest.java
(added)
+++ directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/OIDTest.java
Sun Aug 21 08:00:13 2005
@@ -0,0 +1,418 @@
+/*
+ *   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.asn1new.primitives;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1new.DecoderException;
+
+
+/**
+ * Test the OID primitive
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class OIDTest extends TestCase
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Test a null OID
+     */
+    public void testOidNull()
+    {
+
+        OID oid = new OID();
+
+        try
+        {
+            oid.setOID( ( byte[] ) 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.toString() );
+            }
+
+            // itu-t(0), question(1)
+            oid.setOID( new byte[] { 0x01 } );
+            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.toString() );
+            }
+
+            // 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.toString() );
+                }
+                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.toString() );
+
+                }
+            }
+        }
+        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.toString() );
+
+            // iso(1), registration-authority(1)
+            oid.setOID( new byte[] { 40 + 1 } );
+            Assert.assertEquals( "1.1", oid.toString() );
+
+            // iso(1), member-body(2)
+            oid.setOID( new byte[] { 40 + 2 } );
+            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.toString() );
+        }
+        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.toString() );
+
+            // joint-iso-itu-t(2), asn1(1)
+            oid.setOID( new byte[] { 80 + 1 } );
+            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.toString() );
+
+            // joint-iso-itu-t(2), reliable-transfer(3)
+            oid.setOID( new byte[] { 80 + 3 } );
+            Assert.assertEquals( "2.3", oid.toString() );
+
+            // ...
+            // joint-iso-itu-t(2), upu(40)
+            oid.setOID( new byte[] { 80 + 40 } );
+            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 )
+        {
+            Assert.fail();
+        }
+    }
+
+    /**
+     * 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()
+    {
+
+        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.toString() );
+        }
+        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.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 )
+        {
+            Assert.fail();
+        }
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/PrimitivesTest.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/PrimitivesTest.java?rev=234224&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/PrimitivesTest.java
(added)
+++ directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/primitives/PrimitivesTest.java
Sun Aug 21 08:00:13 2005
@@ -0,0 +1,123 @@
+/*
+ *   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.asn1new.primitives;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.ber.tlv.Value;
+import org.apache.asn1new.util.IntegerDecoder;
+import org.apache.log4j.PropertyConfigurator;
+
+/**
+ * Test the Primitives
+ *
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PrimitivesTest extends TestCase
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Test the Integer Primitive
+     */
+    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

Added: directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java?rev=234224&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java
(added)
+++ directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/MutableStringTest.java
Sun Aug 21 08:00:13 2005
@@ -0,0 +1,55 @@
+/*
+ *   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.asn1new.util;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MutableStringTest extends TestCase {
+    public void testEmptyString()
+    {
+        String s = new MutableString().toString();
+        
+     Assert.assertEquals("", s);   
+    }
+
+    public void testNormalString()
+    {
+        String s = new MutableString("abcdef".getBytes()).toString();
+        
+        Assert.assertEquals("abcdef", s);   
+    }
+
+    /**
+     * Test a string with non ASCII chars
+     *
+     */
+    public void testNonASCIIString()
+    {
+        MutableString ms = new MutableString("Emmanuel Lécharny".getBytes());
+        String s = ms.toString();
+        
+        int msLength = ms.getLength();
+        int sLength = s.getBytes().length;
+        
+        Assert.assertEquals("Emmanuel Lécharny", s);   
+        Assert.assertEquals( sLength, msLength);
+    }
+}

Added: directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java
URL: http://svn.apache.org/viewcvs/directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java?rev=234224&view=auto
==============================================================================
--- directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java
(added)
+++ directory/asn1/branches/asn1-new-ber/ber-new/src/test/org/apache/asn1new/util/StringUtilsTest.java
Sun Aug 21 08:00:13 2005
@@ -0,0 +1,70 @@
+/*
+ *   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.asn1new.util;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StringUtilsTest extends TestCase {
+
+	public void testOneByteChar()
+	{
+		char res = StringUtils.bytesToChar(new byte[]{0x30});
+		
+		Assert.assertEquals('0', res);
+	}
+
+	public void testOneByteChar00()
+	{
+		char res = StringUtils.bytesToChar(new byte[]{0x00});
+		
+		Assert.assertEquals(0x00, res);
+	}
+
+	public void testOneByteChar7F()
+	{
+		char res = StringUtils.bytesToChar(new byte[]{0x7F});
+		
+		Assert.assertEquals(0x7F, res);
+	}
+
+	public void testTwoBytesChar()
+	{
+		char res = StringUtils.bytesToChar(new byte[]{(byte)0xCE, (byte)0x91});
+		
+		Assert.assertEquals(0x0391, res);
+	}
+
+	public void testThreeBytesChar()
+	{
+		char res = StringUtils.bytesToChar(new byte[]{(byte)0xE2, (byte)0x89, (byte)0xA2});
+		
+		Assert.assertEquals(0x2262, res);
+	}
+
+	/*
+	public void testSixBytesChar()
+	{
+		char res = StringUtils.bytesToChar(new byte[]{(byte)0xFD, (byte)0x93, (byte)0x91, (byte)0xBA,
(byte)0x95, (byte)0xA3});
+		
+		Assert.assertEquals(0x7347A563, res);
+	}
+	*/
+}



Mime
View raw message