readclause.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*
  2. * Copyright (C) 2017 Reece H. Dunn
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write see:
  16. * <http://www.gnu.org/licenses/>.
  17. */
  18. #include "config.h"
  19. #include <assert.h>
  20. #include <errno.h>
  21. #include <stdint.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <sys/stat.h>
  26. #include <espeak-ng/espeak_ng.h>
  27. #include <espeak-ng/encoding.h>
  28. #include "readclause.h"
  29. #include "speech.h"
  30. #include "phoneme.h"
  31. #include "voice.h"
  32. #include "synthesize.h"
  33. #include "translate.h"
  34. // Arguments to ReadClause. Declared here to avoid duplicating them across the
  35. // different test functions.
  36. static char source[N_TR_SOURCE+40]; // extra space for embedded command & voice change info at end
  37. static short charix[N_TR_SOURCE+4];
  38. static int charix_top = 0;
  39. static int tone2;
  40. static char voice_change_name[40];
  41. static espeak_ng_STATUS
  42. set_text(const char *text, const char *voicename)
  43. {
  44. espeak_ng_STATUS status = espeak_ng_SetVoiceByName(voicename);
  45. if (status != ENS_OK)
  46. return status;
  47. if (p_decoder == NULL)
  48. p_decoder = create_text_decoder();
  49. count_characters = 0;
  50. return text_decoder_decode_string(p_decoder, text, -1, ESPEAKNG_ENCODING_UTF_8);
  51. }
  52. static void
  53. test_latin()
  54. {
  55. printf("testing Latin (Latn)\n");
  56. assert(clause_type_from_codepoint('?') == CLAUSE_QUESTION);
  57. assert(clause_type_from_codepoint('!') == CLAUSE_EXCLAMATION);
  58. assert(clause_type_from_codepoint(',') == CLAUSE_COMMA);
  59. assert(clause_type_from_codepoint(':') == CLAUSE_COLON);
  60. assert(clause_type_from_codepoint(';') == CLAUSE_SEMICOLON);
  61. assert(clause_type_from_codepoint(0x00A1) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  62. assert(clause_type_from_codepoint(0x00Bf) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  63. assert(clause_type_from_codepoint(0x2013) == CLAUSE_SEMICOLON);
  64. assert(clause_type_from_codepoint(0x2014) == CLAUSE_SEMICOLON);
  65. assert(clause_type_from_codepoint(0x2026) == (CLAUSE_SEMICOLON | CLAUSE_SPEAK_PUNCTUATION_NAME | CLAUSE_OPTIONAL_SPACE_AFTER));
  66. }
  67. static void
  68. test_latin_sentence()
  69. {
  70. printf("testing Latin (Latn) ... sentence\n");
  71. assert(clause_type_from_codepoint('a') == CLAUSE_NONE);
  72. assert(clause_type_from_codepoint('.') == CLAUSE_PERIOD);
  73. short retix[] = {
  74. 0, 2, 3, 4, 5, 6, // Jane
  75. 0, 8, 9, 10, 11, 12, 13, 14, 15, // finished
  76. 0, 17, 18, // #1
  77. 0, 20, 21, // in
  78. 0, 23, 24, 25, // the
  79. 0, 27, 28, 29, 30 }; // race
  80. assert(set_text("Janet finished #1 in the race.", "en") == ENS_OK);
  81. charix_top = 0;
  82. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == (CLAUSE_PERIOD | CLAUSE_DOT_AFTER_LAST_WORD));
  83. assert(!strcmp(source, "Janet finished #1 in the race "));
  84. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 1);
  85. assert(!memcmp(charix, retix, sizeof(retix)));
  86. assert(tone2 == 0);
  87. assert(voice_change_name[0] == 0);
  88. charix_top = 0;
  89. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  90. assert(!strcmp(source, " "));
  91. assert(charix_top == 0);
  92. }
  93. static void
  94. test_greek()
  95. {
  96. printf("testing Greek (Grek)\n");
  97. assert(clause_type_from_codepoint(0x037E) == CLAUSE_QUESTION);
  98. assert(clause_type_from_codepoint(0x0387) == CLAUSE_SEMICOLON);
  99. }
  100. static void
  101. test_armenian()
  102. {
  103. printf("testing Armenian (Armn)\n");
  104. assert(clause_type_from_codepoint(0x055B) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD));
  105. assert(clause_type_from_codepoint(0x055C) == (CLAUSE_EXCLAMATION | CLAUSE_PUNCTUATION_IN_WORD));
  106. assert(clause_type_from_codepoint(0x055D) == CLAUSE_COMMA);
  107. assert(clause_type_from_codepoint(0x055E) == (CLAUSE_QUESTION | CLAUSE_PUNCTUATION_IN_WORD));
  108. assert(clause_type_from_codepoint(0x0589) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  109. }
  110. static void
  111. test_arabic()
  112. {
  113. printf("testing Arabic (Arab)\n");
  114. assert(clause_type_from_codepoint(0x060C) == CLAUSE_COMMA);
  115. assert(clause_type_from_codepoint(0x061B) == CLAUSE_SEMICOLON);
  116. assert(clause_type_from_codepoint(0x061F) == CLAUSE_QUESTION);
  117. assert(clause_type_from_codepoint(0x06D4) == CLAUSE_PERIOD);
  118. }
  119. static void
  120. test_devanagari()
  121. {
  122. printf("testing Devanagari (Deva)\n");
  123. assert(clause_type_from_codepoint(0x0964) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  124. }
  125. static void
  126. test_tibetan()
  127. {
  128. printf("testing Tibetan (Tibt)\n");
  129. assert(clause_type_from_codepoint(0x0F0D) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  130. assert(clause_type_from_codepoint(0x0F0E) == CLAUSE_PARAGRAPH);
  131. }
  132. static void
  133. test_sinhala()
  134. {
  135. printf("testing Sinhala (Sinh)\n");
  136. assert(clause_type_from_codepoint(0x0DF4) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  137. }
  138. static void
  139. test_georgian()
  140. {
  141. printf("testing Georgian (Geor)\n");
  142. assert(clause_type_from_codepoint(0x10FB) == CLAUSE_PARAGRAPH);
  143. }
  144. static void
  145. test_ethiopic()
  146. {
  147. printf("testing Ethiopic (Ethi)\n");
  148. assert(clause_type_from_codepoint(0x1362) == CLAUSE_PERIOD);
  149. assert(clause_type_from_codepoint(0x1363) == CLAUSE_COMMA);
  150. assert(clause_type_from_codepoint(0x1364) == CLAUSE_SEMICOLON);
  151. assert(clause_type_from_codepoint(0x1365) == CLAUSE_COLON);
  152. assert(clause_type_from_codepoint(0x1366) == CLAUSE_COLON);
  153. assert(clause_type_from_codepoint(0x1367) == CLAUSE_QUESTION);
  154. assert(clause_type_from_codepoint(0x1368) == CLAUSE_PARAGRAPH);
  155. }
  156. static void
  157. test_ideographic()
  158. {
  159. printf("testing Ideographic (Hani)\n");
  160. assert(clause_type_from_codepoint(0x3001) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
  161. assert(clause_type_from_codepoint(0x3002) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  162. }
  163. static void
  164. test_fullwidth()
  165. {
  166. printf("testing Full Width\n");
  167. assert(clause_type_from_codepoint(0xFF01) == (CLAUSE_EXCLAMATION | CLAUSE_OPTIONAL_SPACE_AFTER));
  168. assert(clause_type_from_codepoint(0xFF0C) == (CLAUSE_COMMA | CLAUSE_OPTIONAL_SPACE_AFTER));
  169. assert(clause_type_from_codepoint(0xFF0E) == (CLAUSE_PERIOD | CLAUSE_OPTIONAL_SPACE_AFTER));
  170. assert(clause_type_from_codepoint(0xFF1A) == (CLAUSE_COLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  171. assert(clause_type_from_codepoint(0xFF1B) == (CLAUSE_SEMICOLON | CLAUSE_OPTIONAL_SPACE_AFTER));
  172. assert(clause_type_from_codepoint(0xFF1F) == (CLAUSE_QUESTION | CLAUSE_OPTIONAL_SPACE_AFTER));
  173. }
  174. static void
  175. test_uts51_emoji_character()
  176. {
  177. printf("testing Emoji ... UTS-51 ED-3. emoji character\n");
  178. short retix[] = {
  179. 0, -1, -1,
  180. 2, -1, -1,
  181. 3, -1, -1,
  182. 4, -1, -1, -1,
  183. 5, -1, -1, -1,
  184. 6 };
  185. assert(set_text(
  186. "\xE2\x86\x94" // [2194] left right arrow
  187. "\xE2\x86\x95" // [2195] up down arrow
  188. "\xE2\x9B\x94" // [26D5] no entry
  189. "\xF0\x9F\x90\x8B" // [1F40B] whale
  190. "\xF0\x9F\x90\xAC", // [1F42C] dolphin
  191. "en") == ENS_OK);
  192. charix_top = 0;
  193. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  194. assert(!strcmp(source,
  195. "\xE2\x86\x94" // [2194] left right arrow
  196. "\xE2\x86\x95" // [2195] up down arrow
  197. "\xE2\x9B\x94" // [26D5] no entry
  198. "\xF0\x9F\x90\x8B" // [1F40B] whale
  199. "\xF0\x9F\x90\xAC" // [1F42C] dolphin
  200. " "));
  201. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 1);
  202. assert(!memcmp(charix, retix, sizeof(retix)));
  203. assert(tone2 == 0);
  204. assert(voice_change_name[0] == 0);
  205. }
  206. static void
  207. test_uts51_text_presentation_sequence()
  208. {
  209. printf("testing Emoji ... UTS-51 ED-8a. text presentation sequence\n");
  210. short retix[] = {
  211. 0, 2, -1, -1,
  212. 3, 4, -1, -1,
  213. 5, -1, -1, 6, -1, -1,
  214. 7, -1, -1, -1, 8, -1, -1,
  215. 9 };
  216. assert(set_text(
  217. "#\xEF\xB8\x8E" // [0023 FE0E] number sign (text style)
  218. "4\xEF\xB8\x8E" // [0034 FE0E] digit four (text style)
  219. "\xE2\x80\xBC\xEF\xB8\x8E" // [203C FE0E] double exclamation mark (text style)
  220. "\xF0\x9F\x97\x92\xEF\xB8\x8E", // [1F5D2 FE0E] spiral note pad (text style)
  221. "en") == ENS_OK);
  222. charix_top = 0;
  223. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  224. assert(!strcmp(source,
  225. "#\xEF\xB8\x8E" // [0023 FE0E] number sign (text style)
  226. "4\xEF\xB8\x8E" // [0034 FE0E] digit four (text style)
  227. "\xE2\x80\xBC\xEF\xB8\x8E" // [203C FE0E] double exclamation mark (text style)
  228. "\xF0\x9F\x97\x92\xEF\xB8\x8E" // [1F5D2 FE0E] spiral note pad (text style)
  229. " "));
  230. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 1);
  231. assert(!memcmp(charix, retix, sizeof(retix)));
  232. assert(tone2 == 0);
  233. assert(voice_change_name[0] == 0);
  234. }
  235. static void
  236. test_uts51_emoji_presentation_sequence()
  237. {
  238. printf("testing Emoji ... UTS-51 ED-9a. emoji presentation sequence\n");
  239. short retix[] = {
  240. 0, 2, -1, -1,
  241. 3, 4, -1, -1,
  242. 5, -1, -1, 6, -1, -1,
  243. 7, -1, -1, -1, 8, -1, -1,
  244. 9 };
  245. assert(set_text(
  246. "#\xEF\xB8\x8F" // [0023 FE0F] number sign (emoji style)
  247. "4\xEF\xB8\x8F" // [0034 FE0F] digit four (emoji style)
  248. "\xE2\x80\xBC\xEF\xB8\x8F" // [203C FE0F] double exclamation mark (emoji style)
  249. "\xF0\x9F\x97\x92\xEF\xB8\x8F", // [1F5D2 FE0F] spiral note pad (emoji style)
  250. "en") == ENS_OK);
  251. charix_top = 0;
  252. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  253. assert(!strcmp(source,
  254. "#\xEF\xB8\x8F" // [0023 FE0F] number sign (emoji style)
  255. "4\xEF\xB8\x8F" // [0034 FE0F] digit four (emoji style)
  256. "\xE2\x80\xBC\xEF\xB8\x8F" // [203C FE0F] double exclamation mark (emoji style)
  257. "\xF0\x9F\x97\x92\xEF\xB8\x8F" // [1F5D2 FE0F] spiral note pad (emoji style)
  258. " "));
  259. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 1);
  260. assert(!memcmp(charix, retix, sizeof(retix)));
  261. assert(tone2 == 0);
  262. assert(voice_change_name[0] == 0);
  263. }
  264. static void
  265. test_uts51_emoji_modifier_sequence()
  266. {
  267. printf("testing Emoji ... UTS-51 ED-13. emoji modifier sequence\n");
  268. short retix[] = {
  269. 0, -1, -1, 2, -1, -1, -1,
  270. 3, -1, -1, -1, 4, -1, -1, -1,
  271. 5, -1, -1, -1, 6, -1, -1, -1,
  272. 7 };
  273. assert(set_text(
  274. "\xE2\x98\x9D\xF0\x9F\x8F\xBB" // [261D 1F3FB] index pointing up; light skin tone
  275. "\xF0\x9F\x91\xB0\xF0\x9F\x8F\xBD" // [1F5D2 1F3FD] bride with veil; medium skin tone
  276. "\xF0\x9F\x92\xAA\xF0\x9F\x8F\xBF", // [1F4AA 1F3FF] flexed biceps; dark skin tone
  277. "en") == ENS_OK);
  278. charix_top = 0;
  279. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  280. assert(!strcmp(source,
  281. "\xE2\x98\x9D\xF0\x9F\x8F\xBB" // [261D 1F3FB] index pointing up; light skin tone
  282. "\xF0\x9F\x91\xB0\xF0\x9F\x8F\xBD" // [1F5D2 1F3FD] bride with veil; medium skin tone
  283. "\xF0\x9F\x92\xAA\xF0\x9F\x8F\xBF" // [1F4AA 1F3FF] flexed biceps; dark skin tone
  284. " "));
  285. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 1);
  286. assert(!memcmp(charix, retix, sizeof(retix)));
  287. assert(tone2 == 0);
  288. assert(voice_change_name[0] == 0);
  289. }
  290. static void
  291. test_uts51_emoji_flag_sequence()
  292. {
  293. printf("testing Emoji ... UTS-51 ED-14. emoji flag sequence\n");
  294. short retix[] = {
  295. 0, -1, -1, -1, 2, -1, -1, -1,
  296. 3, -1, -1, -1, 4, -1, -1, -1,
  297. 5, -1, -1, -1, 6, -1, -1, -1,
  298. 7, -1, -1, -1, 8, -1, -1, -1,
  299. 9 };
  300. assert(set_text(
  301. "\xF0\x9F\x87\xA6\xF0\x9F\x87\xB7" // [1F1E6 1F1F7] AR (argentina)
  302. "\xF0\x9F\x87\xA7\xF0\x9F\x87\xAC" // [1F1E7 1F1EC] BG (bulgaria)
  303. "\xF0\x9F\x87\xAC\xF0\x9F\x87\xA8" // [1F1EC 1F1E8] GC -- unknown country flag
  304. "\xF0\x9F\x87\xAC\xF0\x9F\x87\xB1", // [1F1EC 1F1F1] GL (greenland)
  305. "en") == ENS_OK);
  306. charix_top = 0;
  307. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  308. assert(!strcmp(source,
  309. "\xF0\x9F\x87\xA6\xF0\x9F\x87\xB7" // [1F1E6 1F1F7] AR (argentina)
  310. "\xF0\x9F\x87\xA7\xF0\x9F\x87\xAC" // [1F1E7 1F1EC] BG (bulgaria)
  311. "\xF0\x9F\x87\xAC\xF0\x9F\x87\xA8" // [1F1EC 1F1E8] GC -- unknown country flag
  312. "\xF0\x9F\x87\xAC\xF0\x9F\x87\xB1" // [1F1EC 1F1F1] GL (greenland)
  313. " "));
  314. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 1);
  315. assert(!memcmp(charix, retix, sizeof(retix)));
  316. assert(tone2 == 0);
  317. assert(voice_change_name[0] == 0);
  318. }
  319. static void
  320. test_uts51_emoji_tag_sequence_emoji_character()
  321. {
  322. printf("testing Emoji ... UTS-51 ED-14a. emoji tag sequence (emoji character)\n");
  323. short retix[] = {
  324. 0, -1, -1, -1, // emoji character
  325. 2, -1, -1, -1, 3, -1, -1, -1, 4, -1, -1, -1, 5, -1, -1, -1, 6, -1, -1, -1, // tag spec
  326. 7, -1, -1, -1, // tag term
  327. 8, -1, -1, -1, // emoji character
  328. 9, -1, -1, -1, 10, -1, -1, -1, 11, -1, -1, -1, 12, -1, -1, -1, 13, -1, -1, -1, // tag spec
  329. 14, -1, -1, -1, // tag term
  330. 15, -1, -1, -1, // emoji character
  331. 16, -1, -1, -1, 17, -1, -1, -1, 18, -1, -1, -1, 19, -1, -1, -1, // tag spec
  332. 20, -1, -1, -1, // tag term
  333. 21 };
  334. assert(set_text(
  335. // tag_base = emoji_character (RGI sequence)
  336. "\xF0\x9F\x8F\xB4" // [1F3F4] flag
  337. "\xF3\xA0\x81\xA7" // [E0067] tag : g
  338. "\xF3\xA0\x81\xA2" // [E0062] tag : b
  339. "\xF3\xA0\x81\xA5" // [E0065] tag : e
  340. "\xF3\xA0\x81\xAE" // [E006E] tag : n
  341. "\xF3\xA0\x81\xA7" // [E006E] tag : g
  342. "\xF3\xA0\x81\xBF" // [E007F] tag : (cancel)
  343. // tag_base = emoji_character (RGI sequence)
  344. "\xF0\x9F\x8F\xB4" // [1F3F4] flag
  345. "\xF3\xA0\x81\xA7" // [E0067] tag : g
  346. "\xF3\xA0\x81\xA2" // [E0062] tag : b
  347. "\xF3\xA0\x81\xB3" // [E0065] tag : s
  348. "\xF3\xA0\x81\xA3" // [E006E] tag : c
  349. "\xF3\xA0\x81\xB4" // [E006E] tag : t
  350. "\xF3\xA0\x81\xBF" // [E007F] tag : (cancel)
  351. // tag_base = emoji_character (non-RGI sequence)
  352. "\xF0\x9F\x8F\xB4" // [1F3F4] flag
  353. "\xF3\xA0\x81\xB5" // [E0067] tag : u
  354. "\xF3\xA0\x81\xB3" // [E0062] tag : s
  355. "\xF3\xA0\x81\xA3" // [E0065] tag : c
  356. "\xF3\xA0\x81\xA1" // [E006E] tag : a
  357. "\xF3\xA0\x81\xBF", // [E007F] tag : (cancel)
  358. "en") == ENS_OK);
  359. charix_top = 0;
  360. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  361. assert(!strcmp(source,
  362. // tag_base = emoji_character (RGI sequence)
  363. "\xF0\x9F\x8F\xB4" // [1F3F4] flag
  364. "\xF3\xA0\x81\xA7" // [E0067] tag : g
  365. "\xF3\xA0\x81\xA2" // [E0062] tag : b
  366. "\xF3\xA0\x81\xA5" // [E0065] tag : e
  367. "\xF3\xA0\x81\xAE" // [E006E] tag : n
  368. "\xF3\xA0\x81\xA7" // [E006E] tag : g
  369. "\xF3\xA0\x81\xBF" // [E007F] tag : (cancel)
  370. // tag_base = emoji_character (RGI sequence)
  371. "\xF0\x9F\x8F\xB4" // [1F3F4] flag
  372. "\xF3\xA0\x81\xA7" // [E0067] tag : g
  373. "\xF3\xA0\x81\xA2" // [E0062] tag : b
  374. "\xF3\xA0\x81\xB3" // [E0065] tag : s
  375. "\xF3\xA0\x81\xA3" // [E006E] tag : c
  376. "\xF3\xA0\x81\xB4" // [E006E] tag : t
  377. "\xF3\xA0\x81\xBF" // [E007F] tag : (cancel)
  378. // tag_base = emoji_character (non-RGI sequence)
  379. "\xF0\x9F\x8F\xB4" // [1F3F4] flag
  380. "\xF3\xA0\x81\xB5" // [E0067] tag : u
  381. "\xF3\xA0\x81\xB3" // [E0062] tag : s
  382. "\xF3\xA0\x81\xA3" // [E0065] tag : c
  383. "\xF3\xA0\x81\xA1" // [E006E] tag : a
  384. "\xF3\xA0\x81\xBF" // [E007F] tag : (cancel)
  385. " "));
  386. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 1);
  387. assert(!memcmp(charix, retix, sizeof(retix)));
  388. assert(tone2 == 0);
  389. assert(voice_change_name[0] == 0);
  390. }
  391. static void
  392. test_uts51_emoji_combining_sequence()
  393. {
  394. printf("testing Emoji ... UTS-51 ED-14b. emoji combining sequence\n");
  395. short retix[] = {
  396. 0, -1, -1, 2, -1, -1, // emoji character
  397. 3, -1, -1, 4, -1, -1, 5, -1, -1, // text presentation sequence
  398. 6, -1, -1, 7, -1, -1, 8, -1, -1, // emoji presentation sequence
  399. 9 };
  400. assert(set_text(
  401. "\xE2\x86\x95\xE2\x83\x9E" // [2195 20DE] up down arrow; Me (enclosing square)
  402. "\xE2\x86\x95\xEF\xB8\x8E\xE2\x83\x9E" // [2195 FE0E 20DE] up down arrow; Me (enclosing square)
  403. "\xE2\x86\x95\xEF\xB8\x8F\xE2\x83\x9E", // [2195 FE0F 20DE] up down arrow; Me (enclosing square)
  404. "en") == ENS_OK);
  405. charix_top = 0;
  406. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  407. assert(!strcmp(source,
  408. "\xE2\x86\x95\xE2\x83\x9E" // [2195 20DE] up down arrow; Me (enclosing square)
  409. "\xE2\x86\x95\xEF\xB8\x8E\xE2\x83\x9E" // [2195 FE0E 20DE] up down arrow; Me (enclosing square)
  410. "\xE2\x86\x95\xEF\xB8\x8F\xE2\x83\x9E" // [2195 FE0F 20DE] up down arrow; Me (enclosing square)
  411. " "));
  412. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 1);
  413. assert(!memcmp(charix, retix, sizeof(retix)));
  414. assert(tone2 == 0);
  415. assert(voice_change_name[0] == 0);
  416. }
  417. static void
  418. test_uts51_emoji_keycap_sequence()
  419. {
  420. printf("testing Emoji ... UTS-51 ED-14c. emoji keycap sequence\n");
  421. short retix[] = {
  422. 0, 2, -1, -1, 3, -1, -1,
  423. 4, 5, -1, -1, 6, -1, -1,
  424. 7, 8, -1, -1, 9, -1, -1,
  425. 10 };
  426. assert(set_text(
  427. "5\xEF\xB8\x8E\xE2\x83\xA3" // [0035 FE0E 20E3] keycap 5
  428. "#\xEF\xB8\x8E\xE2\x83\xA3" // [0023 FE0E 20E3] keycap #
  429. "*\xEF\xB8\x8E\xE2\x83\xA3", // [002A FE0E 20E3] keycap *
  430. "en") == ENS_OK);
  431. charix_top = 0;
  432. assert(ReadClause(translator, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name) == CLAUSE_EOF);
  433. assert(!strcmp(source,
  434. "5\xEF\xB8\x8E\xE2\x83\xA3" // [0035 FE0E 20E3] keycap 5
  435. "#\xEF\xB8\x8E\xE2\x83\xA3" // [0023 FE0E 20E3] keycap #
  436. "*\xEF\xB8\x8E\xE2\x83\xA3" // [002A FE0E 20E3] keycap *
  437. " "));
  438. assert(charix_top == (sizeof(retix)/sizeof(retix[0])) - 1);
  439. assert(!memcmp(charix, retix, sizeof(retix)));
  440. assert(tone2 == 0);
  441. assert(voice_change_name[0] == 0);
  442. }
  443. int
  444. main(int argc, char **argv)
  445. {
  446. (void)argc; // unused parameter
  447. (void)argv; // unused parameter
  448. assert(espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, espeakINITIALIZE_DONT_EXIT) == 22050);
  449. test_latin();
  450. test_latin_sentence();
  451. test_greek();
  452. test_armenian();
  453. test_arabic();
  454. test_devanagari();
  455. test_tibetan();
  456. test_sinhala();
  457. test_georgian();
  458. test_ethiopic();
  459. test_ideographic();
  460. test_fullwidth();
  461. test_uts51_emoji_character();
  462. test_uts51_text_presentation_sequence();
  463. test_uts51_emoji_presentation_sequence();
  464. test_uts51_emoji_modifier_sequence();
  465. test_uts51_emoji_flag_sequence();
  466. test_uts51_emoji_tag_sequence_emoji_character();
  467. test_uts51_emoji_combining_sequence();
  468. test_uts51_emoji_keycap_sequence();
  469. assert(espeak_Terminate() == EE_OK);
  470. return EXIT_SUCCESS;
  471. }
  472. // References:
  473. // [UTS-51] Unicode Emoji (http://www.unicode.org/reports/tr51/tr51-12.html) 5.0-12. 2017-05-18