CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
  2. include(GoogleTest)
  3. endif()
  4. set(googleTest_Dir ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
  5. if(EXISTS ${googleTest_Dir})
  6. set(GTestSrc ${googleTest_Dir}/googletest)
  7. set(GMockSrc ${googleTest_Dir}/googlemock)
  8. else()
  9. message(FATAL_ERROR "No googletest src dir found!")
  10. endif()
  11. set(test_SRCS
  12. StdInc.cpp
  13. main.cpp
  14. CMemoryBufferTest.cpp
  15. CVcmiTestConfig.cpp
  16. JsonComparer.cpp
  17. battle/BattleHexTest.cpp
  18. battle/CBattleInfoCallbackTest.cpp
  19. battle/CHealthTest.cpp
  20. battle/CUnitStateTest.cpp
  21. battle/CUnitStateMagicTest.cpp
  22. battle/battle_UnitTest.cpp
  23. game/CGameStateTest.cpp
  24. map/CMapEditManagerTest.cpp
  25. map/CMapFormatTest.cpp
  26. map/MapComparer.cpp
  27. spells/AbilityCasterTest.cpp
  28. spells/TargetConditionTest.cpp
  29. spells/effects/EffectFixture.cpp
  30. spells/effects/CatapultTest.cpp
  31. spells/effects/CloneTest.cpp
  32. spells/effects/DamageTest.cpp
  33. spells/effects/DispelTest.cpp
  34. spells/effects/HealTest.cpp
  35. spells/effects/SacrificeTest.cpp
  36. spells/effects/SummonTest.cpp
  37. spells/effects/TeleportTest.cpp
  38. spells/effects/TimedTest.cpp
  39. spells/targetConditions/AbsoluteSpellConditionTest.cpp
  40. spells/targetConditions/AbsoluteLevelConditionTest.cpp
  41. spells/targetConditions/BonusConditionTest.cpp
  42. spells/targetConditions/CreatureConditionTest.cpp
  43. spells/targetConditions/ElementalConditionTest.cpp
  44. spells/targetConditions/HealthValueConditionTest.cpp
  45. spells/targetConditions/ImmunityNegationConditionTest.cpp
  46. spells/targetConditions/NormalLevelConditionTest.cpp
  47. spells/targetConditions/NormalSpellConditionTest.cpp
  48. spells/targetConditions/ReceptiveFeatureConditionTest.cpp
  49. spells/targetConditions/SpellEffectConditionTest.cpp
  50. spells/targetConditions/TargetConditionItemFixture.cpp
  51. vcai/mock_ResourceManager.cpp
  52. vcai/mock_VCAI.cpp
  53. vcai/ResurceManagerTest.cpp
  54. mock/mock_IGameCallback.cpp
  55. mock/mock_MapService.cpp
  56. mock/mock_BonusBearer.cpp
  57. mock/mock_CPSICallback.cpp
  58. )
  59. set(test_HEADERS
  60. StdInc.h
  61. CVcmiTestConfig.h
  62. JsonComparer.h
  63. map/MapComparer.h
  64. spells/effects/EffectFixture.h
  65. spells/targetConditions/TargetConditionItemFixture.h
  66. vcai/ResourceManagerTest.h
  67. mock/mock_BonusBearer.h
  68. mock/mock_IGameCallback.h
  69. mock/mock_MapService.h
  70. mock/mock_BonusBearer.h
  71. )
  72. assign_source_group(${test_SRCS} ${test_HEADERS})
  73. set(mock_HEADERS
  74. mock/mock_battle_IBattleState.h
  75. mock/mock_battle_Unit.h
  76. mock/mock_UnitInfo.h
  77. mock/mock_UnitEnvironment.h
  78. mock/mock_spells_Mechanics.h
  79. mock/mock_spells_Problem.h
  80. mock/mock_spells_Spell.h
  81. mock/mock_vstd_RNG.h
  82. mock/mock_CPSICallback.h
  83. vcai/mock_ResourceManager.h
  84. vcai/mock_VCAI.h
  85. vcai/mock_VCAI_CGoal.h
  86. )
  87. add_subdirectory_with_folder("3rdparty" googletest EXCLUDE_FROM_ALL)
  88. add_executable(vcmitest ${test_SRCS} ${test_HEADERS} ${mock_HEADERS} ${GTestSrc}/src/gtest-all.cc ${GMockSrc}/src/gmock-all.cc)
  89. target_link_libraries(vcmitest vcmi ${RT_LIB} ${DL_LIB})
  90. target_include_directories(
  91. PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
  92. PRIVATE ${GTestSrc}
  93. PRIVATE ${GTestSrc}/include
  94. PRIVATE ${GMockSrc}
  95. PRIVATE ${GMockSrc}/include
  96. )
  97. if(FALSE AND NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
  98. # Running tests one by one using ctest not recommended due to vcmi having
  99. # slow global initialization.
  100. gtest_discover_tests(vcmitest
  101. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
  102. else()
  103. add_test(NAME tests
  104. COMMAND vcmitest
  105. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
  106. endif()
  107. vcmi_set_output_dir(vcmitest "")
  108. set_target_properties(vcmitest PROPERTIES ${PCH_PROPERTIES})
  109. cotire(vcmitest)
  110. file (GLOB_RECURSE testdata "testdata/*.*")
  111. foreach(resource ${testdata})
  112. get_filename_component(filename ${resource} NAME)
  113. get_filename_component(dir ${resource} DIRECTORY)
  114. get_filename_component(dirname ${dir} NAME)
  115. set (output "")
  116. while(NOT ${dirname} STREQUAL testdata)
  117. get_filename_component(path_component ${dir} NAME)
  118. set (output "${path_component}/${output}")
  119. get_filename_component(dir ${dir} DIRECTORY)
  120. get_filename_component(dirname ${dir} NAME)
  121. endwhile()
  122. set(output "${CMAKE_BINARY_DIR}/bin/test/testdata/${output}/${filename}")
  123. configure_file(${resource} ${output} COPYONLY)
  124. endforeach()