Skip to content

Commit

Permalink
Fix use of BOOST_CHECK_MESSAGE in test-dnsrecords_cc.cc
Browse files Browse the repository at this point in the history
BOOST_CHECK_MESSAGE is designed to take a statement that describes a condition.

When `-l all` is used, it will print the statement, the condition, and
whether or not the condition passed.

With this change, output can appear like this:
test-dnsrecords_cc.cc:72: error: in "test_dnsrecords_cc/test_record_types": record types should be sorted such that 13 >= 21
Checking record type HINFO test #1
test-dnsrecords_cc.cc:72: info: check 'record types should be sorted such that 13 >= 13' has passed
  • Loading branch information
jsoref committed Sep 28, 2018
1 parent 9e5e6b2 commit 758cc25
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pdns/test-dnsrecords_cc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace {
BOOST_AUTO_TEST_SUITE(test_dnsrecords_cc)

#define REC_CHECK_EQUAL(a,b) { if (broken_marker::BROKEN == broken) { BOOST_WARN_EQUAL(a,b); } else { BOOST_CHECK_EQUAL(a,b); } }
#define REC_CHECK_MESSAGE(cond,msg) { if (broken_marker::BROKEN == broken) { BOOST_WARN_MESSAGE(cond,msg); } else { BOOST_CHECK_MESSAGE(cond,msg); } }
#define REC_CHECK_MESSAGE(cond,msg) { if (broken_marker::BROKEN == broken) { BOOST_WARN_MESSAGE(cond,"Failed to verify " << msg); } else { BOOST_CHECK_MESSAGE(cond,msg); } }
#define REC_FAIL_XSUCCESS(msg) { if (broken_marker::BROKEN == broken) { BOOST_CHECK_MESSAGE(false, std::string("Test has unexpectedly passed: ") + msg); } } // fail if test succeeds

BOOST_AUTO_TEST_CASE(test_record_types) {
Expand Down Expand Up @@ -201,15 +201,15 @@ BOOST_AUTO_TEST_CASE(test_record_types) {
const broken_marker broken = val.get<4>();

if (lq != q.getCode()) n = 0;
BOOST_CHECK_MESSAGE(q.getCode() >= lq, "record types not sorted correctly: " << q.getCode() << " < " << lq);
BOOST_CHECK_MESSAGE(q.getCode() >= lq, "record types should be sorted such that " << q.getCode() << " >= " << lq);
lq = q.getCode();
n++;
BOOST_TEST_CHECKPOINT("Checking record type " << q.getName() << " test #" << n);
BOOST_TEST_MESSAGE("Checking record type " << q.getName() << " test #" << n);
try {
std::string recData;
auto rec = DNSRecordContent::mastermake(q.getCode(), 1, inval);
BOOST_CHECK_MESSAGE(rec != NULL, "mastermake( " << q.getCode() << ", 1, " << inval << ") returned NULL");
BOOST_CHECK_MESSAGE(rec != NULL, "mastermake( " << q.getCode() << ", 1, " << inval << ") should not return NULL");
if (rec == NULL) continue;
// now verify the record (note that this will be same as *zone* value (except for certain QTypes)

Expand All @@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(test_record_types) {
recData = rec->serialize(DNSName("rec.test"));

std::shared_ptr<DNSRecordContent> rec2 = DNSRecordContent::unserialize(DNSName("rec.test"),q.getCode(),recData);
BOOST_CHECK_MESSAGE(rec2 != NULL, "unserialize(rec.test, " << q.getCode() << ", recData) returned NULL");
BOOST_CHECK_MESSAGE(rec2 != NULL, "unserialize(rec.test, " << q.getCode() << ", recData) should not return NULL");
if (rec2 == NULL) continue;
// now verify the zone representation (here it can be different!)
REC_CHECK_EQUAL(rec2->getZoneRepresentation(), zoneval);
Expand All @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(test_record_types) {
recData = makeHexDump(recData);
REC_CHECK_EQUAL(recData, cmpData);
} catch (std::runtime_error &err) {
REC_CHECK_MESSAGE(false, "Failed to verify " << q.getName() << ": " << err.what());
REC_CHECK_MESSAGE(false, q.getName() << ": " << err.what());
continue;
}
REC_FAIL_XSUCCESS(q.getName() << " test #" << n << " has unexpectedly passed")
Expand Down

0 comments on commit 758cc25

Please sign in to comment.