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);