/*****
***** Commonly used structures
*****/
+/*
+ * An array of these structures is passed to compare_ok().
+ */
+struct compare_ok {
+ const char *text1; /* text passed to fromtext_*() */
+ const char *text2; /* text passed to fromtext_*() */
+ int answer; /* -1, 0, 1 */
+ int lineno; /* source line defining this RDATA */
+};
+typedef struct compare_ok compare_ok_t;
/*
* An array of these structures is passed to check_text_ok().
***** Convenience macros for creating the above structures
*****/
+#define COMPARE(r1, r2, answer) \
+ { r1, r2, answer, __LINE__ }
+#define COMPARE_SENTINEL() \
+ { NULL, NULL, 0, __LINE__ }
+
#define TEXT_VALID_CHANGED(data_in, data_out) \
{ data_in, data_out, __LINE__ }
#define TEXT_VALID(data) { data, data, __LINE__ }
check_wire_ok_single(&empty_wire, rdclass, type, structsize);
}
+/*
+ * Check that two records compare as expected with dns_rdata_compare().
+ */
+static void
+check_compare_ok_single(const compare_ok_t *compare_ok,
+ dns_rdataclass_t rdclass, dns_rdatatype_t type)
+{
+ dns_rdata_t rdata1 = DNS_RDATA_INIT, rdata2 = DNS_RDATA_INIT;
+ unsigned char buf1[1024], buf2[1024];
+ isc_result_t result;
+ int answer;
+
+ result = dns_test_rdatafromstring(&rdata1, rdclass, type,
+ buf1, sizeof(buf1),
+ compare_ok->text1);
+
+ ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "line %d: '%s': "
+ "expected success, got failure",
+ compare_ok->lineno, compare_ok->text1);
+
+ result = dns_test_rdatafromstring(&rdata2, rdclass, type,
+ buf2, sizeof(buf2),
+ compare_ok->text2);
+
+ ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS, "line %d: '%s': "
+ "expected success, got failure",
+ compare_ok->lineno, compare_ok->text2);
+
+ answer = dns_rdata_compare(&rdata1, &rdata2);
+ if (compare_ok->answer == 0) {
+ ATF_REQUIRE_MSG(answer == 0,
+ "line %d: dns_rdata_compare('%s', '%s'): "
+ "expected equal, got %s",
+ compare_ok->lineno,
+ compare_ok->text1, compare_ok->text2,
+ (answer > 0) ? "greater than" : "less than");
+ }
+ if (compare_ok->answer < 0) {
+ ATF_REQUIRE_MSG(answer < 0,
+ "line %d: dns_rdata_compare('%s', '%s'): "
+ "expected less than, got %s",
+ compare_ok->lineno,
+ compare_ok->text1, compare_ok->text2,
+ (answer == 0) ? "equal" : "greater than");
+ }
+ if (compare_ok->answer > 0) {
+ ATF_REQUIRE_MSG(answer > 0,
+ "line %d: dns_rdata_compare('%s', '%s'): "
+ "expected greater than, got %s",
+ compare_ok->lineno,
+ compare_ok->text1, compare_ok->text2,
+ (answer == 0) ? "equal" : "less than");
+ }
+}
+
+/*
+ * Check that all the records sets in compare_ok compare as expected
+ * with dns_rdata_compare().
+ */
+static void
+check_compare_ok(const compare_ok_t *compare_ok,
+ dns_rdataclass_t rdclass, dns_rdatatype_t type)
+{
+ size_t i;
+ /*
+ * Check all entries in the supplied array.
+ */
+ for (i = 0; compare_ok[i].text1 != NULL; i++) {
+ check_compare_ok_single(&compare_ok[i], rdclass, type);
+ }
+}
+
/*
* Test whether supplied sets of text form and/or wire form RDATA are handled
* as expected. This is just a helper function which should be the only
*/
static void
check_rdata(const text_ok_t *text_ok, const wire_ok_t *wire_ok,
+ const compare_ok_t *compare_ok,
bool empty_ok, dns_rdataclass_t rdclass,
dns_rdatatype_t type, size_t structsize)
{
if (wire_ok != NULL) {
check_wire_ok(wire_ok, empty_ok, rdclass, type, structsize);
}
+ if (compare_ok != NULL) {
+ check_compare_ok(compare_ok, rdclass, type);
+ }
dns_test_end();
}
UNUSED(tc);
- check_rdata(text_ok, wire_ok, true, dns_rdataclass_in,
+ check_rdata(text_ok, wire_ok, NULL, true, dns_rdataclass_in,
dns_rdatatype_apl, sizeof(dns_rdata_in_apl_t));
}
UNUSED(tc);
- check_rdata(text_ok, wire_ok, false, dns_rdataclass_in,
+ check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_atma, sizeof(dns_rdata_in_atma_t));
}
UNUSED(tc);
- check_rdata(text_ok, wire_ok, false, dns_rdataclass_in,
+ check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_csync, sizeof(dns_rdata_csync_t));
}
UNUSED(tc);
- check_rdata(text_ok, wire_ok, false, dns_rdataclass_in,
+ check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_doa, sizeof(dns_rdata_doa_t));
}
UNUSED(tc);
- check_rdata(NULL, wire_ok, true, dns_rdataclass_in,
+ check_rdata(NULL, wire_ok, NULL, true, dns_rdataclass_in,
dns_rdatatype_opt, sizeof(dns_rdata_opt_t));
}
UNUSED(tc);
- check_rdata(text_ok, wire_ok, false, dns_rdataclass_in,
+ check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_eid, sizeof(dns_rdata_in_eid_t));
}
UNUSED(tc);
- check_rdata(NULL, wire_ok, false, dns_rdataclass_in,
+ check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_isdn, sizeof(dns_rdata_isdn_t));
}
UNUSED(tc);
- check_rdata(text_ok, wire_ok, false, dns_rdataclass_in,
+ check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_nimloc, sizeof(dns_rdata_in_nimloc_t));
}
UNUSED(tc);
- check_rdata(text_ok, wire_ok, false, dns_rdataclass_in,
+ check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_nsec, sizeof(dns_rdata_nsec_t));
}
UNUSED(tc);
- check_rdata(text_ok, NULL, false, dns_rdataclass_in,
+ check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in,
dns_rdatatype_nsec3, sizeof(dns_rdata_nsec3_t));
}
+/*
+ * NXT Tests.
+ */
+ATF_TC(nxt);
+ATF_TC_HEAD(nxt, tc) {
+ atf_tc_set_md_var(tc, "descr", "NXT RDATA manipulations");
+}
+ATF_TC_BODY(nxt, tc) {
+ compare_ok_t compare_ok[] = {
+ COMPARE("a. A SIG", "a. A SIG", 0),
+ /*
+ * Records that differ only in the case of the next
+ * name should be equal.
+ */
+ COMPARE("A. A SIG", "a. A SIG", 0),
+ /*
+ * Sorting on name field.
+ */
+ COMPARE("A. A SIG", "b. A SIG", -1),
+ COMPARE("b. A SIG", "A. A SIG", 1),
+ /* bit map differs */
+ COMPARE("b. A SIG", "b. A AAAA SIG", -1),
+ /* order of bit map does not matter */
+ COMPARE("b. A SIG AAAA", "b. A AAAA SIG", 0),
+ COMPARE_SENTINEL()
+ };
+
+ UNUSED(tc);
+
+ check_rdata(NULL, NULL, compare_ok, false, dns_rdataclass_in,
+ dns_rdatatype_nxt, sizeof(dns_rdata_nxt_t));
+}
+
/*
* WKS tests.
*
UNUSED(tc);
- check_rdata(text_ok, wire_ok, false, dns_rdataclass_in,
+ check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
dns_rdatatype_wks, sizeof(dns_rdata_in_wks_t));
}
ATF_TP_ADD_TC(tp, nimloc);
ATF_TP_ADD_TC(tp, nsec);
ATF_TP_ADD_TC(tp, nsec3);
+ ATF_TP_ADD_TC(tp, nxt);
ATF_TP_ADD_TC(tp, wks);
return (atf_no_error());