From 9558ebad624ed7c03eb7ddee12445482d1749a19 Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Mon, 15 Jul 2024 17:35:28 +0200 Subject: [PATCH] Add test for stpcpy(). --- test/val/stpcpy.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/val/stpcpy.c diff --git a/test/val/stpcpy.c b/test/val/stpcpy.c new file mode 100644 index 000000000..8bdbfb926 --- /dev/null +++ b/test/val/stpcpy.c @@ -0,0 +1,44 @@ +// 2024-07-15 Sven Michael Klose + +#include +#include +#include +#include + +#define STR_SHORT "Hello, World!" +#define STR_LONG "This is a longer test string for stpcpy." + +int +main () +{ + char dest[50]; + const char *src_empty; + const char *src_short; + const char *src_long; + char *end; + + src_empty = ""; + end = stpcpy (dest, src_empty); + assert(!strcmp (dest, src_empty)); + assert(!*end); + assert(end == dest); + printf ("Test 1 passed.\n"); + + src_short = STR_SHORT; + end = stpcpy (dest, src_short); + assert(!strcmp (dest, src_short)); + assert(!*end); + assert(end == &dest[sizeof (STR_SHORT) - 1]); + printf ("Test 2 passed.\n"); + + src_long = STR_LONG; + end = stpcpy (dest, src_long); + assert(!strcmp (dest, src_long)); + assert(!*end); + assert(end == &dest[sizeof (STR_LONG) - 1]); + printf ("Test 3 passed.\n"); + + printf ("All tests passed.\n"); + return EXIT_SUCCESS; +} +