Suppress some false positive coverity results.

It apparently does not understand CuTest code well?
Add a check for Lua eff_skill binding.
This commit is contained in:
Enno Rehling 2018-05-19 20:53:51 +02:00
parent 76b163dc07
commit dfa0ff09d1
5 changed files with 33 additions and 7 deletions

View file

@ -486,3 +486,13 @@ function test_rising_undead()
assert_equal(2, u.number) assert_equal(2, u.number)
assert_equal(u.number, u:get_item('rustysword')) assert_equal(u.number, u:get_item('rustysword'))
end end
function test_dwarf_mining()
local f = faction.create('dwarf')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
u.name = 'Xolgrim'
u:set_skill('mining', 2)
assert_equal(2, u:get_skill('mining'))
assert_equal(4, u:eff_skill('mining'))
end

View file

@ -85,13 +85,15 @@ static void test_steal_okay(CuTest * tc) {
struct steal env; struct steal env;
race *rc; race *rc;
struct terrain_type *ter; struct terrain_type *ter;
message *msg;
test_setup(); test_setup();
ter = test_create_terrain("plain", LAND_REGION); ter = test_create_terrain("plain", LAND_REGION);
rc = test_create_race("human"); rc = test_create_race("human");
rc->flags = 0; rc->flags = 0;
setup_steal(&env, ter, rc); setup_steal(&env, ter, rc);
CuAssertPtrEquals(tc, 0, steal_message(env.u, 0)); CuAssertPtrEquals(tc, NULL, msg = steal_message(env.u, 0));
msg_release(msg);
test_teardown(); test_teardown();
} }
@ -739,6 +741,7 @@ static void test_expand_production(CuTest *tc) {
CuAssertPtrEquals(tc, u, results[0]->unit); CuAssertPtrEquals(tc, u, results[0]->unit);
CuAssertPtrEquals(tc, u, results[1]->unit); CuAssertPtrEquals(tc, u, results[1]->unit);
CuAssertIntEquals(tc, 0, u->n); CuAssertIntEquals(tc, 0, u->n);
free(results);
test_teardown(); test_teardown();
} }

View file

@ -40,12 +40,15 @@ static void setup_give(struct give *env) {
env->r = test_create_region(0, 0, ter); env->r = test_create_region(0, 0, ter);
env->src = test_create_unit(env->f1, env->r); env->src = test_create_unit(env->f1, env->r);
env->dst = env->f2 ? test_create_unit(env->f2, env->r) : 0;
env->itype = it_get_or_create(rt_get_or_create("money")); env->itype = it_get_or_create(rt_get_or_create("money"));
env->itype->flags |= ITF_HERB; env->itype->flags |= ITF_HERB;
if (env->f1 && env->f2) { if (env->f2) {
ally * al = ally_add(&env->f2->allies, env->f1); ally * al = ally_add(&env->f2->allies, env->f1);
al->status = HELP_GIVE; al->status = HELP_GIVE;
env->dst = test_create_unit(env->f2, env->r);
}
else {
env->dst = NULL;
} }
if (env->lang) { if (env->lang) {
locale_setstring(env->lang, env->itype->rtype->_name, "SILBER"); locale_setstring(env->lang, env->itype->rtype->_name, "SILBER");
@ -139,10 +142,12 @@ static void test_give_unit_to_ocean(CuTest * tc) {
static void test_give_men(CuTest * tc) { static void test_give_men(CuTest * tc) {
struct give env = { 0 }; struct give env = { 0 };
message * msg;
test_setup_ex(tc); test_setup_ex(tc);
env.f2 = env.f1 = test_create_faction(NULL); env.f2 = env.f1 = test_create_faction(NULL);
setup_give(&env); setup_give(&env);
CuAssertPtrEquals(tc, 0, give_men(1, env.src, env.dst, NULL)); CuAssertPtrEquals(tc, NULL, msg = give_men(1, env.src, env.dst, NULL));
msg_release(msg);
CuAssertIntEquals(tc, 2, env.dst->number); CuAssertIntEquals(tc, 2, env.dst->number);
CuAssertIntEquals(tc, 0, env.src->number); CuAssertIntEquals(tc, 0, env.src->number);
test_teardown(); test_teardown();
@ -222,10 +227,13 @@ static void test_give_men_in_ocean(CuTest * tc) {
static void test_give_men_too_many(CuTest * tc) { static void test_give_men_too_many(CuTest * tc) {
struct give env = { 0 }; struct give env = { 0 };
message * msg;
test_setup_ex(tc); test_setup_ex(tc);
env.f2 = env.f1 = test_create_faction(NULL); env.f2 = env.f1 = test_create_faction(NULL);
setup_give(&env); setup_give(&env);
CuAssertPtrEquals(tc, 0, give_men(2, env.src, env.dst, NULL)); CuAssertPtrEquals(tc, NULL, msg = give_men(2, env.src, env.dst, NULL));
msg_release(msg);
CuAssertIntEquals(tc, 2, env.dst->number); CuAssertIntEquals(tc, 2, env.dst->number);
CuAssertIntEquals(tc, 0, env.src->number); CuAssertIntEquals(tc, 0, env.src->number);
test_teardown(); test_teardown();

View file

@ -78,6 +78,7 @@ static void test_merge_split(CuTest *tc) {
static void test_noerror(CuTest *tc) { static void test_noerror(CuTest *tc) {
unit *u; unit *u;
struct locale *lang; struct locale *lang;
message *msg;
test_setup(); test_setup();
lang = test_create_locale(); lang = test_create_locale();
@ -85,8 +86,10 @@ static void test_noerror(CuTest *tc) {
u->thisorder = parse_order("!@move", lang); u->thisorder = parse_order("!@move", lang);
CuAssertIntEquals(tc, K_MOVE | CMD_QUIET | CMD_PERSIST, u->thisorder->command); CuAssertIntEquals(tc, K_MOVE | CMD_QUIET | CMD_PERSIST, u->thisorder->command);
CuAssertTrue(tc, !is_persistent(u->thisorder)); CuAssertTrue(tc, !is_persistent(u->thisorder));
CuAssertPtrEquals(tc, NULL, msg_error(u, u->thisorder, 100)); CuAssertPtrEquals(tc, NULL, msg = msg_error(u, u->thisorder, 100));
CuAssertPtrEquals(tc, NULL, msg_feedback(u, u->thisorder, "error_unit_not_found", NULL)); msg_release(msg);
CuAssertPtrEquals(tc, NULL, msg = msg_feedback(u, u->thisorder, "error_unit_not_found", NULL));
msg_release(msg);
test_teardown(); test_teardown();
} }

View file

@ -239,6 +239,7 @@ static void test_is_persistent(CuTest *tc) {
ord = parse_order("@invalid", lang); ord = parse_order("@invalid", lang);
CuAssertPtrEquals(tc, NULL, ord); CuAssertPtrEquals(tc, NULL, ord);
free_order(ord);
ord = parse_order("give", lang); ord = parse_order("give", lang);
CuAssertIntEquals(tc, K_GIVE, ord->command); CuAssertIntEquals(tc, K_GIVE, ord->command);
@ -290,6 +291,7 @@ static void test_is_silent(CuTest *tc) {
ord = parse_order("@invalid", lang); ord = parse_order("@invalid", lang);
CuAssertPtrEquals(tc, NULL, ord); CuAssertPtrEquals(tc, NULL, ord);
free_order(ord);
ord = parse_order("// comment", lang); ord = parse_order("// comment", lang);
CuAssertTrue(tc, is_persistent(ord)); CuAssertTrue(tc, is_persistent(ord));