ASSERT_TRUE(dns_zone_is_empty(zone));
}
+/* ================================================================
+ * dns_zone_remove_rr()
+ * ================================================================ */
+
+TEST(dns_zone_remove_rr_match) {
+ Manager manager = {};
+ _cleanup_(dns_scope_freep) DnsScope *scope = NULL;
+ DnsZone *zone = NULL;
+ _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr_in = NULL, *rr_out = NULL;
+
+ dns_scope_new(&manager, &scope, NULL, DNS_PROTOCOL_DNS, AF_INET);
+ ASSERT_NOT_NULL(scope);
+ zone = &scope->zone;
+
+ rr_in = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+ ASSERT_NOT_NULL(rr_in);
+ rr_in->a.in_addr.s_addr = htobe32(0xc0a8017f);
+
+ ASSERT_OK(dns_zone_put(zone, scope, rr_in, 0));
+
+ rr_out = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+ ASSERT_NOT_NULL(rr_out);
+ rr_out->a.in_addr.s_addr = htobe32(0xc0a8017f);
+
+ ASSERT_NOT_NULL(dns_zone_get(zone, rr_in));
+ dns_zone_remove_rr(zone, rr_out);
+ ASSERT_NULL(dns_zone_get(zone, rr_in));
+}
+
+TEST(dns_zone_remove_rr_match_one) {
+ Manager manager = {};
+ _cleanup_(dns_scope_freep) DnsScope *scope = NULL;
+ DnsZone *zone = NULL;
+ _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr_in = NULL, *rr_out = NULL;
+
+ dns_scope_new(&manager, &scope, NULL, DNS_PROTOCOL_DNS, AF_INET);
+ ASSERT_NOT_NULL(scope);
+ zone = &scope->zone;
+
+ rr_in = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+ ASSERT_NOT_NULL(rr_in);
+ rr_in->a.in_addr.s_addr = htobe32(0xc0a8017f);
+
+ ASSERT_OK(dns_zone_put(zone, scope, rr_in, 0));
+ dns_resource_record_unref(rr_in);
+
+ rr_in = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_CNAME, "example.com");
+ ASSERT_NOT_NULL(rr_in);
+ rr_in->cname.name = strdup("www.example.com");
+
+ ASSERT_OK(dns_zone_put(zone, scope, rr_in, 0));
+
+ rr_out = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+ ASSERT_NOT_NULL(rr_out);
+ rr_out->a.in_addr.s_addr = htobe32(0xc0a8017f);
+
+ ASSERT_NOT_NULL(dns_zone_get(zone, rr_out));
+ dns_zone_remove_rr(zone, rr_out);
+ ASSERT_NULL(dns_zone_get(zone, rr_out));
+ ASSERT_NOT_NULL(dns_zone_get(zone, rr_in));
+}
+
+TEST(dns_zone_remove_rr_different_payload) {
+ Manager manager = {};
+ _cleanup_(dns_scope_freep) DnsScope *scope = NULL;
+ DnsZone *zone = NULL;
+ _cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr_in = NULL, *rr_out = NULL;
+
+ dns_scope_new(&manager, &scope, NULL, DNS_PROTOCOL_DNS, AF_INET);
+ ASSERT_NOT_NULL(scope);
+ zone = &scope->zone;
+
+ rr_in = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+ ASSERT_NOT_NULL(rr_in);
+ rr_in->a.in_addr.s_addr = htobe32(0xc0a8017f);
+
+ ASSERT_OK(dns_zone_put(zone, scope, rr_in, 0));
+
+ rr_out = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+ ASSERT_NOT_NULL(rr_out);
+ rr_out->a.in_addr.s_addr = htobe32(0xc0a80180);
+
+ ASSERT_NOT_NULL(dns_zone_get(zone, rr_in));
+ dns_zone_remove_rr(zone, rr_out);
+ ASSERT_NOT_NULL(dns_zone_get(zone, rr_in));
+}
+
DEFINE_TEST_MAIN(LOG_DEBUG);