diff options
Diffstat (limited to 'source/test')
-rw-r--r-- | source/test/unittests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | source/test/unittests/secure_random.test.c | 22 |
2 files changed, 24 insertions, 2 deletions
diff --git a/source/test/unittests/CMakeLists.txt b/source/test/unittests/CMakeLists.txt index 261b69e..b2ef480 100644 --- a/source/test/unittests/CMakeLists.txt +++ b/source/test/unittests/CMakeLists.txt @@ -4,5 +4,5 @@ target_sources( async_function.test.c bigint.test.c mutex.test.c test_duration.test.c main.test.c string_ref.test.c atomic.test.c thread.test.c array_ref.test.c input_stream.test.c lower_bound.test.c - condition_variable.test.c mersenne_twister_64.test.c input_buffer.test.c - move_back.test.c dynamic_array.test.c file.test.c) + secure_random.test.c condition_variable.test.c mersenne_twister_64.test.c + input_buffer.test.c move_back.test.c dynamic_array.test.c file.test.c) diff --git a/source/test/unittests/secure_random.test.c b/source/test/unittests/secure_random.test.c new file mode 100644 index 0000000..ec0a7b2 --- /dev/null +++ b/source/test/unittests/secure_random.test.c @@ -0,0 +1,22 @@ +#include "../../kit/secure_random.h" +#include <string.h> + +#define KIT_TEST_FILE secure_random +#include "../../kit_test/test.h" + +TEST("secure random") { + int v[20]; + memset(v, 0, sizeof v); + + secure_random(40, v); + secure_random(40, v + 10); + + int repeats = 0; + + for (int i = 1; i < sizeof v / sizeof *v; i++) + for (int j = 0; j < i; j++) + if (v[i] == v[j]) + repeats++; + + REQUIRE(repeats == 0); +} |