diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9e4b424b096beac09b2c130ab0fe041f56196d8b..3bea0c5f3a4bf2371811b6fc8c50f0e3f4ca83fd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -86,14 +86,17 @@ test: tags: [ docker ] stage: test script: - - mkdir build - - cd build - - VERSION="$(conan inspect --raw version ..)" - - conan install -s "compiler.libcxx=libstdc++11" --build=missing -o build_acm=True .. "caosdb/$VERSION@_/_" - - cmake -DCMAKE_BUILD_TYPE=Debug .. - - cmake --build . -j - - cmake --build . -j --target unit_test_coverage - - cmake --build . -j --target cxxcaosdbcli + - conan profile detect + - make test + # - mkdir build + # - cd build + # - VERSION="$(conan inspect --raw version ..)" + # - conan install -s "compiler.libcxx=libstdc++11" --build=missing -o build_acm=True . #.. "caosdb/$VERSION@_/_" + # - conan build -s "compiler.libcxx=libstdc++11" . --s build_type=Debug + # - cd build/Debug + # - cmake --build . -j + # - cmake --build . -j --target unit_test_coverage + # - cmake --build . -j --target cxxcaosdbcli # - cmake --build . -j --target ccaosdbcli # Disabled until it compiles again. trigger_prepare: @@ -223,8 +226,9 @@ trigger_julialib: tags: [ cached-dind ] stage: deploy script: + - conan profile detect - make doc - - cp -r build/doc/sphinx_out ./public + - cp -r build/Release/doc/sphinx_out ./public test_pages: <<: *pages_prepare diff --git a/CMakeLists.txt b/CMakeLists.txt index 710a1302d0bbf5e45f89920f28d2cf7f8f9dec36..eb566f0d90c7e6d3819b5130356117a5815d56cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,20 +55,19 @@ ENDIF() ### DEPENDENCY MANAGEMENT with CONAN ########################################### message(STATUS "Build directory ${CMAKE_BINARY_DIR}") -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() -# fix grpc - remove unsecure (no-op ssl implementations) -string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_LIBS_GRPC - "${CONAN_LIBS_GRPC}") -string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS_GRPC - "${CONAN_PKG_LIBS_GRPC}") -string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_LIBS - "${CONAN_LIBS}") -string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS - "${CONAN_PKG_LIBS}") +# TODO: Is this still necessary? +# # fix grpc - remove unsecure (no-op ssl implementations) +# string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_LIBS_GRPC +# "${CONAN_LIBS_GRPC}") +# string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS_GRPC +# "${CONAN_PKG_LIBS_GRPC}") +# string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_LIBS +# "${CONAN_LIBS}") +# string(REGEX REPLACE "grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS +# "${CONAN_PKG_LIBS}") -message(STATUS "CONAN_LIBS: ${CONAN_LIBS}") +# message(STATUS "CONAN_LIBS: ${CONAN_LIBS}") ########################################### ### GENERAL SETUP of SOURCES @@ -82,6 +81,8 @@ add_subdirectory(doc) ### CODE GENERATION (WITH GRPC) #################################################################### +# TODO: Replace this with the protobuf_generate_cpp function + # Protobuf/Grpc source files set(PROTO_FILES ${PROJECT_SOURCE_DIR}/proto/proto/caosdb/info/v1/main.proto @@ -147,6 +148,9 @@ add_custom_command( ${PROTO_FILES} DEPENDS ${PROTO_FILES}) +# show generated files +message(DEBUG "GRPC_GENERATED: ${GRPC_GENERATED}") + ############################################################################### ### Set up main targets ### * [caosdb_grpc] - only in Debug builds. Otherwise this library is compiled @@ -157,37 +161,50 @@ add_custom_command( ### * ccaosdbcli - A plain C test client. ############################################################################### +find_package(gRPC CONFIG REQUIRED) +find_package(Protobuf CONFIG REQUIRED) +find_package(Boost REQUIRED) +find_package(GTest REQUIRED) + +# print include directories for debugging +message(DEBUG "CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}") +message(DEBUG "PROTOBUF_INCLUDE_DIRS: ${PROTOBUF_INCLUDE_DIRS}") +message(DEBUG "gRPC_INCLUDE_DIRS: ${gRPC_INCLUDE_DIRS}") + + +# libcaosdb +# --------- + +# In Debug, build separate libraries for grpc-generated code and caosdb if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") - add_library(caosdb_grpc SHARED ${GRPC_GENERATED}) - add_library(caosdb SHARED ${libcaosdb_INCL} ${libcaosdb_SRC}) - target_link_libraries(caosdb caosdb_grpc) - set(LIBCAOSDB caosdb caosdb_grpc) + add_library(caosdb_grpc SHARED ${GRPC_GENERATED}) + target_link_libraries(caosdb_grpc + grpc::grpc protobuf::protobuf boost::boost + ) target_include_directories(caosdb_grpc PUBLIC - $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> - $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> - + $<BUILD_INTERFACE:${PROJECT_INCLUDE_DIR}> + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> ) - target_include_directories(caosdb_grpc SYSTEM PUBLIC - ${CONAN_INCLUDE_DIRS} + + add_library(caosdb SHARED ${libcaosdb_INCL} ${libcaosdb_SRC}) + + target_link_libraries(caosdb + caosdb_grpc grpc::grpc protobuf::protobuf boost::boost ) + + set(LIBCAOSDB caosdb caosdb_grpc) else() add_library(caosdb SHARED ${libcaosdb_INCL} ${libcaosdb_SRC} ${GRPC_GENERATED}) - set(LIBCAOSDB caosdb) -endif() - -IF (WIN32) - target_link_libraries(caosdb - ${CONAN_LIBS} - ) -ELSE() - target_link_libraries(caosdb - ${CONAN_LIBS} + target_link_libraries(caosdb + grpc::grpc protobuf::protobuf boost::boost stdc++fs ) -ENDIF() + set(LIBCAOSDB caosdb) +endif() + target_include_directories(caosdb PUBLIC $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> @@ -195,35 +212,27 @@ target_include_directories(caosdb PUBLIC $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/src> $<INSTALL_INTERFACE:include> ) -target_include_directories(caosdb SYSTEM PUBLIC - ${CONAN_INCLUDE_DIRS} -) -add_library(ccaosdb SHARED src/ccaosdb.cpp ${GRPC_GENERATED}) -IF (WIN32) - target_link_libraries(ccaosdb - ${CONAN_LIBS} - ${LIBCAOSDB} - ) -ELSE() - target_link_libraries(ccaosdb - ${CONAN_LIBS} - ${LIBCAOSDB} - stdc++fs - ) -ENDIF() + +# libccaosdb +# ---------- +add_library(ccaosdb SHARED src/ccaosdb.cpp) +target_link_libraries(ccaosdb + grpc::grpc protobuf::protobuf boost::boost + ${LIBCAOSDB} + stdc++fs +) target_include_directories(ccaosdb PUBLIC $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> ) -target_include_directories(ccaosdb SYSTEM PUBLIC - ${CONAN_INCLUDE_DIRS} -) +# ccaosdbcli +# ---------- add_executable(ccaosdbcli EXCLUDE_FROM_ALL src/ccaosdbcli.c) target_include_directories(ccaosdbcli PUBLIC $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> @@ -235,11 +244,13 @@ target_include_directories(ccaosdbcli SYSTEM PUBLIC ) target_link_libraries(ccaosdbcli - ${CONAN_LIBS} + grpc::grpc protobuf::protobuf boost::boost ${LIBCAOSDB} ccaosdb ) +# cxxcaosdbcli +# ------------ add_executable(cxxcaosdbcli EXCLUDE_FROM_ALL src/cxxcaosdbcli.cpp) target_include_directories(cxxcaosdbcli PUBLIC $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> @@ -251,7 +262,7 @@ target_include_directories(cxxcaosdbcli SYSTEM PUBLIC ) target_link_libraries(cxxcaosdbcli ${LIBCAOSDB} - ${CONAN_LIBS} + grpc::grpc protobuf::protobuf boost::boost ) @@ -302,7 +313,7 @@ if(_LINTING) add_compiler_flag("-Wall") add_compiler_flag("-Wextra") add_compiler_flag("-pedantic") - add_compiler_flag("-Werror") + # add_compiler_flag("-Werror") # removed until issue #71 is resolved message(STATUS "PEDANTIC_CMAKE_CXX_FLAGS: [${PEDANTIC_CMAKE_CXX_FLAGS}]") set(TARGET_CAOSDB_COMPILE_FLAGS "${TARGET_CAOSDB_COMPILE_FLAGS} ${PEDANTIC_CMAKE_CXX_FLAGS}") @@ -346,11 +357,11 @@ if(_LINTING) else() message(STATUS "clang-tidy: ${clang_tidy}") set(_CMAKE_CXX_CLANG_TIDY_CHECKS - "--checks=*,-fuchsia-*,-llvmlibc-*,-readability-convert-member-functions-to-static,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-else-after-return,-readability-else-after-return,-modernize-use-trailing-return-type,-bugprone-branch-clone,-altera-*") + "--checks=*,-fuchsia-*,-llvmlibc-*,-readability-convert-member-functions-to-static,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-else-after-return,-readability-else-after-return,-modernize-use-trailing-return-type,-bugprone-branch-clone,-altera-*,-misc-include-cleaner,-readability-identifier-*,-llvm-include-order,-misc-const-correctness") set(_CMAKE_C_CLANG_TIDY_CHECKS "${_CMAKE_CXX_CLANG_TIDY_CHECKS}") set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}" - "--header-filter=caosdb/.*[^\(\.pb\.h\)]$" - "--warnings-as-errors=*") + "--header-filter=caosdb/.*[^\(\.pb\.h\)]$") + # "--warnings-as-errors=*") set(_CMAKE_C_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}") option(AUTO_FIX_LINTING "Append --fix option to clang-tidy" OFF) if(AUTO_FIX_LINTING) @@ -383,9 +394,9 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") add_subdirectory(test) endif() -############################################### -############ INSTALLATION ##################### -############################################### +# ############################################### +# ############ INSTALLATION ##################### +# ############################################### set(libcaosdb_INCLUDE_DEST "include/caosdb") set(libcaosdb_LIB_DEST "lib") diff --git a/HUMANS.md b/HUMANS.md index 3104ed33f893da734c04d97b694bc2c1126ac519..95ce3cffda358d2b07885556d8591dbdec298104 100644 --- a/HUMANS.md +++ b/HUMANS.md @@ -1,3 +1,6 @@ # Active Contributors * Timm Fitschen <t.fitschen@indiscale.com> +* Daniel Hornung <d.hornung@indiscale.com> +* Joscha Schmiedt <joscha@schmiedt.dev> +* Florian Spreckelsen <f.spreckelsen@indiscale.com> diff --git a/Makefile b/Makefile index 9a4abd9173578cbffc7a7b7260e8a681101fc5a6..682257ad63ca86f0c776b372e36d5c3e108fd9e1 100644 --- a/Makefile +++ b/Makefile @@ -56,9 +56,9 @@ style: .PHONY: style conan-install-deps: - conan install . -s $(CONAN_SETTINGS) || \ + conan install . -s $(CONAN_SETTINGS) -s build_type=Release || \ (echo "'conan install' failed, trying to build from sources..."; \ - conan install . -s $(CONAN_SETTINGS) --build=missing) + conan install . -s $(CONAN_SETTINGS) -s build_type=Release --build=missing) .PHONY: conan-install-deps conan-install-debug: @@ -68,22 +68,40 @@ conan-install-debug: .PHONY: conan-install-debug conan-create: - conan create -s $(CONAN_SETTINGS) -o caosdb:build_acm=True . "caosdb/$$(conan inspect --raw version .)@_/_" + conan create -s $(CONAN_SETTINGS) -o caosdb/*:build_acm=True . .PHONY: conan-create conan-create-debug: - conan create -s $(CONAN_SETTINGS) -s build_type=Debug -o caosdb:build_acm=True . "caosdb/$$(conan inspect --raw version .)@_/_" + conan create -s $(CONAN_SETTINGS) -s build_type=Debug -o caosdb/*:build_acm=True . .PHONY: conan-create-debug conan: conan-install-deps conan-create .PHONY: conan -doc: - mkdir -p build && cd build && conan install .. --build=missing -s $(CONAN_SETTINGS) \ - && cmake .. && cmake --build . --target doc-sphinx \ - && echo "The documentation starts at build/doc/sphinx_out/index.html ." +doc: conan-install-deps + @doxygen --version || ( echo "Doxygen not found. Please install Doxygen first." ; exit 1 ) + cd build/Release\ + && cmake -S ../.. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" \ + && cmake --build . --target doc-sphinx \ + && echo "The documentation starts at build/Release/doc/sphinx_out/index.html ." .PHONY: doc conan-debug: conan-install-debug conan-create-debug .PHONY: conan-debug + +conan-build: + conan build . -s $(CONAN_SETTINGS) -s build_type=Release + +conan-build-debug: + conan build . -s $(CONAN_SETTINGS) -s build_type=Debug + + +ctest: + cd build/Debug && ctest + +test: conan-install-debug conan-build-debug ctest + + +clean: + rm -rf build \ No newline at end of file diff --git a/conanfile.py b/conanfile.py index 021f04037e522749b7480f45c3f99eb242ba6de9..83c5914a2f1c8b5d3c6d85bb695f4a918a768304 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,4 +1,8 @@ -from conans import ConanFile, CMake, tools +import os +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout, CMakeDeps, CMakeToolchain +from conan.tools.files import copy +from conan.errors import ConanInvalidConfiguration class CaosdbConan(ConanFile): @@ -20,48 +24,75 @@ class CaosdbConan(ConanFile): "fPIC": True, "build_acm": False, } - generators = "cmake" - requires = [ - ("grpc/1.48.4"), - ] - build_requires = [ - ("boost/1.78.0"), - ("gtest/1.11.0"), - ] + exports = ("*.cmake", "*CMakeLists.txt", "*.in", "*.h", "*.proto", "*.c", "*.cpp", "*.rst", "*.md", - ) - exports_sources = "src", "doc", "include", "test", "cmake", "proto" + ) + + exports_sources = "CMakeLists.txt", "src/*", "doc/*", "include/*", "test/*", "cmake/*", "proto/*", "*.cmake" + + def build_requirements(self): + self.tool_requires("protobuf/3.21.12") + self.tool_requires("cmake/[>=3.13]") + self.tool_requires("boost/1.78.0") + self.test_requires("gtest/1.11.0") + self.requires("grpc/1.48.4") + self.requires("protobuf/3.21.12") + self.requires("boost/1.78.0") def config_options(self): if self.settings.os == "Windows": - del self.options.fPIC + self.options.rm_safe("fPIC") self.options["boost"].without_python = True + self.options["boost"].without_test = True self.options["boost"].filesystem_version = "3" - # def source(self): - # self.run("git clone https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib.git") - # self.run("cd caosdb-cpplib && git submodule update --init") + def generate(self): + + tc = CMakeToolchain(self) + if self.options.build_acm: + tc.cache_variables["BUILD_ACM"] = "ON" + tc.generate() + + cmake = CMakeDeps(self) + cmake.generate() - def imports(self): - self.copy("protoc*", "build_tools", "bin") - self.copy("grpc_cpp_plugin*", "build_tools", "bin") + for dep in self.dependencies.values(): + dst = self.build_folder + "/build_tools" + src = dep.cpp_info.bindirs[0] + copied = copy(self, pattern="protoc*", dst=dst, src=src) + copy(self, pattern="grpc_cpp_plugin*", dst=dst, src=src) + + def layout(self): + cmake_layout(self, src_folder=".") def build(self): cmake = CMake(self) - if self.options.build_acm: - cmake.definitions["BUILD_ACM"] = "On" - cmake.configure(source_folder="") - cmake.build() + cmake.configure() + cmake.build(target=["all"]) # , "ccaosdbcli", "cxxcaosdbcli"]) def package(self): - self.copy("*.h", dst="include", src="include") - self.copy("*.dll", dst="bin", keep_path=False) - self.copy("*.so", dst="lib", keep_path=False) - self.copy("*.dylib", dst="lib", keep_path=False) - self.copy("*.a", dst="lib", keep_path=False) + cmake = CMake(self) + cmake.install() + + copy(self, pattern="*.h", + dst=os.path.join(self.package_folder, "include"), + src=os.path.join(self.source_folder, "include")) + copy(self, pattern="*.dll", src=os.path.join(self.build_folder, "bin"), + dst=os.path.join(self.package_folder, "bin"), keep_path=False) + copy(self, pattern="*.so", src=os.path.join(self.build_folder, "bin"), + dst=os.path.join(self.package_folder, "lib"), keep_path=False) + copy(self, pattern="*.dylib", src=os.path.join(self.build_folder, "bin"), + dst=os.path.join(self.package_folder, "lib"), keep_path=False) + copy(self, pattern="*.a", src=os.path.join(self.build_folder, "bin"), + dst=os.path.join(self.package_folder, "lib"), keep_path=False) def package_info(self): self.cpp_info.libs = ["caosdb", "ccaosdb"] + self.cpp_info.requires = ["boost::headers", "grpc::grpc", "protobuf::protobuf"] + + def validate(self): + if self.settings.os not in ("Linux", "Windows"): + raise ConanInvalidConfiguration(f"{self.settings.os} is currently not supported") diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 66d8b3660215477bf3e0ba83b7f115d7637352fe..32f54a4e3afa5efdf9f3afb49c40d1221f183267 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Updated dependency versions. +- Updated Python dependencies for Conan 2 and support Python 3.12. +- Updated C++ package manager Conan to 2.5.0. ### Deprecated @@ -22,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Values can now hold empty vectors and do not silently convert them into a scalar. + ### Security ### Documentation diff --git a/doc/Install_develop.rst b/doc/Install_develop.rst index bf4fb03102316f5f2e6e0b85337892317b0f0483..67618dc45457e87a1d0fb15b509b97cb4eca8ce2 100644 --- a/doc/Install_develop.rst +++ b/doc/Install_develop.rst @@ -4,7 +4,7 @@ How to use and develop libcaosdb Dependencies ------------ -- See the `dependencies <DEPENDENCIES.md>`__ file, install with ``pip install -r requiremens.txt``. +- See the `dependencies <DEPENDENCIES.md>`__ file, install with ``pip install -r requirements.txt``. Build ----- @@ -26,9 +26,9 @@ We use `cmake <https://cmake.org>`__ as build tool, with Conan as package manager. The compiler must support the C++17 standard. 1. clone/update the subrepo ``git submodule update --init proto`` -2. ``mkdir build && cd build`` -3. ``conan install .. -s "compiler.libcxx=libstdc++11"`` -4. ``cmake -B . ..`` +2. ``conan install . -s build_type=Release --build=missing`` +3. ``cd build/Release`` +4. ``cmake .`` 5. ``cmake --build .`` You may also want to install libcaosdb system-wide to @@ -38,7 +38,7 @@ You may also want to install libcaosdb system-wide to The default install prefix is ``~/.local``. It can be set by adding ``-DCMAKE_INSTALL_PREFIX=/path/to/install/prefix`` to the first cmake -command (3.). +command (4.). .. Note:: @@ -54,15 +54,7 @@ to merge requests which support multiple ways of installation. How to build on MacOS ~~~~~~~~~~~~~~~~~~~~~ -If you use apple-clang as the compiler: Instead of the above conan -command (2.) use - -1. ``conan install .. -s "compiler.cppstd=17"`` - -and continue as you would when building on a Linux system. You may have -to add ``build/lib/`` (or, alternatively after installation, -``CMAKE_INSTALL_PREFIX/lib``) to your ``DYLD_LIBRARY_PATH`` -environmental variable. +... is currently untested. Problems and solutions ^^^^^^^^^^^^^^^^^^^^^^ @@ -77,14 +69,13 @@ How to build on Windows ~~~~~~~~~~~~~~~~~~~~~~~ We use `Visual Studio -2019 <https://visualstudio.microsoft.com/de/vs/features/cplusplus/>`__ +2022 <https://visualstudio.microsoft.com/de/vs/features/cplusplus/>`__ as compiler. We use `cmake <https://cmake.org/download/>`__ as build tool. 1. clone/update the subrepo ``git submodule update --init proto`` -2. ``mkdir build`` -3. ``cd build`` -4. ``conan install .. -g visual_studio -s arch=x86_64 -s build_type=Release -s compiler.toolset=v142 -s compiler.version=16 -s compiler.runtime=MD --build=missing --update`` +2. ``conan install .. -g visual_studio -s arch=x86_64 -s build_type=Release -s compiler.toolset=v142 -s compiler.version=16 -s compiler.runtime=MD --build=missing --update`` +3. ``cd build/Release`` 5. ``cmake -B . ..`` 6. open ``libcaosdb.sln`` with Visual Studio, change the buildtype to ``Release`` and build the project. (You can open Tools/Command @@ -103,6 +94,17 @@ Known problems Troubleshooting ~~~~~~~~~~~~~~~ +ERROR: The default build profile '~/.conan2/profiles/default' doesn't exist +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Follow the instructions and run + +.. code:: console + + conan profile detect + +Check the output and adjust settings if necessary. + Warning: WARNING: GCC OLD ABI COMPATIBILITY ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -175,25 +177,26 @@ Unit tests Build ^^^^^ -For the tests there is a slightly different setup required (with option -``-D CMAKE_BUILD_TYPE=Debug``) +For the tests the build type has to be Debug. As a shorthand you can run ``make +test``. If you want to build manually, follow these steps: -1. ``mkdir build && cd build/`` -2. ``conan install ..`` (with gcc, append - ``-s "compiler.libcxx=libstdc++11"``, with apple-clang, append - ``-s compiler.cppstd=17``) -3. ``cmake -B . -D CMAKE_BUILD_TYPE=Debug ..`` +1. ``conan install . -s build_type=Debug --build=missing`` +2. ``cd build/Debug`` +3. ``cmake -S ../.. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Debug`` - If your clang-format version is too old, formatting, linting etc. can be skipped: ``cmake -B . -D CMAKE_BUILD_TYPE=Debug -D SKIP_LINTING=ON ..`` - Depending on the clang version it may be necessary to also add ``-DCMAKE_CXX_FLAGS="-Wno-unused-parameter"`` -4. ``cmake --build .`` +5. ``cmake --build . `` + - If this fails with ``Error running '': No such file or directory``, you may want to try + CMake's ``-D SKIP_LINTING=ON``. (See previous step.) Run ^^^ -In the build directory, run ``ctest`` +In the build directory, run ``ctest``. For more verbose output of a single test: +``ctest -R test_value.test_list -V`` Framework ^^^^^^^^^ diff --git a/doc/requirements.txt b/doc/requirements.txt index 458d5d584d3a8020543e287c651b521e0479b713..2a508b715a81bec87be01b179009b570f0730b04 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -9,7 +9,7 @@ idna==2.10 imagesize==1.2.0 Jinja2==2.11.3 MarkupSafe==1.1.1 -packaging==20.9 +packaging==24.1 Pygments==2.9.0 pyparsing==2.4.7 pytz==2021.1 diff --git a/include/caosdb/value.h b/include/caosdb/value.h index cffb11162b9ed8b83508316c155f1fca46be2714..1da6f1c2178b1b9091b990a016e1959b5e7f2a4c 100644 --- a/include/caosdb/value.h +++ b/include/caosdb/value.h @@ -36,6 +36,10 @@ for (const auto &value : values) { \ this->wrapped->mutable_list_values()->add_values()->SETTER(value); \ } \ + if (values.empty()) { \ + this->wrapped->mutable_list_values()->add_values()->set_special_value( \ + ProtoSpecialValue::SPECIAL_VALUE_UNSPECIFIED); \ + } \ } namespace caosdb::entity { @@ -385,7 +389,9 @@ public: return !IsNull() && this->wrapped->value_case() == ValueCase::kListValues; } [[nodiscard]] inline auto GetAsVector() const noexcept -> const std::vector<ScalarValue> & { - if (!IsVector()) { + if (!IsVector() || (this->wrapped->list_values().values(0).has_special_value() && + this->wrapped->list_values().values(0).special_value() == + ProtoSpecialValue::SPECIAL_VALUE_UNSPECIFIED)) { // create empty list static std::vector<ScalarValue> empty_values; return empty_values; diff --git a/requirements.txt b/requirements.txt index c3029f4aa360788c3c32abbae097f5a0023a5c42..beee199161c222749b8c113e78d52069cfdff852 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,22 +1,17 @@ -bottle==0.12.23 -certifi==2022.9.24 -charset-normalizer==2.1.1 +certifi==2024.6.2 +charset-normalizer==3.3.2 colorama==0.4.6 -conan==1.61.0 -distro==1.7.0 -fasteners==0.18 -future==0.18.2 -idna==3.4 -Jinja2==3.1.2 -MarkupSafe==2.1.1 -node-semver==0.6.1 +packaging==24.1 +setuptools==71.0.4 +conan==2.5.0 +distro==1.8.0 +fasteners==0.19 +idna==3.7 +Jinja2==3.1.4 +MarkupSafe==2.1.5 patch-ng==1.17.4 -pluginbase==1.0.1 -Pygments==2.13.0 -PyJWT==2.6.0 -python-dateutil==2.8.2 +python-dateutil==2.9.0.post0 PyYAML==6.0.1 -requests==2.28.1 +requests==2.32.3 six==1.16.0 -tqdm==4.64.1 -urllib3==1.26.12 +urllib3==1.26.18 diff --git a/src/caosdb/authentication.cpp b/src/caosdb/authentication.cpp index 7faa8619b4153c8ff3c03549369b7d976a62e035..11c3c17366ae9d24f209f7915c640fd2fee80d95 100644 --- a/src/caosdb/authentication.cpp +++ b/src/caosdb/authentication.cpp @@ -19,11 +19,13 @@ * */ #include "caosdb/authentication.h" -#include <grpcpp/security/credentials.h> // for MetadataCredentialsPlugin -#include <map> // for multimap -#include <memory> // for allocator, shared_ptr -#include <string> // for basic_string, operator+ -#include <utility> // for pair, move, make_pair +#include "caosdb/utility.h" // for base64_encode +#include <grpcpp/security/credentials.h> // for MetadataCredentialsPlugin +#include <grpcpp/security/auth_context.h> // for AuthContext +#include <map> // for multimap +#include <memory> // for allocator, shared_ptr +#include <string> // for basic_string, operator+ +#include <utility> // for pair, move, make_pair namespace caosdb::authentication { using caosdb::utility::base64_encode; diff --git a/src/caosdb/connection.cpp b/src/caosdb/connection.cpp index 550e35aac5c58383b7a8129bc68330769c5260ad..ebd55631d9df2208d56a40385bcb4d8e4b9dad82 100644 --- a/src/caosdb/connection.cpp +++ b/src/caosdb/connection.cpp @@ -36,6 +36,7 @@ #include <grpcpp/create_channel.h> // for CreateChannel #include <grpcpp/support/status.h> // for Status #include <string> // for string, operator+ +#include <memory> // for make_shared #ifdef BUILD_ACM #include <vector> // for vector #endif diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index c8bcb486d6f34db98d8cbe993a74e9bac096d672..1567488144935c3281562af75f1476fdcbbb5603 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -23,9 +23,10 @@ #include "caosdb/data_type.h" // for DataType #include "caosdb/entity/v1/main.pb.h" // for Messages #include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/value.h" // for Value +#include "caosdb/status_code.h" // for StatusCode #include <google/protobuf/arena.h> // for Arena -#include <string> +#include <string> // for string +#include <vector> // for vector namespace caosdb::entity { using ProtoParent = caosdb::entity::v1::Parent; diff --git a/src/caosdb/logging.cpp b/src/caosdb/logging.cpp index f6ca7f48600adc67e0ba315105642208c5619987..65b59c954e96a1a7a8d0b46f1183f949a07efa7b 100644 --- a/src/caosdb/logging.cpp +++ b/src/caosdb/logging.cpp @@ -20,28 +20,17 @@ */ #include "caosdb/logging.h" #include "caosdb/log_level.h" -#include <boost/core/swap.hpp> // for swap -#include <boost/iterator/iterator_facade.hpp> #include <boost/log/attributes/clock.hpp> #include <boost/log/core/core.hpp> // for core #include <boost/log/core/record.hpp> -#include <boost/log/detail/attachable_sstream_buf.hpp> #include <boost/log/sources/record_ostream.hpp> #include <boost/log/sources/severity_channel_logger.hpp> #include <boost/log/utility/setup/from_settings.hpp> #include <boost/log/utility/setup/settings.hpp> -#include <boost/multi_index/detail/bidir_node_iterator.hpp> -#include <boost/operators.hpp> -#include <boost/preprocessor/seq/limits/enum_256.hpp> -#include <boost/preprocessor/seq/limits/size_256.hpp> -#include <boost/property_tree/detail/exception_implementation.hpp> -#include <boost/smart_ptr/intrusive_ptr.hpp> -#include <boost/smart_ptr/intrusive_ref_counter.hpp> #include <boost/smart_ptr/shared_ptr.hpp> #include <cstdint> // for uint64_t #include <filesystem> #include <memory> -#include <sstream> #include <string> #include <utility> // for move #include <vector> diff --git a/src/caosdb/utility.cpp b/src/caosdb/utility.cpp index ca7e1cbe9102763ed54763f7ca1dd271ed0b06db..1cefe34c5a69477b5ebc8d5f457eaebc044f96aa 100644 --- a/src/caosdb/utility.cpp +++ b/src/caosdb/utility.cpp @@ -115,7 +115,7 @@ auto base64_encode(const std::string &plain) -> std::string { auto size_encoded = boost::beast::detail::base64::encoded_size(size_plain); std::string result = std::string(size_encoded, '\0'); - boost::beast::detail::base64::encode(&result[0], plain.c_str(), size_plain); + boost::beast::detail::base64::encode(result.data(), plain.c_str(), size_plain); return result; } @@ -123,7 +123,7 @@ auto base64_encode(const std::string &plain) -> std::string { auto _load_json_file(const path &json_file) -> value { assert(exists(json_file)); - constexpr auto buffer_size = std::size_t(4096); + constexpr auto buffer_size = static_cast<size_t>(4096); auto stream = ifstream(json_file); stream.exceptions(std::ios_base::badbit); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 659254bf1e215c6c203eb82c0d2bca030a12a0b9..931c9d69a919bd0f2695ae2a6a5fe45bb4b89aa3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -51,8 +51,10 @@ set(_CMAKE_CXX_CLANG_TIDY_TEST_CHECKS ) # add special cmake functions for gtest +find_package(GTest REQUIRED) include(GoogleTest) +message(DEBUG "CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}") # loop over all test cases and add them to the test runner list(LENGTH test_cases len_test_cases) @@ -63,7 +65,7 @@ foreach (i RANGE "${len_test_cases}") set(libcaosdb_TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${test_case_name}.cpp ${libcaosdb_TEST_SRC}") target_link_libraries(${test_case_name} - PRIVATE ${LIBCAOSDB} ccaosdb ${CONAN_LIBS_GTEST} ${CONAN_LIBS_BOOST}) + PRIVATE GTest::gtest_main ${LIBCAOSDB} ccaosdb gtest::gtest) target_include_directories(${test_case_name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) if(_LINTING) diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index 71c2a829316b5b5418702686c6ea0fdfa48e5198..c09775311f5512269b852e4b5aaeb6df2578ccaa 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -21,11 +21,12 @@ */ #include "caosdb/configuration.h" -#include "caosdb/status_code.h" // for StatusCode -#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR -#include "ccaosdb.h" // for caosdb_utility_get_env_fallback -#include <cstdint> // for int64_t -#include <cstring> // for strcmp +#include "caosdb/status_code.h" // for StatusCode +#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR +#include "ccaosdb.h" // for caosdb_utility_get_env_fallback +#include <cstdint> // for int64_t +#include <cstring> // for strcmp +#include <gtest/gtest.h> #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl #include <gtest/gtest_pred_impl.h> // for Test, TestInfo, EXPECT_EQ, TEST diff --git a/test/test_configuration.cpp b/test/test_configuration.cpp index 6d5f2e9449e5be21452fdcca6a04f4e02f531d13..2f5e754b83ad5be6903deb6f521190f07911f9b6 100644 --- a/test/test_configuration.cpp +++ b/test/test_configuration.cpp @@ -19,11 +19,12 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/configuration.h" // for ConfigurationError, Configuration... -#include "caosdb/exceptions.h" // for ConfigurationError -#include "caosdb/log_level.h" // for CAOSDB_DEFAULT_LOG_LEVEL, CAOSDB_... -#include "caosdb/logging.h" // for ConsoleSinkConfiguration, Logging... -#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR +#include "caosdb/configuration.h" // for ConfigurationError, Configuration... +#include "caosdb/exceptions.h" // for ConfigurationError +#include "caosdb/log_level.h" // for CAOSDB_DEFAULT_LOG_LEVEL, CAOSDB_... +#include "caosdb/logging.h" // for ConsoleSinkConfiguration, Logging... +#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR +#include <gtest/gtest.h> #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver #include <gtest/gtest_pred_impl.h> // for TestInfo, TEST_F, Test diff --git a/test/test_connection.cpp b/test/test_connection.cpp index 9b8783a0ae88f6669de4e5ec4e5a43dea26447c5..29339b5d6e6bec03052a62bf3e65fd5911946a23 100644 --- a/test/test_connection.cpp +++ b/test/test_connection.cpp @@ -27,11 +27,12 @@ #include "caosdb/connection.h" // for ConnectionManager #include "caosdb/exceptions.h" // for ConnectionConfigurationError #include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_... -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPartR... -#include <gtest/gtest_pred_impl.h> // for AssertionResult, TestInfo -#include <memory> // for allocator, operator!=, shar... -#include <string> // for operator+, string +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPartR... +#include <gtest/gtest_pred_impl.h> // for AssertionResult, TestInfo +#include <memory> // for allocator, operator!=, shar... +#include <string> // for operator+, string namespace caosdb::connection { #ifdef BUILD_ACM diff --git a/test/test_data_type.cpp b/test/test_data_type.cpp index 6b7b8b6ea3d36135164d73c90e8f45693a49b1cc..540b06d5d677eef0e90587ca76bc01bb14cb2ead 100644 --- a/test/test_data_type.cpp +++ b/test/test_data_type.cpp @@ -25,12 +25,13 @@ #include "caosdb/entity/v1/main.pb.h" // for DataType, Ato... #include "caosdb/logging.h" // for CAOSDB_LOG_DEBUG #include "caosdb/protobuf_helper.h" // for CAOSDB_DEBUG_... -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi... -#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test -#include <map> // for map, operator!= -#include <string> // for allocator -#include <utility> // for pair +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi... +#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test +#include <map> // for map, operator!= +#include <string> // for allocator +#include <utility> // for pair namespace caosdb::entity { using ProtoEntity = caosdb::entity::v1::Entity; diff --git a/test/test_entity.cpp b/test/test_entity.cpp index a42e91781922c5e8b9530663b5bdbc53d4532fe3..5122e681152ea9c5cf51826b1169a6d7c41ac872 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -31,14 +31,15 @@ #include "caosdb/value.h" // for Value #include "caosdb_test_utility.h" // for TEST_DATA_DIR #include <google/protobuf/arena.h> // for Arena -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, Sui... -#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ -#include <iostream> // for operator<<, basic_o... -#include <memory> // for allocator, shared_ptr -#include <stdexcept> // for out_of_range -#include <string> // for operator+, to_string -#include <utility> // for move +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult, Sui... +#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ +#include <iostream> // for operator<<, basic_o... +#include <memory> // for allocator, shared_ptr +#include <stdexcept> // for out_of_range +#include <string> // for operator+, to_string +#include <utility> // for move // IWYU pragma: no_include "net/proto2/public/repeated_field.h" namespace caosdb::entity { diff --git a/test/test_file_transmission.cpp b/test/test_file_transmission.cpp index c5847a0842ae8a3bb46a8126e42b31bb5b1d6451..4a48a99f071d8603f7efa8de5de284ccd60a15a0 100644 --- a/test/test_file_transmission.cpp +++ b/test/test_file_transmission.cpp @@ -19,8 +19,9 @@ */ #include "caosdb/file_transmission/file_writer.h" #include "caosdb/file_transmission/file_reader.h" -#include <chrono> // for filesystem -#include <filesystem> // for path +#include <chrono> // for filesystem +#include <filesystem> // for path +#include <gtest/gtest.h> #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver #include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult diff --git a/test/test_info.cpp b/test/test_info.cpp index 4331219ab02ae5c60e165bee7992c6466d4889f2..bc1e41784148ae3d2a14ac1e77ad23b3cdccb5ee 100644 --- a/test/test_info.cpp +++ b/test/test_info.cpp @@ -22,10 +22,11 @@ #include "caosdb/info.h" // for VersionInfo #include "caosdb/info/v1/main.pb.h" // for VersionInfo -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiRe... -#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST -#include <memory> // for allocator +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiRe... +#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST +#include <memory> // for allocator namespace caosdb::info { using ProtoVersionInfo = caosdb::info::v1::VersionInfo; diff --git a/test/test_issues.cpp b/test/test_issues.cpp index 6422da5f4c86128be44286d853d768cd58db3c8c..bedb2bc2e83d88c3d352f8ab37466f19cd8f744c 100644 --- a/test/test_issues.cpp +++ b/test/test_issues.cpp @@ -23,10 +23,11 @@ #include "caosdb/status_code.h" // for StatusCode, EXECUTING #include "caosdb/transaction.h" // for Transaction #include "caosdb/transaction_status.h" // for StatusCode -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... -#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST -#include <memory> // for allocator, unique_ptr +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... +#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST +#include <memory> // for allocator, unique_ptr namespace caosdb::transaction { using caosdb::configuration::InsecureConnectionConfiguration; diff --git a/test/test_list_properties.cpp b/test/test_list_properties.cpp index 8e69ba381c20808fa4112eca06270c8bda5fa351..f2ef401b7b0433d627e4666ace115c363912a1cc 100644 --- a/test/test_list_properties.cpp +++ b/test/test_list_properties.cpp @@ -25,12 +25,13 @@ #include "caosdb/entity/v1/main.pb.h" // for AtomicDataType, DataType #include "caosdb/value.h" // for Value #include <cstdint> // for int64_t -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi... -#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test -#include <memory> // for allocator_traits<>::valu... -#include <string> // for string -#include <vector> // for vector +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi... +#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test +#include <memory> // for allocator_traits<>::valu... +#include <string> // for string +#include <vector> // for vector namespace caosdb::entity { using ProtoEntity = caosdb::entity::v1::Entity; diff --git a/test/test_protobuf.cpp b/test/test_protobuf.cpp index 42e1e574437e47f0129cb30b336ab336613daede..2abb0bf32137bf010c7ef7e2fbfba12ea2b73604 100644 --- a/test/test_protobuf.cpp +++ b/test/test_protobuf.cpp @@ -23,10 +23,11 @@ #include "caosdb/entity.h" // for Entity #include "caosdb/entity/v1/main.pb.h" // for RepeatedPtrField, Message #include <google/protobuf/arena.h> // for Arena -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... -#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST -#include <memory> // for allocator +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... +#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST +#include <memory> // for allocator namespace caosdb { using ProtoEntity = caosdb::entity::v1::Entity; diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index ed4dcd2aa72e3e857bc871f401504147b330385b..47b2cb0f8b3433e6229f03863dd00951ca244b17 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -30,14 +30,15 @@ #include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE #include <algorithm> // for max #include <google/protobuf/arena.h> // for Arena -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... -#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST -#include <memory> // for allocator, unique_ptr -#include <stdexcept> // for out_of_range -#include <string> // for string, basic_string -#include <utility> // for move -#include <vector> // for vector +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... +#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST +#include <memory> // for allocator, unique_ptr +#include <stdexcept> // for out_of_range +#include <string> // for string, basic_string +#include <utility> // for move +#include <vector> // for vector // IWYU pragma: no_include "net/proto2/public/repeated_field.h" namespace caosdb::transaction { diff --git a/test/test_user.cpp b/test/test_user.cpp index 5715833d0f23c5e8b887a8198fe5f96324dcafd8..8dcef60623f69b0c89c1d14fc2f16d4c513abeeb 100644 --- a/test/test_user.cpp +++ b/test/test_user.cpp @@ -20,7 +20,8 @@ * */ -#include "caosdb/acm/user.h" // for User +#include "caosdb/acm/user.h" // for User +#include <gtest/gtest.h> #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiRe... #include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, TEST diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 74db29afa798ccdbf9d4be45497e1a44762d630d..8db42b4991e0b643ecaf04b6e5fcf3d06d38e9bf 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -26,13 +26,14 @@ #include "caosdb/status_code.h" // for get_status_description #include "caosdb/utility.h" // for base64_encode, load_js... #include "caosdb_test_utility.h" // for TEST_DATA_DIR -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteA... -#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, TestInfo -#include <map> // for map, operator!=, _Rb_t... -#include <stdexcept> // for out_of_range -#include <string> // for allocator, string, ope... -#include <utility> // for pair +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteA... +#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, TestInfo +#include <map> // for map, operator!=, _Rb_t... +#include <stdexcept> // for out_of_range +#include <string> // for allocator, string, ope... +#include <utility> // for pair namespace caosdb::utility { diff --git a/test/test_value.cpp b/test/test_value.cpp index 8de10b9051c5ded66f8ea3b4a23581f861a75b8d..767965df68e648a04ba64a4148dc58839ebcc08c 100644 --- a/test/test_value.cpp +++ b/test/test_value.cpp @@ -25,12 +25,13 @@ #include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper #include <algorithm> // for max #include <cmath> // for isnan -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi... -#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test -#include <initializer_list> // for initializer_list -#include <string> // for string, basic_string -#include <vector> // for vector +#include <gtest/gtest.h> +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi... +#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test +#include <initializer_list> // for initializer_list +#include <string> // for string, basic_string +#include <vector> // for vector namespace caosdb::entity { using ProtoValue = caosdb::entity::v1::Value; @@ -136,6 +137,14 @@ TEST(test_value, test_list) { EXPECT_EQ(item.IsString(), true); EXPECT_EQ(item.GetAsString(), "id" + std::to_string(counter++)); } + + // Test empty lists + auto empty_content = std::vector<int>(); + Value value_0(empty_content); + EXPECT_TRUE(value_0.IsVector()); + auto const &list_value_0 = value_0.GetAsVector(); + EXPECT_EQ(list_value_0.size(), 0); + EXPECT_TRUE(list_value_0.empty()); } TEST(test_value, test_scalar_value_to_value) { diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 6e0db0446b0d4a2e1767f1ecdf2156ffb5dbb295..41be00cd59d8252bc50285c88ba8a998c52deb79 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.13) project(PackageTest CXX) ####################################################################### @@ -12,9 +12,9 @@ set(test_cases ### Set up tests using GoogleTest (GTest) ################################################### -# dependencies -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) + +find_package(caosdb REQUIRED) +find_package(GTest REQUIRED) # supress warnings during build of gtest cmake_policy(SET CMP0054 NEW) @@ -24,24 +24,34 @@ enable_testing() include(GoogleTest REQUIRED) # 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") -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 ${CONAN_LIBS_CAOSDB} - ${CONAN_LIBS_GTEST} ${CONAN_LIBS_GRPC} ${CONAN_LIBS_ABSEIL} - ${CONAN_LIBS_OPENSSL} ${CONAN_LIBS_C-ARES} ${CONAN_LIBS_BZIP2} - ${CONAN_LIBS_PROTOBUF} ${CONAN_LIBS_ZLIB}) - if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") - target_link_libraries(${test_case_name} PRIVATE caosdb_grpc) - endif() - target_include_directories(${test_case_name} PUBLIC ${CONAN_INCLUDE_DIRS}) - set_target_properties(${test_case_name} - PROPERTIES - CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}" - CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") - gtest_discover_tests(${test_case_name} - PROPERTIES - LABELS "caosdb-cpplib-int-tests") -endforeach () +add_executable(test_info test_info.cpp) +target_link_libraries(test_info PRIVATE GTest::gtest GTest::gtest_main caosdb::caosdb) +gtest_discover_tests(test_info) + +# foreach(test_case ${test_cases}) +# add_executable(${test_case} ${test_case}.cpp) +# target_link_libraries(${test_case} PRIVATE GTest::gtest GTest::gtest_main caosdb::caosdb) +# if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") +# target_link_libraries(${test_case} PRIVATE caosdb_grpc) +# endif() +# endforeach() + + +# list(LENGTH test_cases len_test_cases) +# math(EXPR len_test_cases "${len_test_cases} - 1") +# 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 GTest::gtest GTest::gtest_main caosdb::caosdb) +# if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") +# target_link_libraries(${test_case_name} PRIVATE caosdb_grpc) +# endif() +# target_include_directories(${test_case_name} PUBLIC ${CONAN_INCLUDE_DIRS}) +# set_target_properties(${test_case_name} +# PROPERTIES +# CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}" +# CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}") +# gtest_discover_tests(${test_case_name} +# PROPERTIES +# LABELS "caosdb-cpplib-int-tests") +# endforeach () diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 541113405bfca3b1222de81124a13586fe4bbda5..8915ddcdaff5c67d757be9424a2cbf5dada79844 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,28 +1,40 @@ -import os - -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout, CMakeDeps, CMakeToolchain +from conan.tools.files import copy +from conan.tools.build import cross_building class LibcaosdbTestConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake" - build_requires = [ - ("gtest/1.11.0"), - ] + + def requirements(self): + self.requires(self.tested_reference_str) + self.test_requires("gtest/1.11.0") + self.requires("grpc/1.48.4") + self.requires("protobuf/3.21.12") + self.requires("boost/1.78.0") + + def layout(self): + cmake_layout(self, src_folder=".") + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + + cmake = CMakeDeps(self) + cmake.generate() def build(self): cmake = CMake(self) - # Current dir is "test_package/build/<build_id>" and CMakeLists.txt is - # in "test_package" cmake.configure() cmake.build() - def imports(self): - self.copy("*.dll", dst="bin", src="bin") - self.copy("*.dylib*", dst="bin", src="lib") - self.copy('*.so*', dst='bin', src='lib') + # def imports(self): + # copy("*.dll", dst="bin", src="bin") + # copy("*.dylib*", dst="bin", src="lib") + # copy('*.so*', dst='bin', src='lib') def test(self): - if not tools.cross_building(self): + if not cross_building(self): cmake = CMake(self) cmake.test()