diff options
Diffstat (limited to 'tests/random.c')
-rw-r--r-- | tests/random.c | 75 |
1 files changed, 30 insertions, 45 deletions
diff --git a/tests/random.c b/tests/random.c index 09ad1a7..19c23b0 100644 --- a/tests/random.c +++ b/tests/random.c @@ -1,22 +1,28 @@ #include "../src/random.c" + +#include <stdlib.h> + #include "../src/testing.h" + static int -test_urandom_bytes(void) { +test_random_bytes(void) { int rc = -1; - test_start("urandom_bytes()"); + test_start("random_bytes()"); { testing("we get to pick the size that comes out"); - const size_t LEN = 256; - uint8_t arr[256 /* LEN */] = { 0 }; + enum { + LEN = 256, + }; + u8 arr[LEN] = { 0 }; for (size_t n = 0; n < LEN; n++) { - if (urandom_bytes(n, &arr)) { - logerr("urandom_bytes()"); + if (random_bytes(n, &arr)) { + logerr("random_bytes()"); goto out; } for (size_t i = n; i < LEN; i++) { @@ -30,19 +36,21 @@ test_urandom_bytes(void) { { testing("we always get a new value as a result"); - const size_t LEN = 64; - uint8_t arr1[64 /* LEN */] = { 0 }; - uint8_t arr2[64 /* LEN */] = { 0 }; + enum { + LEN = 64, + }; + u8 arr1[LEN] = { 0 }; + u8 arr2[LEN] = { 0 }; - if (urandom_bytes(LEN, &arr1)) { - logerr("urandom_bytes()"); + if (random_bytes(LEN, &arr1)) { + logerr("random_bytes()"); goto out; } const size_t attempts = 10; for (size_t n = 0; n < attempts; n++) { - if (urandom_bytes(LEN, &arr2)) { - logerr("urandom_bytes()"); + if (random_bytes(LEN, &arr2)) { + logerr("random_bytes()"); goto out; } assert(memcmp(arr1, arr2, LEN) != 0); @@ -56,50 +64,27 @@ out: return rc; } -static int -test_random_new(void) { - // FIXME: implement these - return 0; -} - -static int -test_random_free(void) { - // FIXME: implement these - return 0; -} - -static int -test_random_generate(void) { - // FIXME: implement these - return 0; -} - int main(void) { int rc = EXIT_FAILURE; - if (test_urandom_bytes()) { - logerr("test_urandom_bytes()"); - goto out; - } - - if (test_random_new()) { - logerr("test_random_new()"); + if (random_init()) { + logerr("random_init()"); goto out; } - if (test_random_free()) { - logerr("test_random_free()"); - goto out; - } - - if (test_random_generate()) { - logerr("test_random_generate()"); + if (test_random_bytes()) { + logerr("test_random_bytes()"); goto out; } rc = EXIT_SUCCESS; out: + if (random_end()) { + if (rc == EXIT_SUCCESS) { + rc = EXIT_FAILURE; + } + } return rc; } |