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_MFG_TEST_STR "\x0D\x00myfoo/mybar=\x01"
12 #define CF_RUNNING_TEST_STR "\x0D\x00myfoo/mybar=\x08"
13
ZTEST(settings_config_fs,test_config_small_file)14 ZTEST(settings_config_fs, test_config_small_file)
15 {
16 int rc;
17 struct settings_file cf_mfg;
18 struct settings_file cf_running;
19 const char cf_mfg_test[] = CF_MFG_TEST_STR;
20 const char cf_running_test[] = CF_RUNNING_TEST_STR;
21
22 config_wipe_srcs();
23
24 cf_mfg.cf_name = TEST_CONFIG_DIR "/mfg";
25 cf_running.cf_name = TEST_CONFIG_DIR "/running";
26
27 rc = settings_file_src(&cf_mfg);
28 zassert_true(rc == 0, "can't register FS as configuration source");
29 rc = settings_file_src(&cf_running);
30 zassert_true(rc == 0, "can't register FS as configuration source");
31
32 rc = fsutil_write_file(TEST_CONFIG_DIR "/mfg", cf_mfg_test,
33 sizeof(cf_mfg_test));
34 zassert_true(rc == 0, "can't write to file");
35
36 settings_load();
37 zassert_true(test_set_called, "the SET handler wasn't called");
38 zassert_true(val8 == 1U,
39 "SET handler: was called with wrong parameters");
40
41 ctest_clear_call_state();
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 zassert_true(test_set_called, "the SET handler wasn't called");
49 zassert_true(val8 == 8U,
50 "SET handler: was called with wrong parameters");
51
52 ctest_clear_call_state();
53 }
54