<commit_before>/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>
#include <ztest.h>

#include <zephyr.h>
#include <misc/reboot.h>
#include <string.h>

#include <settings/settings.h>

static u32_t val32;

static int c1_set(int argc, char **argv, char *val)
{
	u32_t new_val32;
	int ret;

	if (argc != 1) {
		return -ENOENT;
	}

	if (strcmp(argv[0], "val32")) {
		return -ENOENT;
	}

	ret = SETTINGS_VALUE_SET(val, SETTINGS_INT32, new_val32);
	if (ret != 0) {
		return -EIO;
	}

	val32 = new_val32;

	return 0;
}

static int c1_export(int (*export_func)(const char *name, char *val))
{
	char buf[32];

	ARG_UNUSED(tgt);

	settings_str_from_value(SETTINGS_INT32, &val32, buf, sizeof(val32));

	export_func("hello/val32", buf);

	return 0;
}

static struct settings_handler c1_settings = {
	.name = "hello",
	.h_set = c1_set,
	.h_export = c1_export,
};

void test_init(void)
{
	int err;
	u32_t prev_int;

	val32++;

	err = settings_save();
	zassert_true(err == 0, "can't save settings");
<commit_msg>tests: subsys: settings: fcb-int tests rework<commit_after>/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>
#include <ztest.h>

#include <zephyr.h>
#include <misc/reboot.h>
#include <string.h>

#include <settings/settings.h>

static u32_t val32;

static int c1_set(int argc, char **argv, void *value_ctx)
{
	int rc;

	if (argc == 1 && !strcmp(argv[0], "val32"))	 {
		rc = settings_val_read_cb(value_ctx, &val32, sizeof(val32));
		zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback");
		return 0;
	}

	return -ENOENT;
}

static int c1_export(int (*export_func)(const char *name, void *value,
					size_t val_len))
{
	(void)export_func("hello/val32", &val32, sizeof(val32));

	return 0;
}

static struct settings_handler c1_settings = {
	.name = "hello",
	.h_set = c1_set,
	.h_export = c1_export,
};

void test_init(void)
{
	int err;
	u32_t prev_int;

	val32++;

	err = settings_save();
	zassert_true(err == 0, "can't save settings");

{'fraction_non_alphanumeric': 0.1556741028128031, 'fraction_numerical': 0.041707080504364696, 'mean_word_length': 4.358441558441559, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6612496', 'n_tokens_mistral': 930, 'n_tokens_neox': 858, 'n_words': 197}