2014-06-16 03:34:39 +02:00
|
|
|
#include <platform.h>
|
2014-08-27 20:10:17 +02:00
|
|
|
#include <kernel/types.h>
|
|
|
|
|
2014-06-16 03:34:39 +02:00
|
|
|
#include "direction.h"
|
|
|
|
#include "tests.h"
|
|
|
|
|
2014-08-27 21:09:39 +02:00
|
|
|
#include <util/language.h>
|
2014-08-27 20:10:17 +02:00
|
|
|
|
2014-06-16 03:34:39 +02:00
|
|
|
#include <CuTest.h>
|
|
|
|
|
2014-06-16 17:01:59 +02:00
|
|
|
static void test_init_directions(CuTest *tc) {
|
2014-06-16 03:34:39 +02:00
|
|
|
struct locale *lang;
|
|
|
|
|
|
|
|
test_cleanup();
|
2014-06-16 07:17:08 +02:00
|
|
|
lang = get_or_create_locale("en");
|
2014-06-16 03:34:39 +02:00
|
|
|
locale_setstring(lang, "dir_nw", "NW");
|
|
|
|
init_directions(lang);
|
2014-06-16 07:17:08 +02:00
|
|
|
CuAssertIntEquals(tc, D_NORTHWEST, get_direction("nw", lang));
|
2014-06-16 03:34:39 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-06-16 17:01:59 +02:00
|
|
|
static void test_init_direction(CuTest *tc) {
|
2014-06-16 03:34:39 +02:00
|
|
|
struct locale *lang;
|
|
|
|
test_cleanup();
|
|
|
|
|
2014-06-16 07:17:08 +02:00
|
|
|
lang = get_or_create_locale("de");
|
2014-06-16 03:34:39 +02:00
|
|
|
init_direction(lang, D_NORTHWEST, "NW");
|
|
|
|
init_direction(lang, D_EAST, "OST");
|
2014-06-16 07:17:08 +02:00
|
|
|
CuAssertIntEquals(tc, D_NORTHWEST, get_direction("nw", lang));
|
|
|
|
CuAssertIntEquals(tc, D_EAST, get_direction("ost", lang));
|
|
|
|
CuAssertIntEquals(tc, NODIRECTION, get_direction("east", lang));
|
2014-06-16 03:34:39 +02:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-06-16 17:01:59 +02:00
|
|
|
static void test_finddirection(CuTest *tc) {
|
2014-06-16 07:17:08 +02:00
|
|
|
test_cleanup();
|
|
|
|
CuAssertIntEquals(tc, D_SOUTHWEST, finddirection("southwest"));
|
|
|
|
CuAssertIntEquals(tc, D_SOUTHEAST, finddirection("southeast"));
|
|
|
|
CuAssertIntEquals(tc, D_NORTHWEST, finddirection("northwest"));
|
|
|
|
CuAssertIntEquals(tc, D_NORTHEAST, finddirection("northeast"));
|
|
|
|
CuAssertIntEquals(tc, D_WEST, finddirection("west"));
|
|
|
|
CuAssertIntEquals(tc, D_EAST, finddirection("east"));
|
|
|
|
CuAssertIntEquals(tc, D_PAUSE, finddirection("pause"));
|
|
|
|
CuAssertIntEquals(tc, NODIRECTION, finddirection(""));
|
|
|
|
CuAssertIntEquals(tc, NODIRECTION, finddirection("potato"));
|
|
|
|
}
|
|
|
|
|
2014-06-16 17:01:59 +02:00
|
|
|
static void test_get_direction_default(CuTest *tc) {
|
2014-06-16 03:34:39 +02:00
|
|
|
struct locale *lang;
|
|
|
|
test_cleanup();
|
2014-06-16 07:17:08 +02:00
|
|
|
lang = get_or_create_locale("en");
|
|
|
|
CuAssertIntEquals(tc, NODIRECTION, get_direction("potato", lang));
|
|
|
|
CuAssertIntEquals(tc, D_SOUTHWEST, get_direction("southwest", lang));
|
|
|
|
CuAssertIntEquals(tc, D_SOUTHEAST, get_direction("southeast", lang));
|
|
|
|
CuAssertIntEquals(tc, D_NORTHWEST, get_direction("northwest", lang));
|
|
|
|
CuAssertIntEquals(tc, D_NORTHEAST, get_direction("northeast", lang));
|
|
|
|
CuAssertIntEquals(tc, D_WEST, get_direction("west", lang));
|
|
|
|
CuAssertIntEquals(tc, D_EAST, get_direction("east", lang));
|
2014-06-16 03:34:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-16 17:01:59 +02:00
|
|
|
#define SUITE_DISABLE_TEST(suite, test) (void)test
|
|
|
|
|
2014-06-16 03:34:39 +02:00
|
|
|
CuSuite *get_direction_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_init_direction);
|
|
|
|
SUITE_ADD_TEST(suite, test_init_directions);
|
2014-06-16 07:17:08 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_finddirection);
|
2014-06-16 17:01:59 +02:00
|
|
|
SUITE_DISABLE_TEST(suite, test_get_direction_default);
|
2014-06-16 03:34:39 +02:00
|
|
|
return suite;
|
|
|
|
}
|
|
|
|
|