]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Unit test for hex_str func
authorAnders Sundman <anders@4zm.org>
Mon, 31 Oct 2011 22:36:35 +0000 (23:36 +0100)
committerAnders Sundman <anders@4zm.org>
Thu, 10 Nov 2011 22:26:29 +0000 (23:26 +0100)
Note: Too long input is undefined by contract. That behaviour should not be asserted in test.

src/test/test_util.c

index 6603ab00d38aae74f5aa799bbf1c10aa85176740..e9240e1d9aed477010abfdbdc03a1a294ea43a53 100644 (file)
@@ -409,6 +409,20 @@ test_util_strmisc(void)
     SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
     smartlist_free(sl);
   }
+
+  /* Test hex_str */
+  {
+    char binary_data[64];
+    size_t i;
+    for (i = 0; i < sizeof(binary_data); ++i)
+      binary_data[i] = i;
+    test_streq(hex_str(binary_data, 0), "");
+    test_streq(hex_str(binary_data, 1), "00");
+    test_streq(hex_str(binary_data, 17), "000102030405060708090A0B0C0D0E0F10");
+    test_streq(hex_str(binary_data, 32),
+               "000102030405060708090A0B0C0D0E0F"
+               "101112131415161718191A1B1C1D1E1F");
+  }
  done:
   ;
 }