9unit/test/run-test-compare.c

88 lines
1.9 KiB
C
Raw Normal View History

2023-11-23 15:23:23 -05:00
/*
9unit
Copyright (C) Jonathan Lamothe <jonathan@jlamothe.net>
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
<http://www.gnu.org/licenses/>.
*/
#include <u.h>
#include <libc.h>
#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