forked from github/server
Implement tests for magicpath. They are failing (Bug 2066).
Also move spell and race initialization code from being server-only into game_init, where tests can use it.
This commit is contained in:
parent
4b6d65fb16
commit
798b3d6ad6
|
@ -20,12 +20,14 @@
|
|||
#include <modules/xmas.h>
|
||||
#include <items/itemtypes.h>
|
||||
#include <attributes/attributes.h>
|
||||
#include <races/races.h>
|
||||
#include "chaos.h"
|
||||
#include "report.h"
|
||||
#include "items.h"
|
||||
#include "creport.h"
|
||||
#include "names.h"
|
||||
#include "wormhole.h"
|
||||
#include "spells.h"
|
||||
|
||||
void game_done(void)
|
||||
{
|
||||
|
@ -55,6 +57,8 @@ void game_init(void)
|
|||
register_nr();
|
||||
register_cr();
|
||||
|
||||
register_races();
|
||||
register_spells();
|
||||
register_names();
|
||||
register_resources();
|
||||
register_buildings();
|
||||
|
|
|
@ -2,7 +2,11 @@
|
|||
#include "types.h"
|
||||
#include "curse.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <util/attrib.h>
|
||||
#include <util/message.h>
|
||||
#include <tests.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
|
||||
|
@ -22,9 +26,46 @@ static void test_curse(CuTest * tc)
|
|||
CuAssertPtrEquals(tc, NULL, result);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
curse *c;
|
||||
region *r;
|
||||
unit *u;
|
||||
} curse_fixture;
|
||||
|
||||
static void setup_curse(curse_fixture *fix, const char *name) {
|
||||
test_cleanup();
|
||||
fix->r = test_create_region(0, 0, NULL);
|
||||
fix->u = test_create_unit(test_create_faction(NULL), fix->r);
|
||||
fix->c = create_curse(fix->u, &fix->r->attribs, ct_find(name), 1.0, 1, 1.0, 0);
|
||||
}
|
||||
|
||||
static void test_magicstreet(CuTest *tc) {
|
||||
curse_fixture fix;
|
||||
message *msg;
|
||||
setup_curse(&fix, "magicstreet");
|
||||
fix.c->duration = 3;
|
||||
msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0);
|
||||
CuAssertStrEquals(tc, "curseinfo::magicstreet", (const char *)msg->parameters[0].v);
|
||||
msg_release(msg);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_magicstreet_warning(CuTest *tc) {
|
||||
curse_fixture fix;
|
||||
message *msg;
|
||||
setup_curse(&fix, "magicstreet");
|
||||
fix.c->duration = 2;
|
||||
msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0);
|
||||
CuAssertStrEquals(tc, "curseinfo::magicstreetwarn", (const char *)msg->parameters[0].v);
|
||||
msg_release(msg);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_curse_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_curse);
|
||||
SUITE_ADD_TEST(suite, test_magicstreet);
|
||||
SUITE_ADD_TEST(suite, test_magicstreet_warning);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -1725,21 +1725,23 @@ int unit_max_hp(const unit * u)
|
|||
get_param_int(global.parameters, "rules.stamina", STAMINA_AFFECTS_HP);
|
||||
}
|
||||
h = u_race(u)->hitpoints;
|
||||
if (heal_ct == NULL)
|
||||
heal_ct = ct_find("healingzone");
|
||||
|
||||
if (rules_stamina & 1) {
|
||||
p = pow(effskill(u, SK_STAMINA) / 2.0, 1.5) * 0.2;
|
||||
h += (int)(h * p + 0.5);
|
||||
}
|
||||
|
||||
/* der healing curse veraendert die maximalen hp */
|
||||
if (u->region) {
|
||||
if (heal_ct == NULL)
|
||||
heal_ct = ct_find("healingzone");
|
||||
if (heal_ct) {
|
||||
curse *c = get_curse(u->region->attribs, heal_ct);
|
||||
if (c) {
|
||||
h = (int)(h * (1.0 + (curse_geteffect(c) / 100)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
|
|
|
@ -304,8 +304,6 @@ int main(int argc, char **argv)
|
|||
|
||||
L = lua_init();
|
||||
game_init();
|
||||
register_races();
|
||||
register_spells();
|
||||
bind_monsters(L);
|
||||
err = eressea_run(L, luafile);
|
||||
if (err) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <platform.h>
|
||||
#include <eressea.h>
|
||||
#include <kernel/config.h>
|
||||
#include <CuTest.h>
|
||||
#include <stdio.h>
|
||||
|
@ -30,7 +31,7 @@ int RunAllTests(void)
|
|||
int fail_count, flags = log_flags;
|
||||
|
||||
log_flags = LOG_FLUSH | LOG_CPERROR;
|
||||
kernel_init();
|
||||
game_init();
|
||||
|
||||
/* self-test */
|
||||
RUN_TESTS(suite, tests);
|
||||
|
@ -86,7 +87,7 @@ int RunAllTests(void)
|
|||
log_flags = flags;
|
||||
fail_count = suite->failCount;
|
||||
CuSuiteDelete(suite);
|
||||
kernel_done();
|
||||
game_done();
|
||||
return fail_count;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue