|
13 | 13 | #include "data.h" |
14 | 14 | #include "test_utils.h" |
15 | 15 |
|
| 16 | +extern struct thingset_data_object data_objects[]; |
| 17 | +extern size_t data_objects_size; |
| 18 | +extern int32_t nested_beginning; |
| 19 | +extern float nested_obj2_item2; |
| 20 | + |
16 | 21 | static struct thingset_context ts; |
17 | 22 |
|
18 | 23 | ZTEST(thingset_bin, test_get_root_ids) |
@@ -985,6 +990,100 @@ ZTEST(thingset_bin, test_import_data) |
985 | 990 | b = true; |
986 | 991 | } |
987 | 992 |
|
| 993 | +ZTEST(thingset_bin, test_import_report) |
| 994 | +{ |
| 995 | + |
| 996 | + uint8_t data[THINGSET_TEST_BUF_SIZE]; |
| 997 | + |
| 998 | + const char rpt_exp_hex[] = |
| 999 | + "1F 19 08 00 A5 " |
| 1000 | + "10 19 03 E8 " /* t_s */ |
| 1001 | + "19 02 01 F5 " /* Types/wBool */ |
| 1002 | + "19 06 00 02 " /* Records: 2 */ |
| 1003 | + "19 07 01 01 " /* Nested/rBeginning */ |
| 1004 | + "19 07 08 FA 40 0C CC CD"; /* Nested/Obj2/rItem2_V */ |
| 1005 | + |
| 1006 | + struct thingset_context ts_local; |
| 1007 | + thingset_init(&ts_local, data_objects, data_objects_size); |
| 1008 | + |
| 1009 | + int data_len = hex2bin_spaced(rpt_exp_hex, data, sizeof(data)); |
| 1010 | + |
| 1011 | + /* save old values */ |
| 1012 | + uint32_t timestamp_old = timestamp; |
| 1013 | + bool b_old = b; |
| 1014 | + int32_t nested_beginning_old = nested_beginning; |
| 1015 | + float nested_obj2_item2_old = nested_obj2_item2; |
| 1016 | + |
| 1017 | + /* set values to zero/false */ |
| 1018 | + timestamp = 0; |
| 1019 | + b = false; |
| 1020 | + nested_obj2_item2 = 0.0; |
| 1021 | + nested_beginning = 0; |
| 1022 | + |
| 1023 | + int status = thingset_import_report(&ts_local, data, data_len, THINGSET_WRITE_MASK, |
| 1024 | + THINGSET_BIN_IDS_VALUES, 0x800); |
| 1025 | + zassert_equal(status, 0); |
| 1026 | + zassert_equal(timestamp, timestamp_old); |
| 1027 | + zassert_equal(b, b_old); |
| 1028 | + zassert_equal(nested_beginning, nested_beginning_old); |
| 1029 | + zassert_equal(nested_obj2_item2, nested_obj2_item2_old); |
| 1030 | + |
| 1031 | + /* set to originial values */ |
| 1032 | + timestamp = timestamp_old; |
| 1033 | + b = b_old; |
| 1034 | + nested_beginning = nested_beginning_old; |
| 1035 | + nested_obj2_item2 = nested_obj2_item2_old; |
| 1036 | +} |
| 1037 | + |
| 1038 | +ZTEST(thingset_bin, test_import_report_error) |
| 1039 | +{ |
| 1040 | + |
| 1041 | + uint8_t data[THINGSET_TEST_BUF_SIZE]; |
| 1042 | + |
| 1043 | + const char rpt_exp_hex[] = |
| 1044 | + "1F 19 08 00 A5 " |
| 1045 | + "10 19 03 E8 " /* t_s */ |
| 1046 | + "19 02 01 F5 " /* Types/wBool */ |
| 1047 | + "19 06 00 02 " /* Records: 2 */ |
| 1048 | + "19 07 01 01 " /* Nested/rBeginning */ |
| 1049 | + "19 07 08 FA 40 0C CC CD"; /* Nested/Obj2/rItem2_V */ |
| 1050 | + |
| 1051 | + struct thingset_context ts_local; |
| 1052 | + thingset_init(&ts_local, data_objects, data_objects_size); |
| 1053 | + |
| 1054 | + int data_len = hex2bin_spaced(rpt_exp_hex, data, sizeof(data)); |
| 1055 | + |
| 1056 | + /* save old values */ |
| 1057 | + uint32_t timestamp_old = timestamp; |
| 1058 | + bool b_old = b; |
| 1059 | + int32_t nested_beginning_old = nested_beginning; |
| 1060 | + float nested_obj2_item2_old = nested_obj2_item2; |
| 1061 | + |
| 1062 | + /* set values to zero/false */ |
| 1063 | + timestamp = 0; |
| 1064 | + b = false; |
| 1065 | + nested_obj2_item2 = 0.0; |
| 1066 | + nested_beginning = 0; |
| 1067 | + |
| 1068 | + /* no report */ |
| 1069 | + data[0] = 0x00; |
| 1070 | + int status = thingset_import_report(&ts_local, data, data_len, THINGSET_WRITE_MASK, |
| 1071 | + THINGSET_BIN_IDS_VALUES, 0x800); |
| 1072 | + zassert_equal(status, -THINGSET_ERR_UNSUPPORTED_FORMAT); |
| 1073 | + |
| 1074 | + /* wrong subset */ |
| 1075 | + data[0] = 0x1f; |
| 1076 | + status = thingset_import_report(&ts_local, data, data_len, THINGSET_WRITE_MASK, |
| 1077 | + THINGSET_BIN_IDS_VALUES, 0x0); |
| 1078 | + zassert_equal(status, -THINGSET_ERR_NOT_FOUND); |
| 1079 | + |
| 1080 | + /* set to originial values */ |
| 1081 | + timestamp = timestamp_old; |
| 1082 | + b = b_old; |
| 1083 | + nested_beginning = nested_beginning_old; |
| 1084 | + nested_obj2_item2 = nested_obj2_item2_old; |
| 1085 | +} |
| 1086 | + |
988 | 1087 | ZTEST(thingset_bin, test_import_record) |
989 | 1088 | { |
990 | 1089 | struct thingset_endpoint endpoint; |
|
0 commit comments