From dfbc52020327d5475ae1f48c5a95a3b271043047 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 14 Sep 2016 21:46:57 +0200 Subject: [PATCH] add a simple test for prepare_report. TODO: it is _too_ simple. --- src/reports.c | 4 ++-- src/reports.h | 3 ++- src/reports.test.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/reports.c b/src/reports.c index 589053b1b..8a91bee63 100644 --- a/src/reports.c +++ b/src/reports.c @@ -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 * lighthouses and travelthru reports */ -static void prepare_report(report_context *ctx, faction *f) +void prepare_report(report_context *ctx, faction *f) { region *r; building *b; @@ -1454,7 +1454,7 @@ static void prepare_report(report_context *ctx, faction *f) ctx->last = lastregion(f); } -static void finish_reports(report_context *ctx) { +void finish_reports(report_context *ctx) { region *r; ql_free(ctx->addresses); for (r = ctx->first; r != ctx->last; r = r->next) { diff --git a/src/reports.h b/src/reports.h index 7e35d26f4..fd0efb591 100644 --- a/src/reports.h +++ b/src/reports.h @@ -74,7 +74,8 @@ extern "C" { time_t report_time; } 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, const char *charset); diff --git a/src/reports.test.c b/src/reports.test.c index 5cd7eed6d..dff9256d3 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -222,9 +222,37 @@ static void test_arg_resources(CuTest *tc) { 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 *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_prepare_report); SUITE_ADD_TEST(suite, test_reorder_units); SUITE_ADD_TEST(suite, test_seen_faction); SUITE_ADD_TEST(suite, test_regionid);