add a simple test for prepare_report.

TODO: it is _too_ simple.
This commit is contained in:
Enno Rehling 2016-09-14 21:46:57 +02:00
parent 929db73102
commit dfbc520203
3 changed files with 32 additions and 3 deletions

View File

@ -1388,7 +1388,7 @@ static void cb_add_seen(region *r, unit *u, void *cbdata) {
* this function may also update ctx->last and ctx->first for potential * this function may also update ctx->last and ctx->first for potential
* lighthouses and travelthru reports * lighthouses and travelthru reports
*/ */
static void prepare_report(report_context *ctx, faction *f) void prepare_report(report_context *ctx, faction *f)
{ {
region *r; region *r;
building *b; building *b;
@ -1454,7 +1454,7 @@ static void prepare_report(report_context *ctx, faction *f)
ctx->last = lastregion(f); ctx->last = lastregion(f);
} }
static void finish_reports(report_context *ctx) { void finish_reports(report_context *ctx) {
region *r; region *r;
ql_free(ctx->addresses); ql_free(ctx->addresses);
for (r = ctx->first; r != ctx->last; r = r->next) { for (r = ctx->first; r != ctx->last; r = r->next) {

View File

@ -74,7 +74,8 @@ extern "C" {
time_t report_time; time_t report_time;
} report_context; } report_context;
void prepare_seen(struct report_context *ctx); void prepare_report(report_context *ctx, struct faction *f);
void finish_reports(report_context *ctx);
typedef int(*report_fun) (const char *filename, report_context * ctx, typedef int(*report_fun) (const char *filename, report_context * ctx,
const char *charset); const char *charset);

View File

@ -222,9 +222,37 @@ static void test_arg_resources(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_prepare_report(CuTest *tc) {
report_context ctx;
faction *f;
region *r;
unit *u;
test_setup();
f = test_create_faction(0);
r = test_create_region(0, 0, 0);
prepare_report(&ctx, f);
CuAssertPtrEquals(tc, 0, ctx.first);
CuAssertPtrEquals(tc, 0, ctx.last);
CuAssertIntEquals(tc, seen_none, r->seen.mode);
finish_reports(&ctx);
u = test_create_unit(f, r);
prepare_report(&ctx, f);
CuAssertPtrEquals(tc, r, ctx.first);
CuAssertPtrEquals(tc, 0, ctx.last);
CuAssertIntEquals(tc, seen_unit, r->seen.mode);
finish_reports(&ctx);
CuAssertIntEquals(tc, seen_none, r->seen.mode);
test_cleanup();
}
CuSuite *get_reports_suite(void) CuSuite *get_reports_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_prepare_report);
SUITE_ADD_TEST(suite, test_reorder_units); SUITE_ADD_TEST(suite, test_reorder_units);
SUITE_ADD_TEST(suite, test_seen_faction); SUITE_ADD_TEST(suite, test_seen_faction);
SUITE_ADD_TEST(suite, test_regionid); SUITE_ADD_TEST(suite, test_regionid);