From 59685c84348f8d71dc3bbd3513c5eb10cc738a8e Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Fri, 03 Nov 2006 16:39:22 +0000
Subject: [PATCH] Refactor DN and RDN classes and improve their test coverage.

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java
index 059c3d5..a6ee8a4 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/util/TestStaticUtils.java
@@ -293,6 +293,65 @@
   }
 
   /**
+   * Create test data for {@link StaticUtils#compare(byte[], byte[])}.
+   * 
+   * @return Returns an array of test data.
+   */
+  @DataProvider(name = "compareBytesTestData")
+  public Object[][] createCompareBytesTestData() {
+    return new Object[][] {
+        { null, null, 0 },
+        { null, new byte[0], -1 },
+        { new byte[0], null, 1 },
+        { new byte[0], new byte[0], 0 },
+        { new byte[] { 0x00 }, new byte[] { 0x00 }, 0 },
+        { new byte[] { 0x01 }, new byte[] { 0x00 }, 1 },
+        { new byte[] { 0x7f }, new byte[] { 0x00 }, 1 },
+        { new byte[] { (byte) 0x80 }, new byte[] { 0x00 }, -1 },
+        { new byte[] { (byte) 0xff }, new byte[] { 0x00 }, -1 },
+        { new byte[] { 0x00 }, new byte[] { 0x01 }, -1 },
+        { new byte[] { 0x00 }, new byte[] { 0x7f }, -1 },
+        { new byte[] { 0x00 }, new byte[] { (byte) 0x80 }, 1 },
+        { new byte[] { 0x00 }, new byte[] { (byte) 0xff }, 1 },
+        { new byte[] { 0x00, 0x01, 0x02 },
+            new byte[] { 0x00, 0x01, 0x02 }, 0 },
+        { new byte[] { 0x00, 0x01 }, new byte[] { 0x00, 0x01, 0x02 },
+            -1 },
+        { new byte[] { 0x00, 0x01, 0x02 }, new byte[] { 0x00, 0x01 },
+            1 }, };
+  }
+
+  /**
+   * Tests the {@link StaticUtils#compare(byte[], byte[])} method.
+   * 
+   * @param a
+   *          The first byte array.
+   * @param a2
+   *          The second byte array.
+   * @param expected
+   *          The expected result.
+   * @throws Exception
+   *           If the test failed unexpectedly.
+   */
+  @Test(dataProvider = "compareBytesTestData")
+  public void testCompareBytes(byte[] a, byte[] a2, int expected)
+      throws Exception {
+    int rc = StaticUtils.compare(a, a2);
+
+    if (expected < 0 && rc >= 0) {
+      Assert.fail("Expected negative result but got " + rc);
+    }
+
+    if (expected > 0 && rc <= 0) {
+      Assert.fail("Expected positive result but got " + rc);
+    }
+
+    if (expected == 0 && rc != 0) {
+      Assert.fail("Expected zero result but got " + rc);
+    }
+  }
+
+  /**
    * Create test strings for the {@link StaticUtils#isDigit(char)}.
    *
    * @return Returns an array of test data.

--
Gitblit v1.10.0