diff --git a/Makefile.am b/Makefile.am index de35cb02..7cca850f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -255,6 +255,12 @@ tests_api_test_CFLAGS = -Isrc/libespeak-ng ${AM_CFLAGS} tests_api_test_LDADD = src/libespeak-ng-test.la tests_api_test_SOURCES = tests/api.c +check_PROGRAMS += tests/ieee80.test + +tests_ieee80_test_CFLAGS = -Isrc/libespeak-ng ${AM_CFLAGS} +tests_ieee80_test_LDADD = src/libespeak-ng-test.la +tests_ieee80_test_SOURCES = tests/ieee80.c + .test.check: @echo " TEST $<" @ESPEAK_DATA_PATH=$(CURDIR) $< && echo " PASSED $<" @@ -265,6 +271,7 @@ check: tests/encoding.check \ tests/ssml.check \ tests/ssml-fuzzer.check \ tests/api.check \ + tests/ieee80.check \ tests/dictionary.check \ tests/language-phonemes.check \ tests/language-replace.check \ diff --git a/tests/ieee80.c b/tests/ieee80.c new file mode 100644 index 00000000..92aef073 --- /dev/null +++ b/tests/ieee80.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2022 Ulrich Müller + * + * 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, see: . + * + * + * Alternatively, at your option, you can distribute this file under + * the terms of the 2-clause BSD license. + */ + +#include "config.h" +#include +#include +#include +#include "ieee80.h" + +int +main(int argc, char **argv) +{ + (void)argc; (void)argv; /* unused */ + + /* Define only constants that can be exactly represented both in + decimal and in binary, in order to avoid rounding errors */ + unsigned char in[][10] = { + { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 0 */ + { 0x3f,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 1 */ + { 0xbf,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* -1 */ + { 0x40,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 2 */ + { 0x3f,0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 0.5 */ + { 0x3f,0xf7,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* 0.005859375 */ + { 0x40,0x22,0x98,0x76,0x54,0x32,0x10,0x00,0x00,0x00 }, /* 40926266145 */ + { 0x7f,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* inf */ + { 0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, /* -inf */ + { 0x7f,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } /* nan */ + }; + + assert(ieee_extended_to_double(in[0]) == 0.); + assert(ieee_extended_to_double(in[1]) == 1.); + assert(ieee_extended_to_double(in[2]) == -1.); + assert(ieee_extended_to_double(in[3]) == 2.); + assert(ieee_extended_to_double(in[4]) == 0.5); + assert(ieee_extended_to_double(in[5]) == 0.005859375); + assert(ieee_extended_to_double(in[6]) == 40926266145.); +#ifdef INFINITY + assert(ieee_extended_to_double(in[7]) == INFINITY); + assert(ieee_extended_to_double(in[8]) == -INFINITY); +#endif +#ifdef NAN + assert(isnan(ieee_extended_to_double(in[9]))); +#endif + + return EXIT_SUCCESS; +}