create_order takes variable arguments!

more snprintf removal.
This commit is contained in:
Enno Rehling 2017-01-07 21:19:58 +01:00
parent 3fb12d8f1e
commit 6d60b48b3f
4 changed files with 11 additions and 22 deletions

View File

@ -233,7 +233,6 @@ static void test_give_men_requires_contact(CuTest * tc) {
struct give env = { 0 }; struct give env = { 0 };
message * msg; message * msg;
order *ord; order *ord;
char cmd[32];
test_setup_ex(tc); test_setup_ex(tc);
env.f1 = test_create_faction(0); env.f1 = test_create_faction(0);
@ -244,8 +243,7 @@ static void test_give_men_requires_contact(CuTest * tc) {
CuAssertIntEquals(tc, 1, env.dst->number); CuAssertIntEquals(tc, 1, env.dst->number);
CuAssertIntEquals(tc, 1, env.src->number); CuAssertIntEquals(tc, 1, env.src->number);
_snprintf(cmd, sizeof(cmd), "%s ALLES PERSONEN", itoa36(env.dst->no)); ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no));
ord = create_order(K_GIVE, env.f1->locale, cmd);
test_clear_messages(env.f1); test_clear_messages(env.f1);
give_cmd(env.src, ord); give_cmd(env.src, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person")); CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person"));
@ -307,7 +305,6 @@ static void test_give(CuTest * tc) {
static void test_give_cmd(CuTest * tc) { static void test_give_cmd(CuTest * tc) {
struct give env = { 0 }; struct give env = { 0 };
struct order *ord; struct order *ord;
char cmd[32];
test_setup_ex(tc); test_setup_ex(tc);
env.lang = test_create_locale(); env.lang = test_create_locale();
@ -316,8 +313,7 @@ static void test_give_cmd(CuTest * tc) {
i_change(&env.src->items, env.itype, 10); i_change(&env.src->items, env.itype, 10);
_snprintf(cmd, sizeof(cmd), "%s 5 %s", itoa36(env.dst->no), LOC(env.f1->locale, env.itype->rtype->_name)); ord = create_order(K_GIVE, env.f1->locale, "%s 5 %s", itoa36(env.dst->no), LOC(env.f1->locale, env.itype->rtype->_name));
ord = create_order(K_GIVE, env.f1->locale, cmd);
assert(ord); assert(ord);
give_cmd(env.src, ord); give_cmd(env.src, ord);
CuAssertIntEquals(tc, 5, i_get(env.src->items, env.itype)); CuAssertIntEquals(tc, 5, i_get(env.src->items, env.itype));
@ -330,7 +326,6 @@ static void test_give_cmd(CuTest * tc) {
static void test_give_herbs(CuTest * tc) { static void test_give_herbs(CuTest * tc) {
struct give env = { 0 }; struct give env = { 0 };
struct order *ord; struct order *ord;
char cmd[32];
test_setup_ex(tc); test_setup_ex(tc);
test_create_world(); test_create_world();
@ -338,8 +333,7 @@ static void test_give_herbs(CuTest * tc) {
setup_give(&env); setup_give(&env);
i_change(&env.src->items, env.itype, 10); i_change(&env.src->items, env.itype, 10);
_snprintf(cmd, sizeof(cmd), "%s %s", itoa36(env.dst->no), LOC(env.f1->locale, parameters[P_HERBS])); ord = create_order(K_GIVE, env.f1->locale, "%s %s", itoa36(env.dst->no), LOC(env.f1->locale, parameters[P_HERBS]));
ord = create_order(K_GIVE, env.f1->locale, cmd);
assert(ord); assert(ord);
give_cmd(env.src, ord); give_cmd(env.src, ord);

View File

@ -801,10 +801,10 @@ static void json_settings(cJSON *json) {
else { else {
char value[32]; char value[32];
if (child->type == cJSON_Number && child->valuedouble && child->valueint<child->valuedouble) { if (child->type == cJSON_Number && child->valuedouble && child->valueint<child->valuedouble) {
_snprintf(value, sizeof(value), "%f", child->valuedouble); sprintf(value, "%f", child->valuedouble);
} }
else { else {
_snprintf(value, sizeof(value), "%d", child->valueint); sprintf(value, "%d", child->valueint);
} }
config_set(child->string, value); config_set(child->string, value);
} }

View File

@ -140,37 +140,34 @@ static void test_scale_number(CuTest *tc) {
static void test_unit_name(CuTest *tc) { static void test_unit_name(CuTest *tc) {
unit *u; unit *u;
char name[32];
test_cleanup(); test_cleanup();
test_create_world(); test_create_world();
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
renumber_unit(u, 666);
unit_setname(u, "Hodor"); unit_setname(u, "Hodor");
_snprintf(name, sizeof(name), "Hodor (%s)", itoa36(u->no)); CuAssertStrEquals(tc, "Hodor (ii)", unitname(u));
CuAssertStrEquals(tc, name, unitname(u));
test_cleanup(); test_cleanup();
} }
static void test_unit_name_from_race(CuTest *tc) { static void test_unit_name_from_race(CuTest *tc) {
unit *u; unit *u;
char name[32];
struct locale *lang; struct locale *lang;
test_cleanup(); test_cleanup();
test_create_world(); test_create_world();
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
renumber_unit(u, 666);
unit_setname(u, NULL); unit_setname(u, NULL);
lang = get_or_create_locale("de"); lang = get_or_create_locale("de");
locale_setstring(lang, rc_name_s(u->_race, NAME_SINGULAR), "Mensch"); locale_setstring(lang, rc_name_s(u->_race, NAME_SINGULAR), "Mensch");
locale_setstring(lang, rc_name_s(u->_race, NAME_PLURAL), "Menschen"); locale_setstring(lang, rc_name_s(u->_race, NAME_PLURAL), "Menschen");
_snprintf(name, sizeof(name), "Mensch (%s)", itoa36(u->no)); CuAssertStrEquals(tc, "Mensch (ii)", unitname(u));
CuAssertStrEquals(tc, name, unitname(u));
CuAssertStrEquals(tc, "Mensch", unit_getname(u)); CuAssertStrEquals(tc, "Mensch", unit_getname(u));
u->number = 2; u->number = 2;
_snprintf(name, sizeof(name), "Menschen (%s)", itoa36(u->no)); CuAssertStrEquals(tc, "Menschen (ii)", unitname(u));
CuAssertStrEquals(tc, name, unitname(u));
CuAssertStrEquals(tc, "Menschen", unit_getname(u)); CuAssertStrEquals(tc, "Menschen", unit_getname(u));
test_cleanup(); test_cleanup();

View File

@ -521,7 +521,6 @@ static void test_pay_cmd_other_building(CuTest *tc) {
order *ord; order *ord;
faction *f; faction *f;
building *b; building *b;
char cmd[32];
test_setup(); test_setup();
setup_pay_cmd(&fix); setup_pay_cmd(&fix);
@ -531,8 +530,7 @@ static void test_pay_cmd_other_building(CuTest *tc) {
config_set("rules.region_owner_pay_building", "lighthouse"); config_set("rules.region_owner_pay_building", "lighthouse");
update_owners(b->region); update_owners(b->region);
_snprintf(cmd, sizeof(cmd), "NOT %s", itoa36(b->no)); ord = create_order(K_PAY, f->locale, "NOT %s", itoa36(b->no));
ord = create_order(K_PAY, f->locale, cmd);
assert(ord); assert(ord);
CuAssertPtrEquals(tc, fix.u1, building_owner(b)); CuAssertPtrEquals(tc, fix.u1, building_owner(b));
CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord)); CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord));