forked from github/server
Tests for GIVE UNIT and groups.
This commit is contained in:
parent
8ddca8ab0e
commit
cf7971bcfc
5 changed files with 44 additions and 8 deletions
|
@ -37,6 +37,35 @@ function setup()
|
|||
eressea.settings.set("study.random_progress", "0")
|
||||
end
|
||||
|
||||
function test_give_unit()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = create_faction('elf')
|
||||
local f2 = create_faction('elf')
|
||||
local u1, u2 = two_units(r, f1, f2)
|
||||
assert_equal(f1, u1.faction)
|
||||
assert_equal(f2, u2.faction)
|
||||
u2.name = 'Xolgrim'
|
||||
u2.group = 'Experten'
|
||||
assert_equal('Experten', u2.group)
|
||||
u1:add_order("HELFE " .. itoa36(f2.id) .. " GIB")
|
||||
u2:add_order("GIB " .. itoa36(u1.id) .. " EINHEIT")
|
||||
process_orders()
|
||||
assert_equal(f1, u2.faction)
|
||||
assert_nil(u2.group)
|
||||
end
|
||||
|
||||
function test_set_faction()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = create_faction('elf')
|
||||
local f2 = create_faction('elf')
|
||||
local u = one_unit(r, f1)
|
||||
u.group = 'Experten'
|
||||
assert_equal('Experten', u.group)
|
||||
u.faction = f2
|
||||
assert_equal(f2, u.faction)
|
||||
assert_nil(u.group)
|
||||
end
|
||||
|
||||
function test_locales()
|
||||
assert_equal(2, eressea.locale.direction("de", "Ost"))
|
||||
assert_equal(5, eressea.locale.direction("de", "westen"))
|
||||
|
|
|
@ -49,7 +49,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
static group *ghash[GMAXHASH];
|
||||
static int maxgid;
|
||||
|
||||
group *new_group(faction * f, const char *name, int gid)
|
||||
group *create_group(faction * f, const char *name, int gid)
|
||||
{
|
||||
group **gp = &f->groups;
|
||||
int index = gid % GMAXHASH;
|
||||
|
@ -63,6 +63,7 @@ group *new_group(faction * f, const char *name, int gid)
|
|||
if (gid > maxgid) maxgid = gid;
|
||||
g->name = str_strdup(name);
|
||||
g->gid = gid;
|
||||
g->f = f;
|
||||
|
||||
g->nexthash = ghash[index];
|
||||
return ghash[index] = g;
|
||||
|
@ -93,11 +94,15 @@ static int read_group(variant *var, void *owner, gamedata *data)
|
|||
{
|
||||
struct storage *store = data->store;
|
||||
group *g;
|
||||
unit * u = (unit *)owner;
|
||||
int gid;
|
||||
|
||||
READ_INT(store, &gid);
|
||||
var->v = g = find_group(gid);
|
||||
if (g != 0) {
|
||||
if (g != NULL) {
|
||||
if (g->f != u->faction) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
g->members++;
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
@ -184,7 +189,7 @@ group *join_group(unit * u, const char *name)
|
|||
if (name && name[0]) {
|
||||
g = find_groupbyname(u->faction->groups, name);
|
||||
if (g == NULL) {
|
||||
g = new_group(u->faction, name, ++maxgid);
|
||||
g = create_group(u->faction, name, ++maxgid);
|
||||
init_group(u->faction, g);
|
||||
}
|
||||
}
|
||||
|
@ -219,7 +224,7 @@ void read_groups(gamedata *data, faction * f)
|
|||
if (gid == 0)
|
||||
break;
|
||||
READ_STR(store, buf, sizeof(buf));
|
||||
g = new_group(f, buf, gid);
|
||||
g = create_group(f, buf, gid);
|
||||
read_allies(data, &g->allies);
|
||||
read_attribs(data, &g->attribs, g);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ extern "C" {
|
|||
extern void set_group(struct unit *u, struct group *g);
|
||||
extern struct group * get_group(const struct unit *u);
|
||||
extern void free_group(struct group *g);
|
||||
struct group *new_group(struct faction * f, const char *name, int gid);
|
||||
struct group *create_group(struct faction * f, const char *name, int gid);
|
||||
|
||||
extern void write_groups(struct gamedata *data, const struct faction *f);
|
||||
extern void read_groups(struct gamedata *data, struct faction *f);
|
||||
|
|
|
@ -80,8 +80,10 @@ static void test_group_readwrite(CuTest * tc)
|
|||
mstream_init(&data.strm);
|
||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
f = test_create_faction(NULL);
|
||||
new_group(f, "NW", 42);
|
||||
g = new_group(f, "Egoisten", 43);
|
||||
create_group(f, "NW", 42);
|
||||
g = create_group(f, "Egoisten", 43);
|
||||
CuAssertPtrEquals(tc, f, g->f);
|
||||
CuAssertStrEquals(tc, "Egoisten", g->name);
|
||||
key_set(&g->attribs, 44, 44);
|
||||
ally_set(&g->allies, f, HELP_GIVE);
|
||||
write_groups(&data, f);
|
||||
|
|
|
@ -923,7 +923,7 @@ void u_setfaction(unit * u, faction * f)
|
|||
--u->faction->num_units;
|
||||
u->faction->num_people -= u->number;
|
||||
}
|
||||
join_group(u, NULL);
|
||||
set_group(u, NULL);
|
||||
free_orders(&u->orders);
|
||||
set_order(&u->thisorder, NULL);
|
||||
|
||||
|
|
Loading…
Reference in a new issue