From 9008dca31797ba1b05fa3ed6cacb540ef175c666 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Sat, 07 Feb 2009 00:56:52 +0000
Subject: [PATCH] Align ASN1Reader with ASN1Writer by adding readEnumerated().

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/asn1/ASN1ReaderTestCase.java |   73 +++++++++++++++++++++++++++++++++++-
 1 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/asn1/ASN1ReaderTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/asn1/ASN1ReaderTestCase.java
index ee4299b..668b566 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/asn1/ASN1ReaderTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/asn1/ASN1ReaderTestCase.java
@@ -67,8 +67,6 @@
    *
    * @return  A list of byte arrays with encoded ASN.1 elements that can be
    *          decoded as octet strings.
-   *
-   * @throws  Exception  If an unexpected problem occurs.
    */
   @DataProvider(name = "elementArrays")
   public Object[][] getElementArrays()
@@ -102,6 +100,17 @@
         };
   }
 
+  /**
+   * Gets the reader to be use for the unit tests.
+   *
+   * @param b
+   *          The array of bytes to be read.
+   * @param maxElementSize
+   *          The max element size.
+   * @return The reader to be use for the unit tests.
+   * @throws IOException
+   *           In an unexpected IO exception occurred.
+   */
   abstract ASN1Reader getReader(byte[] b, int maxElementSize)
       throws IOException;
 
@@ -213,6 +222,20 @@
     getReader(b, 0).readInteger();
   }
 
+  /**
+   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
+   * a short array.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test(expectedExceptions = { ASN1Exception.class })
+  public void testDecodeShortArrayAsEnumerated()
+      throws Exception
+  {
+    byte[] b = new byte[0];
+    getReader(b, 0).readEnumerated();
+  }
+
 
 
   /**
@@ -232,6 +255,22 @@
 
 
   /**
+   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
+   * a long length array.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test(expectedExceptions = { ASN1Exception.class })
+  public void testDecodeLongLengthArrayAsEnumerated()
+      throws Exception
+  {
+    byte[] b = { 0x02, (byte) 0x85, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 };
+    getReader(b, 0).readEnumerated();
+  }
+
+
+
+  /**
    * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array with
    * a truncated length array.
    *
@@ -248,6 +287,22 @@
 
 
   /**
+   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
+   * a truncated length array.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test(expectedExceptions = { ASN1Exception.class })
+  public void testDecodeTruncatedLengthArrayAsEnumerated()
+      throws Exception
+  {
+    byte[] b = { 0x02, (byte) 0x82, 0x00 };
+    getReader(b, 0).readEnumerated();
+  }
+
+
+
+  /**
    * Tests the <CODE>decodeAsInteger</CODE> method that takes a byte array with
    * a length mismatch.
    *
@@ -262,6 +317,20 @@
   }
 
   /**
+   * Tests the <CODE>readEnumerated</CODE> method that takes a byte array with
+   * a length mismatch.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test(expectedExceptions = { ASN1Exception.class })
+  public void testDecodeLengthMismatchArrayAsEnumerated()
+      throws Exception
+  {
+    byte[] b = { 0x02, (byte) 0x81, 0x01 };
+    getReader(b, 0).readEnumerated();
+  }
+
+  /**
    * Tests the <CODE>decodeAsBoolean</CODE> method that takes a byte array
    * argument with valid arrays.
    *

--
Gitblit v1.10.0