From 5ae7112494b7442550090270633814663f26b4a9 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Fri, 17 Jun 2022 15:05:06 -0400 Subject: [PATCH 1/6] Catch2: Header templates for tests Since Catch2 v3.0+ uses a vasty different organization for headers and targets, we have two templates for what the unit test code will include. One or the other is configure by CMake as the file openshot_catch.h in the build directory, and all of the unit test sources can include that instead. --- tests/catch2v2.h.in | 19 +++++++++++++++++++ tests/catch2v3.h.in | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/catch2v2.h.in create mode 100644 tests/catch2v3.h.in diff --git a/tests/catch2v2.h.in b/tests/catch2v2.h.in new file mode 100644 index 00000000..39b82264 --- /dev/null +++ b/tests/catch2v2.h.in @@ -0,0 +1,19 @@ +/** + * @file + * @brief Header (template) for tests built with Catch2 v2 + * @author Jonathan Thomas + * @author FeRD (Frank Dana) + * + * @ref License + */ + +// Copyright (c) 2008-2022 OpenShot Studios, LLC +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef OPENSHOT_CATCH2_H +#define OPENSHOT_CATCH2_H + +#include + +#endif diff --git a/tests/catch2v3.h.in b/tests/catch2v3.h.in new file mode 100644 index 00000000..6e309c54 --- /dev/null +++ b/tests/catch2v3.h.in @@ -0,0 +1,19 @@ +/** + * @file + * @brief Header (template) for tests built with Catch2 v3.0 or later + * @author Jonathan Thomas + * @author FeRD (Frank Dana) + * + * @ref License + */ + +// Copyright (c) 2008-2022 OpenShot Studios, LLC +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef OPENSHOT_CATCH2_H +#define OPENSHOT_CATCH2_H + +#include + +#endif From 6db5f141397ec83a9e0f2c36bc59137c09c87aff Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Fri, 17 Jun 2022 15:08:50 -0400 Subject: [PATCH 2/6] Update catch_main.cpp (only for Catch2v2) --- tests/catch_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/catch_main.cpp b/tests/catch_main.cpp index 1a548c5b..d4cf752d 100644 --- a/tests/catch_main.cpp +++ b/tests/catch_main.cpp @@ -11,5 +11,5 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #define CATCH_CONFIG_MAIN -#include +#include "openshot_catch.h" From 159d4fc6295203bd6d74ccf8d237d881a59d0431 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Fri, 17 Jun 2022 15:09:16 -0400 Subject: [PATCH 3/6] tests/CMakeLists: Handle Catch2 v2 vs. v3 --- tests/CMakeLists.txt | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 374e5889..56f47e15 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -68,20 +68,37 @@ if(NOT BUILD_TESTING) return() endif() -# Create object library for test executable main(), -# to avoid recompiling for every test -add_library(catch-main OBJECT catch_main.cpp) -target_link_libraries(catch-main PUBLIC Catch2::Catch2) +add_library(openshot_catch2 INTERFACE) +target_include_directories(openshot_catch2 INTERFACE + "${CMAKE_CURRENT_BINARY_DIR}" +) +target_compile_definitions(openshot_catch2 INTERFACE + TEST_MEDIA_PATH="${TEST_MEDIA_PATH}") + +if(TARGET Catch2::Catch2WithMain) + # Catch2 v3 works a bit differently + configure_file(catch2v3.h.in openshot_catch.h) + target_link_libraries(openshot_catch2 INTERFACE Catch2::Catch2WithMain) +else() + configure_file(catch2v2.h.in openshot_catch.h) + # Create object library for test executable main(), + # to avoid recompiling for every test + add_library(catch-main OBJECT catch_main.cpp) + target_link_libraries(catch-main PUBLIC Catch2::Catch2) + target_include_directories(catch-main PUBLIC + "${CMAKE_CURRENT_BINARY_DIR}") + target_link_libraries(openshot_catch2 INTERFACE Catch2::Catch2) + target_sources(openshot_catch2 INTERFACE $) +endif() foreach(tname ${OPENSHOT_TESTS}) add_executable(openshot-${tname}-test ${tname}.cpp - $ ) - target_compile_definitions(openshot-${tname}-test PRIVATE - TEST_MEDIA_PATH="${TEST_MEDIA_PATH}" + target_link_libraries(openshot-${tname}-test + openshot_catch2 + openshot ) - target_link_libraries(openshot-${tname}-test Catch2::Catch2 openshot) # Automatically configure CTest targets from Catch2 test cases catch_discover_tests( From 677ed5f59184a3fb9499787c3aca78f1c678c0c0 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Fri, 17 Jun 2022 15:07:16 -0400 Subject: [PATCH 4/6] Tests: Switch test files to openshot_catch.h --- tests/CVObjectDetection.cpp | 2 +- tests/CVStabilizer.cpp | 2 +- tests/CVTracker.cpp | 2 +- tests/CacheDisk.cpp | 2 +- tests/CacheMemory.cpp | 2 +- tests/ChromaKey.cpp | 2 +- tests/Clip.cpp | 2 +- tests/Color.cpp | 2 +- tests/Coordinate.cpp | 2 +- tests/Crop.cpp | 2 +- tests/DummyReader.cpp | 2 +- tests/FFmpegReader.cpp | 2 +- tests/FFmpegWriter.cpp | 2 +- tests/Fraction.cpp | 2 +- tests/Frame.cpp | 2 +- tests/FrameMapper.cpp | 2 +- tests/ImageWriter.cpp | 2 +- tests/KeyFrame.cpp | 2 +- tests/Point.cpp | 2 +- tests/QtImageReader.cpp | 2 +- tests/ReaderBase.cpp | 2 +- tests/Settings.cpp | 2 +- tests/Timeline.cpp | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/CVObjectDetection.cpp b/tests/CVObjectDetection.cpp index 939fc967..4d5b4b29 100644 --- a/tests/CVObjectDetection.cpp +++ b/tests/CVObjectDetection.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include "openshot_catch.h" #include "Clip.h" #include "CVObjectDetection.h" diff --git a/tests/CVStabilizer.cpp b/tests/CVStabilizer.cpp index 1c0d5990..401062d9 100644 --- a/tests/CVStabilizer.cpp +++ b/tests/CVStabilizer.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include "openshot_catch.h" #include "Clip.h" #include "CVStabilization.h" // for TransformParam, CamTrajectory, CVStabilization diff --git a/tests/CVTracker.cpp b/tests/CVTracker.cpp index e485d15f..95bcc6c8 100644 --- a/tests/CVTracker.cpp +++ b/tests/CVTracker.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include "openshot_catch.h" #include "Clip.h" #include "CVTracker.h" // for FrameData, CVTracker diff --git a/tests/CacheDisk.cpp b/tests/CacheDisk.cpp index b69c218f..6f18fb76 100644 --- a/tests/CacheDisk.cpp +++ b/tests/CacheDisk.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include "openshot_catch.h" #include "CacheDisk.h" #include "Frame.h" diff --git a/tests/CacheMemory.cpp b/tests/CacheMemory.cpp index dc6917b6..6338cac8 100644 --- a/tests/CacheMemory.cpp +++ b/tests/CacheMemory.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include "openshot_catch.h" #include "CacheMemory.h" #include "Frame.h" diff --git a/tests/ChromaKey.cpp b/tests/ChromaKey.cpp index 8aadde27..c478bcba 100644 --- a/tests/ChromaKey.cpp +++ b/tests/ChromaKey.cpp @@ -28,7 +28,7 @@ std::ostream& operator << ( std::ostream& os, QColor const& value ) { return os; } -#include +#include "openshot_catch.h" using namespace openshot; diff --git a/tests/Clip.cpp b/tests/Clip.cpp index 46b60d74..c0d47695 100644 --- a/tests/Clip.cpp +++ b/tests/Clip.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include "openshot_catch.h" #include #include diff --git a/tests/Color.cpp b/tests/Color.cpp index 5dc16d4f..032cc949 100644 --- a/tests/Color.cpp +++ b/tests/Color.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include "openshot_catch.h" #include diff --git a/tests/Coordinate.cpp b/tests/Coordinate.cpp index 68a20ab5..c043dcff 100644 --- a/tests/Coordinate.cpp +++ b/tests/Coordinate.cpp @@ -10,7 +10,7 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include +#include "openshot_catch.h" #include "Coordinate.h" #include "Exceptions.h" diff --git a/tests/Crop.cpp b/tests/Crop.cpp index 250b087a..5632be74 100644 --- a/tests/Crop.cpp +++ b/tests/Crop.cpp @@ -13,7 +13,7 @@ #include -#include +#include "openshot_catch.h" #include "Frame.h" #include "effects/Crop.h" diff --git a/tests/DummyReader.cpp b/tests/DummyReader.cpp index 7cc075b9..7d459392 100644 --- a/tests/DummyReader.cpp +++ b/tests/DummyReader.cpp @@ -12,7 +12,7 @@ #include -#include +#include "openshot_catch.h" #include "DummyReader.h" #include "Exceptions.h" diff --git a/tests/FFmpegReader.cpp b/tests/FFmpegReader.cpp index d46b7c79..c397fc0a 100644 --- a/tests/FFmpegReader.cpp +++ b/tests/FFmpegReader.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include "openshot_catch.h" #include "FFmpegReader.h" #include "Exceptions.h" diff --git a/tests/FFmpegWriter.cpp b/tests/FFmpegWriter.cpp index 40c0cc69..cce3c89d 100644 --- a/tests/FFmpegWriter.cpp +++ b/tests/FFmpegWriter.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include "openshot_catch.h" #include "FFmpegWriter.h" #include "Exceptions.h" diff --git a/tests/Fraction.cpp b/tests/Fraction.cpp index 4b466d2d..a730593c 100644 --- a/tests/Fraction.cpp +++ b/tests/Fraction.cpp @@ -10,7 +10,7 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include +#include "openshot_catch.h" #include #include diff --git a/tests/Frame.cpp b/tests/Frame.cpp index 5a54a668..ffe4d84d 100644 --- a/tests/Frame.cpp +++ b/tests/Frame.cpp @@ -24,7 +24,7 @@ #undef uint64 #endif -#include +#include "openshot_catch.h" #include "Clip.h" #include "Fraction.h" diff --git a/tests/FrameMapper.cpp b/tests/FrameMapper.cpp index 7cf0e88a..3571d384 100644 --- a/tests/FrameMapper.cpp +++ b/tests/FrameMapper.cpp @@ -10,7 +10,7 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include +#include "openshot_catch.h" #include "CacheMemory.h" #include "Clip.h" diff --git a/tests/ImageWriter.cpp b/tests/ImageWriter.cpp index 4056a9ab..5c7edc1e 100644 --- a/tests/ImageWriter.cpp +++ b/tests/ImageWriter.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include "openshot_catch.h" #include "ImageWriter.h" #include "Exceptions.h" diff --git a/tests/KeyFrame.cpp b/tests/KeyFrame.cpp index 1826befb..a09bdd92 100644 --- a/tests/KeyFrame.cpp +++ b/tests/KeyFrame.cpp @@ -10,7 +10,7 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include +#include "openshot_catch.h" #include #include diff --git a/tests/Point.cpp b/tests/Point.cpp index 1e57d153..bd54fecf 100644 --- a/tests/Point.cpp +++ b/tests/Point.cpp @@ -10,7 +10,7 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include +#include "openshot_catch.h" #include #include "Point.h" diff --git a/tests/QtImageReader.cpp b/tests/QtImageReader.cpp index a5189125..1db67e05 100644 --- a/tests/QtImageReader.cpp +++ b/tests/QtImageReader.cpp @@ -10,7 +10,7 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include +#include "openshot_catch.h" #include diff --git a/tests/ReaderBase.cpp b/tests/ReaderBase.cpp index 06fa77fa..506da944 100644 --- a/tests/ReaderBase.cpp +++ b/tests/ReaderBase.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include "openshot_catch.h" #include "ReaderBase.h" #include "CacheBase.h" diff --git a/tests/Settings.cpp b/tests/Settings.cpp index f55e005f..f4717b37 100644 --- a/tests/Settings.cpp +++ b/tests/Settings.cpp @@ -10,7 +10,7 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include +#include "openshot_catch.h" #include "Settings.h" diff --git a/tests/Timeline.cpp b/tests/Timeline.cpp index 1c545d6a..d2d9d458 100644 --- a/tests/Timeline.cpp +++ b/tests/Timeline.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include "openshot_catch.h" #include "Timeline.h" #include "Clip.h" From 190bd915be354e9d827c4d773f1bec9b4d243a20 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Fri, 17 Jun 2022 15:49:52 -0400 Subject: [PATCH 5/6] Catch2v3: Use catch_all header --- tests/catch2v3.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/catch2v3.h.in b/tests/catch2v3.h.in index 6e309c54..0bdf1066 100644 --- a/tests/catch2v3.h.in +++ b/tests/catch2v3.h.in @@ -14,6 +14,6 @@ #ifndef OPENSHOT_CATCH2_H #define OPENSHOT_CATCH2_H -#include +#include #endif From 6c5ffe1c1d84b98f3f20b669b09c16c91f794ca2 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Sat, 18 Jun 2022 04:45:50 -0400 Subject: [PATCH 6/6] HACK: 'using namespace Catch' in v3 header --- tests/catch2v3.h.in | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/catch2v3.h.in b/tests/catch2v3.h.in index 0bdf1066..2df0cb03 100644 --- a/tests/catch2v3.h.in +++ b/tests/catch2v3.h.in @@ -15,5 +15,6 @@ #define OPENSHOT_CATCH2_H #include +using namespace Catch; #endif