diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-08-18 00:05:41 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-08-21 12:41:07 +0200 |
commit | 9ca45586e67c6d061d0db7bdf5b05d30e37e368d (patch) | |
tree | 0a9c3677c7a49602f715d93dc678228c8b077680 /src/test/test-dns-domain.c | |
parent | 46a5e0e7421bcc47755ae15d430c15a16dc9e03e (diff) |
dns-domain: add call for concatenating two domain names
This is specifically useful for appending the mDNS ".local" suffix to a
single-label hostname in the most correct way. (used in later commit)
Diffstat (limited to 'src/test/test-dns-domain.c')
-rw-r--r-- | src/test/test-dns-domain.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/test-dns-domain.c b/src/test/test-dns-domain.c index 0042722c99..2193eb6f7d 100644 --- a/src/test/test-dns-domain.c +++ b/src/test/test-dns-domain.c @@ -251,6 +251,39 @@ static void test_dns_name_reverse(void) { test_dns_name_reverse_one("::1", "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa"); } +static void test_dns_name_concat_one(const char *a, const char *b, int r, const char *result) { + _cleanup_free_ char *p = NULL; + + assert_se(dns_name_concat(a, b, &p) == r); + assert_se(streq_ptr(p, result)); +} + +static void test_dns_name_concat(void) { + test_dns_name_concat_one("foo", "bar", 0, "foo.bar"); + test_dns_name_concat_one("foo.foo", "bar.bar", 0, "foo.foo.bar.bar"); + test_dns_name_concat_one("foo", NULL, 0, "foo"); + test_dns_name_concat_one("foo.", "bar.", 0, "foo.bar"); +} + +static void test_dns_name_is_valid_one(const char *s, int ret) { + assert_se(dns_name_is_valid(s) == ret); +} + +static void test_dns_name_is_valid(void) { + test_dns_name_is_valid_one("foo", 1); + test_dns_name_is_valid_one("foo.", 1); + test_dns_name_is_valid_one("Foo", 1); + test_dns_name_is_valid_one("foo.bar", 1); + test_dns_name_is_valid_one("foo.bar.baz", 1); + test_dns_name_is_valid_one("", 1); + test_dns_name_is_valid_one("foo..bar", 0); + test_dns_name_is_valid_one(".foo.bar", 0); + test_dns_name_is_valid_one("foo.bar.", 1); + test_dns_name_is_valid_one("\\zbar", 0); + test_dns_name_is_valid_one("รค", 1); + test_dns_name_is_valid_one("\n", 0); +} + int main(int argc, char *argv[]) { test_dns_label_unescape(); @@ -263,6 +296,8 @@ int main(int argc, char *argv[]) { test_dns_name_root(); test_dns_name_single_label(); test_dns_name_reverse(); + test_dns_name_concat(); + test_dns_name_is_valid(); return 0; } |