diff options
Diffstat (limited to 'tests/t_hex.c')
| -rw-r--r-- | tests/t_hex.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/tests/t_hex.c b/tests/t_hex.c index 7cce8ac..a761737 100644 --- a/tests/t_hex.c +++ b/tests/t_hex.c | |||
| @@ -18,7 +18,7 @@ static void case_encode(void) { | |||
| 18 | 18 | ||
| 19 | test_case("a hash encodes to forty upper case digits and a terminator"); | 19 | test_case("a hash encodes to forty upper case digits and a terminator"); |
| 20 | memset(dest, 0x7f, sizeof(dest)); | 20 | memset(dest, 0x7f, sizeof(dest)); |
| 21 | CHECK_PTR(hex_fromhash(dest, sample), dest); | 21 | CHECK_PTR(hex_from_hash(dest, sample), dest); |
| 22 | CHECK_STR(dest, "000123456789ABCDEFFF10203040506070809" "0A0"); | 22 | CHECK_STR(dest, "000123456789ABCDEFFF10203040506070809" "0A0"); |
| 23 | CHECK_INT(strlen(dest), 40); | 23 | CHECK_INT(strlen(dest), 40); |
| 24 | CHECK_INT((unsigned char)dest[41], 0x7f); | 24 | CHECK_INT((unsigned char)dest[41], 0x7f); |
| @@ -28,7 +28,7 @@ static void case_decode(void) { | |||
| 28 | ot_hash hash; | 28 | ot_hash hash; |
| 29 | 29 | ||
| 30 | test_case("forty digits decode back to the hash"); | 30 | test_case("forty digits decode back to the hash"); |
| 31 | CHECK(hex_tohash(hash, "000123456789ABCDEFFF10203040506070809" "0A0")); | 31 | CHECK(hex_to_hash(hash, "000123456789ABCDEFFF10203040506070809" "0A0")); |
| 32 | CHECK_MEM(hash, sample, sizeof(sample)); | 32 | CHECK_MEM(hash, sample, sizeof(sample)); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| @@ -41,8 +41,8 @@ static void case_round_trip(void) { | |||
| 41 | for (i = 0; i < 256; ++i) { | 41 | for (i = 0; i < 256; ++i) { |
| 42 | uint8_t probe[20]; | 42 | uint8_t probe[20]; |
| 43 | memset(probe, (uint8_t)i, sizeof(probe)); | 43 | memset(probe, (uint8_t)i, sizeof(probe)); |
| 44 | hex_fromhash(text, probe); | 44 | hex_from_hash(text, probe); |
| 45 | if (!hex_tohash(hash, text) || memcmp(hash, probe, sizeof(probe))) { | 45 | if (!hex_to_hash(hash, text) || memcmp(hash, probe, sizeof(probe))) { |
| 46 | test_failf(__FILE__, __LINE__, "round trip failed for byte value %zu", i); | 46 | test_failf(__FILE__, __LINE__, "round trip failed for byte value %zu", i); |
| 47 | return; | 47 | return; |
| 48 | } | 48 | } |
| @@ -54,8 +54,8 @@ static void case_decode_is_case_insensitive(void) { | |||
| 54 | ot_hash upper, lower; | 54 | ot_hash upper, lower; |
| 55 | 55 | ||
| 56 | test_case("lower case digits decode the same as upper case"); | 56 | test_case("lower case digits decode the same as upper case"); |
| 57 | CHECK(hex_tohash(upper, "ABCDEF0123456789ABCDEF0123456789ABCDEF01")); | 57 | CHECK(hex_to_hash(upper, "ABCDEF0123456789ABCDEF0123456789ABCDEF01")); |
| 58 | CHECK(hex_tohash(lower, "abcdef0123456789abcdef0123456789abcdef01")); | 58 | CHECK(hex_to_hash(lower, "abcdef0123456789abcdef0123456789abcdef01")); |
| 59 | CHECK_MEM(lower, upper, sizeof(ot_hash)); | 59 | CHECK_MEM(lower, upper, sizeof(ot_hash)); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| @@ -63,18 +63,18 @@ static void case_rejects_non_digits(void) { | |||
| 63 | ot_hash hash; | 63 | ot_hash hash; |
| 64 | 64 | ||
| 65 | test_case("a non hex character anywhere rejects the whole string"); | 65 | test_case("a non hex character anywhere rejects the whole string"); |
| 66 | CHECK_INT(hex_tohash(hash, "g00123456789ABCDEFFF102030405060708090A0"), 0); | 66 | CHECK_INT(hex_to_hash(hash, "g00123456789ABCDEFFF102030405060708090A0"), 0); |
| 67 | CHECK_INT(hex_tohash(hash, "000123456789ABCDEFFF102030405060708090Ag"), 0); | 67 | CHECK_INT(hex_to_hash(hash, "000123456789ABCDEFFF102030405060708090Ag"), 0); |
| 68 | CHECK_INT(hex_tohash(hash, "000123456789ABCDEF:F102030405060708090A"), 0); | 68 | CHECK_INT(hex_to_hash(hash, "000123456789ABCDEF:F102030405060708090A"), 0); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | static void case_rejects_short_input(void) { | 71 | static void case_rejects_short_input(void) { |
| 72 | ot_hash hash; | 72 | ot_hash hash; |
| 73 | 73 | ||
| 74 | test_case("a string shorter than forty digits is rejected"); | 74 | test_case("a string shorter than forty digits is rejected"); |
| 75 | CHECK_INT(hex_tohash(hash, ""), 0); | 75 | CHECK_INT(hex_to_hash(hash, ""), 0); |
| 76 | CHECK_INT(hex_tohash(hash, "00"), 0); | 76 | CHECK_INT(hex_to_hash(hash, "00"), 0); |
| 77 | CHECK_INT(hex_tohash(hash, "000123456789ABCDEFFF102030405060708090A"), 0); | 77 | CHECK_INT(hex_to_hash(hash, "000123456789ABCDEFFF102030405060708090A"), 0); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | static void case_leaves_hash_untouched_on_failure(void) { | 80 | static void case_leaves_hash_untouched_on_failure(void) { |
| @@ -82,7 +82,7 @@ static void case_leaves_hash_untouched_on_failure(void) { | |||
| 82 | 82 | ||
| 83 | test_case("a rejected string leaves the destination untouched"); | 83 | test_case("a rejected string leaves the destination untouched"); |
| 84 | memset(hash, 0x5a, sizeof(hash)); | 84 | memset(hash, 0x5a, sizeof(hash)); |
| 85 | CHECK_INT(hex_tohash(hash, "000123456789ABCDEFFF10203040506070809XX0"), 0); | 85 | CHECK_INT(hex_to_hash(hash, "000123456789ABCDEFFF10203040506070809XX0"), 0); |
| 86 | CHECK_MEM(hash, "\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a", sizeof(hash)); | 86 | CHECK_MEM(hash, "\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a\x5a", sizeof(hash)); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| @@ -96,7 +96,7 @@ static void case_stops_at_the_terminator(void) { | |||
| 96 | memcpy(guarded, "0012", 4); | 96 | memcpy(guarded, "0012", 4); |
| 97 | guarded[4] = 0; | 97 | guarded[4] = 0; |
| 98 | memset(guarded + 5, 'f', 3); | 98 | memset(guarded + 5, 'f', 3); |
| 99 | CHECK_INT(hex_tohash(hash, guarded), 0); | 99 | CHECK_INT(hex_to_hash(hash, guarded), 0); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | static void case_isdigit(void) { | 102 | static void case_isdigit(void) { |
