コード例 #1
0
  /** @tests java.security.MessageDigest#digest(byte[], int, int) */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "digest",
      args = {byte[].class, int.class, int.class})
  public void test_digestLB$LILI() throws Exception {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    byte[] b = {1, 2, 3, 4, 5};
    assertEquals("incorrect result", 0, md.digest(b, 2, 3));
    assertTrue("digest failed", md.runEngineDigest);

    // Regression for Harmony-1148
    md = new MyMessageDigest1();
    final byte[] bytes = new byte[] {2, 4, 1};
    try {
      // buf == null
      md.digest(null, 0, 1);
      fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
      // offset + len > buf.length
      md.digest(bytes, 0, bytes.length + 1);
      fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
      // offset + len > Integer.MAX_VALUE
      md.digest(bytes, Integer.MAX_VALUE, 1);
      fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    // offset<0 and len<0 are passed to provider
    final int offset = -1;
    final int len = -1;
    final int status = 33;
    md =
        new MyMessageDigest1("ABC") {
          @Override
          public int engineDigest(byte[] arg0, int arg1, int arg2) {
            assertSame("buf", bytes, arg0);
            assertEquals("offset", offset, arg1);
            assertEquals("len", len, arg2);
            return status;
          }
        };
    assertEquals("returned status", status, md.digest(bytes, offset, len));

    try {
      MessageDigest digest = MessageDigest.getInstance("TestDigest", new TestProvider());
      digest.digest(new byte[5], 0, 5);
      fail("expected DigestException");
    } catch (DigestException e) {
      // ok
    }
  }
コード例 #2
0
 /** @tests java.security.MessageDigest#digest() */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "digest",
     args = {})
 public void test_digest() {
   MyMessageDigest1 md = new MyMessageDigest1("ABC");
   assertEquals("incorrect result", 0, md.digest().length);
   assertTrue(md.runEngineDigest);
 }