]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: tests for dns_question_is_equal()
authorJames Coglan <james@neighbourhood.ie>
Fri, 31 May 2024 08:47:11 +0000 (09:47 +0100)
committerLuca Boccassi <bluca@debian.org>
Tue, 23 Jul 2024 12:09:46 +0000 (13:09 +0100)
src/resolve/test-dns-question.c

index 62156ac6e27f2cf225eb691aaa94954097990039..9f01a0694ef11742b1e944443df7a0a1e61963cf 100644 (file)
@@ -474,4 +474,187 @@ TEST(dns_question_is_valid_for_query_multi_different_names) {
         ASSERT_FALSE(dns_question_is_valid_for_query(question));
 }
 
+/* ================================================================
+ * dns_question_is_equal()
+ * ================================================================ */
+
+TEST(dns_question_is_equal_same_pointer) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *a = NULL;
+
+        a = dns_question_new(0);
+        ASSERT_NOT_NULL(a);
+
+        ASSERT_TRUE(dns_question_is_equal(a, a));
+}
+
+TEST(dns_question_is_equal_both_empty) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *a = NULL, *b = NULL;
+
+        a = dns_question_new(0);
+        ASSERT_NOT_NULL(a);
+
+        b = dns_question_new(0);
+        ASSERT_NOT_NULL(b);
+
+        ASSERT_TRUE(dns_question_is_equal(a, b));
+}
+
+TEST(dns_question_is_equal_single) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *a = NULL, *b = NULL;
+        DnsResourceKey *key = NULL;
+
+        a = dns_question_new(1);
+        ASSERT_NOT_NULL(a);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(a, key, 0);
+        dns_resource_key_unref(key);
+
+        b = dns_question_new(1);
+        ASSERT_NOT_NULL(b);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.EXAMPLE.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(b, key, 0);
+        dns_resource_key_unref(key);
+
+        ASSERT_TRUE(dns_question_is_equal(a, b));
+}
+
+TEST(dns_question_is_equal_different_names) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *a = NULL, *b = NULL;
+        DnsResourceKey *key = NULL;
+
+        a = dns_question_new(1);
+        ASSERT_NOT_NULL(a);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(a, key, 0);
+        dns_resource_key_unref(key);
+
+        b = dns_question_new(1);
+        ASSERT_NOT_NULL(b);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.org");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(b, key, 0);
+        dns_resource_key_unref(key);
+
+        ASSERT_FALSE(dns_question_is_equal(a, b));
+}
+
+TEST(dns_question_is_equal_different_types) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *a = NULL, *b = NULL;
+        DnsResourceKey *key = NULL;
+
+        a = dns_question_new(1);
+        ASSERT_NOT_NULL(a);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(a, key, 0);
+        dns_resource_key_unref(key);
+
+        b = dns_question_new(1);
+        ASSERT_NOT_NULL(b);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_AAAA, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(b, key, 0);
+        dns_resource_key_unref(key);
+
+        ASSERT_FALSE(dns_question_is_equal(a, b));
+}
+
+TEST(dns_question_is_equal_first_larger) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *a = NULL, *b = NULL;
+        DnsResourceKey *key = NULL;
+
+        a = dns_question_new(2);
+        ASSERT_NOT_NULL(a);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(a, key, 0);
+        dns_resource_key_unref(key);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_AAAA, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(a, key, 0);
+        dns_resource_key_unref(key);
+
+        b = dns_question_new(1);
+        ASSERT_NOT_NULL(b);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(b, key, 0);
+        dns_resource_key_unref(key);
+
+        ASSERT_FALSE(dns_question_is_equal(a, b));
+}
+
+TEST(dns_question_is_equal_second_larger) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *a = NULL, *b = NULL;
+        DnsResourceKey *key = NULL;
+
+        a = dns_question_new(1);
+        ASSERT_NOT_NULL(a);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(a, key, 0);
+        dns_resource_key_unref(key);
+
+        b = dns_question_new(2);
+        ASSERT_NOT_NULL(b);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(b, key, 0);
+        dns_resource_key_unref(key);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_AAAA, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(b, key, 0);
+        dns_resource_key_unref(key);
+
+        ASSERT_FALSE(dns_question_is_equal(a, b));
+}
+
+TEST(dns_question_is_equal_different_order) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *a = NULL, *b = NULL;
+        DnsResourceKey *key = NULL;
+
+        a = dns_question_new(2);
+        ASSERT_NOT_NULL(a);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_AAAA, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(a, key, 0);
+        dns_resource_key_unref(key);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(a, key, 0);
+        dns_resource_key_unref(key);
+
+        b = dns_question_new(2);
+        ASSERT_NOT_NULL(b);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(b, key, 0);
+        dns_resource_key_unref(key);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_AAAA, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        dns_question_add(b, key, 0);
+        dns_resource_key_unref(key);
+
+        ASSERT_TRUE(dns_question_is_equal(a, b));
+}
+
 DEFINE_TEST_MAIN(LOG_DEBUG);