forked from github/server
test that two different volcano_dead messages are sent for units in different regions.
new test_find_messagetype_ex helper.
This commit is contained in:
parent
b56c48d95c
commit
9400a05a87
17
src/tests.c
17
src/tests.c
|
@ -377,17 +377,30 @@ const char * test_get_messagetype(const message *msg) {
|
||||||
return name;
|
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;
|
struct mlist *ml;
|
||||||
if (!msgs) return 0;
|
if (!msgs) return 0;
|
||||||
for (ml = msgs->begin; ml; ml = ml->next) {
|
for (ml = msgs->begin; ml; ml = ml->next) {
|
||||||
if (strcmp(name, test_get_messagetype(ml->msg)) == 0) {
|
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;
|
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) {
|
void test_clear_messages(faction *f) {
|
||||||
if (f->msgs) {
|
if (f->msgs) {
|
||||||
free_messagelist(f->msgs->begin);
|
free_messagelist(f->msgs->begin);
|
||||||
|
|
|
@ -51,6 +51,7 @@ extern "C" {
|
||||||
int RunAllTests(void);
|
int RunAllTests(void);
|
||||||
void test_translate_param(const struct locale *lang, param_t param, const char *text);
|
void test_translate_param(const struct locale *lang, param_t param, const char *text);
|
||||||
const char * test_get_messagetype(const struct message *msg);
|
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_find_messagetype(struct message_list *msgs, const char *name);
|
||||||
struct message * test_get_last_message(struct message_list *mlist);
|
struct message * test_get_last_message(struct message_list *mlist);
|
||||||
void test_clear_messages(struct faction *f);
|
void test_clear_messages(struct faction *f);
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
#include "volcano.h"
|
#include "volcano.h"
|
||||||
|
|
||||||
|
#include <kernel/faction.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/terrain.h>
|
#include <kernel/terrain.h>
|
||||||
|
#include <kernel/unit.h>
|
||||||
#include <kernel/messages.h>
|
#include <kernel/messages.h>
|
||||||
|
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
@ -31,6 +33,8 @@ static void test_volcano_update(CuTest *tc) {
|
||||||
|
|
||||||
static void test_volcano_outbreak(CuTest *tc) {
|
static void test_volcano_outbreak(CuTest *tc) {
|
||||||
region *r, *rn;
|
region *r, *rn;
|
||||||
|
unit *u1, *u2;
|
||||||
|
faction *f;
|
||||||
message *m;
|
message *m;
|
||||||
const struct terrain_type *t_volcano, *t_active;
|
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);
|
t_active = test_create_terrain("activevolcano", LAND_REGION);
|
||||||
r = test_create_region(0, 0, t_active);
|
r = test_create_region(0, 0, t_active);
|
||||||
rn = test_create_region(1, 0, t_volcano);
|
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);
|
volcano_outbreak(r, rn);
|
||||||
CuAssertPtrEquals(tc, (void *)t_active, (void *)r->terrain);
|
CuAssertPtrEquals(tc, (void *)t_active, (void *)r->terrain);
|
||||||
CuAssertIntEquals(tc, 0, rtrees(r, 0));
|
CuAssertIntEquals(tc, 0, rtrees(r, 0));
|
||||||
CuAssertIntEquals(tc, 0, rtrees(r, 1));
|
CuAssertIntEquals(tc, 0, rtrees(r, 1));
|
||||||
CuAssertIntEquals(tc, 0, rtrees(r, 2));
|
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(r->attribs, &at_reduceproduction));
|
||||||
CuAssertPtrNotNull(tc, a_find(rn->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();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue