lkml.org 
[lkml]   [2023]   [Apr]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 3/9] string: Add Kunit tests for strcat() family
> +static void strncat_test(struct kunit *test)
> +{
> + char dest[8];
> +
> + /* Destination is terminated. */
> + memset(dest, 0, sizeof(dest));
> + KUNIT_EXPECT_EQ(test, strlen(dest), 0);
> + /* Empty copy of size 0 does nothing. */
> + KUNIT_EXPECT_TRUE(test, strncat(dest, "", 0) == dest);
> + KUNIT_EXPECT_STREQ(test, dest, "");
> + /* Empty copy of size 1 does nothing too. */
> + KUNIT_EXPECT_TRUE(test, strncat(dest, "", 1) == dest);
> + KUNIT_EXPECT_STREQ(test, dest, "");
> + /* Copy of max 0 characters should do nothing. */
> + KUNIT_EXPECT_TRUE(test, strncat(dest, "asdf", 0) == dest);
> + KUNIT_EXPECT_STREQ(test, dest, "");
> +
> + /* 4 characters copied in, even if max is 8. */
> + KUNIT_EXPECT_TRUE(test, strncat(dest, "four\000123", 8) == dest);
> + KUNIT_EXPECT_STREQ(test, dest, "four");
> + KUNIT_EXPECT_EQ(test, dest[5], '\0');

Maybe also add a test case for strncat(dest, "four", 4) that checks
that the fourth byte of dest is not 0?

\
 
 \ /
  Last update: 2023-04-06 11:12    [W:0.171 / U:0.804 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site