Skip to content

Commit

Permalink
gh-685: Improve celix_launcher coverage and fix memleaks
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Jun 4, 2024
1 parent e06e2ad commit bf0011a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
17 changes: 17 additions & 0 deletions libs/framework/gtest/src/CelixLauncherTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion libs/framework/src/celix_launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit bf0011a

Please sign in to comment.