From 4daa817502b18640c481ec91d85e114e9a168d94 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@allmydata.com>
Date: Tue, 4 Mar 2008 14:42:25 -0700
Subject: [PATCH] test_util.py: get 100% test coverage for hashutil.py

---
 src/allmydata/test/test_util.py | 36 +++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py
index 9c2c0cca..d80f0903 100644
--- a/src/allmydata/test/test_util.py
+++ b/src/allmydata/test/test_util.py
@@ -384,6 +384,11 @@ class DeferredUtilTests(unittest.TestCase):
         self.failUnless(f.check(RuntimeError))
 
 class HashUtilTests(unittest.TestCase):
+
+    def test_random_key(self):
+        k = hashutil.random_key()
+        self.failUnlessEqual(len(k), hashutil.KEYLEN)
+
     def test_sha256d(self):
         h1 = hashutil.tagged_hash("tag1", "value")
         h2 = hashutil.tagged_hasher("tag1")
@@ -408,3 +413,34 @@ class HashUtilTests(unittest.TestCase):
         h2.update("data")
         h2 = h2.digest()
         self.failUnlessEqual(h1, h2)
+
+    def test_hashers(self):
+        h1 = hashutil.block_hash("foo")
+        h2 = hashutil.block_hasher()
+        h2.update("foo")
+        self.failUnlessEqual(h1, h2.digest())
+
+        h1 = hashutil.uri_extension_hash("foo")
+        h2 = hashutil.uri_extension_hasher()
+        h2.update("foo")
+        self.failUnlessEqual(h1, h2.digest())
+
+        h1 = hashutil.plaintext_hash("foo")
+        h2 = hashutil.plaintext_hasher()
+        h2.update("foo")
+        self.failUnlessEqual(h1, h2.digest())
+
+        h1 = hashutil.crypttext_hash("foo")
+        h2 = hashutil.crypttext_hasher()
+        h2.update("foo")
+        self.failUnlessEqual(h1, h2.digest())
+
+        h1 = hashutil.crypttext_segment_hash("foo")
+        h2 = hashutil.crypttext_segment_hasher()
+        h2.update("foo")
+        self.failUnlessEqual(h1, h2.digest())
+
+        h1 = hashutil.plaintext_segment_hash("foo")
+        h2 = hashutil.plaintext_segment_hasher()
+        h2.update("foo")
+        self.failUnlessEqual(h1, h2.digest())
-- 
2.45.2