148 lines
5.0 KiB
C
148 lines
5.0 KiB
C
#define CT_IMPLEMENTATION
|
|
#include "test.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
Channel *drawc;
|
|
Channel *keyc;
|
|
Channel *dictreqc;
|
|
Channel *dictresc;
|
|
Lang testvi;
|
|
|
|
void
|
|
die(char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
fprint(2, "unit_test: ");
|
|
va_start(ap, fmt);
|
|
vfprint(2, fmt, ap);
|
|
va_end(ap);
|
|
fprint(2, "\n");
|
|
threadexitsall("die");
|
|
}
|
|
|
|
void*
|
|
emalloc(ulong n)
|
|
{
|
|
void *p;
|
|
|
|
p = mallocz(n, 1);
|
|
if(p == nil)
|
|
die("out of memory");
|
|
return p;
|
|
}
|
|
|
|
void*
|
|
erealloc(void *p, ulong n)
|
|
{
|
|
p = realloc(p, n);
|
|
if(p == nil)
|
|
die("out of memory");
|
|
return p;
|
|
}
|
|
|
|
static void
|
|
testmapinit(void)
|
|
{
|
|
Lang *jp, *kata;
|
|
|
|
jp = getlang(LangJP);
|
|
kata = getlang(LangJPK);
|
|
if(jp == nil || kata == nil)
|
|
die("test language is not registered");
|
|
jp->map = trieopen("../map/hira.map");
|
|
kata->map = trieopen("../map/kata.map");
|
|
memset(&testvi, 0, sizeof testvi);
|
|
testvi.lang = LangVI;
|
|
testvi.mapname = "telex";
|
|
testvi.trans = transvi;
|
|
testvi.back = backvi;
|
|
testvi.map = trieopen("../map/telex.map");
|
|
}
|
|
|
|
static const struct ct_test tests[] = {
|
|
{ "str/init-utf8", str_init_utf8 },
|
|
{ "str/edit-and-alias", str_edit_and_alias },
|
|
{ "str/utf8-capacity", str_utf8_capacity },
|
|
{ "str/invalid-full-appends", str_invalid_and_full_appends },
|
|
{ "hmap/set-replace-grow", hmap_set_replace_and_grow },
|
|
{ "hmap/long-utf8-keys", hmap_long_utf8_keys },
|
|
{ "hmap/binary-invalid-lengths", hmap_binary_keys_and_invalid_lengths },
|
|
{ "trie/exact-prefix-duplicate", trie_exact_prefix_and_duplicate },
|
|
{ "trie/optional-invalid-lengths", trie_optional_outputs_and_invalid_lengths },
|
|
{ "wayland/press-release", wayland_press_release_state },
|
|
{ "wayland/repeat", wayland_repeat_state },
|
|
{ "wayland/repeat-cancellation", wayland_repeat_cancellation },
|
|
{ "popup/layout", popup_layout },
|
|
{ "map/production-lifecycle", production_maps_load },
|
|
{ "transmap/states", transmap_states },
|
|
{ "hangul/sequences", korean_sequences },
|
|
{ "hangul/compound-vowels", korean_compound_vowels },
|
|
{ "hangul/compound-finals", korean_compound_finals },
|
|
{ "hangul/backspace", korean_backspace },
|
|
{ "telex/transitions", vietnamese_transitions },
|
|
{ "telex/backspace", vietnamese_backspace },
|
|
{ "telex/state-lifetime", vietnamese_state_lifetime },
|
|
{ "engine/clears-candidates", engine_clears_candidates },
|
|
{ "engine/backspace-clears-candidates", engine_backspace_clears_candidates },
|
|
{ "engine/selects-visible-candidate", engine_selects_visible_candidate },
|
|
{ "engine/candidate-shortcut-modifiers", engine_candidate_shortcut_modifiers },
|
|
{ "engine/dictionary-queue-latest", engine_dictionary_queue_latest_wins },
|
|
{ "engine/active-owner-lifecycle", engine_active_owner_lifecycle },
|
|
{ "engine/active-owner-caret", engine_active_owner_caret },
|
|
{ "engine/commit-contract", engine_commit_contract },
|
|
{ "engine/language-switch-state", engine_language_switch_state },
|
|
{ "engine/telex-history-bound", engine_telex_history_bound },
|
|
{ "engine/korean-modifiers-backspace", engine_korean_modifiers_and_backspace },
|
|
{ "engine/direct-language-modes", engine_direct_language_modes },
|
|
{ "engine/japanese-readings", engine_japanese_readings },
|
|
{ "engine/japanese-candidates", engine_japanese_candidates },
|
|
{ "engine/japanese-backspace-boundaries", engine_japanese_backspace_and_boundaries },
|
|
{ "engine/katakana-sequences", engine_katakana_sequences },
|
|
{ "engine/emoji-single-candidate", engine_emoji_single_candidate },
|
|
{ "engine/emoji-queries", engine_emoji_queries },
|
|
{ "engine/emoji-japanese-multirune", engine_emoji_japanese_and_multirune },
|
|
{ "engine/emoji-digit-aliases", engine_emoji_digit_aliases },
|
|
{ "engine/emoji-navigation", engine_emoji_navigation },
|
|
{ "engine/emoji-preedit-languages", engine_emoji_preedit_languages },
|
|
{ "engine/emoji-start-and-unknown", engine_emoji_start_and_unknown },
|
|
{ "engine/emoji-dictionary-identity", engine_emoji_dictionary_identity },
|
|
{ "engine/randomized-stress", engine_randomized_stress },
|
|
{ "engine/full-boundary-passthrough", engine_full_boundary_passthrough },
|
|
{ "dict/candidates", dictionary_candidates },
|
|
{ "dict/misses-clear-result", dictionary_misses_clear_result },
|
|
{ "dict/emoji-identity", dictionary_emoji_identity },
|
|
{ "ipc/masks-modifiers", ipc_masks_modifiers },
|
|
{ "ipc/runtime-path", ipc_runtime_path },
|
|
{ "ipc/response-pack-boundaries", ipc_response_pack_boundaries },
|
|
{ "ipc/response-empty-preedit", ipc_response_empty_and_preedit },
|
|
{ "ipc/response-max-drain", ipc_response_max_and_drain },
|
|
{ "ipc/response-fragmented-truncated", ipc_response_fragmented_and_truncated },
|
|
{ "ipc/broken-peer-send", ipc_broken_peer_send },
|
|
};
|
|
|
|
void
|
|
threadmain(int argc, char **argv)
|
|
{
|
|
int i, status;
|
|
|
|
drawc = chancreate(sizeof(Drawcmd), 4);
|
|
keyc = chancreate(sizeof(Keyreq), 0);
|
|
dictreqc = chancreate(sizeof(Dictreq), 64);
|
|
dictresc = chancreate(sizeof(Dictres), 0);
|
|
testmapinit();
|
|
status = CT_RUN_ARGS(tests, argc, argv);
|
|
for(i = 0; i < nlang; i++){
|
|
trieclose(langs[i].map);
|
|
langs[i].map = nil;
|
|
}
|
|
trieclose(testvi.map);
|
|
testvi.map = nil;
|
|
chanfree(drawc);
|
|
chanfree(keyc);
|
|
chanfree(dictreqc);
|
|
chanfree(dictresc);
|
|
threadexitsall(status == 0 ? nil : "tests failed");
|
|
}
|