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
test_config_save_one_byte_value(const char * name,uint8_t val)11 static int test_config_save_one_byte_value(const char *name, uint8_t val)
12 {
13 return settings_save_one(name, &val, 1);
14 }
15
16
ZTEST(settings_config_fs,test_config_save_one_file)17 ZTEST(settings_config_fs, test_config_save_one_file)
18 {
19 int rc;
20 struct settings_file cf;
21
22 config_wipe_srcs();
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 = 33U;
37 rc = settings_save();
38 zassert_true(rc == 0, "fs write error");
39
40 rc = test_config_save_one_byte_value("myfoo/mybar", 42);
41 zassert_equal(rc, 0, "fs one item write error");
42
43 rc = settings_load();
44 zassert_true(rc == 0, "fs redout error");
45 zassert_true(val8 == 42U, "bad value read");
46
47 rc = test_config_save_one_byte_value("myfoo/mybar", 44);
48 zassert_true(rc == 0, "fs one item write error");
49
50 rc = settings_load();
51 zassert_true(rc == 0, "fs redout error");
52 zassert_true(val8 == 44U, "bad value read");
53 }
54