diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e970c9544fcdf995648b40b010005a814311f8f..b8ce061d0341999447a9cd5fcbf70ec23b11b60a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,13 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # "${CONAN_PKG_LIBS}") +find_package(linkahead CONFIG REQUIRED) +find_package(GTest CONFIG REQUIRED) +find_package(gRPC CONFIG REQUIRED) +find_package(protobuf CONFIG REQUIRED) + + + set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) enable_testing() add_subdirectory(test) diff --git a/README.md b/README.md index 510518c88a4dcb99280f6fea260229ba6ba8e3b6..9b58caa1d3e42fd92be1a4cea4535c8fae88f584 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,29 @@ or manually via path to the pem file in the `CAOSDB_SERVER_CERT` environment variable. 7. Run with `ctest` in the build directory. +### Windows ### + +On windows, you still need to build and create a conan package from +linkahead-cpplib using conan-create or the make.ps1 script in the +cpplib repo. + +This repo also provides a make script `make.ps1` to run the +integration tests on Windows. You need to create a python virtual +environment and install the requirements from linkahead cpplib or +recycle the one you used to create the package there: + +```sh +python -m venv .venv # Choose any path you like for your venv +.venv/Scripts/Actvate.ps1 +pip install ../linkahead-cpplib/requirements.txt # You may need to change the pass to cpplib here +``` + +Then build and run the tests with + +```sh +make.ps1 all +``` + ### Troubleshooting ### - If you don't have `clang-tidy` installed, you can run the first `cmake` command with diff --git a/make.ps1 b/make.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..ad8e12f33ba20d005da07c57005cf47d3294ac1b --- /dev/null +++ b/make.ps1 @@ -0,0 +1,89 @@ +param ( + [string]$target +) + +$buildType = "Release" +$cppStd=17 + +function Install-Conan { + Write-Output "Installing Release dependencies with Conan..." + # check if conan is available + if (-not (Get-Command conan -ErrorAction SilentlyContinue)) { + Write-Output "Conan is not available. Please install Conan or activate the Conan environment venv" + exit 1 + } + conan install . --build=missing -s build_type=$buildType -s compiler.cppstd=$cppStd + cmake --preset conan-default +} + +function Invoke-Build { + Write-Output "Building the project..." + # check if msbuild is available + if (-not (Get-Command msbuild -ErrorAction SilentlyContinue)) { + Write-Output "msbuild is not available. Please install Visual Studio or open the Developer PowerShell." + exit 1 + } + # check if conan install was run + if (-not (Test-Path .\build\liblinkahead_inttests.sln)) { + Write-Output "Please run conan-install first." + exit 1 + } + msbuild .\build\liblinkahead_inttests.sln /property:Configuration=$buildType +} + +function Invoke-Tests { + Write-Output "Running tests..." + + Set-Location .\build\ + ctest + Set-Location ..\ +} + +function Invoke-Create { + Write-Output "Creating Conan package..." + conan create . +} + +# check if vswhere is available +if (-not (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe")) { + Write-Output "vswhere is not available. Please install Visual Studio" + exit 1 +} + +# locate the latest Visual Studio installation +$currentPath = Get-Location +$installPath = &"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath +Import-Module (Join-Path $installPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") +Enter-VsDevShell -VsInstallPath $installPath +Set-Location $currentPath + + +# Windows is with Release only for now + +switch ($target) { + "build" { + Invoke-Build + } + "test" { + Invoke-Tests + } + "conan-install" { + Install-Conan + } + "conan-create" { + Invoke-Create + } + "clean"{ + Write-Output "Cleaning the project..." + Remove-Item -Recurse -Force .\build\* + } + "all" { + Install-Conan + Invoke-Build + Invoke-Tests + Invoke-Create + } + default { + Write-Output "Usage: .\make.ps1 [all|conan-install|build|test|clean]" + } +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9fcfff044d98b4b5129aa2db057e6caa4f8f809a..f655e74dbade34de923c10bdc38b4693b336c425 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,6 +35,9 @@ set(test_cases add_compile_definitions(BUILD_ACM) +# copy DLLs from linkahead_LIB_DIRS_RELEASE to the binary directory +file(COPY ${linkahead_LIB_DIRS_RELEASE}/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + include(CheckCXXCompilerFlag) include(CheckCCompilerFlag) @@ -99,14 +102,10 @@ endif() ### Set up tests using GoogleTest (GTest) ################################################### + # add special cmake functions for gtest include(GoogleTest REQUIRED) -find_package(linkahead) -find_package(GTest) -find_package(gRPC) -find_package(protobuf) - # loop over all test cases and add them to the test runner list(LENGTH test_cases len_test_cases) math(EXPR len_test_cases "${len_test_cases} - 1") @@ -114,10 +113,13 @@ foreach (i RANGE "${len_test_cases}") list(GET test_cases ${i} test_case_name) add_executable(${test_case_name} ${test_case_name}.cpp) target_link_libraries(${test_case_name} PRIVATE - linkahead::linkahead gtest::gtest grpc::grpc protobuf::protobuf + linkahead::linkahead linkahead clinkahead caosdb_grpc + gtest::gtest grpc::grpc protobuf::protobuf ) target_include_directories(${test_case_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + set_target_properties(${test_case_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + if(LINTING) set_target_properties(${test_case_name} PROPERTIES @@ -125,6 +127,6 @@ foreach (i RANGE "${len_test_cases}") CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") endif() gtest_discover_tests(${test_case_name} - PROPERTIES + PROPERTIES LABELS "linkahead-cpplib-int-tests") endforeach () diff --git a/test/test_clinkahead.cpp b/test/test_clinkahead.cpp index 9466d03686cf13fab6ed3e78d83bc0f75d1ca770..164b89df2e2153f1de85569d5b8d6fcd458be877 100644 --- a/test/test_clinkahead.cpp +++ b/test/test_clinkahead.cpp @@ -591,7 +591,7 @@ TEST_F(test_clinkahead, test_up_n_download_file) { linkahead_entity_entity original_entity; linkahead_entity_create_entity(&original_entity); linkahead_entity_entity_set_role(&original_entity, "FILE"); - linkahead_entity_entity_set_local_path(&original_entity, test_upload_file_1.c_str()); + linkahead_entity_entity_set_local_path(&original_entity, test_upload_file_1.string().c_str()); linkahead_entity_entity_set_file_path(&original_entity, "/some/file"); linkahead_transaction_transaction insert_transaction; @@ -619,7 +619,7 @@ TEST_F(test_clinkahead, test_up_n_download_file) { // return_code = linkahead_transaction_transaction_retrieve_by_id( // &retrieve_transaction_1, rec_id); return_code = linkahead_transaction_transaction_retrieve_and_download_file_by_id( - &retrieve_transaction_1, rec_id, test_download_file_1.c_str()); + &retrieve_transaction_1, rec_id, test_download_file_1.string().c_str()); EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); return_code = linkahead_transaction_transaction_execute(&retrieve_transaction_1); EXPECT_EQ(return_code, 0); @@ -628,4 +628,7 @@ TEST_F(test_clinkahead, test_up_n_download_file) { return_code = linkahead_transaction_transaction_get_result_set(&retrieve_transaction_1, &result_set); EXPECT_EQ(return_code, 0); + + return_code = linkahead_transaction_delete_transaction(&retrieve_transaction_1); + EXPECT_EQ(return_code, 0); }