eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readclause.c 18KB

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