added a test for addfaction.

removing struct player, since it is not in use.
This commit is contained in:
Enno Rehling 2014-08-20 23:42:33 +02:00
parent acfe72f24e
commit cc0b0ad71b
6 changed files with 35 additions and 150 deletions

View File

@ -46,7 +46,6 @@ names.c
order.c
pathfinder.c
plane.c
player.c
pool.c
race.c
region.c

View File

@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
struct player;
struct alliance;
struct item;
struct seen_region;
@ -60,7 +59,6 @@ typedef struct faction {
struct faction *next;
struct faction *nexthash;
struct player *owner;
#ifdef SMART_INTERVALS
struct region *first;
struct region *last;

View File

@ -1,11 +1,39 @@
#include <platform.h>
#include <kernel/types.h>
#include <kernel/race.h>
#include <kernel/config.h>
#include <util/language.h>
#include "faction.h"
#include <CuTest.h>
#include <stdio.h>
void test_get_monsters(CuTest *tc) {
static void test_addfaction(CuTest *tc) {
faction *f = 0;
const struct race *rc = rc_get_or_create("human");
const struct locale *lang = get_or_create_locale("en");
f = addfaction("test@eressea.de", "hurrdurr", rc, lang, 1234);
CuAssertPtrNotNull(tc, f);
CuAssertPtrNotNull(tc, f->name);
CuAssertPtrEquals(tc, NULL, (void *)f->units);
CuAssertPtrEquals(tc, NULL, (void *)f->next);
CuAssertPtrEquals(tc, NULL, (void *)f->banner);
CuAssertPtrEquals(tc, NULL, (void *)f->spellbook);
CuAssertPtrEquals(tc, NULL, (void *)f->ursprung);
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
CuAssertStrEquals(tc, "test@eressea.de", f->email);
CuAssertStrEquals(tc, "hurrdurr", f->passw);
CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
CuAssertIntEquals(tc, 1234, f->subscription);
CuAssertIntEquals(tc, 0, f->flags);
CuAssertIntEquals(tc, 0, f->age);
CuAssertIntEquals(tc, 1, f->alive);
CuAssertIntEquals(tc, M_GRAY, f->magiegebiet);
CuAssertIntEquals(tc, turn, f->lastorders);
CuAssertPtrEquals(tc, f, findfaction(f->no));
}
static void test_get_monsters(CuTest *tc) {
faction *f;
CuAssertPtrEquals(tc, NULL, get_monsters());
f = get_or_create_monsters();
@ -22,6 +50,7 @@ void test_get_monsters(CuTest *tc) {
CuSuite *get_faction_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_addfaction);
SUITE_ADD_TEST(suite, test_get_monsters);
return suite;
}

View File

@ -256,6 +256,11 @@ static order *create_order_i(keyword_t kwd, const char *sptr, int persistent,
order *ord = NULL;
int lindex;
if (keyword_disabled(kwd)) {
log_error("trying to create an order for disabled keyword %s.", keyword(kwd));
return NULL;
}
/* if this is just nonsense, then we skip it. */
if (lomem) {
switch (kwd) {

View File

@ -1,103 +0,0 @@
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#include <platform.h>
#include "player.h"
#include <util/goodies.h>
#include <util/rng.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#define PMAXHASH 1021
typedef struct player_hash {
struct player *entries;
} player_hash;
static player_hash *players[PMAXHASH];
player *make_player(const struct faction *f)
{
player *p = calloc(sizeof(player), 1);
unsigned int hash;
for (p->id = rng_int();; p->id++) {
/* if there is a hashing conflict, resolve it */
player *pi = get_player(p->id);
if (pi)
p->id++;
else
break;
}
hash = p->id % PMAXHASH;
p->faction = f;
p->nexthash = players[hash]->entries;
players[hash]->entries = p;
return p;
}
player *next_player(player * p)
{
if (p->nexthash)
return p->nexthash;
else {
unsigned int hash = p->id % PMAXHASH;
p = NULL;
while (++hash != PMAXHASH) {
if (players[hash]->entries != NULL) {
p = players[hash]->entries;
break;
}
}
return p;
}
}
player *get_player(unsigned int id)
{
unsigned int hash = id % PMAXHASH;
struct player *p = players[hash]->entries;
while (p && p->id != id)
p = p->nexthash;
return p;
}
player *get_players(void)
{
struct player *p = NULL;
unsigned int hash = 0;
while (p != NULL && hash != PMAXHASH) {
p = players[hash++]->entries;
}
return p;
}
void players_done(void)
{
int i;
for (i = 0; i != PMAXHASH; ++i) {
player *p = players[i]->entries;
players[i]->entries = p->nexthash;
free(p->name);
if (p->email)
free(p->email);
if (p->name)
free(p->name);
free(p);
}
}

View File

@ -1,43 +0,0 @@
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#ifndef H_KRNL_PLAYER
#define H_KRNL_PLAYER
#ifdef __cplusplus
extern "C" {
#endif
struct faction;
typedef struct player {
unsigned int id;
char *name;
char *email;
char *address;
struct vacation {
int weeks;
char *email;
} *vacation;
const struct faction *faction;
struct player *nexthash; /* don't use! */
} player;
extern struct player *get_players(void);
extern struct player *get_player(unsigned int id);
extern struct player *make_player(const struct faction *f);
extern struct player *next_player(struct player *p);
#ifdef __cplusplus
}
#endif
#endif