From d479075c531d25ae4c10c521cfe320fed6cee0c3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 23 Feb 2011 23:23:32 -0800 Subject: [PATCH] Testing util is no longer such an include-weirdness. --- src/gamecode/market.c | 57 +++++++++++++++++++--------------------- src/tests.c | 5 +++- src/util.vcxproj | 5 ++-- src/util.vcxproj.filters | 3 +++ src/util/base36.c | 4 --- src/util/base36_test.c | 3 +++ 6 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/gamecode/market.c b/src/gamecode/market.c index 34d13172e..2f0f3ba2c 100644 --- a/src/gamecode/market.c +++ b/src/gamecode/market.c @@ -17,6 +17,7 @@ without prior permission by the authors of Eressea. #include #include +#include #include #include @@ -89,7 +90,7 @@ static int rc_herb_trade(const struct race * rc) void do_markets(void) { - unit_list * traders = 0; + quicklist * traders = 0; unit * markets[MAX_MARKETS]; region * r; for (r=regions;r;r=r->next) { @@ -119,11 +120,8 @@ void do_markets(void) item * items; attrib * a = a_find(u->attribs, &at_market); if (a==NULL) { - unit_list * ulist = malloc(sizeof(unit_list)); a = a_add(&u->attribs, a_new(&at_market)); - ulist->next = traders; - ulist->data = u; - traders = ulist; + ql_push(&traders, u); } items = (item *)a->data.v; i_change(&items, lux, 1); @@ -136,11 +134,8 @@ void do_markets(void) item * items; attrib * a = a_find(u->attribs, &at_market); if (a==NULL) { - unit_list * ulist = malloc(sizeof(unit_list)); a = a_add(&u->attribs, a_new(&at_market)); - ulist->next = traders; - ulist->data = u; - traders = ulist; + ql_push(&traders, u); } items = (item *)a->data.v; i_change(&items, herb, 1); @@ -152,33 +147,35 @@ void do_markets(void) } } - while (traders) { - unit_list * trade = traders; - unit * u = trade->data; - attrib * a = a_find(u->attribs, &at_market); - item * items = a->data.v; + if (traders) { + quicklist * qliter = traders; + int qli = 0; + for (qli=0;qliter;ql_advance(&qliter, &qli, 1)) { + unit * u = (unit *)ql_get(qliter, qli); + attrib * a = a_find(u->attribs, &at_market); + item * items = (item *)a->data.v; - a->data.v = NULL; - while (items) { - item * itm = items; - items = itm->next; + a->data.v = NULL; + while (items) { + item * itm = items; + items = itm->next; - if (itm->number) { - ADDMSG(&u->faction->msgs, msg_message("buyamount", - "unit amount resource", u, itm->number, itm->type->rtype)); - itm->next = NULL; - i_add(&u->items, itm); - } else { - i_free(itm); + if (itm->number) { + ADDMSG(&u->faction->msgs, msg_message("buyamount", + "unit amount resource", u, itm->number, itm->type->rtype)); + itm->next = NULL; + i_add(&u->items, itm); + } else { + i_free(itm); + } } + + a_remove(&u->attribs, a); } - - traders = trade->next; - - a_remove(&u->attribs, a); - free(trade); + ql_free(traders); } } + #ifndef DISABLE_TESTS #include "market_test.c" #endif diff --git a/src/tests.c b/src/tests.c index e47442a22..5a7695c97 100644 --- a/src/tests.c +++ b/src/tests.c @@ -4,7 +4,9 @@ #include #include "tests.h" -CuSuite* get_base36_suite(void); +#include +#include + CuSuite* get_curse_suite(void); CuSuite* get_market_suite(void); CuSuite* get_laws_suite(void); @@ -26,6 +28,7 @@ int RunAllTests(void) { init_resources(); CuSuiteAddSuite(suite, get_base36_suite()); + CuSuiteAddSuite(suite, get_quicklist_suite()); CuSuiteAddSuite(suite, get_curse_suite()); CuSuiteAddSuite(suite, get_market_suite()); CuSuiteAddSuite(suite, get_laws_suite()); diff --git a/src/util.vcxproj b/src/util.vcxproj index b744abb18..02c556a66 100644 --- a/src/util.vcxproj +++ b/src/util.vcxproj @@ -125,9 +125,7 @@ - - true - + @@ -147,6 +145,7 @@ + diff --git a/src/util.vcxproj.filters b/src/util.vcxproj.filters index 6d6e644bf..726f4856e 100644 --- a/src/util.vcxproj.filters +++ b/src/util.vcxproj.filters @@ -205,5 +205,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/src/util/base36.c b/src/util/base36.c index 3c795077a..149d42e24 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -109,7 +109,3 @@ i10toi36(int i) } return r; } - -#ifndef DISABLE_TESTS -#include "base36_test.c" -#endif diff --git a/src/util/base36_test.c b/src/util/base36_test.c index c11847ad7..2658becc1 100644 --- a/src/util/base36_test.c +++ b/src/util/base36_test.c @@ -1,4 +1,7 @@ #include +#include "base36.h" +#include +#include static void test_atoi36(CuTest * tc) { CuAssertIntEquals(tc, 0, atoi36("0"));