From: James Coglan Date: Fri, 31 May 2024 08:47:11 +0000 (+0100) Subject: resolved: tests for dns_question_is_equal() X-Git-Tag: v257-rc1~842^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b45d3501a434bed829bbc57f053fa46f9d57d32d;p=thirdparty%2Fsystemd.git resolved: tests for dns_question_is_equal() --- diff --git a/src/resolve/test-dns-question.c b/src/resolve/test-dns-question.c index 62156ac6e27..9f01a0694ef 100644 --- a/src/resolve/test-dns-question.c +++ b/src/resolve/test-dns-question.c @@ -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);