diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-04-14 17:53:00 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-04-14 22:48:35 +0200 |
| commit | 16a42e43922f3ae40dac6e0e4a8474439401b2c8 (patch) | |
| tree | a64afa7b9fd0b55031a384528aff7828024f3137 /test | |
| parent | d1dd43787960cd7974e24be5f8d73fe83a0e6c9a (diff) | |
Improve debug output when verification tests fail.
Diffstat (limited to 'test')
| -rw-r--r-- | test/verify_test.cc | 97 |
1 files 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 @@ -196,45 +196,76 @@ 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<int>(note.type()), + static_cast<int>(note.code()), + note.note().get_value_or("<none>"), + note.file().get_value_or("<none>"), + 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("<none>"), + note.other_id().get_value_or("<none>"), + note.cpl_id().get_value_or("<none>"), + note.reference_hash().get_value_or("<none>"), + note.calculated_hash().get_value_or("<none>") + ); + + return s; +} + + +static void -check_verify_result(vector<path> dir, vector<dcp::DecryptedKDM> kdm, vector<dcp::VerificationNote> test_notes) +check_verify_result(vector<dcp::VerificationNote> notes, vector<dcp::VerificationNote> 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<int>(i.type()), - static_cast<int>(i.code()), - i.note().get_value_or("<none>"), - i.file().get_value_or("<none>"), - i.line().get_value_or(0), - i.cpl_id().get_value_or("<none>"), - i.reference_hash().get_value_or("<none>"), - i.calculated_hash().get_value_or("<none>") - ); + string message = "\n"; + + vector<dcp::VerificationNote> 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<int>(i.type()), - static_cast<int>(i.code()), - i.note().get_value_or("<none>"), - i.file().get_value_or("<none>"), - i.line().get_value_or(0), - i.cpl_id().get_value_or("<none>"), - i.reference_hash().get_value_or("<none>"), - i.calculated_hash().get_value_or("<none>") - ); + + vector<dcp::VerificationNote> 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<path> dir, vector<dcp::DecryptedKDM> kdm, vector<dcp::VerificationNote> test_notes) +{ + check_verify_result(dcp::verify({dir}, kdm, &stage, &progress, {}, xsd_test).notes, test_notes); } |
