From 17ad81f6b647df7843e95cafca303db76b8e090d Mon Sep 17 00:00:00 2001 From: jlamothe Date: Thu, 23 Nov 2023 20:23:23 +0000 Subject: [PATCH] testing run_test_compare() --- test/mkfile | 2 + test/run-test-compare.c | 87 +++++++++++++++++++++++++++++++++++++++++ test/run-test-compare.h | 24 ++++++++++++ test/tests.c | 2 + 4 files changed, 115 insertions(+) create mode 100644 test/run-test-compare.c create mode 100644 test/run-test-compare.h diff --git a/test/mkfile b/test/mkfile index 28f73d7..90a5722 100644 --- a/test/mkfile +++ b/test/mkfile @@ -23,6 +23,7 @@ HFILES=\ initial-state.h\ run-test.h\ run-test-with.h\ + run-test-compare.h\ append-test-log.h\ test-context.h @@ -31,6 +32,7 @@ OFILES=\ initial-state.$O\ run-test.$O\ run-test-with.$O\ + run-test-compare.$O\ append-test-log.$O\ test-context.$O diff --git a/test/run-test-compare.c b/test/run-test-compare.c new file mode 100644 index 0000000..dccbc18 --- /dev/null +++ b/test/run-test-compare.c @@ -0,0 +1,87 @@ +/* + + 9unit + Copyright (C) Jonathan Lamothe + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program. If not, see + . + +*/ + +#include +#include + +#include "../9unit.h" +#include "util.h" +#include "run-test-compare.h" + +// Internal Prototypes + +static TestResult +test_run_test_compare_test(TestState *, void *, void *); + +// Public Functions + +void +test_run_test_compare(TestState *s) +{ + TestState actual, expected; + + // build initial state + mk_sample_state(&actual); + void + *pass_in1 = malloc(1), + *pass_in2 = malloc(1), + *passed_in[2]; + for (int i = 0; i < 2; i++) + passed_in[i] = 0; + actual.ptr = passed_in; + + // run it and see what was passed + run_test_compare( + &actual, + test_run_test_compare_test, + pass_in1, + pass_in2 + ); + chk_ptr_eq(s, "first value passed", passed_in[0], pass_in1); + chk_ptr_eq(s, "second value passed", passed_in[1], pass_in2); + + // ensure the state was updated correctly + mk_sample_state(&expected); + expected.passed = 2; + expected.run = 7; + expected.ptr = &passed_in; + chk_TestState_eq(s, "resulting state", &actual, &expected); + + free(pass_in1); + free(pass_in2); +} + +// Internal Functions + +static TestResult +test_run_test_compare_test( + TestState *s, + void *ptr1, + void *ptr2 +) +{ + void **passed_in = s->ptr; + passed_in[0] = ptr1; + passed_in[1] = ptr2; + return test_success; +} + +//jl diff --git a/test/run-test-compare.h b/test/run-test-compare.h new file mode 100644 index 0000000..88562d7 --- /dev/null +++ b/test/run-test-compare.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 Lesser 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program. If not, see + . + +*/ + +extern void test_run_test_compare(TestState *); + +//jl diff --git a/test/tests.c b/test/tests.c index cea7959..eb06eb9 100644 --- a/test/tests.c +++ b/test/tests.c @@ -26,6 +26,7 @@ #include "initial-state.h" #include "run-test.h" #include "run-test-with.h" +#include "run-test-compare.h" #include "append-test-log.h" #include "test-context.h" @@ -56,6 +57,7 @@ tests(TestState *s) test_context_with(s, "initial state", test_initial_state, &scpy); test_context(s, "run_test()", test_run_test); test_context(s, "run_test_with()", test_run_test_with); + test_context(s, "run_test_compare()", test_run_test_compare); test_context(s, "append_test_log()", test_append_test_log); test_context(s, "test_context()", test_test_context); }