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 2020/03/08 20:08:13 UTC
[celix] 01/02: Refactors some celix framework test from cpputest to
gtest.
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/framework_racecondition
in repository https://gitbox.apache.org/repos/asf/celix.git
commit aad0ecd8a173bcea08c2d57f6d4442bc116fbcbc
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Fri Mar 6 11:35:12 2020 +0100
Refactors some celix framework test from cpputest to gtest.
---
libs/framework/CMakeLists.txt | 4 +-
libs/framework/{test => gtest}/CMakeLists.txt | 18 +-
.../framework/{test => gtest}/config.properties.in | 0
.../{test => gtest}/framework1.properties.in | 0
.../{test => gtest}/framework2.properties.in | 0
.../src}/bundle_context_bundles_tests.cpp | 224 ++++++++--------
.../src}/bundle_context_services_test.cpp | 281 +++++++++++----------
libs/framework/{test => gtest/src}/dm_tests.cpp | 38 +--
.../src}/multiple_frameworks_test.cpp | 25 +-
libs/framework/{test => gtest/src}/nop_activator.c | 0
libs/framework/{test => gtest/src}/run_tests.cpp | 10 +-
.../{test => gtest/src}/single_framework_test.cpp | 41 +--
.../{test => gtest}/subdir/CMakeLists.txt | 0
libs/framework/{test => gtest}/subdir/src/foo.c | 0
14 files changed, 325 insertions(+), 316 deletions(-)
diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt
index 8297a97..a8d551a 100644
--- a/libs/framework/CMakeLists.txt
+++ b/libs/framework/CMakeLists.txt
@@ -52,9 +52,7 @@ add_library(Celix::framework ALIAS framework)
if (ENABLE_TESTING)
- find_package(CppUTest REQUIRED)
- include_directories(SYSTEM PRIVATE ${CPPUTEST_INCLUDE_DIR})
- add_subdirectory(test)
+ add_subdirectory(gtest)
endif()
diff --git a/libs/framework/test/CMakeLists.txt b/libs/framework/gtest/CMakeLists.txt
similarity index 84%
rename from libs/framework/test/CMakeLists.txt
rename to libs/framework/gtest/CMakeLists.txt
index 33a7428..33cb7b9 100644
--- a/libs/framework/test/CMakeLists.txt
+++ b/libs/framework/gtest/CMakeLists.txt
@@ -18,10 +18,10 @@
add_celix_bundle(simple_test_bundle1 NO_ACTIVATOR VERSION 1.0.0)
add_celix_bundle(simple_test_bundle2 NO_ACTIVATOR VERSION 1.0.0)
add_celix_bundle(simple_test_bundle3 NO_ACTIVATOR VERSION 1.0.0)
-add_celix_bundle(bundle_with_exception SOURCES nop_activator.c VERSION 1.0.0)
+add_celix_bundle(bundle_with_exception SOURCES src/nop_activator.c VERSION 1.0.0)
add_subdirectory(subdir) #simple_test_bundle4, simple_test_bundle5 and sublib
-add_celix_bundle(unresolveable_bundle SOURCES nop_activator.c VERSION 1.0.0)
+add_celix_bundle(unresolveable_bundle SOURCES src/nop_activator.c VERSION 1.0.0)
target_link_libraries(unresolveable_bundle PRIVATE "-L${CMAKE_CURRENT_BINARY_DIR}/subdir -lsublib")
if(NOT APPLE)
set_target_properties(unresolveable_bundle PROPERTIES LINK_FLAGS -Wl,--no-as-needed)
@@ -29,15 +29,15 @@ endif()
add_dependencies(unresolveable_bundle sublib)
add_executable(test_framework
- run_tests.cpp
- single_framework_test.cpp
- multiple_frameworks_test.cpp
- bundle_context_bundles_tests.cpp
- bundle_context_services_test.cpp
- dm_tests.cpp
+ src/run_tests.cpp
+ src/single_framework_test.cpp
+ src/multiple_frameworks_test.cpp
+ src/bundle_context_bundles_tests.cpp
+ src/bundle_context_services_test.cpp
+ src/dm_tests.cpp
)
-target_link_libraries(test_framework Celix::framework CURL::libcurl ${CPPUTEST_LIBRARY})
+target_link_libraries(test_framework Celix::framework CURL::libcurl GTest::GTest)
add_dependencies(test_framework simple_test_bundle1_bundle simple_test_bundle2_bundle simple_test_bundle3_bundle simple_test_bundle4_bundle simple_test_bundle5_bundle bundle_with_exception_bundle unresolveable_bundle_bundle)
target_include_directories(test_framework PRIVATE ../src)
diff --git a/libs/framework/test/config.properties.in b/libs/framework/gtest/config.properties.in
similarity index 100%
rename from libs/framework/test/config.properties.in
rename to libs/framework/gtest/config.properties.in
diff --git a/libs/framework/test/framework1.properties.in b/libs/framework/gtest/framework1.properties.in
similarity index 100%
rename from libs/framework/test/framework1.properties.in
rename to libs/framework/gtest/framework1.properties.in
diff --git a/libs/framework/test/framework2.properties.in b/libs/framework/gtest/framework2.properties.in
similarity index 100%
rename from libs/framework/test/framework2.properties.in
rename to libs/framework/gtest/framework2.properties.in
diff --git a/libs/framework/test/bundle_context_bundles_tests.cpp b/libs/framework/gtest/src/bundle_context_bundles_tests.cpp
similarity index 67%
rename from libs/framework/test/bundle_context_bundles_tests.cpp
rename to libs/framework/gtest/src/bundle_context_bundles_tests.cpp
index 72a4891..7295367 100644
--- a/libs/framework/test/bundle_context_bundles_tests.cpp
+++ b/libs/framework/gtest/src/bundle_context_bundles_tests.cpp
@@ -17,6 +17,8 @@
* under the License.
*/
+#include <gtest/gtest.h>
+
#include <thread>
#include <chrono>
#include <iostream>
@@ -27,14 +29,11 @@
#include "celix_api.h"
-#include <CppUTest/TestHarness.h>
-#include <CppUTest/CommandLineTestRunner.h>
-
-
-TEST_GROUP(CelixBundleContextBundlesTests) {
- framework_t* fw = nullptr;
- bundle_context_t *ctx = nullptr;
- properties_t *properties = nullptr;
+class CelixBundleContextBundlesTests : public ::testing::Test {
+public:
+ celix_framework_t* fw = nullptr;
+ celix_bundle_context_t *ctx = nullptr;
+ celix_properties_t *properties = nullptr;
const char * const TEST_BND1_LOC = "simple_test_bundle1.zip";
const char * const TEST_BND2_LOC = "simple_test_bundle2.zip";
@@ -44,7 +43,7 @@ TEST_GROUP(CelixBundleContextBundlesTests) {
const char * const TEST_BND_WITH_EXCEPTION_LOC = "bundle_with_exception.zip";
const char * const TEST_BND_UNRESOLVEABLE_LOC = "unresolveable_bundle.zip";
- void setup() {
+ CelixBundleContextBundlesTests() {
properties = properties_create();
properties_set(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", "true");
properties_set(properties, "org.osgi.framework.storage.clean", "onFirstInit");
@@ -53,35 +52,42 @@ TEST_GROUP(CelixBundleContextBundlesTests) {
fw = celix_frameworkFactory_createFramework(properties);
ctx = framework_getContext(fw);
}
-
- void teardown() {
+
+ ~CelixBundleContextBundlesTests() override {
celix_frameworkFactory_destroyFramework(fw);
}
+
+ CelixBundleContextBundlesTests(CelixBundleContextBundlesTests&&) = delete;
+ CelixBundleContextBundlesTests(const CelixBundleContextBundlesTests&) = delete;
+ CelixBundleContextBundlesTests& operator=(CelixBundleContextBundlesTests&&) = delete;
+ CelixBundleContextBundlesTests& operator=(const CelixBundleContextBundlesTests&) = delete;
};
-TEST(CelixBundleContextBundlesTests, installBundlesTest) {
+
+
+TEST_F(CelixBundleContextBundlesTests, installBundlesTest) {
long bndId = celix_bundleContext_installBundle(ctx, "non-existing.zip", true);
- CHECK(bndId < 0);
+ ASSERT_TRUE(bndId < 0);
bndId = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true);
- CHECK(bndId >= 0);
+ ASSERT_TRUE(bndId >= 0);
bndId = celix_bundleContext_installBundle(ctx, TEST_BND4_LOC, true); //not loaded in subdir
- CHECK(bndId < 0);
+ ASSERT_TRUE(bndId < 0);
setenv(CELIX_BUNDLES_PATH_NAME, "subdir", true);
bndId = celix_bundleContext_installBundle(ctx, TEST_BND4_LOC, true); //subdir now part of CELIX_BUNDLES_PATH
- CHECK(bndId >= 0);
+ ASSERT_TRUE(bndId >= 0);
}
-TEST(CelixBundleContextBundlesTests, useBundlesTest) {
+TEST_F(CelixBundleContextBundlesTests, useBundlesTest) {
int count = 0;
auto use = [](void *handle, const bundle_t *bnd) {
int *c = (int*)handle;
*c += 1;
long id = celix_bundle_getId(bnd);
- CHECK(id >= 0);
+ ASSERT_TRUE(id >= 0);
};
celix_bundleContext_useBundles(ctx, &count, use);
@@ -89,193 +95,193 @@ TEST(CelixBundleContextBundlesTests, useBundlesTest) {
count = 0;
celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true);
celix_bundleContext_useBundles(ctx, &count, use);
- CHECK_EQUAL(1, count);
+ ASSERT_EQ(1, count);
};
-TEST(CelixBundleContextBundlesTests, installAndUninstallBundlesTest) {
+TEST_F(CelixBundleContextBundlesTests, installAndUninstallBundlesTest) {
//install bundles
long bndId1 = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true);
long bndId2 = celix_bundleContext_installBundle(ctx, TEST_BND2_LOC, false);
long bndId3 = celix_bundleContext_installBundle(ctx, TEST_BND3_LOC, true);
- CHECK_TRUE(bndId1 >= 0L);
- CHECK_TRUE(bndId2 >= 0L);
- CHECK_TRUE(bndId3 >= 0L);
+ ASSERT_TRUE(bndId1 >= 0L);
+ ASSERT_TRUE(bndId2 >= 0L);
+ ASSERT_TRUE(bndId3 >= 0L);
- CHECK_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId1));
- CHECK_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId2));
- CHECK_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId3));
+ ASSERT_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId1));
+ ASSERT_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId2));
+ ASSERT_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId3));
- CHECK_TRUE(celix_bundleContext_isBundleActive(ctx, bndId1));
- CHECK_FALSE(celix_bundleContext_isBundleActive(ctx, bndId2)); //not auto started
- CHECK_TRUE(celix_bundleContext_isBundleActive(ctx, bndId3));
+ ASSERT_TRUE(celix_bundleContext_isBundleActive(ctx, bndId1));
+ ASSERT_FALSE(celix_bundleContext_isBundleActive(ctx, bndId2)); //not auto started
+ ASSERT_TRUE(celix_bundleContext_isBundleActive(ctx, bndId3));
//uninstall bundles
- CHECK_TRUE(celix_bundleContext_uninstallBundle(ctx, bndId1));
- CHECK_TRUE(celix_bundleContext_uninstallBundle(ctx, bndId2));
- CHECK_TRUE(celix_bundleContext_uninstallBundle(ctx, bndId3));
+ ASSERT_TRUE(celix_bundleContext_uninstallBundle(ctx, bndId1));
+ ASSERT_TRUE(celix_bundleContext_uninstallBundle(ctx, bndId2));
+ ASSERT_TRUE(celix_bundleContext_uninstallBundle(ctx, bndId3));
- CHECK_FALSE(celix_bundleContext_isBundleInstalled(ctx, bndId1));
- CHECK_FALSE(celix_bundleContext_isBundleInstalled(ctx, bndId2));
- CHECK_FALSE(celix_bundleContext_isBundleInstalled(ctx, bndId3));
+ ASSERT_FALSE(celix_bundleContext_isBundleInstalled(ctx, bndId1));
+ ASSERT_FALSE(celix_bundleContext_isBundleInstalled(ctx, bndId2));
+ ASSERT_FALSE(celix_bundleContext_isBundleInstalled(ctx, bndId3));
- CHECK_FALSE(celix_bundleContext_isBundleActive(ctx, bndId1)); //not uninstall -> not active
- CHECK_FALSE(celix_bundleContext_isBundleActive(ctx, bndId2));
- CHECK_FALSE(celix_bundleContext_isBundleActive(ctx, bndId3));
+ ASSERT_FALSE(celix_bundleContext_isBundleActive(ctx, bndId1)); //not uninstall -> not active
+ ASSERT_FALSE(celix_bundleContext_isBundleActive(ctx, bndId2));
+ ASSERT_FALSE(celix_bundleContext_isBundleActive(ctx, bndId3));
//reinstall bundles
long bndId4 = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true);
long bndId5 = celix_bundleContext_installBundle(ctx, TEST_BND2_LOC, false);
long bndId6 = celix_bundleContext_installBundle(ctx, TEST_BND3_LOC, true);
- CHECK_TRUE(bndId4 >= 0L);
- CHECK_FALSE(bndId1 == bndId4); //not new id
- CHECK_TRUE(bndId5 >= 0L);
- CHECK_FALSE(bndId2 == bndId5); //not new id
- CHECK_TRUE(bndId6 >= 0L);
- CHECK_FALSE(bndId5 == bndId6); //not new id
+ ASSERT_TRUE(bndId4 >= 0L);
+ ASSERT_FALSE(bndId1 == bndId4); //not new id
+ ASSERT_TRUE(bndId5 >= 0L);
+ ASSERT_FALSE(bndId2 == bndId5); //not new id
+ ASSERT_TRUE(bndId6 >= 0L);
+ ASSERT_FALSE(bndId5 == bndId6); //not new id
}
-TEST(CelixBundleContextBundlesTests, startBundleWithException) {
+TEST_F(CelixBundleContextBundlesTests, startBundleWithException) {
long bndId = celix_bundleContext_installBundle(ctx, TEST_BND_WITH_EXCEPTION_LOC, true);
- CHECK(bndId > 0); //bundle is installed, but not started
+ ASSERT_TRUE(bndId > 0); //bundle is installed, but not started
bool called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void */*handle*/, const celix_bundle_t *bnd) {
auto state = celix_bundle_getState(bnd);
- CHECK_EQUAL(state, OSGI_FRAMEWORK_BUNDLE_RESOLVED);
+ ASSERT_EQ(state, OSGI_FRAMEWORK_BUNDLE_RESOLVED);
});
- CHECK_TRUE(called);
+ ASSERT_TRUE(called);
}
-TEST(CelixBundleContextBundlesTests, startUnresolveableBundle) {
+TEST_F(CelixBundleContextBundlesTests, startUnresolveableBundle) {
long bndId = celix_bundleContext_installBundle(ctx, TEST_BND_UNRESOLVEABLE_LOC, true);
- CHECK(bndId > 0); //bundle is installed, but not resolved
+ ASSERT_TRUE(bndId > 0); //bundle is installed, but not resolved
bool called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void *, const celix_bundle_t *bnd) {
auto state = celix_bundle_getState(bnd);
- CHECK_EQUAL(OSGI_FRAMEWORK_BUNDLE_INSTALLED, state);
+ ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_INSTALLED, state);
});
- CHECK_TRUE(called);
+ ASSERT_TRUE(called);
celix_bundleContext_startBundle(ctx, bndId);
called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void *, const celix_bundle_t *bnd) {
auto state = celix_bundle_getState(bnd);
- CHECK_EQUAL(OSGI_FRAMEWORK_BUNDLE_INSTALLED, state);
+ ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_INSTALLED, state);
});
- CHECK_TRUE(called);
+ ASSERT_TRUE(called);
}
-TEST(CelixBundleContextBundlesTests, useBundleTest) {
+TEST_F(CelixBundleContextBundlesTests, useBundleTest) {
int count = 0;
bool called = celix_bundleContext_useBundle(ctx, 0, &count, [](void *handle, const bundle_t *bnd) {
int *c = (int*)handle;
*c += 1;
long id = celix_bundle_getId(bnd);
- CHECK_EQUAL(0, id);
+ ASSERT_EQ(0, id);
});
- CHECK_TRUE(called);
- CHECK_EQUAL(1, count);
+ ASSERT_TRUE(called);
+ ASSERT_EQ(1, count);
};
-TEST(CelixBundleContextBundlesTests, StopStartTest) {
+TEST_F(CelixBundleContextBundlesTests, StopStartTest) {
long bndId1 = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true);
long bndId2 = celix_bundleContext_installBundle(ctx, TEST_BND2_LOC, true);
long bndId3 = celix_bundleContext_installBundle(ctx, TEST_BND3_LOC, true);
- CHECK_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId1));
- CHECK_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId2));
- CHECK_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId3));
- CHECK_FALSE(celix_bundleContext_isBundleInstalled(ctx, 600 /*non existing*/));
+ ASSERT_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId1));
+ ASSERT_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId2));
+ ASSERT_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId3));
+ ASSERT_FALSE(celix_bundleContext_isBundleInstalled(ctx, 600 /*non existing*/));
celix_array_list_t *ids = celix_bundleContext_listBundles(ctx);
size_t size = arrayList_size(ids);
- CHECK_EQUAL(3, size);
+ ASSERT_EQ(3, size);
int count = 0;
celix_bundleContext_useBundles(ctx, &count, [](void *handle, const celix_bundle_t *bnd) {
auto *c = (int*)handle;
- CHECK_EQUAL(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
+ ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
*c += 1;
});
- CHECK_EQUAL(3, count);
+ ASSERT_EQ(3, count);
for (size_t i = 0; i < size; ++i) {
bool stopped = celix_bundleContext_stopBundle(ctx, celix_arrayList_getLong(ids, (int)i));
- CHECK_TRUE(stopped);
+ ASSERT_TRUE(stopped);
}
bool stopped = celix_bundleContext_stopBundle(ctx, 42 /*non existing*/);
- CHECK_FALSE(stopped);
+ ASSERT_FALSE(stopped);
bool started = celix_bundleContext_startBundle(ctx, 42 /*non existing*/);
- CHECK_FALSE(started);
+ ASSERT_FALSE(started);
for (size_t i = 0; i < size; ++i) {
- bool started = celix_bundleContext_startBundle(ctx, celix_arrayList_getLong(ids, (int)i));
- CHECK_TRUE(started);
+ started = celix_bundleContext_startBundle(ctx, celix_arrayList_getLong(ids, (int)i));
+ ASSERT_TRUE(started);
}
count = 0;
celix_bundleContext_useBundles(ctx, &count, [](void *handle, const celix_bundle_t *bnd) {
auto *c = (int*)handle;
- CHECK_EQUAL(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
+ ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
*c += 1;
});
- CHECK_EQUAL(3, count);
+ ASSERT_EQ(3, count);
celix_arrayList_destroy(ids);
}
-TEST(CelixBundleContextBundlesTests, DoubleStopTest) {
+TEST_F(CelixBundleContextBundlesTests, DoubleStopTest) {
long bndId = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true);
- CHECK_TRUE(bndId > 0);
- CHECK_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId));
+ ASSERT_TRUE(bndId > 0);
+ ASSERT_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId));
bool called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void *, const celix_bundle_t *bnd) {
- CHECK_EQUAL(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
+ ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
});
- CHECK_TRUE(called);
+ ASSERT_TRUE(called);
//first
celix_bundleContext_stopBundle(ctx, bndId);
called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void *, const celix_bundle_t *bnd) {
- CHECK_EQUAL(OSGI_FRAMEWORK_BUNDLE_RESOLVED, celix_bundle_getState(bnd));
+ ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_RESOLVED, celix_bundle_getState(bnd));
});
- CHECK_TRUE(called);
+ ASSERT_TRUE(called);
//second
celix_bundleContext_stopBundle(ctx, bndId);
called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void *, const celix_bundle_t *bnd) {
- CHECK_EQUAL(OSGI_FRAMEWORK_BUNDLE_RESOLVED, celix_bundle_getState(bnd));
+ ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_RESOLVED, celix_bundle_getState(bnd));
});
- CHECK_TRUE(called);
+ ASSERT_TRUE(called);
//first
celix_bundleContext_startBundle(ctx, bndId);
called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void *, const celix_bundle_t *bnd) {
- CHECK_EQUAL(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
+ ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
});
- CHECK_TRUE(called);
+ ASSERT_TRUE(called);
//second
celix_bundleContext_startBundle(ctx, bndId);
called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void *, const celix_bundle_t *bnd) {
- CHECK_EQUAL(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
+ ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_ACTIVE, celix_bundle_getState(bnd));
});
- CHECK_TRUE(called);
+ ASSERT_TRUE(called);
}
-TEST(CelixBundleContextBundlesTests, trackBundlesTest) {
+TEST_F(CelixBundleContextBundlesTests, trackBundlesTest) {
struct data {
int count{0};
std::mutex mutex{};
@@ -285,7 +291,7 @@ TEST(CelixBundleContextBundlesTests, trackBundlesTest) {
auto started = [](void *handle, const bundle_t *bnd) {
struct data *d = static_cast<struct data*>(handle);
- CHECK(bnd != nullptr);
+ ASSERT_TRUE(bnd != nullptr);
d->mutex.lock();
d->count += 1;
d->cond.notify_all();
@@ -293,7 +299,7 @@ TEST(CelixBundleContextBundlesTests, trackBundlesTest) {
};
auto stopped = [](void *handle, const bundle_t *bnd) {
struct data *d = static_cast<struct data*>(handle);
- CHECK(bnd != nullptr);
+ ASSERT_TRUE(bnd != nullptr);
d->mutex.lock();
d->count -= 1;
d->cond.notify_all();
@@ -301,28 +307,28 @@ TEST(CelixBundleContextBundlesTests, trackBundlesTest) {
};
long trackerId = celix_bundleContext_trackBundles(ctx, static_cast<void*>(&data), started, stopped);
- CHECK_EQUAL(0, data.count); //note default framework bundle is not tracked
+ ASSERT_EQ(0, data.count); //note default framework bundle is not tracked
long bundleId1 = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true);
- CHECK(bundleId1 >= 0);
+ ASSERT_TRUE(bundleId1 >= 0);
{
std::unique_lock<std::mutex> lock{data.mutex};
data.cond.wait_for(lock, std::chrono::milliseconds(100), [&]{return data.count == 2;});
}
- CHECK_EQUAL(1, data.count);
+ ASSERT_EQ(1, data.count);
long bundleId2 = celix_bundleContext_installBundle(ctx, TEST_BND2_LOC, true);
- CHECK(bundleId2 >= 0);
+ ASSERT_TRUE(bundleId2 >= 0);
{
std::unique_lock<std::mutex> lock{data.mutex};
data.cond.wait_for(lock, std::chrono::milliseconds(100), [&]{return data.count == 3;});
}
- CHECK_EQUAL(2, data.count);
+ ASSERT_EQ(2, data.count);
celix_bundleContext_uninstallBundle(ctx, bundleId2);
{
@@ -330,31 +336,31 @@ TEST(CelixBundleContextBundlesTests, trackBundlesTest) {
data.cond.wait_for(lock, std::chrono::milliseconds(100), [&]{return data.count == 2;});
}
- CHECK_EQUAL(2, data.count);
+ ASSERT_EQ(2, data.count);
long bundleId3 = celix_bundleContext_installBundle(ctx, TEST_BND3_LOC, true);
- CHECK(bundleId3 >= 0);
+ ASSERT_TRUE(bundleId3 >= 0);
{
std::unique_lock<std::mutex> lock{data.mutex};
data.cond.wait_for(lock, std::chrono::milliseconds(100), [&]{return data.count == 3;});
}
- CHECK_EQUAL(3, data.count);
+ ASSERT_EQ(3, data.count);
bundleId2 = celix_bundleContext_installBundle(ctx, TEST_BND2_LOC, true);
- CHECK(bundleId3 >= 0);
+ ASSERT_TRUE(bundleId3 >= 0);
{
std::unique_lock<std::mutex> lock{data.mutex};
data.cond.wait_for(lock, std::chrono::milliseconds(100), [&]{return data.count == 4;});
}
- CHECK_EQUAL(4, data.count);
+ ASSERT_EQ(4, data.count);
celix_bundleContext_stopTracker(ctx, trackerId);
};
-TEST(CelixBundleContextBundlesTests, useBundlesConcurrentTest) {
+TEST_F(CelixBundleContextBundlesTests, useBundlesConcurrentTest) {
struct data {
std::mutex mutex{};
@@ -365,7 +371,7 @@ TEST(CelixBundleContextBundlesTests, useBundlesConcurrentTest) {
struct data data{};
auto use = [](void *handle, const bundle_t *bnd) {
- CHECK(bnd != nullptr);
+ ASSERT_TRUE(bnd != nullptr);
struct data *d = static_cast<struct data*>(handle);
@@ -380,7 +386,7 @@ TEST(CelixBundleContextBundlesTests, useBundlesConcurrentTest) {
auto call = [&] {
bool called = celix_bundleContext_useBundle(ctx, bndId, &data, use);
- CHECK(called);
+ ASSERT_TRUE(called);
};
std::thread useThread{call};
@@ -413,7 +419,7 @@ TEST(CelixBundleContextBundlesTests, useBundlesConcurrentTest) {
std::cout << "uninstall thread joined" << std::endl;
};
-TEST(CelixBundleContextBundlesTests, bundleInfoTests) {
+TEST_F(CelixBundleContextBundlesTests, bundleInfoTests) {
struct data {
int provideCount{0};
int requestedCount{0};
@@ -431,18 +437,18 @@ TEST(CelixBundleContextBundlesTests, bundleInfoTests) {
};
bool called = celix_bundleContext_useBundle(ctx, 0, &data, updateCountFp);
- CHECK_TRUE(called);
- CHECK_EQUAL(0, data.provideCount);
- CHECK_EQUAL(0, data.requestedCount);
+ ASSERT_TRUE(called);
+ ASSERT_EQ(0, data.provideCount);
+ ASSERT_EQ(0, data.requestedCount);
long svcId = celix_bundleContext_registerService(ctx, (void*)0x42, "NopService", NULL);
long trackerId = celix_bundleContext_trackServices(ctx, "AService", NULL, NULL, NULL);
called = celix_bundleContext_useBundle(ctx, 0, &data, updateCountFp);
- CHECK_TRUE(called);
- CHECK_EQUAL(1, data.provideCount);
- CHECK_EQUAL(1, data.requestedCount);
+ ASSERT_TRUE(called);
+ ASSERT_EQ(1, data.provideCount);
+ ASSERT_EQ(1, data.requestedCount);
celix_bundleContext_unregisterService(ctx, svcId);
celix_bundleContext_stopTracker(ctx, trackerId);
diff --git a/libs/framework/test/bundle_context_services_test.cpp b/libs/framework/gtest/src/bundle_context_services_test.cpp
similarity index 77%
rename from libs/framework/test/bundle_context_services_test.cpp
rename to libs/framework/gtest/src/bundle_context_services_test.cpp
index 262cae2..fa650a4 100644
--- a/libs/framework/test/bundle_context_services_test.cpp
+++ b/libs/framework/gtest/src/bundle_context_services_test.cpp
@@ -17,14 +17,15 @@
* under the License.
*/
+#include <gtest/gtest.h>
+
+
#include <thread>
#include <chrono>
#include <iostream>
#include <mutex>
#include <condition_variable>
-#include <zconf.h>
#include <string.h>
-#include <map>
#include <future>
#include "celix_api.h"
@@ -32,18 +33,13 @@
#include "celix_service_factory.h"
#include "service_tracker_private.h"
+class CelixBundleContextServicesTests : public ::testing::Test {
+public:
+ celix_framework_t* fw = nullptr;
+ celix_bundle_context_t *ctx = nullptr;
+ celix_properties_t *properties = nullptr;
-#include <CppUTest/TestHarness.h>
-#include <CppUTest/CommandLineTestRunner.h>
-
-
-
-TEST_GROUP(CelixBundleContextServicesTests) {
- framework_t* fw = nullptr;
- bundle_context_t *ctx = nullptr;
- properties_t *properties = nullptr;
-
- void setup() {
+ CelixBundleContextServicesTests() {
properties = properties_create();
properties_set(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", "true");
properties_set(properties, "org.osgi.framework.storage.clean", "onFirstInit");
@@ -53,12 +49,17 @@ TEST_GROUP(CelixBundleContextServicesTests) {
ctx = framework_getContext(fw);
}
- void teardown() {
+ ~CelixBundleContextServicesTests() override {
celix_frameworkFactory_destroyFramework(fw);
}
+
+ CelixBundleContextServicesTests(CelixBundleContextServicesTests&&) = delete;
+ CelixBundleContextServicesTests(const CelixBundleContextServicesTests&) = delete;
+ CelixBundleContextServicesTests& operator=(CelixBundleContextServicesTests&&) = delete;
+ CelixBundleContextServicesTests& operator=(const CelixBundleContextServicesTests&) = delete;
};
-TEST(CelixBundleContextServicesTests, registerService) {
+TEST_F(CelixBundleContextServicesTests, registerService) {
struct calc {
int (*calc)(int);
};
@@ -70,18 +71,18 @@ TEST(CelixBundleContextServicesTests, registerService) {
};
long svcId = celix_bundleContext_registerService(ctx, &svc, calcName, nullptr);
- CHECK(svcId >= 0);
+ ASSERT_TRUE(svcId >= 0);
celix_bundleContext_unregisterService(ctx, svcId);
};
-TEST(CelixBundleContextServicesTests, incorrectUnregisterCalls) {
+TEST_F(CelixBundleContextServicesTests, incorrectUnregisterCalls) {
celix_bundleContext_unregisterService(ctx, 1);
celix_bundleContext_unregisterService(ctx, 2);
celix_bundleContext_unregisterService(ctx, -1);
celix_bundleContext_unregisterService(ctx, -2);
};
-TEST(CelixBundleContextServicesTests, registerMultipleAndUseServices) {
+TEST_F(CelixBundleContextServicesTests, registerMultipleAndUseServices) {
struct calc {
int (*calc)(int);
};
@@ -93,16 +94,16 @@ TEST(CelixBundleContextServicesTests, registerMultipleAndUseServices) {
};
long svcId1 = celix_bundleContext_registerService(ctx, &svc, calcName, nullptr);
- CHECK(svcId1 >= 0);
+ ASSERT_TRUE(svcId1 >= 0);
long svcId2 = celix_bundleContext_registerService(ctx, &svc, calcName, nullptr);
- CHECK(svcId2 >= 0);
+ ASSERT_TRUE(svcId2 >= 0);
long svcId3 = celix_bundleContext_registerService(ctx, &svc, calcName, nullptr);
- CHECK(svcId3 >= 0);
+ ASSERT_TRUE(svcId3 >= 0);
auto use = [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
int *total = static_cast<int*>(handle);
struct calc *calc = static_cast<struct calc*>(svc);
int tmp = calc->calc(1);
@@ -111,24 +112,24 @@ TEST(CelixBundleContextServicesTests, registerMultipleAndUseServices) {
int total = 0;
celix_bundleContext_useServices(ctx, "calc", &total, use);
- CHECK_EQUAL(42 * 3, total);
+ ASSERT_EQ(42 * 3, total);
celix_bundleContext_unregisterService(ctx, svcId3);
total = 0;
celix_bundleContext_useServices(ctx, "calc", &total, use);
- CHECK_EQUAL(42 * 2, total);
+ ASSERT_EQ(42 * 2, total);
total = 0;
bool called = celix_bundleContext_useService(ctx, "calc", &total, use);
- CHECK(called);
- CHECK_EQUAL(42, total);
+ ASSERT_TRUE(called);
+ ASSERT_EQ(42, total);
celix_bundleContext_unregisterService(ctx, svcId1);
celix_bundleContext_unregisterService(ctx, svcId2);
};
-TEST(CelixBundleContextServicesTests, registerAndUseService) {
+TEST_F(CelixBundleContextServicesTests, registerAndUseService) {
struct calc {
int (*calc)(int);
};
@@ -140,18 +141,18 @@ TEST(CelixBundleContextServicesTests, registerAndUseService) {
};
long svcId = celix_bundleContext_registerService(ctx, &svc, calcName, nullptr);
- CHECK(svcId >= 0);
+ ASSERT_TRUE(svcId >= 0);
int result = 0;
bool called = celix_bundleContext_useServiceWithId(ctx, svcId, calcName, &result, [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
int *result = static_cast<int*>(handle);
struct calc *calc = static_cast<struct calc*>(svc);
int tmp = calc->calc(2);
*result = tmp;
});
- CHECK(called);
- CHECK_EQUAL(84, result);
+ ASSERT_TRUE(called);
+ ASSERT_EQ(84, result);
result = 0;
long nonExistingSvcId = 101;
@@ -161,13 +162,13 @@ TEST(CelixBundleContextServicesTests, registerAndUseService) {
int tmp = calc->calc(2);
*result = tmp;
});
- CHECK(!called);
- CHECK_EQUAL(0, result); //e.g. not called
+ ASSERT_TRUE(!called);
+ ASSERT_EQ(0, result); //e.g. not called
celix_bundleContext_unregisterService(ctx, svcId);
};
-TEST(CelixBundleContextServicesTests, registerAndUseServiceWithTimeout) {
+TEST_F(CelixBundleContextServicesTests, registerAndUseServiceWithTimeout) {
struct calc {
int (*calc)(int);
};
@@ -182,7 +183,7 @@ TEST(CelixBundleContextServicesTests, registerAndUseServiceWithTimeout) {
opts.filter.serviceName = "calc";
bool called = celix_bundleContext_useServiceWithOptions(ctx, &opts);
- CHECK(!called); //service not avail.
+ ASSERT_TRUE(!called); //service not avail.
std::future<bool> result{std::async([&]{
opts.waitTimeoutInSeconds = 5.0;
@@ -192,10 +193,10 @@ TEST(CelixBundleContextServicesTests, registerAndUseServiceWithTimeout) {
return calledAsync;
})};
long svcId = celix_bundleContext_registerService(ctx, &svc, calcName, nullptr);
- CHECK(svcId >= 0);
+ ASSERT_TRUE(svcId >= 0);
- CHECK(result.get()); //should return true after waiting for the registered service.
+ ASSERT_TRUE(result.get()); //should return true after waiting for the registered service.
celix_bundleContext_unregisterService(ctx, svcId);
@@ -209,12 +210,12 @@ TEST(CelixBundleContextServicesTests, registerAndUseServiceWithTimeout) {
printf("returned from use service with timeout. calc called %s.\n", calledAsync ? "true" : "false");
return calledAsync;
})};
- CHECK(!result2.get());
+ ASSERT_TRUE(!result2.get());
celix_bundleContext_unregisterService(ctx, svcId);
}
-TEST(CelixBundleContextServicesTests, registerAndUseServiceWithCorrectVersion) {
+TEST_F(CelixBundleContextServicesTests, registerAndUseServiceWithCorrectVersion) {
struct calc {
int (*calc)(int);
};
@@ -235,7 +236,7 @@ TEST(CelixBundleContextServicesTests, registerAndUseServiceWithCorrectVersion) {
reg_opts.svc = &svc;
bool called = celix_bundleContext_useServiceWithOptions(ctx, &use_opts);
- CHECK(!called); //service not avail.
+ ASSERT_TRUE(!called); //service not avail.
std::future<bool> result{std::async([&]{
use_opts.waitTimeoutInSeconds = 5.0;
@@ -245,14 +246,14 @@ TEST(CelixBundleContextServicesTests, registerAndUseServiceWithCorrectVersion) {
return calledAsync;
})};
long svcId = celix_bundleContext_registerServiceWithOptions(ctx, ®_opts);
- CHECK(svcId >= 0);
+ ASSERT_TRUE(svcId >= 0);
- CHECK(result.get()); //should return true after waiting for the registered service.
+ ASSERT_TRUE(result.get()); //should return true after waiting for the registered service.
celix_bundleContext_unregisterService(ctx, svcId);
}
-TEST(CelixBundleContextServicesTests, registerAndUseServiceWithIncorrectVersion) {
+TEST_F(CelixBundleContextServicesTests, registerAndUseServiceWithIncorrectVersion) {
struct calc {
int (*calc)(int);
};
@@ -273,7 +274,7 @@ TEST(CelixBundleContextServicesTests, registerAndUseServiceWithIncorrectVersion)
reg_opts.svc = &svc;
bool called = celix_bundleContext_useServiceWithOptions(ctx, &use_opts);
- CHECK(!called); //service not avail.
+ ASSERT_TRUE(!called); //service not avail.
std::future<bool> result{std::async([&]{
use_opts.waitTimeoutInSeconds = 1.0;
@@ -283,13 +284,13 @@ TEST(CelixBundleContextServicesTests, registerAndUseServiceWithIncorrectVersion)
return calledAsync;
})};
long svcId = celix_bundleContext_registerServiceWithOptions(ctx, ®_opts);
- CHECK(svcId >= 0);
- CHECK(!result.get());
+ ASSERT_TRUE(svcId >= 0);
+ ASSERT_TRUE(!result.get());
celix_bundleContext_unregisterService(ctx, svcId);
}
-TEST(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition) {
+TEST_F(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition) {
struct calc {
int (*calc)(int);
};
@@ -301,7 +302,7 @@ TEST(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition) {
};
long svcId = celix_bundleContext_registerService(ctx, &svc, calcName, nullptr);
- CHECK(svcId >= 0);
+ ASSERT_TRUE(svcId >= 0);
struct sync {
std::mutex mutex{};
@@ -314,7 +315,7 @@ TEST(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition) {
struct sync callInfo{};
auto use = [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
struct sync *h = static_cast<struct sync*>(handle);
@@ -333,8 +334,8 @@ TEST(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition) {
auto call = [&] {
bool called = celix_bundleContext_useServiceWithId(ctx, svcId, calcName, &callInfo, use);
- CHECK(called);
- CHECK_EQUAL(84, callInfo.result);
+ ASSERT_TRUE(called);
+ ASSERT_EQ(84, callInfo.result);
};
std::thread useThread{call};
@@ -369,71 +370,71 @@ TEST(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition) {
};
-TEST(CelixBundleContextServicesTests, servicesTrackerTest) {
+TEST_F(CelixBundleContextServicesTests, servicesTrackerTest) {
int count = 0;
auto add = [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
int *c = static_cast<int*>(handle);
*c += 1;
};
auto remove = [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
int *c = static_cast<int*>(handle);
*c -= 1;
};
long trackerId = celix_bundleContext_trackServices(ctx, "calc", &count, add, remove);
- CHECK(trackerId > 0);
- CHECK_EQUAL(0, count);
+ ASSERT_TRUE(trackerId > 0);
+ ASSERT_EQ(0, count);
long svcId1 = celix_bundleContext_registerService(ctx, (void*)0x100, "calc", nullptr);
- CHECK(svcId1 > 0);
- CHECK_EQUAL(1, count);
+ ASSERT_TRUE(svcId1 > 0);
+ ASSERT_EQ(1, count);
long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x200, "calc", nullptr);
- CHECK(svcId2 > 0);
- CHECK_EQUAL(2, count);
+ ASSERT_TRUE(svcId2 > 0);
+ ASSERT_EQ(2, count);
celix_bundleContext_unregisterService(ctx, svcId1);
- CHECK_EQUAL(1, count);
+ ASSERT_EQ(1, count);
celix_bundleContext_stopTracker(ctx, trackerId);
celix_bundleContext_unregisterService(ctx, svcId2);
}
-TEST(CelixBundleContextServicesTests, servicesTrackerInvalidArgsTest) {
+TEST_F(CelixBundleContextServicesTests, servicesTrackerInvalidArgsTest) {
long trackerId = celix_bundleContext_trackServices(nullptr, nullptr, nullptr, nullptr, nullptr);
- CHECK(trackerId < 0); //required ctx and service name missing
+ ASSERT_TRUE(trackerId < 0); //required ctx and service name missing
trackerId = celix_bundleContext_trackServices(ctx, nullptr, nullptr, nullptr, nullptr);
- CHECK(trackerId < 0); //required service name missing
+ ASSERT_TRUE(trackerId < 0); //required service name missing
trackerId = celix_bundleContext_trackServices(ctx, "calc", nullptr, nullptr, nullptr);
- CHECK(trackerId >= 0); //valid
+ ASSERT_TRUE(trackerId >= 0); //valid
celix_bundleContext_stopTracker(ctx, trackerId);
//opts
trackerId = celix_bundleContext_trackServicesWithOptions(nullptr, nullptr);
- CHECK(trackerId < 0); //required ctx and opts missing
+ ASSERT_TRUE(trackerId < 0); //required ctx and opts missing
trackerId = celix_bundleContext_trackServicesWithOptions(ctx, nullptr);
- CHECK(trackerId < 0); //required opts missing
+ ASSERT_TRUE(trackerId < 0); //required opts missing
celix_service_tracking_options_t opts{};
trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
- CHECK(trackerId < 0); //required opts->serviceName missing
+ ASSERT_TRUE(trackerId < 0); //required opts->serviceName missing
opts.filter.serviceName = "calc";
trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
- CHECK(trackerId >= 0); //valid
+ ASSERT_TRUE(trackerId >= 0); //valid
celix_bundleContext_stopTracker(ctx, trackerId);
}
-TEST(CelixBundleContextServicesTests, servicesTrackerTestWithAlreadyRegisteredServices) {
+TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithAlreadyRegisteredServices) {
int count = 0;
auto add = [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
int *c = static_cast<int*>(handle);
*c += 1;
};
auto remove = [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
int *c = static_cast<int*>(handle);
*c -= 1;
};
@@ -444,37 +445,37 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithAlreadyRegisteredSe
long trackerId = celix_bundleContext_trackServices(ctx, "calc", &count, add, remove);
- CHECK(trackerId > 0);
- CHECK_EQUAL(2, count);
+ ASSERT_TRUE(trackerId > 0);
+ ASSERT_EQ(2, count);
long svcId3 = celix_bundleContext_registerService(ctx, (void*)0x100, "calc", nullptr);
- CHECK(svcId1 > 0);
- CHECK_EQUAL(3, count);
+ ASSERT_TRUE(svcId1 > 0);
+ ASSERT_EQ(3, count);
long svcId4 = celix_bundleContext_registerService(ctx, (void*)0x200, "calc", nullptr);
- CHECK(svcId2 > 0);
- CHECK_EQUAL(4, count);
+ ASSERT_TRUE(svcId2 > 0);
+ ASSERT_EQ(4, count);
celix_bundleContext_unregisterService(ctx, svcId1);
celix_bundleContext_unregisterService(ctx, svcId3);
- CHECK_EQUAL(2, count);
+ ASSERT_EQ(2, count);
celix_bundleContext_stopTracker(ctx, trackerId);
celix_bundleContext_unregisterService(ctx, svcId2);
celix_bundleContext_unregisterService(ctx, svcId4);
}
-TEST(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) {
+TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) {
int count = 0;
auto add = [](void *handle, void *svc, const properties_t *props) {
- CHECK(svc != nullptr);
- STRCMP_EQUAL("C", celix_properties_get(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, nullptr));
+ ASSERT_TRUE(svc != nullptr);
+ ASSERT_STRCASEEQ("C", celix_properties_get(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, nullptr));
int *c = static_cast<int*>(handle);
*c += 1;
};
auto remove = [](void *handle, void *svc, const properties_t *props) {
- CHECK(svc != nullptr);
- STRCMP_EQUAL("C", celix_properties_get(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, nullptr));
+ ASSERT_TRUE(svc != nullptr);
+ ASSERT_STRCASEEQ("C", celix_properties_get(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, nullptr));
int *c = static_cast<int*>(handle);
*c -= 1;
};
@@ -487,33 +488,33 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) {
opts.addWithProperties = add;
opts.removeWithProperties = remove;
long trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
- CHECK(trackerId > 0);
- CHECK_EQUAL(1, count);
+ ASSERT_TRUE(trackerId > 0);
+ ASSERT_EQ(1, count);
long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x200, "calc", nullptr);
- CHECK(svcId1 > 0);
- CHECK_EQUAL(2, count);
+ ASSERT_TRUE(svcId1 > 0);
+ ASSERT_EQ(2, count);
celix_bundleContext_unregisterService(ctx, svcId1);
celix_bundleContext_unregisterService(ctx, svcId2);
- CHECK_EQUAL(0, count);
+ ASSERT_EQ(0, count);
celix_bundleContext_stopTracker(ctx, trackerId);
}
-TEST(CelixBundleContextServicesTests, servicesTrackerTestWithOwner) {
+TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithOwner) {
int count = 0;
auto add = [](void *handle, void *svc, const properties_t *props, const bundle_t *svcOwner) {
- CHECK(svc != nullptr);
- STRCMP_EQUAL("C", celix_properties_get(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, nullptr));
- CHECK(celix_bundle_getId(svcOwner) >= 0);
+ ASSERT_TRUE(svc != nullptr);
+ ASSERT_STRCASEEQ("C", celix_properties_get(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, nullptr));
+ ASSERT_TRUE(celix_bundle_getId(svcOwner) >= 0);
int *c = static_cast<int*>(handle);
*c += 1;
};
auto remove = [](void *handle, void *svc, const properties_t *props, const bundle_t *svcOwner) {
- CHECK(svc != nullptr);
- STRCMP_EQUAL("C", celix_properties_get(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, nullptr));
- CHECK(celix_bundle_getId(svcOwner) >= 0);
+ ASSERT_TRUE(svc != nullptr);
+ ASSERT_STRCASEEQ("C", celix_properties_get(props, CELIX_FRAMEWORK_SERVICE_LANGUAGE, nullptr));
+ ASSERT_TRUE(celix_bundle_getId(svcOwner) >= 0);
int *c = static_cast<int*>(handle);
*c -= 1;
};
@@ -526,21 +527,21 @@ TEST(CelixBundleContextServicesTests, servicesTrackerTestWithOwner) {
opts.addWithOwner = add;
opts.removeWithOwner = remove;
long trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
- CHECK(trackerId > 0);
- CHECK_EQUAL(1, count);
+ ASSERT_TRUE(trackerId > 0);
+ ASSERT_EQ(1, count);
long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x200, "calc", nullptr);
- CHECK(svcId1 > 0);
- CHECK_EQUAL(2, count);
+ ASSERT_TRUE(svcId1 > 0);
+ ASSERT_EQ(2, count);
celix_bundleContext_unregisterService(ctx, svcId1);
celix_bundleContext_unregisterService(ctx, svcId2);
- CHECK_EQUAL(0, count);
+ ASSERT_EQ(0, count);
celix_bundleContext_stopTracker(ctx, trackerId);
}
-TEST(CelixBundleContextServicesTests, serviceTrackerWithRaceConditionTest) {
+TEST_F(CelixBundleContextServicesTests, serviceTrackerWithRaceConditionTest) {
struct calc {
int (*calc)(int);
};
@@ -563,7 +564,7 @@ TEST(CelixBundleContextServicesTests, serviceTrackerWithRaceConditionTest) {
struct data data{};
auto add = [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
struct data *d = static_cast<struct data*>(handle);
@@ -582,7 +583,7 @@ TEST(CelixBundleContextServicesTests, serviceTrackerWithRaceConditionTest) {
};
auto remove = [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
struct data *d = static_cast<struct data*>(handle);
@@ -636,14 +637,14 @@ TEST(CelixBundleContextServicesTests, serviceTrackerWithRaceConditionTest) {
unregisterThread.join();
std::cout << "threads joined" << std::endl;
- CHECK_EQUAL(84, data.result);
- CHECK(data.inAddCall);
- CHECK(data.inRemoveCall);
+ ASSERT_EQ(84, data.result);
+ ASSERT_TRUE(data.inAddCall);
+ ASSERT_TRUE(data.inRemoveCall);
celix_bundleContext_stopTracker(ctx, trackerId);
};
-TEST(CelixBundleContextServicesTests, servicesTrackerSetTest) {
+TEST_F(CelixBundleContextServicesTests, servicesTrackerSetTest) {
int count = 0;
void *svc1 = (void*)0x100; //no ranking
@@ -652,18 +653,18 @@ TEST(CelixBundleContextServicesTests, servicesTrackerSetTest) {
void *svc4 = (void*)0x400; //5 ranking
auto set = [](void *handle, void *svc) {
- CHECK(svc != nullptr);
+ ASSERT_TRUE(svc != nullptr);
static int callCount = 0;
callCount += 1;
if (callCount == 1) {
//first time svc1 should be set (oldest service with equal ranking
- CHECK_EQUAL(0x100, (long)svc);
+ ASSERT_EQ(0x100, (long)svc);
} else if (callCount == 2) {
- CHECK_EQUAL(0x300, (long)svc);
+ ASSERT_EQ(0x300, (long)svc);
//second time svc3 should be set (highest ranking)
} else if (callCount == 3) {
//third time svc4 should be set (highest ranking
- CHECK_EQUAL(0x400, (long)svc);
+ ASSERT_EQ(0x400, (long)svc);
}
int *c = static_cast<int*>(handle);
@@ -679,7 +680,7 @@ TEST(CelixBundleContextServicesTests, servicesTrackerSetTest) {
opts.filter.serviceName = "NA";
opts.set = set;
long trackerId = celix_bundleContext_trackServicesWithOptions(ctx, &opts);
- CHECK(trackerId > 0);
+ ASSERT_TRUE(trackerId > 0);
//register svc3 should lead to second set call
properties_t *props3 = celix_properties_create();
@@ -699,13 +700,13 @@ TEST(CelixBundleContextServicesTests, servicesTrackerSetTest) {
celix_bundleContext_unregisterService(ctx, svcId2);
celix_bundleContext_unregisterService(ctx, svcId4);
- CHECK_EQUAL(3, count); //check if the set is called the expected times
+ ASSERT_EQ(3, count); //check if the set is called the expected times
}
//TODO test tracker with options for properties & service owners
-TEST(CelixBundleContextServicesTests, serviceFactoryTest) {
+TEST_F(CelixBundleContextServicesTests, serviceFactoryTest) {
struct calc {
int (*calc)(int);
};
@@ -728,7 +729,7 @@ TEST(CelixBundleContextServicesTests, serviceFactoryTest) {
};
long facId = celix_bundleContext_registerServiceFactory(ctx, &fac, name, nullptr);
- CHECK_TRUE(facId >= 0);
+ ASSERT_TRUE(facId >= 0);
int result = -1;
@@ -737,30 +738,30 @@ TEST(CelixBundleContextServicesTests, serviceFactoryTest) {
auto *calc = (struct calc*)svc;
*r = calc->calc(2);
});
- CHECK_TRUE(called);
- CHECK_EQUAL(84, result);
- CHECK_EQUAL(2, count); //expecting getService & unGetService to be called during the useService call.
+ ASSERT_TRUE(called);
+ ASSERT_EQ(84, result);
+ ASSERT_EQ(2, count); //expecting getService & unGetService to be called during the useService call.
celix_bundleContext_unregisterService(ctx, facId);
}
-TEST(CelixBundleContextServicesTests, findServicesTest) {
+TEST_F(CelixBundleContextServicesTests, findServicesTest) {
long svcId1 = celix_bundleContext_registerService(ctx, (void*)0x100, "example", nullptr);
long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x100, "example", nullptr);
long foundId = celix_bundleContext_findService(ctx, "non existing service name");
- CHECK_EQUAL(-1L, foundId);
+ ASSERT_EQ(-1L, foundId);
foundId = celix_bundleContext_findService(ctx, "example");
- CHECK_EQUAL(foundId, svcId1); //oldest should have highest ranking
+ ASSERT_EQ(foundId, svcId1); //oldest should have highest ranking
array_list_t *list = celix_bundleContext_findServices(ctx, "non existintg service name");
- CHECK_EQUAL(0, celix_arrayList_size(list));
+ ASSERT_EQ(0, celix_arrayList_size(list));
arrayList_destroy(list);
list = celix_bundleContext_findServices(ctx, "example");
- CHECK_EQUAL(2, celix_arrayList_size(list));
+ ASSERT_EQ(2, celix_arrayList_size(list));
arrayList_destroy(list);
celix_bundleContext_unregisterService(ctx, svcId1);
@@ -768,50 +769,50 @@ TEST(CelixBundleContextServicesTests, findServicesTest) {
celix_service_filter_options_t opts{};
opts.serviceName = "example";
foundId = celix_bundleContext_findServiceWithOptions(ctx, &opts);
- CHECK_EQUAL(foundId, svcId2); //only one left
+ ASSERT_EQ(foundId, svcId2); //only one left
celix_bundleContext_unregisterService(ctx, svcId2);
}
-TEST(CelixBundleContextServicesTests, trackServiceTrackerTest) {
+TEST_F(CelixBundleContextServicesTests, trackServiceTrackerTest) {
int count = 0;
auto add = [](void *handle, const celix_service_tracker_info_t *info) {
- STRCMP_EQUAL("example", info->serviceName);
- STRCMP_EQUAL(CELIX_FRAMEWORK_SERVICE_C_LANGUAGE, info->serviceLanguage);
+ ASSERT_STRCASEEQ("example", info->serviceName);
+ ASSERT_STRCASEEQ(CELIX_FRAMEWORK_SERVICE_C_LANGUAGE, info->serviceLanguage);
auto *c = static_cast<int*>(handle);
*c += 1;
};
auto remove = [](void *handle, const celix_service_tracker_info_t *info) {
- STRCMP_EQUAL("example", info->serviceName);
- STRCMP_EQUAL(CELIX_FRAMEWORK_SERVICE_C_LANGUAGE, info->serviceLanguage);
+ ASSERT_STRCASEEQ("example", info->serviceName);
+ ASSERT_STRCASEEQ(CELIX_FRAMEWORK_SERVICE_C_LANGUAGE, info->serviceLanguage);
auto *c = static_cast<int*>(handle);
*c -= 1;
};
long trackerId = celix_bundleContext_trackServiceTrackers(ctx, "example", &count, add, remove);
- CHECK_TRUE(trackerId >= 0);
- CHECK_EQUAL(0, count);
+ ASSERT_TRUE(trackerId >= 0);
+ ASSERT_EQ(0, count);
long tracker2 = celix_bundleContext_trackService(ctx, "example", nullptr, nullptr);
- CHECK_TRUE(tracker2 >= 0);
- CHECK_EQUAL(1, count);
+ ASSERT_TRUE(tracker2 >= 0);
+ ASSERT_EQ(1, count);
long tracker3 = celix_bundleContext_trackServices(ctx, "example", nullptr, nullptr, nullptr);
- CHECK_TRUE(tracker3 >= 0);
- CHECK_EQUAL(2, count);
+ ASSERT_TRUE(tracker3 >= 0);
+ ASSERT_EQ(2, count);
long tracker4 = celix_bundleContext_trackServices(ctx, "no-match", nullptr, nullptr, nullptr);
- CHECK_TRUE(tracker4 >= 0);
- CHECK_EQUAL(2, count);
+ ASSERT_TRUE(tracker4 >= 0);
+ ASSERT_EQ(2, count);
celix_bundleContext_stopTracker(ctx, tracker2);
celix_serviceTracker_syncForContext(ctx); //service tracker shutdown on separate track -> need sync
- CHECK_EQUAL(1, count);
+ ASSERT_EQ(1, count);
celix_bundleContext_stopTracker(ctx, tracker3);
celix_serviceTracker_syncForContext(ctx); //service tracker shutdown on separate track -> need sync
- CHECK_EQUAL(0, count);
+ ASSERT_EQ(0, count);
celix_bundleContext_stopTracker(ctx, trackerId);
celix_bundleContext_stopTracker(ctx, tracker4);
diff --git a/libs/framework/test/dm_tests.cpp b/libs/framework/gtest/src/dm_tests.cpp
similarity index 67%
rename from libs/framework/test/dm_tests.cpp
rename to libs/framework/gtest/src/dm_tests.cpp
index 81eb8c0..18ed4e1 100644
--- a/libs/framework/test/dm_tests.cpp
+++ b/libs/framework/gtest/src/dm_tests.cpp
@@ -17,18 +17,17 @@
* under the License.
*/
-#include "celix_api.h"
-
-#include <CppUTest/TestHarness.h>
-#include <CppUTest/CommandLineTestRunner.h>
+#include <gtest/gtest.h>
+#include "celix_api.h"
-TEST_GROUP(DepenencyManagerTests) {
- framework_t* fw = nullptr;
- bundle_context_t *ctx = nullptr;
- properties_t *properties = nullptr;
+class DepenencyManagerTests : public ::testing::Test {
+public:
+ celix_framework_t* fw = nullptr;
+ celix_bundle_context_t *ctx = nullptr;
+ celix_properties_t *properties = nullptr;
- void setup() {
+ DepenencyManagerTests() {
properties = properties_create();
properties_set(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", "true");
properties_set(properties, "org.osgi.framework.storage.clean", "onFirstInit");
@@ -38,27 +37,32 @@ TEST_GROUP(DepenencyManagerTests) {
ctx = framework_getContext(fw);
}
- void teardown() {
+ ~DepenencyManagerTests() override {
celix_frameworkFactory_destroyFramework(fw);
}
+
+ DepenencyManagerTests(DepenencyManagerTests&&) = delete;
+ DepenencyManagerTests(const DepenencyManagerTests&) = delete;
+ DepenencyManagerTests& operator=(DepenencyManagerTests&&) = delete;
+ DepenencyManagerTests& operator=(const DepenencyManagerTests&) = delete;
};
-TEST(DepenencyManagerTests, DmCreateComponent) {
+TEST_F(DepenencyManagerTests, DmCreateComponent) {
auto *mng = celix_bundleContext_getDependencyManager(ctx);
auto *cmp = celix_dmComponent_create(ctx, "test1");
celix_dependencyManager_add(mng, cmp);
- CHECK_EQUAL(1, celix_dependencyManager_nrOfComponents(mng));
- CHECK_TRUE(celix_dependencyManager_allComponentsActive(mng));
+ ASSERT_EQ(1, celix_dependencyManager_nrOfComponents(mng));
+ ASSERT_TRUE(celix_dependencyManager_allComponentsActive(mng));
cmp = celix_dmComponent_create(ctx, "test2");
celix_dependencyManager_add(mng, cmp);
- CHECK_EQUAL(2, celix_dependencyManager_nrOfComponents(mng));
- CHECK_TRUE(celix_dependencyManager_allComponentsActive(mng));
+ ASSERT_EQ(2, celix_dependencyManager_nrOfComponents(mng));
+ ASSERT_TRUE(celix_dependencyManager_allComponentsActive(mng));
}
-TEST(DepenencyManagerTests, TestCheckActive) {
+TEST_F(DepenencyManagerTests, TestCheckActive) {
auto *mng = celix_bundleContext_getDependencyManager(ctx);
auto *cmp = celix_dmComponent_create(ctx, "test1");
@@ -69,5 +73,5 @@ TEST(DepenencyManagerTests, TestCheckActive) {
celix_dependencyManager_add(mng, cmp);
- CHECK_FALSE(celix_dependencyManager_areComponentsActive(mng));
+ ASSERT_FALSE(celix_dependencyManager_areComponentsActive(mng));
}
diff --git a/libs/framework/test/multiple_frameworks_test.cpp b/libs/framework/gtest/src/multiple_frameworks_test.cpp
similarity index 84%
rename from libs/framework/test/multiple_frameworks_test.cpp
rename to libs/framework/gtest/src/multiple_frameworks_test.cpp
index 0797980..910f2b9 100644
--- a/libs/framework/test/multiple_frameworks_test.cpp
+++ b/libs/framework/gtest/src/multiple_frameworks_test.cpp
@@ -17,8 +17,7 @@
* under the License.
*/
-#include <CppUTest/TestHarness.h>
-#include <CppUTest/CommandLineTestRunner.h>
+#include <gtest/gtest.h>
extern "C" {
@@ -44,26 +43,26 @@ extern "C" {
//server
rc = celixLauncher_launch("framework1.properties", &serverFramework);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
+ ASSERT_EQ(CELIX_SUCCESS, rc);
bundle = nullptr;
rc = framework_getFrameworkBundle(serverFramework, &bundle);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
+ ASSERT_EQ(CELIX_SUCCESS, rc);
rc = bundle_getContext(bundle, &serverContext);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
+ ASSERT_EQ(CELIX_SUCCESS, rc);
//client
rc = celixLauncher_launch("framework2.properties", &clientFramework);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
+ ASSERT_EQ(CELIX_SUCCESS, rc);
bundle = nullptr;
rc = framework_getFrameworkBundle(clientFramework, &bundle);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
+ ASSERT_EQ(CELIX_SUCCESS, rc);
rc = bundle_getContext(bundle, &clientContext);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
+ ASSERT_EQ(CELIX_SUCCESS, rc);
}
static void teardownFm(void) {
@@ -88,17 +87,17 @@ extern "C" {
}
-
-TEST_GROUP(CelixMultipleFrameworks) {
- void setup() {
+class CelixMultipleFrameworks : public ::testing::Test {
+public:
+ CelixMultipleFrameworks() {
setupFm();
}
- void teardown() {
+ ~CelixMultipleFrameworks() override {
teardownFm();
}
};
-TEST(CelixMultipleFrameworks, testFrameworks) {
+TEST_F(CelixMultipleFrameworks, testFrameworks) {
testFrameworks();
}
diff --git a/libs/framework/test/nop_activator.c b/libs/framework/gtest/src/nop_activator.c
similarity index 100%
rename from libs/framework/test/nop_activator.c
rename to libs/framework/gtest/src/nop_activator.c
diff --git a/libs/framework/test/run_tests.cpp b/libs/framework/gtest/src/run_tests.cpp
similarity index 79%
rename from libs/framework/test/run_tests.cpp
rename to libs/framework/gtest/src/run_tests.cpp
index efaee82..339f725 100644
--- a/libs/framework/test/run_tests.cpp
+++ b/libs/framework/gtest/src/run_tests.cpp
@@ -17,10 +17,10 @@
* under the License.
*/
-#include <CppUTest/TestHarness.h>
-#include "CppUTest/CommandLineTestRunner.h"
+#include <gtest/gtest.h>
-int main(int argc, char** argv) {
- MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
- return RUN_ALL_TESTS(argc, argv);
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ int rc = RUN_ALL_TESTS();
+ return rc;
}
\ No newline at end of file
diff --git a/libs/framework/test/single_framework_test.cpp b/libs/framework/gtest/src/single_framework_test.cpp
similarity index 77%
rename from libs/framework/test/single_framework_test.cpp
rename to libs/framework/gtest/src/single_framework_test.cpp
index b13342b..f2015dd 100644
--- a/libs/framework/test/single_framework_test.cpp
+++ b/libs/framework/gtest/src/single_framework_test.cpp
@@ -17,8 +17,7 @@
* under the License.
*/
-#include <CppUTest/TestHarness.h>
-#include <CppUTest/CommandLineTestRunner.h>
+#include <gtest/gtest.h>
extern "C" {
@@ -32,21 +31,21 @@ extern "C" {
#include "celix_framework_factory.h"
- static framework_pt framework = nullptr;
- static bundle_context_pt context = nullptr;
+ static celix_framework_t *framework = nullptr;
+ static celix_bundle_context_t *context = nullptr;
static void setupFm(void) {
int rc = 0;
rc = celixLauncher_launch("config.properties", &framework);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
+ ASSERT_EQ(CELIX_SUCCESS, rc);
bundle_pt bundle = nullptr;
rc = framework_getFrameworkBundle(framework, &bundle);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
+ ASSERT_EQ(CELIX_SUCCESS, rc);
rc = bundle_getContext(bundle, &context);
- CHECK_EQUAL(CELIX_SUCCESS, rc);
+ ASSERT_EQ(CELIX_SUCCESS, rc);
}
static void teardownFm(void) {
@@ -64,38 +63,40 @@ extern "C" {
printf("testing startup/shutdown single framework\n");
}
- //TODO test register / use service
-
}
-TEST_GROUP(CelixFramework) {
- void setup() {
+class CelixFramework : public ::testing::Test {
+public:
+ CelixFramework() {
setupFm();
}
- void teardown() {
+ ~CelixFramework() override {
teardownFm();
}
};
-TEST(CelixFramework, testFramework) {
+TEST_F(CelixFramework, testFramework) {
testFramework();
}
-TEST_GROUP(FrameworkFactory) {
+class FrameworkFactory : public ::testing::Test {
+public:
+ FrameworkFactory() = default;
+ ~FrameworkFactory() override = default;
};
-TEST(FrameworkFactory, testFactoryCreate) {
+TEST_F(FrameworkFactory, testFactoryCreate) {
framework_t* fw = celix_frameworkFactory_createFramework(nullptr);
- CHECK(fw != nullptr);
+ ASSERT_TRUE(fw != nullptr);
celix_frameworkFactory_destroyFramework(fw);
}
-TEST(FrameworkFactory, testFactoryCreateAndToManyStartAndStops) {
+TEST_F(FrameworkFactory, testFactoryCreateAndToManyStartAndStops) {
framework_t* fw = celix_frameworkFactory_createFramework(nullptr);
- CHECK(fw != nullptr);
+ ASSERT_TRUE(fw != nullptr);
framework_start(fw); //should already be done by frameworkFactory_newFramework();
framework_start(fw);
@@ -112,9 +113,9 @@ TEST(FrameworkFactory, testFactoryCreateAndToManyStartAndStops) {
framework_destroy(fw); //note stop, wait and then destroy is needed .. combine ?
}
-TEST(FrameworkFactory, restartFramework) {
+TEST_F(FrameworkFactory, restartFramework) {
framework_t* fw = celix_frameworkFactory_createFramework(nullptr);
- CHECK(fw != nullptr);
+ ASSERT_TRUE(fw != nullptr);
/* TODO fix mem leak in restarting framework
diff --git a/libs/framework/test/subdir/CMakeLists.txt b/libs/framework/gtest/subdir/CMakeLists.txt
similarity index 100%
rename from libs/framework/test/subdir/CMakeLists.txt
rename to libs/framework/gtest/subdir/CMakeLists.txt
diff --git a/libs/framework/test/subdir/src/foo.c b/libs/framework/gtest/subdir/src/foo.c
similarity index 100%
rename from libs/framework/test/subdir/src/foo.c
rename to libs/framework/gtest/subdir/src/foo.c