/** @tests java.security.MessageDigest#getDigestLength() */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "getDigestLength",
     args = {})
 public void test_getDigestLength() {
   MyMessageDigest1 md = new MyMessageDigest1("ABC");
   assertEquals(0, md.getDigestLength());
 }
 /** @tests java.security.MessageDigest#getProvider() */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "getProvider",
     args = {})
 public void test_getProvider() {
   MyMessageDigest1 md = new MyMessageDigest1("ABC");
   assertNull(md.getProvider());
 }
 /** @tests java.security.MessageDigest#update(byte) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "update",
     args = {byte.class})
 public void test_updateLB() {
   MyMessageDigest1 md = new MyMessageDigest1("ABC");
   md.update((byte) 1);
   assertTrue(md.runEngineUpdate1);
 }
 /** @tests java.security.MessageDigest#reset() */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "reset",
     args = {})
 public void test_reset() {
   MyMessageDigest1 md = new MyMessageDigest1("ABC");
   md.reset();
   assertTrue(md.runEngineReset);
 }
 /** @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);
 }
 /** @tests java.security.MessageDigest#update(byte[]) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "update",
     args = {byte[].class})
 public void test_updateLB$() {
   MyMessageDigest1 md = new MyMessageDigest1("ABC");
   byte[] b = {1, 2, 3, 4, 5};
   md.update(b);
   assertTrue(md.runEngineUpdate2);
 }
  /** @tests java.security.MessageDigest#update(ByteBuffer) */
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "update",
      args = {java.nio.ByteBuffer.class})
  public void test_updateLjava_nio_ByteBuffer() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    byte[] b = {1, 2, 3, 4, 5};
    ByteBuffer byteBuffer = ByteBuffer.wrap(b);

    int limit = byteBuffer.limit();
    md.update(byteBuffer);
    assertTrue(md.runEngineUpdate2);
    assertEquals(byteBuffer.limit(), byteBuffer.position());
    assertEquals(limit, byteBuffer.limit());
  }
  /** @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
    }
  }
  /** @tests java.security.MessageDigest#update(byte[], int, int) */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "update",
      args = {byte[].class, int.class, int.class})
  public void test_updateLB$LILI() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    final byte[] bytes = {1, 2, 3, 4, 5};
    md.update(bytes, 1, 2);
    assertTrue(md.runEngineUpdate2);

    // Regression for HARMONY-1120
    try {
      // buf == null
      md.update(null, 0, 1);
      fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
      // offset + len > buf.length
      md.update(bytes, 0, bytes.length + 1);
      fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
      // offset + len > Integer.MAX_VALUE
      md.update(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;
    md =
        new MyMessageDigest1("ABC") {
          @Override
          public void engineUpdate(byte[] arg0, int arg1, int arg2) {
            assertSame("buf", bytes, arg0);
            assertEquals("offset", offset, arg1);
            assertEquals("len", len, arg2);
            runEngineUpdate2 = true;
          }
        };
    md.update(bytes, offset, len);
    assertTrue(md.runEngineUpdate2);
  }