Skip to content
Permalink
Browse files
Add test_package for pushstreams, fix compilation error, and make Fin…
…dCppUTest.cmake compatible with the one generated by conan.
  • Loading branch information
PengZheng committed Mar 19, 2022
1 parent 93f358d commit b4606a16b44dff4096a65e3a53b666581e45739b
Showing 15 changed files with 105 additions and 33 deletions.
@@ -29,7 +29,7 @@ celix_bundle_files(rsa_dfi_tst_bundle ${DESCR} DESTINATION .)
get_target_property(DESCR remote_example_api INTERFACE_DESCRIPTOR)
celix_bundle_files(rsa_dfi_tst_bundle ${DESCR} DESTINATION .)

target_link_libraries(rsa_dfi_tst_bundle PRIVATE ${CppUTest_LIBRARY} calculator_api remote_example_api)
target_link_libraries(rsa_dfi_tst_bundle PRIVATE calculator_api remote_example_api)
target_include_directories(rsa_dfi_tst_bundle PRIVATE src)

add_executable(test_rsa_dfi
@@ -35,7 +35,7 @@ add_executable(test_rsa_shm

${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
)
target_link_libraries(test_rsa_shm celix_framework celix_utils CURL::libcurl ${CppUTest_LIBRARY})
target_link_libraries(test_rsa_shm celix_framework celix_utils CURL::libcurl CppUTest::CppUTest)

get_property(rsa_bundle_file TARGET remote_service_admin_shm PROPERTY BUNDLE_FILE)
get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE_FILE)
@@ -32,7 +32,7 @@ add_subdirectory(disc_mock)
add_executable(test_tm_scoped
tms_tests.cpp
)
target_include_directories(test_tm_scoped SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} PRIVATE ../src ../include)
target_include_directories(test_tm_scoped PRIVATE ../src ../include)
target_link_libraries(test_tm_scoped PRIVATE
Celix::framework
GTest::gtest GTest::gtest_main
@@ -16,7 +16,6 @@
# under the License.

include_directories(
SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/framework/public/include
${PROJECT_SOURCE_DIR}/utils/public/include
)
@@ -31,4 +30,4 @@ celix_bundle_files(topology_manager_test_bundle
DESTINATION .
)

target_link_libraries(topology_manager_test_bundle PRIVATE ${CppUTest_LIBRARY} Celix::deprecated_rsa_spi calculator_api)
target_link_libraries(topology_manager_test_bundle PRIVATE Celix::deprecated_rsa_spi calculator_api)
@@ -22,7 +22,6 @@ add_celix_bundle(topology_manager_disc_mock_bundle
disc_mock_service.c
)
target_include_directories(topology_manager_disc_mock_bundle PRIVATE
SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR}
$<TARGET_PROPERTY:Celix::rsa_discovery_common,INCLUDE_DIRECTORIES>
)
target_link_libraries(topology_manager_disc_mock_bundle PRIVATE ${CppUTest_LIBRARY} Celix::framework)
target_link_libraries(topology_manager_disc_mock_bundle PRIVATE Celix::framework)
@@ -31,14 +31,16 @@ add_test(NAME test_shell COMMAND test_shell)
setup_target_for_coverage(test_shell SCAN_DIR ..)


add_executable(test_cxx_shell
src/ShellTestSuite.cc
)
if (CELIX_CXX)
add_executable(test_cxx_shell
src/ShellTestSuite.cc
)

target_link_libraries(test_cxx_shell PRIVATE Celix::framework Celix::shell_api GTest::gtest GTest::gtest_main)
add_celix_bundle_dependencies(test_cxx_shell ShellCxx)
target_compile_definitions(test_cxx_shell PRIVATE -DSHELL_BUNDLE_LOCATION=\"$<TARGET_PROPERTY:ShellCxx,BUNDLE_FILE>\")
target_compile_definitions(test_cxx_shell PRIVATE -DCXX_SHELL)
target_link_libraries(test_cxx_shell PRIVATE Celix::framework Celix::shell_api GTest::gtest GTest::gtest_main)
add_celix_bundle_dependencies(test_cxx_shell ShellCxx)
target_compile_definitions(test_cxx_shell PRIVATE -DSHELL_BUNDLE_LOCATION=\"$<TARGET_PROPERTY:ShellCxx,BUNDLE_FILE>\")
target_compile_definitions(test_cxx_shell PRIVATE -DCXX_SHELL)

add_test(NAME test_cxx_shell COMMAND test_cxx_shell)
setup_target_for_coverage(test_cxx_shell SCAN_DIR ..)
add_test(NAME test_cxx_shell COMMAND test_cxx_shell)
setup_target_for_coverage(test_cxx_shell SCAN_DIR ..)
endif()
@@ -82,6 +82,7 @@ find_dependency(CURL) #Needed by framework (used for curl initialization)
find_dependency(LIBZIP) #Needed by utils
find_dependency(Jansson) #Needed by dfi, etcdlib, remote services, pubsub
find_dependency(FFI) #Needed by dfi
find_dependency(Threads)

if (NOT TARGET ZLIB::ZLIB)
#Note more recent zlib will create ZLIB::ZLIB target
@@ -116,6 +117,3 @@ endif ()
if (TARGET Celix::pubsub_admin_nanomsg)
find_dependency(NanoMsg)
endif ()
if (TARGET Celix::Promises)
find_dependency(Threads)
endif ()
@@ -44,7 +44,21 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(CppUTest DEFAULT_MSG CppUTest_LIBRARY CppUTest
IF(CPPUTEST_FOUND)
SET(CppUTest_LIBRARIES ${CppUTest_LIBRARY})
SET(CppUTest_INCLUDE_DIRS ${CppUTest_INCLUDE_DIR})
if(NOT TARGET CppUTest::CppUTest)
add_library(CppUTest::CppUTest STATIC IMPORTED)
set_target_properties(CppUTest::CppUTest PROPERTIES
IMPORTED_LOCATION "${CppUTest_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${CppUTest_INCLUDE_DIR}"
)
endif()
ENDIF(CPPUTEST_FOUND)

SET(CppUTest_EXT_LIBRARIES ${CppUTest_EXT_LIBRARY})
SET(CppUTest_EXT_INCLUDE_DIRS ${CppUTest_EXT_INCLUDE_DIR})
if(NOT TARGET CppUTest::CppUTestExt)
add_library(CppUTest::CppUTestExt STATIC IMPORTED)
set_target_properties(CppUTest::CppUTestExt PROPERTIES
IMPORTED_LOCATION "${CppUTest_EXT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${CppUTest_EXT_INCLUDE_DIR}"
)
endif()
@@ -194,8 +194,7 @@ def requirements(self):
self.options['openssl'].shared = True
self.options['libxml2'].shared = True
if self.options.enable_testing:
self.requires("gtest/1.10.0")
self.requires("cpputest/4.0")
self.options['gtest'].shared = True
if self.options.celix_add_openssl_dep or self.options.build_zmq_security:
self.requires("openssl/1.1.1k")
if self.options.build_remote_service_admin or self.options.build_shell_bonjour:
@@ -21,6 +21,7 @@

#include "celix/PushEvent.h"
#include "celix/IPushEventConsumer.h"
#include <functional>

namespace celix {
template <typename T>
@@ -45,7 +45,7 @@ add_library(utils SHARED
${MEMSTREAM_SOURCES}
)
set_target_properties(utils PROPERTIES OUTPUT_NAME "celix_utils")
target_link_libraries(utils PUBLIC libzip::libzip)
target_link_libraries(utils PRIVATE libzip::libzip)

if (NOT OPEN_MEMSTREAM_EXISTS)
target_compile_definitions(utils PUBLIC -DNO_MEMSTREAM_AVAILABLE)
@@ -91,31 +91,31 @@ if (ENABLE_TESTING)
include_directories(src)

add_executable(hash_map_test private/test/hash_map_test.cpp)
target_link_libraries(hash_map_test Celix::utils ${CppUTest_LIBRARY} pthread)
target_link_libraries(hash_map_test Celix::utils CppUTest::CppUTest pthread)

add_executable(array_list_test private/test/array_list_test.cpp)
target_link_libraries(array_list_test Celix::utils ${CppUTest_LIBRARY} pthread)
target_link_libraries(array_list_test Celix::utils CppUTest::CppUTest pthread)

add_executable(celix_threads_test private/test/celix_threads_test.cpp)
target_link_libraries(celix_threads_test Celix::utils ${CppUTest_LIBRARY} ${CppUTest_EXT_LIBRARIES} pthread)
target_link_libraries(celix_threads_test Celix::utils CppUTest::CppUTest ${CppUTest_EXT_LIBRARIES} pthread)

add_executable(linked_list_test private/test/linked_list_test.cpp)
target_link_libraries(linked_list_test Celix::utils ${CppUTest_LIBRARY} pthread)
target_link_libraries(linked_list_test Celix::utils CppUTest::CppUTest pthread)

add_executable(properties_test private/test/properties_test.cpp)
target_link_libraries(properties_test ${CppUTest_LIBRARY} ${CppUTest_EXT_LIBRARIES} Celix::utils pthread)
target_link_libraries(properties_test CppUTest::CppUTest CppUTest::CppUTestExt Celix::utils pthread)

add_executable(utils_test private/test/utils_test.cpp)
target_link_libraries(utils_test ${CppUTest_LIBRARY} Celix::utils pthread)
target_link_libraries(utils_test CppUTest::CppUTest Celix::utils pthread)

add_executable(ip_utils_test private/test/ip_utils_test.cpp)
target_link_libraries(ip_utils_test ${CppUTest_LIBRARY} Celix::utils pthread)
target_link_libraries(ip_utils_test CppUTest::CppUTest Celix::utils pthread)

add_executable(filter_test private/test/filter_test.cpp)
target_link_libraries(filter_test ${CppUTest_LIBRARY} Celix::utils pthread)
target_link_libraries(filter_test CppUTest::CppUTest Celix::utils pthread)

add_executable(version_test private/test/version_test.cpp)
target_link_libraries(version_test ${CppUTest_LIBRARY} Celix::utils pthread)
target_link_libraries(version_test CppUTest::CppUTest Celix::utils pthread)

configure_file(private/resources-test/properties.txt ${CMAKE_CURRENT_BINARY_DIR}/resources-test/properties.txt COPYONLY)

@@ -32,7 +32,7 @@ SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}/utils" )

add_executable(config_admin_test config_admin_test.cpp)
target_link_libraries(config_admin_test Celix::framework ${CELIX_LIBRARIES} ${CppUTest_LIBRARY} pthread)
target_link_libraries(config_admin_test Celix::framework ${CELIX_LIBRARIES} CppUTest::CppUTest pthread)


get_property(config_admin_bundle_file TARGET config_admin PROPERTY BUNDLE_FILE)
@@ -21,6 +21,9 @@ set(CMAKE_CXX_STANDARD 17)

find_package(Celix REQUIRED)

set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--unresolved-symbols=ignore-in-shared-libs")
set (CMAKE_EXE_LINKER_FLAGS "-Wl,--unresolved-symbols=ignore-in-shared-libs")

add_celix_bundle(hello VERSION 1.0.0 SOURCES hello_bundle.c)
target_link_libraries(hello PRIVATE Celix::log_helper)
celix_get_bundle_file(hello HELLO_TEST_BUNDLE)
@@ -107,3 +110,9 @@ if (TEST_PROMISES)
add_executable(use_promises test_promises.cpp)
target_link_libraries(use_promises PRIVATE Celix::Promises)
endif ()

option(TEST_PUSHSTREAMS "Test pushstreams" OFF)
if (TEST_PUSHSTREAMS)
add_executable(use_pushstreams test_pushstreams.cpp)
target_link_libraries(use_pushstreams PRIVATE Celix::PushStreams)
endif ()
@@ -41,7 +41,7 @@ def build(self):
cmake.definitions["TEST_ETCD_LIB"] = self.options["celix"].build_celix_etcdlib
cmake.definitions["TEST_LAUNCHER"] = self.options["celix"].build_launcher
cmake.definitions["TEST_PROMISES"] = self.options["celix"].build_promises
# cmake.definitions["TEST_PUSHSTREAMS"] = self.options["celix"].build_pushstreams
cmake.definitions["TEST_PUSHSTREAMS"] = self.options["celix"].build_pushstreams
cmake.definitions["CMAKE_PROJECT_test_package_INCLUDE"] = os.path.join(self.build_folder, "conan_paths.cmake")
cmake.configure()
cmake.build()
@@ -69,4 +69,6 @@ def test(self):
self.run("./use_launcher", cwd=os.path.join("deploy", "use_launcher"), run_environment=True)
if self.options["celix"].build_promises:
self.run("./use_promises", run_environment=True)
if self.options["celix"].build_pushstreams:
self.run("./use_pushstreams", run_environment=True)

@@ -0,0 +1,49 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

#include <memory>
#include <celix/PushStreamProvider.h>
#include <exception>
#include <iostream>

using celix::PushStreamProvider;

int main() {
using namespace celix;
PushStreamProvider psp {};
std::shared_ptr<celix::PromiseFactory> promiseFactory {std::make_shared<celix::PromiseFactory>()};
int onClosedReceived{0};
int onErrorReceived{0};
auto ses = psp.template createSynchronousEventSource<int>(promiseFactory);
auto stream = psp.createUnbufferedStream<int>(ses, promiseFactory);
auto streamEnded = stream->filter([](const int& /*event*/) -> bool {
return true;
}).onClose([&](){
onClosedReceived++;
}).onError([&](){
onErrorReceived++;
}).forEach([&](int /*event*/) {
throw std::exception();
});

ses->publish(1);
streamEnded.wait();
std::cout << "onClosedReceived=" << onClosedReceived << " onErrorReceived=" << onErrorReceived << std::endl;
return 0;
}

0 comments on commit b4606a1

Please sign in to comment.