From 2cc8c1f8710b405030c17984210d144cca2ebe89 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Tue, 13 Jan 2015 13:34:26 +0100 Subject: [PATCH] trying to solve spy message bug #1604 Conflicts: src/kernel/CMakeLists.txt --- res/core/messages.xml | 3 ++ src/kernel/CMakeLists.txt | 1 + src/kernel/spy.test.c | 94 +++++++++++++++++++++++++++++++++++++++ src/spy.c | 12 ++--- src/test_eressea.c | 1 + 5 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 src/kernel/spy.test.c diff --git a/res/core/messages.xml b/res/core/messages.xml index 56f7bb01b..c25f61fec 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -3466,6 +3466,7 @@ + @@ -3474,6 +3475,7 @@ + @@ -3482,6 +3484,7 @@ + diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index bc2c20418..e7170e7b2 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -22,6 +22,7 @@ spellbook.test.c curse.test.c jsonconf.test.c messages.test.c +spy.test.c ) SET(_FILES diff --git a/src/kernel/spy.test.c b/src/kernel/spy.test.c new file mode 100644 index 000000000..fc1a5f53c --- /dev/null +++ b/src/kernel/spy.test.c @@ -0,0 +1,94 @@ +#include +#include "types.h" +#include "spy.h" +#include "magic.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +typedef struct { + region *r; + unit *spy; + unit *victim; +} spy_fixture; + +static void setup_spy(spy_fixture *fix) { + test_cleanup(); + fix->r = test_create_region(0, 0, NULL); + fix->spy = test_create_unit(test_create_faction(NULL), fix->r); + fix->victim = test_create_unit(test_create_faction(NULL), fix->r); +} + + +static const message_type *register_msg(const char *type, int n_param, ...) { + char **argv; + va_list args; + int i; + + va_start(args, n_param); + + argv = malloc(sizeof(char *) * (n_param+1)); + for (i=0; ifaction->msgs->begin; + m = 0; + 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; + } + CuAssertIntEquals(tc, 3, m); + + test_cleanup(); +} + +CuSuite *get_spy_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_spy_message); + return suite; +} diff --git a/src/spy.c b/src/spy.c index 601deff65..86631d8f6 100644 --- a/src/spy.c +++ b/src/spy.c @@ -58,15 +58,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * Spionage des Spions */ void spy_message(int spy, const unit * u, const unit * target) { - const char *str = report_kampfstatus(target, u->faction->locale); + /* const char *str = report_kampfstatus(target, u->faction->locale);*/ ADDMSG(&u->faction->msgs, msg_message("spyreport", "spy target status", u, - target, str)); + target)); if (spy > 20) { sc_mage *mage = get_mage(target); /* for mages, spells and magic school */ if (mage) { - ADDMSG(&u->faction->msgs, msg_message("spyreport_mage", "target type", + ADDMSG(&u->faction->msgs, msg_message("spyreport_mage", "spy target type", u, target, magic_school[mage->magietyp])); } } @@ -75,7 +75,7 @@ void spy_message(int spy, const unit * u, const unit * target) if (fv && fv != target->faction) { /* true faction */ ADDMSG(&u->faction->msgs, msg_message("spyreport_faction", - "target faction", target, target->faction)); + "spy target faction", u, target, target->faction)); add_seen_faction(u->faction, target->faction); } } @@ -103,12 +103,12 @@ void spy_message(int spy, const unit * u, const unit * target) } } if (found) { - ADDMSG(&u->faction->msgs, msg_message("spyreport_skills", "target skills", + ADDMSG(&u->faction->msgs, msg_message("spyreport_skills", "spy target skills", u, target, buf)); } if (target->items) { - ADDMSG(&u->faction->msgs, msg_message("spyreport_items", "target items", + ADDMSG(&u->faction->msgs, msg_message("spyreport_items", "target items", u, target, target->items)); } } diff --git a/src/test_eressea.c b/src/test_eressea.c index ccbac8463..5f6d380e7 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -84,6 +84,7 @@ int RunAllTests(void) RUN_TESTS(suite, upkeep); RUN_TESTS(suite, vortex); RUN_TESTS(suite, wormhole); + RUN_TESTS(suite, spy); printf("\ntest summary: %d tests, %d failed\n", suite->count, suite->failCount); log_flags = flags;