| 1 |
/* |
| 2 |
* Test systemd helpers |
| 3 |
*/ |
| 4 |
|
| 5 |
#undef NDEBUG |
| 6 |
#include <c-stdaux.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include "util/systemd.h" |
| 9 |
|
| 10 |
static void test_systemd_escape_unit(void) { |
| 11 |
static const char * const from[] = { |
| 12 |
"foobar", |
| 13 |
"-foobar", |
| 14 |
"/foo/bar/", |
| 15 |
"\\foobar", |
| 16 |
".foo.bar", |
| 17 |
}; |
| 18 |
static const char * const to[] = { |
| 19 |
"foobar", |
| 20 |
"\\x2dfoobar", |
| 21 |
"-foo-bar-", |
| 22 |
"\\x5cfoobar", |
| 23 |
"\\x2efoo.bar", |
| 24 |
}; |
| 25 |
|
| 26 |
for (size_t i = 0; i < C_ARRAY_SIZE(from); ++i) { |
| 27 |
_c_cleanup_(c_freep) char *e = NULL; |
| 28 |
int r; |
| 29 |
|
| 30 |
r = systemd_escape_unit(&e, from[i]); |
| 31 |
c_assert(!r); |
| 32 |
c_assert(!strcmp(e, to[i])); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
int main(int argc, char **argv) { |
| 37 |
test_systemd_escape_unit(); |
| 38 |
return 0; |
| 39 |
} |