summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-dns-domain.c35
-rw-r--r--src/test/test-util.c3
2 files changed, 38 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;
}
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 3c1bac4606..dff38ab6f6 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -1539,6 +1539,7 @@ static void test_extract_first_word(void) {
p = original = "\"";
assert_se(extract_first_word(&p, &t, NULL, 0) == 1);
assert_se(streq(t, "\""));
+ free(t);
assert_se(isempty(p));
p = original = "\"";
@@ -1548,6 +1549,7 @@ static void test_extract_first_word(void) {
p = original = "\'";
assert_se(extract_first_word(&p, &t, NULL, 0) == 1);
assert_se(streq(t, "\'"));
+ free(t);
assert_se(isempty(p));
p = original = "\'";
@@ -1557,6 +1559,7 @@ static void test_extract_first_word(void) {
p = original = "\'fooo";
assert_se(extract_first_word(&p, &t, NULL, 0) == 1);
assert_se(streq(t, "\'fooo"));
+ free(t);
assert_se(isempty(p));
p = original = "\'fooo";