add focused unit and map checks
This commit is contained in:
112
tests/unit_test.c
Normal file
112
tests/unit_test.c
Normal file
@@ -0,0 +1,112 @@
|
||||
#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 = malloc(n);
|
||||
if(p == nil)
|
||||
die("out of memory");
|
||||
memset(p, 0, n);
|
||||
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;
|
||||
|
||||
jp = getlang(LangJP);
|
||||
if(jp == nil)
|
||||
die("test language is not registered");
|
||||
jp->map = trieopen("data/hira.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 },
|
||||
{ "hmap/set-replace-grow", hmap_set_replace_and_grow },
|
||||
{ "hmap/long-utf8-keys", hmap_long_utf8_keys },
|
||||
{ "trie/exact-prefix-duplicate", trie_exact_prefix_and_duplicate },
|
||||
{ "map/production-lifecycle", production_maps_load },
|
||||
{ "transmap/states", transmap_states },
|
||||
{ "hangul/sequences", korean_sequences },
|
||||
{ "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/selects-visible-candidate", engine_selects_visible_candidate },
|
||||
{ "engine/commit-contract", engine_commit_contract },
|
||||
{ "engine/telex-history-bound", engine_telex_history_bound },
|
||||
{ "dict/candidates", dictionary_candidates },
|
||||
{ "ipc/request-codec", ipc_request_codec },
|
||||
{ "ipc/response-pack-boundaries", ipc_response_pack_boundaries },
|
||||
{ "ipc/response-codec-drain", ipc_response_codec_and_drain },
|
||||
{ "ipc/truncated-frame", ipc_truncated_frame },
|
||||
{ "ipc/fragmented-request", ipc_fragmented_request },
|
||||
{ "ipc/closed-peer", ipc_closed_peer },
|
||||
};
|
||||
|
||||
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");
|
||||
}
|
||||
Reference in New Issue
Block a user