From 16a42e43922f3ae40dac6e0e4a8474439401b2c8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 14 Apr 2024 17:53:00 +0200 Subject: [PATCH] Improve debug output when verification tests fail. --- test/verify_test.cc | 97 ++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 33 deletions(-) diff --git a/test/verify_test.cc b/test/verify_test.cc index 161201b9..b4019acd 100644 --- a/test/verify_test.cc +++ b/test/verify_test.cc @@ -195,46 +195,77 @@ dump_notes (vector const & notes) LIBDCP_ENABLE_WARNINGS +static +string +to_string(dcp::VerificationNote const& note) +{ + string s = note_to_string(note) + dcp::String::compose( + "\n [%1 %2 %3 %4 %5 %6 ", + static_cast(note.type()), + static_cast(note.code()), + note.note().get_value_or(""), + note.file().get_value_or(""), + note.line().get_value_or(0), + note.frame().get_value_or(0) + ); + + s += dcp::String::compose( + "%1 %2 %3 %4 %5]\n", + note.id().get_value_or(""), + note.other_id().get_value_or(""), + note.cpl_id().get_value_or(""), + note.reference_hash().get_value_or(""), + note.calculated_hash().get_value_or("") + ); + + return s; +} + + static void -check_verify_result(vector dir, vector kdm, vector test_notes) +check_verify_result(vector notes, vector test_notes) { - auto notes = dcp::verify({dir}, kdm, &stage, &progress, {}, xsd_test).notes; - std::sort (notes.begin(), notes.end()); - std::sort (test_notes.begin(), test_notes.end()); + std::sort(notes.begin(), notes.end()); + std::sort(test_notes.begin(), test_notes.end()); - string message = "\nVerification notes from test:\n"; - for (auto i: notes) { - message += " " + note_to_string(i) + "\n"; - message += dcp::String::compose( - " [%1 %2 %3 %4 %5 %6 %7 %8]\n", - static_cast(i.type()), - static_cast(i.code()), - i.note().get_value_or(""), - i.file().get_value_or(""), - i.line().get_value_or(0), - i.cpl_id().get_value_or(""), - i.reference_hash().get_value_or(""), - i.calculated_hash().get_value_or("") - ); + string message = "\n"; + + vector not_expected; + for (auto note: notes) { + auto iter = std::find_if(test_notes.begin(), test_notes.end(), [note](dcp::VerificationNote const& n) { return note.type() == n.type() && note.code() == n.code(); }); + if (iter != test_notes.end() && *iter != note) { + message += "Wrong details:\n --seen " + to_string(note) + " --expected " + to_string(*iter) + "\n"; + } else if (iter == test_notes.end()) { + not_expected.push_back(note); + } } - message += "Expected:\n"; - for (auto i: test_notes) { - message += " " + note_to_string(i) + "\n"; - message += dcp::String::compose( - " [%1 %2 %3 %4 %5 %6 %7 %8]\n", - static_cast(i.type()), - static_cast(i.code()), - i.note().get_value_or(""), - i.file().get_value_or(""), - i.line().get_value_or(0), - i.cpl_id().get_value_or(""), - i.reference_hash().get_value_or(""), - i.calculated_hash().get_value_or("") - ); + + vector not_seen; + for (auto note: test_notes) { + auto iter = std::find_if(notes.begin(), notes.end(), [note](dcp::VerificationNote const& n) { return note.type() == n.type() && note.code() == n.code(); }); + if (iter == notes.end()) { + not_seen.push_back(note); + } + } + + for (auto note: not_expected) { + message += "Not expected:\n" + to_string(note) + "\n"; + } + + for (auto note: not_seen) { + message += "Not seen:\n" + to_string(note) + "\n"; } - BOOST_REQUIRE_MESSAGE (notes == test_notes, message); + BOOST_REQUIRE_MESSAGE(notes == test_notes, message); +} + + +static +void +check_verify_result(vector dir, vector kdm, vector test_notes) +{ + check_verify_result(dcp::verify({dir}, kdm, &stage, &progress, {}, xsd_test).notes, test_notes); } -- 2.30.2