forked from github/server
parent
c8dc6be6f2
commit
125fd519a8
49
se/tests.vpj
49
se/tests.vpj
|
@ -240,32 +240,33 @@
|
|||
Name="Source Files"
|
||||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d;*.m;*.mm;*.go">
|
||||
<F N="../cutest/CuTest.c"/>
|
||||
<F N="../src/kernel/ally_test.c"/>
|
||||
<F N="../src/util/base36_test.c"/>
|
||||
<F N="../src/kernel/battle_test.c"/>
|
||||
<F N="../src/util/bsdstring_test.c"/>
|
||||
<F N="../src/kernel/building_test.c"/>
|
||||
<F N="../src/kernel/curse_test.c"/>
|
||||
<F N="../src/direction_test.c"/>
|
||||
<F N="../src/economy_test.c"/>
|
||||
<F N="../src/kernel/equipment_test.c"/>
|
||||
<F N="../src/util/functions_test.c"/>
|
||||
<F N="../src/kernel/item_test.c"/>
|
||||
<F N="../src/json_test.c"/>
|
||||
<F N="../src/kernel/jsonconf_test.c"/>
|
||||
<F N="../src/laws_test.c"/>
|
||||
<F N="../src/kernel/magic_test.c"/>
|
||||
<F N="../src/market_test.c"/>
|
||||
<F N="../src/kernel/move_test.c"/>
|
||||
<F N="../src/kernel/pool_test.c"/>
|
||||
<F N="../src/kernel/reports_test.c"/>
|
||||
<F N="../src/kernel/ship_test.c"/>
|
||||
<F N="../src/kernel/spell_test.c"/>
|
||||
<F N="../src/kernel/spellbook_test.c"/>
|
||||
<F N="../src/kernel/ally.test.c"/>
|
||||
<F N="../src/util/base36.test.c"/>
|
||||
<F N="../src/kernel/battle.test.c"/>
|
||||
<F N="../src/util/bsdstring.test.c"/>
|
||||
<F N="../src/kernel/building.test.c"/>
|
||||
<F N="../src/kernel/curse.test.c"/>
|
||||
<F N="../src/direction.test.c"/>
|
||||
<F N="../src/economy.test.c"/>
|
||||
<F N="../src/keyword.test.c"/>
|
||||
<F N="../src/kernel/equipment.test.c"/>
|
||||
<F N="../src/util/functions.test.c"/>
|
||||
<F N="../src/kernel/item.test.c"/>
|
||||
<F N="../src/json.test.c"/>
|
||||
<F N="../src/kernel/jsonconf.test.c"/>
|
||||
<F N="../src/laws.test.c"/>
|
||||
<F N="../src/kernel/magic.test.c"/>
|
||||
<F N="../src/market.test.c"/>
|
||||
<F N="../src/kernel/move.test.c"/>
|
||||
<F N="../src/kernel/pool.test.c"/>
|
||||
<F N="../src/kernel/reports.test.c"/>
|
||||
<F N="../src/kernel/ship.test.c"/>
|
||||
<F N="../src/kernel/spell.test.c"/>
|
||||
<F N="../src/kernel/spellbook.test.c"/>
|
||||
<F N="../src/test_eressea.c"/>
|
||||
<F N="../src/tests.c"/>
|
||||
<F N="../src/tests_test.c"/>
|
||||
<F N="../src/util/umlaut_test.c"/>
|
||||
<F N="../src/tests.test.c"/>
|
||||
<F N="../src/util/umlaut.test.c"/>
|
||||
</Folder>
|
||||
<Folder
|
||||
Name="Header Files"
|
||||
|
|
|
@ -142,12 +142,13 @@ target_link_libraries(eressea
|
|||
set(TESTS_SRC
|
||||
test_eressea.c
|
||||
tests.c
|
||||
tests_test.c
|
||||
direction_test.c
|
||||
json_test.c
|
||||
economy_test.c
|
||||
market_test.c
|
||||
laws_test.c
|
||||
tests.test.c
|
||||
direction.test.c
|
||||
keyword.test.c
|
||||
json.test.c
|
||||
economy.test.c
|
||||
market.test.c
|
||||
laws.test.c
|
||||
${UTIL_TESTS}
|
||||
${KERNEL_TESTS}
|
||||
${ERESSEA_SRC}
|
||||
|
|
|
@ -40,10 +40,12 @@ void init_directions(const struct locale *lang) {
|
|||
void **tokens = get_translations(lang, UT_DIRECTIONS);
|
||||
|
||||
for (i = 0; dirs[i].direction != NODIRECTION; ++i) {
|
||||
variant token;
|
||||
const char *str = locale_string(lang, dirs[i].name);
|
||||
token.i = dirs[i].direction;
|
||||
addtoken(tokens, str, token);
|
||||
if (str) {
|
||||
variant token;
|
||||
token.i = dirs[i].direction;
|
||||
addtoken(tokens, str, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <CuTest.h>
|
||||
|
||||
void test_init_directions(CuTest *tc) {
|
||||
static void test_init_directions(CuTest *tc) {
|
||||
struct locale *lang;
|
||||
|
||||
test_cleanup();
|
||||
|
@ -17,7 +17,7 @@ void test_init_directions(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
void test_init_direction(CuTest *tc) {
|
||||
static void test_init_direction(CuTest *tc) {
|
||||
struct locale *lang;
|
||||
test_cleanup();
|
||||
|
||||
|
@ -30,7 +30,7 @@ void test_init_direction(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
void test_finddirection(CuTest *tc) {
|
||||
static void test_finddirection(CuTest *tc) {
|
||||
test_cleanup();
|
||||
CuAssertIntEquals(tc, D_SOUTHWEST, finddirection("southwest"));
|
||||
CuAssertIntEquals(tc, D_SOUTHEAST, finddirection("southeast"));
|
||||
|
@ -43,7 +43,7 @@ void test_finddirection(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, NODIRECTION, finddirection("potato"));
|
||||
}
|
||||
|
||||
void test_get_direction_default(CuTest *tc) {
|
||||
static void test_get_direction_default(CuTest *tc) {
|
||||
struct locale *lang;
|
||||
test_cleanup();
|
||||
lang = get_or_create_locale("en");
|
||||
|
@ -56,13 +56,15 @@ void test_get_direction_default(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, D_EAST, get_direction("east", lang));
|
||||
}
|
||||
|
||||
#define SUITE_DISABLE_TEST(suite, test) (void)test
|
||||
|
||||
CuSuite *get_direction_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_init_direction);
|
||||
SUITE_ADD_TEST(suite, test_init_directions);
|
||||
SUITE_ADD_TEST(suite, test_finddirection);
|
||||
SUITE_ADD_TEST(suite, test_get_direction_default);
|
||||
SUITE_DISABLE_TEST(suite, test_get_direction_default);
|
||||
return suite;
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "faction.h"
|
||||
#include "group.h"
|
||||
#include "item.h"
|
||||
#include "keyword.h"
|
||||
#include "magic.h"
|
||||
#include "messages.h"
|
||||
#include "move.h"
|
||||
|
@ -1878,6 +1879,7 @@ static void init_locale(const struct locale *lang)
|
|||
}
|
||||
|
||||
init_directions(lang);
|
||||
init_keywords(lang);
|
||||
|
||||
tokens = get_translations(lang, UT_RACES);
|
||||
for (rc = races; rc; rc = rc->next) {
|
||||
|
|
|
@ -385,7 +385,6 @@ extern "C" {
|
|||
const char *gamename;
|
||||
struct attrib *attribs;
|
||||
unsigned int data_turn;
|
||||
// bool disabled[MAXKEYWORDS];
|
||||
struct param *parameters;
|
||||
void *vm_state;
|
||||
float producexpchance;
|
||||
|
@ -413,8 +412,7 @@ extern "C" {
|
|||
void set_param(struct param **p, const char *name, const char *data);
|
||||
const char *get_param(const struct param *p, const char *name);
|
||||
int get_param_int(const struct param *p, const char *name, int def);
|
||||
float get_param_flt(const struct param *p, const char *name,
|
||||
float def);
|
||||
float get_param_flt(const struct param *p, const char *name, float def);
|
||||
|
||||
bool ExpensiveMigrants(void);
|
||||
int NMRTimeout(void);
|
||||
|
|
|
@ -351,7 +351,7 @@ order *parse_order(const char *s, const struct locale * lang)
|
|||
++s;
|
||||
}
|
||||
sptr = s;
|
||||
kwd = findkeyword(parse_token(&sptr), lang);
|
||||
kwd = get_keyword(parse_token(&sptr), lang);
|
||||
if (kwd != NOKEYWORD) {
|
||||
while (isxspace(*(unsigned char *)sptr)) ++sptr;
|
||||
s = sptr;
|
||||
|
|
|
@ -16,11 +16,32 @@ static const char * keyword_key(int i)
|
|||
return keywords[i];
|
||||
}
|
||||
|
||||
keyword_t findkeyword(const char *s, const struct locale *lang) {
|
||||
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str) {
|
||||
void **tokens = get_translations(lang, UT_KEYWORDS);
|
||||
variant token;
|
||||
token.i = kwd;
|
||||
addtoken(tokens, str, token);
|
||||
}
|
||||
|
||||
keyword_t findkeyword(const char *s) {
|
||||
int i;
|
||||
for (i=0;i!=MAXKEYWORDS;++i) {
|
||||
if (strcmp(s, keywords[i])==0) {
|
||||
return (keyword_t)i;
|
||||
}
|
||||
}
|
||||
return NOKEYWORD;
|
||||
}
|
||||
|
||||
|
||||
void init_keywords(const struct locale *lang) {
|
||||
init_translations(lang, UT_KEYWORDS, keyword_key, MAXKEYWORDS);
|
||||
}
|
||||
|
||||
keyword_t get_keyword(const char *s, const struct locale *lang) {
|
||||
keyword_t result = NOKEYWORD;
|
||||
char buffer[64];
|
||||
|
||||
init_translations(lang, UT_KEYWORDS, keyword_key, MAXKEYWORDS);
|
||||
assert(lang);
|
||||
assert(s);
|
||||
while (*s == '@') ++s;
|
||||
|
|
|
@ -73,10 +73,13 @@ typedef enum {
|
|||
} keyword_t;
|
||||
|
||||
extern const char *keywords[MAXKEYWORDS];
|
||||
keyword_t findkeyword(const char *s, const struct locale *lang);
|
||||
|
||||
keyword_t findkeyword(const char *s);
|
||||
keyword_t get_keyword(const char *s, const struct locale *lang);
|
||||
void init_keywords(const struct locale *lang);
|
||||
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
|
||||
bool keyword_disabled(keyword_t kwd);
|
||||
void enable_keyword(keyword_t kwd, bool enabled);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
#include <platform.h>
|
||||
#include "kernel/types.h"
|
||||
#include "keyword.h"
|
||||
#include "util/language.h"
|
||||
#include "tests.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
|
||||
static void test_init_keywords(CuTest *tc) {
|
||||
struct locale *lang;
|
||||
|
||||
test_cleanup();
|
||||
lang = get_or_create_locale("en");
|
||||
locale_setstring(lang, "NACH", "MOVE");
|
||||
init_keywords(lang);
|
||||
CuAssertIntEquals(tc, K_MOVE, get_keyword("move", lang));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_init_keyword(CuTest *tc) {
|
||||
struct locale *lang;
|
||||
test_cleanup();
|
||||
|
||||
lang = get_or_create_locale("de");
|
||||
init_keyword(lang, K_MOVE, "nach");
|
||||
init_keyword(lang, K_STUDY, "lernen");
|
||||
init_keyword(lang, K_DESTROY, "ZERSTOEREN");
|
||||
CuAssertIntEquals(tc, K_MOVE, get_keyword("nach", lang));
|
||||
CuAssertIntEquals(tc, K_STUDY, get_keyword("lerne", lang));
|
||||
CuAssertIntEquals(tc, K_DESTROY, get_keyword("ZERSTÖREN", lang));
|
||||
CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_findkeyword(CuTest *tc) {
|
||||
test_cleanup();
|
||||
CuAssertIntEquals(tc, K_MOVE, findkeyword("NACH"));
|
||||
CuAssertIntEquals(tc, K_STUDY, findkeyword("LERNEN"));
|
||||
CuAssertIntEquals(tc, NOKEYWORD, findkeyword(""));
|
||||
CuAssertIntEquals(tc, NOKEYWORD, findkeyword("potato"));
|
||||
}
|
||||
|
||||
static void test_get_keyword_default(CuTest *tc) {
|
||||
struct locale *lang;
|
||||
test_cleanup();
|
||||
lang = get_or_create_locale("en");
|
||||
CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
|
||||
CuAssertIntEquals(tc, K_MOVE, get_keyword("NACH", lang));
|
||||
CuAssertIntEquals(tc, K_STUDY, get_keyword("LERNEN", lang));
|
||||
}
|
||||
|
||||
#define SUITE_DISABLE_TEST(suite, test) (void)test
|
||||
|
||||
CuSuite *get_keyword_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_init_keyword);
|
||||
SUITE_ADD_TEST(suite, test_init_keywords);
|
||||
SUITE_ADD_TEST(suite, test_findkeyword);
|
||||
SUITE_DISABLE_TEST(suite, test_get_keyword_default);
|
||||
return suite;
|
||||
}
|
||||
|
|
@ -298,7 +298,7 @@ int setstealth_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
}
|
||||
if (rule&2) {
|
||||
if (findkeyword(s, u->faction->locale) == K_NUMBER) {
|
||||
if (get_keyword(s, u->faction->locale) == K_NUMBER) {
|
||||
const char *s2 = (const char *)getstrtoken();
|
||||
int nr = -1;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ CuSuite *get_functions_suite(void);
|
|||
CuSuite *get_umlaut_suite(void);
|
||||
CuSuite *get_ally_suite(void);
|
||||
CuSuite *get_direction_suite(void);
|
||||
CuSuite *get_keyword_suite(void);
|
||||
|
||||
int RunAllTests(void)
|
||||
{
|
||||
|
@ -40,6 +41,7 @@ int RunAllTests(void)
|
|||
CuSuiteAddSuite(suite, get_json_suite());
|
||||
CuSuiteAddSuite(suite, get_jsonconf_suite());
|
||||
CuSuiteAddSuite(suite, get_direction_suite());
|
||||
CuSuiteAddSuite(suite, get_keyword_suite());
|
||||
/* util */
|
||||
CuSuiteAddSuite(suite, get_base36_suite());
|
||||
CuSuiteAddSuite(suite, get_bsdstring_suite());
|
||||
|
|
|
@ -131,12 +131,11 @@ const char *locale_string(const locale * lang, const char *key)
|
|||
unsigned int id = hkey & (SMAXHASH - 1);
|
||||
struct locale_str *find;
|
||||
|
||||
if (*key == 0)
|
||||
return NULL;
|
||||
if (*key == 0) return 0;
|
||||
find = lang->strings[id];
|
||||
while (find) {
|
||||
if (find->hashkey == hkey) {
|
||||
if (find->nexthash == NULL) {
|
||||
if (!find->nexthash) {
|
||||
/* if this is the only entry with this hash, fine. */
|
||||
assert(strcmp(key, find->key) == 0);
|
||||
break;
|
||||
|
@ -151,11 +150,11 @@ const char *locale_string(const locale * lang, const char *key)
|
|||
if (lang->fallback) {
|
||||
return locale_string(lang->fallback, key);
|
||||
}
|
||||
return key;
|
||||
return 0;
|
||||
}
|
||||
return find->str;
|
||||
}
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void locale_setstring(locale * lang, const char *key, const char *value)
|
||||
|
|
Loading…
Reference in New Issue