2012-05-23 21:42:14 +02:00
|
|
|
#include <platform.h>
|
|
|
|
|
|
|
|
#include <kernel/spell.h>
|
|
|
|
#include <kernel/spellbook.h>
|
|
|
|
#include <util/language.h>
|
|
|
|
|
2012-05-31 04:17:08 +02:00
|
|
|
#include <CuTest.h>
|
2012-05-23 21:42:14 +02:00
|
|
|
#include <tests.h>
|
|
|
|
|
2014-03-15 19:29:11 +01:00
|
|
|
#include <stdlib.h>
|
2012-05-23 21:42:14 +02:00
|
|
|
|
|
|
|
int count_spell_cb(spellbook_entry * sbe, void * ptr)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
int * counter = (int *)ptr;
|
|
|
|
++*counter;
|
|
|
|
return 0;
|
2012-05-23 21:42:14 +02:00
|
|
|
}
|
|
|
|
|
2012-05-24 05:22:12 +02:00
|
|
|
void test_named_spellbooks(CuTest * tc)
|
2012-05-23 21:42:14 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
spell *sp;
|
|
|
|
spellbook *sb;
|
|
|
|
spellbook_entry *sbe;
|
|
|
|
int counter = 0;
|
2012-05-24 09:56:54 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
sb = create_spellbook(0);
|
|
|
|
CuAssertPtrNotNull(tc, sb);
|
2018-10-14 11:48:21 +02:00
|
|
|
CuAssertPtrEquals(tc, NULL, sb->name);
|
2015-01-30 20:37:14 +01:00
|
|
|
spellbook_clear(sb);
|
|
|
|
free(sb);
|
2012-05-24 05:22:12 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
sb = create_spellbook("spells");
|
|
|
|
CuAssertPtrNotNull(tc, sb);
|
|
|
|
CuAssertStrEquals(tc, "spells", sb->name);
|
2012-05-24 05:22:12 +02:00
|
|
|
|
2017-05-01 17:04:28 +02:00
|
|
|
sp = create_spell("testspell");
|
2015-01-30 20:37:14 +01:00
|
|
|
spellbook_add(sb, sp, 1);
|
|
|
|
CuAssertPtrNotNull(tc, sb->spells);
|
2012-05-24 09:56:54 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
sbe = spellbook_get(sb, sp);
|
|
|
|
CuAssertPtrNotNull(tc, sbe);
|
|
|
|
CuAssertIntEquals(tc, 1, sbe->level);
|
2018-05-05 07:38:11 +02:00
|
|
|
CuAssertPtrEquals(tc, sp, spellref_get(&sbe->spref));
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
|
|
spellbook_foreach(sb, count_spell_cb, &counter);
|
|
|
|
CuAssertIntEquals(tc, 1, counter);
|
2012-05-24 05:22:12 +02:00
|
|
|
|
|
|
|
#ifdef TODO
|
2015-01-30 20:37:14 +01:00
|
|
|
/* try adding the same spell twice. that should fail */
|
|
|
|
spellbook_add(sb, sp, 1);
|
|
|
|
spellbook_foreach(sb, count_spell_cb, &counter);
|
|
|
|
CuAssertIntEquals(tc, 1, counter);
|
2012-05-24 05:22:12 +02:00
|
|
|
#endif
|
2015-01-30 20:37:14 +01:00
|
|
|
spellbook_clear(sb);
|
|
|
|
free(sb);
|
2012-05-23 21:42:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_spellbook_suite(void)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_named_spellbooks);
|
|
|
|
return suite;
|
2012-05-23 21:42:14 +02:00
|
|
|
}
|