123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578 |
- /*
- * Copyright (C) 2017 Reece H. Dunn
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write see:
- * <http://www.gnu.org/licenses/>.
- */
- #include "config.h"
- #include <assert.h>
- #include <stdlib.h>
- #include <string.h>
- #include <espeak-ng/espeak_ng.h>
- #include <espeak-ng/speak_lib.h>
- #include <espeak-ng/encoding.h>
- #include "speech.h"
- #include "phoneme.h"
- #include "voice.h"
- #include "synthesize.h"
- #include "translate.h"
- // region espeak_Initialize
- static void
- test_espeak_terminate_without_initialize()
- {
- printf("testing espeak_Terminate without espeak_Initialize\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_initialize()
- {
- printf("testing espeak_Initialize\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- // endregion
- // region espeak_Synth
- static void
- test_espeak_synth()
- {
- printf("testing espeak_Synth\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_synth_no_voices(const char *path)
- {
- printf("testing espeak_Synth in path with no voices\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, path, espeakINITIALIZE_DONT_EXIT) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_NOT_FOUND);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- // endregion
- // region espeak_ng_Synthesize
- static void
- test_espeak_ng_synthesize()
- {
- printf("testing espeak_ng_Synthesize\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_ng_Synthesize(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == ENS_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_ng_synthesize_no_voices(const char *path)
- {
- printf("testing espeak_ng_Synthesize in path with no voices\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, path, espeakINITIALIZE_DONT_EXIT) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_ng_Synthesize(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == ENS_VOICE_NOT_FOUND);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- // endregion
- // region espeak_SetVoiceByName
- static void
- test_espeak_set_voice_by_name_null_voice()
- {
- printf("testing espeak_SetVoiceByName(NULL)\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_SetVoiceByName("") == EE_NOT_FOUND);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_set_voice_by_name_blank_voice()
- {
- printf("testing espeak_SetVoiceByName(\"\")\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_SetVoiceByName("") == EE_NOT_FOUND);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_set_voice_by_name_valid_voice()
- {
- printf("testing espeak_SetVoiceByName(\"de\")\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_SetVoiceByName("de") == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "de") == 0);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "de") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "de") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_set_voice_by_name_invalid_voice()
- {
- printf("testing espeak_SetVoiceByName(\"zzz\")\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_SetVoiceByName("zzz") == EE_NOT_FOUND);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_set_voice_by_name_language_variant_intonation_parameter()
- {
- printf("testing espeak_SetVoiceByName(\"!v/Annie\") (language variant; intonation)\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_SetVoiceByName("!v/Annie") == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- // endregion
- // region espeak_SetVoiceByProperties
- static void
- test_espeak_set_voice_by_properties_empty()
- {
- printf("testing espeak_SetVoiceByProperties: (none)\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- espeak_VOICE properties;
- memset(&properties, 0, sizeof(properties));
- assert(espeak_SetVoiceByProperties(&properties) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_set_voice_by_properties_blank_language()
- {
- printf("testing espeak_SetVoiceByProperties: languages=\"\"\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- espeak_VOICE properties;
- memset(&properties, 0, sizeof(properties));
- properties.languages = "";
- assert(espeak_SetVoiceByProperties(&properties) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_set_voice_by_properties_with_valid_language()
- {
- printf("testing espeak_SetVoiceByProperties: languages=\"mk\" (valid)\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- espeak_VOICE properties;
- memset(&properties, 0, sizeof(properties));
- properties.languages = "mk";
- assert(espeak_SetVoiceByProperties(&properties) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "mk") == 0);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "mk") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "mk") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- static void
- test_espeak_set_voice_by_properties_with_invalid_language()
- {
- printf("testing espeak_SetVoiceByProperties: languages=\"zzz\" (invalid)\n");
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- assert(espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, 0, NULL, 0) == 22050);
- assert(event_list != NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- espeak_VOICE properties;
- memset(&properties, 0, sizeof(properties));
- properties.languages = "zzz";
- assert(espeak_SetVoiceByProperties(&properties) == EE_NOT_FOUND);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- const char *test = "One two three.";
- assert(espeak_Synth(test, strlen(test)+1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL) == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Synchronize() == EE_OK);
- assert(translator != NULL);
- assert(strcmp(translator->dictionary_name, "en") == 0);
- assert(p_decoder != NULL);
- assert(espeak_Terminate() == EE_OK);
- assert(event_list == NULL);
- assert(translator == NULL);
- assert(p_decoder == NULL);
- }
- // endregion
- int
- main(int argc, char **argv)
- {
- (void)argc; // unused parameter
- char *progdir = strdup(argv[0]);
- char *dir = strrchr(progdir, '/');
- if (dir != NULL) *dir = 0;
- test_espeak_terminate_without_initialize();
- test_espeak_initialize();
- test_espeak_synth();
- test_espeak_synth(); // Check that this does not crash when run a second time.
- test_espeak_synth_no_voices(progdir);
- test_espeak_synth();
- test_espeak_ng_synthesize();
- test_espeak_ng_synthesize(); // Check that this does not crash when run a second time.
- test_espeak_ng_synthesize_no_voices(progdir);
- test_espeak_ng_synthesize();
- test_espeak_set_voice_by_name_null_voice();
- test_espeak_set_voice_by_name_blank_voice();
- test_espeak_set_voice_by_name_valid_voice();
- test_espeak_set_voice_by_name_invalid_voice();
- test_espeak_set_voice_by_name_language_variant_intonation_parameter();
- test_espeak_set_voice_by_properties_empty();
- test_espeak_set_voice_by_properties_blank_language();
- test_espeak_set_voice_by_properties_with_valid_language();
- test_espeak_set_voice_by_properties_with_invalid_language();
- free(progdir);
- return EXIT_SUCCESS;
- }
|