Compare commits
4 Commits
daf189dc8d
...
17ad81f6b6
Author | SHA1 | Date | |
---|---|---|---|
17ad81f6b6 | |||
c6dd2559f8 | |||
3b616f2e22 | |||
23ed415852 |
|
@ -52,6 +52,7 @@ static void mf_chk_first(TestState *, void *);
|
||||||
static void mf_chk_second(TestState *, void *);
|
static void mf_chk_second(TestState *, void *);
|
||||||
static void mf_chk_third(TestState*, void *);
|
static void mf_chk_third(TestState*, void *);
|
||||||
static void mk_log_data(LogData *);
|
static void mk_log_data(LogData *);
|
||||||
|
static void clean_entry(TestLogEntry *);
|
||||||
|
|
||||||
static void chk_ptr_chg(
|
static void chk_ptr_chg(
|
||||||
TestState *,
|
TestState *,
|
||||||
|
@ -128,6 +129,11 @@ missing_first(TestState *s)
|
||||||
append_test_log(&ld.state, "baz");
|
append_test_log(&ld.state, "baz");
|
||||||
test_context_with(s, "first_log", mf_chk_first, &ld);
|
test_context_with(s, "first_log", mf_chk_first, &ld);
|
||||||
test_context_with(s, "last_log", chk_last, &ld);
|
test_context_with(s, "last_log", chk_last, &ld);
|
||||||
|
TestLogEntry
|
||||||
|
*context = ld.second.next,
|
||||||
|
*warning = context->next;
|
||||||
|
clean_entry(context);
|
||||||
|
clean_entry(warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -197,8 +203,7 @@ chk_last(TestState *s, void *ptr)
|
||||||
chk_ptr_chg(s, 0, ld->state.last_log, &ld->second);
|
chk_ptr_chg(s, 0, ld->state.last_log, &ld->second);
|
||||||
chk_str_eq(s, "text", ld->state.last_log->text, "baz");
|
chk_str_eq(s, "text", ld->state.last_log->text, "baz");
|
||||||
chk_ptr_eq(s, "next", ld->state.last_log->next, 0);
|
chk_ptr_eq(s, "next", ld->state.last_log->next, 0);
|
||||||
free(ld->state.last_log->text);
|
clean_entry(ld->state.last_log);
|
||||||
free(ld->state.last_log);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -272,4 +277,11 @@ chk_ptr_chg_test(
|
||||||
chk_ptr_ne(s, "not null", actual, 0);
|
chk_ptr_ne(s, "not null", actual, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clean_entry(TestLogEntry *e)
|
||||||
|
{
|
||||||
|
free(e->text);
|
||||||
|
free(e);
|
||||||
|
}
|
||||||
|
|
||||||
//jl
|
//jl
|
||||||
|
|
|
@ -22,6 +22,8 @@ HFILES=\
|
||||||
util.h\
|
util.h\
|
||||||
initial-state.h\
|
initial-state.h\
|
||||||
run-test.h\
|
run-test.h\
|
||||||
|
run-test-with.h\
|
||||||
|
run-test-compare.h\
|
||||||
append-test-log.h\
|
append-test-log.h\
|
||||||
test-context.h
|
test-context.h
|
||||||
|
|
||||||
|
@ -29,6 +31,8 @@ OFILES=\
|
||||||
util.$O\
|
util.$O\
|
||||||
initial-state.$O\
|
initial-state.$O\
|
||||||
run-test.$O\
|
run-test.$O\
|
||||||
|
run-test-with.$O\
|
||||||
|
run-test-compare.$O\
|
||||||
append-test-log.$O\
|
append-test-log.$O\
|
||||||
test-context.$O
|
test-context.$O
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
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
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void test_run_test_compare(TestState *);
|
||||||
|
|
||||||
|
//jl
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
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-with.h"
|
||||||
|
|
||||||
|
// Internal Prototypes
|
||||||
|
|
||||||
|
static TestResult test_run_test_with_test(TestState *, void *);
|
||||||
|
|
||||||
|
// Public Functions
|
||||||
|
|
||||||
|
void
|
||||||
|
test_run_test_with(TestState *s)
|
||||||
|
{
|
||||||
|
TestState actual, expected;
|
||||||
|
|
||||||
|
// build initial state
|
||||||
|
mk_sample_state(&actual);
|
||||||
|
void
|
||||||
|
*pass_in = malloc(0),
|
||||||
|
*passed_in = 0;
|
||||||
|
actual.ptr = &passed_in;
|
||||||
|
|
||||||
|
// run it and see what was passed
|
||||||
|
run_test_with(&actual, test_run_test_with_test, pass_in);
|
||||||
|
chk_ptr_eq(s, "value passed", passed_in, pass_in);
|
||||||
|
|
||||||
|
// 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_in);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal Functions
|
||||||
|
|
||||||
|
static TestResult
|
||||||
|
test_run_test_with_test(TestState *s, void *ptr)
|
||||||
|
{
|
||||||
|
void **passed_in = s->ptr;
|
||||||
|
*passed_in = ptr;
|
||||||
|
return test_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
//jl
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern void test_run_test_with(TestState *);
|
||||||
|
|
||||||
|
//jl
|
|
@ -25,6 +25,8 @@
|
||||||
#include "../9unit.h"
|
#include "../9unit.h"
|
||||||
#include "initial-state.h"
|
#include "initial-state.h"
|
||||||
#include "run-test.h"
|
#include "run-test.h"
|
||||||
|
#include "run-test-with.h"
|
||||||
|
#include "run-test-compare.h"
|
||||||
#include "append-test-log.h"
|
#include "append-test-log.h"
|
||||||
#include "test-context.h"
|
#include "test-context.h"
|
||||||
|
|
||||||
|
@ -54,6 +56,8 @@ tests(TestState *s)
|
||||||
|
|
||||||
test_context_with(s, "initial state", test_initial_state, &scpy);
|
test_context_with(s, "initial state", test_initial_state, &scpy);
|
||||||
test_context(s, "run_test()", test_run_test);
|
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, "append_test_log()", test_append_test_log);
|
||||||
test_context(s, "test_context()", test_test_context);
|
test_context(s, "test_context()", test_test_context);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user