check for number of arguments as good as possible and cleaning up test

This commit is contained in:
Steffen Mecke 2015-01-18 15:44:44 +01:00
parent e28222c5be
commit d4aa6e834e
2 changed files with 7 additions and 8 deletions

View File

@ -147,6 +147,7 @@ message *msg_message(const char *name, const char *sig, ...)
const message_type *mtype = mt_find(name);
char paramname[64];
const char *ic = sig;
int argnum=0;
variant args[16];
memset(args, 0, sizeof(args));
@ -183,6 +184,7 @@ message *msg_message(const char *name, const char *sig, ...)
else {
assert(!"unknown variant type");
}
argnum++;
}
else {
log_error("invalid parameter %s for message type %s\n", paramname, mtype->name);
@ -192,6 +194,10 @@ message *msg_message(const char *name, const char *sig, ...)
ic++;
}
va_end(vargs);
if (argnum != mtype->nparameters) {
log_error("not enough parameters for message type %s\n", mtype->name);
assert(!"program aborted.");
}
return msg_create(mtype, args);
}

View File

@ -50,9 +50,8 @@ static void test_spy_message(CuTest *tc) {
spy_fixture fix;
struct mlist *msglist;
struct message *msg;
int m, p;
int m;
const message_type *expected[3];
variant v;
setup_spy(&fix);
enable_skill(SK_MAGIC, true);
@ -72,12 +71,6 @@ static void test_spy_message(CuTest *tc) {
while (msglist) {
msg = msglist->msg;
CuAssertStrEquals(tc, expected[m]->name, msg->type->name);
/* I'm not sure how to test for correct number and maybe even type of parameters */
for (p = 0; p != msg->type->nparameters; ++p) {
v = msg->parameters[p];
if (v.v || !v.v)
v = msg->parameters[p];
}
msglist = msglist->next;
++m;
}