forked from github/server
added a test for addfaction.
removing struct player, since it is not in use.
This commit is contained in:
parent
acfe72f24e
commit
cc0b0ad71b
|
@ -46,7 +46,6 @@ names.c
|
||||||
order.c
|
order.c
|
||||||
pathfinder.c
|
pathfinder.c
|
||||||
plane.c
|
plane.c
|
||||||
player.c
|
|
||||||
pool.c
|
pool.c
|
||||||
race.c
|
race.c
|
||||||
region.c
|
region.c
|
||||||
|
|
|
@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct player;
|
|
||||||
struct alliance;
|
struct alliance;
|
||||||
struct item;
|
struct item;
|
||||||
struct seen_region;
|
struct seen_region;
|
||||||
|
@ -60,7 +59,6 @@ typedef struct faction {
|
||||||
struct faction *next;
|
struct faction *next;
|
||||||
struct faction *nexthash;
|
struct faction *nexthash;
|
||||||
|
|
||||||
struct player *owner;
|
|
||||||
#ifdef SMART_INTERVALS
|
#ifdef SMART_INTERVALS
|
||||||
struct region *first;
|
struct region *first;
|
||||||
struct region *last;
|
struct region *last;
|
||||||
|
|
|
@ -1,11 +1,39 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
|
#include <kernel/race.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
#include <util/language.h>
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <stdio.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;
|
faction *f;
|
||||||
CuAssertPtrEquals(tc, NULL, get_monsters());
|
CuAssertPtrEquals(tc, NULL, get_monsters());
|
||||||
f = get_or_create_monsters();
|
f = get_or_create_monsters();
|
||||||
|
@ -22,6 +50,7 @@ void test_get_monsters(CuTest *tc) {
|
||||||
CuSuite *get_faction_suite(void)
|
CuSuite *get_faction_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
SUITE_ADD_TEST(suite, test_addfaction);
|
||||||
SUITE_ADD_TEST(suite, test_get_monsters);
|
SUITE_ADD_TEST(suite, test_get_monsters);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,6 +256,11 @@ static order *create_order_i(keyword_t kwd, const char *sptr, int persistent,
|
||||||
order *ord = NULL;
|
order *ord = NULL;
|
||||||
int lindex;
|
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 this is just nonsense, then we skip it. */
|
||||||
if (lomem) {
|
if (lomem) {
|
||||||
switch (kwd) {
|
switch (kwd) {
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
Loading…
Reference in New Issue