1 /*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 * Copyright (c) 2015 Runtime Inc
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #include "settings_test.h"
9 #include "settings/settings_file.h"
10 #include <zephyr/fs/fs.h>
11
ZTEST(settings_config_fs,test_config_empty_file)12 ZTEST(settings_config_fs, test_config_empty_file)
13 {
14 int rc;
15 struct settings_file cf_mfg;
16 struct settings_file cf_running;
17 const char cf_mfg_test[] = "";
18 const char cf_running_test[] = "\n\n";
19
20 config_wipe_srcs();
21
22 cf_mfg.cf_name = TEST_CONFIG_DIR"/mfg";
23 cf_running.cf_name = TEST_CONFIG_DIR"/running";
24
25 rc = settings_file_src(&cf_mfg);
26 zassert_true(rc == 0, "can't register FS as configuration source");
27 rc = settings_file_src(&cf_running);
28 zassert_true(rc == 0, "can't register FS as configuration source");
29
30 settings_mount_file_backend(&cf_mfg);
31 /*
32 * No files
33 */
34 settings_load();
35
36 rc = fs_mkdir(TEST_CONFIG_DIR);
37 zassert_true(rc == 0 || rc == -EEXIST, "can't create directory");
38
39 rc = fsutil_write_file(TEST_CONFIG_DIR"/mfg", cf_mfg_test,
40 0);
41 zassert_true(rc == 0, "can't write to file");
42
43 rc = fsutil_write_file(TEST_CONFIG_DIR"/running", cf_running_test,
44 sizeof(cf_running_test));
45 zassert_true(rc == 0, "can't write to file");
46
47 settings_load();
48 config_wipe_srcs();
49 ctest_clear_call_state();
50 }
51