You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2021/05/07 14:32:40 UTC

[celix] branch feature/additional_pstm_test created (now 1a24f81)

This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a change to branch feature/additional_pstm_test
in repository https://gitbox.apache.org/repos/asf/celix.git.


      at 1a24f81  Adds tests for publisher with same topic, but different scopes

This branch includes the following new commits:

     new 9fcd285  Converts pubsub test from cpputest to gtest
     new 1a24f81  Adds tests for publisher with same topic, but different scopes

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[celix] 01/02: Converts pubsub test from cpputest to gtest

Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/additional_pstm_test
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 9fcd28531a86e1d6a5a9f8b6e3c6f34199239adc
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Fri May 7 11:18:48 2021 +0200

    Converts pubsub test from cpputest to gtest
---
 bundles/pubsub/test/CMakeLists.txt               |  71 +++++++-------
 bundles/pubsub/test/test/test_endpoint_runner.cc |  34 ++++---
 bundles/pubsub/test/test/test_runner.cc          | 115 ++++++++++++-----------
 3 files changed, 111 insertions(+), 109 deletions(-)

diff --git a/bundles/pubsub/test/CMakeLists.txt b/bundles/pubsub/test/CMakeLists.txt
index fd16f9e..a803025 100644
--- a/bundles/pubsub/test/CMakeLists.txt
+++ b/bundles/pubsub/test/CMakeLists.txt
@@ -15,7 +15,6 @@
 # specific language governing permissions and limitations
 # under the License.
 
-find_package(CppUTest REQUIRED)
 find_package(Jansson REQUIRED)
 
 add_celix_bundle(pubsub_endpoint_sut
@@ -152,8 +151,8 @@ if (BUILD_PUBSUB_PSA_UDP_MC)
                 pubsub_sut
                 pubsub_tst
     )
-    target_link_libraries(pubsub_udpmc_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson Celix::dfi)
-    target_include_directories(pubsub_udpmc_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_udpmc_tests PRIVATE Celix::pubsub_api Jansson Celix::dfi GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_udpmc_tests SYSTEM PRIVATE test)
 
     add_celix_container(pstm_deadlock_udpmc_test
             USE_CONFIG #ensures that a config.properties will be created with the launch bundles.
@@ -171,7 +170,7 @@ if (BUILD_PUBSUB_PSA_UDP_MC)
             Celix::shell_tui
             )
     target_compile_definitions(pstm_deadlock_udpmc_test PRIVATE -DDEADLOCK_SUT_BUNDLE_FILE=\"${DEADLOCK_SUT_BUNDLE_FILE}\")
-    target_link_libraries(pstm_deadlock_udpmc_test PRIVATE Celix::pubsub_api GTest::gtest GTest::gtest_main Jansson Celix::dfi)
+    target_link_libraries(pstm_deadlock_udpmc_test PRIVATE Celix::pubsub_api Jansson Celix::dfi GTest::gtest GTest::gtest_main)
     target_include_directories(pstm_deadlock_udpmc_test SYSTEM PRIVATE pstm_deadlock_udpmc_test)
 
     #Note we do not link to bundles, as result (to ensure a bundle zip file is created) an dependency on the bundle is needed.
@@ -207,8 +206,8 @@ if (BUILD_PUBSUB_PSA_TCP)
             pubsub_sut
             pubsub_tst
             )
-    target_link_libraries(pubsub_tcp_wire_v1_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson Celix::dfi)
-    target_include_directories(pubsub_tcp_wire_v1_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_tcp_wire_v1_tests PRIVATE Celix::pubsub_api Jansson Celix::dfi GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_tcp_wire_v1_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_tcp_wire_v1_tests COMMAND pubsub_tcp_wire_v1_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_wire_v1_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_tcp_wire_v1_tests SCAN_DIR ..)
 
@@ -229,8 +228,8 @@ if (BUILD_PUBSUB_PSA_TCP)
             pubsub_sut
             pubsub_tst
             )
-    target_link_libraries(pubsub_tcp_wire_v2_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson Celix::dfi)
-    target_include_directories(pubsub_tcp_wire_v2_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_tcp_wire_v2_tests PRIVATE Celix::pubsub_api Jansson Celix::dfi GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_tcp_wire_v2_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_tcp_wire_v2_tests COMMAND pubsub_tcp_wire_v2_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_wire_v2_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_tcp_wire_v2_tests SCAN_DIR ..)
 
@@ -252,8 +251,8 @@ if (BUILD_PUBSUB_PSA_TCP)
             pubsub_sut
             pubsub_tst
     )
-    target_link_libraries(pubsub_tcp_wire_v2_with_no_scope_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson Celix::dfi)
-    target_include_directories(pubsub_tcp_wire_v2_with_no_scope_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_tcp_wire_v2_with_no_scope_tests PRIVATE Celix::pubsub_api Jansson Celix::dfi GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_tcp_wire_v2_with_no_scope_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_tcp_wire_v2_with_no_scope_tests COMMAND pubsub_tcp_wire_v2_with_no_scope_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_wire_v2_with_no_scope_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_tcp_wire_v2_with_no_scope_tests SCAN_DIR ..)
 
@@ -275,8 +274,8 @@ if (BUILD_PUBSUB_PSA_TCP)
             pubsub_endpoint_sut
             pubsub_loopback
             )
-    target_link_libraries(pubsub_tcp_endpoint_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson Celix::dfi)
-    target_include_directories(pubsub_tcp_endpoint_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_tcp_endpoint_tests PRIVATE Celix::pubsub_api Jansson Celix::dfi GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_tcp_endpoint_tests SYSTEM PRIVATE test)
 
     add_celix_container(pstm_deadlock_tcp_test
             USE_CONFIG #ensures that a config.properties will be created with the launch bundles.
@@ -333,8 +332,8 @@ if (BUILD_PUBSUB_PSA_TCP)
             pubsub_tst
             pubsub_serializer
             )
-    target_link_libraries(pubsub_tcp_v2_wire_v1_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Celix::dfi)
-    target_include_directories(pubsub_tcp_v2_wire_v1_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_tcp_v2_wire_v1_tests PRIVATE Celix::pubsub_api Celix::dfi GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_tcp_v2_wire_v1_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_tcp_v2_wire_v1_tests COMMAND pubsub_tcp_v2_wire_v1_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_v2_wire_v1_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_tcp_v2_wire_v1_tests SCAN_DIR ..)
 
@@ -356,8 +355,8 @@ if (BUILD_PUBSUB_PSA_TCP)
             pubsub_tst
             pubsub_serializer
             )
-    target_link_libraries(pubsub_tcp_v2_wire_v2_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Celix::dfi)
-    target_include_directories(pubsub_tcp_v2_wire_v2_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_tcp_v2_wire_v2_tests PRIVATE Celix::pubsub_api Celix::dfi GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_tcp_v2_wire_v2_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_tcp_v2_wire_v2_tests COMMAND pubsub_tcp_v2_wire_v2_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_v2_wire_v2_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_tcp_v2_wire_v2_tests SCAN_DIR ..)
 
@@ -380,8 +379,8 @@ if (BUILD_PUBSUB_PSA_TCP)
             pubsub_tst
             pubsub_serializer
             )
-    target_link_libraries(pubsub_tcp_v2_wire_v2_with_no_scope_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Celix::dfi)
-    target_include_directories(pubsub_tcp_v2_wire_v2_with_no_scope_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_tcp_v2_wire_v2_with_no_scope_tests PRIVATE Celix::pubsub_api Celix::dfi GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_tcp_v2_wire_v2_with_no_scope_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_tcp_v2_wire_v2_with_no_scope_tests COMMAND pubsub_tcp_v2_wire_v2_with_no_scope_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_tcp_v2_wire_v2_with_no_scope_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_tcp_v2_wire_v2_with_no_scope_tests SCAN_DIR ..)
 
@@ -404,8 +403,8 @@ if (BUILD_PUBSUB_PSA_TCP)
             pubsub_loopback
             pubsub_serializer
             )
-    target_link_libraries(pubsub_tcp_v2_endpoint_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Celix::dfi)
-    target_include_directories(pubsub_tcp_v2_endpoint_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_tcp_v2_endpoint_tests PRIVATE Celix::pubsub_api Celix::dfi GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_tcp_v2_endpoint_tests SYSTEM PRIVATE test)
 
     add_celix_container(pstm_deadlock_tcp_v2_test
             USE_CONFIG #ensures that a config.properties will be created with the launch bundles.
@@ -462,8 +461,8 @@ if (BUILD_PUBSUB_PSA_WS)
             pubsub_sut
             pubsub_tst
             )
-    target_link_libraries(pubsub_websocket_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson Celix::dfi civetweb_shared)
-    target_include_directories(pubsub_websocket_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_websocket_tests PRIVATE Celix::pubsub_api Jansson Celix::dfi civetweb_shared GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_websocket_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_websocket_tests COMMAND pubsub_websocket_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_websocket_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_websocket_tests SCAN_DIR ..)
 
@@ -514,8 +513,8 @@ if (BUILD_PUBSUB_PSA_WS)
             pubsub_tst
             pubsub_serializer
             )
-    target_link_libraries(pubsub_websocket_v2_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson civetweb_shared)
-    target_include_directories(pubsub_websocket_v2_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_websocket_v2_tests PRIVATE Celix::pubsub_api Jansson civetweb_shared GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_websocket_v2_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_websocket_v2_tests COMMAND pubsub_websocket_v2_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_websocket_v2_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_websocket_v2_tests SCAN_DIR ..)
 
@@ -587,13 +586,13 @@ if (BUILD_PUBSUB_PSA_ZMQ)
                 pubsub_serializer
             )
 
-    target_link_libraries(pubsub_zmq_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Celix::dfi ZMQ::lib CZMQ::lib)
-    target_include_directories(pubsub_zmq_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_zmq_tests PRIVATE Celix::pubsub_api Celix::dfi ZMQ::lib CZMQ::lib GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_zmq_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_zmq_tests COMMAND pubsub_zmq_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_zmq_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_zmq_tests SCAN_DIR ..)
 
-    target_link_libraries(pubsub_zmq_v2_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Celix::dfi ZMQ::lib CZMQ::lib)
-    target_include_directories(pubsub_zmq_v2_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_zmq_v2_tests PRIVATE Celix::pubsub_api Celix::dfi ZMQ::lib CZMQ::lib GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_zmq_v2_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_zmq_v2_tests COMMAND pubsub_zmq_v2_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_zmq_v2_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_zmq_v2_tests SCAN_DIR ..)
 
@@ -614,8 +613,8 @@ if (BUILD_PUBSUB_PSA_ZMQ)
         pubsub_serializer
         )
 
-    target_link_libraries(pubsub_zmq_wire_v2_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson Celix::dfi ZMQ::lib CZMQ::lib)
-    target_include_directories(pubsub_zmq_wire_v2_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_zmq_wire_v2_tests PRIVATE Celix::pubsub_api Jansson Celix::dfi ZMQ::lib CZMQ::lib GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_zmq_wire_v2_tests SYSTEM PRIVATE test)
     add_test(NAME pubsub_zmq_wire_v2_tests COMMAND pubsub_zmq_wire_v2_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_zmq_wire_v2_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_zmq_wire_v2_tests SCAN_DIR ..)
 
@@ -659,14 +658,14 @@ if (BUILD_PUBSUB_PSA_ZMQ)
                 pubsub_tst
                 pubsub_serializer
             )
-    target_link_libraries(pubsub_zmq_zerocopy_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson Celix::dfi ZMQ::lib CZMQ::lib)
-    target_include_directories(pubsub_zmq_zerocopy_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_zmq_zerocopy_tests PRIVATE Celix::pubsub_api Jansson Celix::dfi ZMQ::lib CZMQ::lib GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_zmq_zerocopy_tests SYSTEM PRIVATE test)
 
     add_test(NAME pubsub_zmq_zerocopy_tests COMMAND pubsub_zmq_zerocopy_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_zmq_zerocopy_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_zmq_zerocopy_tests SCAN_DIR ..)
 
-    target_link_libraries(pubsub_zmq_v2_zerocopy_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Celix::dfi ZMQ::lib CZMQ::lib)
-    target_include_directories(pubsub_zmq_v2_zerocopy_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_zmq_v2_zerocopy_tests PRIVATE Celix::pubsub_api Celix::dfi ZMQ::lib CZMQ::lib GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_zmq_v2_zerocopy_tests SYSTEM PRIVATE test)
 
     add_test(NAME pubsub_zmq_v2_zerocopy_tests COMMAND pubsub_zmq_v2_zerocopy_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_zmq_v2_zerocopy_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_zmq_v2_zerocopy_tests SCAN_DIR ..)
@@ -690,8 +689,8 @@ if (BUILD_PUBSUB_PSA_ZMQ)
         pubsub_tst
         pubsub_serializer
         )
-    target_link_libraries(pubsub_zmq_zerocopy_wire_v2_tests PRIVATE Celix::pubsub_api ${CppUTest_LIBRARIES} Jansson Celix::dfi ZMQ::lib CZMQ::lib)
-    target_include_directories(pubsub_zmq_zerocopy_wire_v2_tests SYSTEM PRIVATE ${CppUTest_INCLUDE_DIR} test)
+    target_link_libraries(pubsub_zmq_zerocopy_wire_v2_tests PRIVATE Celix::pubsub_api Jansson Celix::dfi ZMQ::lib CZMQ::lib GTest::gtest GTest::gtest_main)
+    target_include_directories(pubsub_zmq_zerocopy_wire_v2_tests SYSTEM PRIVATE test)
 
     add_test(NAME pubsub_zmq_zerocopy_wire_v2_tests COMMAND pubsub_zmq_zerocopy_wire_v2_tests WORKING_DIRECTORY $<TARGET_PROPERTY:pubsub_zmq_zerocopy_wire_v2_tests,CONTAINER_LOC>)
     setup_target_for_coverage(pubsub_zmq_zerocopy_wire_v2_tests SCAN_DIR ..)
diff --git a/bundles/pubsub/test/test/test_endpoint_runner.cc b/bundles/pubsub/test/test/test_endpoint_runner.cc
index ae65175..2a5b23a 100644
--- a/bundles/pubsub/test/test/test_endpoint_runner.cc
+++ b/bundles/pubsub/test/test/test_endpoint_runner.cc
@@ -17,37 +17,35 @@
  * under the License.
  */
 
+#include <gtest/gtest.h>
+
 #include "celix_api.h"
 #include <unistd.h>
 #include "receive_count_service.h"
 
-#include <CppUTest/TestHarness.h>
-#include <CppUTest/CommandLineTestRunner.h>
-
-int main(int argc, char **argv) {
-    MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
-    int rc = RUN_ALL_TESTS(argc, argv);
-    return rc;
-}
-
-TEST_GROUP(PUBSUB_INT_GROUP) {
-    celix_framework_t *fw = nullptr;
-    celix_bundle_context_t *ctx = nullptr;
-    void setup() override {
+class PubSubIntegrationTestSuite : public ::testing::Test {
+public:
+    PubSubIntegrationTestSuite() {
         celixLauncher_launch("config.properties", &fw);
         ctx = celix_framework_getFrameworkContext(fw);
     }
 
-    void teardown() override {
+    ~PubSubIntegrationTestSuite() override {
         celixLauncher_stop(fw);
         celixLauncher_waitForShutdown(fw);
         celixLauncher_destroy(fw);
-        ctx = nullptr;
-        fw = nullptr;
     }
+
+    PubSubIntegrationTestSuite(const PubSubIntegrationTestSuite&) = delete;
+    PubSubIntegrationTestSuite(PubSubIntegrationTestSuite&&) = delete;
+    PubSubIntegrationTestSuite& operator=(const PubSubIntegrationTestSuite&) = delete;
+    PubSubIntegrationTestSuite& operator=(PubSubIntegrationTestSuite&&) = delete;
+
+    celix_framework_t* fw = nullptr;
+    celix_bundle_context_t* ctx = nullptr;
 };
 
-TEST(PUBSUB_INT_GROUP, recvTest) {
+TEST_F(PubSubIntegrationTestSuite, recvTest) {
     constexpr int TRIES = 50;
     constexpr int TIMEOUT = 250000;
     constexpr int MSG_COUNT = 100;
@@ -67,5 +65,5 @@ TEST(PUBSUB_INT_GROUP, recvTest) {
         }
         usleep(TIMEOUT);
     }
-    CHECK(count >= MSG_COUNT);
+    EXPECT_GE(count, MSG_COUNT);
 }
diff --git a/bundles/pubsub/test/test/test_runner.cc b/bundles/pubsub/test/test/test_runner.cc
index 28975e0..bedf494 100644
--- a/bundles/pubsub/test/test/test_runner.cc
+++ b/bundles/pubsub/test/test/test_runner.cc
@@ -17,68 +17,72 @@
  * under the License.
  */
 
+#include <gtest/gtest.h>
+
 #include "celix_api.h"
 #include <unistd.h>
 #include "receive_count_service.h"
 
-#include <CppUTest/TestHarness.h>
-#include <CppUTest/CommandLineTestRunner.h>
+class PubSubIntegrationTestSuite : public ::testing::Test {
+public:
+    PubSubIntegrationTestSuite() {
+        celixLauncher_launch("config.properties", &fw);
+        ctx = celix_framework_getFrameworkContext(fw);
+    }
 
-int main(int argc, char **argv) {
-    MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
-    int rc = RUN_ALL_TESTS(argc, argv);
-    return rc;
-}
+    ~PubSubIntegrationTestSuite() override {
+        celixLauncher_stop(fw);
+        celixLauncher_waitForShutdown(fw);
+        celixLauncher_destroy(fw);
+    }
 
-TEST_GROUP(PUBSUB_INT_GROUP) {
-        celix_framework_t * fw = NULL;
-        celix_bundle_context_t *ctx = NULL;
-        void setup() override {
-            celixLauncher_launch("config.properties", &fw);
-            ctx = celix_framework_getFrameworkContext(fw);
-        }
+    PubSubIntegrationTestSuite(const PubSubIntegrationTestSuite&) = delete;
+    PubSubIntegrationTestSuite(PubSubIntegrationTestSuite&&) = delete;
+    PubSubIntegrationTestSuite& operator=(const PubSubIntegrationTestSuite&) = delete;
+    PubSubIntegrationTestSuite& operator=(PubSubIntegrationTestSuite&&) = delete;
 
-        void teardown() override {
-            celixLauncher_stop(fw);
-            celixLauncher_waitForShutdown(fw);
-            celixLauncher_destroy(fw);
-            ctx = NULL;
-            fw = NULL;
-        }
+    celix_framework_t* fw = nullptr;
+    celix_bundle_context_t* ctx = nullptr;
 };
 
-TEST_GROUP(PUBSUB_INT_ENV_GROUP) {
-        celix_framework_t * fw = NULL;
-        celix_bundle_context_t *ctx = NULL;
-        void setup() override {
-            setenv("PSA_TCP_STATIC_BIND_URL_FOR_ping", "tcp://localhost:9001", 1);
-            setenv("PSA_TCP_STATIC_CONNECT_URL_FOR_ping", "tcp://localhost:9001", 1);
-            setenv("PSA_UDPMC_STATIC_BIND_PORT_FOR_ping", "9001", 1);
-            setenv("PSA_UDPMC_STATIC_CONNECT_URLS_FOR_ping", "224.100.0.1:9001", 1);
-            setenv("PUBSUB_WEBSOCKET_STATIC_CONNECT_SOCKET_ADDRESSES_FOR_ping", "127.0.0.1:9001", 1);
-            setenv("CELIX_HTTP_ADMIN_LISTENING_PORTS", "9001", 1);
-            setenv("PSA_ZMQ_STATIC_BIND_URL_FOR_ping", "ipc:///tmp/pubsub-envtest", 1);
-            setenv("PSA_ZMQ_STATIC_CONNECT_URL_FOR_ping", "ipc:///tmp/pubsub-envtest", 1);
-
-            celixLauncher_launch("config.properties", &fw);
-            ctx = celix_framework_getFrameworkContext(fw);
-        }
+class PubSubIntegrationWithEnvironmentTestSuite : public ::testing::Test {
+public:
+    PubSubIntegrationWithEnvironmentTestSuite() {
+        setenv("PSA_TCP_STATIC_BIND_URL_FOR_ping", "tcp://localhost:9001", 1);
+        setenv("PSA_TCP_STATIC_CONNECT_URL_FOR_ping", "tcp://localhost:9001", 1);
+        setenv("PSA_UDPMC_STATIC_BIND_PORT_FOR_ping", "9001", 1);
+        setenv("PSA_UDPMC_STATIC_CONNECT_URLS_FOR_ping", "224.100.0.1:9001", 1);
+        setenv("PUBSUB_WEBSOCKET_STATIC_CONNECT_SOCKET_ADDRESSES_FOR_ping", "127.0.0.1:9001", 1);
+        setenv("CELIX_HTTP_ADMIN_LISTENING_PORTS", "9001", 1);
+        setenv("PSA_ZMQ_STATIC_BIND_URL_FOR_ping", "ipc:///tmp/pubsub-envtest", 1);
+        setenv("PSA_ZMQ_STATIC_CONNECT_URL_FOR_ping", "ipc:///tmp/pubsub-envtest", 1);
 
-        void teardown() override {
-            celixLauncher_stop(fw);
-            celixLauncher_waitForShutdown(fw);
-            celixLauncher_destroy(fw);
-            ctx = NULL;
-            fw = NULL;
-            unsetenv("PSA_TCP_STATIC_BIND_URL_FOR_ping");
-            unsetenv("PSA_TCP_STATIC_CONNECT_URL_FOR_ping");
-            unsetenv("PSA_UDPMC_STATIC_BIND_PORT_FOR_ping");
-            unsetenv("PSA_UDPMC_STATIC_CONNECT_URLS_FOR_ping");
-            unsetenv("PUBSUB_WEBSOCKET_STATIC_CONNECT_SOCKET_ADDRESSES_FOR_ping");
-            unsetenv("CELIX_HTTP_ADMIN_LISTENING_PORTS");
-            unsetenv("PSA_ZMQ_STATIC_BIND_URL_FOR_ping");
-            unsetenv("PSA_ZMQ_STATIC_CONNECT_URL_FOR_ping");
-        }
+        celixLauncher_launch("config.properties", &fw);
+        ctx = celix_framework_getFrameworkContext(fw);
+    }
+
+    ~PubSubIntegrationWithEnvironmentTestSuite() override {
+        celixLauncher_stop(fw);
+        celixLauncher_waitForShutdown(fw);
+        celixLauncher_destroy(fw);
+
+        unsetenv("PSA_TCP_STATIC_BIND_URL_FOR_ping");
+        unsetenv("PSA_TCP_STATIC_CONNECT_URL_FOR_ping");
+        unsetenv("PSA_UDPMC_STATIC_BIND_PORT_FOR_ping");
+        unsetenv("PSA_UDPMC_STATIC_CONNECT_URLS_FOR_ping");
+        unsetenv("PUBSUB_WEBSOCKET_STATIC_CONNECT_SOCKET_ADDRESSES_FOR_ping");
+        unsetenv("CELIX_HTTP_ADMIN_LISTENING_PORTS");
+        unsetenv("PSA_ZMQ_STATIC_BIND_URL_FOR_ping");
+        unsetenv("PSA_ZMQ_STATIC_CONNECT_URL_FOR_ping");
+    }
+
+    PubSubIntegrationWithEnvironmentTestSuite(const PubSubIntegrationWithEnvironmentTestSuite&) = delete;
+    PubSubIntegrationWithEnvironmentTestSuite(PubSubIntegrationWithEnvironmentTestSuite&&) = delete;
+    PubSubIntegrationWithEnvironmentTestSuite& operator=(const PubSubIntegrationWithEnvironmentTestSuite&) = delete;
+    PubSubIntegrationWithEnvironmentTestSuite& operator=(PubSubIntegrationWithEnvironmentTestSuite&&) = delete;
+
+    celix_framework_t* fw = nullptr;
+    celix_bundle_context_t* ctx = nullptr;
 };
 
 void receiveTest(celix_bundle_context_t *ctx) {
@@ -101,13 +105,14 @@ void receiveTest(celix_bundle_context_t *ctx) {
         }
         usleep(TIMEOUT);
     }
-    CHECK(count >= MSG_COUNT);
+    EXPECT_GE(count, MSG_COUNT);
 }
 
-TEST(PUBSUB_INT_GROUP, recvTest) {
+TEST_F(PubSubIntegrationTestSuite, recvTest) {
     receiveTest(ctx);
 }
 
-TEST(PUBSUB_INT_ENV_GROUP, recvTest) {
+
+TEST_F(PubSubIntegrationWithEnvironmentTestSuite, recvTest) {
     receiveTest(ctx);
 }

[celix] 02/02: Adds tests for publisher with same topic, but different scopes

Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/additional_pstm_test
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 1a24f81c003f8679fe0de55a71771fa54efb70a9
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Fri May 7 16:28:09 2021 +0200

    Adds tests for publisher with same topic, but different scopes
---
 bundles/pubsub/test/CMakeLists.txt                 | 28 +++++++++
 .../PubSubTopicAndScopeIntegrationTestSuite.cc     | 69 ++++++++++++++++++++++
 2 files changed, 97 insertions(+)

diff --git a/bundles/pubsub/test/CMakeLists.txt b/bundles/pubsub/test/CMakeLists.txt
index a803025..260c7e7 100644
--- a/bundles/pubsub/test/CMakeLists.txt
+++ b/bundles/pubsub/test/CMakeLists.txt
@@ -753,3 +753,31 @@ if (BUILD_PUBSUB_PSA_ZMQ)
     add_test(NAME pstm_deadlock_zmq_v2_test COMMAND pstm_deadlock_zmq_v2_test WORKING_DIRECTORY $<TARGET_PROPERTY:pstm_deadlock_zmq_v2_test,CONTAINER_LOC>)
     setup_target_for_coverage(pstm_deadlock_zmq_v2_test SCAN_DIR ..)
 endif ()
+
+
+if (BUILD_PUBSUB_PSA_ZMQ)
+    #Test suite to test if component with same topic and different scope combinations work
+    add_executable(test_pubsub_topic_and_scope_integration
+            topic_different_scope_test/PubSubTopicAndScopeIntegrationTestSuite.cc
+    )
+    target_link_libraries(test_pubsub_topic_and_scope_integration PRIVATE Celix::framework Celix::pubsub_api GTest::gtest GTest::gtest_main)
+    setup_target_for_coverage(test_pubsub_topic_and_scope_integration SCAN_DIR ..)
+
+    #configure topology manager and pubsub zmq, json serializer and wire protocol v2 bundles
+    celix_get_bundle_file(Celix::pubsub_serializer_json PUBSUB_JSON_BUNDLE_FILE)
+    celix_get_bundle_file(Celix::pubsub_topology_manager PUBSUB_TOPMAN_BUNDLE_FILE)
+    celix_get_bundle_file(Celix::pubsub_admin_zmq_v2 PUBSUB_ZMQ_BUNDLE_FILE)
+    celix_get_bundle_file(Celix::pubsub_protocol_wire_v2 PUBSUB_WIRE_BUNDLE_FILE)
+    add_dependencies(test_pubsub_topic_and_scope_integration
+            celix_pubsub_serializer_json_bundle
+            celix_pubsub_topology_manager_bundle
+            celix_pubsub_admin_zmq_v2_bundle
+            celix_pubsub_protocol_wire_v2_bundle
+    )
+    target_compile_definitions(test_pubsub_topic_and_scope_integration PRIVATE
+            PUBSUB_JSON_BUNDLE_FILE="${PUBSUB_JSON_BUNDLE_FILE}"
+            PUBSUB_TOPMAN_BUNDLE_FILE="${PUBSUB_TOPMAN_BUNDLE_FILE}"
+            PUBSUB_ZMQ_BUNDLE_FILE="${PUBSUB_ZMQ_BUNDLE_FILE}"
+            PUBSUB_WIRE_BUNDLE_FILE="${PUBSUB_WIRE_BUNDLE_FILE}"
+    )
+endif ()
\ No newline at end of file
diff --git a/bundles/pubsub/test/topic_different_scope_test/PubSubTopicAndScopeIntegrationTestSuite.cc b/bundles/pubsub/test/topic_different_scope_test/PubSubTopicAndScopeIntegrationTestSuite.cc
new file mode 100644
index 0000000..f900b4a
--- /dev/null
+++ b/bundles/pubsub/test/topic_different_scope_test/PubSubTopicAndScopeIntegrationTestSuite.cc
@@ -0,0 +1,69 @@
+/*
+ * 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 <gtest/gtest.h>
+#include <thread>
+
+#include "celix/FrameworkFactory.h"
+#include "pubsub/publisher.h"
+
+class PubSubTopicAndScopeIntegrationTestSuite : public ::testing::Test {
+public:
+
+    PubSubTopicAndScopeIntegrationTestSuite() {
+        celix::Properties config {{"CELIX_LOGGING_DEFAULT_ACTIVE_LOG_LEVEL", "trace"}};
+        fw = celix::createFramework(config);
+        ctx = fw->getFrameworkBundleContext();
+
+        EXPECT_GE(ctx->installBundle(PUBSUB_JSON_BUNDLE_FILE), 0);
+        EXPECT_GE(ctx->installBundle(PUBSUB_TOPMAN_BUNDLE_FILE), 0);
+        EXPECT_GE(ctx->installBundle(PUBSUB_ZMQ_BUNDLE_FILE), 0);
+        EXPECT_GE(ctx->installBundle(PUBSUB_WIRE_BUNDLE_FILE), 0);
+    }
+
+
+    std::shared_ptr<celix::Framework> fw{};
+    std::shared_ptr<celix::BundleContext> ctx{};
+};
+
+class TestComponent{};
+
+TEST_F(PubSubTopicAndScopeIntegrationTestSuite, ComponentsWithSameTopicAndDifferentScope) {
+    //When I create publisher with the same topic, but different scope
+    //I expect the pubsub topology manager and a PSA can handle this and the
+    //publisher components will become active. 
+
+    auto& cmp1 = ctx->getDependencyManager()->createComponent<TestComponent>();
+    cmp1.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME)
+            .setFilter("(topic=foo)");
+    cmp1.build();
+    EXPECT_EQ(cmp1.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL);
+
+    auto& cmp2 = ctx->getDependencyManager()->createComponent<TestComponent>();
+    cmp2.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME)
+            .setFilter("(&(topic=foo)(scope=bar))");
+    cmp2.build();
+    EXPECT_EQ(cmp2.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL);
+
+    auto& cmp3 = ctx->getDependencyManager()->createComponent<TestComponent>();
+    cmp3.createServiceDependency<pubsub_publisher>(PUBSUB_PUBLISHER_SERVICE_NAME)
+            .setFilter("(&(topic=foo)(scope=default))");
+    cmp3.build();
+    EXPECT_EQ(cmp3.getState(), celix::dm::ComponentState::TRACKING_OPTIONAL);
+}
\ No newline at end of file