--- /dev/null
+@@
+expression E;
+identifier ROOT =~ "^dns_rootname$";
+@@
+
+- dns_name_equal(E, ROOT)
++ dns_name_isroot(E)
+
+@@
+expression E;
+identifier ROOT =~ "^dns_rootname$";
+@@
+
+- dns_name_equal(ROOT, E)
++ dns_name_isroot(E)
+
+@@
+expression E;
+identifier ROOT =~ "^dns_rootname$";
+@@
+
+- dns_name_compare(E, ROOT) == 0
++ dns_name_isroot(E)
+
+@@
+expression E;
+identifier ROOT =~ "^dns_rootname$";
+@@
+
+- dns_name_compare(ROOT, E) == 0
++ dns_name_isroot(E)
+
+@@
+constant ONE =~ "^1[uUlL]*$";
+expression E;
+@@
+
+- dns_name_countlabels(E) <= ONE
++ !dns_name_belowroot(E)
+
+@@
+constant ONE =~ "^1[uUlL]*$";
+expression E;
+@@
+
+- dns_name_countlabels(E) > ONE
++ dns_name_belowroot(E)
* Requires:
* \li 'name' to be valid.
*/
+
+static inline bool
+dns_name_isroot(const dns_name_t *name) {
+ REQUIRE(DNS_NAME_VALID(name));
+
+ return name->length == 1 && name->ndata[0] == 0;
+}
+/*%<
+ * Return whether 'name' is the root name.
+ *
+ * Requires:
+ * \li 'name' to be valid.
+ */
+
+static inline bool
+dns_name_belowroot(const dns_name_t *name) {
+ REQUIRE(DNS_NAME_VALID(name));
+
+ return name->length != 0 && name->ndata[0] != 0;
+}
+/*%<
+ * Return whether 'name' is below root. It checks whether there's at least one
+ * non-root label.
+ *
+ * Requires:
+ * \li 'name' to be valid.
+ */
}
}
+/* dns_name_isroot */
+ISC_RUN_TEST_IMPL(isroot) {
+ struct {
+ const char *namestr;
+ bool expect;
+ } testcases[] = {
+ { ".", true },
+ { "x", false },
+ { "x.", false },
+ { "x.y.", false },
+ };
+ dns_name_t empty;
+
+ UNUSED(state);
+
+ dns_name_init(&empty);
+ assert_false(dns_name_isroot(&empty));
+
+ for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
+ dns_fixedname_t fixed;
+ dns_name_t *name = dns_fixedname_initname(&fixed);
+ isc_result_t result = dns_name_fromstring(
+ name, testcases[i].namestr, NULL, 0, NULL);
+
+ assert_int_equal(result, ISC_R_SUCCESS);
+ assert_int_equal(dns_name_isroot(name), testcases[i].expect);
+ }
+}
+
+/* dns_name_belowroot */
+ISC_RUN_TEST_IMPL(belowroot) {
+ struct {
+ const char *namestr;
+ bool expect;
+ } testcases[] = {
+ { ".", false },
+ { "x", true },
+ { "x.", true },
+ { "x.y.", true },
+ };
+ dns_name_t empty;
+
+ UNUSED(state);
+
+ dns_name_init(&empty);
+ assert_false(dns_name_belowroot(&empty));
+
+ for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
+ dns_fixedname_t fixed;
+ dns_name_t *name = dns_fixedname_initname(&fixed);
+ isc_result_t result = dns_name_fromstring(
+ name, testcases[i].namestr, NULL, 0, NULL);
+
+ assert_int_equal(result, ISC_R_SUCCESS);
+ assert_int_equal(dns_name_belowroot(name), testcases[i].expect);
+ }
+}
+
/* dns_name_hash */
ISC_RUN_TEST_IMPL(hash) {
struct {
#endif /* DNS_BENCHMARK_TESTS */
ISC_TEST_LIST_START
+ISC_TEST_ENTRY(belowroot)
ISC_TEST_ENTRY(buffer)
ISC_TEST_ENTRY(collision)
ISC_TEST_ENTRY(compression)
ISC_TEST_ENTRY(init)
ISC_TEST_ENTRY(invalidate)
ISC_TEST_ENTRY(isabsolute)
+ISC_TEST_ENTRY(isroot)
ISC_TEST_ENTRY(issubdomain)
ISC_TEST_ENTRY(istat)
ISC_TEST_ENTRY(maxlabels)