These patches add some more test cases.
2025-05-17 Bruno Haible <br...@clisp.org> cosh: Add more tests. * tests/test-cosh.c: Include <stdio.h>, <string.h>. (main): Add another test case. 2025-05-17 Bruno Haible <br...@clisp.org> sinh: Add more tests. * tests/test-sinh.c: Include <stdio.h>, <string.h>. (main): Add another test case. 2025-05-17 Bruno Haible <br...@clisp.org> crypto/sha512-buffer: Add some tests. * tests/test-sha384-buffer.c: New file, based on tests/test-sha1-buffer.c. * tests/test-sha512-buffer.c: New file, based on tests/test-sha1-buffer.c. * modules/crypto/sha512-buffer-tests (Files): Add them. (Makefile.am): Compile and test test-sha384-buffer, test-sha512-buffer. 2025-05-17 Bruno Haible <br...@clisp.org> crypto/sha256-buffer: Add some tests. * tests/test-sha224-buffer.c: New file, based on tests/test-sha1-buffer.c. * tests/test-sha256-buffer.c: New file, based on tests/test-sha1-buffer.c. * modules/crypto/sha256-buffer-tests (Files): Add them. (Makefile.am): Compile and test test-sha224-buffer, test-sha256-buffer. 2025-05-17 Bruno Haible <br...@clisp.org> next-prime tests: Add more tests. * tests/test-next-prime.c (main): Add another test case.
>From a27e7618c7c99b0d26738dd7470423a6fc6bef15 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 17 May 2025 11:09:58 +0200 Subject: [PATCH 1/5] next-prime tests: Add more tests. * tests/test-next-prime.c (main): Add another test case. --- ChangeLog | 5 +++++ tests/test-next-prime.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/ChangeLog b/ChangeLog index 39681ca16a..a1937a6772 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2025-05-17 Bruno Haible <br...@clisp.org> + + next-prime tests: Add more tests. + * tests/test-next-prime.c (main): Add another test case. + 2025-05-17 Bruno Haible <br...@clisp.org> clean-temp: Fix typo in comment. diff --git a/tests/test-next-prime.c b/tests/test-next-prime.c index 4a6a25e054..5bec1e0eeb 100644 --- a/tests/test-next-prime.c +++ b/tests/test-next-prime.c @@ -34,6 +34,8 @@ main () ASSERT (next_prime (12) == 13); ASSERT (next_prime (640) == 641); + ASSERT (next_prime (8647) == 8647); + ASSERT (next_prime (9551) == 9551); ASSERT (next_prime (9552) == 9587); -- 2.43.0
>From 6dec260c7d677992b441a205441a3cd2d739a232 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 17 May 2025 14:16:01 +0200 Subject: [PATCH 2/5] crypto/sha256-buffer: Add some tests. * tests/test-sha224-buffer.c: New file, based on tests/test-sha1-buffer.c. * tests/test-sha256-buffer.c: New file, based on tests/test-sha1-buffer.c. * modules/crypto/sha256-buffer-tests (Files): Add them. (Makefile.am): Compile and test test-sha224-buffer, test-sha256-buffer. --- ChangeLog | 10 ++++++ modules/crypto/sha256-buffer-tests | 6 ++++ tests/test-sha224-buffer.c | 51 ++++++++++++++++++++++++++++++ tests/test-sha256-buffer.c | 51 ++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 tests/test-sha224-buffer.c create mode 100644 tests/test-sha256-buffer.c diff --git a/ChangeLog b/ChangeLog index a1937a6772..21ca1b4a63 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2025-05-17 Bruno Haible <br...@clisp.org> + + crypto/sha256-buffer: Add some tests. + * tests/test-sha224-buffer.c: New file, based on + tests/test-sha1-buffer.c. + * tests/test-sha256-buffer.c: New file, based on + tests/test-sha1-buffer.c. + * modules/crypto/sha256-buffer-tests (Files): Add them. + (Makefile.am): Compile and test test-sha224-buffer, test-sha256-buffer. + 2025-05-17 Bruno Haible <br...@clisp.org> next-prime tests: Add more tests. diff --git a/modules/crypto/sha256-buffer-tests b/modules/crypto/sha256-buffer-tests index cf93a8f5fe..1fae2f412e 100644 --- a/modules/crypto/sha256-buffer-tests +++ b/modules/crypto/sha256-buffer-tests @@ -1,4 +1,6 @@ Files: +tests/test-sha224-buffer.c +tests/test-sha256-buffer.c tests/bench-sha224.c tests/bench-sha256.c tests/bench-digest.h @@ -12,7 +14,11 @@ gettimeofday configure.ac: Makefile.am: +TESTS += test-sha224-buffer test-sha256-buffer +check_PROGRAMS += test-sha224-buffer test-sha256-buffer noinst_PROGRAMS += bench-sha224 bench-sha256 +test_sha224_buffer_LDADD = $(LDADD) @LIB_CRYPTO@ +test_sha256_buffer_LDADD = $(LDADD) @LIB_CRYPTO@ bench_sha224_CPPFLAGS = $(AM_CPPFLAGS) -DNDEBUG bench_sha224_LDADD = $(LDADD) @LIB_CRYPTO@ bench_sha256_CPPFLAGS = $(AM_CPPFLAGS) -DNDEBUG diff --git a/tests/test-sha224-buffer.c b/tests/test-sha224-buffer.c new file mode 100644 index 0000000000..97e888e80c --- /dev/null +++ b/tests/test-sha224-buffer.c @@ -0,0 +1,51 @@ +/* Test of sha224_buffer() function. + Copyright (C) 2005-2025 Free Software Foundation, Inc. + + 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 <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "sha256.h" + +#include <stdio.h> +#include <string.h> + +int +main (void) +{ + const char *in1 = + "Prejmer has 8647 inhabitants.\n" + "<https://en.wikipedia.org/wiki/Prejmer>\n"; + const char *out1 = + "\x8a\x7d\x25\x22\x11\x13\x61\x35\x7a\x61\x6e\x4a\xf5\xbd\x0a\x17" + "\x5b\xdf\x7e\x27\xa1\xb7\x00\xf4\x62\x89\x41\x84"; + char buf[SHA224_DIGEST_SIZE]; + + if (memcmp (sha224_buffer (in1, strlen (in1), buf), + out1, SHA224_DIGEST_SIZE) != 0) + { + size_t i; + printf ("expected:\n"); + for (i = 0; i < SHA224_DIGEST_SIZE; i++) + printf ("%02x ", out1[i] & 0xFFu); + printf ("\ncomputed:\n"); + for (i = 0; i < SHA224_DIGEST_SIZE; i++) + printf ("%02x ", buf[i] & 0xFFu); + printf ("\n"); + return 1; + } + + return 0; +} diff --git a/tests/test-sha256-buffer.c b/tests/test-sha256-buffer.c new file mode 100644 index 0000000000..08fb841c6a --- /dev/null +++ b/tests/test-sha256-buffer.c @@ -0,0 +1,51 @@ +/* Test of sha256_buffer() function. + Copyright (C) 2005-2025 Free Software Foundation, Inc. + + 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 <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "sha256.h" + +#include <stdio.h> +#include <string.h> + +int +main (void) +{ + const char *in1 = + "Prejmer has 8647 inhabitants.\n" + "<https://en.wikipedia.org/wiki/Prejmer>\n"; + const char *out1 = + "\xd1\x27\xec\x93\xdd\x7f\x60\xaa\x72\x51\x51\x40\xd0\xe2\x5e\xc7" + "\x89\xaf\xfa\x91\x9c\x8a\x85\xb7\x19\x8d\x8b\x15\xaf\xa3\x4b\x2c"; + char buf[SHA256_DIGEST_SIZE]; + + if (memcmp (sha256_buffer (in1, strlen (in1), buf), + out1, SHA256_DIGEST_SIZE) != 0) + { + size_t i; + printf ("expected:\n"); + for (i = 0; i < SHA256_DIGEST_SIZE; i++) + printf ("%02x ", out1[i] & 0xFFu); + printf ("\ncomputed:\n"); + for (i = 0; i < SHA256_DIGEST_SIZE; i++) + printf ("%02x ", buf[i] & 0xFFu); + printf ("\n"); + return 1; + } + + return 0; +} -- 2.43.0
>From 9e1233a1aad8d74fd76869662f8b1b06054b1e1e Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 17 May 2025 14:17:24 +0200 Subject: [PATCH 3/5] crypto/sha512-buffer: Add some tests. * tests/test-sha384-buffer.c: New file, based on tests/test-sha1-buffer.c. * tests/test-sha512-buffer.c: New file, based on tests/test-sha1-buffer.c. * modules/crypto/sha512-buffer-tests (Files): Add them. (Makefile.am): Compile and test test-sha384-buffer, test-sha512-buffer. --- ChangeLog | 10 ++++++ modules/crypto/sha512-buffer-tests | 6 ++++ tests/test-sha384-buffer.c | 52 +++++++++++++++++++++++++++++ tests/test-sha512-buffer.c | 53 ++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 tests/test-sha384-buffer.c create mode 100644 tests/test-sha512-buffer.c diff --git a/ChangeLog b/ChangeLog index 21ca1b4a63..5c1e3f2b6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2025-05-17 Bruno Haible <br...@clisp.org> + + crypto/sha512-buffer: Add some tests. + * tests/test-sha384-buffer.c: New file, based on + tests/test-sha1-buffer.c. + * tests/test-sha512-buffer.c: New file, based on + tests/test-sha1-buffer.c. + * modules/crypto/sha512-buffer-tests (Files): Add them. + (Makefile.am): Compile and test test-sha384-buffer, test-sha512-buffer. + 2025-05-17 Bruno Haible <br...@clisp.org> crypto/sha256-buffer: Add some tests. diff --git a/modules/crypto/sha512-buffer-tests b/modules/crypto/sha512-buffer-tests index 0b68d5064d..ceabf0382d 100644 --- a/modules/crypto/sha512-buffer-tests +++ b/modules/crypto/sha512-buffer-tests @@ -1,4 +1,6 @@ Files: +tests/test-sha384-buffer.c +tests/test-sha512-buffer.c tests/bench-sha384.c tests/bench-sha512.c tests/bench-digest.h @@ -12,7 +14,11 @@ gettimeofday configure.ac: Makefile.am: +TESTS += test-sha384-buffer test-sha512-buffer +check_PROGRAMS += test-sha384-buffer test-sha512-buffer noinst_PROGRAMS += bench-sha384 bench-sha512 +test_sha384_buffer_LDADD = $(LDADD) @LIB_CRYPTO@ +test_sha512_buffer_LDADD = $(LDADD) @LIB_CRYPTO@ bench_sha384_CPPFLAGS = $(AM_CPPFLAGS) -DNDEBUG bench_sha384_LDADD = $(LDADD) @LIB_CRYPTO@ bench_sha512_CPPFLAGS = $(AM_CPPFLAGS) -DNDEBUG diff --git a/tests/test-sha384-buffer.c b/tests/test-sha384-buffer.c new file mode 100644 index 0000000000..91de0739f0 --- /dev/null +++ b/tests/test-sha384-buffer.c @@ -0,0 +1,52 @@ +/* Test of sha384_buffer() function. + Copyright (C) 2005-2025 Free Software Foundation, Inc. + + 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 <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "sha512.h" + +#include <stdio.h> +#include <string.h> + +int +main (void) +{ + const char *in1 = + "Deldoul has 8647 inhabitants.\n" + "<https://en.wikipedia.org/wiki/Deldoul,_Timimoun>\n"; + const char *out1 = + "\x57\x93\xc9\xcf\x15\x18\x89\x99\x3d\xd1\x42\x89\x1e\x0a\xec\xec" + "\x7f\xb0\x4f\x82\x0e\x3a\x4f\xe0\x69\x8a\x5d\x36\x40\x07\x63\xd3" + "\x74\x8d\x80\x99\xfb\x05\xb5\x22\xa3\x8f\x29\x1c\xea\xdd\x7a\x82"; + char buf[SHA384_DIGEST_SIZE]; + + if (memcmp (sha384_buffer (in1, strlen (in1), buf), + out1, SHA384_DIGEST_SIZE) != 0) + { + size_t i; + printf ("expected:\n"); + for (i = 0; i < SHA384_DIGEST_SIZE; i++) + printf ("%02x ", out1[i] & 0xFFu); + printf ("\ncomputed:\n"); + for (i = 0; i < SHA384_DIGEST_SIZE; i++) + printf ("%02x ", buf[i] & 0xFFu); + printf ("\n"); + return 1; + } + + return 0; +} diff --git a/tests/test-sha512-buffer.c b/tests/test-sha512-buffer.c new file mode 100644 index 0000000000..a11efbecec --- /dev/null +++ b/tests/test-sha512-buffer.c @@ -0,0 +1,53 @@ +/* Test of sha512_buffer() function. + Copyright (C) 2005-2025 Free Software Foundation, Inc. + + 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 <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "sha512.h" + +#include <stdio.h> +#include <string.h> + +int +main (void) +{ + const char *in1 = + "Deldoul has 8647 inhabitants.\n" + "<https://en.wikipedia.org/wiki/Deldoul,_Timimoun>\n"; + const char *out1 = + "\xe5\x31\xc6\x89\x31\x84\xe7\xda\xa2\x26\x4c\xfa\xb1\x40\xb7\x3d" + "\x49\x5c\xce\xfb\x53\xbf\x5a\xe3\x1c\x2b\xad\x5c\x3e\x0b\x82\x9a" + "\xa5\x3c\x25\xb1\x39\x52\xa7\xca\x73\xe5\xf2\xb8\xc1\xef\xa7\x45" + "\xac\x8a\xf9\x83\x9c\x35\x92\x94\x2d\xb7\xb4\xb4\x08\x2e\x7f\xe2"; + char buf[SHA512_DIGEST_SIZE]; + + if (memcmp (sha512_buffer (in1, strlen (in1), buf), + out1, SHA512_DIGEST_SIZE) != 0) + { + size_t i; + printf ("expected:\n"); + for (i = 0; i < SHA512_DIGEST_SIZE; i++) + printf ("%02x ", out1[i] & 0xFFu); + printf ("\ncomputed:\n"); + for (i = 0; i < SHA512_DIGEST_SIZE; i++) + printf ("%02x ", buf[i] & 0xFFu); + printf ("\n"); + return 1; + } + + return 0; +} -- 2.43.0
>From bf5e55b81821413908f40503a2e834d97c76e52e Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 17 May 2025 14:18:45 +0200 Subject: [PATCH 4/5] sinh: Add more tests. * tests/test-sinh.c: Include <stdio.h>, <string.h>. (main): Add another test case. --- ChangeLog | 6 ++++++ tests/test-sinh.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5c1e3f2b6e..f3a175cfba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-05-17 Bruno Haible <br...@clisp.org> + + sinh: Add more tests. + * tests/test-sinh.c: Include <stdio.h>, <string.h>. + (main): Add another test case. + 2025-05-17 Bruno Haible <br...@clisp.org> crypto/sha512-buffer: Add some tests. diff --git a/tests/test-sinh.c b/tests/test-sinh.c index 4ee11bc433..24c91c7f69 100644 --- a/tests/test-sinh.c +++ b/tests/test-sinh.c @@ -23,6 +23,9 @@ #include "signature.h" SIGNATURE_CHECK (sinh, double, (double)); +#include <stdio.h> +#include <string.h> + #include "macros.h" volatile double x; @@ -36,5 +39,14 @@ main () y = sinh (x); ASSERT (y >= 0.6366535821 && y <= 0.6366535822); + /* Another particular value. */ + { + char buf[80]; + x = 5.152978147453169098; + y = sinh (x); + sprintf (buf, "%.2f", y); + ASSERT (strcmp (buf, "86.47") == 0); + } + return test_exit_status; } -- 2.43.0
>From 7a952c548983074602901ed4ad9d02054c4d9f93 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 17 May 2025 14:19:24 +0200 Subject: [PATCH 5/5] cosh: Add more tests. * tests/test-cosh.c: Include <stdio.h>, <string.h>. (main): Add another test case. --- ChangeLog | 6 ++++++ tests/test-cosh.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog b/ChangeLog index f3a175cfba..32a3bb93a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-05-17 Bruno Haible <br...@clisp.org> + + cosh: Add more tests. + * tests/test-cosh.c: Include <stdio.h>, <string.h>. + (main): Add another test case. + 2025-05-17 Bruno Haible <br...@clisp.org> sinh: Add more tests. diff --git a/tests/test-cosh.c b/tests/test-cosh.c index 9ff633e73c..cc94396758 100644 --- a/tests/test-cosh.c +++ b/tests/test-cosh.c @@ -23,6 +23,9 @@ #include "signature.h" SIGNATURE_CHECK (cosh, double, (double)); +#include <stdio.h> +#include <string.h> + #include "macros.h" volatile double x; @@ -36,5 +39,14 @@ main () y = cosh (x); ASSERT (y >= 1.185465218 && y <= 1.185465219); + /* Another particular value. */ + { + char buf[80]; + x = 5.152911276257581641; + y = cosh (x); + sprintf (buf, "%.2f", y); + ASSERT (strcmp (buf, "86.47") == 0); + } + return test_exit_status; } -- 2.43.0