TARNE PARTEI creport test

This commit is contained in:
Enno Rehling 2017-03-01 14:59:20 +01:00
parent e2e602e7ba
commit fc8e6dc6de
4 changed files with 70 additions and 22 deletions

View File

@ -1,6 +1,7 @@
#include <platform.h> #include <platform.h>
#include "creport.h" #include "creport.h"
#include "move.h" #include "move.h"
#include "spy.h"
#include "travelthru.h" #include "travelthru.h"
#include "keyword.h" #include "keyword.h"
@ -48,9 +49,59 @@ static void test_cr_unit(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static int cr_get_int(stream *strm, const char *match, int def)
{
char line[1024];
strm->api->rewind(strm->handle);
while (strm->api->readln(strm->handle, line, sizeof(line))==0) {
if (strstr(line, match)) {
return atoi(line);
}
}
return def;
}
static void test_cr_factionstealth(CuTest *tc) {
stream strm;
faction *f1, *f2, *fr;
region *r;
unit *u;
test_setup();
mstream_init(&strm);
f1 = test_create_faction(0);
f2 = test_create_faction(0);
fr = test_create_faction(0);
r = test_create_region(0, 0, 0);
u = test_create_unit(f1, r);
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));
set_factionstealth(u, f2);
CuAssertPtrNotNull(tc, u->attribs);
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));
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));
mstream_done(&strm);
test_cleanup();
}
CuSuite *get_creport_suite(void) CuSuite *get_creport_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_cr_unit); SUITE_ADD_TEST(suite, test_cr_unit);
SUITE_ADD_TEST(suite, test_cr_factionstealth);
return suite; return suite;
} }

View File

@ -178,7 +178,7 @@ int spy_cmd(unit * u, struct order *ord)
return 0; return 0;
} }
void set_factionstealth(unit * u, faction * f) static bool can_set_factionstealth(const unit * u, const faction * f)
{ {
region *lastr = NULL; region *lastr = NULL;
/* for all units mu of our faction, check all the units in the region /* for all units mu of our faction, check all the units in the region
@ -194,7 +194,7 @@ void set_factionstealth(unit * u, faction * f)
faction *fv = visible_faction(f, ru); faction *fv = visible_faction(f, ru);
if (fv == f) { if (fv == f) {
if (cansee(f, lastr, ru, 0)) if (cansee(f, lastr, ru, 0))
break; return true;
} }
} }
ru = ru->next; ru = ru->next;
@ -204,13 +204,15 @@ void set_factionstealth(unit * u, faction * f)
} }
mu = mu->nextF; mu = mu->nextF;
} }
if (mu != NULL) { return true;
}
void set_factionstealth(unit *u, faction *f) {
attrib *a = a_find(u->attribs, &at_otherfaction); attrib *a = a_find(u->attribs, &at_otherfaction);
if (!a) if (!a)
a = a_add(&u->attribs, make_otherfaction(f)); a = a_add(&u->attribs, make_otherfaction(f));
else else
a->data.v = f; a->data.v = f;
}
} }
int setstealth_cmd(unit * u, struct order *ord) int setstealth_cmd(unit * u, struct order *ord)
@ -315,7 +317,7 @@ int setstealth_cmd(unit * u, struct order *ord)
} }
else { else {
struct faction *f = findfaction(nr); struct faction *f = findfaction(nr);
if (f == NULL) { if (f == NULL || !can_set_factionstealth(u, f)) {
cmistake(u, ord, 66, MSG_EVENT); cmistake(u, ord, 66, MSG_EVENT);
break; break;
} }

View File

@ -26,12 +26,15 @@ extern "C" {
struct region; struct region;
struct strlist; struct strlist;
struct order; struct order;
struct faction;
extern int setstealth_cmd(struct unit *u, struct order *ord); int setstealth_cmd(struct unit *u, struct order *ord);
extern int spy_cmd(struct unit *u, struct order *ord); int spy_cmd(struct unit *u, struct order *ord);
extern int sabotage_cmd(struct unit *u, struct order *ord); int sabotage_cmd(struct unit *u, struct order *ord);
extern void spy_message(int spy, const struct unit *u, void spy_message(int spy, const struct unit *u,
const struct unit *target); const struct unit *target);
void set_factionstealth(struct unit * u, struct faction * f);
#define OCEAN_SWIMMER_CHANCE 0.1 #define OCEAN_SWIMMER_CHANCE 0.1
#define CANAL_SWIMMER_CHANCE 0.9 #define CANAL_SWIMMER_CHANCE 0.9

View File

@ -50,14 +50,6 @@ static void test_simple_spy_message(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void set_factionstealth(unit *u, faction *f) {
attrib *a = a_find(u->attribs, &at_otherfaction);
if (!a)
a = a_add(&u->attribs, make_otherfaction(f));
else
a->data.v = f;
}
static void test_all_spy_message(CuTest *tc) { static void test_all_spy_message(CuTest *tc) {
spy_fixture fix; spy_fixture fix;
item_type *itype; item_type *itype;