From e0085eac0c797add6302bb53e24b3e472684cc58 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 1 Mar 2017 19:52:23 +0100 Subject: [PATCH] write a test for get_addresses before modifying it. --- src/creport.c | 2 +- src/reports.c | 2 +- src/reports.h | 1 + src/reports.test.c | 27 +++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/creport.c b/src/creport.c index d2f50e816..99a9ede97 100644 --- a/src/creport.c +++ b/src/creport.c @@ -764,7 +764,6 @@ void cr_output_unit(stream *out, const region * r, const faction * f, } /* print faction information */ sf = visible_faction(NULL, u); - prefix = raceprefix(u); if (u->faction == f || omniscient(f)) { /* my own faction, full info */ const attrib *a = NULL; @@ -807,6 +806,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f, } } } + prefix = raceprefix(u); if (prefix) { prefix = mkname("prefix", prefix); stream_printf(out, "\"%s\";typprefix\n", translate(prefix, LOC(f->locale, diff --git a/src/reports.c b/src/reports.c index a70219b0b..acbc36f69 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1024,7 +1024,7 @@ static void add_travelthru_addresses(region *r, faction *f, selist **flist, int travelthru_map(r, cb_add_address, &cbdata); } -static void get_addresses(report_context * ctx) +void get_addresses(report_context * ctx) { /* "TODO: travelthru" */ region *r; diff --git a/src/reports.h b/src/reports.h index 4fab104ef..855234376 100644 --- a/src/reports.h +++ b/src/reports.h @@ -81,6 +81,7 @@ extern "C" { void prepare_report(report_context *ctx, struct faction *f); void finish_reports(report_context *ctx); + void get_addresses(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 e3ca5c89b..534cb2187 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -279,6 +279,32 @@ static void test_prepare_travelthru(CuTest *tc) { test_cleanup(); } +static void test_get_addresses(CuTest *tc) { + report_context ctx; + faction *f, *f2, *f1; + region *r; + int i; + + test_setup(); + f = test_create_faction(0); + f1 = test_create_faction(0); + f2 = test_create_faction(0); + r = test_create_region(0, 0, 0); + test_create_unit(f, r); + test_create_unit(f1, r); + test_create_unit(f2, r); + prepare_report(&ctx, f); + CuAssertPtrEquals(tc, r, ctx.first); + CuAssertPtrEquals(tc, NULL, ctx.last); + get_addresses(&ctx); + CuAssertPtrNotNull(tc, ctx.addresses); + CuAssertIntEquals(tc, 3, selist_length(ctx.addresses)); + CuAssertIntEquals(tc, 1, (i=0, selist_find(&ctx.addresses, &i, f1, NULL))); + CuAssertIntEquals(tc, 1, (i=0, selist_find(&ctx.addresses, &i, f2, NULL))); + CuAssertIntEquals(tc, 1, (i=0, selist_find(&ctx.addresses, &i, f, NULL))); + test_cleanup(); +} + void test_prepare_lighthouse_capacity(CuTest *tc) { building *b; building_type *btype; @@ -490,6 +516,7 @@ CuSuite *get_reports_suite(void) SUITE_ADD_TEST(suite, test_prepare_lighthouse_owners); SUITE_ADD_TEST(suite, test_prepare_lighthouse_capacity); SUITE_ADD_TEST(suite, test_prepare_travelthru); + SUITE_ADD_TEST(suite, test_get_addresses); SUITE_ADD_TEST(suite, test_reorder_units); SUITE_ADD_TEST(suite, test_seen_faction); SUITE_ADD_TEST(suite, test_regionid);