CMakeLists.txt 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. # Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
  2. # Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 2 or (at your option)
  7. # version 3 of the License.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. include_directories(
  17. ${CMAKE_CURRENT_SOURCE_DIR}
  18. ${CMAKE_CURRENT_BINARY_DIR}
  19. ${CMAKE_SOURCE_DIR}/src
  20. ${CMAKE_CURRENT_BINARY_DIR}/../src)
  21. add_definitions(-DQT_TEST_LIB)
  22. set(KEEPASSX_TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
  23. configure_file(config-keepassx-tests.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepassx-tests.h)
  24. macro(parse_arguments prefix arg_names option_names)
  25. set(DEFAULT_ARGS)
  26. foreach(arg_name ${arg_names})
  27. set(${prefix}_${arg_name})
  28. endforeach(arg_name)
  29. foreach(option ${option_names})
  30. set(${prefix}_${option} FALSE)
  31. endforeach(option)
  32. set(current_arg_name DEFAULT_ARGS)
  33. set(current_arg_list)
  34. foreach(arg ${ARGN})
  35. set(larg_names ${arg_names})
  36. list(FIND larg_names "${arg}" is_arg_name)
  37. if(is_arg_name GREATER -1)
  38. set(${prefix}_${current_arg_name} ${current_arg_list})
  39. set(current_arg_name ${arg})
  40. set(current_arg_list)
  41. else()
  42. set(loption_names ${option_names})
  43. list(FIND loption_names "${arg}" is_option)
  44. if(is_option GREATER -1)
  45. set(${prefix}_${arg} TRUE)
  46. else(is_option GREATER -1)
  47. set(current_arg_list ${current_arg_list} ${arg})
  48. endif()
  49. endif()
  50. endforeach(arg)
  51. set(${prefix}_${current_arg_name} ${current_arg_list})
  52. endmacro(parse_arguments)
  53. macro(add_unit_test)
  54. parse_arguments(TEST "NAME;SOURCES;LIBS;LAUNCHER" "" ${ARGN})
  55. set(_test_NAME ${TEST_NAME})
  56. set(_test_LAUNCHER ${TEST_LAUNCHER})
  57. set(_srcList ${TEST_SOURCES})
  58. add_executable(${_test_NAME} ${_srcList})
  59. target_link_libraries(${_test_NAME} ${TEST_LIBS})
  60. if(NOT TEST_OUTPUT)
  61. set(TEST_OUTPUT plaintext)
  62. endif(NOT TEST_OUTPUT)
  63. set(TEST_OUTPUT ${TEST_OUTPUT} CACHE STRING "The output to generate when running the QTest unit tests")
  64. if(KDE4_TEST_OUTPUT STREQUAL "xml")
  65. add_test(${_test_NAME} ${_test_LAUNCHER} ${_test_NAME} -xml -o ${_test_NAME}.tml)
  66. else(KDE4_TEST_OUTPUT STREQUAL "xml")
  67. add_test(${_test_NAME} ${_test_LAUNCHER} ${_test_NAME})
  68. endif(KDE4_TEST_OUTPUT STREQUAL "xml")
  69. if(NOT MSVC_IDE) #not needed for the ide
  70. # if the tests are EXCLUDE_FROM_ALL, add a target "buildtests" to build all tests
  71. if(NOT WITH_TESTS)
  72. get_directory_property(_buildtestsAdded BUILDTESTS_ADDED)
  73. if(NOT _buildtestsAdded)
  74. add_custom_target(buildtests)
  75. set_directory_properties(PROPERTIES BUILDTESTS_ADDED TRUE)
  76. endif()
  77. add_dependencies(buildtests ${_test_NAME})
  78. endif()
  79. endif()
  80. endmacro(add_unit_test)
  81. set(TEST_LIBRARIES keepassx_core Qt5::Test)
  82. set(testsupport_SOURCES
  83. modeltest.cpp
  84. FailDevice.cpp
  85. mock/MockClock.cpp
  86. util/TemporaryFile.cpp)
  87. add_library(testsupport STATIC ${testsupport_SOURCES})
  88. target_link_libraries(testsupport Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test)
  89. add_unit_test(NAME testgroup SOURCES TestGroup.cpp
  90. LIBS testsupport ${TEST_LIBRARIES})
  91. add_unit_test(NAME testkdbx2 SOURCES TestKdbx2.cpp
  92. LIBS ${TEST_LIBRARIES})
  93. add_unit_test(NAME testkdbx3 SOURCES TestKeePass2Format.cpp FailDevice.cpp mock/MockChallengeResponseKey.cpp TestKdbx3.cpp
  94. LIBS testsupport ${TEST_LIBRARIES})
  95. add_unit_test(NAME testkdbx4 SOURCES TestKeePass2Format.cpp FailDevice.cpp mock/MockChallengeResponseKey.cpp TestKdbx4.cpp
  96. LIBS testsupport ${TEST_LIBRARIES})
  97. add_unit_test(NAME testkeys SOURCES TestKeys.cpp mock/MockChallengeResponseKey.cpp
  98. LIBS ${TEST_LIBRARIES})
  99. add_unit_test(NAME testgroupmodel SOURCES TestGroupModel.cpp
  100. LIBS testsupport ${TEST_LIBRARIES})
  101. add_unit_test(NAME testentrymodel SOURCES TestEntryModel.cpp
  102. LIBS testsupport ${TEST_LIBRARIES})
  103. add_unit_test(NAME testcryptohash SOURCES TestCryptoHash.cpp
  104. LIBS ${TEST_LIBRARIES})
  105. add_unit_test(NAME testsymmetriccipher SOURCES TestSymmetricCipher.cpp
  106. LIBS ${TEST_LIBRARIES})
  107. if(WITH_XC_KEESHARE)
  108. add_unit_test(NAME testsignature SOURCES TestSignature.cpp
  109. LIBS ${TEST_LIBRARIES})
  110. endif()
  111. add_unit_test(NAME testhashedblockstream SOURCES TestHashedBlockStream.cpp
  112. LIBS testsupport ${TEST_LIBRARIES})
  113. add_unit_test(NAME testkeepass2randomstream SOURCES TestKeePass2RandomStream.cpp
  114. LIBS ${TEST_LIBRARIES})
  115. add_unit_test(NAME testmodified SOURCES TestModified.cpp
  116. LIBS testsupport ${TEST_LIBRARIES})
  117. add_unit_test(NAME testdeletedobjects SOURCES TestDeletedObjects.cpp
  118. LIBS ${TEST_LIBRARIES})
  119. add_unit_test(NAME testkeepass1reader SOURCES TestKeePass1Reader.cpp
  120. LIBS ${TEST_LIBRARIES})
  121. add_unit_test(NAME testopvaultreader SOURCES TestOpVaultReader.cpp
  122. LIBS ${TEST_LIBRARIES})
  123. if(WITH_XC_NETWORKING)
  124. add_unit_test(NAME testupdatecheck SOURCES TestUpdateCheck.cpp
  125. LIBS ${TEST_LIBRARIES})
  126. add_unit_test(NAME testicondownloader SOURCES TestIconDownloader.cpp LIBS ${TEST_LIBRARIES})
  127. endif()
  128. if(WITH_XC_AUTOTYPE)
  129. add_unit_test(NAME testautotype SOURCES TestAutoType.cpp
  130. LIBS ${TEST_LIBRARIES})
  131. set_target_properties(testautotype PROPERTIES ENABLE_EXPORTS ON)
  132. endif()
  133. if(WITH_XC_SSHAGENT)
  134. add_unit_test(NAME testopensshkey SOURCES TestOpenSSHKey.cpp
  135. LIBS sshagent ${TEST_LIBRARIES})
  136. if(NOT WIN32)
  137. add_unit_test(NAME testsshagent SOURCES TestSSHAgent.cpp
  138. LIBS ${TEST_LIBRARIES})
  139. endif()
  140. endif()
  141. add_unit_test(NAME testentry SOURCES TestEntry.cpp
  142. LIBS ${TEST_LIBRARIES})
  143. add_unit_test(NAME testmerge SOURCES TestMerge.cpp
  144. LIBS testsupport ${TEST_LIBRARIES})
  145. add_unit_test(NAME testpasswordgenerator SOURCES TestPasswordGenerator.cpp
  146. LIBS ${TEST_LIBRARIES})
  147. add_unit_test(NAME testpasswordhealth SOURCES TestPasswordHealth.cpp
  148. LIBS ${TEST_LIBRARIES})
  149. add_unit_test(NAME testpassphrasegenerator SOURCES TestPassphraseGenerator.cpp
  150. LIBS ${TEST_LIBRARIES})
  151. add_unit_test(NAME testhibp SOURCES TestHibp.cpp
  152. LIBS ${TEST_LIBRARIES})
  153. add_unit_test(NAME testtotp SOURCES TestTotp.cpp
  154. LIBS ${TEST_LIBRARIES})
  155. add_unit_test(NAME testbase32 SOURCES TestBase32.cpp
  156. LIBS ${TEST_LIBRARIES})
  157. add_unit_test(NAME testcsvparser SOURCES TestCsvParser.cpp
  158. LIBS ${TEST_LIBRARIES})
  159. add_unit_test(NAME testrandomgenerator SOURCES TestRandomGenerator.cpp
  160. LIBS testsupport ${TEST_LIBRARIES})
  161. add_unit_test(NAME testentrysearcher SOURCES TestEntrySearcher.cpp
  162. LIBS ${TEST_LIBRARIES})
  163. add_unit_test(NAME testcsvexporter SOURCES TestCsvExporter.cpp
  164. LIBS ${TEST_LIBRARIES})
  165. if(WITH_XC_YUBIKEY)
  166. add_unit_test(NAME testykchallengeresponsekey
  167. SOURCES TestYkChallengeResponseKey.cpp
  168. LIBS ${TEST_LIBRARIES})
  169. endif()
  170. if(WITH_XC_KEESHARE)
  171. add_unit_test(NAME testsharing SOURCES TestSharing.cpp
  172. LIBS testsupport ${TEST_LIBRARIES})
  173. endif()
  174. add_unit_test(NAME testdatabase SOURCES TestDatabase.cpp
  175. LIBS testsupport ${TEST_LIBRARIES})
  176. add_unit_test(NAME testtools SOURCES TestTools.cpp
  177. LIBS ${TEST_LIBRARIES})
  178. add_unit_test(NAME testconfig SOURCES TestConfig.cpp
  179. LIBS testsupport ${TEST_LIBRARIES})
  180. if(WITH_XC_FDOSECRETS)
  181. add_unit_test(NAME testfdosecrets SOURCES TestFdoSecrets.cpp
  182. LIBS testsupport ${TEST_LIBRARIES})
  183. endif()
  184. if(WITH_XC_BROWSER)
  185. add_unit_test(NAME testbrowser SOURCES TestBrowser.cpp
  186. LIBS ${TEST_LIBRARIES})
  187. endif()
  188. if(WITH_GUI_TESTS)
  189. # CLI clip tests need X environment on Linux
  190. add_unit_test(NAME testcli SOURCES TestCli.cpp
  191. LIBS testsupport cli ${TEST_LIBRARIES})
  192. add_subdirectory(gui)
  193. endif(WITH_GUI_TESTS)