From fcd744d6c9a586d6a0b1c161a06dbe19762d9d94 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 6 Feb 2023 19:27:15 -0800 Subject: [PATCH] meson: add unit tests Signed-off-by: Rosen Penev --- .github/workflows/on_PR_meson.yaml | 3 ++ .github/workflows/on_PR_meson_clang.yaml | 1 + meson.build | 2 + meson_options.txt | 4 ++ subprojects/gtest.wrap | 15 +++++++ unitTests/meson.build | 55 ++++++++++++++++++++++++ 6 files changed, 80 insertions(+) create mode 100644 subprojects/gtest.wrap create mode 100644 unitTests/meson.build diff --git a/.github/workflows/on_PR_meson.yaml b/.github/workflows/on_PR_meson.yaml index 73e91bcdc0..071a8fa350 100644 --- a/.github/workflows/on_PR_meson.yaml +++ b/.github/workflows/on_PR_meson.yaml @@ -27,6 +27,7 @@ jobs: run: | env CXX=g++-${{matrix.cxx}} meson setup "${{github.workspace}}/build" --wrap-mode=${{matrix.deps}} -Ddefault_library=${{matrix.type}} meson compile -C "${{github.workspace}}/build" --verbose + #meson test -C "${{github.workspace}}/build" --verboise #fails for some reason VisualStudio: runs-on: windows-latest @@ -47,6 +48,7 @@ jobs: run: | meson setup "${{github.workspace}}/build" --wrap-mode=${{matrix.deps}} -Ddefault_library=${{matrix.type}} meson compile -C "${{github.workspace}}/build" --verbose + meson test -C "${{github.workspace}}/build" --verbose MacOS: runs-on: macos-latest @@ -66,3 +68,4 @@ jobs: run: | meson setup "${{github.workspace}}/build" --wrap-mode=${{matrix.deps}} -Ddefault_library=${{matrix.type}} meson compile -C "${{github.workspace}}/build" --verbose + meson test -C "${{github.workspace}}/build" --verbose diff --git a/.github/workflows/on_PR_meson_clang.yaml b/.github/workflows/on_PR_meson_clang.yaml index 4a13bbe9dc..0ef89df847 100644 --- a/.github/workflows/on_PR_meson_clang.yaml +++ b/.github/workflows/on_PR_meson_clang.yaml @@ -27,3 +27,4 @@ jobs: run: | env CXX=clang++-${{matrix.cxx}} CXXFLAGS=-stdlib=libc++ meson setup "${{github.workspace}}/build" --wrap-mode=${{matrix.deps}} -Ddefault_library=${{matrix.type}} meson compile -C "${{github.workspace}}/build" --verbose + #meson test -C "${{github.workspace}}/build" --verbose diff --git a/meson.build b/meson.build index d6ff0e62ac..050acd473c 100644 --- a/meson.build +++ b/meson.build @@ -339,3 +339,5 @@ executable( dependencies: exiv2_dep, install: true, ) + +subdir('unitTests') diff --git a/meson_options.txt b/meson_options.txt index dd8e7d84c0..f80430a706 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -40,3 +40,7 @@ option('video', type : 'boolean', option('xmp', type : 'feature', description : 'Build support for XMP', ) + +option('unitTests', type : 'feature', + description : 'Build and run unit tests', +) diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap new file mode 100644 index 0000000000..195aaca89a --- /dev/null +++ b/subprojects/gtest.wrap @@ -0,0 +1,15 @@ +[wrap-file] +directory = googletest-1.13.0 +source_url = https://github.com/google/googletest/archive/refs/tags/v1.13.0.tar.gz +source_filename = gtest-1.13.0.tar.gz +source_hash = ad7fdba11ea011c1d925b3289cf4af2c66a352e18d4c7264392fead75e919363 +patch_filename = gtest_1.13.0-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.13.0-1/get_patch +patch_hash = 6d82a02c3a45071cea989983bf6becde801cbbfd29196ba30dada0215393b082 +wrapdb_version = 1.13.0-1 + +[provide] +gtest = gtest_dep +gtest_main = gtest_main_dep +gmock = gmock_dep +gmock_main = gmock_main_dep diff --git a/unitTests/meson.build b/unitTests/meson.build new file mode 100644 index 0000000000..a3e1a72654 --- /dev/null +++ b/unitTests/meson.build @@ -0,0 +1,55 @@ +gtest_dep = dependency('gmock_main', required: get_option('unitTests')) +if not gtest_dep.found() + subdir_done() +endif + +test_sources = files( + 'test_DateValue.cpp', + 'test_Error.cpp', + 'test_FileIo.cpp', + 'test_ImageFactory.cpp', + 'test_LangAltValueRead.cpp', + 'test_Photoshop.cpp', + 'test_TimeValue.cpp', + 'test_XmpKey.cpp', + 'test_basicio.cpp', + 'test_bmpimage.cpp', + 'test_cr2header_int.cpp', + 'test_enforce.cpp', + 'test_futils.cpp', + 'test_helper_functions.cpp', + 'test_image_int.cpp', + 'test_jp2image.cpp', + 'test_jp2image_int.cpp', + 'test_pngimage.cpp', + 'test_safe_op.cpp', + 'test_slice.cpp', + 'test_tiffheader.cpp', + 'test_types.cpp', + 'test_utils.cpp', + #'test_datasets.cpp', + #'test_IptcKey.cpp', +) + +test_sources += int_lib + +if get_option('video') + test_sources += files( + 'test_asfvideo.cpp', + 'test_matroskavideo.cpp', + 'test_riffVideo.cpp', + ) +endif + +t_args = ['-UEXIV2API', '-DEXIV2API=', '-DTESTDATA_PATH="@0@"'.format('..' / 'test' / 'data')] + +privinc = include_directories('../src', '../include/exiv2') +unit_tests = executable( + 'unit_tests', + test_sources, + cpp_args: t_args, + dependencies: [deps, exiv2_dep, gtest_dep], + include_directories: privinc, +) + +test('Unit Tests', unit_tests)