diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 213543b77..95acbd4c0 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -25,9 +25,8 @@ #include #include -#include - #include +#include static void test_readwrite_data(CuTest * tc) { @@ -283,7 +282,9 @@ static void test_read_password_external(CuTest *tc) { FILE * F; test_setup(); - remove(pwfile); + if (remove(pwfile) != 0) { + errno = 0; + } f = test_create_faction(0); faction_setpassword(f, password_encode("secret", PASSWORD_DEFAULT)); CuAssertPtrNotNull(tc, f->_password); diff --git a/src/laws.test.c b/src/laws.test.c index 32144fc4d..66cb5ef10 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -522,7 +522,7 @@ static void test_pay_cmd_other_building(CuTest *tc) { building *b; char cmd[32]; - test_cleanup(); + test_setup(); setup_pay_cmd(&fix); f = fix.u1->faction; b = test_create_building(fix.u1->region, bt_get_or_create("lighthouse")); diff --git a/src/lighthouse.c b/src/lighthouse.c index 52ebc5aeb..441eb0458 100644 --- a/src/lighthouse.c +++ b/src/lighthouse.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -25,14 +26,12 @@ static attrib_type at_lighthouse = { */ void update_lighthouse(building * lh) { - if (is_building_type(lh->type, "lighthouse")) { + if (lh->size>0 && is_building_type(lh->type, "lighthouse")) { region *r = lh->region; int d = (int)log10(lh->size) + 1; int x; - if (lh->size > 0) { - r->flags |= RF_LIGHTHOUSE; - } + r->flags |= RF_LIGHTHOUSE; for (x = -d; x <= d; ++x) { int y; @@ -40,6 +39,7 @@ void update_lighthouse(building * lh) attrib *a; region *r2; int px = r->x + x, py = r->y + y; + pnormalize(&px, &py, rplane(r)); r2 = findregion(px, py); if (!r2 || !fval(r2->terrain, SEA_REGION)) diff --git a/src/study.test.c b/src/study.test.c index 0ecd7ae2e..1bab404d8 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -318,15 +318,58 @@ static void test_study_cmd(CuTest *tc) { test_cleanup(); } +static void test_study_magic(CuTest *tc) { + unit *u; + faction *f; + const struct locale *lang; + const struct resource_type *rtype; + + test_setup(); + init_resources(); + f = test_create_faction(0); + u = test_create_unit(f, test_create_region(0, 0, 0)); + lang = f->locale; + CuAssertPtrNotNull(tc, rtype = get_resourcetype(R_SILVER)); + u->thisorder = create_order(K_STUDY, lang, "%s", skillnames[SK_MAGIC]); + study_cmd(u, u->thisorder); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error178")); + free_order(u->thisorder); + + test_clear_messages(f); + u->thisorder = create_order(K_STUDY, lang, "%s %s", skillnames[SK_MAGIC], magic_school[M_GWYRRD]); + study_cmd(u, u->thisorder); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error65")); + + test_clear_messages(f); + i_change(&u->items, rtype->itype, 100); + study_cmd(u, u->thisorder); + CuAssertIntEquals(tc, M_GWYRRD, f->magiegebiet); + CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype)); + CuAssertPtrNotNull(tc, get_mage(u)); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error65")); + CuAssertIntEquals(tc, M_GWYRRD, get_mage(u)->magietyp); + + /* the static cost array in study_cost prevents this test: + test_clear_messages(f); + config_set("skills.cost.magic", "50"); + i_change(&u->items, rtype->itype, 50); + study_cmd(u, u->thisorder); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error65")); + */ + + test_cleanup(); +} + static void test_study_cost(CuTest *tc) { unit *u; const struct item_type *itype; + test_setup(); init_resources(); itype = get_resourcetype(R_SILVER)->itype; u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); scale_number(u, 2); - u->thisorder = create_order(K_STUDY, u->faction->locale, "ALCHEMY"); + u->thisorder = create_order(K_STUDY, u->faction->locale, skillnames[SK_ALCHEMY]); i_change(&u->items, itype, u->number * study_cost(u, SK_ALCHEMY)); learn_inject(); study_cmd(u, u->thisorder); @@ -505,6 +548,7 @@ CuSuite *get_study_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_study_cmd); SUITE_ADD_TEST(suite, test_study_cost); + SUITE_ADD_TEST(suite, test_study_magic); SUITE_ADD_TEST(suite, test_teach_cmd); SUITE_ADD_TEST(suite, test_teach_two); SUITE_ADD_TEST(suite, test_teach_one_to_many); diff --git a/src/tests.c b/src/tests.c index 1af387543..85aafd211 100644 --- a/src/tests.c +++ b/src/tests.c @@ -94,16 +94,14 @@ struct locale * test_create_locale(void) { for (i = 0; i != MAXKEYWORDS; ++i) { locale_setstring(loc, mkname("keyword", keywords[i]), keywords[i]); } - for (i = 0; i != MAXSKILLS; ++i) { - locale_setstring(loc, mkname("skill", skillnames[i]), skillnames[i]); - } for (i = 0; i != MAXPARAMS; ++i) { locale_setstring(loc, parameters[i], parameters[i]); test_translate_param(loc, i, parameters[i]); } - init_parameters(loc); - init_keywords(loc); - init_skills(loc); + for (i = 0; i != MAXMAGIETYP; ++i) { + locale_setstring(loc, mkname("school", magic_school[i]), magic_school[i]); + } + init_locale(loc); } return loc; } @@ -163,6 +161,13 @@ static void test_reset(void) { int i; turn = 0; default_locale = 0; + + if (errno) { + int error = errno; + errno = 0; + log_error("errno: %d (%s)", error, strerror(error)); + } + free_gamedata(); free_terrains(); free_resources(); @@ -184,13 +189,13 @@ static void test_reset(void) { for (i = 0; i != MAXKEYWORDS; ++i) { enable_keyword(i, true); } + random_source_reset(); + if (errno) { int error = errno; errno = 0; log_error("errno: %d (%s)", error, strerror(error)); } - - random_source_reset(); } void test_setup(void) {