Merge branch 'master' of github.com:badgerman/eressea

This commit is contained in:
Enno Rehling 2015-01-29 17:02:05 +01:00
commit c8b9e67e95
9 changed files with 96 additions and 20 deletions

View File

@ -21,6 +21,7 @@ race.test.c
spellbook.test.c
curse.test.c
jsonconf.test.c
messages.test.c
)
SET(_FILES

View File

@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#include <platform.h>
#include <kernel/config.h>
#include "messages.h"
/* kernel includes */
@ -140,7 +139,7 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
message *msg_message(const char *name, const char *sig, ...)
/* msg_message("oops_error", "unit region command", u, r, cmd) */
{
va_list marker;
va_list vargs;
const message_type *mtype = mt_find(name);
char paramname[64];
const char *ic = sig;
@ -155,7 +154,7 @@ message *msg_message(const char *name, const char *sig, ...)
return NULL;
}
va_start(marker, sig);
va_start(vargs, sig);
while (*ic && !isalnum(*ic))
ic++;
while (*ic) {
@ -172,9 +171,9 @@ message *msg_message(const char *name, const char *sig, ...)
}
if (i != mtype->nparameters) {
if (mtype->types[i]->vtype == VAR_VOIDPTR) {
args[i].v = va_arg(marker, void *);
args[i].v = va_arg(vargs, void *);
} else if (mtype->types[i]->vtype == VAR_INT) {
args[i].i = va_arg(marker, int);
args[i].i = va_arg(vargs, int);
} else {
assert(!"unknown variant type");
}
@ -185,7 +184,7 @@ message *msg_message(const char *name, const char *sig, ...)
while (*ic && !isalnum(*ic))
ic++;
}
va_end(marker);
va_end(vargs);
return msg_create(mtype, args);
}

View File

@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
#include <kernel/types.h>
#include <util/message.h>
struct faction;

View File

@ -0,0 +1,44 @@
#include <platform.h>
#include "messages.h"
#include <CuTest.h>
#include <tests.h>
void test_missing_message(CuTest *tc) {
message *msg;
msg = msg_message("unknown", "unit", NULL);
CuAssertPtrNotNull(tc, msg);
CuAssertPtrNotNull(tc, msg->type);
CuAssertStrEquals(tc, msg->type->name, "missing_message");
msg_release(msg);
}
void test_message(CuTest *tc) {
message *msg;
// const char * args[] = { }
message_type *mtype = mt_new("custom", NULL);
mt_register(mtype);
CuAssertPtrEquals(tc, mtype, (void *)mt_find("custom"));
CuAssertIntEquals(tc, 0, mtype->nparameters);
CuAssertPtrEquals(tc, NULL, (void *)mtype->pnames);
CuAssertPtrEquals(tc, NULL, (void *)mtype->types);
msg = msg_message("custom", "");
CuAssertPtrNotNull(tc, msg);
CuAssertIntEquals(tc, 1, msg->refcount);
CuAssertPtrEquals(tc, NULL, msg->parameters);
CuAssertPtrEquals(tc, mtype, (void *)msg->type);
CuAssertPtrEquals(tc, msg, msg_addref(msg));
CuAssertIntEquals(tc, 2, msg->refcount);
msg_release(msg);
CuAssertIntEquals(tc, 1, msg->refcount);
msg_release(msg);
test_cleanup();
}
CuSuite *get_messages_suite(void) {
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_missing_message);
SUITE_ADD_TEST(suite, test_message);
return suite;
}

View File

@ -177,7 +177,11 @@ race *rc_get_or_create(const char *zName)
rc = (race *)calloc(sizeof(race), 1);
rc->hitpoints = 1;
rc->weight = PERSON_WEIGHT;
rc->capacity = 540;
rc->recruit_multi = 1.0F;
rc->regaura = 1.0F;
rc->speed = 1.0F;
if (strchr(zName, ' ') != NULL) {
log_error("race '%s' has an invalid name. remove spaces\n", zName);
assert(strchr(zName, ' ') == NULL);

View File

@ -8,17 +8,43 @@
#include <assert.h>
static void test_rc_name(CuTest *tc) {
struct race *rc = test_create_race("human");
struct race *rc;
test_cleanup();
rc = test_create_race("human");
CuAssertStrEquals(tc, "race::human", rc_name_s(rc, NAME_SINGULAR));
CuAssertStrEquals(tc, "race::human_p", rc_name_s(rc, NAME_PLURAL));
CuAssertStrEquals(tc, "race::human_d", rc_name_s(rc, NAME_DEFINITIVE));
CuAssertStrEquals(tc, "race::human_x", rc_name_s(rc, NAME_CATEGORY));
test_cleanup();
}
static void test_rc_defaults(CuTest *tc) {
struct race *rc;
test_cleanup();
rc = rc_get_or_create("human");
CuAssertStrEquals(tc, "human", rc->_name);
CuAssertDblEquals(tc, 0.0, rc->magres, 0.0);
CuAssertDblEquals(tc, 0.0, rc->maxaura, 0.0);
CuAssertDblEquals(tc, 1.0, rc->recruit_multi, 0.0);
CuAssertDblEquals(tc, 1.0, rc->regaura, 0.0);
CuAssertDblEquals(tc, 1.0, rc->speed, 0.0);
CuAssertIntEquals(tc, 0, rc->flags);
CuAssertIntEquals(tc, 0, rc->recruitcost);
CuAssertIntEquals(tc, 0, rc->maintenance);
CuAssertIntEquals(tc, 540, rc->capacity);
CuAssertIntEquals(tc, 1, rc->hitpoints);
CuAssertIntEquals(tc, 0, rc->armor);
CuAssertIntEquals(tc, 0, rc->at_bonus);
CuAssertIntEquals(tc, 0, rc->df_bonus);
CuAssertIntEquals(tc, PERSON_WEIGHT, rc->weight);
test_cleanup();
}
CuSuite *get_race_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_rc_name);
SUITE_ADD_TEST(suite, test_rc_defaults);
return suite;
}

View File

@ -1626,22 +1626,22 @@ static int parse_races(xmlDocPtr doc)
rc->def_damage = _strdup((const char *)propValue);
xmlFree(propValue);
rc->magres = (float)xml_fvalue(node, "magres", 0.0);
rc->maxaura = (float)xml_fvalue(node, "maxaura", 0.0);
rc->regaura = (float)xml_fvalue(node, "regaura", 1.0);
rc->recruitcost = xml_ivalue(node, "recruitcost", 0);
rc->maintenance = xml_ivalue(node, "maintenance", 0);
rc->weight = xml_ivalue(node, "weight", PERSON_WEIGHT);
rc->capacity = xml_ivalue(node, "capacity", 540);
rc->speed = (float)xml_fvalue(node, "speed", 1.0F);
rc->hitpoints = xml_ivalue(node, "hp", 0);
rc->armor = (char)xml_ivalue(node, "ac", 0);
rc->magres = (float)xml_fvalue(node, "magres", rc->magres);
rc->maxaura = (float)xml_fvalue(node, "maxaura", rc->maxaura);
rc->regaura = (float)xml_fvalue(node, "regaura", rc->regaura);
rc->recruitcost = xml_ivalue(node, "recruitcost", rc->recruitcost);
rc->maintenance = xml_ivalue(node, "maintenance", rc->maintenance);
rc->weight = xml_ivalue(node, "weight", rc->weight);
rc->capacity = xml_ivalue(node, "capacity", rc->capacity);
rc->speed = (float)xml_fvalue(node, "speed", rc->speed);
rc->hitpoints = xml_ivalue(node, "hp", rc->hitpoints);
rc->armor = (char)xml_ivalue(node, "ac", rc->armor);
study_speed_base = xml_ivalue(node, "studyspeed", 0);
rc->at_default = (char)xml_ivalue(node, "unarmedattack", -2);
rc->df_default = (char)xml_ivalue(node, "unarmeddefense", -2);
rc->at_bonus = (char)xml_ivalue(node, "attackmodifier", 0);
rc->df_bonus = (char)xml_ivalue(node, "defensemodifier", 0);
rc->at_bonus = (char)xml_ivalue(node, "attackmodifier", rc->at_bonus);
rc->df_bonus = (char)xml_ivalue(node, "defensemodifier", rc->df_bonus);
if (!xml_bvalue(node, "playerrace", false))
rc->flags |= RCF_NPC;

View File

@ -71,6 +71,7 @@ int RunAllTests(void)
RUN_TESTS(suite, building);
RUN_TESTS(suite, spell);
RUN_TESTS(suite, ally);
RUN_TESTS(suite, messages);
/* gamecode */
RUN_TESTS(suite, battle);
RUN_TESTS(suite, economy);

View File

@ -146,7 +146,7 @@ message *msg_create(const struct message_type *mtype, variant args[])
return NULL;
}
msg->type = mtype;
msg->parameters = (variant *) calloc(mtype->nparameters, sizeof(variant));
msg->parameters = (variant *)(mtype->nparameters ? calloc(mtype->nparameters, sizeof(variant)) : NULL);
msg->refcount = 1;
for (i = 0; i != mtype->nparameters; ++i) {
msg->parameters[i] = copy_arg(mtype->types[i], args[i]);