[PATCH] add more tests for t-printf and t-strerror

pengyi pengyi37 at huawei.com
Wed Dec 7 21:59:25 CET 2022


Hi. I found in libgpg-error, the tests/t-strerror.c didn’t include some system error case; the tests/t-printf.c didn’t test the functionality of gpgrt_fwrite() which is also a common API. So I wonder if it’s possible to add more testcases in these two tests.

Signed-off-by:"pengyi" <pengyi37 at huawei.com>
---
 tests/t-printf.c   | 25 +++++++++++++++++++++++++
 tests/t-strerror.c |  3 ++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/tests/t-printf.c b/tests/t-printf.c
index c261838..fa2501c 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("[==>Niente<==]", 1, 14, stream);
+  expect = "[==>Niente<==]";
+  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..5b749d1 100644
--- a/tests/t-strerror.c
+++ b/tests/t-strerror.c
@@ -49,7 +49,8 @@ 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, GPG_ERR_SYSTEM_ERROR | 2 }, { 1, GPG_ERR_SYSTEM_ERROR | 4 } };
       int i = 0;
 
       while (i < sizeof (list) / sizeof (list[0]))
-- 
2.27.0




More information about the Gnupg-devel mailing list