From 88d3011455ae0779f39ab676223dc85bf2b5e3a5 Mon Sep 17 00:00:00 2001 From: Frank Dana Date: Mon, 27 Sep 2021 07:14:48 -0400 Subject: [PATCH] Unit tests: Use == to compare strings (#741) When there's a mismatch, Catch2 will output the contents of both strings rather than a meaningless .compare() numeric value. --- tests/FFmpegReader.cpp | 3 +-- tests/FFmpegWriter.cpp | 3 +-- tests/FrameMapper.cpp | 3 +-- tests/KeyFrame.cpp | 4 ++-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/FFmpegReader.cpp b/tests/FFmpegReader.cpp index 747ae0e2..c5696b76 100644 --- a/tests/FFmpegReader.cpp +++ b/tests/FFmpegReader.cpp @@ -300,6 +300,5 @@ TEST_CASE( "DisplayInfo", "[libopenshot][ffmpegreader]" ) r.DisplayInfo(&output); // Compare a [0, expected.size()) substring of output to expected - auto compare_value = output.str().compare(0, expected.size(), expected); - CHECK(compare_value == 0); + CHECK(output.str().substr(0, expected.size()) == expected); } diff --git a/tests/FFmpegWriter.cpp b/tests/FFmpegWriter.cpp index adb555b2..6a9a0211 100644 --- a/tests/FFmpegWriter.cpp +++ b/tests/FFmpegWriter.cpp @@ -199,6 +199,5 @@ TEST_CASE( "DisplayInfo", "[libopenshot][ffmpegwriter]" ) w.Close(); // Compare a [0, expected.size()) substring of output to expected - auto compare_value = output.str().compare(0, expected.size(), expected); - CHECK(compare_value == 0); + CHECK(output.str().substr(0, expected.size()) == expected); } diff --git a/tests/FrameMapper.cpp b/tests/FrameMapper.cpp index fc1f70d4..7553345b 100644 --- a/tests/FrameMapper.cpp +++ b/tests/FrameMapper.cpp @@ -651,8 +651,7 @@ Target frame #: 10 mapped to original frame #: (8 odd, 8 even) mapping.PrintMapping(&mapping_out); // Compare a [0, expected.size()) substring of output to expected - auto compare_value = mapping_out.str().compare(0, expected.size(), expected); - CHECK(compare_value == 0); + CHECK(mapping_out.str().substr(0, expected.size()) == expected); } TEST_CASE( "Json", "[libopenshot][framemapper]" ) diff --git a/tests/KeyFrame.cpp b/tests/KeyFrame.cpp index 3f186729..7b5ec149 100644 --- a/tests/KeyFrame.cpp +++ b/tests/KeyFrame.cpp @@ -536,7 +536,7 @@ R"( 1 10.0000 999 12345.6777)"; // Ensure the two strings are equal up to the limits of 'expected' - CHECK(output.str().compare(0, expected.size(), expected) == 0); + CHECK(output.str().substr(0, expected.size()) == expected); } TEST_CASE( "PrintValues", "[libopenshot][keyframe]" ) @@ -582,7 +582,7 @@ R"(│Frame# (X) │ Y Value │ Delta Y │ Increasing? │ Repeat Fraction │ 25 │ 16.5446 │ +1 │ true │ Fraction(1, 2) │)"; // Ensure the two strings are equal up to the limits of 'expected' - CHECK(output.str().compare(0, expected.size(), expected) == 0); + CHECK(output.str().substr(0, expected.size()) == expected); } #ifdef USE_OPENCV