zephyr/tests/subsys/settings/src/settings_test_getset_bytes.c
Andrzej Puzdrowski 94ff339cbf subsys: Add a new settings subsystem
Adapt the MyNewt non-volatile configuration system to become a settings
system in Zephyr.
The original code was modifed in the following ways:

* Renamed from config to settings
* Use the zephyr FCB, FS API, and base64 subsystems
* lltoa like function was added to sources as it was required but not
  included in Zephyr itself.
* The original code was modified to use Zephyr's slist.h as single
  linked list implementation.
* Reworked code which was using strtok_r, added function
  for decoding a string to a s64_t value.
* Thank to the above the settings subsys doesn't require newlibc anymore.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-28 10:44:20 -04:00

40 lines
924 B
C

/*
* Copyright (c) 2018 Nordic Semiconductor ASA
* Copyright (c) 2015 Runtime Inc
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "settings_test.h"
void test_config_getset_bytes(void)
{
char orig[32];
char bytes[32];
char str[48];
char *ret;
int j, i;
int tmp;
int rc;
for (j = 1; j < sizeof(orig); j++) {
for (i = 0; i < j; i++) {
orig[i] = i + j + 1;
}
ret = settings_str_from_bytes(orig, j, str, sizeof(str));
zassert_not_null(ret, "string base64 encodding\n");
tmp = strlen(str);
zassert_true(tmp < sizeof(str), "encoded string is to long\n");
memset(bytes, 0, sizeof(bytes));
tmp = sizeof(bytes);
tmp = sizeof(bytes);
rc = settings_bytes_from_str(str, bytes, &tmp);
zassert_true(rc == 0, "base64 to string decodding\n");
zassert_true(tmp == j, "decoded string bad length\n");
zassert_true(!memcmp(orig, bytes, j),
"decoded string not match to origin\n");
}
}