bug 2303: correct the test.

we cannot reuse the memstream.
need to recreate it for each test.
need to rewrite the code in creport.c, it is crazy.
This commit is contained in:
Enno Rehling 2017-03-06 20:37:17 +01:00
parent 1c72b0f297
commit 4b246863c0
2 changed files with 16 additions and 11 deletions

View File

@ -796,14 +796,14 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
else {
/* other unit. show visible faction, not u->faction */
stream_printf(out, "%d;Partei\n", sf ? sf->no : f->no);
if (sf == f) {
stream_printf(out, "1;Verraeter\n");
}
if (sf && sf != u->faction) {
if (alliedunit(u, f, HELP_FSTEALTH)) {
if (sf && sf != u->faction) {
stream_printf(out, "%d;Anderepartei\n", sf->no);
}
}
else if (sf == f) {
stream_printf(out, "1;Verraeter\n");
}
}
}
prefix = raceprefix(u);

View File

@ -71,39 +71,44 @@ static void test_cr_factionstealth(CuTest *tc) {
ally *al;
test_setup();
mstream_init(&strm);
f1 = test_create_faction(0);
f2 = test_create_faction(0);
r = test_create_region(0, 0, 0);
u = test_create_unit(f1, r);
mstream_init(&strm);
cr_output_unit(&strm, u->region, f1, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
mstream_done(&strm);
set_factionstealth(u, f2);
CuAssertPtrNotNull(tc, u->attribs);
mstream_init(&strm);
cr_output_unit(&strm, u->region, f1, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
mstream_done(&strm);
mstream_init(&strm);
cr_output_unit(&strm, u->region, f2, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, 1, cr_get_int(&strm, ";Verraeter", -1));
mstream_done(&strm);
al = ally_add(&f1->allies, f2);
al->status = HELP_FSTEALTH;
mstream_init(&strm);
cr_output_unit(&strm, u->region, f2, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, 1, cr_get_int(&strm, ";Verraeter", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
mstream_done(&strm);
test_cleanup();
}