static void test_finddirection(CuTest *tc) { 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")); }
static void json_direction(cJSON *json, struct locale *lang) { cJSON *child; if (json->type!=cJSON_Object) { log_error("directions for locale `%s` not a json object: %d", locale_name(lang), json->type); return; } for (child=json->child;child;child=child->next) { direction_t dir = finddirection(child->string); if (dir!=NODIRECTION) { if (child->type==cJSON_String) { init_direction(lang, dir, child->valuestring); } else if (child->type==cJSON_Array) { cJSON *entry; for (entry=child->child;entry;entry=entry->next) { init_direction(lang, dir, entry->valuestring); } } else { log_error("invalid type %d for direction `%s`", child->type, child->string); } } } }