Add a failing test for bug 2379.

This commit is contained in:
Enno Rehling 2017-11-05 15:11:02 +01:00
parent a17c8ada71
commit 12646f726a
3 changed files with 63 additions and 16 deletions

View File

@ -1446,25 +1446,20 @@ static void expandbuying(region * r, request * buyorders)
const resource_type *rsilver = get_resourcetype(R_SILVER); const resource_type *rsilver = get_resourcetype(R_SILVER);
int max_products; int max_products;
unit *u; unit *u;
static struct trade { struct trade {
const luxury_type *type; const luxury_type *type;
int number; int number;
int multi; int multi;
} trades[MAXLUXURIES], *trade; } trades[MAXLUXURIES], *trade;
static int ntrades = 0; int ntrades = 0;
int i;
const luxury_type *ltype; const luxury_type *ltype;
if (ntrades == 0) {
for (ntrades = 0, ltype = luxurytypes; ltype; ltype = ltype->next) { for (ntrades = 0, ltype = luxurytypes; ltype; ltype = ltype->next) {
assert(ntrades < MAXLUXURIES); assert(ntrades < MAXLUXURIES);
trades[ntrades].number = 0;
trades[ntrades].multi = 1;
trades[ntrades++].type = ltype; trades[ntrades++].type = ltype;
} }
}
for (i = 0; i != ntrades; ++i) {
trades[i].number = 0;
trades[i].multi = 1;
}
if (!buyorders) if (!buyorders)
return; return;
@ -1490,7 +1485,7 @@ static void expandbuying(region * r, request * buyorders)
int price, multi; int price, multi;
ltype = g_requests[j].type.ltype; ltype = g_requests[j].type.ltype;
trade = trades; trade = trades;
while (trade->type != ltype) while (trade->type && trade->type != ltype)
++trade; ++trade;
multi = trade->multi; multi = trade->multi;
price = ltype->price * multi; price = ltype->price * multi;

View File

@ -170,6 +170,60 @@ static void test_normals_recruit(CuTest * tc) {
test_cleanup(); test_cleanup();
} }
static region *setup_trade_region(CuTest *tc, const struct terrain_type *terrain) {
region *r;
item_type *it_luxury;
struct locale * lang = default_locale;
new_luxurytype(it_luxury = test_create_itemtype("jewel"), 5);
locale_setstring(lang, it_luxury->rtype->_name, it_luxury->rtype->_name);
CuAssertStrEquals(tc, it_luxury->rtype->_name, LOC(lang, resourcename(it_luxury->rtype, 0)));
new_luxurytype(it_luxury = test_create_itemtype("balm"), 5);
locale_setstring(lang, it_luxury->rtype->_name, it_luxury->rtype->_name);
CuAssertStrEquals(tc, it_luxury->rtype->_name, LOC(lang, resourcename(it_luxury->rtype, 0)));
r = test_create_region(0, 0, terrain);
return r;
}
static unit *setup_trade_unit(CuTest *tc, region *r, const struct race *rc) {
unit *u;
UNUSED_ARG(tc);
u = test_create_unit(test_create_faction(rc), r);
set_level(u, SK_TRADE, 2);
return u;
}
static void test_trade_insect(CuTest *tc) {
/* Insekten können in Wüsten und Sümpfen auch ohne Burgen handeln. */
unit *u;
region *r;
const item_type *it_luxury;
const item_type *it_silver;
struct locale *lang;
test_setup();
init_resources();
lang = test_create_locale();
it_silver = get_resourcetype(R_SILVER)->itype;
r = setup_trade_region(tc, get_terrain("swamp"));
it_luxury = r_luxury(r);
CuAssertPtrNotNull(tc, it_luxury);
u = setup_trade_unit(tc, r, test_create_race("insect"));
unit_addorder(u, create_order(K_BUY, u->faction->locale, "1 %s",
LOC(u->faction->locale, resourcename(it_luxury->rtype, 0))));
set_item(u, it_silver, 10);
produce(u->region);
CuAssertIntEquals(tc, 1, get_item(u, it_luxury));
CuAssertIntEquals(tc, 5, get_item(u, it_silver));
}
static void test_buy_cmd(CuTest *tc) { static void test_buy_cmd(CuTest *tc) {
region * r; region * r;
unit *u; unit *u;
@ -622,6 +676,7 @@ CuSuite *get_economy_suite(void)
SUITE_ADD_TEST(suite, test_heroes_dont_recruit); SUITE_ADD_TEST(suite, test_heroes_dont_recruit);
SUITE_ADD_TEST(suite, test_tax_cmd); SUITE_ADD_TEST(suite, test_tax_cmd);
SUITE_ADD_TEST(suite, test_buy_cmd); SUITE_ADD_TEST(suite, test_buy_cmd);
SUITE_ADD_TEST(suite, test_trade_insect);
SUITE_ADD_TEST(suite, test_maintain_buildings); SUITE_ADD_TEST(suite, test_maintain_buildings);
SUITE_ADD_TEST(suite, test_recruit); SUITE_ADD_TEST(suite, test_recruit);
return suite; return suite;

View File

@ -45,9 +45,6 @@ typedef struct locale {
struct locale_str *strings[SMAXHASH]; struct locale_str *strings[SMAXHASH];
} locale; } locale;
extern locale *default_locale;
extern locale *locales;
locale *default_locale; locale *default_locale;
locale *locales; locale *locales;