Merge branch 'stm2-bug2211_addendum' into develop

This commit is contained in:
Enno Rehling 2017-05-21 14:53:14 +02:00
commit 9525c8790c
2 changed files with 53 additions and 52 deletions

View File

@ -2390,6 +2390,7 @@ static void display_race(unit * u, const race * rc)
static void reshow_other(unit * u, struct order *ord, const char *s) {
int err = 21;
bool found = false;
if (s) {
const spell *sp = 0;
@ -2426,7 +2427,7 @@ static void reshow_other(unit * u, struct order *ord, const char *s) {
else {
display_item(u, itype);
}
return;
found = true;
}
if (sp) {
@ -2437,15 +2438,16 @@ static void reshow_other(unit * u, struct order *ord, const char *s) {
if (a != NULL) {
a_remove(&u->faction->attribs, a);
}
return;
found = true;
}
if (rc && u_race(u) == rc) {
display_race(u, rc);
return;
found = true;
}
}
cmistake(u, ord, err, MSG_EVENT);
if (!found)
cmistake(u, ord, err, MSG_EVENT);
}
static void reshow(unit * u, struct order *ord, const char *s, param_t p)

View File

@ -1363,53 +1363,6 @@ static void test_show_without_item(CuTest *tc)
test_cleanup();
}
static void test_show_elf(CuTest *tc) {
order *ord;
race * rc;
unit *u;
struct locale *loc;
message * msg;
const struct item_type *itype;
test_setup();
mt_register(mt_new_va("msg_event", "string:string", 0));
rc = test_create_race("elf");
itype = test_create_itemtype("elvenhorse");
loc = test_create_locale();
locale_setstring(loc, "elvenhorse", "Elfenpferd");
locale_setstring(loc, "elvenhorse_p", "Elfenpferde");
locale_setstring(loc, "race::elf_p", "Elfen");
locale_setstring(loc, "race::elf", "Elf");
init_locale(loc);
CuAssertPtrNotNull(tc, finditemtype("elf", loc));
CuAssertPtrNotNull(tc, findrace("elf", loc));
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
u->faction->locale = loc;
ord = create_order(K_RESHOW, loc, "Elf");
reshow_cmd(u, ord);
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error36") == NULL);
msg = test_find_messagetype(u->faction->msgs, "msg_event");
CuAssertPtrNotNull(tc, msg);
CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0);
test_clear_messages(u->faction);
i_change(&u->items, itype, 1);
reshow_cmd(u, ord);
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error36") == NULL);
msg = test_find_messagetype(u->faction->msgs, "msg_event");
CuAssertPtrNotNull(tc, msg);
CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0);
test_clear_messages(u->faction);
free_order(ord);
test_cleanup();
}
static void test_show_race(CuTest *tc) {
order *ord;
race * rc;
@ -1451,6 +1404,52 @@ static void test_show_race(CuTest *tc) {
test_cleanup();
}
static void test_show_both(CuTest *tc) {
order *ord;
race * rc;
unit *u;
struct locale *loc;
message * msg;
test_cleanup();
mt_register(mt_new_va("msg_event", "string:string", 0));
mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", 0));
rc = test_create_race("elf");
test_create_itemtype("elvenhorse");
loc = get_or_create_locale("de");
locale_setstring(loc, "elvenhorse", "Elfenpferd");
locale_setstring(loc, "elvenhorse_p", "Elfenpferde");
locale_setstring(loc, "iteminfo::elvenhorse", "Hiyaa!");
locale_setstring(loc, "race::elf_p", "Elfen");
locale_setstring(loc, "race::elf", "Elf");
init_locale(loc);
CuAssertPtrNotNull(tc, finditemtype("elf", loc));
CuAssertPtrNotNull(tc, findrace("elf", loc));
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
u->faction->locale = loc;
i_change(&u->items, finditemtype("elfenpferd", loc), 1);
ord = create_order(K_RESHOW, loc, "Elf");
reshow_cmd(u, ord);
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error36") == NULL);
msg = test_find_messagetype(u->faction->msgs, "msg_event");
CuAssertPtrNotNull(tc, msg);
CuAssertTrue(tc, memcmp("Elf:", msg->parameters[0].v, 4) == 0);
msg = test_find_messagetype(u->faction->msgs, "displayitem");
CuAssertPtrNotNull(tc, msg);
CuAssertTrue(tc, memcmp("Hiyaa!", msg->parameters[2].v, 4) == 0);
test_clear_messages(u->faction);
free_order(ord);
test_cleanup();
}
static int low_wage(const region * r, const faction * f, const race * rc, int in_turn) {
return 1;
}
static void test_immigration(CuTest * tc)
{
region *r;
@ -1618,8 +1617,8 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_name_building);
SUITE_ADD_TEST(suite, test_name_ship);
SUITE_ADD_TEST(suite, test_show_without_item);
SUITE_ADD_TEST(suite, test_show_elf);
SUITE_ADD_TEST(suite, test_show_race);
SUITE_ADD_TEST(suite, test_show_both);
SUITE_ADD_TEST(suite, test_immigration);
SUITE_ADD_TEST(suite, test_demon_hunger);
SUITE_ADD_TEST(suite, test_armedmen);