]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: tests for dns_resource_key_new_append_suffix()
authorJames Coglan <james@neighbourhood.ie>
Wed, 29 May 2024 09:19:46 +0000 (10:19 +0100)
committerLuca Boccassi <bluca@debian.org>
Tue, 23 Jul 2024 11:44:35 +0000 (12:44 +0100)
src/resolve/test-dns-rr.c

index 0b99b88a6fa10138ef72f0fa18bf8e4192fb3226..4f476d20b33cad64608aefff6463422f05d734dc 100644 (file)
@@ -127,4 +127,37 @@ TEST(dns_resource_key_new_redirect_dname_no_match) {
         ASSERT_STREQ(dns_resource_key_name(redirected), "www.examples.com");
 }
 
+/* ================================================================
+ * dns_resource_key_new_append_suffix()
+ * ================================================================ */
+
+TEST(dns_resource_key_new_append_suffix_root) {
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *source = NULL, *target = NULL;
+
+        source = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(source);
+
+        ASSERT_OK(dns_resource_key_new_append_suffix(&target, source, (char *)""));
+        ASSERT_NOT_NULL(target);
+        ASSERT_TRUE(target == source);
+
+        ASSERT_OK(dns_resource_key_new_append_suffix(&target, source, (char *)"."));
+        ASSERT_NOT_NULL(target);
+        ASSERT_TRUE(target == source);
+
+        dns_resource_key_unref(source);
+}
+
+TEST(dns_resource_key_new_append_suffix_not_root) {
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *source = NULL, *target = NULL;
+
+        source = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example");
+        ASSERT_NOT_NULL(source);
+
+        ASSERT_OK(dns_resource_key_new_append_suffix(&target, source, (char *)"com"));
+        ASSERT_NOT_NULL(target);
+        ASSERT_FALSE(target == source);
+        ASSERT_STREQ(dns_resource_key_name(target), "www.example.com");
+}
+
 DEFINE_TEST_MAIN(LOG_DEBUG);