add tests for visible_unit, remove unused cansee_ex

This commit is contained in:
Enno Rehling 2017-12-23 17:49:30 +01:00
parent 1b13f6119b
commit 5dabd19504
7 changed files with 33 additions and 30 deletions

View File

@ -246,15 +246,17 @@ int lua_do(lua_State * L)
{
int status = loadline(L);
if (status != -1) {
if (status == 0)
if (status == 0) {
status = docall(L, 0, 0);
}
report(L, status);
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
lua_getglobal(L, "print");
lua_insert(L, 1);
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) {
l_message(NULL, lua_pushfstring(L, "error calling `print' (%s)",
lua_tostring(L, -1)));
lua_tostring(L, -1)));
}
}
}
lua_settop(L, 0); /* clear stack */

View File

@ -1481,7 +1481,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r)
/* visible units */
for (u = r->units; u; u = u->next) {
if (visible_unit(u, f, stealthmod)) {
if (visible_unit(u, f, stealthmod, r->seen.mode)) {
cr_output_unit_compat(F, r, f, u, r->seen.mode);
}
}

View File

@ -1679,25 +1679,6 @@ static void test_cansee(CuTest *tc) {
test_cleanup();
}
static void test_cansee_spell(CuTest *tc) {
unit *u2;
faction *f;
test_setup();
f = test_create_faction(0);
u2 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
CuAssertTrue(tc, cansee_ex(f, u2->region, u2, 0, seen_spell));
CuAssertTrue(tc, cansee_ex(f, u2->region, u2, 0, seen_battle));
set_level(u2, SK_STEALTH, 1);
CuAssertTrue(tc, !cansee_ex(f, u2->region, u2, 0, seen_spell));
CuAssertTrue(tc, cansee_ex(f, u2->region, u2, 1, seen_spell));
CuAssertTrue(tc, cansee_ex(f, u2->region, u2, 1, seen_battle));
test_cleanup();
}
static void test_cansee_ring(CuTest *tc) {
unit *u, *u2;
item_type *itype[2];
@ -1835,7 +1816,6 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_cansee);
SUITE_ADD_TEST(suite, test_cansee_ring);
SUITE_ADD_TEST(suite, test_cansee_sphere);
SUITE_ADD_TEST(suite, test_cansee_spell);
return suite;
}

View File

@ -2337,7 +2337,7 @@ report_plaintext(const char *filename, report_context * ctx,
}
}
while (u && !u->ship) {
if (visible_unit(u, f, stealthmod)) {
if (visible_unit(u, f, stealthmod, r->seen.mode)) {
nr_unit(out, f, u, 4, r->seen.mode);
}
assert(!u->building);

View File

@ -2225,16 +2225,14 @@ int count_travelthru(struct region *r, const struct faction *f) {
return data.n;
}
bool visible_unit(const unit *u, const faction *f, int stealthmod)
bool visible_unit(const unit *u, const faction *f, int stealthmod, seen_mode mode)
{
if (u->faction == f) {
return true;
}
else {
const region *r = u->region;
seen_mode mode = r->seen.mode;
if (stealthmod > INT_MIN && mode >= seen_unit) {
return cansee_ex(f, r, u, stealthmod, mode);
return cansee(f, u->region, u, stealthmod);
}
}
return false;

View File

@ -137,7 +137,7 @@ extern "C" {
int count_travelthru(struct region *r, const struct faction *f);
const char *get_mailcmd(const struct locale *loc);
bool visible_unit(const struct unit *u, const struct faction *f, int stealthmod);
bool visible_unit(const struct unit *u, const struct faction *f, int stealthmod, seen_mode mode);
#define GR_PLURAL 0x01 /* grammar: plural */
#define MAX_INVENTORY 128 /* maimum number of different items in an inventory */

View File

@ -4,6 +4,7 @@
#include "calendar.h"
#include "keyword.h"
#include "lighthouse.h"
#include "laws.h"
#include "move.h"
#include "spells.h"
#include "spy.h"
@ -820,6 +821,27 @@ static void test_newbie_warning(CuTest *tc) {
test_cleanup();
}
static void test_cansee_spell(CuTest *tc) {
unit *u2;
faction *f;
test_setup();
f = test_create_faction(0);
u2 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
CuAssertTrue(tc, cansee(f, u2->region, u2, 0));
CuAssertTrue(tc, visible_unit(u2, f, 0, seen_spell));
CuAssertTrue(tc, visible_unit(u2, f, 0, seen_battle));
set_level(u2, SK_STEALTH, 1);
CuAssertTrue(tc, !cansee(f, u2->region, u2, 0));
CuAssertTrue(tc, cansee(f, u2->region, u2, 1));
CuAssertTrue(tc, visible_unit(u2, f, 1, seen_spell));
CuAssertTrue(tc, visible_unit(u2, f, 1, seen_battle));
test_cleanup();
}
CuSuite *get_reports_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -849,5 +871,6 @@ CuSuite *get_reports_suite(void)
SUITE_ADD_TEST(suite, test_arg_resources);
SUITE_ADD_TEST(suite, test_insect_warnings);
SUITE_ADD_TEST(suite, test_newbie_warning);
SUITE_ADD_TEST(suite, test_cansee_spell);
return suite;
}