From bb3b086f24f3be03be5206f5970733cdbab6ca87 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Tue, 2 Sep 2014 22:52:59 -0700 Subject: [PATCH] test MD5.clone() --- tests/automation.js | 2 +- tests/com/sun/midp/crypto/TestMD5.java | 30 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/automation.js b/tests/automation.js index 5b7e3237..8d0ad34d 100644 --- a/tests/automation.js +++ b/tests/automation.js @@ -9,7 +9,7 @@ casper.test.begin("unit tests", 8, function(test) { casper .start("http://localhost:8000/index.html?main=RunTests") .waitForText("DONE", function then() { - test.assertTextExists("DONE: 1369 pass, 0 fail, 12 known fail, 0 unknown pass", "run unit tests"); + test.assertTextExists("DONE: 1371 pass, 0 fail, 12 known fail, 0 unknown pass", "run unit tests"); }, function onTimeout() { test.fail(); }, 10000); diff --git a/tests/com/sun/midp/crypto/TestMD5.java b/tests/com/sun/midp/crypto/TestMD5.java index 1b1cdfa1..81a508dd 100644 --- a/tests/com/sun/midp/crypto/TestMD5.java +++ b/tests/com/sun/midp/crypto/TestMD5.java @@ -131,5 +131,35 @@ public class TestMD5 implements Testlet { e.printStackTrace(); } th.todo(Util.hexEncode(buf), "3fd0fac5027a9cd891c2dc778c88167a"); + + try { + this.testClone(th); + } catch (DigestException e) { + th.fail("Unexpected exception: " + e); + e.printStackTrace(); + } + } + + private void testClone(TestHarness th) throws DigestException { + MD5 md51 = new MD5(); + byte[] buf1 = new byte[16]; + String part1 = "a"; + md51.update(part1.getBytes(), 0, part1.length()); + + MD5 md52 = (MD5)md51.clone(); + byte[] buf2 = new byte[16]; + String part2 = "b"; + md52.update(part2.getBytes(), 0, part2.length()); + + // md51 should be unaffected by the update to md52. + md51.digest(buf1, 0, 16); + th.check(Util.hexEncode(buf1), "0cc175b9c0f1b6a831c399e269772661"); + + // md52 should now hash "ab", the concatenation of part1 and part2. + md52.digest(buf2, 0, 16); + th.check(Util.hexEncode(buf2), "187ef4436122d1cc2f40dc2b92f0eba0"); + + md51.reset(); + md52.reset(); } }