This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch
feature/685-update-container-config-properties-usage
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to
refs/heads/feature/685-update-container-config-properties-usage by this push:
new bf0011a45 gh-685: Improve celix_launcher coverage and fix memleaks
bf0011a45 is described below
commit bf0011a454450f922f06c3909bab97a750c13975
Author: Pepijn Noltes <[email protected]>
AuthorDate: Tue Jun 4 21:03:57 2024 +0200
gh-685: Improve celix_launcher coverage and fix memleaks
---
.../gtest/src/CelixLauncherErrorInjectionTestSuite.cc | 9 +++++++++
libs/framework/gtest/src/CelixLauncherTestSuite.cc | 17 +++++++++++++++++
libs/framework/src/celix_launcher.c | 3 ++-
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/libs/framework/gtest/src/CelixLauncherErrorInjectionTestSuite.cc
b/libs/framework/gtest/src/CelixLauncherErrorInjectionTestSuite.cc
index 6b448f013..416d753b6 100644
--- a/libs/framework/gtest/src/CelixLauncherErrorInjectionTestSuite.cc
+++ b/libs/framework/gtest/src/CelixLauncherErrorInjectionTestSuite.cc
@@ -78,4 +78,13 @@ TEST_F(CelixLauncherErrorInjectionTestSuite,
CombinePropertiesErrorTest) {
//Then an exception is expected
EXPECT_EQ(1, rc);
+
+ //Given an error injection for celix_properties_setEntry is primed when
called from celix_launcher_combineProperties
+
celix_ei_expect_celix_properties_setEntry((void*)celix_launcher_combineProperties,
0, ENOMEM);
+
+ //When calling celix_launcher_launchAndWait with a create cache flag
+ rc = launch({"programName", "-c"}, nullptr);
+
+ //Then an exception is expected
+ EXPECT_EQ(1, rc);
}
diff --git a/libs/framework/gtest/src/CelixLauncherTestSuite.cc
b/libs/framework/gtest/src/CelixLauncherTestSuite.cc
index 58f0da64f..55fc2cfbb 100644
--- a/libs/framework/gtest/src/CelixLauncherTestSuite.cc
+++ b/libs/framework/gtest/src/CelixLauncherTestSuite.cc
@@ -40,6 +40,7 @@ class CelixLauncherTestSuite : public ::testing::Test {
celix_autofree char* str;
EXPECT_EQ(CELIX_SUCCESS, celix_properties_saveToString(props, 0,
&str));
propsStr = str;
+ celix_properties_destroy(props);
}
return std::async(std::launch::async, [args, propsStr, expectedRc] {
char** argv = new char*[args.size()];
@@ -243,3 +244,19 @@ TEST_F(CelixLauncherTestSuite,
StartWithInvalidEmbeddedPropertiesTest) {
//Then the launch will exit with a return code of 1
EXPECT_EQ(1, rc);
}
+
+TEST_F(CelixLauncherTestSuite, StartWithInvalidArgumentsTest) {
+ //When launching the framework with invalid arguments and expect a 1
return code
+ auto future = launchInThread({"programName", "config1.properties",
"config2.properties"}, nullptr, 1);
+
+ // The launch will exit
+ auto status =
future.wait_for(std::chrono::milliseconds{LAUNCH_WAIT_TIMEOUT});
+ EXPECT_EQ(status, std::future_status::ready);
+
+ //When launching the framework with invalid arguments and expect a 1
return code
+ future = launchInThread({"programName", "-c", "-p"}, nullptr, 1);
+
+ // The launch will exit
+ status = future.wait_for(std::chrono::milliseconds{LAUNCH_WAIT_TIMEOUT});
+ EXPECT_EQ(status, std::future_status::ready);
+}
diff --git a/libs/framework/src/celix_launcher.c
b/libs/framework/src/celix_launcher.c
index 19ec3d3cd..c4bd7188b 100644
--- a/libs/framework/src/celix_launcher.c
+++ b/libs/framework/src/celix_launcher.c
@@ -24,7 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/stat.h>
+#include <libgen.h>
#ifndef CELIX_NO_CURLINIT
#include <curl/curl.h>
@@ -333,6 +333,7 @@ celix_status_t
celix_launcher_combineProperties(celix_properties_t* embeddedProp
CELIX_PROPERTIES_ITERATE(runtimeProps, visit) {
celix_status_t status = celix_properties_setEntry(embeddedProps,
visit.key, &visit.entry);
if (status != CELIX_SUCCESS) {
+ celix_properties_destroy(embeddedProps);
return status;
}
}