]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-replace-var.c
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / test / test-replace-var.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright 2012 Lennart Poettering
4 ***/
5
6 #include <string.h>
7
8 #include "macro.h"
9 #include "replace-var.h"
10 #include "string-util.h"
11 #include "util.h"
12
13 static char *lookup(const char *variable, void *userdata) {
14 return strjoin("<<<", variable, ">>>");
15 }
16
17 int main(int argc, char *argv[]) {
18 char *r;
19
20 assert_se(r = replace_var("@@@foobar@xyz@HALLO@foobar@test@@testtest@TEST@...@@@", lookup, NULL));
21 puts(r);
22 assert_se(streq(r, "@@@foobar@xyz<<<HALLO>>>foobar@test@@testtest<<<TEST>>>...@@@"));
23 free(r);
24
25 assert_se(r = strreplace("XYZFFFFXYZFFFFXYZ", "XYZ", "ABC"));
26 puts(r);
27 assert_se(streq(r, "ABCFFFFABCFFFFABC"));
28 free(r);
29
30 return 0;
31 }