Debian Codegraph @

tests/suggestChunks.c

raw symbols SCIP
1 /* liblouis Braille Translation and Back-Translation Library
2
3 Copyright (C) 2017 Swiss Library for the Blind, Visually Impaired and Print Disabled
4
5 Copying and distribution of this file, with or without modification,
6 are permitted in any medium without royalty provided the copyright
7 notice and this notice are preserved. This file is offered as-is,
8 without any warranty. */
9
10 #include <config.h>
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include "internal.h"
16
17 extern void loadTable(const char *tableList);
18 extern int hyphenationEnabled();
19 extern widechar toLowercase(widechar c);
20 extern int suggestChunks(widechar *text, widechar *braille, char *hyphen_string);
21
22 static int test_toLowercase() {
23 widechar upper = 'A';
24 widechar lower = 'a';
25 return lower != toLowercase(upper);
26 }
27
28 static int check_suggestion(const char* text, const char* braille, const char* expected_hyphen_string) {
29 int in_len = strlen(text);
30 int out_len = in_len;
31 widechar *inbuf = malloc(sizeof(widechar) * (in_len + 1));
32 widechar *outbuf = malloc(sizeof(widechar) * (out_len + 1));
33 in_len = _lou_extParseChars(text, inbuf);
34 out_len = _lou_extParseChars(braille, outbuf);
35 inbuf[in_len] = '\0';
36 outbuf[out_len] = '\0';
37 char *hyphen_string = malloc(sizeof(char) * (in_len + 2));
38 int ret;
39 if (!suggestChunks(inbuf, outbuf, hyphen_string)) {
40 printf("Could not find a solution for %s => %s\n", text, braille);
41 ret = 1;
42 } else if (strcmp(expected_hyphen_string, hyphen_string) != 0) {
43 printf("Expected %s but got %s\n", expected_hyphen_string, hyphen_string);
44 ret = 1;
45 } else
46 ret = 0;
47 free(inbuf);
48 free(outbuf);
49 free(hyphen_string);
50 return ret;
51 }
52
53 int main(int argc, char **argv) {
54 int result = 0;
55
56 loadTable("tests/tables/suggestChunks.ctb");
57
58 result |= test_toLowercase();
59 result |= hyphenationEnabled();
60
61 result |= check_suggestion("foobar", "FUBR", "^00x00$");
62
63 // check that this long word does not take ages
64 result |= check_suggestion("achtunddreißigtausenddreihundertsiebzehn",
65 "A4TUNDDR3^IGT1SENDDR3HUNDERTS0BZEHN",
66 "^x0xxxxxxx0xxxxx0xxxxxxx0xxxxxxxxx0xxxxx$");
67
68 // n(or)m|(al)|(lich)tque|(ll)e
69 result |= check_suggestion("normallichtquelle",
70 "N?M:_T'QUEQE",
71 "^x0x101000xxxx10x$");
72
73 return result;
74 }