/* Selftests for libiberty. */
-/* Verify that both strndup and xstrndup generate EXPECTED
- when called on SRC and N. */
+/* Verify that xstrndup generates EXPECTED when called on SRC and N. */
static void
-assert_strndup_eq (const char *expected, const char *src, size_t n)
+assert_xstrndup_eq (const char *expected, const char *src, size_t n)
{
- char *buf = strndup (src, n);
- if (buf)
- ASSERT_STREQ (expected, buf);
- free (buf);
-
- buf = xstrndup (src, n);
+ char *buf = xstrndup (src, n);
ASSERT_STREQ (expected, buf);
free (buf);
}
-/* Verify that strndup and xstrndup work as expected. */
+/* Verify that xstrndup works as expected. */
static void
-test_strndup ()
+test_xstrndup ()
{
- assert_strndup_eq ("", "test", 0);
- assert_strndup_eq ("t", "test", 1);
- assert_strndup_eq ("te", "test", 2);
- assert_strndup_eq ("tes", "test", 3);
- assert_strndup_eq ("test", "test", 4);
- assert_strndup_eq ("test", "test", 5);
+ assert_xstrndup_eq ("", "test", 0);
+ assert_xstrndup_eq ("t", "test", 1);
+ assert_xstrndup_eq ("te", "test", 2);
+ assert_xstrndup_eq ("tes", "test", 3);
+ assert_xstrndup_eq ("test", "test", 4);
+ assert_xstrndup_eq ("test", "test", 5);
/* Test on an string without zero termination. */
const char src[4] = {'t', 'e', 's', 't'};
- assert_strndup_eq ("", src, 0);
- assert_strndup_eq ("t", src, 1);
- assert_strndup_eq ("te", src, 2);
- assert_strndup_eq ("tes", src, 3);
- assert_strndup_eq ("test", src, 4);
+ assert_xstrndup_eq ("", src, 0);
+ assert_xstrndup_eq ("t", src, 1);
+ assert_xstrndup_eq ("te", src, 2);
+ assert_xstrndup_eq ("tes", src, 3);
+ assert_xstrndup_eq ("test", src, 4);
}
/* Run selftests for libiberty. */
static void
test_libiberty ()
{
- test_strndup ();
+ test_xstrndup ();
}
/* Selftests for the selftest system itself. */