backfill test that demonstrates bug 2305.

This commit is contained in:
Enno Rehling 2017-03-08 20:15:41 +01:00
parent 4bda1a34e0
commit 77abd703bd
4 changed files with 83 additions and 20 deletions

View File

@ -25,9 +25,9 @@ extern "C" {
struct attrib; struct attrib;
extern struct attrib_type at_otherfaction; extern struct attrib_type at_otherfaction;
extern struct faction *get_otherfaction(const struct unit *u); struct faction *get_otherfaction(const struct unit *u);
extern struct attrib *make_otherfaction(struct faction *f); struct attrib *make_otherfaction(struct faction *f);
extern struct faction *visible_faction(const struct faction *f, struct faction *visible_faction(const struct faction *f,
const struct unit *u); const struct unit *u);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -27,6 +27,7 @@
#include <util/message.h> #include <util/message.h>
#include <attributes/key.h> #include <attributes/key.h>
#include <attributes/otherfaction.h>
#include <selist.h> #include <selist.h>
#include <stream.h> #include <stream.h>
@ -157,48 +158,95 @@ static void test_sparagraph(CuTest *tc) {
freestrlist(sp); freestrlist(sp);
} }
static void test_bufunit_bug_2305(CuTest *tc) { static void test_bufunit_fstealth(CuTest *tc) {
unit *u;
faction *f1, *f2; faction *f1, *f2;
region *r; region *r;
unit *u;
ally *al; ally *al;
char buf[1024]; char buf[256];
struct locale *lang;
test_setup(); test_setup();
r = test_create_region(0, 0, 0); lang = get_or_create_locale("de");
locale_setstring(lang, "status_aggressive", "aggressive");
locale_setstring(lang, "anonymous", "anonymous");
f1 = test_create_faction(0); f1 = test_create_faction(0);
f1->locale = lang;
f2 = test_create_faction(0); f2 = test_create_faction(0);
f2->locale = lang;
r = test_create_region(0, 0, 0);
u = test_create_unit(f1, r); u = test_create_unit(f1, r);
faction_setname(u->faction, "UFO"); faction_setname(f1, "UFO");
renumber_faction(u->faction, 1); renumber_faction(f1, 1);
faction_setname(f2, "TWW");
renumber_faction(f2, 2);
unit_setname(u, "Hodor"); unit_setname(u, "Hodor");
unit_setid(u, 1); unit_setid(u, 1);
key_set(&u->attribs, 42, 42); key_set(&u->attribs, 42, 42);
/* report to self */ /* report to ourselves */
bufunit(f1, u, 0, seen_unit, buf, sizeof(buf)); bufunit(f1, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressive.", buf); CuAssertStrEquals(tc, "Hodor (1), 1 human, aggressive.", buf);
/* report to another faction */ /* ... also when we are anonymous */
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf)); u->flags |= UFL_ANON_FACTION;
CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buf); bufunit(f1, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human, aggressive.", buf);
u->flags &= ~UFL_ANON_FACTION;
/* we see that our unit is cloaked */
set_factionstealth(u, f2);
CuAssertPtrNotNull(tc, u->attribs);
bufunit(f1, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), TWW (2), 1 human, aggressive.", buf);
/* ... also when we are anonymous */
u->flags |= UFL_ANON_FACTION;
bufunit(f1, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human, aggressive.", buf);
u->flags &= ~UFL_ANON_FACTION;
/* we can see that someone is presenting as us */
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), TWW (2), 1 human.", buf);
/* ... but not if they are anonymous */
u->flags |= UFL_ANON_FACTION;
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf);
u->flags &= ~UFL_ANON_FACTION;
/* we see the same thing as them when we are an ally */
al = ally_add(&f1->allies, f2); al = ally_add(&f1->allies, f2);
al->status = HELP_FSTEALTH; al->status = HELP_FSTEALTH;
/* report to an allied faction (bug 2305) */
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf)); bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buf); CuAssertStrEquals(tc, "Hodor (1), TWW (2) (UFO (1)), 1 human.", buf);
/* ... also when they are anonymous */
u->flags |= UFL_ANON_FACTION;
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf);
u->flags &= ~UFL_ANON_FACTION;
/* fstealth has no influence when we are allies, same results again */
set_factionstealth(u, NULL);
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), UFO(1), 1 human.", buf);
u->flags |= UFL_ANON_FACTION;
bufunit(f2, u, 0, seen_unit, buf, sizeof(buf));
CuAssertStrEquals(tc, "Hodor (1), anonymous, 1 human.", buf);
u->flags &= ~UFL_ANON_FACTION;
test_cleanup(); test_cleanup();
} }
static void test_write_unit(CuTest *tc) { static void test_bufunit(CuTest *tc) {
unit *u; unit *u;
faction *f; faction *f;
race *rc; race *rc;
struct locale *lang; struct locale *lang;
char buffer[1024]; char buffer[256];
test_setup(); test_setup();
rc = rc_get_or_create("human"); rc = rc_get_or_create("human");
@ -231,6 +279,7 @@ static void test_write_unit(CuTest *tc) {
f->locale = get_or_create_locale("de"); f->locale = get_or_create_locale("de");
bufunit(f, u, 0, 0, buffer, sizeof(buffer)); bufunit(f, u, 0, 0, buffer, sizeof(buffer));
CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buffer); CuAssertStrEquals(tc, "Hodor (1), UFO (1), 1 human.", buffer);
test_cleanup(); test_cleanup();
} }
@ -620,8 +669,8 @@ CuSuite *get_reports_suite(void)
SUITE_ADD_TEST(suite, test_seen_faction); SUITE_ADD_TEST(suite, test_seen_faction);
SUITE_ADD_TEST(suite, test_regionid); SUITE_ADD_TEST(suite, test_regionid);
SUITE_ADD_TEST(suite, test_sparagraph); SUITE_ADD_TEST(suite, test_sparagraph);
SUITE_ADD_TEST(suite, test_write_unit); SUITE_ADD_TEST(suite, test_bufunit);
SUITE_ADD_TEST(suite, test_bufunit_bug_2305); SUITE_ADD_TEST(suite, test_bufunit_fstealth);
SUITE_ADD_TEST(suite, test_arg_resources); SUITE_ADD_TEST(suite, test_arg_resources);
return suite; return suite;
} }

View File

@ -3,6 +3,7 @@ IF EXIST ..\build-vs10 SET BUILD=..\build-vs10\eressea\Debug
IF EXIST ..\build-vs11 SET BUILD=..\build-vs11\eressea\Debug IF EXIST ..\build-vs11 SET BUILD=..\build-vs11\eressea\Debug
IF EXIST ..\build-vs12 SET BUILD=..\build-vs12\eressea\Debug IF EXIST ..\build-vs12 SET BUILD=..\build-vs12\eressea\Debug
IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug
IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug
SET SERVER=%BUILD%\eressea.exe SET SERVER=%BUILD%\eressea.exe
%BUILD%\test_eressea.exe %BUILD%\test_eressea.exe
%SERVER% ..\scripts\run-tests.lua %SERVER% ..\scripts\run-tests.lua

13
vs2017-build.bat Normal file
View File

@ -0,0 +1,13 @@
@ECHO OFF
SET VSVERSION=15
SET SRCDIR=%CD%
CD ..
SET ERESSEA=%CD%
CD %SRCDIR%
IF exist build-vs%VSVERSION% goto HAVEDIR
mkdir build-vs%VSVERSION%
:HAVEDIR
cd build-vs%VSVERSION%
"%ProgramFiles%\CMake\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%/Lua/5.1;%ERESSEA%/dependencies-win32" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE ..
PAUSE