2012-05-25 08:50:27 +02:00
|
|
|
#include <platform.h>
|
|
|
|
|
2014-11-01 12:57:01 +01:00
|
|
|
#include "magic.h"
|
|
|
|
|
2018-05-11 21:30:26 +02:00
|
|
|
#include <kernel/callbacks.h>
|
2012-05-25 08:50:27 +02:00
|
|
|
#include <kernel/equipment.h>
|
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/spell.h>
|
|
|
|
|
2012-05-31 04:17:08 +02:00
|
|
|
#include <CuTest.h>
|
2012-05-25 08:50:27 +02:00
|
|
|
#include <tests.h>
|
|
|
|
|
2018-05-15 21:51:47 +02:00
|
|
|
static unit *eq_unit;
|
|
|
|
static const char *eq_name;
|
|
|
|
static int eq_mask;
|
|
|
|
|
|
|
|
static bool equip_callback(unit *u, const char *eqname, int mask) {
|
|
|
|
eq_unit = u;
|
|
|
|
eq_name = eqname;
|
|
|
|
eq_mask = mask;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-18 17:20:09 +02:00
|
|
|
static void test_equipment(CuTest * tc)
|
2012-05-25 08:50:27 +02:00
|
|
|
{
|
2018-05-15 21:51:47 +02:00
|
|
|
callbacks.equip_unit = equip_callback;
|
2015-01-30 20:37:14 +01:00
|
|
|
unit * u;
|
|
|
|
|
2016-09-07 19:04:42 +02:00
|
|
|
test_setup();
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2018-01-14 09:38:26 +01:00
|
|
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
2018-05-15 21:51:47 +02:00
|
|
|
CuAssertIntEquals(tc, true, equip_unit_mask(u, "hodor", EQUIP_ALL));
|
|
|
|
CuAssertIntEquals(tc, EQUIP_ALL, eq_mask);
|
|
|
|
CuAssertPtrEquals(tc, u, eq_unit);
|
|
|
|
CuAssertStrEquals(tc, "hodor", eq_name);
|
2012-05-25 08:50:27 +02:00
|
|
|
|
2018-05-15 21:51:47 +02:00
|
|
|
CuAssertIntEquals(tc, true, equip_unit_mask(u, "foobar", EQUIP_ITEMS));
|
|
|
|
CuAssertIntEquals(tc, EQUIP_ITEMS, eq_mask);
|
|
|
|
CuAssertPtrEquals(tc, u, eq_unit);
|
|
|
|
CuAssertStrEquals(tc, "foobar", eq_name);
|
2017-09-18 17:20:09 +02:00
|
|
|
|
2018-05-15 21:51:47 +02:00
|
|
|
CuAssertIntEquals(tc, true, equip_unit(u, "unknown"));
|
|
|
|
CuAssertIntEquals(tc, EQUIP_ALL, eq_mask);
|
|
|
|
CuAssertPtrEquals(tc, u, eq_unit);
|
|
|
|
CuAssertStrEquals(tc, "unknown", eq_name);
|
2017-09-18 17:20:09 +02:00
|
|
|
|
2018-05-11 21:30:26 +02:00
|
|
|
test_teardown();
|
|
|
|
}
|
|
|
|
|
2012-05-25 08:50:27 +02:00
|
|
|
CuSuite *get_equipment_suite(void)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_equipment);
|
|
|
|
return suite;
|
2012-05-25 08:50:27 +02:00
|
|
|
}
|