resolved: tests for dns_resource_key_reduce()

This commit is contained in:
James Coglan
2024-07-23 12:44:35 +01:00
committed by Luca Boccassi
parent 5982caccd7
commit 6104ba9d42
+69
View File
@@ -696,4 +696,73 @@ TEST(dns_resource_key_to_string) {
ASSERT_STREQ(ans, "www.example.com IN CNAME");
}
/* ================================================================
* dns_resource_key_reduce()
* ================================================================ */
TEST(dns_resource_key_reduce_same_pointer) {
DnsResourceKey *a = NULL, *b = NULL;
a = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
ASSERT_NOT_NULL(a);
b = a;
ASSERT_TRUE(dns_resource_key_reduce(&a, &b));
ASSERT_TRUE(a == b);
dns_resource_key_unref(a);
}
TEST(dns_resource_key_reduce_same_values) {
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *a = NULL, *b = NULL;
a = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
ASSERT_NOT_NULL(a);
b = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
ASSERT_NOT_NULL(b);
ASSERT_TRUE(a != b);
ASSERT_TRUE(dns_resource_key_reduce(&a, &b));
ASSERT_TRUE(a == b);
}
TEST(dns_resource_key_reduce_different_values) {
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *a = NULL, *b = NULL;
a = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "example.com");
ASSERT_NOT_NULL(a);
b = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
ASSERT_NOT_NULL(b);
ASSERT_TRUE(a != b);
ASSERT_FALSE(dns_resource_key_reduce(&a, &b));
ASSERT_TRUE(a != b);
}
TEST(dns_resource_key_reduce_refcount) {
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *a = NULL, *b = NULL, *c = NULL;
a = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
ASSERT_NOT_NULL(a);
b = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
ASSERT_NOT_NULL(b);
c = b;
ASSERT_TRUE(a != b);
a->n_ref = 3;
b->n_ref = 2;
ASSERT_TRUE(dns_resource_key_reduce(&a, &b));
ASSERT_TRUE(a == b);
ASSERT_EQ(a->n_ref, 4u);
ASSERT_EQ(c->n_ref, 1u);
/* set refcount so that objects will be freed */
a->n_ref = 2;
}
DEFINE_TEST_MAIN(LOG_DEBUG);