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.
This commit is contained in:
parent
8c010c903b
commit
cc7ff4122d
@ -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 )
|
||||
|
||||
@ -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
|
||||
|
||||
22
unitTests/test_tiffheader.cpp
Normal file
22
unitTests/test_tiffheader.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <tiffimage_int.hpp>
|
||||
|
||||
#include "gtestwrapper.h"
|
||||
#include <sstream>
|
||||
|
||||
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());
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user