|
13 | 13 | #include "data.h" |
14 | 14 | #include "test_utils.h" |
15 | 15 |
|
| 16 | +extern struct thingset_data_object report_data_objects[]; |
| 17 | +extern size_t report_data_objects_size; |
| 18 | +extern uint32_t report_timestamp; |
| 19 | +extern bool report_b; |
| 20 | +extern int32_t report_nested_beginning; |
| 21 | +extern float report_nested_obj2_item2; |
| 22 | + |
16 | 23 | static struct thingset_context ts; |
17 | 24 |
|
18 | 25 | ZTEST(thingset_bin, test_get_root_ids) |
@@ -985,6 +992,63 @@ ZTEST(thingset_bin, test_import_data) |
985 | 992 | b = true; |
986 | 993 | } |
987 | 994 |
|
| 995 | +ZTEST(thingset_bin, test_import_report) |
| 996 | +{ |
| 997 | + uint8_t data[THINGSET_TEST_BUF_SIZE]; |
| 998 | + |
| 999 | + const char rpt_exp_hex[] = |
| 1000 | + "1F 19 08 00 A5 " |
| 1001 | + "10 19 03 E8 " /* t_s */ |
| 1002 | + "19 02 01 F5 " /* Types/wBool */ |
| 1003 | + "19 06 00 02 " /* Records: 2 */ |
| 1004 | + "19 07 01 01 " /* Nested/rBeginning */ |
| 1005 | + "19 07 08 FA 40 0C CC CD"; /* Nested/Obj2/rItem2_V */ |
| 1006 | + |
| 1007 | + struct thingset_context ts_local; |
| 1008 | + thingset_init(&ts_local, report_data_objects, report_data_objects_size); |
| 1009 | + |
| 1010 | + int data_len = hex2bin_spaced(rpt_exp_hex, data, sizeof(data)); |
| 1011 | + |
| 1012 | + int status = thingset_import_report(&ts_local, data, data_len, THINGSET_WRITE_MASK, |
| 1013 | + THINGSET_BIN_IDS_VALUES, 0x800); |
| 1014 | + |
| 1015 | + zassert_equal(status, 0); |
| 1016 | + zassert_equal(report_timestamp, 1000); |
| 1017 | + zassert_equal(report_b, true); |
| 1018 | + zassert_equal(report_nested_beginning, 1); |
| 1019 | + zassert_equal(report_nested_obj2_item2, 2.2F); |
| 1020 | +} |
| 1021 | + |
| 1022 | +ZTEST(thingset_bin, test_import_report_error) |
| 1023 | +{ |
| 1024 | + uint8_t data[THINGSET_TEST_BUF_SIZE]; |
| 1025 | + |
| 1026 | + const char rpt_exp_hex[] = |
| 1027 | + "1F 19 08 00 A5 " |
| 1028 | + "10 19 03 E8 " /* t_s */ |
| 1029 | + "19 02 01 F5 " /* Types/wBool */ |
| 1030 | + "19 06 00 02 " /* Records: 2 */ |
| 1031 | + "19 07 01 01 " /* Nested/rBeginning */ |
| 1032 | + "19 07 08 FA 40 0C CC CD"; /* Nested/Obj2/rItem2_V */ |
| 1033 | + |
| 1034 | + struct thingset_context ts_local; |
| 1035 | + thingset_init(&ts_local, report_data_objects, report_data_objects_size); |
| 1036 | + |
| 1037 | + int data_len = hex2bin_spaced(rpt_exp_hex, data, sizeof(data)); |
| 1038 | + |
| 1039 | + /* no report */ |
| 1040 | + data[0] = 0x00; |
| 1041 | + int status = thingset_import_report(&ts_local, data, data_len, THINGSET_WRITE_MASK, |
| 1042 | + THINGSET_BIN_IDS_VALUES, 0x800); |
| 1043 | + zassert_equal(status, -THINGSET_ERR_UNSUPPORTED_FORMAT); |
| 1044 | + |
| 1045 | + /* wrong subset */ |
| 1046 | + data[0] = 0x1f; |
| 1047 | + status = thingset_import_report(&ts_local, data, data_len, THINGSET_WRITE_MASK, |
| 1048 | + THINGSET_BIN_IDS_VALUES, 0x0); |
| 1049 | + zassert_equal(status, -THINGSET_ERR_NOT_FOUND); |
| 1050 | +} |
| 1051 | + |
988 | 1052 | ZTEST(thingset_bin, test_import_record) |
989 | 1053 | { |
990 | 1054 | struct thingset_endpoint endpoint; |
|
0 commit comments