diff options
| author | J08nY | 2017-08-30 19:47:47 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-30 19:47:47 +0200 |
| commit | 5856d4d9c66b361c613b85fd187e9e989c270129 (patch) | |
| tree | 4684e59b0ddaa4c841bbf314cd95cb0c5b3de2f5 /test/src | |
| parent | 0685c1ce85218184657f931e5cfcb587fd3ee82f (diff) | |
| download | ecgen-5856d4d9c66b361c613b85fd187e9e989c270129.tar.gz ecgen-5856d4d9c66b361c613b85fd187e9e989c270129.tar.zst ecgen-5856d4d9c66b361c613b85fd187e9e989c270129.zip | |
Don't always read numbers as hexadecimal. Add tests for input.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/io/test_input.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/src/io/test_input.c b/test/src/io/test_input.c index 8b13789..6e7064f 100644 --- a/test/src/io/test_input.c +++ b/test/src/io/test_input.c @@ -1 +1,80 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#include "test/utils.h" +#include "io/input.h" +#include "io/output.h" +#include <criterion/criterion.h> + +static FILE *write_in; + +void input_setup() { + default_setup(); + config_t cfg; + memset(&cfg, 0, sizeof(cfg)); + + cfg.output = "/dev/null"; + input_init(&cfg); + output_init(&cfg); + + int in_fd[2]; + pipe(in_fd); + + write_in = fdopen(in_fd[1], "w"); + setlinebuf(write_in); + in = fdopen(in_fd[0], "r"); +} + +void input_teardown() { + default_teardown(); + input_quit(); + output_quit(); + fclose(write_in); +} + +TestSuite(input, .init = input_setup, .fini = input_teardown); + +Test(input, test_prime) { + fprintf(write_in, "5\n"); + GEN p = input_prime(NULL, 10); + cr_assert(gequal(p, stoi(5)),); +} + +Test(input, test_prime_nan) { + fprintf(write_in, "....\n"); + GEN p = input_prime(NULL, 10); + cr_assert(gequal(p, gen_m1),); +} + +Test(input, test_prime_nonprime) { + fprintf(write_in, "6\n"); + GEN p = input_prime(NULL, 10); + cr_assert(gequal(p, gen_m1),); +} + +Test(input, test_int) { + fprintf(write_in, "256\n"); + GEN i = input_int(NULL, 10); + cr_assert(gequal(i, stoi(256)),); +} + +Test(input, test_int_too_big) { + fprintf(write_in, "256\n"); + GEN i = input_int(NULL, 4); + cr_assert(gequal(i, gen_m1),); +} + +Test(input, test_int_newline) { + fprintf(write_in, "\n"); + GEN i = input_int(NULL, 4); + cr_assert(gequal(i, gen_m1),); +} + +Test(input, test_str) { + fprintf(write_in, "something\n"); + GEN s = input_string(NULL); + GEN expected = strtoGENstr("something"); + cr_assert(gequal(s, expected),); +} |
