diff --git a/src/tests.c b/src/tests.c index 120d62e12..be62fdde8 100644 --- a/src/tests.c +++ b/src/tests.c @@ -377,17 +377,30 @@ const char * test_get_messagetype(const message *msg) { return name; } -struct message * test_find_messagetype(struct message_list *msgs, const char *name) { +struct message * test_find_messagetype_ex(struct message_list *msgs, const char *name, struct message *prev) +{ struct mlist *ml; if (!msgs) return 0; for (ml = msgs->begin; ml; ml = ml->next) { if (strcmp(name, test_get_messagetype(ml->msg)) == 0) { - return ml->msg; + if (prev) { + if (ml->msg == prev) { + prev = NULL; + } + } + else { + return ml->msg; + } } } return 0; } +struct message * test_find_messagetype(struct message_list *msgs, const char *name) +{ + return test_find_messagetype_ex(msgs, name, NULL); +} + void test_clear_messages(faction *f) { if (f->msgs) { free_messagelist(f->msgs->begin); diff --git a/src/tests.h b/src/tests.h index d18ff6456..e31578beb 100644 --- a/src/tests.h +++ b/src/tests.h @@ -51,6 +51,7 @@ extern "C" { int RunAllTests(void); void test_translate_param(const struct locale *lang, param_t param, const char *text); const char * test_get_messagetype(const struct message *msg); + struct message * test_find_messagetype_ex(struct message_list *msgs, const char *name, struct message *prev); struct message * test_find_messagetype(struct message_list *msgs, const char *name); struct message * test_get_last_message(struct message_list *mlist); void test_clear_messages(struct faction *f); diff --git a/src/volcano.test.c b/src/volcano.test.c index 091628cb7..a79d08829 100644 --- a/src/volcano.test.c +++ b/src/volcano.test.c @@ -2,8 +2,10 @@ #include #include "volcano.h" +#include #include #include +#include #include #include @@ -31,6 +33,8 @@ static void test_volcano_update(CuTest *tc) { static void test_volcano_outbreak(CuTest *tc) { region *r, *rn; + unit *u1, *u2; + faction *f; message *m; const struct terrain_type *t_volcano, *t_active; @@ -40,18 +44,26 @@ static void test_volcano_outbreak(CuTest *tc) { t_active = test_create_terrain("activevolcano", LAND_REGION); r = test_create_region(0, 0, t_active); rn = test_create_region(1, 0, t_volcano); + f = test_create_faction(0); + u1 = test_create_unit(f, r); + u1->hp = u1->number; + u2 = test_create_unit(f, rn); + u2->hp = u2->number; volcano_outbreak(r, rn); CuAssertPtrEquals(tc, (void *)t_active, (void *)r->terrain); CuAssertIntEquals(tc, 0, rtrees(r, 0)); CuAssertIntEquals(tc, 0, rtrees(r, 1)); CuAssertIntEquals(tc, 0, rtrees(r, 2)); - CuAssertPtrNotNull(tc, m = test_find_messagetype(rn->msgs, "volcanooutbreak")); - CuAssertPtrEquals(tc, r, m->parameters[0].v); - CuAssertPtrEquals(tc, rn, m->parameters[1].v); CuAssertPtrNotNull(tc, a_find(r->attribs, &at_reduceproduction)); CuAssertPtrNotNull(tc, a_find(rn->attribs, &at_reduceproduction)); + CuAssertPtrNotNull(tc, m = test_find_messagetype(rn->msgs, "volcanooutbreak")); + CuAssertPtrEquals(tc, r, m->parameters[0].v); + CuAssertPtrEquals(tc, rn, m->parameters[1].v); + + CuAssertPtrNotNull(tc, m = test_find_messagetype_ex(f->msgs, "volcano_dead", NULL)); + CuAssertPtrNotNull(tc, m = test_find_messagetype_ex(f->msgs, "volcano_dead", m)); test_cleanup(); }