From d4aa6e834e7ff4ab1202ce11e3253cc4ed95baf0 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Sun, 18 Jan 2015 15:44:44 +0100 Subject: [PATCH] check for number of arguments as good as possible and cleaning up test --- src/kernel/messages.c | 6 ++++++ src/kernel/spy.test.c | 9 +-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/kernel/messages.c b/src/kernel/messages.c index f92b8acf9..9291592b1 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -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); } diff --git a/src/kernel/spy.test.c b/src/kernel/spy.test.c index fc1a5f53c..07a414220 100644 --- a/src/kernel/spy.test.c +++ b/src/kernel/spy.test.c @@ -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; }