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
11 #define CF_FILE_CONTENT_1 "\x0d\x00myfoo/mybar=\x08"
12 #define CF_FILE_CONTENT_2 "\x0d\x00myfoo/mybar=\x2b"
13
ZTEST(settings_config_fs,test_config_save_in_file)14 ZTEST(settings_config_fs, test_config_save_in_file)
15 {
16 int rc;
17 struct settings_file cf;
18 const char cf_pattern_1[] = CF_FILE_CONTENT_1;
19 const char cf_pattern_2[] = CF_FILE_CONTENT_2;
20
21 config_wipe_srcs();
22
23 rc = fs_mkdir(TEST_CONFIG_DIR);
24 zassert_true(rc == 0 || rc == -EEXIST, "can't create directory");
25
26 cf.cf_name = TEST_CONFIG_DIR "/blah";
27 cf.cf_maxlines = 1000;
28 cf.cf_lines = 0; /* normally fetched while loading, but this is test */
29 rc = settings_file_src(&cf);
30 zassert_true(rc == 0, "can't register FS as configuration source");
31
32 rc = settings_file_dst(&cf);
33 zassert_true(rc == 0,
34 "can't register FS as configuration destination");
35
36 val8 = 8U;
37 rc = settings_save();
38 zassert_true(rc == 0, "fs write error");
39
40 rc = settings_test_file_strstr(cf.cf_name, cf_pattern_1,
41 sizeof(cf_pattern_1)-1);
42 zassert_true(rc == 0, "bad value read");
43
44 val8 = 43U;
45 rc = settings_save();
46 zassert_true(rc == 0, "fs write error");
47
48 rc = settings_test_file_strstr(cf.cf_name, cf_pattern_2,
49 sizeof(cf_pattern_2)-1);
50 zassert_true(rc == 0, "bad value read");
51 }
52