From d7207a3df3a279d4b4ad13dc2dbb98289239e521 Mon Sep 17 00:00:00 2001 From: jlamothe Date: Wed, 8 Nov 2023 00:20:33 +0000 Subject: [PATCH] broke initial state testing off into separate module --- test/initial-state.c | 119 +++++++++++++++++++++++++++++++++++++++++++ test/initial-state.h | 23 +++++++++ test/macros.h | 24 +++++++++ test/mkfile | 3 +- test/tests.c | 89 +------------------------------- 5 files changed, 169 insertions(+), 89 deletions(-) create mode 100644 test/initial-state.c create mode 100644 test/initial-state.h create mode 100644 test/macros.h diff --git a/test/initial-state.c b/test/initial-state.c new file mode 100644 index 0000000..85be69d --- /dev/null +++ b/test/initial-state.c @@ -0,0 +1,119 @@ +/* + + 9unit + Copyright (C) Jonathan Lamothe + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +#include +#include + +#include "../9unit.h" +#include "macros.h" +#include "initial-state.h" + +// Internal Prototypes + +static void tests(TestState *); +decl_test(initial_test_count); +decl_test(initial_pass_count); +decl_test(initial_fail_count); +decl_test(initial_pend_count); +decl_test(initial_first_log); +decl_test(initial_last_log); +decl_test(initial_ptr); + +// Public Functions + +void +test_initial_state(TestState *s) +{ + print("Testing initial state\n"); + run_test(s, &initial_test_count); + run_test(s, &initial_pass_count); + run_test(s, &initial_fail_count); + run_test(s, &initial_pend_count); + run_test(s, &initial_first_log); + run_test(s, &initial_last_log); + run_test(s, &initial_ptr); +} + +// Internal Functions + +def_test(initial_test_count, s) +{ + TestState *scpy = s->ptr; + print("\trun\n"); + if (scpy->run == 0) return test_success; + append_test_log(s, "initial run was nonzero"); + return test_failure; +} + +def_test(initial_pass_count, s) +{ + TestState *scpy = s->ptr; + print("\tpassed\n"); + if (scpy->passed == 0) return test_success; + append_test_log(s, "initial passed was nonzero"); + return test_failure; +} + +def_test(initial_fail_count, s) +{ + TestState *scpy = s->ptr; + print("\tfailed\n"); + if (scpy->failed == 0) return test_success; + append_test_log(s, "initial failed was nonzero"); + return test_failure; +} + +def_test(initial_pend_count, s) +{ + TestState *scpy = s->ptr; + print("\tpending\n"); + if (scpy->pending == 0) return test_success; + append_test_log(s, "initial pending was nonzero"); + return test_failure; +} + +def_test(initial_first_log, s) +{ + TestState *scpy = s->ptr; + print("\tfirst_log\n"); + if (scpy->first_log == 0) return test_success; + append_test_log(s, "initial first_log was not null"); + return test_failure; +} + +def_test(initial_last_log, s) +{ + TestState *scpy = s->ptr; + print("\tlast_log\n"); + if (scpy->last_log == 0) return test_success; + append_test_log(s, "initial last_log was not null"); + return test_failure; +} + +def_test(initial_ptr, s) +{ + TestState *scpy = s->ptr; + print("\tptr\n"); + if (scpy->ptr == 0) return test_success; + append_test_log(s, "initial ptr was not null"); + return test_failure; +} + +//jl diff --git a/test/initial-state.h b/test/initial-state.h new file mode 100644 index 0000000..741e9fa --- /dev/null +++ b/test/initial-state.h @@ -0,0 +1,23 @@ +/* + + 9unit + Copyright (C) Jonathan Lamothe + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +void test_initial_state(TestState *); + +//jl diff --git a/test/macros.h b/test/macros.h new file mode 100644 index 0000000..e8db2ee --- /dev/null +++ b/test/macros.h @@ -0,0 +1,24 @@ +/* + + 9unit + Copyright (C) Jonathan Lamothe + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +#define decl_test(n) static TestResult n(TestState *) +#define def_test(n, s) static TestResult n(TestState *s) + +//jl diff --git a/test/mkfile b/test/mkfile index 1a2493f..d029c7a 100644 --- a/test/mkfile +++ b/test/mkfile @@ -16,7 +16,8 @@ #include "../9unit.h" - -#define decl_test(n) static TestResult n(TestState *) -#define def_test(n, s) static TestResult n(TestState *s) +#include "initial-state.h" // Internal Prototypes -static void test(TestState *); -static void test_initial_state(TestState *); static void tests(TestState *); -decl_test(initial_test_count); -decl_test(initial_pass_count); -decl_test(initial_fail_count); -decl_test(initial_pend_count); -decl_test(initial_first_log); -decl_test(initial_last_log); -decl_test(initial_ptr); // Public Functions @@ -63,80 +52,4 @@ tests(TestState *s) test_initial_state(s); } -static void -test_initial_state(TestState *s) -{ - print("Testing initial state\n"); - run_test(s, &initial_test_count); - run_test(s, &initial_pass_count); - run_test(s, &initial_fail_count); - run_test(s, &initial_pend_count); - run_test(s, &initial_first_log); - run_test(s, &initial_last_log); - run_test(s, &initial_ptr); -} - -def_test(initial_test_count, s) -{ - TestState *scpy = s->ptr; - print("\trun\n"); - if (scpy->run == 0) return test_success; - append_test_log(s, "initial run was nonzero"); - return test_failure; -} - -def_test(initial_pass_count, s) -{ - TestState *scpy = s->ptr; - print("\tpassed\n"); - if (scpy->passed == 0) return test_success; - append_test_log(s, "initial passed was nonzero"); - return test_failure; -} - -def_test(initial_fail_count, s) -{ - TestState *scpy = s->ptr; - print("\tfailed\n"); - if (scpy->failed == 0) return test_success; - append_test_log(s, "initial failed was nonzero"); - return test_failure; -} - -def_test(initial_pend_count, s) -{ - TestState *scpy = s->ptr; - print("\tpending\n"); - if (scpy->pending == 0) return test_success; - append_test_log(s, "initial pending was nonzero"); - return test_failure; -} - -def_test(initial_first_log, s) -{ - TestState *scpy = s->ptr; - print("\tfirst_log\n"); - if (scpy->first_log == 0) return test_success; - append_test_log(s, "initial first_log was not null"); - return test_failure; -} - -def_test(initial_last_log, s) -{ - TestState *scpy = s->ptr; - print("\tlast_log\n"); - if (scpy->last_log == 0) return test_success; - append_test_log(s, "initial last_log was not null"); - return test_failure; -} - -def_test(initial_ptr, s) -{ - TestState *scpy = s->ptr; - print("\tptr\n"); - if (scpy->ptr == 0) return test_success; - append_test_log(s, "initial ptr was not null"); - return test_failure; -} - //jl