From cc7ff4122d75b6cd23270039e5b751fbe09331a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Thu, 23 Nov 2017 22:44:09 +0100 Subject: [PATCH] Export all symbols when running unit tests. Add dummy test for private code. I tried to use directly the private OBJECT library (exiv2lib_int) in the unit_tests targets, but the private objects have dependencies on the public symbols (circular dependency) and therefore it is impossible to test the private code with that approach with the current design of the library. Starting from CMake 3.3 we can use the variable CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS to export all the symbols of a shared library: https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/ Even having the opportunity to use this variable (that will be only used when EXIV2_BUILD_UNIT_TESTS is enabled) the previous commits are still valid. It is interesting to clearly differentiate between the public and private code of the library. Enforcing this, make us think twice before putting code in the public part of the library. --- CMakeLists.txt | 4 ++++ unitTests/CMakeLists.txt | 6 ++++-- unitTests/test_tiffheader.cpp | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 unitTests/test_tiffheader.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 87a167ce..96426850 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,10 @@ if( EXIV2_ENABLE_COMMERCIAL ) set (EXIV2_ENABLE_NLS OFF) endif() +if( EXIV2_BUILD_UNIT_TESTS ) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # Requires CMake 3.3.3 +endif() + include(config/findDependencies.cmake) include(config/compilerFlags.cmake) include( config/generateConfigFile.cmake ) diff --git a/unitTests/CMakeLists.txt b/unitTests/CMakeLists.txt index 2f141d2e..735543ed 100644 --- a/unitTests/CMakeLists.txt +++ b/unitTests/CMakeLists.txt @@ -1,10 +1,11 @@ add_executable(unit_tests mainTestRunner.cpp - test_types.cpp gtestwrapper.h + test_types.cpp + test_tiffheader.cpp ) #TODO Use GTest::GTest once we upgrade the minimum CMake version required -target_link_libraries(unit_tests +target_link_libraries(unit_tests PRIVATE exiv2lib ${GTEST_BOTH_LIBRARIES} @@ -13,6 +14,7 @@ target_link_libraries(unit_tests target_include_directories(unit_tests PRIVATE ${GTEST_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/src ) target_compile_definitions(unit_tests diff --git a/unitTests/test_tiffheader.cpp b/unitTests/test_tiffheader.cpp new file mode 100644 index 00000000..8afa721e --- /dev/null +++ b/unitTests/test_tiffheader.cpp @@ -0,0 +1,22 @@ +#include + +#include "gtestwrapper.h" +#include + +using namespace Exiv2; + +static const byte tiffLittleEndian[] = {0x49, 0x49, 0x2a, 0x00, 0x10, 0x00, 0x00, 0x00}; + +class ATiffHeader: public ::testing::Test +{ +public: + Internal::TiffHeader header; +}; + +TEST_F(ATiffHeader, hasExpectedValuesAfterCreation) +{ + ASSERT_EQ(8u, header.size()); + ASSERT_EQ(42, header.tag()); + ASSERT_EQ(8u, header.offset()); + ASSERT_EQ(littleEndian, header.byteOrder()); +}