From 3da8316ca3edf81cb17e19551d9499855d52905c Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 29 Aug 2017 14:53:36 +0200 Subject: Add first working test. --- test/src/math/test_subgroups.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/src/math/test_subgroups.c (limited to 'test/src/math') diff --git a/test/src/math/test_subgroups.c b/test/src/math/test_subgroups.c new file mode 100644 index 0000000..fa81788 --- /dev/null +++ b/test/src/math/test_subgroups.c @@ -0,0 +1,31 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#include "gen/types.h" +#include "math/subgroups.h" +#include + +void setup(void) { + pari_init(1000000000, 1000000); +} + +TestSuite(subgroups, .init=setup); + +Test(subgroups, test_prime_factors) { + curve_t curve = {.order = stoi(12)}; + config_t cfg = {.prime = false}; + GEN divs = subgroups_prime(&curve, &cfg); + GEN vec = gtocol0(gen_0, 2); + gel(vec, 1) = stoi(2); + gel(vec, 2) = stoi(3); + cr_assert(gequal(divs, vec), "Factors not equal!"); +} + +Test(subgroups, test_prime_prime) { + curve_t curve = {.order = stoi(5)}; + config_t cfg = {.prime = true}; + GEN divs = subgroups_prime(&curve, &cfg); + GEN vec = gtocol(stoi(5)); + cr_assert(gequal(divs, vec), "Factors not equal!"); +} \ No newline at end of file -- cgit v1.3.1 From 4b5d03eda289aa477e693cad8b598a398bb7e04c Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 29 Aug 2017 16:57:31 +0200 Subject: Refactor test setup. --- test/CMakeLists.txt | 5 ++--- test/src/math/test_subgroups.c | 7 ++----- test/src/test/utils.c | 14 ++++++++++++++ test/src/test/utils.h | 12 ++++++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 test/src/test/utils.c create mode 100644 test/src/test/utils.h (limited to 'test/src/math') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3def321..066defb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,12 +4,11 @@ project(test_ecgen C) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/criterion/include) -message("${CMAKE_LIBRARY_PATH}") - find_library(criterion NAMES criterion PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib/criterion/build) file(GLOB TEST_SRC "src/math/*.c" "src/gen/*.c" "src/cm/*.c" "src/invalid/*.c" "src/io/*.c" "src/exhaustive/*.c" "src/util/*.c") -add_executable(test_ecgen ${TEST_SRC} ${SRC}) +file(GLOB TESTING_SRC "src/test/*.c") +add_executable(test_ecgen ${TEST_SRC} ${TESTING_SRC} ${SRC}) target_link_libraries(test_ecgen pthread rt pari ${parson} ${sha1} ${criterion}) diff --git a/test/src/math/test_subgroups.c b/test/src/math/test_subgroups.c index fa81788..ad42282 100644 --- a/test/src/math/test_subgroups.c +++ b/test/src/math/test_subgroups.c @@ -5,12 +5,9 @@ #include "gen/types.h" #include "math/subgroups.h" #include +#include "test/utils.h" -void setup(void) { - pari_init(1000000000, 1000000); -} - -TestSuite(subgroups, .init=setup); +TestSuite(subgroups, .init=default_setup, .fini=default_teardown); Test(subgroups, test_prime_factors) { curve_t curve = {.order = stoi(12)}; diff --git a/test/src/test/utils.c b/test/src/test/utils.c new file mode 100644 index 0000000..a8a11db --- /dev/null +++ b/test/src/test/utils.c @@ -0,0 +1,14 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#include "utils.h" +#include + +void default_setup(void) { + pari_init(1000000, 1000000); +} + +void default_teardown(void) { + pari_close(); +} \ No newline at end of file diff --git a/test/src/test/utils.h b/test/src/test/utils.h new file mode 100644 index 0000000..2780bd2 --- /dev/null +++ b/test/src/test/utils.h @@ -0,0 +1,12 @@ +/* + * ecgen, tool for generating Elliptic curve domain parameters + * Copyright (C) 2017 J08nY + */ +#ifndef ECGEN_UTILS_H +#define ECGEN_UTILS_H + +void default_setup(void); + +void default_teardown(void); + +#endif //ECGEN_UTILS_H -- cgit v1.3.1