This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: New Security Engine getInstance Test


This patch, commited, adds a new test to
java.security.Engine.getInstance. This new test checks that algorithm
names are being accepted as case insensitive.

Thanks,

Matt Wringe.


Changelog:

2006-07-10 Matt Wringe  <mwringe@redhat.com>

    * gnu/testlet/java/security/Engine/getInstance.java
    (testAlgorithmCase): New Test. Tests algorithm name case
insensitivity.

Index: getInstance.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/security/Engine/getInstance.java,v
retrieving revision 1.1
diff -u -r1.1 getInstance.java
--- getInstance.java	2 Jan 2006 14:02:58 -0000	1.1
+++ getInstance.java	10 Jul 2006 15:35:37 -0000
@@ -28,26 +28,46 @@
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import java.security.NoSuchAlgorithmException;
 import java.security.Provider;
 import java.security.Security;
 
 public class getInstance extends Provider implements Testlet
 {
+  
+  private Provider provider;
+    
   public getInstance()
   {
-    super("FakeProvider", 1.0, "");
+    super("FakeProvider", 1.0, "A Fake Provider Used Within the Mauve Test Suite");
 
     put("MessageDigest.foo",
         "gnu.testlet.java.security.MessageDigest.MauveDigest");
     put("Alg.Alias.MessageDigest.bar", "foo");
   }
 
-  public void test (TestHarness harness)
-  {
-    harness.checkPoint ("Engine");
+  
+  // Test case for the behaviour of
+  // Engine.getInstance (service, algorithm, provider).
+  // White space should be ignored.
+  // The algorithm names should be case insensitive.
+  public void test (TestHarness harness){
+    setUp (harness);
+    testWhiteSpace(harness);
+    testAlgorithmCase (harness);
+  }
 
-    Provider provider = this;
+  private void setUp (TestHarness harness){
+    provider = this;
     Security.addProvider(provider);
+  }
+  
+  // Tests the behaviour of 
+  // Engine.getInstance (service, algorithm, provider).
+  // The algorithms and service names should ignore any white space.
+  private void testWhiteSpace (TestHarness harness)
+  {
+    harness.checkPoint ("Engine");
     String signature;
 
     signature = "getInstance(\"MessageDigest\", \"foo\", provider)";
@@ -102,4 +122,120 @@
         harness.debug(x);
       }
   }
+
+  // Tests the behaviour of 
+  // Engine.getInstance (service, algorithm, provider).
+  // The algorithm names should be case insensitive.
+  private void testAlgorithmCase(TestHarness harness)
+  {
+    try
+      {
+
+        // test to make sure the engine can be found using all lowercase
+        // characters.
+
+        try
+          {
+            Engine.getInstance("MessageDigest", "foo", provider);
+          }
+        catch (NoSuchAlgorithmException e)
+          {
+            harness.fail("Could not find engine when using all lowercase characters");
+            harness.debug(e);
+          }
+
+        // test to make sure the engine can be found using all uppercase
+        // characters
+        try
+          {
+            Engine.getInstance("MessageDigest", "FOO", provider);
+          }
+        catch (NoSuchAlgorithmException e)
+          {
+            harness.fail("Could not find engine when using all uppercase characters");
+            harness.debug(e);
+          }
+
+        // test to make sure the engine can be found using a random case for the
+        // characters
+        try
+          {
+            Engine.getInstance("MessageDigest", "FoO", provider);
+          }
+        catch (NoSuchAlgorithmException e)
+          {
+            harness.fail("Could not find engine when using random case characters");
+            harness.debug(e);
+          }
+
+        // test to make sure the engine can be found using the exact same case
+        // specified in the Provider
+        try
+          {
+            Engine.getInstance("MessageDigest", "foo", provider);
+          }
+        catch (NoSuchAlgorithmException e)
+          {
+            harness.fail("Could not find engine using exact case characters");
+            harness.debug(e);
+          }
+
+        // test to make sure the engine can be found usinga all lowercase
+        // characters using the alias
+        try
+          {
+            Engine.getInstance("MessageDigest", "bar", provider);
+          }
+        catch (NoSuchAlgorithmException e)
+          {
+            harness.fail("Could not find engine using alias and all lowercase characters");
+            harness.debug(e);
+          }
+
+        // test to make sure the engine can be found using all uppercase
+        // characters using the alias
+        try
+          {
+            Engine.getInstance("MessageDigest", "BAR", provider);
+          }
+        catch (NoSuchAlgorithmException e)
+          {
+            harness.fail("Could not find engine using alias and all uppercase characters");
+            harness.debug(e);
+          }
+
+        // test to make sure the engine can be found using a random case for the
+        // characters using the alias
+        try
+          {
+            Engine.getInstance("MessageDigest", "bAr", provider);
+          }
+        catch (NoSuchAlgorithmException e)
+          {
+            harness.fail("Could not find engine using alias and random case characters");
+            harness.debug(e);
+          }
+
+        // test to make sure the engine can be found using the exact same case
+        // specified in the Provider using the alias
+        try
+          {
+            Engine.getInstance("MessageDigest", "bar", provider);
+          }
+        catch (NoSuchAlgorithmException e)
+          {
+            harness.fail("Could not find engine using alias and exact case characters");
+            harness.debug(e);
+          }
+      }
+
+    catch (Exception e)
+      {
+        harness.debug(e);
+        harness.fail(String.valueOf(e));
+      }
+
+  }
+
+
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]