From 72e0fb3fc858301de7b200e1c08da6904ab44bc0 Mon Sep 17 00:00:00 2001 From: pengyi Date: Thu, 8 Dec 2022 04:59:25 +0800 Subject: Add more tests for t-printf and t-strerror. * tests/t-printf.c (check_fwrite): New. (main): Add check_fwrite. * tests/t-strerror.c (main): Add three more cases to LIST. -- The string in check_fwrite is from the Gateless Gate, for people who want to discuss "Niente". --- gniibe Co-authored-by: NIIBE Yutaka Signed-off-by: "pengyi" --- tests/t-printf.c | 25 +++++++++++++++++++++++++ tests/t-strerror.c | 5 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/t-printf.c b/tests/t-printf.c index c261838..c1ad0b0 100644 --- a/tests/t-printf.c +++ b/tests/t-printf.c @@ -489,6 +489,30 @@ check_fprintf_sf (void) gpgrt_fclose (stream); } +static void +check_fwrite (void) +{ + gpgrt_stream_t stream; + const char *expect; + char *result; + + stream = gpgrt_fopenmem (0, "w+b"); + if (!stream) + die ("fopenmem failed at line %d\n", __LINE__); + + gpgrt_fwrite ("Has the dog Buddha-nature or not?", 1, 33, stream); + expect = "Has the dog Buddha-nature or not?"; + result = stream_to_string (stream); + if (strcmp (result, expect)) + { + show ("expect: '%s'\n", expect); + show ("result: '%s'\n", result); + fail ("fprintf_sf failed at %d\n", __LINE__); + } + free (result); + gpgrt_fclose (stream); +} + int main (int argc, char **argv) @@ -535,6 +559,7 @@ main (int argc, char **argv) run_tests (); check_snprintf (); check_fprintf_sf (); + check_fwrite (); #ifdef __GLIBC__ return !!errorcount; diff --git a/tests/t-strerror.c b/tests/t-strerror.c index 9289066..5c38fca 100644 --- a/tests/t-strerror.c +++ b/tests/t-strerror.c @@ -49,7 +49,10 @@ main (int argc, char *argv[]) gpg_err_source_t src; gpg_err_code_t code; } list[] = { { 0, 0 }, { 1, 201 }, { 2, 2 }, { 3, 102 }, - { 4, 100 }, { 5, 99 }, { 6, 110 }, { 7, 7 }, { 8, 888 } }; + { 4, 100 }, { 5, 99 }, { 6, 110 }, { 7, 7 }, { 8, 888 }, + { 1, GPG_ERR_SYSTEM_ERROR | 1 }, + { 1, GPG_ERR_SYSTEM_ERROR | 35 }, + { 1, GPG_ERR_SYSTEM_ERROR | 81 } }; int i = 0; while (i < sizeof (list) / sizeof (list[0])) -- cgit v1.2.1