11a1589223
Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
54 lines
1.7 KiB
C
54 lines
1.7 KiB
C
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
/***
|
|
This file is part of systemd.
|
|
|
|
Copyright 2017 Lennart Poettering
|
|
***/
|
|
|
|
#include "alloc-util.h"
|
|
#include "log.h"
|
|
#include "specifier.h"
|
|
#include "string-util.h"
|
|
#include "strv.h"
|
|
|
|
static void test_specifier_escape_one(const char *a, const char *b) {
|
|
_cleanup_free_ char *x = NULL;
|
|
|
|
x = specifier_escape(a);
|
|
assert_se(streq_ptr(x, b));
|
|
}
|
|
|
|
static void test_specifier_escape(void) {
|
|
test_specifier_escape_one(NULL, NULL);
|
|
test_specifier_escape_one("", "");
|
|
test_specifier_escape_one("%", "%%");
|
|
test_specifier_escape_one("foo bar", "foo bar");
|
|
test_specifier_escape_one("foo%bar", "foo%%bar");
|
|
test_specifier_escape_one("%%%%%", "%%%%%%%%%%");
|
|
}
|
|
|
|
static void test_specifier_escape_strv_one(char **a, char **b) {
|
|
_cleanup_strv_free_ char **x = NULL;
|
|
|
|
assert_se(specifier_escape_strv(a, &x) >= 0);
|
|
assert_se(strv_equal(x, b));
|
|
}
|
|
|
|
static void test_specifier_escape_strv(void) {
|
|
test_specifier_escape_strv_one(NULL, NULL);
|
|
test_specifier_escape_strv_one(STRV_MAKE(NULL), STRV_MAKE(NULL));
|
|
test_specifier_escape_strv_one(STRV_MAKE(""), STRV_MAKE(""));
|
|
test_specifier_escape_strv_one(STRV_MAKE("foo"), STRV_MAKE("foo"));
|
|
test_specifier_escape_strv_one(STRV_MAKE("%"), STRV_MAKE("%%"));
|
|
test_specifier_escape_strv_one(STRV_MAKE("foo", "%", "foo%", "%foo", "foo%foo", "quux", "%%%"), STRV_MAKE("foo", "%%", "foo%%", "%%foo", "foo%%foo", "quux", "%%%%%%"));
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
log_set_max_level(LOG_DEBUG);
|
|
|
|
test_specifier_escape();
|
|
test_specifier_escape_strv();
|
|
|
|
return 0;
|
|
}
|