aboutsummaryrefslogtreecommitdiffstats
path: root/strnccpy.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-06-12 20:13:23 +0200
committerMattias Andrée <maandree@kth.se>2022-06-12 20:13:23 +0200
commit3d6482b0949159c33d6ac2972a69868bdda766f2 (patch)
tree722cf9ab069d75af63664eeae0c35c63aa73c51c /strnccpy.c
parentFix warnings (diff)
downloadlibsimple-3d6482b0949159c33d6ac2972a69868bdda766f2.tar.gz
libsimple-3d6482b0949159c33d6ac2972a69868bdda766f2.tar.bz2
libsimple-3d6482b0949159c33d6ac2972a69868bdda766f2.tar.xz
Move some test code to newline created .c files
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'strnccpy.c')
-rw-r--r--strnccpy.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/strnccpy.c b/strnccpy.c
index 3d91c08..176c8a0 100644
--- a/strnccpy.c
+++ b/strnccpy.c
@@ -12,6 +12,76 @@ extern inline char *libsimple_strnccpy(char *restrict, const char *restrict, int
int
main(void)
{
+ char buf[1024];
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", '\0', 1024) == &buf[6]);
+ assert(!strcmp(buf, "hello"));
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'o', 1024) == &buf[5]);
+ assert(!strcmp(buf, "hello"));
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'l', 1024) == &buf[3]);
+ assert(!strcmp(buf, "hel"));
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'x', 1024) == NULL);
+ assert(!strcmp(buf, "hello"));
+
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", '\0', 6) == &buf[6]);
+ assert(!strcmp(buf, "hello"));
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'o', 6) == &buf[5]);
+ assert(!strcmp(buf, "hello"));
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'l', 6) == &buf[3]);
+ assert(!strcmp(buf, "hel"));
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'x', 6) == NULL);
+ assert(!strcmp(buf, "hello"));
+
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", '\0', 5) == NULL);
+ assert(!strncmp(buf, "hellox", 6));
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'o', 5) == &buf[5]);
+ assert(!strncmp(buf, "hellox", 6));
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'l', 5) == &buf[3]);
+ assert(!strcmp(buf, "hel"));
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'x', 5) == NULL);
+ assert(!strncmp(buf, "hellox", 6));
+
+
+ memset(buf, 'x', sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ assert(libsimple_strnccpy(buf, "hello", 'o', 3) == NULL);
+ assert(!strncmp(buf, "helx", 4));
+
return 0;
}