mirror of
https://github.com/systemd/systemd.git
synced 2024-10-27 01:55:22 +03:00
resolved: tests for dns_zone_put()
This commit is contained in:
parent
c01267c4a9
commit
c7e3e5507e
@ -210,6 +210,17 @@ executables += [
|
||||
],
|
||||
'include_directories' : resolve_includes,
|
||||
},
|
||||
test_template + {
|
||||
'sources' : [
|
||||
files('test-dns-zone.c'),
|
||||
basic_dns_sources,
|
||||
systemd_resolved_sources,
|
||||
],
|
||||
'dependencies' : [
|
||||
systemd_resolved_dependencies,
|
||||
],
|
||||
'include_directories' : resolve_includes,
|
||||
},
|
||||
test_template + {
|
||||
'sources' : [
|
||||
files('test-resolved-link.c'),
|
||||
|
83
src/resolve/test-dns-zone.c
Normal file
83
src/resolve/test-dns-zone.c
Normal file
@ -0,0 +1,83 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "dns-type.h"
|
||||
#include "resolved-dns-rr.h"
|
||||
#include "resolved-dns-scope.h"
|
||||
#include "resolved-dns-zone.h"
|
||||
#include "resolved-link.h"
|
||||
#include "resolved-manager.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void dns_scope_freep(DnsScope **s) {
|
||||
if (s != NULL && *s != NULL)
|
||||
dns_scope_free(*s);
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* dns_zone_put()
|
||||
* ================================================================ */
|
||||
|
||||
TEST(dns_zone_put_simple) {
|
||||
Manager manager = {};
|
||||
_cleanup_(dns_scope_freep) DnsScope *scope = NULL;
|
||||
DnsZone *zone = NULL;
|
||||
DnsZoneItem *item = NULL;
|
||||
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
|
||||
|
||||
ASSERT_OK(dns_scope_new(&manager, &scope, NULL, DNS_PROTOCOL_DNS, AF_INET));
|
||||
ASSERT_NOT_NULL(scope);
|
||||
zone = &scope->zone;
|
||||
|
||||
rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
|
||||
ASSERT_NOT_NULL(rr);
|
||||
|
||||
ASSERT_TRUE(dns_zone_is_empty(zone));
|
||||
|
||||
ASSERT_OK(dns_zone_put(zone, scope, rr, 0));
|
||||
|
||||
ASSERT_FALSE(dns_zone_is_empty(zone));
|
||||
|
||||
item = dns_zone_get(zone, rr);
|
||||
ASSERT_NOT_NULL(item);
|
||||
ASSERT_EQ((int)item->state, DNS_ZONE_ITEM_ESTABLISHED);
|
||||
}
|
||||
|
||||
TEST(dns_zone_put_any_class_is_invalid) {
|
||||
Manager manager = {};
|
||||
_cleanup_(dns_scope_freep) DnsScope *scope = NULL;
|
||||
DnsZone *zone = NULL;
|
||||
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
|
||||
|
||||
dns_scope_new(&manager, &scope, NULL, DNS_PROTOCOL_DNS, AF_INET);
|
||||
ASSERT_NOT_NULL(scope);
|
||||
zone = &scope->zone;
|
||||
|
||||
rr = dns_resource_record_new_full(DNS_CLASS_ANY, DNS_TYPE_A, "www.example.com");
|
||||
ASSERT_NOT_NULL(rr);
|
||||
|
||||
ASSERT_ERROR(dns_zone_put(zone, scope, rr, 0), EINVAL);
|
||||
|
||||
ASSERT_TRUE(dns_zone_is_empty(zone));
|
||||
}
|
||||
|
||||
TEST(dns_zone_put_any_type_is_invalid) {
|
||||
Manager manager = {};
|
||||
_cleanup_(dns_scope_freep) DnsScope *scope = NULL;
|
||||
DnsZone *zone = NULL;
|
||||
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
|
||||
|
||||
dns_scope_new(&manager, &scope, NULL, DNS_PROTOCOL_DNS, AF_INET);
|
||||
ASSERT_NOT_NULL(scope);
|
||||
zone = &scope->zone;
|
||||
|
||||
rr = dns_resource_record_new_full(DNS_CLASS_IN, DNS_TYPE_ANY, "www.example.com");
|
||||
ASSERT_NOT_NULL(rr);
|
||||
|
||||
ASSERT_ERROR(dns_zone_put(zone, scope, rr, 0), EINVAL);
|
||||
|
||||
ASSERT_TRUE(dns_zone_is_empty(zone));
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
Loading…
Reference in New Issue
Block a user