mirror of
https://github.com/falk-werner/webfused
synced 2024-10-27 20:44:08 +00:00
fix: copy items when init from another list
This commit is contained in:
parent
d8879cf1d9
commit
fa46f9fd6e
@ -219,7 +219,7 @@ wfd_config_read_mountoptions(
|
||||
config_setting_t * filesystem,
|
||||
struct wfd_string_list * mount_options)
|
||||
{
|
||||
config_setting_t * list = config_setting_get_member(filesystem, "mountpoint_options");
|
||||
config_setting_t * list = config_setting_get_member(filesystem, "mount_options");
|
||||
if ((NULL != list) && (CONFIG_TRUE == config_setting_is_list(list)))
|
||||
{
|
||||
int length = config_setting_length(list);
|
||||
|
@ -24,7 +24,10 @@ wfd_string_list_init_copy(
|
||||
list->capacity = other->capacity;
|
||||
list->items = malloc(sizeof(char *) * list->capacity);
|
||||
|
||||
memcpy(list->items, other->items, (sizeof(char*) * list->size));
|
||||
for(size_t i = 0; i < other->size; i++)
|
||||
{
|
||||
list->items[i] = strdup(other->items[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2,12 +2,14 @@
|
||||
|
||||
#include "webfused/config/config.h"
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/util/string_list.h"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock/logger.hpp"
|
||||
#include "mock/config_builder.hpp"
|
||||
#include "mock/libconfig.hpp"
|
||||
|
||||
using ::testing::Invoke;
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrictMock;
|
||||
@ -169,3 +171,29 @@ TEST(configfile_fs, filesystems_failed_add_options)
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_fs, with_mountoptions)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(1).WillOnce(Invoke(
|
||||
[](wfd_config * config, char const * name, char const * mountpoint, wfd_string_list const * mount_options) -> bool {
|
||||
std::cout << mount_options->items[0] << std::endl;
|
||||
std::cout << mount_options->items[1] << std::endl;
|
||||
return (2 == mount_options->size);
|
||||
}));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {name = \"foo\", mount_point = \"/tmp/test\", mount_options = (\"-o\", \"allow_user\") }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user