1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/ztest.h>
8 #include "senml_encode.h"
9 
10 #ifndef ZCBOR_CANONICAL
11 #define TEST_INDEFINITE_LENGTH_ARRAYS
12 #endif
13 #include <common_test.h>
14 
ZTEST(cbor_encode_test4,test_senml)15 ZTEST(cbor_encode_test4, test_senml)
16 {
17 	struct lwm2m_senml input = {
18 		.lwm2m_senml_record_m[0] = {
19 			.record_bn = {.record_bn = {.value = "Foo", .len = 3}},
20 			.record_bn_present = 1,
21 			.record_bt = {.record_bt = 42},
22 			.record_bt_present = 1,
23 			.record_n = {.record_n = {.value = "Bar", .len = 3}},
24 			.record_n_present = 1,
25 			.record_t = {.record_t = 7},
26 			.record_t_present = 1,
27 			.record_union = {
28 				.union_vb = true,
29 				.record_union_choice = union_vb_c,
30 			},
31 			.record_union_present = 1,
32 			.record_key_value_pair_m_count = 0,
33 		},
34 		.lwm2m_senml_record_m_count = 1,
35 	};
36 	uint8_t payload[100];
37 	size_t encode_len;
38 	uint8_t exp_payload1[] = {
39 		LIST(1), MAP(5), 0x21, 0x63, 'F', 'o', 'o', 0x22, 0x18, 42,
40 		0x00, 0x63, 'B', 'a', 'r', 0x06, 0x07, 0x04, 0xF5, END END
41 	};
42 
43 	zassert_equal(ZCBOR_SUCCESS, cbor_encode_lwm2m_senml(payload, sizeof(payload), &input, &encode_len), NULL);
44 	zassert_equal(sizeof(exp_payload1), encode_len, NULL);
45 	zassert_mem_equal(payload, exp_payload1, encode_len, NULL);
46 }
47 
48 ZTEST_SUITE(cbor_encode_test4, NULL, NULL, NULL, NULL, NULL);
49