1 // SPDX-License-Identifier: GPL-2.0
3 #include "util/debug.h"
5 #include <linux/compiler.h>
9 static int test_strreplace(char needle
, const char *haystack
,
10 const char *replace
, const char *expected
)
12 char *new = strreplace_chars(needle
, haystack
, replace
);
13 int ret
= strcmp(new, expected
);
19 static int test__util(struct test_suite
*t __maybe_unused
, int subtest __maybe_unused
)
21 TEST_ASSERT_VAL("empty string", test_strreplace(' ', "", "123", ""));
22 TEST_ASSERT_VAL("no match", test_strreplace('5', "123", "4", "123"));
23 TEST_ASSERT_VAL("replace 1", test_strreplace('3', "123", "4", "124"));
24 TEST_ASSERT_VAL("replace 2", test_strreplace('a', "abcabc", "ef", "efbcefbc"));
25 TEST_ASSERT_VAL("replace long", test_strreplace('a', "abcabc", "longlong",
26 "longlongbclonglongbc"));
31 DEFINE_SUITE("util", util
);