This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/fix_lb_command in repository https://gitbox.apache.org/repos/asf/celix.git
commit 359fccf5ec9236265754441bda10fe4e087cd8b9 Author: Pepijn Noltes <[email protected]> AuthorDate: Sat Apr 15 11:58:55 2023 +0200 Refactor some framework gtest naming/file extensions. --- libs/framework/gtest/CMakeLists.txt | 8 +- ...s.cpp => CelixBundleContextBundlesTestSuite.cc} | 88 +++++++++-------- ....cpp => CelixBundleContextServicesTestSuite.cc} | 106 ++++++++++----------- .../gtest/src/CelixFrameworkUtilsTestSuite.cc | 12 +-- .../gtest/src/MultipleFrameworkTestSuite.cc | 56 +++++++++++ .../gtest/src/multiple_frameworks_test.cpp | 103 -------------------- 6 files changed, 166 insertions(+), 207 deletions(-) diff --git a/libs/framework/gtest/CMakeLists.txt b/libs/framework/gtest/CMakeLists.txt index fea4c0b5..ebc23dcf 100644 --- a/libs/framework/gtest/CMakeLists.txt +++ b/libs/framework/gtest/CMakeLists.txt @@ -41,11 +41,11 @@ endif() add_dependencies(unresolvable_bundle sublib) set(CELIX_FRAMEWORK_TEST_SOURCES - src/single_framework_test.cpp + src/CelixFrameworkTestSuite.cc src/CelixFrameworkUtilsTestSuite.cc - src/multiple_frameworks_test.cpp - src/bundle_context_bundles_tests.cpp - src/bundle_context_services_test.cpp + src/MultipleFrameworkTestSuite.cc + src/CelixBundleContextBundlesTestSuite.cc + src/CelixBundleContextServicesTestSuite.cc src/DependencyManagerTestSuite.cc src/CxxBundleContextTestSuite.cc src/HelloWorldCxxActivator.cc diff --git a/libs/framework/gtest/src/bundle_context_bundles_tests.cpp b/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc similarity index 88% rename from libs/framework/gtest/src/bundle_context_bundles_tests.cpp rename to libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc index 43e6bfa2..5a9e0e44 100644 --- a/libs/framework/gtest/src/bundle_context_bundles_tests.cpp +++ b/libs/framework/gtest/src/CelixBundleContextBundlesTestSuite.cc @@ -29,7 +29,7 @@ #include "celix_api.h" -class CelixBundleContextBundlesTests : public ::testing::Test { +class CelixBundleContextBundlesTestSuite : public ::testing::Test { public: celix_framework_t* fw = nullptr; celix_bundle_context_t *ctx = nullptr; @@ -43,7 +43,7 @@ public: const char * const TEST_BND_WITH_EXCEPTION_LOC = "" TEST_BUNDLE_WITH_EXCEPTION_LOCATION ""; const char * const TEST_BND_UNRESOLVABLE_LOC = "" TEST_BUNDLE_UNRESOLVABLE_LOCATION ""; - CelixBundleContextBundlesTests() { + CelixBundleContextBundlesTestSuite() { properties = properties_create(); properties_set(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", "true"); properties_set(properties, "org.osgi.framework.storage.clean", "onFirstInit"); @@ -53,27 +53,26 @@ public: ctx = framework_getContext(fw); } - ~CelixBundleContextBundlesTests() override { + ~CelixBundleContextBundlesTestSuite() override { celix_frameworkFactory_destroyFramework(fw); } - CelixBundleContextBundlesTests(CelixBundleContextBundlesTests&&) = delete; - CelixBundleContextBundlesTests(const CelixBundleContextBundlesTests&) = delete; - CelixBundleContextBundlesTests& operator=(CelixBundleContextBundlesTests&&) = delete; - CelixBundleContextBundlesTests& operator=(const CelixBundleContextBundlesTests&) = delete; + CelixBundleContextBundlesTestSuite(CelixBundleContextBundlesTestSuite&&) = delete; + CelixBundleContextBundlesTestSuite(const CelixBundleContextBundlesTestSuite&) = delete; + CelixBundleContextBundlesTestSuite& operator=(CelixBundleContextBundlesTestSuite&&) = delete; + CelixBundleContextBundlesTestSuite& operator=(const CelixBundleContextBundlesTestSuite&) = delete; }; - -TEST_F(CelixBundleContextBundlesTests, StartStopTest) { +TEST_F(CelixBundleContextBundlesTestSuite, StartStopTest) { //nop } -TEST_F(CelixBundleContextBundlesTests, installABundleTest) { +TEST_F(CelixBundleContextBundlesTestSuite, InstallABundleTest) { long bndId = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true); ASSERT_TRUE(bndId >= 0); } -TEST_F(CelixBundleContextBundlesTests, installBundlesTest) { +TEST_F(CelixBundleContextBundlesTestSuite, InstallBundlesTest) { long bndId = celix_bundleContext_installBundle(ctx, "non-existing.zip", true); ASSERT_TRUE(bndId < 0); @@ -89,7 +88,7 @@ TEST_F(CelixBundleContextBundlesTests, installBundlesTest) { ASSERT_TRUE(bndId >= 0); } -TEST_F(CelixBundleContextBundlesTests, TestIsSystemBundle) { +TEST_F(CelixBundleContextBundlesTestSuite, TestIsSystemBundle) { celix_bundle_t* fwBnd = celix_framework_getFrameworkBundle(fw); ASSERT_TRUE(celix_bundle_isSystemBundle(fwBnd)); @@ -101,8 +100,8 @@ TEST_F(CelixBundleContextBundlesTests, TestIsSystemBundle) { EXPECT_TRUE(called); } -TEST_F(CelixBundleContextBundlesTests, useBundlesTest) { - int count = 0; +TEST_F(CelixBundleContextBundlesTestSuite, UseBundlesTest) { + int callbackCount = 0; auto use = [](void *handle, const bundle_t *bnd) { int *c = (int*)handle; @@ -115,15 +114,22 @@ TEST_F(CelixBundleContextBundlesTests, useBundlesTest) { ASSERT_EQ(celix_version_getMajor(v), 1); }; - celix_bundleContext_useBundles(ctx, &count, use); + celix_bundleContext_useBundles(ctx, &callbackCount, use); - count = 0; + callbackCount = 0; celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true); - celix_bundleContext_useBundles(ctx, &count, use); - ASSERT_EQ(1, count); + size_t useCount = celix_bundleContext_useBundles(ctx, &callbackCount, use); + EXPECT_EQ(1, callbackCount); + EXPECT_EQ(1, useCount); + + callbackCount = 0; + celix_bundleContext_installBundle(ctx, TEST_BND2_LOC, false); //note installed, but not started + useCount = celix_bundleContext_useBundles(ctx, &callbackCount, use); + EXPECT_EQ(2, callbackCount); + EXPECT_EQ(2, useCount); }; -TEST_F(CelixBundleContextBundlesTests, installAndUninstallBundlesTest) { +TEST_F(CelixBundleContextBundlesTestSuite, InstallAndUninstallBundlesTest) { //install bundles long bndId1 = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true); long bndId2 = celix_bundleContext_installBundle(ctx, TEST_BND2_LOC, false); @@ -167,11 +173,11 @@ TEST_F(CelixBundleContextBundlesTests, installAndUninstallBundlesTest) { ASSERT_TRUE(bndId3 == bndId6); //bundle cache -> reuse of bundle id. } -TEST_F(CelixBundleContextBundlesTests, startBundleWithException) { +TEST_F(CelixBundleContextBundlesTestSuite, StartBundleWithException) { long bndId = celix_bundleContext_installBundle(ctx, TEST_BND_WITH_EXCEPTION_LOC, true); 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) { + bool called = celix_bundleContext_useBundle(ctx, bndId, nullptr, [](void */*handle*/, const celix_bundle_t *bnd) { auto state = celix_bundle_getState(bnd); ASSERT_EQ(state, CELIX_BUNDLE_STATE_RESOLVED); ASSERT_EQ(state, OSGI_FRAMEWORK_BUNDLE_RESOLVED); @@ -179,11 +185,11 @@ TEST_F(CelixBundleContextBundlesTests, startBundleWithException) { ASSERT_TRUE(called); } -TEST_F(CelixBundleContextBundlesTests, startUnresolveableBundle) { +TEST_F(CelixBundleContextBundlesTestSuite, StartUnresolveableBundle) { long bndId = celix_bundleContext_installBundle(ctx, TEST_BND_UNRESOLVABLE_LOC, true); 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) { + bool called = celix_bundleContext_useBundle(ctx, bndId, nullptr, [](void *, const celix_bundle_t *bnd) { auto state = celix_bundle_getState(bnd); ASSERT_EQ(CELIX_BUNDLE_STATE_INSTALLED, state); ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_INSTALLED, celix_bundle_getState(bnd)); //NOTE the OSGI_ variant is equivalent @@ -192,7 +198,7 @@ TEST_F(CelixBundleContextBundlesTests, startUnresolveableBundle) { celix_bundleContext_startBundle(ctx, bndId); - called = celix_framework_useBundle(fw, false, bndId, nullptr, [](void *, const celix_bundle_t *bnd) { + called = celix_bundleContext_useBundle(ctx, bndId, nullptr, [](void *, const celix_bundle_t *bnd) { auto state = celix_bundle_getState(bnd); ASSERT_EQ(CELIX_BUNDLE_STATE_INSTALLED, state); ASSERT_EQ(OSGI_FRAMEWORK_BUNDLE_INSTALLED, state); //NOTE the OSGI_ variant is equivalent @@ -201,7 +207,7 @@ TEST_F(CelixBundleContextBundlesTests, startUnresolveableBundle) { } -TEST_F(CelixBundleContextBundlesTests, useBundleTest) { +TEST_F(CelixBundleContextBundlesTestSuite, UseBundleTest) { int count = 0; bool called = celix_bundleContext_useBundle(ctx, 0, &count, [](void *handle, const bundle_t *bnd) { @@ -215,7 +221,7 @@ TEST_F(CelixBundleContextBundlesTests, useBundleTest) { ASSERT_EQ(1, count); }; -TEST_F(CelixBundleContextBundlesTests, StopStartTest) { +TEST_F(CelixBundleContextBundlesTestSuite, 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); @@ -272,7 +278,7 @@ TEST_F(CelixBundleContextBundlesTests, StopStartTest) { celix_arrayList_destroy(ids); } -TEST_F(CelixBundleContextBundlesTests, DoubleStopTest) { +TEST_F(CelixBundleContextBundlesTestSuite, DoubleStopTest) { long bndId = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true); ASSERT_TRUE(bndId > 0); ASSERT_TRUE(celix_bundleContext_isBundleInstalled(ctx, bndId)); @@ -320,7 +326,7 @@ TEST_F(CelixBundleContextBundlesTests, DoubleStopTest) { ASSERT_TRUE(called); } -TEST_F(CelixBundleContextBundlesTests, trackBundlesTest) { +TEST_F(CelixBundleContextBundlesTestSuite, TrackBundlesTest) { struct data { std::atomic<int> installedCount{0}; std::atomic<int> startedCount{0}; @@ -402,7 +408,7 @@ TEST_F(CelixBundleContextBundlesTests, trackBundlesTest) { }; -TEST_F(CelixBundleContextBundlesTests, trackBundlesTestAsync) { +TEST_F(CelixBundleContextBundlesTestSuite, TrackBundlesTestAsync) { struct data { std::atomic<int> installedCount{0}; std::atomic<int> startedCount{0}; @@ -485,7 +491,7 @@ TEST_F(CelixBundleContextBundlesTests, trackBundlesTestAsync) { celix_bundleContext_waitForAsyncStopTracker(ctx, trackerId); }; -TEST_F(CelixBundleContextBundlesTests, useBundlesConcurrentTest) { +TEST_F(CelixBundleContextBundlesTestSuite, useBundlesConcurrentTest) { struct data { std::mutex mutex{}; @@ -544,7 +550,7 @@ TEST_F(CelixBundleContextBundlesTests, useBundlesConcurrentTest) { std::cout << "uninstall thread joined" << std::endl; }; -TEST_F(CelixBundleContextBundlesTests, bundleInfoTests) { +TEST_F(CelixBundleContextBundlesTestSuite, BundleInfoTests) { struct data { int provideCount{0}; int requestedCount{0}; @@ -579,7 +585,7 @@ TEST_F(CelixBundleContextBundlesTests, bundleInfoTests) { celix_bundleContext_stopTracker(ctx, trackerId); } -TEST_F(CelixBundleContextBundlesTests, startStopBundleTrackerAsync) { +TEST_F(CelixBundleContextBundlesTestSuite, StartStopBundleTrackerAsync) { std::atomic<int> count{0}; auto cb = [](void* data) { @@ -600,7 +606,7 @@ TEST_F(CelixBundleContextBundlesTests, startStopBundleTrackerAsync) { EXPECT_EQ(2, count.load()); //1x tracker started, 1x tracker stopped } -TEST_F(CelixBundleContextBundlesTests, testBundleStateToString) { +TEST_F(CelixBundleContextBundlesTestSuite, TestBundleStateToString) { const char* result = celix_bundleState_getName(CELIX_BUNDLE_STATE_UNKNOWN); EXPECT_STREQ(result, "UNKNOWN"); @@ -647,7 +653,7 @@ TEST_F(CelixBundleContextBundlesTests, testBundleStateToString) { EXPECT_STREQ(result, "UNKNOWN"); } -class CelixBundleContextTempBundlesTests : public ::testing::Test { +class CelixBundleContextTempBundlesTestSuite : public ::testing::Test { public: celix_framework_t* fw = nullptr; celix_bundle_context_t *ctx = nullptr; @@ -655,7 +661,7 @@ public: const char * const TEST_BND1_LOC = "" SIMPLE_TEST_BUNDLE1_LOCATION ""; - CelixBundleContextTempBundlesTests() { + CelixBundleContextTempBundlesTestSuite() { properties = celix_properties_create(); celix_properties_setBool(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", true); celix_properties_setBool(properties, CELIX_FRAMEWORK_CACHE_USE_TMP_DIR, true); @@ -665,17 +671,17 @@ public: EXPECT_NE(ctx, nullptr); } - ~CelixBundleContextTempBundlesTests() override { + ~CelixBundleContextTempBundlesTestSuite() override { celix_frameworkFactory_destroyFramework(fw); } - CelixBundleContextTempBundlesTests(CelixBundleContextTempBundlesTests&&) = delete; - CelixBundleContextTempBundlesTests(const CelixBundleContextTempBundlesTests&) = delete; - CelixBundleContextTempBundlesTests& operator=(CelixBundleContextTempBundlesTests&&) = delete; - CelixBundleContextTempBundlesTests& operator=(const CelixBundleContextTempBundlesTests&) = delete; + CelixBundleContextTempBundlesTestSuite(CelixBundleContextTempBundlesTestSuite&&) = delete; + CelixBundleContextTempBundlesTestSuite(const CelixBundleContextTempBundlesTestSuite&) = delete; + CelixBundleContextTempBundlesTestSuite& operator=(CelixBundleContextTempBundlesTestSuite&&) = delete; + CelixBundleContextTempBundlesTestSuite& operator=(const CelixBundleContextTempBundlesTestSuite&) = delete; }; -TEST_F(CelixBundleContextTempBundlesTests, installABundleTest) { +TEST_F(CelixBundleContextTempBundlesTestSuite, InstallABundleTest) { long bndId = celix_bundleContext_installBundle(ctx, TEST_BND1_LOC, true); ASSERT_TRUE(bndId >= 0); } diff --git a/libs/framework/gtest/src/bundle_context_services_test.cpp b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc similarity index 93% rename from libs/framework/gtest/src/bundle_context_services_test.cpp rename to libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc index 199e214c..e5351d4b 100644 --- a/libs/framework/gtest/src/bundle_context_services_test.cpp +++ b/libs/framework/gtest/src/CelixBundleContextServicesTestSuite.cc @@ -33,7 +33,7 @@ #include "celix_service_factory.h" #include "service_tracker_private.h" -class CelixBundleContextServicesTests : public ::testing::Test { +class CelixBundleContextServicesTestSuite : public ::testing::Test { public: celix_framework_t* fw = nullptr; celix_bundle_context_t *ctx = nullptr; @@ -41,7 +41,7 @@ public: const char * const CMP_TEST_BND_LOC = "" CMP_TEST_BUNDLE_LOC ""; - CelixBundleContextServicesTests() { + CelixBundleContextServicesTestSuite() { properties = celix_properties_create(); celix_properties_set(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", "true"); celix_properties_set(properties, "org.osgi.framework.storage.clean", "onFirstInit"); @@ -53,14 +53,14 @@ public: ctx = framework_getContext(fw); } - ~CelixBundleContextServicesTests() override { + ~CelixBundleContextServicesTestSuite() override { celix_frameworkFactory_destroyFramework(fw); } - CelixBundleContextServicesTests(CelixBundleContextServicesTests&&) = delete; - CelixBundleContextServicesTests(const CelixBundleContextServicesTests&) = delete; - CelixBundleContextServicesTests& operator=(CelixBundleContextServicesTests&&) = delete; - CelixBundleContextServicesTests& operator=(const CelixBundleContextServicesTests&) = delete; + CelixBundleContextServicesTestSuite(CelixBundleContextServicesTestSuite&&) = delete; + CelixBundleContextServicesTestSuite(const CelixBundleContextServicesTestSuite&) = delete; + CelixBundleContextServicesTestSuite& operator=(CelixBundleContextServicesTestSuite&&) = delete; + CelixBundleContextServicesTestSuite& operator=(const CelixBundleContextServicesTestSuite&) = delete; void registerAndUseServiceWithCorrectVersion(bool direct) { struct calc { @@ -249,7 +249,7 @@ public: } }; -TEST_F(CelixBundleContextServicesTests, registerService) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterServiceTest) { struct calc { int (*calc)(int); }; @@ -265,7 +265,7 @@ TEST_F(CelixBundleContextServicesTests, registerService) { celix_bundleContext_unregisterService(ctx, svcId); }; -TEST_F(CelixBundleContextServicesTests, registerServiceAsync) { +TEST_F(CelixBundleContextServicesTestSuite, TegisterServiceAsyncTest) { struct calc { int (*calc)(int); }; @@ -286,21 +286,21 @@ TEST_F(CelixBundleContextServicesTests, registerServiceAsync) { ASSERT_LT(celix_bundleContext_findService(ctx, calcName), 0L); }; -TEST_F(CelixBundleContextServicesTests, incorrectUnregisterCalls) { +TEST_F(CelixBundleContextServicesTestSuite, IncorrectUnregisterCallsTest) { celix_bundleContext_unregisterService(ctx, 1); celix_bundleContext_unregisterService(ctx, 2); celix_bundleContext_unregisterService(ctx, -1); celix_bundleContext_unregisterService(ctx, -2); }; -TEST_F(CelixBundleContextServicesTests, incorrectAsyncUnregisterCalls) { +TEST_F(CelixBundleContextServicesTestSuite, IncorrectAsyncUnregisterCallsTset) { celix_bundleContext_unregisterServiceAsync(ctx, 1, nullptr, nullptr); celix_bundleContext_unregisterServiceAsync(ctx, 2, nullptr, nullptr); celix_bundleContext_unregisterServiceAsync(ctx, -1, nullptr, nullptr); celix_bundleContext_unregisterServiceAsync(ctx, -2, nullptr, nullptr); }; -TEST_F(CelixBundleContextServicesTests, UseServicesWithoutName) { +TEST_F(CelixBundleContextServicesTestSuite, UseServicesWithoutNameTest) { struct calc { int (*calc)(int); }; @@ -353,7 +353,7 @@ TEST_F(CelixBundleContextServicesTests, UseServicesWithoutName) { celix_bundleContext_unregisterService(ctx, svcId1); } -TEST_F(CelixBundleContextServicesTests, registerMultipleAndUseServices) { +TEST_F(CelixBundleContextServicesTestSuite, TegisterMultipleAndUseServicesTest) { struct calc { int (*calc)(int); }; @@ -434,7 +434,7 @@ TEST_F(CelixBundleContextServicesTests, registerMultipleAndUseServices) { celix_bundleContext_unregisterService(ctx, svcId2); }; -TEST_F(CelixBundleContextServicesTests, useServiceInUseCallback) { +TEST_F(CelixBundleContextServicesTestSuite, UseServiceInUseCallbackTest) { struct calc { int (*calc)(int); }; @@ -477,7 +477,7 @@ TEST_F(CelixBundleContextServicesTests, useServiceInUseCallback) { celix_bundleContext_unregisterService(ctx, svcId3); } -TEST_F(CelixBundleContextServicesTests, registerAndUseService) { +TEST_F(CelixBundleContextServicesTestSuite, TegisterAndUseServiceTest) { struct calc { int (*calc)(int); }; @@ -516,39 +516,39 @@ TEST_F(CelixBundleContextServicesTests, registerAndUseService) { celix_bundleContext_unregisterService(ctx, svcId); }; -TEST_F(CelixBundleContextServicesTests, registerAndUseServiceWithTimeout) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterAndUseServiceWithTimeoutTest) { registerAndUseServiceWithTimeout(false); } -TEST_F(CelixBundleContextServicesTests, registerAndUseServiceDirectWithTimeout) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterAndUseServiceDirectWithTimeoutTest) { registerAndUseServiceWithTimeout(true); } -TEST_F(CelixBundleContextServicesTests, registerAsyncAndUseServiceWithTimeout) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterAsyncAndUseServiceWithTimeoutTest) { registerAsyncAndUseServiceWithTimeout(false); } -TEST_F(CelixBundleContextServicesTests, registerAsyncAndUseServiceDirectWithTimeout) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterAsyncAndUseServiceDirectWithTimeoutTest) { registerAsyncAndUseServiceWithTimeout(true); } -TEST_F(CelixBundleContextServicesTests, registerAndUseServiceWithCorrectVersion) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterAndUseServiceWithCorrectVersionTest) { registerAndUseServiceWithCorrectVersion(false); } -TEST_F(CelixBundleContextServicesTests, registerAndUseServiceDirectWithCorrectVersion) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterAndUseServiceDirectWithCorrectVersionTest) { registerAndUseServiceWithCorrectVersion(true); } -TEST_F(CelixBundleContextServicesTests, registerAndUseServiceWithIncorrectVersion) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterAndUseServiceWithIncorrectVersionTest) { registerAndUseServiceWithIncorrectVersion(false); } -TEST_F(CelixBundleContextServicesTests, registerAndUseServiceDirectWithIncorrectVersion) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterAndUseServiceDirectWithIncorrectVersionTest) { registerAndUseServiceWithIncorrectVersion(true); } -TEST_F(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition) { +TEST_F(CelixBundleContextServicesTestSuite, RegisterAndUseWithForcedRaceConditionTest) { struct calc { int (*calc)(int); }; @@ -628,7 +628,7 @@ TEST_F(CelixBundleContextServicesTests, registerAndUseWithForcedRaceCondition) { }; -TEST_F(CelixBundleContextServicesTests, servicesTrackerTest) { +TEST_F(CelixBundleContextServicesTestSuite, ServicesTrackerTest) { int count = 0; auto add = [](void *handle, void *svc) { ASSERT_TRUE(svc != nullptr); @@ -660,7 +660,7 @@ TEST_F(CelixBundleContextServicesTests, servicesTrackerTest) { celix_bundleContext_unregisterService(ctx, svcId2); } -TEST_F(CelixBundleContextServicesTests, servicesTrackerTestAsync) { +TEST_F(CelixBundleContextServicesTestSuite, ServicesTrackerTestAsync) { std::atomic<int> count {0}; auto add = [](void *handle, void *svc) { ASSERT_TRUE(svc != nullptr); @@ -697,7 +697,7 @@ TEST_F(CelixBundleContextServicesTests, servicesTrackerTestAsync) { celix_framework_waitForEmptyEventQueue(fw); } -TEST_F(CelixBundleContextServicesTests, servicesTrackerInvalidArgsTest) { +TEST_F(CelixBundleContextServicesTestSuite, ServicesTrackerInvalidArgsTest) { long trackerId = celix_bundleContext_trackServices(nullptr, nullptr, nullptr, nullptr, nullptr); ASSERT_TRUE(trackerId < 0); //required ctx missing trackerId = celix_bundleContext_trackServices(ctx, "calc", nullptr, nullptr, nullptr); @@ -721,7 +721,7 @@ TEST_F(CelixBundleContextServicesTests, servicesTrackerInvalidArgsTest) { celix_bundleContext_stopTracker(ctx, trackerId); } -TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithAlreadyRegisteredServices) { +TEST_F(CelixBundleContextServicesTestSuite, ServicesTrackerTestWithAlreadyRegisteredServices) { int count = 0; auto add = [](void *handle, void *svc) { ASSERT_TRUE(svc != nullptr); @@ -760,7 +760,7 @@ TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithAlreadyRegistered celix_bundleContext_unregisterService(ctx, svcId4); } -TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) { +TEST_F(CelixBundleContextServicesTestSuite, ServicesTrackerTestWithProperties) { int count = 0; int count2 = 0; auto add = [](void *handle, void *svc, const properties_t *props) { @@ -810,7 +810,7 @@ TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) { celix_bundleContext_stopTracker(ctx, trackerId); } -TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithOwner) { +TEST_F(CelixBundleContextServicesTestSuite, ServicesTrackerTestWithOwner) { int count = 0; auto add = [](void *handle, void *svc, const properties_t *props, const bundle_t *svcOwner) { ASSERT_TRUE(svc != nullptr); @@ -849,7 +849,7 @@ TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithOwner) { celix_bundleContext_stopTracker(ctx, trackerId); } -TEST_F(CelixBundleContextServicesTests, serviceTrackerWithRaceConditionTest) { +TEST_F(CelixBundleContextServicesTestSuite, ServiceTrackerWithRaceConditionTest) { struct calc { int (*calc)(int); }; @@ -952,7 +952,7 @@ TEST_F(CelixBundleContextServicesTests, serviceTrackerWithRaceConditionTest) { celix_bundleContext_stopTracker(ctx, trackerId); }; -TEST_F(CelixBundleContextServicesTests, useServiceDoesNotBlockInEventLoop) { +TEST_F(CelixBundleContextServicesTestSuite, UseServiceDoesNotBlockInEventLoop) { void *svc1 = (void*)0x100; auto set = [](void *handle, void */*svc*/) { @@ -990,7 +990,7 @@ TEST_F(CelixBundleContextServicesTests, useServiceDoesNotBlockInEventLoop) { celix_bundleContext_unregisterService(ctx, svcId1); } -TEST_F(CelixBundleContextServicesTests, servicesTrackerSetTest) { +TEST_F(CelixBundleContextServicesTestSuite, ServicesTrackerSetTest) { int count = 0; void *svc1 = (void*)0x100; //no ranking @@ -1048,7 +1048,7 @@ TEST_F(CelixBundleContextServicesTests, servicesTrackerSetTest) { ASSERT_EQ(4, count); //check if the set is called the expected times } -TEST_F(CelixBundleContextServicesTests, TrackerOfAllServicesSetTest) { +TEST_F(CelixBundleContextServicesTestSuite, TrackerOfAllServicesSetTest) { int count = 0; void *svc1 = (void*)0x100; //no ranking @@ -1106,7 +1106,7 @@ TEST_F(CelixBundleContextServicesTests, TrackerOfAllServicesSetTest) { ASSERT_EQ(4, count); //check if the set is called the expected times } -TEST_F(CelixBundleContextServicesTests, trackAllServices) { +TEST_F(CelixBundleContextServicesTestSuite, TrackAllServices) { std::atomic<size_t> count{0}; void *svc1 = (void *) 0x100; //no ranking @@ -1138,7 +1138,7 @@ TEST_F(CelixBundleContextServicesTests, trackAllServices) { celix_bundleContext_stopTracker(ctx, trackerId); } -TEST_F(CelixBundleContextServicesTests, metaTrackAllServiceTrackers) { +TEST_F(CelixBundleContextServicesTestSuite, MetaTrackAllServiceTrackers) { std::atomic<size_t> count{0}; auto add = [](void *handle, const celix_service_tracker_info_t*) { auto *c = (std::atomic<size_t>*)handle; @@ -1163,7 +1163,7 @@ TEST_F(CelixBundleContextServicesTests, metaTrackAllServiceTrackers) { celix_bundleContext_stopTracker(ctx, trkId3); } -TEST_F(CelixBundleContextServicesTests, metaTrackServiceTrackersFromOtherBundle) { +TEST_F(CelixBundleContextServicesTestSuite, MetaTrackServiceTrackersFromOtherBundle) { long bndId = celix_bundleContext_installBundle(ctx, CMP_TEST_BND_LOC, true); ASSERT_TRUE(bndId >= 0); long bndIdInAdd = -1; @@ -1193,7 +1193,7 @@ TEST_F(CelixBundleContextServicesTests, metaTrackServiceTrackersFromOtherBundle) EXPECT_EQ(bndIdInRemove, bndId); } -TEST_F(CelixBundleContextServicesTests, serviceFactoryTest) { +TEST_F(CelixBundleContextServicesTestSuite, ServiceFactoryTest) { struct calc { int (*calc)(int); }; @@ -1234,7 +1234,7 @@ TEST_F(CelixBundleContextServicesTests, serviceFactoryTest) { } -TEST_F(CelixBundleContextServicesTests, asyncServiceFactoryTest) { +TEST_F(CelixBundleContextServicesTestSuite, AsyncServiceFactoryTest) { struct calc { int (*calc)(int); }; @@ -1275,7 +1275,7 @@ TEST_F(CelixBundleContextServicesTests, asyncServiceFactoryTest) { celix_bundleContext_unregisterServiceAsync(ctx, facId, nullptr, nullptr); } -TEST_F(CelixBundleContextServicesTests, findServicesTest) { +TEST_F(CelixBundleContextServicesTestSuite, FindServicesTest) { long svcId1 = celix_bundleContext_registerService(ctx, (void*)0x100, "example", nullptr); long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x100, "example", nullptr); long svcId3 = celix_bundleContext_registerService(ctx, (void*)0x100, "example", nullptr); @@ -1308,7 +1308,7 @@ TEST_F(CelixBundleContextServicesTests, findServicesTest) { celix_bundleContext_unregisterService(ctx, svcId2); } -TEST_F(CelixBundleContextServicesTests, trackServiceTrackerTest) { +TEST_F(CelixBundleContextServicesTestSuite, TrackServiceTrackerTest) { int count = 0; @@ -1348,7 +1348,7 @@ TEST_F(CelixBundleContextServicesTests, trackServiceTrackerTest) { celix_bundleContext_stopTracker(ctx, tracker4); } -TEST_F(CelixBundleContextServicesTests, floodEventLoopTest) { +TEST_F(CelixBundleContextServicesTestSuite, FloodEventLoopTest) { struct callback_data { std::mutex mutex{}; std::condition_variable cond{}; @@ -1406,7 +1406,7 @@ TEST_F(CelixBundleContextServicesTests, floodEventLoopTest) { } -TEST_F(CelixBundleContextServicesTests, serviceOnDemandWithAsyncRegisterTest) { +TEST_F(CelixBundleContextServicesTestSuite, ServiceOnDemandWithAsyncRegisterTest) { //NOTE that even though service are registered async, they should be found by a useService call. bool called = celix_bundleContext_useService(ctx, "test", nullptr, [](void*, void*){/*nop*/}); @@ -1435,7 +1435,7 @@ TEST_F(CelixBundleContextServicesTests, serviceOnDemandWithAsyncRegisterTest) { celix_bundleContext_stopTracker(ctx, trkId); } -TEST_F(CelixBundleContextServicesTests, UseServiceOnDemandDirectlyWithAsyncRegisterTest) { +TEST_F(CelixBundleContextServicesTestSuite, UseServiceOnDemandDirectlyWithAsyncRegisterTest) { //NOTE that even though service are registered async, they should be found by a useService call. bool called = celix_bundleContext_useService(ctx, "test", nullptr, [](void*, void*){/*nop*/}); @@ -1466,7 +1466,7 @@ TEST_F(CelixBundleContextServicesTests, UseServiceOnDemandDirectlyWithAsyncRegis celix_bundleContext_stopTracker(ctx, trkId); } -TEST_F(CelixBundleContextServicesTests, UseServicesOnDemandDirectlyWithAsyncRegisterTest) { +TEST_F(CelixBundleContextServicesTestSuite, UseServicesOnDemandDirectlyWithAsyncRegisterTest) { //NOTE that even though service are registered async, they should be found by a useService call. bool called = celix_bundleContext_useService(ctx, "test", nullptr, [](void*, void*){/*nop*/}); @@ -1506,7 +1506,7 @@ TEST_F(CelixBundleContextServicesTests, UseServicesOnDemandDirectlyWithAsyncRegi celix_bundleContext_stopTracker(ctx, trkId1); } -TEST_F(CelixBundleContextServicesTests, startStopServiceTrackerAsync) { +TEST_F(CelixBundleContextServicesTestSuite, StartStopServiceTrackerAsyncTest) { std::atomic<int> count{0}; auto cb = [](void* data) { @@ -1527,7 +1527,7 @@ TEST_F(CelixBundleContextServicesTests, startStopServiceTrackerAsync) { EXPECT_EQ(2, count.load()); //1x tracker started, 1x tracker stopped } -TEST_F(CelixBundleContextServicesTests, startStopMetaServiceTrackerAsync) { +TEST_F(CelixBundleContextServicesTestSuite, StartStopMetaServiceTrackerAsyncTest) { std::atomic<int> count{0}; auto cb = [](void* data) { @@ -1545,7 +1545,7 @@ TEST_F(CelixBundleContextServicesTests, startStopMetaServiceTrackerAsync) { EXPECT_EQ(2, count.load()); //1x tracker started, 1x tracker stopped } -TEST_F(CelixBundleContextServicesTests, onlyCallAsyncCallbackWithAsyncApi) { +TEST_F(CelixBundleContextServicesTestSuite, OnlyCallAsyncCallbackWithAsyncApiTest) { celix_service_tracking_options_t opts{}; opts.trackerCreatedCallback = [](void *) { FAIL(); @@ -1574,7 +1574,7 @@ TEST_F(CelixBundleContextServicesTests, onlyCallAsyncCallbackWithAsyncApi) { celix_bundleContext_stopTracker(ctx, trkId); } -TEST_F(CelixBundleContextServicesTests, unregisterSvcBeforeAsyncRegistration) { +TEST_F(CelixBundleContextServicesTestSuite, UnregisterSvcBeforeAsyncRegistrationTest) { struct callback_data { std::atomic<int> count{}; celix_bundle_context_t* ctx{nullptr}; @@ -1605,7 +1605,7 @@ TEST_F(CelixBundleContextServicesTests, unregisterSvcBeforeAsyncRegistration) { EXPECT_EQ(0, cbData.count.load()); //note create tracker canceled -> no callback } -TEST_F(CelixBundleContextServicesTests, stopSvcTrackerBeforeAsyncTrackerIsCreated) { +TEST_F(CelixBundleContextServicesTestSuite, StopSvcTrackerBeforeAsyncTrackerIsCreatedTest) { struct callback_data { std::atomic<int> count{}; celix_bundle_context_t* ctx{nullptr}; @@ -1642,7 +1642,7 @@ TEST_F(CelixBundleContextServicesTests, stopSvcTrackerBeforeAsyncTrackerIsCreate EXPECT_EQ(0, cbData.count.load()); //note create tracker canceled -> no callback } -TEST_F(CelixBundleContextServicesTests, stopBundleTrackerBeforeAsyncTrackerIsCreated) { +TEST_F(CelixBundleContextServicesTestSuite, StopBundleTrackerBeforeAsyncTrackerIsCreatedTest) { struct callback_data { std::atomic<int> count{}; celix_bundle_context_t* ctx{nullptr}; @@ -1678,7 +1678,7 @@ TEST_F(CelixBundleContextServicesTests, stopBundleTrackerBeforeAsyncTrackerIsCre EXPECT_EQ(0, cbData.count.load()); //note create tracker canceled -> no callback } -TEST_F(CelixBundleContextServicesTests, stopMetaTrackerBeforeAsyncTrackerIsCreated) { +TEST_F(CelixBundleContextServicesTestSuite, StopMetaTrackerBeforeAsyncTrackerIsCreatedTest) { struct callback_data { std::atomic<int> count{}; celix_bundle_context_t* ctx{nullptr}; @@ -1711,7 +1711,7 @@ TEST_F(CelixBundleContextServicesTests, stopMetaTrackerBeforeAsyncTrackerIsCreat } -TEST_F(CelixBundleContextServicesTests, setServicesWithTrackerWhenMultipleRegistrationAlreadyExists) { +TEST_F(CelixBundleContextServicesTestSuite, SetServicesWithTrackerWhenMultipleRegistrationAlreadyExistsTest) { void* dummySvc = (void*)0x42; long svcId1 = celix_bundleContext_registerService(ctx, &dummySvc, "TestService", nullptr); long svcId2 = celix_bundleContext_registerService(ctx, &dummySvc, "TestService", nullptr); diff --git a/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc b/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc index 57c8a0da..1dc59cef 100644 --- a/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc +++ b/libs/framework/gtest/src/CelixFrameworkUtilsTestSuite.cc @@ -51,7 +51,7 @@ static void checkBundleCacheDir(const char* extractDir) { } } -TEST_F(CelixFrameworkUtilsTestSuite, testIsBundleUrlValid) { +TEST_F(CelixFrameworkUtilsTestSuite, IsBundleUrlValidTest) { auto valid = celix_framework_utils_isBundleUrlValid(framework->getCFramework(), "non-existing.zip", false); EXPECT_FALSE(valid); @@ -72,7 +72,7 @@ TEST_F(CelixFrameworkUtilsTestSuite, testIsBundleUrlValid) { EXPECT_TRUE(valid); } -TEST_F(CelixFrameworkUtilsTestSuite, testExtractBundlePath) { +TEST_F(CelixFrameworkUtilsTestSuite, ExtractBundlePathTest) { const char* testExtractDir = "extractBundleTestDir"; celix_utils_deleteDirectory(testExtractDir, nullptr); @@ -118,7 +118,7 @@ TEST_F(CelixFrameworkUtilsTestSuite, testExtractBundlePath) { celix_utils_deleteDirectory(testExtractDir, nullptr); } -TEST_F(CelixFrameworkUtilsTestSuite, testExtractEmbeddedBundle) { +TEST_F(CelixFrameworkUtilsTestSuite, ExtractEmbeddedBundleTest) { const char* testExtractDir = "extractEmbeddedBundleTestDir"; celix_utils_deleteDirectory(testExtractDir, nullptr); @@ -133,7 +133,7 @@ TEST_F(CelixFrameworkUtilsTestSuite, testExtractEmbeddedBundle) { celix_utils_deleteDirectory(testExtractDir, nullptr); } -TEST_F(CelixFrameworkUtilsTestSuite, CheckBundleAge) { +TEST_F(CelixFrameworkUtilsTestSuite, CheckBundleAgeTest) { struct timespec now = {0, 0}; EXPECT_TRUE(celix_framework_utils_isBundleUrlNewerThan(framework->getCFramework(), SIMPLE_TEST_BUNDLE1_LOCATION, &now)); EXPECT_TRUE(celix_framework_utils_isBundleUrlNewerThan(framework->getCFramework(), SIMPLE_TEST_BUNDLE1_LOCATION, nullptr)); @@ -146,7 +146,7 @@ TEST_F(CelixFrameworkUtilsTestSuite, testListEmbeddedBundles) { EXPECT_EQ("embedded://simple_test_bundle2", list[1]); } -TEST_F(CelixFrameworkUtilsTestSuite, installEmbeddedBundles) { +TEST_F(CelixFrameworkUtilsTestSuite, InstallEmbeddedBundlesTest) { auto ids = framework->getFrameworkBundleContext()->listBundleIds(); EXPECT_EQ(0, ids.size()); @@ -155,7 +155,7 @@ TEST_F(CelixFrameworkUtilsTestSuite, installEmbeddedBundles) { EXPECT_EQ(2, ids.size()); } -TEST_F(CelixFrameworkUtilsTestSuite, installBundleSet) { +TEST_F(CelixFrameworkUtilsTestSuite, InstallBundleSetTest) { auto ids = framework->getFrameworkBundleContext()->listBundleIds(); EXPECT_EQ(0, ids.size()); diff --git a/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc b/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc new file mode 100644 index 00000000..08b603ad --- /dev/null +++ b/libs/framework/gtest/src/MultipleFrameworkTestSuite.cc @@ -0,0 +1,56 @@ +/* + * 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 "celix_launcher.h" + + +class MultipleFrameworkTestSuite : public ::testing::Test { +public: + MultipleFrameworkTestSuite() = default; + ~MultipleFrameworkTestSuite() noexcept override = default; +}; + +TEST_F(MultipleFrameworkTestSuite, MultipleFrameworkTest) { + //framework 1 + celix_framework_t *framework1 = nullptr; + int rc = celixLauncher_launch("framework1.properties", &framework1); + ASSERT_EQ(CELIX_SUCCESS, rc); + celix_bundle_t* fwBundle1 = celix_framework_getFrameworkBundle(framework1); + EXPECT_NE(nullptr, fwBundle1); + celix_bundle_context_t* fwBundleContext1 = celix_framework_getFrameworkContext(framework1); + EXPECT_NE(nullptr, fwBundleContext1); + + //framework 2 + celix_framework_t *framework2 = nullptr; + rc = celixLauncher_launch("framework2.properties", &framework2); + celix_bundle_t* fwBundle2 = celix_framework_getFrameworkBundle(framework2); + EXPECT_NE(nullptr, fwBundle2); + celix_bundle_context_t* fwBundleContext2 = celix_framework_getFrameworkContext(framework2); + EXPECT_NE(nullptr, fwBundleContext2); + + celixLauncher_stop(framework1); + celixLauncher_waitForShutdown(framework1); + celixLauncher_destroy(framework1); + + celixLauncher_stop(framework2); + celixLauncher_waitForShutdown(framework2); + celixLauncher_destroy(framework2); +} diff --git a/libs/framework/gtest/src/multiple_frameworks_test.cpp b/libs/framework/gtest/src/multiple_frameworks_test.cpp deleted file mode 100644 index 910f2b95..00000000 --- a/libs/framework/gtest/src/multiple_frameworks_test.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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> - -extern "C" { - -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <unistd.h> - -#include "celix_launcher.h" -#include "framework.h" - - static framework_pt serverFramework = nullptr; - static bundle_context_pt serverContext = nullptr; - - static framework_pt clientFramework = nullptr; - static bundle_context_pt clientContext = nullptr; - - static void setupFm(void) { - int rc = 0; - bundle_pt bundle = nullptr; - - //server - rc = celixLauncher_launch("framework1.properties", &serverFramework); - ASSERT_EQ(CELIX_SUCCESS, rc); - - bundle = nullptr; - rc = framework_getFrameworkBundle(serverFramework, &bundle); - ASSERT_EQ(CELIX_SUCCESS, rc); - - rc = bundle_getContext(bundle, &serverContext); - ASSERT_EQ(CELIX_SUCCESS, rc); - - - //client - rc = celixLauncher_launch("framework2.properties", &clientFramework); - ASSERT_EQ(CELIX_SUCCESS, rc); - - bundle = nullptr; - rc = framework_getFrameworkBundle(clientFramework, &bundle); - ASSERT_EQ(CELIX_SUCCESS, rc); - - rc = bundle_getContext(bundle, &clientContext); - ASSERT_EQ(CELIX_SUCCESS, rc); - } - - static void teardownFm(void) { - - celixLauncher_stop(serverFramework); - celixLauncher_waitForShutdown(serverFramework); - celixLauncher_destroy(serverFramework); - - celixLauncher_stop(clientFramework); - celixLauncher_waitForShutdown(clientFramework); - celixLauncher_destroy(clientFramework); - - serverContext = nullptr; - serverFramework = nullptr; - clientContext = nullptr; - clientFramework = nullptr; - } - - static void testFrameworks(void) { - printf("testing startup/shutdown multiple frameworks\n"); - } - -} - -class CelixMultipleFrameworks : public ::testing::Test { -public: - CelixMultipleFrameworks() { - setupFm(); - } - - ~CelixMultipleFrameworks() override { - teardownFm(); - } -}; - -TEST_F(CelixMultipleFrameworks, testFrameworks) { - testFrameworks(); -}
