2012-05-23 03:44:54 +02:00
|
|
|
#include <platform.h>
|
|
|
|
|
2012-05-09 12:14:54 +02:00
|
|
|
#include <kernel/spell.h>
|
2016-08-29 15:49:31 +02:00
|
|
|
|
2016-01-29 17:49:27 +01:00
|
|
|
#include <util/log.h>
|
2016-08-29 15:49:31 +02:00
|
|
|
#include <util/lists.h>
|
2012-05-09 12:14:54 +02:00
|
|
|
|
2016-08-29 15:49:31 +02:00
|
|
|
#include <quicklist.h>
|
2012-05-31 04:17:08 +02:00
|
|
|
#include <CuTest.h>
|
2012-05-09 12:14:54 +02:00
|
|
|
#include <tests.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-11-12 19:34:25 +01:00
|
|
|
static void test_create_a_spell(CuTest * tc)
|
2012-05-09 12:14:54 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
spell * sp;
|
2012-05-09 12:14:54 +02:00
|
|
|
|
2016-08-29 15:09:47 +02:00
|
|
|
test_setup();
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, spells);
|
|
|
|
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
|
2012-05-23 03:44:54 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
sp = create_spell("testspell", 0);
|
|
|
|
CuAssertPtrEquals(tc, sp, find_spell("testspell"));
|
|
|
|
CuAssertPtrNotNull(tc, spells);
|
2016-08-29 15:09:47 +02:00
|
|
|
test_cleanup();
|
2012-05-23 03:44:54 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 15:49:31 +02:00
|
|
|
static void log_list(void *udata, int flags, const char *module, const char *format, va_list args) {
|
|
|
|
strlist **slp = (strlist **)udata;
|
|
|
|
addstrlist(slp, format);
|
|
|
|
}
|
|
|
|
|
2012-05-23 03:44:54 +02:00
|
|
|
static void test_create_duplicate_spell(CuTest * tc)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
spell *sp;
|
2016-08-29 15:49:31 +02:00
|
|
|
struct log_t *log;
|
|
|
|
strlist *sl = 0;
|
2012-05-23 03:44:54 +02:00
|
|
|
|
2016-08-29 15:09:47 +02:00
|
|
|
test_setup();
|
2016-08-29 15:21:28 +02:00
|
|
|
test_log_stderr(0);
|
2016-08-29 15:49:31 +02:00
|
|
|
log = log_create(LOG_CPERROR, &sl, log_list);
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
|
2012-05-09 12:14:54 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
sp = create_spell("testspell", 0);
|
|
|
|
CuAssertPtrEquals(tc, 0, create_spell("testspell", 0));
|
2016-08-29 15:49:31 +02:00
|
|
|
CuAssertPtrNotNull(tc, sl);
|
|
|
|
CuAssertStrEquals(tc, "create_spell: duplicate name '%s'", sl->s);
|
|
|
|
CuAssertPtrEquals(tc, 0, sl->next);
|
|
|
|
freestrlist(sl);
|
|
|
|
log_destroy(log);
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertPtrEquals(tc, sp, find_spell("testspell"));
|
2016-08-29 15:09:47 +02:00
|
|
|
test_cleanup();
|
2012-05-09 12:14:54 +02:00
|
|
|
}
|
|
|
|
|
2012-05-23 03:44:54 +02:00
|
|
|
static void test_create_spell_with_id(CuTest * tc)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
spell *sp;
|
2016-08-29 15:49:31 +02:00
|
|
|
struct log_t *log;
|
|
|
|
strlist *sl = 0;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2016-08-29 15:09:47 +02:00
|
|
|
test_setup();
|
2016-08-29 15:21:28 +02:00
|
|
|
test_log_stderr(0);
|
2016-08-29 15:49:31 +02:00
|
|
|
log = log_create(LOG_CPERROR, &sl, log_list);
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, find_spellbyid(42));
|
|
|
|
sp = create_spell("testspell", 42);
|
|
|
|
CuAssertPtrEquals(tc, sp, find_spellbyid(42));
|
|
|
|
CuAssertPtrEquals(tc, 0, create_spell("testspell", 47));
|
2016-08-29 15:49:31 +02:00
|
|
|
CuAssertPtrNotNull(tc, sl);
|
|
|
|
CuAssertStrEquals(tc, "create_spell: duplicate name '%s'", sl->s);
|
|
|
|
CuAssertPtrEquals(tc, 0, sl->next);
|
|
|
|
freestrlist(sl);
|
|
|
|
log_destroy(log);
|
2015-01-30 20:37:14 +01:00
|
|
|
CuAssertPtrEquals(tc, 0, find_spellbyid(47));
|
2016-08-29 15:09:47 +02:00
|
|
|
test_cleanup();
|
2012-05-23 03:44:54 +02:00
|
|
|
}
|
|
|
|
|
2012-05-09 12:14:54 +02:00
|
|
|
CuSuite *get_spell_suite(void)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
2015-11-12 19:34:25 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_create_a_spell);
|
2015-01-30 20:37:14 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_create_duplicate_spell);
|
|
|
|
SUITE_ADD_TEST(suite, test_create_spell_with_id);
|
|
|
|
return suite;
|
2012-05-09 12:14:54 +02:00
|
|
|
}
|