celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [celix] Webserver28 commented on a change in pull request #313: Feature/refactor c dep man service trackers
Date Fri, 22 Jan 2021 05:33:03 GMT

Webserver28 commented on a change in pull request #313:
URL: https://github.com/apache/celix/pull/313#discussion_r561992328



##########
File path: libs/framework/gtest/src/DependencyManagerTestSuite.cc
##########
@@ -63,6 +65,87 @@ TEST_F(DependencyManagerTestSuite, DmCreateComponent) {
     ASSERT_TRUE(celix_dependencyManager_allComponentsActive(mng));
 }
 
+TEST_F(DependencyManagerTestSuite, DmComponentAddRemove) {
+    auto *mng = celix_bundleContext_getDependencyManager(ctx);
+    auto *cmp = celix_dmComponent_create(ctx, "test1");
+    celix_dependencyManager_add(mng, cmp);
+    ASSERT_EQ(1, celix_dependencyManager_nrOfComponents(mng));
+
+    celix_dependencyManager_remove(mng, cmp);
+    ASSERT_EQ(0, celix_dependencyManager_nrOfComponents(mng));
+
+    auto *cmp2 = celix_dmComponent_create(ctx, "test2");
+    auto *cmp3 = celix_dmComponent_create(ctx, "test3");
+    celix_dependencyManager_add(mng, cmp2);
+    celix_dependencyManager_add(mng, cmp3);
+    ASSERT_EQ(2, celix_dependencyManager_nrOfComponents(mng));
+
+    celix_dependencyManager_removeAllComponents(mng);
+    ASSERT_EQ(0, celix_dependencyManager_nrOfComponents(mng));
+}
+
+
+TEST_F(DependencyManagerTestSuite, DmComponentAddRemoveAsync) {
+    auto *mng = celix_bundleContext_getDependencyManager(ctx);
+    auto *cmp1 = celix_dmComponent_create(ctx, "test1");
+    celix_dependencyManager_addAsync(mng, cmp1);
+    celix_dependencyManager_wait(mng);
+    EXPECT_EQ(1, celix_dependencyManager_nrOfComponents(mng));
+
+    std::atomic<std::size_t> count{0};
+    auto cb = [](void *data) {
+        auto* c = static_cast<std::atomic<std::size_t>*>(data);
+        c->fetch_add(1);
+    };
+
+    celix_dependencyManager_removeAsync(mng, cmp1, &count, cb);
+    celix_dependencyManager_wait(mng);
+    EXPECT_EQ(0, celix_dependencyManager_nrOfComponents(mng));
+    EXPECT_EQ(1, count.load());
+}
+
+TEST_F(DependencyManagerTestSuite, DmComponentRemoveAllAsync) {
+    auto *mng = celix_bundleContext_getDependencyManager(ctx);
+    auto *cmp1 = celix_dmComponent_create(ctx, "test1");
+    auto *cmp2 = celix_dmComponent_create(ctx, "test2");
+    celix_dependencyManager_add(mng, cmp1);
+    celix_dependencyManager_add(mng, cmp2);
+    EXPECT_EQ(2, celix_dependencyManager_nrOfComponents(mng));
+
+    std::atomic<std::size_t> count{0};
+    celix_dependencyManager_removeAllComponentsAsync(mng, &count, [](void *data) {
+        auto* c = static_cast<std::atomic<std::size_t>*>(data);
+        c->fetch_add(1);
+    });
+    celix_dependencyManager_wait(mng);
+    EXPECT_EQ(0, celix_dependencyManager_nrOfComponents(mng));
+    EXPECT_EQ(1, count.load());
+}
+
+TEST_F(DependencyManagerTestSuite, CDmGetInfo) {
+    auto* mng = celix_bundleContext_getDependencyManager(ctx);
+    auto* cmp = celix_dmComponent_create(ctx, "test1");
+
+    auto* p = celix_properties_create();
+    celix_properties_set(p, "key", "value");
+    celix_dmComponent_addInterface(cmp, "test-interface", nullptr, (void*)0x42, p);

Review comment:
       Magic number, maybe make variable or add comments




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message