]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-strxcpyx.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "string-util.h"
9 static void test_strpcpy(void) {
14 space_left
= sizeof(target
);
15 space_left
= strpcpy(&s
, space_left
, "12345");
16 space_left
= strpcpy(&s
, space_left
, "hey hey hey");
17 space_left
= strpcpy(&s
, space_left
, "waldo");
18 space_left
= strpcpy(&s
, space_left
, "ba");
19 space_left
= strpcpy(&s
, space_left
, "r");
20 space_left
= strpcpy(&s
, space_left
, "foo");
22 assert_se(streq(target
, "12345hey hey heywaldobar"));
23 assert_se(space_left
== 0);
26 static void test_strpcpyf(void) {
31 space_left
= sizeof(target
);
32 space_left
= strpcpyf(&s
, space_left
, "space left: %zu. ", space_left
);
33 space_left
= strpcpyf(&s
, space_left
, "foo%s", "bar");
35 assert_se(streq(target
, "space left: 25. foobar"));
36 assert_se(space_left
== 3);
40 space_left
= strpcpyf(&s
, 12, "00 left: %i. ", 999);
41 assert_se(streq(target
, "00 left: 99"));
42 assert_se(space_left
== 0);
43 assert_se(target
[12] == '2');
46 static void test_strpcpyl(void) {
51 space_left
= sizeof(target
);
52 space_left
= strpcpyl(&s
, space_left
, "waldo", " test", " waldo. ", NULL
);
53 space_left
= strpcpyl(&s
, space_left
, "Banana", NULL
);
55 assert_se(streq(target
, "waldo test waldo. Banana"));
56 assert_se(space_left
== 1);
59 static void test_strscpy(void) {
63 space_left
= sizeof(target
);
64 space_left
= strscpy(target
, space_left
, "12345");
66 assert_se(streq(target
, "12345"));
67 assert_se(space_left
== 20);
70 static void test_strscpyl(void) {
74 space_left
= sizeof(target
);
75 space_left
= strscpyl(target
, space_left
, "12345", "waldo", "waldo", NULL
);
77 assert_se(streq(target
, "12345waldowaldo"));
78 assert_se(space_left
== 10);
81 int main(int argc
, char *argv
[]) {