1 /*
2 * Copyright 2023 Yonatan Schachter
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include <zephyr/bindesc.h>
9 #include <zephyr/version.h>
10
11 #define STR_ID 1
12 #define UINT_ID 2
13 #define BYTES_ID 3
14
15 #define STR_DATA "Hello world!"
16 #define UINT_DATA 5
17 #define BYTES_DATA {1, 2, 3, 4}
18
19 BINDESC_STR_DEFINE(bindesc_string, STR_ID, STR_DATA);
20 BINDESC_UINT_DEFINE(bindesc_uint, UINT_ID, UINT_DATA);
21 BINDESC_BYTES_DEFINE(bindesc_bytes, BYTES_ID, (BYTES_DATA));
22
ZTEST(bindesc_define,test_version_number)23 ZTEST(bindesc_define, test_version_number)
24 {
25 zassert_equal(BINDESC_GET_UINT(kernel_version_number), KERNEL_VERSION_NUMBER,
26 "bindesc kernel version number is incorrect");
27 }
28
ZTEST(bindesc_define,test_custom_bindesc_str)29 ZTEST(bindesc_define, test_custom_bindesc_str)
30 {
31 zassert_equal(BINDESC_GET_SIZE(bindesc_string), sizeof(STR_DATA));
32 zassert_mem_equal(BINDESC_GET_STR(bindesc_string), STR_DATA, sizeof(STR_DATA));
33 }
34
ZTEST(bindesc_define,test_custom_bindesc_uint)35 ZTEST(bindesc_define, test_custom_bindesc_uint)
36 {
37 zassert_equal(BINDESC_GET_SIZE(bindesc_uint), 4);
38 zassert_equal(BINDESC_GET_UINT(bindesc_uint), UINT_DATA);
39 }
40
ZTEST(bindesc_define,test_custom_bindesc_bytes)41 ZTEST(bindesc_define, test_custom_bindesc_bytes)
42 {
43 uint8_t expected_data[] = BYTES_DATA;
44
45 zassert_equal(BINDESC_GET_SIZE(bindesc_bytes), 4);
46 zassert_mem_equal(BINDESC_GET_STR(bindesc_bytes), expected_data, 4);
47 }
48
49 ZTEST_SUITE(bindesc_define, NULL, NULL, NULL, NULL, NULL);
50