summaryrefslogtreecommitdiffstats
path: root/tests/CMakeLists.txt
blob: fd8bc80a69cd98dd97c0c625383e2e3f5d39cd9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# QTest based tests
qt5_add_resources(SUBSURFACE_TEST_RESOURCES ../subsurface.qrc)

# Access test data (dive folder) from SUBSURFACE_SOURCE by default.
# In cross compilation cases or when test will not be executed at build time
# a differnt value can be set via cmake -DSUBSURFACE_TEST_DATA.
if(NOT SUBSURFACE_TEST_DATA)
	if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
		# For windows case we expect tests to be executed
		# with WORKING_DIRECTORY pointing to folder where test data can be found
		set(SUBSURFACE_TEST_DATA .)
	else()
		set(SUBSURFACE_TEST_DATA ${SUBSURFACE_SOURCE})
	endif()
endif()

add_library(RESOURCE_LIBRARY STATIC ${SUBSURFACE_TEST_RESOURCES})

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")

	# Prepare a staging_tests folder
	# Test can run accessing data and dependecies for build time testing
	# or can be deployed for target testing
	# It inludes:
	#  - test data
	#  - test binaries (see TEST macro)
	#  - test binaries dependencies (see TEST macro)
	set(WINDOWS_STAGING_TESTS ${CMAKE_BINARY_DIR}/staging_tests)
	install(DIRECTORY ${SUBSURFACE_SOURCE}/dives DESTINATION ${WINDOWS_STAGING_TESTS})

	# Check if we can run tests locally using wine
	# Add a fake test used to ensure data is deployed to WINDOWS_STAGING_TESTS before running
	find_program(WINE_PROGRAM wine)
	if(WINE_PROGRAM)
		add_test(
			NAME InstallTestsDataAndDependencies
			COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_CURRENT_BINARY_DIR} --target install
			)
	endif()
endif()

# Helper function TEST used to created rules to build, link, install and run tests
function(TEST NAME FILE)
	get_filename_component(HDR "${FILE}" NAME_WE)
	add_executable(${NAME} ${FILE} ${HDR}.h)
	target_link_libraries(
		${NAME}
		subsurface_corelib
		RESOURCE_LIBRARY
		${QT_TEST_LIBRARIES}
		${SUBSURFACE_LINK_LIBRARIES}
		)

	if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
		# Re-install dependencies in WINDOWS_STAGING_TESTS (and not in WINDOWSSTAGING)
		# to avoid packing testing related dlls in the installer
		install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DSUBSURFACE_TARGET=${NAME} -DSUBSURFACE_SOURCE=${SUBSURFACE_SOURCE} -DSTAGING=${WINDOWS_STAGING_TESTS} -P ${CMAKE_SOURCE_DIR}/cmake/Modules/dlllist.cmake WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")

		# Run test using wine
		if(WINE_PROGRAM)
			add_test(
				NAME ${NAME}
				COMMAND "$<TARGET_FILE:${NAME}>"
				WORKING_DIRECTORY ${WINDOWS_STAGING_TESTS}
				)
			# Set WINEPATH (%PATH%) to WINDOWS_STAGING_TESTS allowing wine to find dlls
			# WINEDEBUG=-all is used to avoid anoying winde debug outputs
			set_tests_properties(${NAME} PROPERTIES ENVIRONMENT "WINEPATH=${WINDOWS_STAGING_TESTS};WINEDEBUG=-all")
			set_tests_properties(${NAME} PROPERTIES DEPENDS PrepareTests)
		endif()
	else()
		add_test(NAME ${NAME} COMMAND  $<TARGET_FILE:${NAME}>)
	endif()
endfunction()

add_definitions(-g)
add_definitions(-DSUBSURFACE_TEST_DATA="${SUBSURFACE_TEST_DATA}")

# Build QML test runner
# add_executable demands relative path, therefore ../ 
add_executable(TestQML testqml.cpp ../subsurface-helper.cpp )
target_link_libraries(
	TestQML
	subsurface_corelib
	RESOURCE_LIBRARY
	${QT_TEST_LIBRARIES}
	${SUBSURFACE_LINK_LIBRARIES}
)

# SSRF test cases (TBD, convert to standard qTest setup)
TEST(TestUnitConversion testunitconversion.cpp)
TEST(TestProfile testprofile.cpp)
TEST(TestGpsCoords testgpscoords.cpp)
TEST(TestParse testparse.cpp)
TEST(TestAirPressure testAirPressure.cpp)
if (BTSUPPORT)
	TEST(TestHelper testhelper.cpp)
endif()
TEST(TestParsePerformance testparseperformance.cpp)
TEST(TestPlan testplan.cpp)
TEST(TestDiveSiteDuplication testdivesiteduplication.cpp)
TEST(TestRenumber testrenumber.cpp)
TEST(TestGitStorage testgitstorage.cpp)
TEST(TestPicture testpicture.cpp)
TEST(TestMerge testmerge.cpp)
TEST(TestTagList testtaglist.cpp)

TEST(TestQPrefCloudStorage testqPrefCloudStorage.cpp)
TEST(TestQPrefDisplay testqPrefDisplay.cpp)
TEST(TestQPrefDiveComputer testqPrefDiveComputer.cpp)
TEST(TestQPrefDivePlanner testqPrefDivePlanner.cpp)
TEST(TestQPrefGeneral testqPrefGeneral.cpp)
TEST(TestQPrefEquipment testqPrefEquipment.cpp)
TEST(TestQPrefMedia testqPrefMedia.cpp)
TEST(TestQPrefGeocoding testqPrefGeocoding.cpp)
TEST(TestQPrefLanguage testqPrefLanguage.cpp)
TEST(TestQPrefLocationService testqPrefLocationService.cpp)
TEST(TestQPrefPartialPressureGas testqPrefPartialPressureGas.cpp)
TEST(TestQPrefProxy testqPrefProxy.cpp)
TEST(TestQPrefTechnicalDetails testqPrefTechnicalDetails.cpp)
TEST(TestQPrefUnits testqPrefUnits.cpp)
TEST(TestQPrefUpdateManager testqPrefUpdateManager.cpp)
add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> -input ${SUBSURFACE_SOURCE}/tests)


add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
	DEPENDS
	TestUnitConversion
	TestProfile
	TestGpsCoords
	TestParse
	TestGitStorage
	TestPlan
	TestAirPressure
	TestDiveSiteDuplication
	TestRenumber
	TestPicture
	TestMerge
	TestTagList

	TestQPrefCloudStorage
	TestQPrefDisplay
	TestQPrefDiveComputer
	TestQPrefDivePlanner
	TestQPrefGeneral
	TestQPrefEquipment
	TestQPrefMedia
	TestQPrefGeocoding
	TestQPrefLanguage
	TestQPrefLocationService
	TestQPrefPartialPressureGas
	TestQPrefProxy
	TestQPrefTechnicalDetails
	TestQPrefUnits
	TestQPrefUpdateManager
	TestQML
)

# useful for debugging CMake issues
# print_all_variables()